2014-02-09 4 views
0

Python 2.6부터 .py 파일을 통합하여 파이썬 명령 줄에서 egg 파일을 직접 실행할 수 있습니다.파이썬 클래스에서 계란 파일을 찾는 방법은 무엇입니까?

지금 ... 실행중인 python 코드가 현재 달걀에서 직접 실행되고 있는지, 경로를 알아낼 수 있습니까?

Java ClassLoader를 통해 클래스에서 포함 된 jar를 가져올 수있는 비슷한 Java 기능을 미러링하려고합니다.

답변

0

내가 손으로 그렇지 않으면이 할 수있는 더 좋은 파이썬 방법을 찾지 못했습니다 :

[email protected]:~$ cat __main__.py 
import zipfile, os 
module_path = os.path.dirname(__file__) 
print "Is this an egg? ", zipfile.is_zipfile(module_path) 

[email protected]:~$ python __main__.py 
Is this an egg? False 

[email protected]:~$ zip example.egg __main__.py 
adding: __main__.py (deflated 15%) 

[email protected]:~$ python example.egg 
Is this an egg? True 

희망이 유용하고 실제로 귀하의 질문을 이해했다.

+0

예, 완벽합니다. 죄송하지만 지금 투표 할 신용이 없습니다 :-( – user2123288

+0

@ user2123288 감사합니다. 내 대답은 받아 들일 수 있습니다 plz;) – pna