我最近开始学习Python,就像5天前一样,我的问题是,当我试图从vps运行脚本时,什么都没有发生。脚本位于/root目录中,我尝试chmod它。该文件调用" alfay .py",是的,它包含了一个shebang行(无论您如何称呼它)
I tried to
chmod +x alfa.py
仍然没有输出!这是剧本(是的…很奇怪. .我只是无聊)
#! /usr/bin/python
import time
import urllib2
import socket
import sys
import random
import os
from time import sleep
from random import randint
def cls():
os.system("clear")
def choices():
print "1.IDgenn"
print "2.socksn"
print "3.XatBot (Not working)n"
print "4.Calculator (not working)n"
print "5.XatRaid(not working) n"
print "6.Exitn"
choicechoice = int(raw_input("What do you want(The number)n"))
if choicechoice = 6:
exit()
elif choicechoice = 5:
print "Not working yet...n"
cls()
choices()
elif choicechoice = 4:
print "Not working yet..n"
cls()
choices()
elif choicechoice = 3:
print "Will be done soon...n"
cls()
choiches()
elif choicechoice = 1:
cls()
idgen()
elif choicechoice = 2:
print "Almost donen"
cls()
time.sleep(2)
choices()
def main():
print "Welcome to the main menu!n"
time.sleep(3)
print "Before we start the program, we will ask you a couple of questionsn"
time.sleep(3)
cls()
name = raw_input("What is your name?n")
time.sleep(2)
age = int(raw_input("How old are you?n")
time.sleep(2)
country = raw_input("In what country do you live?n")
time.sleep(2)
print "Thanks for the info!n"
time.sleep(2)
cls()
valid = raw_input("Is this info valid? Answer with y or nn")
if valid == "y"
print "Thanks for submitting your real info!n"
cls()
print "Soo, your real name is {} and you live in {} and your real age is {} ? Nice!n".format(name, country, age)
choices()
else:
exit()
def idgen():
id = urllib2.urlopen("http://xat.com/web_gear/chat/auser3.php").read()
if "&UserId" in id:
file = open("idss.txt","w")
file.write(id+"n")
file.close()
print "ID generated!n"
time.sleep(2)
else:
print "Not an id... um??n"
time.sleep(2)
choices()
main()
当我做python alfa.py
时什么都没有发生!
你的代码中有多个语法错误:
用==
检验是否相等。
所有if语句必须以:
choiches()
与choices()
不相同
所有打开(
必须有关闭)
int(raw_input("How old are you?n")
<-缺少)
这是你的代码与正确的语法,去它所在的目录,并运行它与python alfa.py
:
import time
import urllib2
import socket
import sys
import random
import os
from time import sleep
from random import randint
def cls():
os.system("clear")
def choices():
print "1.IDgenn"
print "2.socksn"
print "3.XatBot (Not working)n"
print "4.Calculator (not working)n"
print "5.XatRaid(not working) n"
print "6.Exitn"
choicechoice = int(raw_input("What do you want(The number)n"))
if choicechoice == 6: # use `==` not =
exit()
elif choicechoice == 5:
print "Not working yet...n"
cls()
choices()
elif choicechoice == 4:
print "Not working yet..n"
cls()
choices()
elif choicechoice == 3:
print "Will be done soon...n"
cls()
choices() # choices not choiches()
elif choicechoice == 1:
cls()
idgen()
elif choicechoice == 2:
print "Almost donen"
cls()
time.sleep(2)
choices()
def main():
print "Welcome to the main menu!n"
time.sleep(3)
print "Before we start the program, we will ask you a couple of questionsn"
time.sleep(3)
cls()
name = raw_input("What is your name?n")
time.sleep(2)
age = int(raw_input("How old are you?n")) # missing a closing paren
time.sleep(2)
country = raw_input("In what country do you live?n")
time.sleep(2)
print ("Thanks for the info!n")
time.sleep(2)
cls()
valid = raw_input("Is this info valid? Answer with y or nn")
if valid == "y":
print "Thanks for submitting your real info!n"
cls()
print "Soo, your real name is {} and you live in {} and your real age is {} ? Nice!n".format(name, country, age)
choices()
else:
exit()
def idgen():
id = urllib2.urlopen("http://xat.com/web_gear/chat/auser3.php").read()
if "&UserId" in id:
file = open("idss.txt", "w")
file.write(id + "n")
file.close()
print "ID generated!n"
time.sleep(2)
else:
print "Not an id... um??n"
time.sleep(2)
choices()
main()