You are a top guy! Thanks for the tips and help.
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Latest posts made by Ald
-
RE: Help with opening files in phythonista
-
Help with opening files in phythonista
Hi folks
I am new to phythonista, iPad and Python. I need the following code to open up a text file in the script folder of pythonista :
scores = {}
result_f = open("results.txt")
for line in result_f:
(name, score) = line.split()
scores[score] = name
result_f.close()
print("the top scores were:")
for each_score in scores.keys():
print('surfer' + scores[each_score]+'scored'+each_score)The contents of results.txt is:
Johnny 8.65
Juan 9.12
Joseph 8.45
Stacey 7.81
Aideen 8.05
Zack 7.21
Aaron 8.31 -
RE: Help with opening files in phythonista
Ok it works now, it turns out my results.txt file had some blank lines at the end that obviously caused the trouble
-
RE: Help with opening files in phythonista
Wow thanks for that. I will learn a lot from the second method. I am going through a book called head first programming and just doing all the tutorials.
Ok it also seems as if the code I insert must be inserted within [] as pointed out to me kindly above.
-
RE: Help with opening files in phythonista
Let's try
[scores = {} result_f = open("results.txt") for line in result_f: (name, score) = line.split() scores[score] = name result_f.close() print("the top scores were:") for each_score in scores.keys(): print('surfer' + scores[each_score]+'scored'+each_score)]
scores = {}
result_f = open("results.txt")
for line in result_f:
(name, score) = line.split()
scores[score] = name
result_f.close()
print("the top scores were:")
for each_score in scores.keys():
print('surfer' + scores[each_score]+'scored'+each_score) -
RE: Help with opening files in phythonista
scores = {}
result_f = open("results.txt")
for line in result_f:
(name, score) = line.split()
scores[score] = name
result_f.close()
print("the top scores were:")
for each_score in scores.keys():
print('surfer' + scores[each_score]+'scored'+each_score)
-
RE: Help with opening files in phythonista
' ' 'python
scores = {}
result_f = open("results.txt")
for line in result_f:
(name, score) = line.split()
scores[score] = name
result_f.close()
print("the top scores were:")
for each_score in scores.keys():
print('surfer' + scores[each_score]+'scored'+each_score)
' ' '