0

So when I add a string to a list via .append and then close that window of the program, is there a way for it to actually alter the code? (Python noob, so sorry if I'm being dumb)

Many thanks

1 Answers1

0

From my experience with python I don't believe so. You could write the contents of your list to file, then whatever you appended would still be there once you repopulate your list. An example of writing to a file would be:

#!/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()

This example is from the Python docs at http://www.tutorialspoint.com/python/file_write.htm

nagnagnag1
  • 28
  • 3