Py学习  »  Python

有没有一种方法可以按顺序执行python代码,并使用不确定的变量量?

Alexis • 3 年前 • 1173 次点击  

我已经用一个预定义的变量编写了一个运行的python代码。

variable = "first_variable"

#code

with open(f"{variable}.txt", "w") as w_file:
    w_file.write("Something")

我现在想 适应 该代码接受任意数量的变量作为参数,并逐个处理它们。 在shell中,我想这样称呼它:

python3 code.py first_variable second_variable third_variable n_variable

你知道我该怎么做吗?我尝试使用输入、创建函数或使用while循环,但失败了。。。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129346
 
1173 次点击  
文章 [ 2 ]  |  最新文章 3 年前