【发布时间】:2019-10-01 10:25:00
【问题描述】:
我正在尝试更好地组织我的程序,并决定将小文件导入 final.py。
这里我希望 DIrectorySetup 在 main 开始时启动。我希望能够调用目录。
这是我尝试过的:
class DirectorySetup:
'''The directory paths for the program'''
def __init__(self):
self.cwd = os.getcwd()
self.Raw_data_dir= self.cwd + '\Raw_data'
self.Clean_data_dir= self.cwd + '\Clean_data'
self.table_dir= self.cwd + '\Tables'
def main(): # Define the main function
#the class with the directory
Directory= DirectorySetup()
os.chdir(Directory.table_dir)
###does other things that I removed for clarity ###
if __name__ == "__main__":
main()
然后我在我的 final.py 程序中运行它:
import INIT_SCTFT
import os
first=INIT_SCTFT
first.main()
first.DirectorySetup.Clean_data_dir
这给了我错误
first.DirectorySetup.Clean_data_dir
AttributeError: type object 'DirectorySetup' has no attribute 'Clean_data_dir'
如何让 main() 保存 DirectorySetup?
【问题讨论】: