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

Related Questions

suppose there is a script doing something like this: # module writer.py import sys
I am doing something like this in myproject.myapp.urls : from django.conf.urls.defaults import * urlpatterns
So I'm doing something wrong in this python script, but it's becoming convoluted and
I know there are similar questions out there, but I'm having trouble with this
Think about doing this: import matplotlib.pyplot as plt plt.plot(x_A,y_A,'g--') plt.plot(x_B,y_B,'r-o') plt.show() How would you
I'm doing this with a very simple class, just to learn, but I'm not
I have this sample of code: import sys from PyQt4.QtGui import (QApplication, QHBoxLayout, QVBoxLayout,
I hate to give the question this heading but I actually don't know whats
This is a stupid question, and I know it is, but for some reason
Im doing this project where i need to download files through a webservice (images,

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.