Answer to Question #208585 in Python for Andu

Question #208585

How to explain this code?


def readAccounts(accounts,fileName):

  pathlibPath = pathlib.Path(fileName)

  if pathlibPath.exists():

    with open(fileName,'r+') as file:

      accountData = json.load(file)

      for account in accountData:

        accountFromFile=Account()

        accountFromFile.setAccountInformation(account['username'],account['password'],account['name'],account['suname'],account['birthDate'],account['listFriends'])

        accounts.append(accountFromFile)

         

        

     

   

main()


1
Expert's answer
2021-06-20T08:12:17-0400
#create a function readAccounts with two arguments, accounts and fileName
def readAccounts(accounts,fileName):
#declare a variable pathlibPath to hold the path of the file
  pathlibPath = pathlib.Path(fileName)
#check if the file exists
  if pathlibPath.exists():
    #open the file
    with open(fileName,'r+') as file:


    #load the content of the file to a variable accountData
      accountData = json.load(file)




      for account in accountData:




        accountFromFile=Account()


        #set information 
        accountFromFile.setAccountInformation(account['username'],account['password'],account['name'],account['suname'],account['birthDate'],account['listFriends'])


        #append the information accountFromFile to accounts
        accounts.append(accountFromFile)




         




        




     




   


#call the main function
main()

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