사용 os.path.join()
는 :
import os
fullpath = os.path.join(base_dir, filename)
os.path 모듈은 플랫폼 독립적 인 경로 조작에 필요한해야하는 모든 메소드가 포함되어 있지만 경우에 당신은 경로 구분자는 당신이 할 수있는 현재의 플랫폼에 무엇인지 알 필요가 os.sep
을 사용하십시오.
import os
class u(str):
"""
Class to deal with urls concat.
"""
def __init__(self, url):
self.url = str(url)
def __add__(self, other):
if isinstance(other, u):
return u(os.path.join(self.url, other.url))
else:
return u(os.path.join(self.url, other))
def __unicode__(self):
return self.url
def __repr__(self):
return self.url
사용법은 다음과 같습니다 :
가능한 [플랫폼 독립적 파일 경로?] (http://stackoverflow.com/questions/6036129/platform-independent-file-paths) –