python

Convert a Python int into a big-endian string of bytes

I have a non-negative int and I would like to efficiently convert it to a big-endian string containing the same data. For example, the int 1245427 (which is 0x1300F3) should result in a string of length 3 containing three characters whose byte values are 0x13, 0x00, and 0xf3. My ints are on the scale of 35 (base-10) digits. How do I d...

What's the quickest way for a Ruby programmer to pick up Python?

I've been programming Ruby pretty extensively for the past four years or so, and I'm extremely comfortable with the language. For no particular reason, I've decided to learn some Python this week. Is there a specific book, tutorial, or reference that would be well-suited to someone coming from a nearly-identical language, or should I jus...

I get "parent_id may not be NULL" when creating my Django model

I'm creating my own Group model; I'm not referring to the builtin Group model. I want each hroup to be a member of another group (it's parent), but there is the one "top" group that doesn't have a parent group. The admin interface won't let me create a group without entering a parent. I get the error personnel_group.parent_id may not be...

Snapshot Movies

I'm currently learning Python and have taken up several small projects to help learn the language. Are there currently any libraries (possibly PythonMagick) out there that are capable of extracting snapshots from .wmv, .avi, .mpg, or other movie formats with only command-line options (no GUI)? And if so, can anyone provide links to exa...

Problem installing pyscopg2 on Mac OS X

I have downloaded the latest build of pyscopg2 and have tried to build and install it using the directions provided. However i always get an error saying that 'w' is undeclared. Does anybody have any experience with this? ...

Is there a mod_python for Apache HTTP Server 2.2 and Python 2.6 or 3.0?

I poked around the mod_python website and I only found the files for Python 2.5 and earlier for Apache HTTP Server 2.2. I Googled around a little, without significant luck. Any suggestions? ...

Modelling a swiss tournament in Django

I'm trying to create models that represent a swiss tournament, with multiple rounds. Each round everyone will be paired up with another player, except in the case where there is an odd player out, when one player will get a bye. I need to keep track of the outcome of each pairing; i.e., which player won. Also, I'd like to be able to ef...

A ListView of checkboxes in PyQt

Hello, I want to display a QListView where each item is a checkbox with some label. The checkboxes should be visible at all times. One way I can think of is using a custom delegate and QAbstractListModel. Are there simpler ways? Can you provide the simplest snippet that does this? Thanks in advance ...

How to read Unicode characters from command-line arguments in Python on Windows

I want my Python script to be able to read Unicode command line arguments in Windows. But it appears that sys.argv is a string encoded in some local encoding, rather than Unicode. How can I read the command line in full Unicode? Example code: argv.py import sys first_arg = sys.argv[1] print first_arg print type(first_arg) print first_...

Parsing in Python: what's the most efficient way to supress/normalize strings?

Hello, I'm parsing a source file, and I want to "suppress" strings. What I mean by this is transform every string like "bla bla bla +/*" to something like "string" that is deterministic and does not contain any characters that may confuse my parser, because I don't care about the value of the strings. One of the issues here is string fo...

Is Twisted an httplib2/socket replacement?

Many python libraries, even recently written ones, use httplib2 or the socket interface to perform networking tasks. Those are obviously easier to code on than Twisted due to their blocking nature, but I think this is a drawback when integrating them with other code, especially GUI one. If you want scalability, concurrency or GUI integr...

Python equivalent of perl's dbi/DBD::Proxy access? (Perl DBI/DBD::Proxy for Python)

I have a perl script that interfaces with an existing database (type of database is unknown) through the DBI module, that I would like to access in python 2.6 on winXP. The perl code is: use DBI; my $DSN = "DBI:Proxy:hostname=some.dot.com;port=12345;dsn=DBI:XXXX:ZZZZZ"; my $dbh = DBI->connect($DSN); Can this be translated into a pyth...

Importing a python module to .net - "No module named signal"

I'm trying to import a Python module in a C# code like this: var setup = Python.CreateRuntimeSetup(null); var runtime = new ScriptRuntime(setup); var engine = Python.GetEngine(runtime); var module = engine.ImportModule("mymodule"); but I get an error saying "No module named signal", does this mean that ...

Is there an ipython equivalent for erlang?

Coming from Python I am looking for some "easy to try out" shell like Python has with ipython (preferably with Emacs support). In the Erlang shell you always have to first compile (c(...)) which slows down the experimental phase very much. ...

User-defined derived data in Django

How do I let my users apply their own custom formula to a table of data to derive new fields? I am working on a Django application which is going to store and process a lot of data for subscribed users on the open web. Think 100-10,000 sensor readings in one page request. I am going to be drawing graphs using this data and also showing ...

Cross-platform way of getting temp directory in Python

Hi all, Is there a cross-platform way of getting the path to the temp directory in Python 2.6? For example, under Linux that would be /tmp, while under XP C:\Documents and settings\\[user]\Application settings\Temp. Thanks! ...

How to write a vb.net code to compile C/C++ programs?

I'm trying to make a vb.net application that has got 2 textboxes, 7 radio buttons and 2 buttons(one named compile and the other 'run'). How can I load the content of a C/C++(or any programming language) file into the 1st textbox and on clicking the compile button, i should be able to show the errors or the C/C++ program in the 2nd textbo...

How do I upload pickled data to django FileField?

I would like to store large dataset generated in Python in a Django model. My idea was to pickle the data to a string and upload it to FileField of my model. My django model is: #models.py from django.db import models class Data(models.Model): label = models.CharField(max_length=30) file = models.FileField(upload_to="data") I...

How can I find the number of arguments of a Python function?

How can I find the number of arguments of a Python function? I need to know how many normal arguments it has and how many named arguments. Example: def someMethod(self, arg1, kwarg1=None): pass This method has 2 arguments and 1 named argument. ...

Measure Path Length in Blender Script?

In Blender (v2.48), how can I determine the length of a path (in Blender units) from a Python script? The value is available from the GUI: With the path selected, the Editing panel contains a PrintLen button. The length appears to the right when the button is pressed. How can I obtain this value programmatically from a Python script ru...