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

Using Shelve to save didn't work for me #8

Open
Shoes01 opened this issue Aug 10, 2018 · 4 comments
Open

Using Shelve to save didn't work for me #8

Shoes01 opened this issue Aug 10, 2018 · 4 comments

Comments

@Shoes01
Copy link

Shoes01 commented Aug 10, 2018

As the title says, the Shelve code didn't work for me. It created files named "savedgame.dat" and appended the extension ".dat" to the end, so I had "savedgame.dat.dat". This wouldn't load.

I was able to fix this by following the code found here and creating my own "savegames" folder.

@Zireael07
Copy link

This issue has been cropping up for some people and seems to depend on the Python version used.

@Shoes01
Copy link
Author

Shoes01 commented Aug 10, 2018

I'm using Python 3.7 on VS Code, if that helps.

@Wolfenswan
Copy link

The problem occurs if shelve defaults to the dumb-dbm, instead of dmb.gnu or dmb.ndbm. dmb.dumb automatically creates .dat & .dir endings, which the other two don't. Afaik dumb is the only available dbm on windows by default, so the issue might be os-related if gnu or ndbm are available on unix-systems from the get-go.

@mattbenson17
Copy link

For me (I'm using Python 3.6 on a Mac) it seems that the shelve.open command is automatically adding a .db extension when writing the savegame file, which lead to the aforementioned problem. os.path.isfile() simply looks for the text contained in the specified filename. My solution was quite simple. Keep the extension .db in line 16 if not os.path.isfile('savegame.db'): but in both def save_game and def load_game supply shelve.open() with only 'savegame' as the filename, without the extension.

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

4 participants