python

File indexing (using Binary trees?) in Python

Background I have many (thousands!) of data files with a standard field based format (think tab-delimited, same fields in every line, in every file). I'm debating various ways of making this data available / searchable. (Some options include RDBMS, NoSQL stuff, using the grep/awk and friends, etc.). Proposal In particular, one ide...

Looping over datasets in Python

I'm trying to write a Python script that will perform the same action on multiple databases. There are too many for me to input them by hand, so I'd like to write a script that will loop over them. Right now, I've gotten as far as the following before getting stuck: countylist = ['01001','01002','01003','01004'] for item in countylist: ...

create a grayscale image

Hi all, I am reading binary data from one file that specifies intensity values across x and y coordinates (not a open-source image format) and want to convert it to a PNG image (or other widely supported format). I have the data loaded into an array (using the array module) where each element is a integer from 0 to 255. To save this to ...

Selecting specific column in each row from array

I am trying to select specific column elements for each row of a numpy array. For example, in the following example: In [1]: a = np.random.random((3,2)) Out[1]: array([[ 0.75670668, 0.1283942 ], [ 0.51326555, 0.59378083], [ 0.03219789, 0.53612603]]) I would like to select the first element of the first row, the secon...

How to build 64-bit Python on OS X 10.6 -- ONLY 64 bit, no Universal nonsense

I just want to build this on my development machine -- the binary install from Python.org is still 32 bits and installing extensions (MySQLdb, for example) is driving me nuts with trying to figure out the proper flags for each and every extension. Clarification: I did NOT replace the system Python, I just installed the Python.org binary...

Django auth without "auth_*" tables

We would like to use our own tables for user management instead of the Django "auth" tables. We already have database tables that include all of the relevant information our application needs but it isn't in the Django format. We would prefer not to have the information duplicated in two tables. We would like to utilize the auth package...

What's the best practice for handling single-value tuples in Python?

I am using a 3rd party library function which reads a set of keywords from a file, and is supposed to return a tuple of values. It does this correctly as long as there are at least two keywords. However, in the case where there is only one keyword, it returns a raw string, not a tuple of size one. This is particularly pernicious because ...

Problem when using python logging in django and unicode

Hi there - totally confused by now... I am developing in python/django and using python logging. All of my app requires unicode and all my models have only a unicode()`, return u'..' methods implemented. Now when logging I have come upon a really strange issue that it took a long time to discover that I could reproduce it. I have tried b...

Math functions as well as flags

from django.db import models from django.contrib.auth.models import User class Product(models.Model): name = models.CharField(max_length = 127) description = models.TextField() code = models.CharField(max_length = 30) lot_no = models.CharField(max_length = 30) inventory = models.IntegerField() commited = models.IntegerField() available ...

Am I doing these unit tests right?

I'm new to unit tests for my own projects, so this is my first attempt to write a unit test from scratch. I'm using python, and the unittest module. The TodoList class being tested here is a wrapper for actual lists, with a few extra methods for stuff like saving to disc. It also defines a few methods for getting items by their ID in the...

How to encrypt a string in Python and decrypt that same string in PHP?

I have a string that I would like to encrypt in Python, store it as a cookie, then in a PHP file I'd like to retrieve that cookie, and decrypt it in PHP. How would I go about doing this? I appreciate the fast responses. All cookie talk aside, lets just say I want to encrypt a string in Python and then decrypt a string in PHP. Are th...

Python 2.x vs 3.x Speed

I'm a PhD student and use Python to write the code I use for my research. My workflow often consists of making a small change to the code, running the program, seeing whether the results improved, and repeating the process. Because of this, I find myself spending more time waiting for my program to run than I do actually working on it...

In Python in Google App Engine, how do you capture output produced by the print statement?

I am working in the Google Application Engine environment where I am loading doctests and python code from strings to test Python homework assignments. My basic implementation (Provided by Alex Martelli) appears to work for all of my problems except for those containing the print statement. Something seems to go wrong when I attempt to e...

generating promotion code using python

Hello By using python language, what would be a clever / efficient way of generating promotion codes. Like to be used for generating special numbers for discount coupons. like: 1027828-1 Thanks ...

Running Python & Django on IIS

Is it possible to run Python & Django on IIS? I am going to be a Lead Developer in some web design company and right now they are using classic ASP and ASP.NET. As far as I can see ASP.NET MVC is not mature. Should I recommend Python & Django stack? If it's not possible to run Python on IIS what do you think I should do? Stick with ASP.N...

Python: creating a grid

Is it possible to create a grid like below? I didn't found anything in the forum. #euler-project problem number 11 #In the 20 times 20 grid below, #four numbers along a diagonal line have been marked in red. #The product of these numbers is 26 times 63 times 78 times 14 = 1788696. #What is the greatest product of four adjacent numbers i...

Import vs C's #include

In C: #include "foo.h" int main() { } I believe that "foo.h" effectively gets copied and pasted in at the spot of the "#include". Python imports are different though, I'm finding. I just refactored a bit of GAE code that initially had ALL request handlers in one big index.py file. NEW directory tree: + | +- [handlers] // all...

How do I fix PyDev "Undefined variable from import" errors?

I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module settings that defines a settings object. I import that in module b and assign an attribute with: from settings import settings settings.main = object() In some of my code--but not all of it, statements like: from s...

How do I fix PyDev "Method should have self as first parameter" errors

I'm developing in Python using PyDev in Eclipse, and some of my code generates errors in the code analysis tool. Specifically: class Group(object): def key(self, k): class Subkey(object): def __enter__(s): self._settings.beginGroup(k) return self def __exit__(s, type,...

Transparent FrameBuffer background in OpenGL

I want to use glClear and glClearColor to fill a frame buffer with a colour including alpha transparency. However the framebuffer always renders as opaque when binded to a texture which is rendered to the screen. I want everything which is rendered to the framebuffer to kept their transparency. I just want to change the background. See...