Tag Info

Hot answers tagged

20

This is happening because normally when process STDOUT is redirected to something other than a terminal, then the output is buffered into some OS-specific-sized buffer (perhaps 4k or 8k in many cases). Conversely, when outputting to a terminal, STDOUT will be line-buffered or not buffered at all, so you'll see output after each \n or for each character. ...


11

This should do the job: import time, sys for i in range(10): print('bla') sys.stdout.flush() time.sleep(5) As Python will buffer the stdout by default, here i have used sys.stdout.flush() to flush the buffer. Another solution would be to use the -u(unbuffered) switch of python. So, the following will do too: python -u script.py >> log ...


2

Here's something I cobbled up using the CSV module: #! /usr/bin/env python3 import csv, sys word_list = ['fcv=demelog','fcv=voyapro','fcv=naisjdf','fcv=naismc','fcv=decoide','fcv=decoccm','fcv=travide','fcv=travccm','fcv=equiccm','fcv=mariccm'] csvin = csv.reader (sys.stdin, delimiter=';') csvout = csv.writer (sys.stdout, delimiter=';') for row in csvin: ...


2

This is fairly easy in Python with os.walk. Warning, untested code. I assume that the list of names contains one name per line with #!/usr/bin/python2 import os names_file = open('names.log') names = set(line.rstrip('\n') for line in names_file.readlines()) names_file.close() for root, dirs, files in os.walk('/path/to/top/directory'): for name in ...


2

You should pass flush=True to the print function: import time for i in range(10): print('bla', flush=True) time.sleep(5) According to the documentation, by default, print doesn't enforce anything about flushing: Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly ...


1

On all recent Fedora releases, /bin is a symlink to /usr/bin — which means if you look in /bin, you actually get redirected to the /usr/bin. However, both appear in $PATH (hmmm; that probably should be cleaned up), and that's what you're seeing with which -a python — two ways to get to an actually-identical binary. So, there's no problem here. (Note, ...


1

Sed or awk are one-line editors. You have to join two lines in one or use options (exist in GNU sed versions > 4.2.1) sed -zi 's~Assurez-vous de bien recevoir tous nos messages en ajoutant bebeco@cab05\.net a votre carnet d'\''adresses.<br />\n Si vous avez des difficult\\&eacute;s pour visualiser ce message, rendez-vous sur~[{headerbebeco}]~g' ...


1

You can use heredoc if you want to keep the source of both bash and python scripts together. For example, say the following are the contents of a file called pyinbash.sh: #!/bin/bash echo "Executing a bash statement" export bashvar=100 cat << EOF > pyscript.py #!/usr/bin/python import subprocess print 'Hello python' ...


1

The simplest approach is to just save the python script as, for example script.py and then either call it from the bash script, or call it after the bash script: #!/usr/bin/env bash echo "This is the bash script" && /path/to/script.py Or script.sh && script.py


1

After discussion with the poster on chat, starting http://chat.stackexchange.com/transcript/message/20047753#20047753, it turned out the poster's machine is missing /usr/lib/python2.7, see http://chat.stackexchange.com/transcript/message/20052960#20052960. This accounts for most of the poster's problems. In particular, the errors: Could not find platform ...


1

If you want twinkle to place a call when you press your button, I would suggest that you get your key-monitoring program to use twinkle's command line to do that directly: twinkle -c --immediate --call sip:in06khattab@ekiga.net It would be far easier that all this fiddling around with ttys, etc. Or have I misunderstood your intent?


1

There are three possible reasons: The package in Ubuntu is broken or unconfigured. First is unlikely, it would be a bug report somewhere, and second is false since dpkg reports ii for installed packages. You are using an interactive python shell that was opened before you installed the module. This is the most likely reason. Just close the shell and open ...


1

You need to create the package file __init__.py in the directory dir.



Only top voted, non community-wiki answers of a minimum length are eligible