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

learn more… | top users | synonyms

25
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 ...
20
votes
3answers
5k 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 ...
13
votes
2answers
7k 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
5answers
6k 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 ...
12
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
4k 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?
9
votes
7answers
2k 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
2answers
4k 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
695 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
5answers
920 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. ...
8
votes
1answer
7k 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 ...
8
votes
2answers
741 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
642 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
1k 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
6k 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
1k 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
674 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
435 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
4answers
894 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 ...
6
votes
1answer
298 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
3answers
202 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
6k 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
1answer
91 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
658 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
760 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
1answer
178 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
2answers
1k 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
4answers
4k 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
4k 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
210 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
1answer
485 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
2answers
3k 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
3answers
745 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
2k 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
853 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
6answers
313 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
141 views

How Can I Automate the Change between a Python Script and a Nohup Python Script?

I have a Raspberry Pi connected to a digital temperature probe, which measures my fermenting beer. A python script reads the temperature every second and prints it to the console, and stores it in a ...
4
votes
2answers
317 views

fail2ban log parsing too slow on Raspberry Pi - options?

I'm running fail2ban on a Raspberry Pi at 950MHz which I cannot overclock further. The Pi is occasionally subject to SYN floods on particular ports. I've set up iptables to throttle the rate of SYNs ...
4
votes
1answer
1k 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
3answers
951 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> ...
3
votes
3answers
132 views

Rescue value from second last line

After I run a script, I've got the following lines: PyMOL(TM) Molecular Graphics System, Version 1.4.1. Copyright (c) Schrodinger, LLC. All Rights Reserved. Created by Warren L. DeLano, ...
3
votes
2answers
1k 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
508 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
362 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
1k 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 ...
3
votes
4answers
747 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, ...
3
votes
3answers
234 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 ...
3
votes
2answers
258 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
313 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 ...