我如何开始我的演讲?

您好,我是新手,一般的Python和编程,我想知道如何
使用"Call"命令
我的代码是这样的

选择 | 换行 | 行号
  1. def con():
  2.     input = raw_input('Press y to start:')
  3.     if input == "y" or "Y":
  4.         return(menu_1())
  5.     else:
  6.         print 'OMG YA NOOB I SAID PRESS y!'
  7.         return    
  8. def menu_1():
  9.     print '(1) Write noob to start "Stupid Program"' 
  10.     print '(2) Write calc to start "Talking"'
  11.     print '(3) This section is under construction'
  12.     print '(4) This section is under construction'
  13.     input2 = raw_input('Insert text here \n'*1)

现在,当我激活它的.py文件时,如何让它工作?
它就是启动不起来,我想我需要让它自动激活,而不需要在开始时编写con(),我该怎么做呢?
我需要使用__init__或_call__吗?我不知道如何使用它,是的,我在网上搜索过,但它对Newby不是很友好!
请帮帮我!

# 回答1


您可以使用以下命令行运行您的文件

选择 | 换行 | 行号
  1. python filename.py args

,其中,filename.py是包含代码的文件的名称,args是该文件的任何命令行参数.至于如何调用函数,只需使用Function(PARAMS).
例如:

选择 | 换行 | 行号
  1. def hello():
  2.    print "Hello, world!"
  3.  
  4. def sum(x, y):
  5.    return x+y
  6.  
  7. if '__name__' == '__main__': not strictly necessary, but a useful trick to know
  8.     hello() #calls hello
  9.     z = sum(3, 4) #returns 3+4=7
  10.     print z
  11.  
# 回答2


谢谢,这很有帮助,另一个问题是,我如何在这方面使用py2exe?
我需要做什么才能让它自动启动,这样我才能让它执行?
(只是好奇)
# 回答3


附注:
我被支持在cmd中写"Start Taco.py Base()"?
(在我"cd"到文件所在的文件夹之后)
我很沮丧...
以获取代码

选择 | 换行 | 行号
  1. def Base():
  2.     input=raw_input('Enter X here to start playing X-')
  3.     if input=="X":
  4.         return(Game())
  5.     elif input=="q":
  6.              exit(0) ...
# 回答4


不是,该命令是'python Taco.py',因为您的文件名是Taco.py.要让它从运行该代码开始,请删除缩进(并在执行该函数时将其去掉).
对不起,我对py2exe一无所知.我坚持使用Linux来完成我的Python工作.

标签: python

添加新评论