Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 66875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:10:19+00:00 2026-05-10T19:10:19+00:00

i have the following script import getopt, sys opts, args = getopt.getopt(sys.argv[1:], h:s) for

  • 0

i have the following script

import getopt, sys opts, args = getopt.getopt(sys.argv[1:], 'h:s') for key,value in opts:     print key, '=>', value 

if i name this getopt.py and run it doesn’t work as it tries to import itself

is there a way around this, so i can keep this filename but specify on import that i want the standard python lib and not this file?

Solution based on Vinko’s answer:

import sys sys.path.reverse() from getopt import getopt  opts, args = getopt(sys.argv[1:], 'h:s')  for key,value in opts:     print key, '=>', value 
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:10:19+00:00Added an answer on May 10, 2026 at 7:10 pm

    You shouldn’t name your scripts like existing modules. Especially if standard.

    That said, you can touch sys.path to modify the library loading order

    ~# 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'] 

    In addition, you may wish to avoid the full import and do it differently, like this:

    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 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written following script in python which works fine: from sys import argv
I have made the following script to upload a csv and import it into
I have following script: #!/usr/bin/python while True: x = raw_input() print x[::-1] I am
I have the following PyObjC script: from Foundation import NSObject import QTKit error =
I have inherited the following Python script: import urllib2 a = urllib2.urlopen('http://mysite/mypage.aspx?action=dosomething') a.read() a.close()
I have the following script defining a tzinfo object: import time from datetime import
I have the following simple Python script: import socket import ssl if __name__ ==
I have the following script: import os import stat curDir = os.getcwd()+'/test' for (paths,
Hello! I have the following script: import os import stat curDir = os.getcwd() autorun_signature
I have the following script that will run each script (sequentially) in a directory:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.