python

What could justify the complexity of Plone?

Plone is very complex. Zope2, Zope3, Five, ZCML, ZODB, ZEO, a whole bunch of acronyms and abbreviations. It's hard to begin and the current state seems to be undecided. It is mainly based on Zope2, but incorporates Zope3 via Five. And there are XML config files everywhere. Does the steep learning curve pay of? Is this complexity still ...

Creating a list of objects in Python

Hi, I'm trying to create a Python script that opens several databases and compares their contents. In the process of creating that script, I've run into a problem in creating a list whose contents are objects that I've created. I've simplified the program to its bare bones for this posting. First I create a new class, create a new ins...

Receive and send emails in python

How can i receive and send email in python? A 'mail server' of sorts. I am looking into making an app that listens to see if it recieves an email addressed to [email protected], and sends an email to the sender. Now, am i able to do this all in python, would it be best to use 3rd party libraries? ...

How can I download all emails with attachments from Gmail?

How do I connect to Gmail and determine which messages have attachments? I then want to download each attachment, printing out the Subject: and From: for each message as I process it. I never found a nice solution to this problem so I'm going to start a bounty. The person who provides the best answer wins. Please provide the complete...

Adding a mimetype in python

On my Centos server Python's mimetypes.guess_type("mobile.3gp") returns (None, None), instead of ('video/3gpp', None). Where does Python get the list of mimetypes from, and is it possible to add a missing type to the list? ...

Formatting a data structure into a comma-separated list of arguments

Hi, I need to convert a list (or a dict) into a comma-separated list for passing to another language. Is there a nicer way of doing this than: result = '' args = ['a', 'b', 'c', 'd'] i = 0 for arg in args: if i != 0: result += arg else: result += arg + ', ' i += 1 result = 'function (' + result + ') ...

How do I find the "concrete class" of a django model baseclass

I'm trying to find the actual class of a django-model object, when using model-inheritance. Some code to describe the problem: class Base(models.model): def basemethod(self): ... class Child_1(Base): pass class Child_2(Base): pass If I create various objects of the two Child classes and the create a queryset con...

How do I pass a python list in the post query?

I want to send some strings in a list in a POST call. eg: www.example.com/?post_data = A list of strings The python code receives the data as a single string (Instead of a list of strings). How do I post it as a list of strings? ...

Run a shortcut under windows

The following doesn't work, because it doesn't wait until the process is finished: import subprocess p = subprocess.Popen('start /WAIT /B MOZILL~1.LNK', shell=True) p.wait() Any idea how to run a shortcut and wait that the subprocess returns ? Edit: originally I was trying this without the shell option in my post, which caused Popen ...

Conway's Game Of Life

I am currently writting a programe about Conway's Game of life,and i am really a beginer of python,dont know how to start at all,anybody can help me with it? ...

Getting the lesser n elements of a list in Python

I need to get the lesser n numbers of a list in Python. I need this to be really fast because it's in a critical part for performance and it needs to be repeated a lot of times. n is usually no greater than 10 and the list usually has around 20000 elements. The list is always different each time I call the function. Sorting can't be mad...

Why is my Python C Extension leaking memory?

The function below takes a python file handle, reads in packed binary data from the file, creates a Python dictionary and returns it. If I loop it endlessly, it'll continually consume RAM. What's wrong with my RefCounting? static PyObject* __binParse_getDBHeader(PyObject *self, PyObject *args){ PyObject *o; //generic object PyObject*...

How does Django Know the Order to Render Form Fields?

If I have a Django form such as: class ContactForm(forms.Form): subject = forms.CharField(max_length=100) message = forms.CharField() sender = forms.EmailField() And I call the as_table() method of an instance of this form, Django will render the fields as the same order as specified above. My question is how does Django ...

What does the function set use to check if two objects are different?

Simple code: >>> set([2,2,1,2,2,2,3,3,5,1]) set([1, 2, 3, 5]) Ok, in the resulting sets there are no duplicates. What if the object in the list are not int but are some defined by me? What method does it check to understand if they are different? I implemented __eq__ and __cmp__ with some objects but set doesn't seems to use them :\ ...

Determine record in multi record html form

In a html form, I'm displaying multiple records from a table, ready for update. Right now I use: name=<column-name>_<pk-id> value=<value> for the fields. Then in my python-script I go for: for key in form.keys(): if key.startswith('<name-A>_'): update <table> set <name-A> = <value> where pk=<pk-id> if key.startswith('<n...

How do I get data from stdin using os.system()

The only reliable method that I a have found for using a script to download text from wikipedia is with cURL. So far the only way I have for doing that is to call os.system(). Even though the output appears properly in the python shell I can't seem to the function it to return anything other than the exit code(0). Alternately somebody co...

How do I mock an IMAP server in Python, despite extreme laziness?

I'm curious to know if there is an easy way to mock an IMAP server (a la the imaplib module) in Python, without doing a lot of work. Is there a pre-existing solution? Ideally I could connect to the existing IMAP server, do a dump, and have the mock server run off the real mailbox/email structure. Some background into the laziness: I ha...

Python method arguments with spaces

I would like to create a simple file format/DSL which would allow my users to input data. My system is in python and using python's parser is appealing. Syntax like this for defining a data element seems quite convenient. Allocation(Param1 = Val1, Param2 = Val2 ) However, it does not support param names with spaces. Allocation(Para...

destroying a Toplevel tk window in python

I was trying to write code that would auto-close a Toplevel Tk window in Python. I ended up getting it to work, but ran into a little problem along the way that I wasn't able to figure out. The second two buttons work, but the first one doesn't and I don't understand why... Any ideas? from Tkinter import * root = Tk() def doDestroy ...

Python imaplib Gmail authenticate failure

I just ran into an issue with Python's imaplib and Gmail's authentication mechanism: >>> import imaplib >>> imap = imaplib.IMAP4_SSL('imap.gmail.com', 993) >>> imap.authenticate('[email protected]', 'Bob Dole likes your style!') Traceback (most recent call last): ... imaplib.error: AUTHENTICATE command error: BAD ['TODO (not supported...