定义主文件,而不在主文件中定义参数。

huangapple go评论63阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年3月31日 02:37:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75891839.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定