gruiick / pySpaceTrader

my python3 remake of SpaceTrader
BSD 2-Clause "Simplified" License
1 stars 0 forks source link

python (shelve module) minimal version? #11

Closed ltaulell closed 2 months ago

ltaulell commented 2 months ago

changes between python3.7 and python3.9/3.11 make load/save processing variable depending on python/shelve versions.

python3.7 (main.py): def load_game(): """ load saved game """ global univers, planetes, captain, fname try: fname = sg.popup_get_file('Saved game to open', default_extension='.db', file_types=(('saved game(s)', '.db'), ('all files', '.*')), ).replace('.db', '') except AttributeError: pass

if fname == "":
    print("empty filename!")
    load_game()
    """ ... """

python3.9/3.11 (main.py): def load_game(): """ load saved game """ global univers, planetes, captain, fname try: fname = sg.popup_get_file('Saved game to open', default_extension='.db', file_types=(('saved game(s)', '.db'), ('all files', '.*')), ) # .replace('.db', '') except AttributeError: pass

if fname == "":
    print("empty filename!")
    load_game()

if ".db" not in fname:
    fname = fname + ".db"
    """ ... """

same for save()/save_as(). Deal with it or impose a minimal version for python? (as 3.7 is already deprecated)

ltaulell commented 2 months ago

Just for the brain: deal with it.

import platform print(platform.python_version())

gruiick commented 2 months ago

How dumb am I?

"if int(python_version())", please.

gruiick commented 2 months ago

less dumb, using:

from platform import python_version
from packaging.version import Version

then:

if Version(python_version()) >= Version('3.9'):