2014-03-29 53 views

回答

0

從我與Python我不相信這樣的經歷。你可以將你的列表的內容寫入文件,然後一旦你重新填充你的列表,你所附加的任何內容都將保留在那裏。其寫入到文件的一個例子是:

#!/usr/bin/python 

# Open a file in write mode 
fo = open("foo.txt", "rw+") 
print "Name of the file: ", fo.name 

# Assuming file has following 5 lines 
# This is 1st line 
# This is 2nd line 
# This is 3rd line 
# This is 4th line 
# This is 5th line 

str = "This is 6th line" 
# Write a line at the end of the file. 
fo.seek(0, 2) 
line = fo.write(str) 

# Now read complete file from beginning. 
fo.seek(0,0) 
for index in range(6): 
    line = fo.next() 
    print "Line No %d - %s" % (index, line) 

# Close opend file 
fo.close() 

這個例子是從Python文檔在http://www.tutorialspoint.com/python/file_write.htm

相關問題