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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:34:28+00:00 2026-06-11T21:34:28+00:00

I’ve a programm that gets an argument from the shell. This argument will be

  • 0

I’ve a programm that gets an argument from the shell. This argument will be the query used in a search operation.

If I pass in English words (i.e. no accents, etc.), it works fine. Nevertheless, if I pass in, namely, ‘café’, I get ‘cafú’ (print sys.argv[1] results in cafÚ instead of café).

I thought I could solve the problem by converting it into a Unicode object, but I was wrong.

Q = unicode(sys.argv[1], encoding=sys.stdin.encoding)

I still get ‘cafÚ’!! I’m going crazy…

  • 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-06-11T21:34:30+00:00Added an answer on June 11, 2026 at 9:34 pm

    I bet you’re on Windows, right?

    >>> a = "café"
    >>> a
    'caf\x82'
    >>> print a
    café
    >>> a.decode("cp850")                      # DOS codepage 850 --> Unicode
    u'caf\xe9'
    >>> a.decode("cp850").encode("cp1252")     # DOS 850 --> Unicode --> Windows 1252
    'caf\xe9'                                  # identical to Unicode codepoint
    >>> print a.decode("cp850").encode("cp1252") # Display a cp1252 string in cp850
    cafÚ
    

    Use encoding="cp1252" instead, then it should work.

    Explanation: (with some guesswork)

    • cmd windows use cp850 as their default codepage. This is evident from the second line in my session above, 0x82 is é in cp850.
    • It appears that Python programs started under Windows use cp1252 as their standard encoding, shown by the last line of the session above: é is 0xe9 in cp1252 (like in Unicode).
    • This is also evident when you write this string to a file (which by default uses cp1252):
      If I do f.write(a), I get caf, as the contents of my file because , is 0x82 in cp1252).
      If I do f.write(a.decode("cp850").encode("cp1252")), I get café.

    Moral: Find out the correct encodings in your environment, convert everything to Unicode as soon as possible, work with it, then convert back to the encoding you need. If you’re outputting into an interactive window, use cp850, if you’re outputting into a file, use cp1252.

    Or switch to Python 3 which makes all of this much easier.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small

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.