0
좋아 다른 파일에서 클래스 가져 오기 후 오류를 발견하지, 난 단지이 클래스 내 프로젝트 내부의 파이썬 파일이 :파이썬 파일이
if __name__ == '__main__':
xml = hd_XML()
print(xml.get_data())
:
class hd_XML():
def __init__(self):
self.path = 'static/XML/current/'
self.filename = 'current_settings.xml'
self.tree = ''
def open(self):
self.tree = ET.parse(self.path + self.filename)
self.root = self.tree.getroot()
return self.root
def get_data(self):
self.root = self.open()
canale = Channel
canali = []
i = 0
for child in self.root:
canale.id = child.attrib['id']
canale.max = child.attrib['max']
canale.color = child.attrib['color']
canali.append(canale)
i += 1
return canali
난이 클래스의 독립을 실행하는 경우
가 작동합니다. 그러나, 나는 다음과 같이 내 주요 응용 프로그램 파일이 클래스,
import hd_modXML #thats my separate file name
xml = hd_modXML.hd_XML()
canali = xml.get_data()
print(canali[0].id)
내가 파일을 가져 오지 수 없습니다 ...
FileNotFoundError: [Errno 2] No such file or directory: 'static/XML/current/current_settings.xml'
이유를 가져 오는 경우?! 독립 실행 형 파일로 찾을 수 있으며 가져온 후에는 볼 수 없습니다.
프로젝트 구조 :
self.path = '/home/grace/pyDev/prova_horus2/static/XML/current/'
나는 이유를 알고하지 않습니다 : 나는 내 경우에, 그래서 파서에게 루트에서 전체 디렉토리 경로를 제공 작동하는지 발견 된 일부 시도 후
main folder <--- where app.py (where is included hd_modXML.py) and hd_modXML.py are
|_static
|_XML
|_current\ <-- where current_settings.xml is
|_templates
프로젝트의 디렉토리 구조를 게시 할 수 있습니까? – yash
게시물에 디렉토리 구조를 추가하십시오 – yash
잠시 후 댓글에서 댓글을 빼내려고합니다 ... – fabbronet