2
在Python中,我能做到这一点,以获得当前文件的路径:如何获得执行当前线程的文件的当前路径?
os.path.dirname(os.path.abspath(__file__))
但是,如果我在一个线程中运行这个说:
def do_stuff():
class RunThread(threading.Thread):
def run(self):
print os.path.dirname(os.path.abspath(__file__))
a = RunThread()
a.start()
我得到这个错误:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "readrss.py", line 137, in run
print os.path.dirname(os.path.abspath(__file__))
NameError: global name '__file__' is not defined
我只是尝试这样做。这真的很酷。 – idjaw
是否有可能获得绝对路径? –
@ Stupid.Fat.Cat在检查文档我没有找到绝对路径提及我知道只有可以检查与os.path.isabs如果它是否...... – LetzerWille