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

  • Home
  • SEARCH
  • 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 6913629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:14:34+00:00 2026-05-27T09:14:34+00:00

Why does the following result in an error? import re from urllib import quote

  • 0

Why does the following result in an error?

import re
from urllib import quote as q
s = re.compile(r'[^a-zA-Z0-9.: ^*$@!+_?-]')
s.sub(q, "A/B")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/python/python-2.7.1/lib/python2.7/urllib.py", line 1236, in quote
    if not s.rstrip(safe):
AttributeError: rstrip

I’d like to call sub on strings that contain forward slashes, not sure why it results in this error. How can it be fixed so that I can pass strings with ‘/’ characters in them to sub()?

thanks.

  • 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-27T09:14:35+00:00Added an answer on May 27, 2026 at 9:14 am

    Because re.sub calls the repl parameter with an instance of re.match.

    I think you want to use:

    s.sub(lambda m: q(m.group()), "A/B")
    

    However, a simpler way of doing this might be to use the safe argument to urllib.quote:

    urllib.quote("A/B", safe="/.: ^*$@!+_?-")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does the following result in a BAD_ACCESS error? NSDictionary *header=[[NSDictionary alloc]initWithObjectsAndKeys:@fred,@title,1,@count, nil]; Can
Why does the following raise a compile time error: 'Cannot implicitly convert type 'int'
Why does the following result in an error message? (it is declared inside a
Why does the following code result in the error 'undefined local variable or method
On Oracle 9i, why does the following produce the result 'abc' select 'abc '
why does the following js expression: test1 foo bar test2.replace(/foo.bar/, $') result in the
The following does not compile, and I cannot for the life of me see
The following does not compile: class Foo { public: Foo( boost::shared_ptr< Bar > arg
The following code throws an error on the CreateIfNotExist method call. I am attempting
Why does the following code not give me a duplicate symbol linker error for

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.