如何使用相对进口?

时间:2018-05-12 18:49:46

标签: python python-3.x relative-path

如何阅读/billy/var/text.txtb.py

目录结构是:

/billy/b.py
/billy/var/text.txt
/sally/s.py

s.py

import sys, os
sys.path.append('..')
from billy import b

print('s.py - ' + os.path.dirname(sys.argv[0]))

b.py

import sys, os

print('b.py - ' + os.path.dirname(sys.argv[0]))
ag = open(os.path.dirname(sys.argv[0]) + '//var//text.txt').read()

0 个答案:

没有答案