How can I create files , read and write files in Python? -
all tutorials can find follow same format isn't working.i don't error message don't normal output. appears file description @ memory location.
# file_test
ftpr= open("file","w") ftpr.write("this sample line/n") a=open("file","r") print #this result <open file 'file', mode 'r' @ 0x00000000029dddb0> >>>
do want read contents of file? try print a.readlines()
.
ie:
with open('file', 'w') f: f.write("hello, world!\ngoodbye, world!\n") open('file', 'r') f: print f.readlines() # ["hello, world!\n", "goodbye, world!\n"]
fyi, with blocks, if you're unfamiliar them, ensure open()
-d files close()
-d.
Comments
Post a Comment