आपको मौजूदा स्क्रिप्ट जैसे अपनी स्क्रिप्ट का नाम नहीं देना चाहिए। विशेष रूप से मानक अगर।
उस ने कहा, आप लाइब्रेरी लोडिंग ऑर्डर को संशोधित करने के लिए 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