怎么if __name__ == "__main__":办?
# Threading example
import time, thread
def myfunction(string, sleeptime, lock, *args):
while True:
lock.acquire()
time.sleep(sleeptime)
lock.release()
time.sleep(sleeptime)
if __name__ == "__main__":
lock = thread.allocate_lock()
thread.start_new_thread(myfunction, ("Thread #: 1", 2, lock))
thread.start_new_thread(myfunction, ("Thread #: 2", 2, lock))
Run Code Online (Sandbox Code Playgroud) def main():
names = []
for line in ins:
number_strings = line.split() # Split the line on runs of whitespace
data.append(numbers_strings) # Add the "row" to your list.
print(data)
Run Code Online (Sandbox Code Playgroud)
我尝试使用此代码打印看起来像这样的文本文件
name num1 num2 C/N
Run Code Online (Sandbox Code Playgroud)
我试图打印这个但是当我运行命令"python3 file.py"时没有输出.而不是打印我正在放入的文件的内容
当我运行程序并输入性别作为其他任何东西但不是男性或女性时,该程序不能按预期工作.我已经挣扎了一天,无法弄清楚.另外如何在调用之后放置函数并仍然使程序运行?我读了一个main函数,但无法弄清楚如何用它修改代码.
from sys import exit
birthdays = {'Alice': 'April 1', 'Bob': 'Dec 12', 'Carol': 'Mar 4'}
def dateOfBirth():
bday = raw_input("> ")
birthdays[name] = bday
print "Database records updated."
print "The number of records is now " + str(len(birthdays)) + "."
print birthday`enter code here`s
exit(0)
while True:
print "Enter a name: (blank to quit)"
name = raw_input("> ")
if name == '':
exit(0)
if name in birthdays:
print birthdays[name] + " is the birthday of " + name + …Run Code Online (Sandbox Code Playgroud)