Function inside function?
Is there any way to add a function inside a function? I am currently
making a game, and it would make my script much more organized!
An example of my current script:
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
#Nothing here yet
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':
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()
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 '01.01.2013 00:00 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()
LVL1_TUTORIAL_07__C_USERS_MRX()
Then I got this error message:
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()
I am not quite sure what's wrong. I really hoped this worked, as it would
make the work much easier for me. For all I know, it could just be a small
typo that caused the problem.
I really hope someone here can see the error!
Thanks!
No comments:
Post a Comment