简体   繁体   English

动态/可变文件路径Python

[英]Dyanamic/ Variable Filepath Python

I'm looking for a method of setting a variable in a path but I can't seem to find some way of doing this: 我正在寻找一种在路径中设置变量的方法,但似乎找不到某种方法来做到这一点:

object = apps.[variable].main.run()

where variable is some string. 其中variable是一些字符串。 Apps and Variable are two directories and main is a python script. Apps和Variable是两个目录,main是python脚本。

(For import statements I was able to use __import__(path) ) (对于导入语句,我能够使用__import__(path)

使用getattr

getattr(apps, variable).main.run()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM