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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:17:20+00:00 2026-06-15T12:17:20+00:00

I have a fun program that displays temperatures. Everything works fine, until I try

  • 0

I have a fun program that displays temperatures. Everything works fine, until I try to use it from Conky:

Traceback (most recent call last):
  File "/home/naftuli/Documents/i7zdaemon/get-i7z-value", line 85, in <module>
    main()
  File "/home/naftuli/Documents/i7zdaemon/get-i7z-value", line 28, in main
    get_temp_value(args)
  File "/home/naftuli/Documents/i7zdaemon/get-i7z-value", line 63, in get_temp_value
    print fmt % (temp if not args.in_fahrenheit else temp * (9.0/5.0) + 32, )
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 2: ordinal not in range(128)

Why is this only throwing an error when used from another program? Everything looks fine when I run it from a terminal directly.

Here’s what I’m doing:

fmt = u"%d\u00B0C" if not args.in_fahrenheit else u"%d\u00B0F"
# ...
print fmt % (temp if not args.in_fahrenheit else temp * (9.0/5.0) + 32, )

That last line kills everything. What gives?

  • 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-15T12:17:21+00:00Added an answer on June 15, 2026 at 12:17 pm

    When you print unicode, the printed text has to be encoded to match whatever encoding is used for the output stream. For Linux terminals, for example, that is usually UTF-8 these days.

    But when you use a different program to run your python script, the output stream encoding (a pipe, or a program window other than a terminal), may well use a different encoding. In this case, no encoding appears to be set and python then falls back to ASCII. The \u00B0 character cannot be encoded to ASCII and the encode fails.

    Perhaps for this program, printing a lowercase o would suffice instead?

    Or, the as the Conky FAQ seems to suggest, explicitly encode to Latin 1 (ISO 8859-1) to output the degree symbol:

    print (fmt % (temp if not args.in_fahrenheit else temp * (9.0/5.0) + 32, )).encode('latin1')
    

    And this posting seems to hint that encoding to UTF-8 is also an option (depending on Conky configuration)? Replace latin1 in the above example with utf8 to try that encoding instead.

    Also see the Python Unicode HOWTO, which specifies how output encoding is handled.

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

Sidebar

Related Questions

I have a Win32 console program that I wrote and it works fine. The
I have a program that returns int*int (Example for illustration purposes): fun program(a,b) =
I have a fun issue where during application shutdown, try / catch blocks are
I have a function fun that returns a double. I want to call the
I have found myself designing a language for fun that is a cross between
I have a program that (amongst other things) has a command line interface that
For about a year I have been thinking about writing a program that writes
I'm fairly new to C# programming. I am making a program for fun that
I have just started learning XNA. This is my first program that I am
I have an application that seems to throw exceptions only after the program has

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.