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 8081887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:53:10+00:00 2026-06-05T16:53:10+00:00

In general, I try very much to respect a modules privacy (If a variable

  • 0

In general, I try very much to respect a modules privacy (If a variable is prefixed with an underscore, I don’t use it). I have a corner case, however, where it seems reasonably “safe”.

Here’s the demo ( my previous question )

parser=argparse.ArgumentParser()
parser.add_argument('--point',help='enter a point (e.g. 2,3,4)')
parser.parse_args('--point=-2,5,6'.split())  #works
parser.parse_args('--point -2,5,6'.split())  #doesn't work

This can be fixed by:

parser=argparse.ArgumentParser()
parser.add_argument('--point',help='enter a point (e.g. 2,3,4)')
parser.parse_args('--point=-2,5,6'.split())  #works
parser._negative_number_matcher = re.compile(r'^-\d+|^-\d*\.\d+')
#Next line works too on Cpython 2.6, 
#got the idea from reading Cpython 3.2 source so it should work there too
parser.parse_args('--point -2,5,6'.split())  

This amount of playing with the internals of a class seems OK in this instance because:

*If argparse changes that variable (unlikely) or a different python implementation does it differently, it seems very unlikely that this will change the behavior of the class causing something to break.

*other python implementations are likely to use cpython’s argparse since it is written in pure python (as far as I can tell).

*My code doesn’t depend critically on this “feature” working. (the user can always revert back to passing ‘–point=-2,5,6’)

My question is this: Am I missing something? Is this really a bad idea? Am I likely to break something? If it is, why?

  • 1 1 Answer
  • 0 Views
  • 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. Editorial Team
    Editorial Team
    2026-06-05T16:53:13+00:00Added an answer on June 5, 2026 at 4:53 pm

    I think it’s a bad idea, and not because it may break something in argparse internals, but because it’s just wrong. ^-\d+ is not a valid regexp for negative numbers (since it matches -23foo), and having plain wrong things in code is not good for maintenance. Imagine yourself (or even worse someone else) staring at this code two years later and puzzling about how the heck ^-\d+ is supposed to match negative numbers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

General use case I am trying to implement a basic shell. Description I need
I have very general problem on DNN 6.0 web site that I am working
I'm very new to Python and multithreaded programming in general. Basically, I have a
Ok this is more of general technology/approach question. We have a very simple web
I have a question about Sage/Python, but I'm sure it's a very general CS
General context : MVVM application. I have a View called JobView. Its DataContext is
General approach in GWT is to use Panels and then apply custom CSS themes
In general, I have the following scenario: Fetch product and its related data from
In general we use biometrics in computer applications say for authentication. Lets get 2
I have a slight dilema. This isn't general to backbone.js but it's certainly causing

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.