小编A S*_*anz的帖子

在Python3中使用Script = argv

我正在玩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.")
Run Code Online (Sandbox Code Playgroud)

如何打印我正在运行的文件?

python sys argv python-3.x

2
推荐指数
1
解决办法
85
查看次数

标签 统计

argv ×1

python ×1

python-3.x ×1

sys ×1