¡@

Home 

python Programming Glossary: sys

Python output buffering

http://stackoverflow.com/questions/107705/python-output-buffering

buffering enabled by default in Python's interpreter for sys.stdout If the answer is positive what are all the ways to disable.. it Suggestions so far Use the u command line switch Wrap sys.stdout in an object that flushes after every write Set PYTHONUNBUFFERED.. flushes after every write Set PYTHONUNBUFFERED env var sys.stdout os.fdopen sys.stdout.fileno 'w' 0 Is there any other..

Python subprocess readlines() hangs

http://stackoverflow.com/questions/12419198/python-subprocess-readlines-hangs

well it works on other OSes. You could try pexpect import sys import pexpect pexpect.run ruby ruby_sleep.rb logfile sys.stdout.. sys import pexpect pexpect.run ruby ruby_sleep.rb logfile sys.stdout Or stdbuf to enable line buffering in non interactive..

Fastest way to list all primes below N in python

http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python

sieve 0 1 1 if __name__ '__main__' import itertools import sys def test f1 f2 num print 'Testing f1 and f2 return same results'.format.. all a b for a b in itertools.izip_longest f1 num f2 num sys.exit Error s s s s f1.func_name num f2.func_name num n 1000000..

How to flush output of Python print? [duplicate]

http://stackoverflow.com/questions/230751/how-to-flush-output-of-python-print

printing flush share improve this question import sys sys.stdout.flush print by default prints to sys.stdout References.. printing flush share improve this question import sys sys.stdout.flush print by default prints to sys.stdout References.. import sys sys.stdout.flush print by default prints to sys.stdout References http docs.python.org reference simple_stmts.html#the..

Import a module from a relative path

http://stackoverflow.com/questions/279237/import-a-module-from-a-relative-path

execute instead of opening a new interpreter. import os sys inspect # realpath with make your script run even if you symlink.. inspect.currentframe 0 if cmd_folder not in sys.path sys.path.insert 0 cmd_folder # use this if you want to.. inspect.currentframe 0 if cmd_folder not in sys.path sys.path.insert 0 cmd_folder # use this if you want to include modules..

Ping a site in Python?

http://stackoverflow.com/questions/316866/ping-a-site-in-python

in Python The basic code is from Tkinter import import os sys ana Tk def ping1 os.system 'ping' a Button pen ip 192.168.0.1.. is from Tkinter import import os sys ana Tk def ping1 os.system 'ping' a Button pen ip 192.168.0.1 a.config text PING bg..

Non-blocking read on a subprocess.PIPE in python

http://stackoverflow.com/questions/375427/non-blocking-read-on-a-subprocess-pipe-in-python

both Windows and Linux is to use Queue.get_nowait import sys from subprocess import PIPE Popen from threading import Thread.. queue import Queue Empty # python 3.x ON_POSIX 'posix' in sys.builtin_module_names def enqueue_output out queue for line in..

How to improve performance of this code?

http://stackoverflow.com/questions/4295799/how-to-improve-performance-of-this-code

'B' 'B' 'B' 'F' 'G' 'F' 'F' real 0m20.883s user 0m20.549s sys 0m0.020s Here's the code import Queue fCamel 'F' bCamel 'B'..

Setting the correct encoding when piping stdout in python

http://stackoverflow.com/questions/492483/setting-the-correct-encoding-when-piping-stdout-in-python

Can I just tell it to use whatever encoding the shell filesystem whatever is using The suggestions I have seen thus far is.. the defaultencoding using this hack # coding utf 8 import sys reload sys sys.setdefaultencoding 'utf 8' print åäö Is there.. using this hack # coding utf 8 import sys reload sys sys.setdefaultencoding 'utf 8' print åäö Is there a better way..

Python read a single character from the user

http://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user

self.impl class _GetchUnix def __init__ self import tty sys def __call__ self import sys tty termios fd sys.stdin.fileno.. def __init__ self import tty sys def __call__ self import sys tty termios fd sys.stdin.fileno old_settings termios.tcgetattr.. import tty sys def __call__ self import sys tty termios fd sys.stdin.fileno old_settings termios.tcgetattr fd try tty.setraw..

Python rounding error with float numbers

http://stackoverflow.com/questions/5997027/python-rounding-error-with-float-numbers

float 29 100 as 0.28999999999999998. But that isn't a systematic error not in the sense it happens to every integer. So.. the following Python script # usr bin env python2.6 import sys n int sys.argv 1 for i in range 0 n 1 a int 100 float i 100.. Python script # usr bin env python2.6 import sys n int sys.argv 1 for i in range 0 n 1 a int 100 float i 100 if i a print..

How do I duplicate sys.stdout to a log file in python?

http://stackoverflow.com/questions/616645/how-do-i-duplicate-sys-stdout-to-a-log-file-in-python

do I duplicate sys.stdout to a log file in python Edit Since it appears that there's.. to accomplish logging when a python app is making a lot of system calls My app has two modes. In interactive mode I want all.. screen as well as to a log file including output from any system calls. In daemon mode all output goes to the log. Daemon..

Why is reading lines from stdin much slower in C++ than Python?

http://stackoverflow.com/questions/9371238/why-is-reading-lines-from-stdin-much-slower-in-c-than-python

Python Equivalent # usr bin env python import time import sys count 0 start time.time for line in sys.stdin count 1 delta_sec.. import time import sys count 0 start time.time for line in sys.stdin count 1 delta_sec int time.time start_time if delta_sec.. . readline_test_cpp 33.30 real 0.04 user 0.74 sys Saw 20000001 lines in 33 seconds. Crunch speed 606060 usr bin..