기존 모듈과 같은 스크립트 이름을 지정하면 안됩니다. 특히 표준 경우.
라이브러리 로딩 순서를 수정 sys.path에 접촉 할 수 말했다
~# cat getopt.py
print "HI"
~# python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import getopt
HI
~# python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.remove('')
>>> import getopt
>>> dir(getopt)
['GetoptError', '__all__', '__builtins__', '__doc__', '__file__', '__name__', 'do_longs', 'do_shorts', 'error', 'getopt', 'gnu_getopt', 'long_has_args', 'os', 'short_has_arg']
또한, 당신은 전체 가져 오기를 방지 할 수 있으며, 그것은 다음과 같이 다르게 수행
import sys
sys.path.remove('')
from getopt import getopt
sys.path.insert(0,'')
opts, args = getopt(sys.argv[1:], "h:s")
for key,value in opts:
print key, "=>", value
@ 대니얼즈 : 여기 http://www.python.org/dev/peps/pep-0328/ –
참조하십시오. 나는 그것을 더 나은 것 같아 sys.path.reverse() 사용 그것은 아마도 현재 폴더에있는 다른 lib를 가져올 필요가 있기 때문에 그것을 제거합니다 당신의 조언을 기반으로 발견 솔루션으로 내 질문을 업데이 트합니다 그것은 작동하지만 내 생각에 사악 해. 훨씬 더 libs – daniels