我在将os导入到我想要使用的类方法时遇到了一些问题
main.py:
import os
import datadir
import dataops
d1 = datadir.datadir(dirtoscan)
uniques = d1.FindPrefixes(dirtoscan)
Materials = d1.SortPhotodiodeData(uniques)
dat1 = dataops.dataops(Materials)
rawdata = dat1.BigDictToArray(Materials)
dataops.py:
import os
class dataops:
def __init__(self,name):
self.name = name
def BigDictToArray(self,Materials):
self.tardir = os.getcwd()
当我尝试在Windows 7上运行此错误时出现错误(我很抱歉)
C:\Python27\dataops.pyc in BigDictToArray(self, Materials)
43 rawdata.append({name[0]:matdata})
44 return rawdata
---> 45
46 def BigDictToArray(self,Materials):
47 self.tardir = os.getcwd()
NameError: global name 'os' is not defined
为什么我似乎无法将os模块导入dataops? os在类datadir中调用没有问题。 dataops和datadir都存储在C:\ Python27中,如果这有任何区别的话。