python

ISO encoded attachment names and python

First of all i don't have the code example on this computer, but i have an example that is quite similar. (http://docs.python.org/library/email-examples.html) The 4th one. My issue lies within this bit of code counter = 1 for part in msg.walk(): # multipart/* are just containers if part.get_content_maintype() == 'multipart': ...

Jython and python modules

I've just started using the PythonInterpreter from within my Java classes, and it works great! However, if I try to include python modules (re, HTMLParser, etc.), I'm receiving the following exception (for re): Exception in thread "main" Traceback (innermost last): File "", line 1, in ? ImportError: no module named re How could I m...

How do I remove VSS hooks from a VS Web Site?

I have a Visual Studio 2008 solution with 7 various projects included with it. 3 of these 'projects' are Web Sites (the kind of project without a project file). I have stripped all the various Visual Sourcesafe files from all the directories, removed the Scc references in the SLN file and all the project files that exist. I deleted th...

Python - why compile?

This may seem like a dumb question, but why would you compile a python script? You can run them directly from the .py file and it works fine, so is there a performance advantage or something? I also notice that some files in my application get compiled into .pyc while others do not, why is this? ...

What is the best way to extract load average float values from a string in Python?

If I have a string such as "17:31:51 up 134 days, 11:26, 1 user, load average: 0.22, 0.15, 0.10" what is the best way to extract just the x3 load average values at the end? I have written a regexp that does this but is this the most efficient / fastest method? >>> s = "17:31:51 up 134 days, 11:26, 1 user, load average: 0.22, 0.15,...

Organising a GUI application

This is going to be a generic question. I am struggling in designing a GUI application, esp. with dealing with interactions between different parts. I don't know how I should deal with shared state. On one hand, shared state is bad, and things should be as explicit as possible. On the other hand, not having shared state introduces unwa...

Is there a Term::ANSIScreen equivalent for Python?

Perl has the excellent module Term::ANSIScreen for doing all sorts of fancy cursor movement and terminal color control. I'd like to reimplement a program that's currently in Perl in Python instead, but the terminal ANSI colors are key to its function. Is anyone aware of an equivalent? ...

Any way to override the and operator in Python?

I tried overriding __and__, but that is for the & operator, not and - the one that I want. Can I override and? ...

Customizing an Admin form in Django while also using autodiscover

I want to modify a few tiny details of Django's built-in django.contrib.auth module. Specifically, I want a different form that makes username an email field (and email an alternate email address. (I'd rather not modify auth any more than necessary -- a simple form change seems to be all that's needed.) When I use autodiscover with a...

Python/Twisted multiuser server - what is more efficient?

In Python, if I want my server to scale well CPU-wise, I obviously need to spawn multiple processes. I was wondering which is better (using Twisted): A) The manager process (the one who holds the actual socket connections) puts received packets into a shared queue (the one from the multiprocessing module), and worker processes pull the ...

Pros and cons of IronPython and IronPython Studio

We are ready in our company to move everything to Python instead of C#, we are a consulting company and we usually write small projects in C# we don't do huge projects and our work is more based on complex mathematical models not complex software structures. So we believe IronPython is a good platform for us because it provides standard ...

Way to have compiled python files in a separate folder?

Is it possible to have Python save the .pyc files to a separate folder location that is in sys.path? /code foo.py foo.pyc bar.py bar.pyc To: /code foo.py bar.py /code_compiled foo.pyc bar.pyc I would like this because I feel it'd be more organized. Thanks for any help you can give me. ...

How to convert XML to JSON in Python?

I'm doing some work on App Engine and I need to convert an XML document being retrieved from a remote server into an equivalent JSON object. I'm using xml.dom.minidom to parse the XML data being returned by urlfetch. I'm also trying to use django.utils.simplejson to convert the parsed XML document into JSON. I'm completely at a loss as ...

Python __slots__

In Python, when would I want to use __slots__ and when would I want to avoid it? ...

Help urgently--Incorrect answer in dll import in Python

Hello friends, I need an urgent help on importing dll. In my Python script i m importing a dll written in vb .net. I m callng a function of initialisation in my script.It takes 2 arguments.One path of xml file and 2nd a string.It returns an integer ,0 for success ,else error.The second argument is passed by reference.So if ...

How to read the header with pycurl

How do I read the response headers returned from a PyCurl request? ...

How to specify uniqueness for a tuple of field in a Django model

Is there a way to specify a Model in Django such that is ensures that pair of fields in unique in the table, in a way similar to the "unique=True" attribute for similar field? Or do I need to check this constraint in the clean() method? ...

TypeError: 'tuple' object is not callable

I was doing the tutorial from the book teach yourself django in 24 hours and in part1 hour 4 i got stuck on this error. Traceback (most recent call last): File "C:\Python25\lib\site-packages\django\core\servers\basehttp.py", line 278, in run self.result = application(self.environ, self.start_response) File "C:\Python25\lib\s...

select single item from a collection : Python

I created a utility function to return the expected single item from an generator expression print one(name for name in ('bob','fred') if name=='bob') Is this a good way to go about it? def one(g): try: val = g.next() try: g.next() except StopIteration: return val else: ...

Subtract from an input appended list with a running balance output

Noob I am trying to write a script that gives a running balance. I am messing up on the elementary declared functions of python. I need it too: accept a balance via input append a list of transactions take those out one by one in the order they were input print a running total use pyhtmltable to make the output in html table rea...