About 11,500,000 results
Open links in new tab
  1. How can I redirect module imports with modern Python?

    May 13, 2022 · Since the import machinery already finds the keys in the sys.modules dictionary, it never even begins looking for the old files. If you want to avoid importing all the submodules immediately, you can emulate a bit of lazy loading by placing …

  2. Redirect stdout to a file in Python? - Stack Overflow

    Jan 13, 2011 · Insert a sys.stdout.flush() before the close(1) statement to make sure the redirect 'file' file gets the output. Also, you can use a tempfile.mkstemp() file in place of 'file'.

  3. How can I transparently redirect a Python import?

    Feb 1, 2011 · All you need to do is modify the __path__ attribute of your package so it points to the folder where your modules are. This will require lib to be a package, not just a module (ie. a folder with an __init__.py). By default __path__ is a one element list that contains the path of folder that is the package -- ['/path/to/lib'].

  4. Redirect standard output to a file in Python | Techie Delight

    Apr 13, 2024 · Here’s how you can redirect the stdout and stderr output to a file using the > operator: $ python main.py > file. 2. Using sys.stdout. Another simple solution to redirect the standard output to a file is to set sys.stdout to the file object, as shown below: 3. Using contextlib.redirect_stdout() function.

    Missing:

    • Modules

    Must include:

  5. Redirecting all kinds of stdout in Python - Eli Bendersky's website

    Feb 20, 2015 · A common task in Python (especially while testing or debugging) is to redirect sys.stdout to a stream or a file while executing some piece of code. However, simply "redirecting stdout " is sometimes not as easy as one would expect; hence the slightly strange title of this post.

  6. How to redirect standard input and output to file in python

    Sep 19, 2024 · Redirecting standard input and output to files in Python is a useful technique when you want to read from a file instead of the keyboard or write output directly to a file instead of the console....

  7. How To Redirect Python Standard Error (stderr) To A File - dev2qa

    Redirecting stderr to a file involves capturing the error messages generated during program execution and writing them to a designated file instead of displaying them on the console. This can be accomplished using the ` sys ` module, which allows interaction with …

  8. How do I redirect python where to look for modules?

    Apr 7, 2023 · I was using spyder but after seeing the hype and love for VSC I want to give it a try as a lot of my colleagues also like it. I copied over my code but when I run it, it can’t find the modules folder and is only looking in my CWD. How can I …

  9. python - Redirect the output of help() function's content to a file ...

    Aug 20, 2018 · Use help() to get the interactive help utility. Use help(str) for help on the str class. How could I write help (browser) to a plain text file. bulit-in help() is a wrapper around pydoc.Helper, it writes to stdout by default, you could temporarily redirecting sys.stdout to a file: or you could call pydoc.Helper directly, :

  10. Redirecting standard input output to a file in python

    Jun 6, 2022 · In order to avoid typing the inputs manually or copy pasting the inputs to the console, it makes sense to just redirect the std io to a file. With that input () and print () in python can...

Refresh