Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Python

Python Discussion forum for Python, a high-level language with simple syntax, but yet powerful.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-19-2007, 12:46 PM
Sir_Rimo's Avatar   
Sir_Rimo Sir_Rimo is offline
Newbie
 
Join Date: Jan 2007
Posts: 18
Rep Power: 7
Sir_Rimo is on a distinguished road
Arrow Python arrays...

Hi EveryBody.
I have a problem with arrays in Python. Can you please help me?
the fact is that there is a program here (I don't know who has written it) that returns an array to me and I must show the results in a list box (QT).
the problem is that I don't know anything about how to handle the array result. it may be [], [(0),] or [3].
I really don't have an idea about the program, but would you please tell me how to work with arrays and convert their results into strings?
I'd be thankful so much.
thanks everybody...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-19-2007, 01:43 PM
v0id's Avatar   
v0id v0id is offline
Super Moderator
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,458
Last Blog:
CherryPy(thon)
Rep Power: 27
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

In Python it's called "lists".
You can access the lists using the index-operators, [].

Lists starts at zero (0) like arrays, and they work almost in the same way. So if you want to get the first element in the list do this [0], the next [1] and so on. You can also use more advanced operators and do like this [0:2] which will return the two first elements in the list like a new list - and if you don't want the first element as a f.ex. string you can get it as a list like this [0:1]. You can also access it both ways using [-x] or [-x:-x], etc.

Now you're probably confused if you don't know to all this, let's see an example:
Code:
l = ["apple", "banana", "orange"]

l[0] # Returns "apple"
l[1] # Returns "banana"

l[0:1] # Returns ["apple"]
l[0:2] # Returns ["apple", "banana"]
l[1:3] # Returns ["banana", "orange"]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-20-2007, 07:13 AM
Sir_Rimo's Avatar   
Sir_Rimo Sir_Rimo is offline
Newbie
 
Join Date: Jan 2007
Posts: 18
Rep Power: 7
Sir_Rimo is on a distinguished road
Default

Thank you dear vOid,
I must say that sometimes when I print the return value of the program, it shows " zeros((0,),'i') "
I know that it is a part of numarray module, but I don't find a way to recieve the result as a string. the tostring() method of array does not work here.
Can you please help me?
Thank you very much.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-20-2007, 08:54 AM
v0id's Avatar   
v0id v0id is offline
Super Moderator
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,458
Last Blog:
CherryPy(thon)
Rep Power: 27
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

You don't need any functions to convert the numeric value to a string, you can use simple type-casting. It's possible in Python because it's a very type-weak language, so everything is almost possible with types.

Here is an example to illustrate it (copy+pastet from the idle):
Code:
>>> my_num = 100
>>> my_str = my_num # will be 'int'
>>> type(my_num)
<type 'int'>
>>> type(my_str)
<type 'int'>
>>> my_str = str(my_num) # now it'll be 'str'
>>> type(my_str)
<type 'str'>
Here it's illustrated with a list:
Code:
>>> my_numbers = [1, 2, 3, 1000, 20000, 30000]
>>> type(my_numbers)
<type 'list'>
>>> type(my_numbers[0])
<type 'int'>
>>> type(str(my_numbers[0]))
<type 'str'>
>>> type(my_numbers[0:2])
<type 'list'>
>>> type(my_numbers[0:2][0])
<type 'int'>
>>> type(str(my_numbers[0:2][0]))
<type 'str'>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Splitting Strings with Empty Separator (Python) Matt Python 3 05-18-2007 12:27 PM
Python 2D array question annannienann Python 3 04-23-2007 04:36 PM
Python Collection reachpradeep Python 1 03-03-2007 02:50 PM
Arrays clookid PHP Tutorials 1 01-11-2007 08:30 PM


All times are GMT -5. The time now is 01:45 PM.

Contest Stats

John ........ 223.00000
dargueta ........ 168.00000
Xav ........ 164.00000
LogicKills ........ 20.00000
sam ........ 20.00000
gaylo565 ........ 18.00000
|pH| ........ 15.00000
WingedPanther ........ 15.00000
Johnnyboy ........ 3.00000
navghost ........ 1.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads