python

Small Python optional arguments question

I have two functions: def f(a,b,c=g(b)): blabla def g(n): blabla c is an optional argument in function f. If the user does not specify its value, the program should compute g(b) and that would be the value of c. But the code does not compile - it says name 'b' is not defined. How to fix that? Someone suggested: def g(b): ...

Interpret this particular REGEX

I did a REGEX pattern some time ago and I don't remember its meaning. For me this is a write-only language :) Here is the REGEX: "(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,10})$" I need to know, in plain English, what does it means. ...

Migrating Django Application to Google App Engine?

Hello, I'm developing a web application and considering Django, Google App Engine, and several other options. I wondered what kind of "penalty" I will incur if I develop a complete Django application assuming it runs on a dedicated server, and then later want to migrate it to Google App Engine. I have a basic understanding of Google's ...

Which are good Python - Django hosting solutions?

I'm looking for a hosting provider for my Python-Django project. I need suggestions in terms of both shared space and managed server solutions. Of course, in case of shared space, Python execution through CGI is not an option. For now, I'm concerning Slicehost or Linode... Anyone with other recommendations? Thanx ...

Python script: import sys failing on WinXP setup

I'm trying out a hello world python script on WinXP. When I execute: python test.py arg1.log I get an error for the first line of the script, which is 'import sys': File "test.py", line 1, in <module> i NameError: name 'i' is not defined Any suggestions? ...

PyQt: event is not triggered, what's wrong with my code?

I'm a Python newbie and I'm trying to write a trivial app with an event handler that gets activated when an item in a custom QTreeWidget is clicked. For some reason it doesn't work. Since I'm only at the beginning of learning it, I can't figure out what I'm doing wrong. Here is the code: #!/usr/bin/env python import sys from PyQt4.QtC...

How to put infinity and minus infinity in Django FloatField?

I am trying to put infinity in a FloatField, but that doesn't seem to work. How do I solve this? f = DjangoModel(float_value=float('inf')) #ok f.save() #crashes Results in: Traceback (most recent call last): ... ProgrammingError: column "inf" does not exist LINE 1: ... "float_value") VALUES (inf) I'm using Django 1.0.2 with Postgre...

Live RX and TX rates in linux

I'm looking for a way to programatically (whether calling a library, or a standalone program) monitor live ip traffic in linux. I don't want totals, i want the current bandwidth that is being used. I'm looking for a tool similar (but non-graphical) to OS X's istat menu's network traffic monitor. I'm fairly certain something like this ex...

Java Python Integration

I have a Java app that needs to integrate with a 3rd party library. The library is written in Python, and I don't have any say over that. I'm trying to figure out the best way to integrate with it. I'm trying out JEPP (Java Embedded Python) - has anyone used that before? My other thought is to use JNI to communicate with the C bindings f...

Base 62 conversion in Python

How would you convert an integer to base 62 (like hexadecimal, but with these digits: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'). I have been trying to find a good Python library for it, but they all seems to be occupied with converting strings. The Python base64 module only accepts strings and turns a single digi...

Using Python to convert color formats?

I'm working on a Python tool to convert image data into these color formats: RGB565 RGBA5551 RGBA4444. What's the simplest way to achieve this? I've used the Python Imaging Library (PIL) frequently. So I know how to load an image and obtain each pixel value in RGBA8888 format. And I know how to write all the conversion code manually...

Getting "Comment post not allowed (400)" when using Django Comments

I'm going through a Django book and I seem to be stuck. The code base used in the book is .96 and I'm using 1.0 for my Django install. The portion I'm stuck at is related to Django comments (django.contrib.comments). When I submit my comments I get "Comment post not allowed (400) Why: Missing content_type or object_pk field". I've fo...

Disabling Python nosetests

When using nosetests for Python it is possible to disable a unit test by setting the test function's __test__ attribute to false. I have implemented this using the following decorator: def unit_test_disabled(): def wrapper(func): func.__test__ = False return func return wrapper @unit_test_disabled def test_m...

How do you cast an instance to a derived class?

I am trying to use a little inheritance in a Python program I am working on. I have a base class, User, which implements all of the functionality of a user. I am adding the concept of an unapproved user, which is just like a user, with the addition of a single method. The User class has some methods that return a User object. This wi...

Platform for developing all things google?

I am interested in developing things for google apps and android using python and java. I am new to both and was wondering if a environment set in windows or linux would be more productive for these tasks? ...

Does Jython have the GIL?

I was sure that it hasn't, but looking for a definite answer on the Interwebs left me in doubt. For example, I got a 2008 post which sort of looked like a joke at first glance but seemed to be serious at looking closer. Edit: ... and turned out to be a joke after looking even closer. Sorry for the confusion. Actually the comments on tha...

What is the best plotting library for Python?

What Python plotting library do you recommend? It should be noted the following considerations: is it cross-OS? speed how clean it's interface? "prettyness" of the resulting plots License etc? In the Python Wiki there is a list, but there is little comparison between them. Interesting SO links (not quite duplicates, but usefull t...

Join Records on Multiple Line File based on Criteria

Hello, I am trying to write a python script that takes record data like this 6xxxxxxxx 7xxxxxxxx 6xxxxxxxx 7xxxxxxxx 7xxxxxxxx 6xxxxxxxx 6xxxxxxxx 6xxxxxxxx 7xxxxxxxx 7xxxxxxxx 7xxxxxxxx and performs the following logic newline = "" read in a record if the record starts with a 6 and newline = '' newline = record if the...

Using Python to execute a command on every file in a folder

Hello everyone, I'm trying to create a Python script that would : Look into the folder "/input" For each video in that folder, run a mencoder command (to transcode them to something playable on my phone) Once mencoder has finished his run, delete the original video. That doesn't seem too hard, but I suck at python :) Any ideas on wh...

Emulator Framework

Are there any good open source frameworks for developing computer system emulators? I am particularly interested in something written in Python or Java that can reduce the effort involved in developing emulators for 8-bit processors (e.g. 6502, 6510, etc.). ...