python

Combining two lists of objects based on an attribute

Every example of list or set usage in Python seems to include trivial cases of integers but I have two lists of objects where the name attribute defines whether two objects instances are "the same" or not (other attributes might have different values). I can create a list that contains all items from both lists, sorted, with tmpList =...

How to prevent boost::python::extract<float> from accepting int

I'm using boost::python::extract<> to convert the items in a boost::python::list to floats. My problem is with int's in python - extract<float> seems to regard int->float as a valid conversion, however I only want true float objects. Is there a way to force extract<> to be more conservative? extract<float> value(o); if (value.check()) {...

Nested Lists in Dict : Accessing members of list within the list of a dictionary

def index_dir(self, base_path): num_files_indexed = 0 allfiles = os.listdir(base_path) self._documents = os.listdir(base_path) num_files_indexed = len(allfiles) docnumber = 0 self._inverted_index = collections.defaultdict(list) docnumlist = [] for file in allfiles: self.documents = [base_path+...

how to know on which platform is remote machine running using python code

I just wanted to know that how can we fetch the platform on which a remote machine is running using Python? ...

Split string by number of words with python

How do I split up a string into several parts of a number of words in python. For example, turn a 10,000 word string into ten 1,000 word strings. Thanks. ...

python email special char

How can I send special character like registered symbol in a email's 'from' email string? E.g. Test® <[email protected]>. Do I require to set some headers? ...

Django 1.2: login issue (GET parameter: next)

Hello, I have a new question about django (I post a lost of them these days^^). Here is my situation : I have a custom login view (registered as login url in the settings) where I authenticate the users. I chose to do a custom view to be able to add messages and logging. The authentication works well, but I have a problem with the GET ...

Python mxTextTools ImportError: DLL load failed

I'm running python 2.7 on windows 7 and trying to get SimpleParse to work. This means I need mxTextTools, which I downloaded from . But when I try to import mx.TextTools, I get an ImportError saying it can't load a DLL (its nice that it doesn't tell me which one). Here is all the code needed to get the error to come up: from mx.TextTool...

Transition from small scripts to bigger apps is not easy

I believe that readability and the KISS principle are the most important things in programming. That's why I use Python :) And here is exact situation, which I encounter very often: Say, I have a nice and clean script, which is a wrapper for database handling: import database_schema as schema loader = schema.Loader("sqlite:///var/datab...

Python library for Amazon MWS

Is there a Python library for interacting with Amazon MWS? I found Ruby, Perl, PHP, C#, and Java versions, but not Python. ...

Celery, Django.. making a Task / thread launch sub-task / threads?

I'm using celery with django and am trying to get a Task, like the one below: class task1 (Task) def run (self): launch_some_other_task.delay() But it doesn't seem to be working, I can go into more detail as far as my code but figured I would just ask first if this sort of thing will work as doesn't seem to be working for me....

Is there a generator version of `string.split()` in Python?

string.split() returns a list instance. Is there a version that returns a generator instead? Are there any reasons against having a generator version? ...

Cancel a group of HTTP requests in twisted

I'm making several HTTP requests with twisted.web.client.getPage, and would like to be able to cancel some of them at the user's request. Ideally I would like to do something like: # Pseudocode, getPage doesn't work like this: getPage(url1, "group1") getPage(url2, "group1") getPage(url3, "group1") ... # Later on reactor.cancel_all("gro...

Doctests: How to suppress/ignore output?

The doctest of the following (nonsense) Python module fails: """ >>> L = [] >>> if True: ... append_to(L) # XXX >>> L [1] """ def append_to(L): L.append(1) class A(object): pass return A() import doctest; doctest.testmod() This is because the output after the line marked XXX is <__main__.A object at ...> (whic...

How can I find all subclasses of a given class in Python?

Hi! I need a working approach of getting all classes that are inherited from the base class in Python. Thanks. ...

Pickling objects

I need to pickle object [wxpython frame object] and send it as a prameter to this function apply_async on multiproccessing pool module could someone provide me an example how can I do it I tried the following and get an error message : myfile = file(r"C:\binary.dat", "w") pickle.dump(self, myfile) myfile.close() self.my_pool.apply_a...

send commands to a backgrounded jobs stdin

I have a java server application that, when its running, you can interact with it sending commands via stdin. I want to write a web interface that can send these commands to it. In order to do that I need some way of getting commands from php to the stdin for this backgrounded job. Is there a way to do this from console? or possibly wr...

How to run ruby file in the background using Python and get stderr and stout?

I am developing a Python based GUI. I need to run a ruby file and get its output. I did it successfully using subprocess module. But I need to run the file in the background and I need to get its output as well. Can you please let me know how to achieve this? ...

What are the full implications of not using the default 'id' primary_key in your Django model?

Consider the case where a CHAR field primary_key is required in order to define a ForeignKey relationship. After some initial investigation I have identified the following possibilities, each with their own drawbacks: 1) Using 'primary_key=True'. Example 1: class Collection(models.Model): code = models.CharField(primary_key=True,...

HTML form POST to a python script?

Does anyone know of any good resources for information on how to POST data from a HTML form over to a python script? ...