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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:00:33+00:00 2026-05-17T00:00:33+00:00

I am doing this: import sys, codecs sys.stdout = codecs.getwriter(‘utf8’)(sys.stdout) sys.stderr = codecs.getwriter(‘utf8’)(sys.stderr) But

  • 0

I am doing this:

import sys, codecs
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
sys.stderr = codecs.getwriter('utf8')(sys.stderr)

But I know there is something missing. I had a huge collection of code before an HD crash, and my snippet in there had something in it which prevented:

reload(sys)

From undoing the codec changes. Does anyone know what that might have been?

  • 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-17T00:00:33+00:00Added an answer on May 17, 2026 at 12:00 am

    Quite apart from UTF8 (and thus entirely apart from your Q’s title), reload(sys) does not reopen stdandard input, output, and error files. Try a simpler case to see that:

    >>> import sys
    >>> print>>sys.stderr,'ciao'
    ciao
    >>> sys.stderr.close()
    >>> print>>sys.stderr,'ciao'
    >>> reload(sys)
    <module 'sys' (built-in)>
    >>> print>>sys.stderr,'ciao'
    

    If you want to restore sys.stdout and/or sys.stderr after rebinding them, just stash away the old references and just rebind them to the “stashed away” refs to restore. (You could use sys.__stdout__ and sys.__stderr__, where Python itself stashes them away at startup, but that might run athwart advanced shells or debuggers you might be running, as the latter may be doing their own similar operations).

    If you also want to survive file or file-descriptor closures, you’ll have to go deeper (reopening e.g. with os.fdopen the standard descriptors 0, 1, and 2 — if the descriptors themselves have been closer, that gets even hairier;-) and living peacefully with advanced shells or debuggers in general may become a lost cause. But for simpler cases, just rebinding things back and forth can work fine.

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

Sidebar

Ask A Question

Stats

  • Questions 534k
  • Answers 534k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For styles wp_register_style( 'namespace', 'http://locationofcss.com/mycss.css' ); Then use: wp_enqueue_style('namespace'); wherever… May 17, 2026 at 12:50 am
  • Editorial Team
    Editorial Team added an answer Use: SELECT x.* FROM YOUR_TABLE x JOIN (SELECT t.item_id, MAX(t.click_dt)… May 17, 2026 at 12:50 am
  • Editorial Team
    Editorial Team added an answer Do you mean what are the pros and cons of… May 17, 2026 at 12:50 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

imagine something like this: import class B.*; interface A supports A.testSum { int sum(
I`m doing something wrong here but I can't figure out what it is .
import sys print (sys.platform) print (2 ** 100) input('press Enter to exit') Suppose I
I've got a webserver that I'm presently benchmarking for CPU usage. What I'm doing
I am writing my first lines in objective-c for an iPhone app. This is
Assume for a moment that one cannot use print (and thus enjoy the benefit
I'm trying to use a User model inheritance in my django application. Model looks
I'm writing a Python program that, if the user changes settings while running it,
I am looking for a way to extract an icon from a .exe file
I'm pretty new to Python, and I want to develop my first serious open

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.