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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:04:16+00:00 2026-05-23T20:04:16+00:00

mystr = ‘aaaa’ myvar = u’My string %s’ % str(mystr) Can this be a

  • 0
mystr = 'aaaa'
myvar = u'My string %s' % str(mystr)

Can this be a problem in the future? I’m messing up woth some in-house code that uses email modules in Python and found some code like this. mystr will always have only ascii characters since it comes from a list with pre defined ascii only characters.

I didn’t write the code, and having str(mystr) or mystr doesn’t change the matter of the question.

Doing the first snippet I’m going to have a safe unicode object, or do I have to do

mystr = u'aaaa'
myvar = u'My string %s' % mystr

or

mystr = 'aaaa'
myvar = u'My string %s' % unicode(mystr)

?

(I know this is not the correct way of doing, I know I should handle the exceptions, I’m asking here only if the first snippet returns a valid unicode object, or if Python mess up with it’s internals or something when doing it.)

  • 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-23T20:04:16+00:00Added an answer on May 23, 2026 at 8:04 pm

    Try putting actual unicode symbols in the strings (like umlauts or cyrillic) and watch hell breaking lose. 🙂

    s = 'свят' # world
    v = u'здравей %s' % s # hello %s 
    
    Traceback (most recent call last):
    File "<input>", line 1, in <module>
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 0: ordinal not in range(128)
    

    The problem is that you will most likely code your application and on a bright shiny day some Russian or German will write her name and will suddenly get an Internal Server Error for having a non-ascii symbol in her name.


    I know… I’m asking about the situation in my example, using ascii only in

    No, there will be no problem. And IMHO this is a fault in Python, because this is bug, waiting to bite. This should have been a fatal error, but because of historical reasons, I guess, it isn’t.

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

Sidebar

Related Questions

I have this very awkward question... void changeString(String str){ str = Hello world: }
I have this String : String myStr = something.bad@foo.us I want to get just
I have a string like this mystr = K1_L1_L2 XX I want to break
list<string> mylist; mylist.push_back(random stuff); list<string>::iterator it; it=mylist.begin(); string mystr; //and this doesn't work: mystr=*it;
If I have a string like: const char* mystr = Test Test Bla Bla
We have a subclass of str (call it MyStr), and I need to be
If I have a string where there is a valid JSON substring like this
I have the followoing string myStr = myname-abc; string myStr1 = strstr(myStr.c_str(), -); now
I am splitting a string based on whitespace as follows: string myStr = The
i've an NSString like this: NSString *myStr=@7JXAX; that is equal in ASCII decimal value

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.