In: Computer Science
this is my code in python I am trying to open a file and then print the contents on my console but when i run it nothing prints in the console
def file_to_dictionary(rosterFile):
myDictionary={}
with open(rosterFile,'r') as f:
for line in f:
myDictionary.append(line.strip())
print(myDictionary)
return myDictionary
file_to_dictionary((f"../data/Roster.txt"))
code:
output :
file :
raw_code :
def file_to_dictionary(rosterFile):
myDictionary = {} #empty dictionary
with open(rosterFile,'r') as f:
for line in f:
(key,val) = line.split() #splitting line to key value pair
myDictionary[key] = val #appending to dictionary
print(myDictionary) #printing dictioanry
#calling function
file_to_dictionary('hello.txt')
***do comment for queries and rate me up****