Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing in a new file

Status
Not open for further replies.

Wulf

Programmer
Nov 30, 2000
9
AT
Your message was:
Without looking at my notes, I think you are going to have to do something like:

for x in table1
f1.write(table1[x])

or something along those lines.

I tried this:

for x in table1:
f1.write(table1[x])

but this doesn't work. I get this error:

Traceback (innermost last):
File "program.py", line 67, in ?
for x in table1:
TypeError: loop over non-sequence

Do you have another idea or do you know what in this loop deosn't work?
 
If your table is a dictionary (hash table), try the following:

for key, value in table.items():
f1.write(str(key) + ':' + str(value))

if this snippet doesn't work for you, please tell us more about your table
 
Thanks, this works. Another question. How can i write a newline at the end of the line to the file?
I tried it like this:

for key, value in table.items():
f1.write(str(key) + ':' + str(value))
f1.write('\n')

But this doesn't work. What is wrong at my version?
 
Thanks, it already works. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top