|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Printing a list desending?
Hello,
I am writing a program somthing like a phonebook and i have a problem. Im using a list to store the values, its looks somthing like this. [('641-567-567', 'Bob'), ('656-567-4567', 'joe'), ('567-567-567', 'Billy')] is it possible to print them going down horizontaly rather than across? Ex. ('641-567-567', 'Bob') ('656-567-4567', 'joe') ('567-567-567', 'Billy') When i enter a new number it saves the list in a file, when the program starts it imports the list data. I tryed a for loop: for entry in phonebook: print entry (phonebook being the list) When i type in new names it works, but the imported ones dont print downwards. Only the new ones. Thx in advance guys ![]() |
|
#2
|
|||
|
|||
|
Your code you posted will work regardless of where the list is coming from.
The fact that it does not work means you are doing something else wrong, but without any code to look at I couldn't say what. |
|
#3
|
|||
|
|||
|
I would want my data file to look something like this:
Code:
641-567-5671, Bob 656-567-4567, Joe 567-567-5672, Billy |
|
#4
|
|||
|
|||
|
Quote:
Thx alot this helped me alot ![]() But i get this error when running Traceback (most recent call last): File "C:\Python25\Compile File\PhoneBook.pyw", line 21, in <module> number, name = item.split(',') ValueError: need more than 1 value to unpack I can post the script if needed(I'd rather not) |
|
#5
|
|||
|
|||
|
item must be a string of the form:
Code:
'567-567-5672, Billy' |
|
#6
|
|||
|
|||
|
Ohh i see
How would i save the file with only that info? Right now im using pickel to write it. import pickle file = open("phone_numbers.dat", "w") pickle.dump(pb_dict, file) file.close() |
|
#7
|
|||
|
|||
|
Last edited by SuperOscar : May 5th, 2008 at 02:55 AM. |
|
#8
|
|||
|
|||
|
Yea! It worked!
Thank you very much SuperOscar and bvdet. ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Printing a list desending? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|