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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:16:28+00:00 2026-05-18T11:16:28+00:00

Wow, this should be so simple, but it’ just not working. I need to

  • 0

Wow, this should be so simple, but it’ just not working.
I need to inset a “\” into a string (for a Bash command), but escaping just doesn’t work.

>>> a = 'testing'
>>> b = a[:3] + '\' + a[3:]
    >>> File "<stdin>", line 1
    >>> b = a[:3] + '\' + a[3:]
                              ^
   >>>SyntaxError: EOL while scanning string literal
>>> b = a[:3] + '\\' + a[3:]
>>> b
'tes\\ting'
>>> sys.version
'2.7 (r27:82500, Sep 16 2010, 18:02:00) \n[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)]' 

The first error is understandable and expexted. The end quote is being eaten, and the interpreter barfs.
However, the second example should work. Why is there two slashes?

Python 2.7

Thanks,

Edit: Thanks Greg. It was a problem with working at the interpreter and not using repr(b). Python was working correctly, but I wasn’t looking at the correct version of the output.

  • 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-18T11:16:29+00:00Added an answer on May 18, 2026 at 11:16 am

    You are being misled by Python’s output. Try:

    >>> a = "test\\ing"
    >>> print(a)
    test\ing
    >>> print(repr(a))
    'test\\ing'
    >>> a
    'test\\ing'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Wow...I've never seen this before. Any way to get around it? foreach( double r
I'm refactoring some legacy code, and I keep running into this Object. I would
To start off, this really isn't CodeIgniter specific. I'm having trouble grasping an idea,
Here's a SQL query that I slightly scrubbed (just the column/table/database names). I kept
Wow, never thought I would ever write anything in DOS. Now that I do,
I send data from javascript to PHP like this: $.ajax({'url': 'my.php', 'type': 'POST', 'data':
For a MMORPG World of Warcraft im trying to write a lib. Money in
I have a very large array of floating point image data: In[25]:= Dimensions[daylightImgd] Out[25]=
see code below.. <div style=overflow:auto;width:250px;height:75px;border:1px solid #336699;padding-left:5px> <label style={width:250px;}><input type=checkbox name=wow[] onclick='highlight_div(this);'> PHP</label><br> <label
I have a requirement to retrieve all modules of a 64bit process in a

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.