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

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -