Byron
2004-07-21 15:49:28 UTC
Hi Fred,
It looks like they have answered your questions. To reiterate in a
simple form, to open a file for reading, it is best to use something
like the following:
f = open("c:/test.txt", "r")
textlines = f.readlines() # Reads all lines into a list (array).
for line in textlines: # Prints each line that is read from the
text file.
print line
---
If you want to append (add additional information) to a text file, use
the following:
f = open("c:/test.txt", "a")
f.write("This is an appended line.\n")
f.close()
Hope this helps,
Byron
------------------------
It looks like they have answered your questions. To reiterate in a
simple form, to open a file for reading, it is best to use something
like the following:
f = open("c:/test.txt", "r")
textlines = f.readlines() # Reads all lines into a list (array).
for line in textlines: # Prints each line that is read from the
text file.
print line
---
If you want to append (add additional information) to a text file, use
the following:
f = open("c:/test.txt", "a")
f.write("This is an appended line.\n")
f.close()
Hope this helps,
Byron
------------------------
Hi,
I've searched the web and the archives of this ng for half an
hour already, and I'm still stuck.
1. On a W2K Pro host, installed the latest ActivePython MSI. Rebooted.
file=concat('test.txt','w')
file.close()
"NameError: name 'concat' is not defined"
- from operator import * -> "AttributeError: 'str' object has no
attribute 'close'"
- import operator -> "NameError: name 'concat' is not defined"
- file=concat('./test.txt','w')
- file=concat('.\test.txt','w')
... all to no avail. Obviously, I'm either missing a package or I need
to tweak something. Any idea?
Thank you
Fred.
I've searched the web and the archives of this ng for half an
hour already, and I'm still stuck.
1. On a W2K Pro host, installed the latest ActivePython MSI. Rebooted.
file=concat('test.txt','w')
file.close()
"NameError: name 'concat' is not defined"
- from operator import * -> "AttributeError: 'str' object has no
attribute 'close'"
- import operator -> "NameError: name 'concat' is not defined"
- file=concat('./test.txt','w')
- file=concat('.\test.txt','w')
... all to no avail. Obviously, I'm either missing a package or I need
to tweak something. Any idea?
Thank you
Fred.