Python is an interpreted, general, high-level programming language. The design emphasizes readability. It is notable for using tabs to indicate block levels. As a dynamic language, it shares many similarities to Ruby, Perl, and Scheme. The language is very popular for scientific computing and ...

learn more… | top users | synonyms

32
votes
6answers
18k views

emacs: how to indent/unindent region of python code by 4 spaces?

I have a region of python code selected in emacs. What are the most efficient ways to indent and unindent every line in it by 4 spaces? Ideally I'd like something that's not context sensitive (eg. ...
25
votes
4answers
69k views

How can I change the default Python version on Snow Leopard?

I recently upgraded my Mac OS X 10.5 Leopard install to 10.6 Snow Leopard, and with that came an upgraded version of Python, 2.6.1 (instead if 2.5.1). Now when I type python in the Terminal i still ...
18
votes
6answers
11k views

How to simulate slow internet connection

I currently deploy with GAE (google app engine) and I try to implement some AJAX validation. So I got a couple text-fields and "spinners" (ajax loaders) which should be displayed when an AJAX request ...
16
votes
2answers
3k views

Run Python scripts without explicitly invoking `python`

I'm using Debian Linux. I was wondering if there was a way to configure to run all Python scripts in the terminal by typing script.py (instead of python script.py).
16
votes
9answers
16k views

How to install matplotlib on OS X?

I want to install matplotlib on OS X. If possible, using homebrew. I installed Python 2.7.1 using brew install python, I modified my path to use it I installed pip using brew install pip I installed ...
15
votes
3answers
17k views

easy_install will not connect through proxy

I'm running Ubuntu Server 10.04 64-bit under VirtualBox, and it seems that everything except easy_install and pip can connect to the Internet. I have set and exported the http_proxy environment ...
15
votes
6answers
21k views

installing wxpython via pip or easy_install

I am running into some problems installing wxpython using pip. Here is my current output: [myuserid]% sudo pip install wxpython Downloading/unpacking wxpython Downloading ...
15
votes
3answers
56k views

How to globally modify the default PYTHONPATH (sys.path)?

On a Ubuntu (10.10) system, I have a Python package that installs itself into /usr/local/lib/python2.6/site-packages/. This isn't contained in the default path (sys.path). How do I add this directory ...
13
votes
6answers
3k views

What is the best method to remove duplicate image files from your computer?

I have a lot of duplicate image files on my Windows computer, in different subfolders and with different file names. What Python script or freeware program would you recommend for removing the ...
13
votes
2answers
3k views

How can I use the Homebrew Python with Homebrew MacVim on Mountain Lion?

I originally asked and answered this question: How can I use the Homebrew Python version with Homebrew MacVim? These instructions worked on Snow Leopard using Xcode 4.0.1 and associated developer ...
13
votes
4answers
23k views

How To Add Python to the Windows Path

How do I add python to the windows PATH permanently?
12
votes
3answers
2k views

Find outdated/updatable pip packages

pip freeze shows me the packages installed, but how do I check against pypi which ones are outdated?
12
votes
1answer
4k views

How can I use the Homebrew Python version with Homebrew MacVim on Snow Leopard?

Note: For Mountain Lion, see: How can I use the Homebrew Python with Homebrew MacVim on Mountain Lion? I've installed Python 2.7 with Homebrew on Mac OS X Snow Leopard. When I install MacVim ...
12
votes
1answer
19k views

How to find installation path for packages installed through apt-get in Ubuntu?

I have been installing python modules using apt-get which works great using the console or launching files from the command line. However I am using Eclipse for easier organisation of files. Eclipse ...
11
votes
7answers
51k views

How to install pip and easy_install on CentOS

I tried to install pip and easy_install on my CentOS but could not find them. How can I install them? Also, I have two versions of Python, 2.4 and 2.7. How will pip make sure to link newly installed ...
11
votes
9answers
9k views

Vim: execute the script I'm working on in a split screen

I'm working on a small python script, which needs frequent execution in order to debug and further develop. Can I split the vim screen and execute my script on one part with a keystroke?
11
votes
3answers
5k views

Python 2.6.1, pycrypto 2.3 pypi package: “Broken Pipe” during build

I am attempting to install Fabric, which requires pycrypto. During the build for pycrypto I always receive a "Broken Pipe" error. I don't know where to start to fix the problem. I'm running Mac OS X ...
11
votes
1answer
5k views

enabling colors in the python interactive shell on OS/X

I have just modified my .bash_profile so as to have colors in iTerm and Terminal. Now, I want to enable syntax highlighting for the Python interactive shell, IDLE-style. How to do that?
10
votes
2answers
10k views

How can I make a table of contents for a markdown document with Python/AWK/SED?

I have the following markdown document: Heading-a ========== ---text--- Heading-b ------------ --- text --- Heading-c ---------- --- text--- Heading-d ======= --- text---- Heading-e --- ... ...
9
votes
2answers
10k views

Python / Selenium / PhantomJS: “Unable to start phantomjs with ghostdriver.”

I'm trying to get Selenium to use phantomjs on a Windows machine. My code compiles without any error: from selenium import webdriver from selenium.webdriver.common.desired_capabilities import ...
9
votes
1answer
795 views

Why is Python for Windows not installed in %PROGRAMFILES% (“C:\Program Files”)?

Python was originally installed in C:\Program Files\Python, but that changed around 1.5. What was the reasoning behind that decision? Is it a bad idea to change the directory back, and if so, why?
9
votes
4answers
23k views

How do I write code of more than 1 line in the Python interpreter?

I have a problem coding Python in terminal. I'm just learning basics so I have no need to create .py files. In terminal I can run one line of code in the Python interpreter, but how do I write more ...
9
votes
4answers
12k views

How can I open Python files in IDLE from Windows?

I'm new to Python. I use Python 2.7 and I am running Windows Vista (64-bit). How do I make it when I click on .py scripts... that it opens up in IDLE so I can edit it a snap? Ya know... without having ...
9
votes
1answer
3k views

How to set up a own Chrome sync server?

I'm trying to set up a sync server for Chromium/Chrome, but i'm totally failed. I also couldn't find a How-To (like this here for Firefox) for that. I only found this question from '10 on superuser ...
8
votes
3answers
722 views

How can I run my python program directly from the shell?

I wrote a script. When it starts, it won't stop, and it keeps getting data from the Internet. I can call it this way: cd /User/Desktop/project/internetScanner/ python3 main.py start But I would ...
8
votes
5answers
7k views

Adding programming code into LaTex / LyX

Maybe I'm just being thick, but I can't find any sensible way to simply paste in my (python) code into latex without losing all the indent information (kinda important for python). Anyone got any ...
8
votes
3answers
934 views

`which python` points to the python I want, but `python` runs the wrong version

I want to use python24 provided by ports, so I've installed it, and python_select -s shows that the version I want is indeed selected. Running which python gives /opt/local/bin/python, and running ...
8
votes
6answers
8k views

Installing pygame on Snow Leopard's system Python 2.6

Snow leopard has python 2.6 included now, and I want to install pygame on it, but it says its for Python from python.org, not system python. I tried using setup.py from source, but it didn't work. Is ...
8
votes
2answers
105 views

Is it possible to modify bash to run one command through another (say a python script)?

I was wondering if it is possible to modify bash such that when I type command --arg1 what actually happens is ~/prerun.py command --arg1 (prerun.py would handle starting command --arg1 itself) ...
7
votes
11answers
16k views

Scripting: what is the easiest to extact a value in a tag of a XML file?

I want to read a pom.xml ('Project Object Model' of Maven) and extract the version information. Here is an example: <?xml version="1.0" encoding="UTF-8"?><project ...
7
votes
5answers
38k views

Updating Python on Ubuntu system

I want to update the Python build on my Linux box, but the only way I know how to do it is uninstalling the current version and installing the new one. My system is already up to date (I updated ...
7
votes
1answer
2k views

%paste magic function on ipython3

I'm using ipython3, installed on Ubuntu with apt-get. I can't use the paste magic function, it complains about missing Tkinter. But I do have Tkinter and the same thing works fine on ipython (2). ...
7
votes
2answers
3k views

cron can't read PYTHONPATH environment variables?

I have added to the PYTHONPATH on my server's .bash_profile file. However it appears that cron isn't reading from it because I am getting import errors. If I run the exact command cron calls on the ...
7
votes
1answer
719 views

Get Python to raise MemoryError instead of eating all my disk space

If I run a Python program with a memory leak, I would normally expect the program to eventually die with MemoryError. But instead, what happens is that all the virtual memory is used until my disk ...
7
votes
4answers
2k views

How can I prevent the python.el that ships with Emacs 23 from EVER loading?

I use python-mode.el instead of python.el for python work, and all of my customizations depend on it. However, periodically for some reason the python.el that ships with Emacs23 will magically get ...
7
votes
5answers
2k views

How do I change the file association to a program with the same name in Windows 7?

Windows 7's file association controls have been "simplified" and now I appear to be unable to change the default association of a file (in my case a Python script) to a different executable. If I ...
7
votes
3answers
4k views

OS X Lion easy_install requires sudo …?

I'm on OS X Lion and wanting to setup python virtual environments. I want to use virtualenvwrapper. Can someone confirm that the correct way to do this is to install packages via easy_install (and ...
7
votes
1answer
2k views

When a Python process is killed on OS X, why doesn't it kill the child processes?

I found myself getting very confused a while back by some changes that I found when moving Python scripts from Linux over to OS X... On Linux, if a Python script has called os.system(), and the ...
7
votes
3answers
4k views

Preferred way to install multiple python versions on Ubuntu Jaunty

Situation: Jaunty ships with 2.6, which does not fit my needs because many libraries are still failing. I want to have a system default 2.5. Also, for testing purposes, I need 2.6, 2.5 and 2.4 ...
6
votes
2answers
23k views

Why is pip not listed in easy_install on CentOS 6? Where to get it?

I am trying to install pip for python on CentOS 6. I thought of installing it through easy_install but it is not there. I tried to find easy_install with find command, but no luck. I tried to ...
6
votes
7answers
14k views

How to convert .xlsx to .txt?

I want to know if there is a Linux tool or a script available to convert .xlsx file to .txt.
6
votes
6answers
2k views

Force output buffer flush in running program

I have a long-running python script that periodically outputs data to standard output that I've invoked with something like: python script.py > output.txt This script has been running for a ...
6
votes
3answers
18k views

How do I properly update Python on Mac OS X

If I download python from the Python website and try to install it with the installer, it installs, but I need to specify that I want the new version of Python when I run my programs from terminal. If ...
6
votes
2answers
3k views

How do I add “input” to my macro, to replace text in Notepad++?

I'm trying to make a macro with an 'input' pop-up dialog that synergizes with the replace feature. It should go something like: "Paste text->ask for input->replace variable in pasted text with input ...
6
votes
4answers
7k views

Making `#!/usr/bin/env python` work on Windows

I use Bash on Windows, provided by MSYS. I tried to run a Python file with a shebang of #!/usr/bin/env python, but I get this error message: /usr/bin/env: python: No such file or directory What ...
6
votes
2answers
6k views

Error Installing python on Windows 7 x64

I am on Windows 7 x64, trying to install Python 2.7.5 or 3.3.2. But I'm continuously getting an error showing : "There is a Problem with this windows installer package. A DLL required for this install ...
6
votes
2answers
224 views

Unexpected shutdown with heavy single threaded process and single core affinity

I'm not sure what's the cause of the problem, but it happened 3 times in two weeks under similar conditions. I checked with the laptop's support desk and they made me run several tests to see if my ...
5
votes
2answers
12k views

“bad interpreter: Permission denied” How can I prevent this error?

I want to run program directly such as ./program without define the interpreter in shell first. so, how can i want to prevent this error? bad interpreter: Permission denied My operating system ...
5
votes
2answers
2k views

Extremely slow pypi package retrieval with i.e. pip

Finding python packages using tools such as pip or easy_install takes very long, up to ten minutes, on my local desktop running Ubuntu 12.10. The same procedures are lightning fast on my cloud ...
5
votes
4answers
3k views

Where can I find a gallery of Pygments CSS files

I googled every possible combination but I couldn't find a list of syntax files. Is there a list of good ones?