Answer to Question #231087 in Python for ash

Question #231087

# 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

1
Expert's answer
2021-08-30T07:30:34-0400
def readLevelsFromFile(file):
  try:
      levelslist = []
      f = open(file, 'r')
      lines = f.readlines()
      for i in lines:
        if i[-1] == '/n' and i[-2] == '/n':
          i.replace(i[-1],'')
          i.replace(i[-2],'')
        levelslist.append(i)
      f.close


  except OSError as e:
     return e.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
New on Blog
APPROVED BY CLIENTS