如何表明Python中是否存在类?

时间:2017-06-05 00:08:38

标签: python class variables pickle nameerror

所以,我正在尝试为我的textgame制作多个savefiles。我想显示文件是否没有该文件的PlayerIG类。

示例(很可能不起作用):

def TitleScreen():
    global PlayerIG
    blankHuge()
    anar()
    print('The Game of Hierarchy and Anarchy\nBy S.G. Harmonia\nText Edition\n▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬\nPress Enter\nTo exit, type "exit".')
    StartGame = input()
    if StartGame == '':
        print('► Which file?\nTo access a file, type its number.\nTo go back, type "back".')

        Attributes = {0:PlayerIG.name,1:PlayerIG.status,2:PlayerIG.month} # raises NameError 

        print('► File 1\n',Attributes)
        if os.path.exists('TGHA1.pickle') == False:
            Attributes = 'Empty'
        blankSmall()

        print('► File 2\n',Attributes)
        if os.path.exists('TGHA2.pickle') == False:
            Attributes = 'Empty'
        blankSmall()

        print('► File 3\n',Attributes)
        if os.path.exists('TGHA3.pickle') == False:
            Attributes = 'Empty'
        blankSmall()

        print('► File 4\n',Attributes)
        if os.path.exists('TGHA4.pickle') == False:
            Attributes = 'Empty'
        blankSmall()
# more stuff...

完整错误:

Traceback (most recent call last):
  File "C:\Users\Sinnoh\AppData\Local\Programs\Python\Python36-
32\TheGameOfHierarchyAndAnarchy.py", line 786, in <module>
    TitleScreen()
  File "C:\Users\Sinnoh\AppData\Local\Programs\Python\Python36-
32\TheGameOfHierarchyAndAnarchy.py", line 141, in TitleScreen
    Attributes = {0:PlayerIG.name,1:PlayerIG.status,2:PlayerIG.month}
NameError: name 'PlayerIG' is not defined

如果文件为空,我有什么方法可以显示吗?

0 个答案:

没有答案