python

Dynamic linking and Python SWIG (C++) works in C++ fails in python

I have a library for which I have created a python wrapper using SWIG. The library itself accepts user provided functions which are in an .so file that is dynamically linked. At the moment I'm dealing with one that I have created myself and have managed to get the dynamic linking working... in C++. When I attempt to run it in python I ge...

Python Watch Folder - interrogating list for filesize

Hi All, I'm trying to get the following code to watch a folder for changes and return the filename (preferably a full path) as a string once it's checked that the filesize hasn't increased recently, to stop the rest of my script inspecting incomplete files. I'm having difficulty with sending my filesize timer function a filename because ...

How to read a raw image using PIL?

I have a raw image where each pixel corresponds to a 16 bits unsigned integer. I am trying to read using the PIL Image.fromstring() function as in the following code: if __name__ == "__main__": if (len(sys.argv) != 4): print 'Error: missing input argument' sys.exit() file = open(sys.argv[1], 'rb') rawData = ...

In Django, correctly making a queryset with multiple categories, multiple tags and search?

I have a list of data. This data model has many-to-many fields to both a categories model and a keywords model. The data model itself has a name and description. The data can have multiple categories and keywords. On the front end, the user can select a number of categories to filter down the data or do a search... So the data shown sho...

IPC solutions for Python processes on POSIX compliant system

Hi all, I have two Python processes that need to communicate with each other on POSIX complaint system, as an IPC I thought that using a named pipe would be the easiest solution, however since I'm new with Python I suspect there are more options available. Anyone care to make a recommendation, besides a named pipe? Thanks in advance, ...

How to get started with a bare-bones Eclipse + PyDev

I am planning to move from SPE to Eclipse + PyDev for better code completion. I think SPE's code completion is rather weird. Anyway, how should I get started with Eclipse + PyDev? I browsed http://www.eclipse.org and I found that Eclipse is made up of some base/core system and plugins are added for more functionality. I also stumbled up...

Django: Model field for storing a list of floats?

I want to store a variable-length list of floats in Django. There is the CommaSeparatedIntegerField, but is there anything like this that I could use? Would it be best to just implement my own CommaSeparetedFloatField or is there something that I am missing completely? Thanks. ...

Basic Python question: referencing original variable inside for loop?

Quick, newbie Python scoping question. How can I make sure that the original variables get changed in the for-loop below? for name in [name_level_1, name_level_2, name_level_3, name_level_4]: name = util.translate("iw", "en", name.encode('utf-8')) print name_level_1 In other words, I want the print statement to print out the chan...

In Django, how to get django-storages, boto and easy_thumbnail to work nicely?

I'm making a website where files are uploaded through the admin and this will then store them on Amazon S3. I'm using django-storages and boto for this, and it seems to be working just fine. Thing is, I'm used to use my easy_thumbnails (the new sorl.thumbnail) on the template side to create thumbnails on the fly. I prefer this approach,...

copy multiple files in python

How to copy all the files in one directory to another in python. I have the source path and the destination path in a string. ...

How can i change the __cmp__ function of an instance (not in class)?

How can i change the __cmp__ function of an instance (not in class)? Ex: class foo: def __init__(self, num): self.num = num def cmp(self, other): return self.num - other.num # Change __cmp__ function in class works foo.__cmp__ = cmp a = foo(1) b = foo(1) # returns True a == b # Change __cmp__ function in instance ...

how can i verify all links on a page as a black-box tester

I'm tryng to verify if all my page links are valid, and also something similar to me if all the pages have a specified link like contact. i use python unit testing and selenium IDE to record actions that need to be tested. So my question is can i verify the links in a loop or i need to try every link on my own? i tried to do this with _...

python: list index of out of range

for row in c: c1.append(row[0:13]) for row in c1: row.append(float(row[13])/100) row.append(float(row[12])/float(row[13])/100) row.append(math.log10(float(row[12]))) c contains a csv file with many rows and columns c1 is a subset of c containing only the first 14 elements i am getting IndexError: list index out of...

Optimize PDF conversion in Django / Python

Hi. I have a webapp that export reports in PDF. Everything is fine when the query returns less than 100 values. When the number of records raise above 100 the server raise a 502 Proxy Error. The report outputs fine in HTML. The process that hangs up the server is the conversion from html to PDF. I'm using xhtml2pdf (AKA pisa 3.0) to gene...

python: is there a frequency function?

in excel there is a frequency function: The Excel FREQUENCY function This useful function can analyse a series of values and summarise them into a number of specified ranges. For example the heights of some children can be grouped in to four categories of [Less than 150cm]; [151 - 160cm]; [161 - 170cm]; [More than 170cm...

Invoking a python script from a makefile in another directory

I have a makefile that invokes a python script that lives in the same directory as the makefile. It works just fine. In makefile #1: auto: ./myscript.py Now, I have another makefile, in another directory, and wish to call the first makefile from it. In makefile #2: target: cd $(DIR); $(MAKE) auto; The problem is, when the s...

Is there a processing python implementation ?

There are javascript and actionscript ports of Processing. Is there a python port ? ...

python: get number without decimal places

a=123.45324 is there a function that will return just 123? ...

How to use multiple Sessions in a pylons app?

I've read "Multiple database connections with Python + Pylons + SQLAlchemy" and I get how to create multiple engines using that technique, but now I'm looking for advice on how to handle the creation of Sessions for these engines. Right now, the Session in my project is defined as per Pylons convention: myapp.model.meta.Session = scoped_...

Get the current date as the default argument for a method

I've got a method: def do_something(year=?, month=?): pass I want the year and month arguments to be optional but I want their default to equal the current year and month. I've thought about setting two variables just before the method declaration but the process this is part of can run for months. It needs to be dynamic. Seems l...