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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:41:11+00:00 2026-05-25T21:41:11+00:00

Before I sit down and start hacking it out, I thought I’d come here

  • 0

Before I sit down and start hacking it out, I thought I’d come here and see if you all had any tips or even if something like this has been done before.

I want to re-create a basic shell like syntax within a python program. In other words, when people run the file with python, they will be greeted with a little prompt

>> 

For simple things, using an option parser to say

opt.parse_args(input.split(" "))

Works just fine, but now I would like to not only escape special characters like spaces with the ‘\’ character, but also treat quoted strings as a single argument, like in a unix shell.

Does there exist anything that might already help with this?

Thanks for any suggestions!
– Chase

  • 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-25T21:41:12+00:00Added an answer on May 25, 2026 at 9:41 pm

    Start with the shlex module:

    $ pydoc shlex
    Help on module shlex:
    
    NAME
        shlex - A lexical analyzer class for simple shell-like syntaxes.
    

    You can use it like this:

    >> import shlex
    >> shlex.split('This "is a" test.')
    ['This', 'is a', 'test']
    

    This just splits things up into logical tokens; it won’t do anything like variable expansion and so forth. That’s still up to you, as is actually running commands.

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

Sidebar

Related Questions

I have asked a similar question before here , but after much thought, and
Before I start, I know there is this post and it doesn't answer my
Before you start firing at me, I'm NOT looking to do this, but someone
Before you guys go telling me that Regex is the epitome of all evil...
See the code below: <div>Lorem ipsum dolor sit amet</div> <object type=application/x-shockwave-flash data=banner.swf width=965 height=120
Before we start, strip_tags() doesn't work. now, I've got some data that needs to
Here's the input HTML: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
Is there any .NET performance profiling tool out there that I can attach to
Given any String like 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit' I'd like
I've run into this problem before and couldn't figure it out, but it's basically

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.