英文:
Define main file without defining the parameters in the main file
问题
I have two .py files, one is Setting.py and one is main.py.
In the Setting.py file I have the following code:
a = 2
def foo(a):
return a + 2
In the main file I have this:
import Setting
if name == 'main':
X = foo(a)
So, when I run the main file, I get the error that 'a' is not defined. So, I don't want to define 'a' again in the main file. Could you please help me with this? This is a minimal code of my main code. I have multiple .py files and parameters. Thanks
英文:
I have two .py files, one is Setting.py and one is main.py.
In the Setting.py file I have the following code:
a= 2
def foo(a):
return a+2
In the main file I have this:
import Setting
if __name__ == '__main__':
X = foo(a)
So, when I run the main file, I get the error that a is not defined. So, I dont want again to define a in the main file. Could you please help me with this? this is a minimal code of my main code. I have multiple .py files and parameters. Thanks
答案1
得分: 1
from Setting import *
或 from Setting import foo,a
任一都可以尝试。
英文:
You could try either
from Setting import *
or from Setting import foo,a
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论