python

Problem using django mptt

Hi, I am having problem implementing django mptt. Here is my model: class Company(models.Model): name = models.CharField( max_length=100) parent = models.ForeignKey('self', null=True, blank=True, related_name='children') mptt.register(Company, order_insertion_by=['name']) And class Financials(models.Model): ...

How do I read/retrieve emails received by local postfix, through python

I am using postfix in my production server which will receive all the emails related to mydomain.com In this context, I want to forward only emails related to few users to different email addresses. By which I mean, lets say I am a super user([email protected]). I want to forward all my emails(all mails with to:[email protected]...

Python xml minidom. generate <text>Some text</text> element.

Hello! I have the following code. from xml.dom.minidom import Document doc = Document() root = doc.createElement('root') doc.appendChild(root) main = doc.createElement('Text') root.appendChild(main) text = doc.createTextNode('Some text here') main.appendChild(text) print doc.toprettyxml(indent='\t') The result is: <?xml version=...

Python includes, module scope issue

Hi everyone, I'm working on my first significant Python project and I'm having trouble with scope issues and executing code in included files. Previously my experience is with PHP. What I would like to do is have one single file that sets up a number of configuration variables, which would then be used throughout the code. Also, I wan...

How do i install pyCurl?

I am VERY new to python. I used libcurl with no problems and used pyCurl once in the past. Now i want to set it up on my machine and dev. However i have no idea how to do it. I rather not DL libcirl files and compile that along with pycurl, i want to know the simplest method. I have libcurl installed on my machine. i'm on windows, i tri...

Fast PDF splitter library

pyPdf is a great library to split, merge PDF files. I'm using it to split pdf documents into 1 page documents. pyPdf is pure python and spends quite a lot of time in the _sweepIndirectReferences() method of the PdfFileWriter object when saving the extracted page. I need something with better performance. I've tried using multi-threading...

get site name from a URL in python

I am new to Python and it seems to have a lot of nice functions that I don't know about. What function can I use to get the root site name? For example, how would I get faqs.org if I gave the function the URL "http://www.faqs.org/docs/diveintopython/kgp_commandline.html"? ...

Is there a good dependency analysis tool for Python?

Dependency analysis programs help us organize code by controlling the dependencies between modules in our code. When one module is a circular dependency of another module, it is a clue to find a way to turn that into a unidirectional dependency or merge two modules into one module. What is the best dependency analysis tool for Python co...

Why does Django only serve files containing a space?

I'm writing a basic Django application. For testing / development purposes I'm trying to serve the static content of the website using Django's development server as per http://docs.djangoproject.com/en/dev/howto/static-files/#howto-static-files. My urls.py contains: (r'^admin/(.*)', admin.site.root), (r'^(?P<page_name>\S*)$',...

AUTO_INCREMENT in sqlite problem with python

I am using sqlite with python 2.5. I get a sqlite error with the syntax below. I looked around and saw AUTOINCREMENT on this page http://www.sqlite.org/syntaxdiagrams.html#column-constraint but that did not work either. Without AUTO_INCREMENT my table can be created. An error occurred: near "AUTO_INCREMENT": syntax error CREATE TABLE f...

Multidimensional array in Python

Hi, I have a little Java problem I want to translate to Python. Therefor I need a multidimensional array. In Java it looks like: double dArray[][][] = new double[x.length()+1][y.length()+1][x.length()+y.length()+3]; dArray[0][0][0] = 0; dArray[0][0][1] = POSITIVE_INFINITY; Further values will be created bei loops and written into the...

Python time to age

I'm trying to convert a date string into an age. The string is like: "Mon, 17 Nov 2008 01:45:32 +0200" and I need to work out how many days old it is. I have sucessfully converted the date using: >>> time.strptime("Mon, 17 Nov 2008 01:45:32 +0200","%a, %d %b %Y %H:%M:%S +0200") (2008, 11, 17, 1, 45, 32, 0, 322, -1) For some reason %...

A replacement for python's httplib?

I have a python client which pushes a great deal of data through the standard library's httlib. Users are complainging that the application is slow. I suspect that this may be partly due to the HTTP client I am using. Could I improve performance by replacing httplib with something else? I've seen that twisted offers a HTTP client. It ...

How to overwrite some bytes in the middle of a file with Python ?

I'd like to be able to overwrite some bytes at a given offset in a file using Python. My attempts have failed miserably and resulted : - either in overwriting the bytes at given offset but also truncating the file just after (file mode = "w" or "w+") - or in appending the bytes at the end of the file (file mode = "a" or "a+") Is it...

good primer for python slice notation

Can anyone recommend a good concise reference for the Python slice notation? I'm a seasoned programmer but new to Python and this notation needs a bit of picking up. It looks extremely powerful, but I haven't quite got my head round it and am looking for a good guide. ...

Passing self to class functions in Python

What's the reason of passing a value for a self reference in class functions in python? For instance: class MyClass: """A simple example class""" i = 12345 def f(**self**): return 'hello world' By doing this, aren't you doing the compiler's work? ...

python reading lines w/o \n ?

Would this work on all platforms? i know windows does \r\n, and remember hearing mac does \r while linux did \n. I ran this code on windows so it seems fine, but do any of you know if its cross platform? while 1: line = f.readline() if line == "": break line = line[:-1] print "\"" + line + "\"" ...

Python M2Crypto - generating a DSA key pair and separating public/private components

Could anybody explain what is the cause of the following: >>> from M2Crypto import DSA, BIO >>> dsa = DSA.gen_params(1024) ..+........+++++++++++++++++++++++++++++++++++++++++++++++++++* ............+.+.+..+.........+.............+.....................+. ...+.............+...........+......................................... +.........+...

Python quotient vs remainder

The python 2.6 docs state that x % y is defined as the remainder of x / y (http://docs.python.org/library/stdtypes.html#numeric-types-int-float-long-complex). I am not clear on what is really occurring though, as: for i in range(2, 11): print 1.0 % i prints "1.0" ten times, rather than "0.5, 0.333333, 0.25" etc. as I expected (1/2...

python chdir to dir the py script is in

How do i chdir to the directory that the python script is in? so far i figured out os.chdir and sys.argv[0]. I'm sure there is a better way then to write my own func to parse argv[0] ...