# Method: Write levelsList to levelsFile (override the existing file)
 def writeLevelsToFile(self):
 # Open the file in a way that will override the existing file (if it already exists)
 ...
 # Use a loop to iterate over levelsList item by item
 ...
# Convert everything in the item to a string and then add \n to it - before writing it to the file
...
 # Close the file
 ...
#Replace all ellipsis with applicable code
# Method: Write levelsList to levelsFile (override the existing file)
def writeLevelsToFile(self):
 # Open the file in a way that will override the existing file (if it already exists)
  with open('myfile.txt', "r") as myfile:
    data = myfilef.read()
 # Use a loop to iterate over levelsList item by item
  for each in myfile:
    print (each)
Â
# Convert everything in the item to a string and then add \n to it - before writing it to the file
  file = open('myfile.txt','w')
  for each in myfile:
    print (str(each),"\n")
    file.write(each)
 # Close the file
  file.Close()
Comments
Leave a comment