''' Data class'''
import os.path
from random import Random
class TestData(object, Random):
def FetchDataFromFile(self, filename):
""" Open the file as read only """
myfile = open(os.path.join(os.getcwd(),filename), 'r')
""" read the information in the file """
lines = myfile.read()
''' Remove the header as this will not be used '''
header = lines[0]
lines.remove(header)
return lines
我遇到了以下问题:
导入错误: 找不到名为path的模块
在“pyclasspath/Lib/Testdata.py”文件的第2行,位于
在我的项目中,所有其他类都可以使用os.path。有人能告诉我我做错了什么吗?
我将这个文件从一个目录移动到了另一个目录。除此之外,这个类和其他类没有任何区别。
from os import path
,但我认为更好的方式是import os
,然后在你的脚本中使用os.path.method_name()
。 - squiguyfrom os import path
,那么他需要使用path
而不是os.path
。 - Tanky Wooos.py
的文件吗? - syntonym