python

Types for which "is" keyword may be equivalent to equality operator in Python

For some types in Python, the is operator seems to be equivalent to the == operator. For example: >>> 1 is 1 True >>> "a spoon" is "a spoon" True >>> (1 == 1) is (2 == 2) True However, this is not always the case: >>> [] == [] True >>> [] is [] False This makes sense for immutable types such as lists. However, immutable types suc...

How do I execute Python/bash code in the current directory as part of a code?

Lets say I am designing a tool foobuzzle (foobuzzle's exact job is to set up SRPM files for cross-compiling a variety of codes into their own compartmentalized prefix directories, but this is not important). I would like foobuzzle to take in an input file (buzzle_input) specified by an (intelligent, code-savvy) client, who will tell foo...

Handling large dense matrices in python.

Basically, what is the best way to go about storing and using dense matrices in python? I have a project that generates similarity metrics between every item in an array. Each item is a custom class, and stores a pointer to the other class and a number representing it's "closeness" to that class. Right now, it works brilliantly up to ...

problem with installing mod_wsgi

Hi, Trying, to figure out why make fails while installin mod_wsgi getting following errors. Can anyone help me out with to figure out what is wrong ? mod_wsgi.c:13910: warning: parameter names (without types) in function declarati on mod_wsgi.c:13910: warning: data definition has no type or storage class mod_wsgi.c:13915: error:...

Python sys.path not including script directory but script itself

As far as I know when running a Python script: python myscript.py, Python would by default include the script directory to the sys.path (in fact it should be sys.path[0]). On my machine (Mac OS 10.6.3, running Python 2.5.4) I do see a different behavior where the script itself is set as sys.path[0] instead of its directory. As you can i...

generating equation png files based on mathematical input

I was wondering what options were available to generate .png based on the kind of input one feeds a graphing calculator.. so (y^2 + 5x + 3) / ((3x + 3) + 5y + 18) would return The only thing I've found so far is texvc in mediawiki, but it seems overkill to get the whole mediawiki for one of it's modules. ...

Unpacking a 1-tuple in a list of length 1

Suppose I have a tuple in a list like this: >>> t = [("asdf", )] I know that the list always contains one 1-tuple. Currently I do this: >>> dummy, = t >>> value, = dummy >>> value 'asdf' Is there a shorter and more elegant way to do this? ...

From Java to Python/Django

Possible Duplicates: Book and tutorial recommedations for Django 1.0 How to Learn Python Hi, I am a Java/JEE programmer and want to learn Python (finally the Django framework) to build web applications. I don't have any experience with scripting languages so this is going to be the first step into the scripting languages wo...

sending raw bits to the terminal in python

As I understand it, files like /dev/urandom provide just a constant stream of bits. The terminal emulator then tries to interpret them as strings, which results in a mess of unrecognised characters. How would I go about doing the same thing in python, send a string of ones and zeros to the terminal as "raw bits"? edit I may have to cl...

How can I pass map<string,string> into py with API?

C/C++ can use python API to load py. But, only simple type is supported. How can I pass map into py to be a dict with API? Or, which methods are better? ...

Can i take package of cpython?

I used cpython api to load py from C/C++. But, if i want not setup cpython in client, can I take package dll of cpython in my program? How to do that? ...

Converting videos for iPhone - ffmpeg

Hi folks, I'm using the following command in order to convert .avi video files ffmpeg -i -f mpegts -acodec libmp3lame -ar 48000 -ab 64k -s 320×240 -vcodec libx264 -b 96k -flags +loop -cmp +chroma -partitions +parti4×4+partp8×8+partb8×8 -subq 5 -trellis 1 -refs 1 -coder 0 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 ...

Tkinter grid() Manager

I am having a bit of trouble with the Tkinter grid() manager. It is spacing the rows too far apart. I have two entry widgets to place, and I need one almost directly under the other. When I place them both on the same row and column, but change the pady option, it places them directly on top of each other. I know there has to be a way to...

Updating my program, using a diff-based patch approach

Currently my program updates itself by downloading the latest .tar.gz file containing the source code, and extracting it over the current directory where the program lives. There are 2 "modes" of update - one for users running the Python source, and one if the user is running the program as a Windows exe. Over time my program's filesiz...

Sending Fax with python?

Ok, we aren't in the mid-1980s any more, but anyway. Are there any fax libraries for python? ...

Escaping chars in Python and sqlite

Hi, I have a python script that reads raw movie text files into an sqlite database. I use re.escape(title) to add escape chars into the strings to make them db safe before executing the inserts. Why does this not work: In [16]: c.execute("UPDATE movies SET rating = '8.7' WHERE name='\'Allo\ \'Allo!\"\ (1982)'") --------------...

How to filter (or replace) unicode characters that would take more than 3 bytes in UTF-8?

I'm using Python and Django, but I'm having a problem caused by a limitation of MySQL. According to the MySQL 5.1 documentation, their utf8 implementation does not support 4-byte characters. MySQL 5.5 will support 4-byte characters using utf8mb4; and, someday in future, utf8 might support it as well. But my server is not ready to upgrad...

Check if python int is too large to convert to float

Is there any way to check if a long integer is too large to convert to a float in python? ...

How do I install an old version of Django on virtualenv?

This may sound like a stupid question, since the very purpose of virtualenv is to this exactly: Installing some specific version of a package (in this case Django) inside the virtual environment. But it's exactly what I want to do, and I can't figure it out. I'm on Windows XP, and I created the virtual environment successfully, and I'm ...

How to Customize the time format for Python logging?

I am new to Python's logging package and plan to use it for my project. I would like to customize the time format to my taste. Here is a short code I copied from a tutorial: import logging # create logger logger = logging.getLogger("logging_tryout2") logger.setLevel(logging.DEBUG) # create console handler and set level to debug ch = l...