【发布时间】:2023-01-26 16:25:43
【问题描述】:
我有两个 python 文件 main.py 和 conftest.py。我想从 contest.py 访问 main.py 方法中的一个变量。我尝试了一些,但我知道这是错误的,因为我首先遇到了语法错误。有什么办法吗?
主程序
class Test():
def test_setup(self):
#make new directory for downloads
new_dir = r"D:\Selenium\Insights\timestamp}".format(timestamp=datetime.now().strftime('%Y-%m-%d_%H-%M-%S'))
# print(new_dir)
if not os.path.exists(new_dir):
os.makedirs(new_dir)
saved_dir=new_dir
比赛.py
from main import Test
def newfunc():
dir=Test.test_setup()
print(dir.saved_dir)
【问题讨论】: