python

Matlab for Python programmers

I've used Matlab on and off before, but I need to develop a good understanding of it now, and the language I'm most familiar with is Python. Care to describe a Matlab language feature, idiom, best practice or philosophy as compared to Python? There's a terrific amount of buzz for and resources pertaining to going the opposite direction...

Is there a python equivalent of ruby's "Pathname" module?

Ruby has this really handy module called Pathname. Is there a python equivalent to it? ...

[Google App Engine] Sort by 2 fields? is there any hacks or with index.yaml? or geoPT?

q = WorldObject.all() # define boundaries # left q.filter('x >=', x) # right q.filter('x <', x + width) # top q.filter('y >=', y) # bottom q.filter('y <', y + height) #q.filter('world', world_key) wobjects = q.fetch(1000) I got an error saying I can't use multiple sorts q = WorldObject.all() q.filter('xy >=', db.GeoPt(1, 1)) q.filt...

Syntax error with IF statement in Python 3.0

I am teaching myself some Python and I have come across a problem which is probably plainly obvious, except that I can't see it and I need another pair of eyes. I am making a small game I made into a gui program. I have this section of code, which when run gives me "Traceback (most recent call last): File "", line 21, in Syntax Er...

Using cython .pxd files to Augment pure python files

Following the example here, "Augementing .pxd", I'm trying to use ".pxd" files to augment a pure python file. (Add type definitions external to the pure python file). python file: class A(object): def foo(self, i=3, x=None): print "Big" if i > 1000 else "Small" pxd file: cdef class A: cpdef foo(self, int i, x) I've...

Uploading multiple files in Django without using django.forms

So I've created a form that includes the following item <input type="file" name="form_file" multiple/> This tells the browser to allow the user to select multiple files while browsing. The problem I am having is is that when reading / writing the files that are being uploaded, I can only see the last of the files, not all of them. I w...

Python -Intersection of multiple lists?

I am playing with python and am able to get the intersection of two lists: result = set(a).intersection(b) Now if d is a list containing a and b and a third element c, is there an built-in function for finding the intersection of all the three lists inside d? So for instance, d = [[1,2,3,4], [2,3,4], [3,4,5,6,7]] then the result sh...

error with django model query

hi guys, I encountered an error when doing the following retrieval: class status(models.Model): pid = models.IntegerField() phase = models.TextField() rejected = models.IntegerField() accepted = models.IntegerField() type = models.IntegerField(default=1) date = models.DateTimeField(primary_key = True) time_t...

How to access a data structure from a currently running Python process on Linux?

Hi, I have a long-running Python process that is generating more data than I planned for. My results are stored in a list that will be serialized (pickled) and written to disk when the program completes -- if it gets that far. But at this rate, it's more likely that the list will exhaust all 1+ GB free RAM and the process will crash, lo...

Django authentication from an automated source

I have a set of URL's in my django application that trigger certain actions or processes. This would be similar to cron jobs. I have a script that polls one or more of these URLS at some regular inverval and I'm interested in adding a layer of security. I'd like to set up an account for the script and require authentication before the...

Success unit testing pyinotify?

I'm using pyinotify to mirror files from a source directory to a destination directory. My code seems to be working when I execute it manually, but I'm having trouble getting accurate unit test results. I think the problem boils down to this: I have to use ThreadedNotifier in my tests, otherwise they will just hang, waiting for manual...

How to convert XML to Dict

I finding some great solution to convert XML to dict in python ...

Run a python script and a compiled c code without terminal or dock item in Mac OS X

Hi, For great help from stackoverflow, the development for the Mac version of my program is done. Now I need to deploy my program, and I was wondering if there is any way to "hide" my running Python code (it also runs .so library and it seems it makes a dock item to appear). The program is supposed to be running in the background and ...

My python code won't run outside of my IDE

The following code runs fine in my IDE (PyScripter), however it won't run outside of it. When I go into computer then python26 and double click the file (a .pyw in this case) it fails to run. I have no idea why it's doing this, can anyone please shed some light? This is in windows 7 BTW. My code: #!/usr/bin/env python import ma...

Python and ADNS, falling in infinite loop somewhere

I have written some code that queries adns. Problem with this code is that it gets stuck, how? Let me explain it: Say my dnslist is ["8.8.4.4", "8.8.8.8", "208.67.220.220", "208.67.222.222", "192.168.50.1"] It would pop a dns from the list and query againt it, now that means that DNS will be queried in reverse order No matter what i d...

Django 1.2 : strange logging behavior

Hello ! I have a really strange problem with the standard logging module used in django views. Sometimes it works perfectly and sometimes it does not log messages. Here is the structure of my code : /mysite/ (Django root) my_logging.py (logging configuration) settings.py views.py (global views) data_objects.py (objects ...

Google App Engine Python - sort by density in ListProperty

Hi all, Is that possible to return a db result which sort by density matching in ListProperty For example, I have a db.ListProperty(basestring) with below value: list_A = ['a1','a2','a3','a4','a5'] list_B = ['b1','b2','b3','b4','b5'] list_C = ['a1','a2','b1','b2','b3'] giving to_be_match_list = ['a1','b1','b2'] and return result in ...

how to pass class attribute and value to markdown syntax

Im using python markdown for my django project, when i have the value #/usr/bin/env python print "this is converted to html code block" the output is <pre><code> #/usr/bin/env python print "this is converted to html code block" </code><pre> Now my question is that how can i pass class attribute and value to code elem. Sample: ...

Get proccess ID with python

Could someone tell/show how to get the current proccess id with python on windows there are this function os.geteuid() but its only works with linux/unix could someone tell what it the pythonic way to get the current proccess id on windows. ...

Python argparse: How to insert newline the help text?

I'm using argparse in Python 2.7 for parsing input options. One of my options is a multiple choice. I want to make a list in its help text, e.g. from argparse import ArgumentParser parser = ArgumentParser(description='test') parser.add_argument('-g', choices=['a', 'b', 'g', 'd', 'e'], default='a', help="Some option, where\n" ...