0

I would like to save strings into text files while ordering them, I need to do it by score (from 1-10) and these can be inputed in any random order. Is there a way to seek out strings in text files and then use the .seek() function there?

I have it to save in the text file as "(Name) has a score of (Score)" I just use f.write to input this into a text file

f = open("Saves.txt", "r")
Score = str(Score)
O = (f.read())
f.close()
f = open("Saves.txt","w")
f.seek(0)
Saving = (O) + "  " + (Name) + " " +(Last_Name) + " has a score of " + (Score) + "\n"
f.write((Saving))
f.close()
Alastair
  • 1
  • 1
  • write some code and paste here first –  Nov 23 '14 at 01:29
  • What is wrong with the code you wrote? – wwii Nov 23 '14 at 01:50
  • Needs more detail. What do the text files look like. Why do you want to use the seek function (are they very large?). Why not read and parse the strings from the text files, score them, sort them and then write the list to the file. (etc etc) – demented hedgehog Nov 23 '14 at 01:58
  • There is nothing wrong with my code, I would just like to add more functionality – Alastair Nov 23 '14 at 13:14

1 Answers1

0

I'd try a memory mapped file. It gives you string and file semantics. For example, you can use the re library with mmap.

generalpiston
  • 911
  • 7
  • 11