Python is an interpreted, general-purpose high-level programming language whose design philosophy emphasizes code readability.

learn more… | top users | synonyms

26
votes
4answers
2k views

python vs bc in evaluating 6^6^6

I am evaluating the expression 6^6^6 using python and bc separately. The content of the python file is print 6**6**6. When I execute time python test.py, I get the output as real 0m0.067s ...
24
votes
3answers
9k 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 ...
16
votes
3answers
1k views

Why is coreutils sort slower than Python?

I wrote the following script to test the speed of Python's sort functionality: from sys import stdin, stdout lines = list(stdin) lines.sort() stdout.writelines(lines) I then compared this to the ...
15
votes
5answers
9k 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 ...
14
votes
1answer
15k 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 ...
13
votes
2answers
9k 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 ...
12
votes
2answers
6k 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 ...
11
votes
5answers
5k 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?
10
votes
7answers
7k views

How to restart the Python script automatically if it is killed or dies

I am running my Python script in the background in my Ubuntu machine (12.04) like this - nohup python testing.py > test.out & Now, it might be possible that at some stage my above Python ...
9
votes
4answers
7k views

Install PIL/Pillow via pip in Debian testing (Jessie)

On Debian testing (Jessie), when I try to install PIL or Pillow (python imaging libs) in a virtualenv via pip I get the following error: running egg_info writing Pillow.egg-info/PKG-INFO writing ...
9
votes
5answers
1k 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. ...
9
votes
3answers
6k 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 ...
9
votes
2answers
785 views

How to manage huge amount of files in shell?

$ ls ./dir_with_huge_amount_of_files/errors/ Suppose a directory is full of pictures with unix timestamps, I mean a lot measured in many GBs or even more. Shell-commands like ls will get ...
8
votes
4answers
2k 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 ...
8
votes
2answers
788 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
3answers
917 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
3answers
2k 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 ...
7
votes
4answers
9k 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): ...
7
votes
3answers
2k 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 ...
7
votes
1answer
1k 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
562 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
1answer
2k views

Using Atlas from scipy

I installed Ubuntu 12.04 64 bit. I need to work with python and scipy, I installed them and when I run the test: python -c "import scipy; scipy.test()" I get the message: ImportError: ...
6
votes
3answers
2k 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 ...
6
votes
1answer
153 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 ...
6
votes
1answer
336 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 ...
6
votes
1answer
50 views

“ValueError: _system not initialized” when using apt.VersionCompare

I wrote a bash script that has to compare two version strings to decide to download new version or not. The test relies on a Python script that does apt.VersionCompare(), which does version comparison ...
6
votes
2answers
134 views

Why does my Python background process end when SSH session is terminated?

I have a bash script that starts up a python3 script (let's call it startup.sh), with the key line: nohup python3 -u <script> & When I ssh in directly and call this script, the python ...
5
votes
2answers
338 views

how to read and modify fstab in python?

I want to automatically configure my fstab in python by running a script. I thought of using ConfigParser in python, but I am unable to use it properly.
5
votes
3answers
343 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 ...
5
votes
4answers
7k 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 ...
5
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 ...
5
votes
4answers
368 views

Using jq to extract values and format in CSV

I have the below json file: { "data": [ { "displayName": "First Name", "rank": 1, "value": "VALUE" }, { "displayName": "Last Name", "rank": 2, ...
5
votes
4answers
912 views

How do I get 'realpath' to find my symbolic link?

I am on MacOSX using bash as my shell. I have symbolic link, created like this: ln -s /usr/bin/python python2 I have a package that uses python2 and I want to create a symbol link in my current ...
5
votes
1answer
959 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
3answers
118 views

How to grab the oldest unread message from `mail` in a script?

In a script I am trying to finish writing now, I need to get the oldest unread message from the current user's mailbox (specifically, I need the subject line for this project). After extracting the ...
5
votes
1answer
1k views

FreeBSD: Can't install Python 2.7

I can't seem to be able to install Python 2.7 on my FreeBSD system. Here is some info: # portsnap update Ports tree is already up to date. Version: # uname -r 7.1-RELEASE Installation: # cd ...
5
votes
3answers
2k 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 ...
5
votes
1answer
248 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 ...
5
votes
1answer
60 views

Why is this Python package trying to use a non-existent gcc?

I'm trying to install PyCrypto for Python 3 on Solaris. Whether I do it via "python3 setup.py install" or "pip3 install pycrypto", I run into the same problem: a call is made to a gcc which does not ...
4
votes
5answers
5k 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 ...
4
votes
3answers
8k 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 ...
4
votes
2answers
463 views

Creating deb and rpm from the same source

Is there a standard for source packages to be able to build rpms, debs (and perhaps others) without too much customization? I'm talking mostly about Python, PyQt programs.
4
votes
2answers
7k 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. ...
4
votes
1answer
760 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
2k views

Recommended way of installing python packages on Arch

What's the recommended way of installing python packages on Arch? Searching for them on the AUR and installing them from there (or create a PKGBUILD file to make a package yourself) or using pip? I ...
4
votes
4answers
4k views

Running python script from Linux Terminal

I have downloaded this script named, pyAES.py and put it in a folder name codes, inside a Desktop directory of my Linux, According to this example, ...
4
votes
2answers
3k 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
2answers
550 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 ...
4
votes
1answer
2k views

How to display the name of the current Virtualenv?

I'm using virtualenv, virtualenvwrapper, zsh, oh-my-zsh, terminator, on Crunchbang. I'm trying to display the name of the current virtualenv like so workon example (example)... I've tried many ...
4
votes
1answer
790 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 ...