Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text file storage and retrival working, sorting values, erasing, and rewriting to text file not working #1

Open
Skparab1 opened this issue Apr 24, 2021 · 3 comments

Comments

@Skparab1
Copy link
Owner

No description provided.

@Skparab1
Copy link
Owner Author

Right now im using standard text file storage and max(), min() and sorted() for sorting and ordering.

@Skparab1
Copy link
Owner Author

Try using shelve instead.

Import shelve

#to write
writer = shelve.open('textfile.txt')
writer['textfile'] = 'textintextfile'
writer.close()

#to read
reader = shelve.open('textfile.txt')
text = reader['textfile']
reader.close()

Also shelve may be favorable since user's can't access the text file easily. Neither mac not windows have a built in reader for the type of text file it creates.

@Skparab1
Copy link
Owner Author

Skparab1 commented May 3, 2021

you can also use and call the following functions
def shelvewrite(textfilename,towrite): #write to text file
textfilenametxt = textfilename + '.txt'
writer = shelve.open(str(textfilenametxt))
writer[str(textfilename)] = towrite
writer.close()
def shelveread(textfilename): # read form text file
textfilenametxt = textfilename + '.txt'
reader = shelve.open(str(textfilenametxt))
text = reader[str(textfilename)]
reader.close()
return text
def shelveappend(textfilename, toappend): #append to text file
textfilenametxt = textfilename + '.txt'
read = shelveread(textfilename)
toappend = (read, toappend)
shelvewrite(textfilename, toappend)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant