【发布时间】:2018-06-26 18:20:55
【问题描述】:
我正在使用 Python3,每次运行下面的代码 Python3 ex14.py 并打印 (f"Hi {user_name}, I'm the {script} script.") 我得到 {user_name} 正确,但 {script} 显示我正在运行的文件加上变量{user_name}
from sys import argv
script = argv
prompt = '> '
# If I use input for the user_name, when running the var script it will show the file script plus user_name
print("Hello Master. Please tell me your name: ")
user_name = input(prompt)
print(f"Hi {user_name}, I'm the {script} script.")
如何只打印我正在运行的文件?
【问题讨论】:
-
使用
script = argv[0] -
包括您调用脚本的准确程度。您描述错误的方式我知道您是从命令行和
input调用中获取用户名的。为什么两者都有?
标签: python python-3.x argv sys