関数内に関数を追加する方法はありますか? 私は現在ゲームを作成しています。これにより、スクリプトがより整理されたものになります。
私の現在のスクリプトの例:
def LVL1_TUTORIAL_07__C_USERS_MRX():
    print
    choice = raw_input('C:\Users\Mr. X>')
    if choice.lower() == 'help':
        print
        print ' dir - Allows you to see the available files and directories in the current directory.'
        print ' cd - (Change Directory) is a command used to switch directories in MS-DOS and the Windows command line.'
        print ' search - Searching'
        print ' connect - connect + name of the server you want to connect'
        LVL1_TUTORIAL_07__C_USERS_MRX()
    if choice.lower() == 'cls':
        os.system('cls')
        LVL1_TUTORIAL_07__C_USERS_MRX()
    if choice.lower() == 'cd':
        print 'C:\Users\Mr. X'
        LVL1_TUTORIAL_07__C_USERS_MRX()
    if choice.lower() == 'cd.':
        print
        LVL1_TUTORIAL_07__C_USERS_MRX()
    if choice.lower() == 'cd..':
        print
    if choice.lower() == 'cd contacts':
        LVL1_TUTORIAL_07__C_USERS_MRX_CONTACTS()
    if choice.lower() == 'cd desktop':
        LVL1_TUTORIAL_07__C_USERS_MRX_DESKTOP()
    if choice.lower() == 'cd documents':
        LVL1_TUTORIAL_07__C_USERS_MRX_DOCUMENTS()
    if choice.lower() == 'cd downloads':
        LVL1_TUTORIAL_07__C_USERS_MRX_DOWNLOADS()
    if choice.lower() == 'cd favorites':
        LVL1_TUTORIAL_07__C_USERS_MRX_FAVORITES()
    if choice.lower() == 'cd links':
        LVL1_TUTORIAL_07__C_USERS_MRX_LINKS()
    if choice.lower() == 'cd music':
        LVL1_TUTORIAL_07__C_USERS_MRX_MUSIC()
    if choice.lower() == 'cd pictures':
        LVL1_TUTORIAL_07__C_USERS_MRX_PICTURES()
    if choice.lower() == 'cd videos':
        print
        print 'test'
        time.sleep(2)
        LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS()
        def LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS():
            print
            choice = raw_input('C:\Users\Mr. X\Videos>')
            if choice.lower() == 'help':
                print 'help'
            if choice.lower() == 'cls':
                os.system('cls')
                LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS()
            if choice.lower() == 'cd folder 1':
                LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS_FOLDER1()
            def LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS_FOLDER1():
                print
                choice = raw_input('C:\Users\Mr. X\Videos>')
                if choice.lower() == 'help':
                    print 'help'
                if choice.lower() == 'cd..':
                    LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS()
                if choice.lower() == 'cd..':
                    LVL1_TUTORIAL_07__C_USERS_MRX()
            return LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS_FOLDER1()
        return LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS()    
    if choice.lower() == 'dir':
        print
        print ' Volume in drive C has no label.'
        print ' Volume Serial Number is 57GE-4AFB'
        print
        print ' Directory of C:\Users\Mr. X'
        print
        print '01.01.2013  00:00    <DIR>          .'
        print '01.01.2013  00:00    <DIR>          ..'
        print '01.01.2013  00:00    <DIR>          Contacts'
        print '01.01.2013  00:00    <DIR>          Desktop'
        print '01.01.2013  00:00    <DIR>          Documents'
        print '01.01.2013  00:00    <DIR>          Downloads'
        print '01.01.2013  00:00    <DIR>          Favorites'
        print '01.01.2013  00:00    <DIR>          Links'
        print '01.01.2013  00:00    <DIR>          Music'
        print '01.01.2013  00:00    <DIR>          Pictures'
        print '28.07.2013  15:57                 0 telnet'
        print '01.01.2013  00:00    <DIR>          Videos'
        print '               1 File(s)              0 bytes'
        print '              11 Dir(s)  53 687 091 200 bytes free'
        print
        LVL1_TUTORIAL_07__C_USERS_MRX()
    else:
        print
        print 'wrong'
        time.sleep(2)
    return LVL1_TUTORIAL_07__C_USERS_MRX()
LVL1_TUTORIAL_07__C_USERS_MRX()
次に、次のエラー メッセージが表示されました。
UnboundLocalError: local variable 'LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS' referenced before assignment
File "C:\Users\Stig Arne\Desktop\HACKER\HACKER.py", line 3715, in <module>
  LVL1_TUTORIAL_07__C_USERS_MRX()
File "C:\Users\Stig Arne\Desktop\HACKER\HACKER.py", line 3656, in LVL1_TUTORIAL_07__C_USERS_MRX
  LVL1_TUTORIAL_07__C_USERS_MRX_VIDEOS()  
何が悪いのかよくわかりません。作業がずっと簡単になるので、これがうまくいくことを本当に望んでいました. 私が知っている限りでは、問題を引き起こしたのは小さなタイプミスである可能性があります.
ここの誰かがエラーを見ることができることを本当に願っています!
ありがとう!