[英]Calling the same function multiple times with different arguments?
it's me again.又是我。
Now that my function is working properly I would like to call it multiple times while changing the arguments each time I call it.现在我的函数工作正常,我想多次调用它,同时每次调用它时更改参数。
This is my function这是我的功能
def my_function(output_name, input_dir):
with open(output_name, "w+") as f:
os.chdir(input_dir)
for fichiers in glob.glob("*"):
today = datetime.datetime.today()
modified_date = datetime.datetime.fromtimestamp(os.path.getmtime(fichiers))
duration = today - modified_date
if duration.days < 5:
f.write(f"{fichiers} = {duration} \n")
EDIT1: So after messing around with the solution given by Joao Santos, I've been able to get the input for the first item in the dictionary but thats it the second and third one don't seem to work at all. EDIT1:所以在搞乱了 Joao Santos 给出的解决方案之后,我已经能够获得字典中第一项的输入,但是第二和第三项似乎根本不起作用。 If put separately they work fine, i'm a little confused...
如果分开放置它们工作正常,我有点困惑......
How can I achieve this result ?我怎样才能达到这个结果?
Thank you very much !!非常感谢 !!
I don't know if I understood what you meant, but here goes ...我不知道我是否理解你的意思,但这里是......
Add your arguments to a dictionary like :将您的参数添加到字典中,例如:
arguments = {"output1.txt": "//10.2.30.61/c$\test/test\test", "output2.txt" : "//10.2.30.61/c$\test1/test1\test1", "output3.txt" : "//10.2.30.61/c$\test1/test1\test1"}
Then, simply iterate over that and call ur function:然后,简单地迭代它并调用 ur 函数:
for output_name, input_dir in arguments.items():
my_function(output_name, input_dir)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.