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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:14:09+00:00 2026-05-24T13:14:09+00:00

Simply put, how can I differentiate these two in test.py: python test.py 1 python

  • 0

Simply put, how can I differentiate these two in test.py:

python test.py 1
python test.py '1'

Workaround is OK.


Edit:

  1. This workaround looks cool but too complex: argparse
  2. Let the invoker specify args later, in python code use arg = input('Please enter either an integer or a string')
  3. And other workarounds as presented in the answers of this question.

Thank you all for the replies. Every body +1.

  • 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-05-24T13:14:10+00:00Added an answer on May 24, 2026 at 1:14 pm

    The shell command line doesn’t support passing arguments of different types. If you want to have commands with arguments of different types you need to write your own command line or at least your own command parser.

    Variant 1:

    Usage:python test.py "1 2 '3' '4'"

    Implementation:

    command = sys.argv[1]
    arguments = map(ast.literal_eval, command.split())
    print arguments
    

    Variant 2:

    Usage:

    python test.py
    1 2 '3' 4'
    5 6 '7' 8'
    

    Implementation:

    for line in sys.stdin:
        arguments = map(ast.literal_eval, line.split())
        print arguments
    

    (Of course, you’d probably want to use raw_input to read the command lines, and readline when it is available, that’s merely an example.)

    A much better solution would be to actually know what kind of arguments you’re expected to get and parse them as such, preferably by using a module like argparse.

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

Sidebar

Related Questions

I have looked all over but can't find an answer to this... Quite simply
Simply put; what does my $99 get me, that I can't already get for
Maybe a very simple question. How can I put in this code <Query> <Where>
Simple question, I know, but I can't seem to find a way to put
Simply put, I would like to make java do what I want but I
I've searched a bit before asking this but I definitely can't get it working...
I have an issue with grabbing an image dynamicly. Simply put, how can I
i don't know if this can be done using php but it would be
Simply put, is there a way to create a 2D javascript array using similar
Simply put, MVC is the pattern for separating contents (model) from presentation (view), and

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.