python

For Python support, what company would be best to get hosting from?

I want to be able to run WSGI apps but my current hosting restricts it. Does anybody know a company that can accommodate my requirements? ...

What is the fastest way to draw an image from discrete pixel values in Python?

I wish to draw an image based on computed pixel values, as a means to visualize some data. Essentially, I wish to take a 2-dimensional matrix of color triplets and render it. Do note that this is not image processing, since I'm not transforming an existing image nor doing any sort of whole-image transformations, and it's also not vecto...

Open document with default application in Python

I need to be able to open a document using it's default application in Windows and Mac OS. Basically, I want to do the same thing that happens when you double click on the document icon in Explorer or Finder. What is the best way to do this in Python? ...

How do I set permissions (attributes) on a file in a zip file using Python's ZipFile module?

When I extract files from a zip file created with the Python zipfile module, all the files are not writeable, read only etc. The file is being created and extracted under Linux and Python 2.5.2. As best I can tell, I need to set the ZipInfo.external_attr property for each file, but this doesn't seem to be documented anywhere I could fi...

Cleaning up a database in django before every test method

By default when Django runs against sqlite backend it creates a new in memory database for a test. That means for every class that derives from unittest.TestCase, I get a new database. Can this be changed so that it is cleared before every test method is run? Example: I am testing a manager class that provides additional abstraction on ...

Ensuring contact form email isn't lost (python)

I have a website with a contact form. User submits name, email and message and the site emails me the details. Very occasionally my server has a problem with it's email system and so the user gets an error and those contact details are lost. (Don't say: get a better server, any server can have email go down now and then and we do get a ...

What is an alternative to execfile in Python 3.0?

It seems they canceled in Python 3.0 all the easy way to quickly load a script file - both execfile() and reload(). Is there an obvious alternative I'm missing? ...

Python: Is there a way to determine the encoding of text file?

I know there is something buried in here. But I was just wondering if there is an actual way built into Python to determine text file encoding? Thanks for your help :) Edit: As a side question, it can be ignored if you want but why is the type of encoding not put into the file so it could be detected easier? ...

How do I split email address/password string in two in Python?

Lets say we have this string: [18] [email protected]:pwd: [email protected] is the email and pwd is the password. Also, lets say we have this variable with a value f = "[18] [email protected]:pwd:" I would like to know if there is a way to make two other variables named var1 and var2, where the var1 variable will take the exact email info...

pyPdf for IndirectObject extraction

Following this example, I can list all elements into a pdf file import pyPdf pdf = pyPdf.PdfFileReader(open("pdffile.pdf")) list(pdf.pages) # Process all the objects. print pdf.resolvedObjects now, I need to extract a non-standard object from the pdf file. My object is the one named MYOBJECT and it is a string. The piece printed by...

Python: import the containing package

In a module residing inside a package, i have the need to use a function defined within the __init__.py of that package. how can i import the package within the module that resides within the package, so i can use that function? Importing __init__ inside the module will not import the package, but instead a module named __init__, leadin...

Python Split String

Lets Say we have Zaptoit:685158:[email protected] How do you split so it only be left 685158:[email protected] ...

What should "value_from_datadict" method of a custom form widget return?

I'm trying to build my own custom django form widgets (putting them in widgets.py of my project directory). What should the value "value_from_datadict()" return? Is it returning a string or the actual expected value of the field? I'm building my own version of a split date/time widget using JQuery objects, what should each part of the...

How to implement a python REPL that nicely handles asynchronous output?

I have a Python-based app that can accept a few commands in a simple read-eval-print-loop. I'm using raw_input('> ') to get the input. On Unix-based systems, I also import readline to make things behave a little better. All this is working fine. The problem is that there are asynchronous events coming in, and I'd like to print output as...

IronPython Webframework

There seem to be many excellent web frameworks for Python. Has anyone used any of these (Pylons, Web2Py, Django) with IronPython? ...

Safe escape function for terminal output

I'm looking for the equivalent of a urlencode for terminal output -- I need to make sure that garbage characters I (may) print from an external source don't end up doing funky things to my terminal, so a prepackaged function to escape special character sequences would be ideal. I'm working in Python, but anything I can readily translate...

How do I unload (reload) a Python module?

I have a long-running python server and would like to be able to upgrade a service without restarting the server. What's the best way do do this? if foo.py has changed: unimport foo <-- how do I do this? import foo myfoo=foo.Foo() ...

Google App Engine - Importing my own source modules (multiple files)

Hello, I am writing a GAE application and am having some difficulty with the following problem. I've created multiple python files (say a.py and b.py) which are both stored in the same folder. I am able to call code in a.py or b.py by mapping URL's to them (using app.yaml). What I haven't figured out how to do is import the code from...

Help needed--Is class necessary in Python scripting???

I am creating an interface for Python scripting. Later I will be dong Python scripting also for automated testing. Is it necessary the at i must use class in my code.Now I have created the code with dictionaries,lists,functions,global and local variables. Is class necessary? Help me in this. ...

Python data structure: SQL, XML, or .py file

What is the best way to store large amounts of data in python, given one (or two) 500,000 item+ dictionary used for undirected graph searching? I've been considering a few options such as storing the data as XML: <key name="a"> <value data="1" /> <value data="2" /> </key> <key name="b"> ... or in a python file for direct acce...