您好,我是新手,一般的Python和编程,我想知道如何
使用"Call"命令
我的代码是这样的
- def con():
- input = raw_input('Press y to start:')
- if input == "y" or "Y":
- return(menu_1())
- else:
- print 'OMG YA NOOB I SAID PRESS y!'
- return
- def menu_1():
- print '(1) Write noob to start "Stupid Program"'
- print '(2) Write calc to start "Talking"'
- print '(3) This section is under construction'
- print '(4) This section is under construction'
- input2 = raw_input('Insert text here \n'*1)
现在,当我激活它的.py文件时,如何让它工作?
它就是启动不起来,我想我需要让它自动激活,而不需要在开始时编写con(),我该怎么做呢?
我需要使用__init__或_call__吗?我不知道如何使用它,是的,我在网上搜索过,但它对Newby不是很友好!
请帮帮我!
# 回答1
您可以使用以下命令行运行您的文件
,其中,filename.py是包含代码的文件的名称,args是该文件的任何命令行参数.至于如何调用函数,只需使用Function(PARAMS).
例如:
- def hello():
- print "Hello, world!"
-
- def sum(x, y):
- return x+y
-
- if '__name__' == '__main__': not strictly necessary, but a useful trick to know
- hello() #calls hello
- z = sum(3, 4) #returns 3+4=7
- print z
-
# 回答2
谢谢,这很有帮助,另一个问题是,我如何在这方面使用py2exe?
我需要做什么才能让它自动启动,这样我才能让它执行?
(只是好奇)
# 回答3
附注:
我被支持在cmd中写"Start Taco.py Base()"?
(在我"cd"到文件所在的文件夹之后)
我很沮丧...
以获取代码
- def Base():
- input=raw_input('Enter X here to start playing X-')
- if input=="X":
- return(Game())
- elif input=="q":
- exit(0) ...
# 回答4
不是,该命令是'python Taco.py',因为您的文件名是Taco.py.要让它从运行该代码开始,请删除缩进(并在执行该函数时将其去掉).
对不起,我对py2exe一无所知.我坚持使用Linux来完成我的Python工作.