Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.
14
votes
3answers
3k views
How does /usr/bin/env know which program to use?
When I use the shebang #!/usr/bin/env python to run a script, how does the system know which python to use? if I look for a python bin path in the environment variables I find nothing.
env | grep -i ...
12
votes
2answers
5k views
What is the proper way to manage multiple python versions?
I have a machine with Python 2.6 installed as the default Python. Then, I installed Python 2.7, and manually created /usr/bin/python as a symlink to the new installation.
Then, I was running into ...
11
votes
5answers
3k views
Using different versions of Python
Background:
Since I develop python programs that must run on different python versions, I have installed different versions of python on my computer.
I am using FC 13 so it came with python 2.6 ...
11
votes
2answers
5k views
Best way to upgrade vim/gvim to 7.3 in Ubuntu 10.04?
I have to use Ubuntu 10.04 at work, and cant upgrade it. I'm using Vim/gVim 7.2.
I want to upgrade it to 7.3 (with Python and Ruby extension support). Which is the best way? Add an entry in ...
10
votes
5answers
2k views
How can I use environment variables in my shebang?
I have a Python script that need to be run with a particular python installation.
Is there a way to craft a shebang so that it runs with $FOO/bar/MyCustomPython?
8
votes
2answers
636 views
View Script Over SSH?
A friend, using a remote machine, SSHed to my machine and ran the following python script:
while (1):
....print "hello world"
(this script simply prints 'hello world' continuously).
I am now ...
8
votes
1answer
426 views
python == python2 OR python == python3 ? How to package, distribute python py2k scripts?
Depending on system, python==python2 or python==python3.
Executable Python scripts, starts with:
#!/usr/bin/env python
#!/usr/bin/env python2
#!/usr/bin/env python3...
For python py3k it is ...
7
votes
2answers
2k views
How can I rename photos, given the EXIF data?
Let's say I have a bunch of photos, all with correct EXIF information, and the photos are randomly named (because of a problem I had). I have a little program called jhead which gives me the below ...
7
votes
1answer
221 views
Problems running python script from motion
I'm trying to set up the raspberry pi with my webcam as a motion detecting cctv that uploads the videos to google drive using Jeremy Blythe's script
I have motion working correctly and the python ...
7
votes
3answers
295 views
Is it possible to execute scripts in BIND based on lookup
Is it possible, to set up BIND as DNS server on my local network, and make execute scripts when it gets a lookup?
I would like to execute a Python or Bash script, based on the incoming DNS lookup, ...
6
votes
5answers
476 views
How can I have more than one possibility in a script's shebang line?
I'm in a bit of an interesting situation where I have a Python script that can theoretically be run by a variety of users with a variety of environments (and PATHs) and on a variety of Linux systems. ...
6
votes
1answer
3k views
How can I start the python SimpleHTTPServer on port 80?
I am using this command on Ubuntu but it is starting on port 8080 and I don't have another server running so I'd like it to start on port 80. I saw ways that you could set up a bash script to do ...
6
votes
2answers
960 views
Which window manager has Python bindings?
I've been coding bits here and there with Python and I'm most interested in Desktop Environments, for which I always have ideas I want to try out.
I have tried to play around with python-xlib but ...
5
votes
4answers
158 views
Hybrid code in shell scripts. Sharing variables
This answer discusses how to run a multi-line Python snippet from the command line in a terminal. I noticed that the answer works great within shell scripts, even with nested indentation, which is ...
5
votes
2answers
4k views
Why is this python error message generated whenever I type a nonsense command?
Whenever I type any "nonsense" command, this python error message is generated. Normal commands work fine. Any idea how to debug this?
$ somenonexistingcommand
Traceback (most recent call last):
...
5
votes
1answer
63 views
Correct handling of Python2 and Python3
What is the correct way running scripts that depend on python2.x but on a system where python3.x is aliased with python.
The solution should take into account the following things :
Python2 ...
5
votes
1answer
250 views
How to stop python from looking for .py files
I have a system with very little resources (embedded). Because of that I only installed the python .pyo files (=byte compiled & optimized) for my program. Now when such a program runs, python ...
5
votes
1answer
478 views
Measuring Python script bandwidth usage
I have a python script that uses urllibs to parse some web pages, and uses selenium to scrape pages with javascript, and I would like to know its cumulative bandwidth usage. I've looked at nethogs, ...
5
votes
1answer
106 views
Using OGG/Vorbis, is there a way to continue to record to an existing audio file?
I am using Vorbis/ogg to record audio (using arecord and then pipping to oggenc). I have downloaded oggvideotools, which gave me oggCat, which will let me join two previously recorded audio files into ...
4
votes
3answers
146 views
Delete XML node containing certain element
I want to remove all Placemarks from a KML file that contain the element <tessellate>. The following block should be wholly removed:
<Placemark>
...
4
votes
1answer
274 views
How to get the name of the user that launched `sudo`
My problem: I have a Python program, and the user launch it using sudo. Sometimes I have to get the user's home, and I can do this only knowing its name:
import pwd
pwd.getpwnam(username)
So: how ...
4
votes
3answers
283 views
On which unix distributions is Python installed as part of the default install?
Does anyone know of an overview that would document on which (recent) UNIX distributions Python is available by default, i.e. part of the default installation?
PS: Answers from StackOverflow, before ...
4
votes
2answers
1k views
Configure Python to include another directory when looking for packages
I'm on a SUSE machine where the default Python site-packages location is /usr/lib64/python2.6/site-packages. Some packages automatically install themselves in /usr/lib/python2.6/site-packages instead. ...
4
votes
4answers
5k views
Run Python script on startup
Running on Ubuntu Karmic. I need to execute the following (updated) script at boot time
#!/bin/sh
# /etc/init.d/scripts
# Description: Starts Python scripts
# ————————————————–
#
### BEGIN INIT INFO
...
4
votes
2answers
2k views
Arch Linux: python and python2 are in conflict
I've recently installed Arch Linux onto my primary (Ubuntu) computer, and it is working really well for me. It's fast, configurable, basically a faster version of Ubuntu.
Since compiz-fusion isn't ...
4
votes
6answers
249 views
What is the easiest way to check if column A and B values goes both ways with AWK? [closed]
What is the easiest way to check if column A and B values goes both ways?
Output to check:
Mike John
John Mike
Pamela Barbara
Barbara Pamela
Mike Paul
Roger Paul
Desired output
Mike <-> ...
4
votes
1answer
569 views
On Debian, how do I add a Python package in dist-packages to a virtualenv?
Given some python package in /usr/share/pyshared/ or /usr/lib/pythonX.Y/dist-packages/ (take python-numpy or python-scipy for example), how do I add that package to a virtualenv?
When adding the ...
4
votes
1answer
861 views
How can I run tcpdump from a Python script without AppArmor complaining?
For inconvenient reasons going beyond the scope of this question, I have to run tcpdump from within a Python script. I currently just call subprocess.Popen(['tcpdump', ...) and everything works just ...
3
votes
2answers
2k views
Running python script from terminal without .py extension
I want to call a python script script.py from the terminal by simply typing script. Is this possible? If so, how?
I know I can avoid typing python script.py by adding #!/usr/bin/env python to the top ...
3
votes
2answers
534 views
Sending the output from 'dd' to awk/sed/grep
I'm trying to approximate the computer's write speed using dd:
dd if=/dev/urandom of=/dev/null bs=1K count=10000
which gives the following output
10000+0 records in
10000+0 records out
10240000 ...
3
votes
3answers
2k views
How can I upgrade pip on Ubuntu 10.04?
On Ubuntu 10.04 I've used apt-get install pip to install pip after which I installed django. Then I tried to uninstall django with pip via pip uninstall django which gives me:
pip: error: No command ...
3
votes
3answers
318 views
Why does installing python-minimal package also grab the python package on Debian?
From running:
apt-cache depends python2.6-minimal | grep Depends
and
apt-cache depends python2.6 | grep Depends
it looks like python2.6 depends on python2.6-minimal and a lot more.
However, ...
3
votes
4answers
286 views
Align a hex text file at 9 bytes each line
I want to align the selected portion of a text file at 9 bytes each column.
For example suppose my text file looks like below.
00 2f c6 b8 29 fd 02 37 11 00 9f 74 34 0b 60 72 38 20 00 9e 61 33 8e ...
3
votes
2answers
171 views
Print row contain maximum and minimum value
I need to read the file (contains 16K rows)and print the entire row if any of columns and all columns contains max value (100) and all columns contain min value (0).The ouput example is given
...
3
votes
3answers
214 views
Why can't I call this program using its full path?
I am trying to build a command line wrapper in Python 3 for an exiting command line tool called spooky and I am having a hard time understanding some strange behavior. If I type spooky on the command ...
3
votes
2answers
60 views
Wait for a X window to appear/disappear (in a sane way)
Inside a shell script, I need to wait for a window that has a string on its title to appear, do some action, and then wait for it to disappear, and do some other action.
Until yesterday, I had this ...
3
votes
3answers
34 views
How can you change the process name of Wing IDE from python to something more descriptive
In my process list under Ubuntu (using top/System Monitor) one of the largest memory hogs (200+Mb) was python. I searched a bit for one of my programs to be the cause until I realised this was my ...
3
votes
3answers
441 views
How do I make python programs behave like proper unix tools?
I have a few Python scripts laying around, and I'm working on rewriting them. I have the same problem with all of them.
It's not obvious to me how to write the programs so that they behave like ...
3
votes
6answers
4k views
Python 2.7 on CentOS 5
Are there any half-official repositories for CentOS 5 with Python 2.7?
EPEL provides only Python 2.6
3
votes
2answers
63 views
Clearing/modifying previous libnotify notifications?
I have written a script which generates notifications like this:
notify-send -i audio-card "Transferring audio playback to speakers." \
"Audio playback has been transferred to the analog output ...
3
votes
1answer
511 views
How to use cron + python to regularly adjust screen brightness?
I want to use cron and this script (http://askubuntu.com/questions/23593/use-webcam-to-sense-lighting-condition-and-adjust-screen-brightness):
import opencv
import opencv.highgui
import time
import ...
3
votes
2answers
2k views
How to install Python 3.x on Debian?
Being new to Linux, I chose Debian for my Linode because it seemed stable and secure. Now I want to write some sysadmin-type scripts in Python to teach myself the language. Based on this SO question ...
3
votes
1answer
471 views
Can I upgrade to a new version of Python on an old version of Ubuntu?
I have Ubuntu 8.04.3 LTS and ran this:
$ sudo apt-get install python2.7
I got this:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Couldn't find ...
3
votes
1answer
207 views
Suddenly I have troubles plotting with python
I have a code that I used yesterday to generate plots. Today, when I tried to use it (with the same input as yesterday), I get an error:
QGtkStyle was unable to detect the current GTK+ theme.
...
3
votes
1answer
2k views
How to do a binary install of Python 2.7 on SUSE Linux Enterprise Server 11?
My SLES11 box came with Python 2.6 installed. I would like to upgrade to 2.7. What is the easiest way to do this?
2
votes
4answers
566 views
How can I run a process in a terminal window and then hide that window?
I want to run python ~/program/proxy.py in a terminal when I boot up. And then hide this terminal window (because it is just a proxy program, and I don't want to see the debug info). So how can I get ...
2
votes
2answers
963 views
What is the python equivalent of grep -v?
I like grep -v. I use it all the time. But I am also doing some text processing in python, and there is one crucial thing that I lack.
Usually, I use grep -v to take extraneous stuff out of text.
...
2
votes
3answers
554 views
How to install StackApplet on Debian?
I would love to install StackApplet on Debian 6.0.2!
I downloaded 'stackapplet_1.4.0_all.deb' and ran following command:
root@debian:/home/dagrevis/Downloads# dpkg -i stackapplet_1.4.0_all.deb
...
2
votes
3answers
135 views
Is there an equivalent of calling the built-in python function help('topics') but in bash?
I would like to explore man pages in bash using something similar to the python help('topics') function. Does this exist in bash?
I know the bash equivalent of python's help('modules') would look ...
2
votes
1answer
119 views
emacs python2.7
I would like to have emacs work as a python ide for me. I can't seem to find how to compile from within emacs. I'm using python2.7 but when I do M-x python-mode it seems to compile using python2.7. Is ...

