Answer to Question #231957 in Python for hay

Question #231957

# Method: Load levelsList using the data in levelsFile 

def readLevelsFromFile(self):

try:

# Set levelsList to an empty list 

...

# Open the file

...

# Use a loop to read through the file line by line

...

# If the last two characters in the line is "\n", remove them

...

...

# Append the line to levelsList

...

# Close the file

 ...

except:

return

#replace all ellipsis with applicable code

1
Expert's answer
2021-09-01T23:57:05-0400
def readLevelsFromFile(file):
  try:
      levelslist = []
      f = open(file, 'r')
      linebyLine = f.readlines()
      for i in linebyLine:
        if i[-1] == '/n' and i[-2] == '/n':
          i.replace(i[-1],'')
          i.replace(i[-2],'')
        levelslist.append(i)
      f.close


  except OSError as ex:
     return ex.errno

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS