python

Path separator char in python 2.4

Just out of curiosity - is there another way to obtain the platform's path separator char than os.path.normcase('/') in Python 2.4? I was expecting something like a os.path.separator constant... ...

How to get colored emails from crontab?

I call a Python script from crontab. The script does generates colored output using ANSI escapes but when crontab is sending the mail with the output I see the escapes instead of colors. What is happening is logic but I would like to know if it would be possible to generate a html message instead. I would like a solution that does no...

Serving static files with Twisted and Django under non-root folders

I am in the process of migrating an application (Sage) from Twisted to Django. Static documentation is currently served under /doc/static, while live (built on-the-fly) documentation are served under /doc/live. Is it possible to use Twisted to serve /doc/static only, leaving Django to serve the rest of /doc/*? ...

Special considerations for using Python in init.d script?

Are there any special considerations for using Python in an 'init.d' script being run through init? (i.e. booting Ubuntu) From what I understand through googling/testing on Ubuntu, the environment variables provided to an 'init.d' script are scarce and so using "#!/usr/bin/env python" might not work. Anything else? ...

How to adjust the quality of a resized image in Python Imaging Library?

Hi, thanks for taking time to read my question. I am working on PIL and need to know if the image quality can be adjusted while resizing or thumbnailing an image. From what I have known is the default quality is set to 85. Can this parameter be tweaked during resizing? I am currently using the following code: image = Image.open(filena...

Consume a Web service thought an Active Directory

Well i have a project in which i have to consume a web service but authenticating in an Active Directory, i have my system written in python3, python-ldap module in not ported yet so i want to know a way to achive this "consumption". In the worst case i will create a standalone consumer in python2.5 but i want to know "howto" consume a ...

What is the simplest URL shortener application one could write in python for the Google App Engine?

Services like bit.ly are great for shortening URL’s that you want to include in tweets and other conversations. What is the simplest URL shortener application one could write in python for the Google App Engine? ...

How to discard from the middle of a list using list comprehensions?

I could do this using an index but I thought there must be a cleaner way using list comprehensions. I'm a beginner. I hope it's not embarrassingly obvious. Thanks for x in firstList: firstFunc(x) secondFunc(x) x = process(x) if x.discard == True: (get rid of x) secondList.append(firstList) ...

How do I determine if my python shell is executing in 32bit or 64bit mode?

I need a way to tell what mode the shell is in from within the shell. I've tried looking at the platform module but it seems only to tell you about "about the bit architecture and the linkage format used for the executable": the binary is compiled as 64bit though (I'm running on OS X 10.6) so it seems to always report 64bit even thoug...

Why does "enable-shared failed" happen on libjpeg build for os X?

I'm trying to install libjpeg on os X to fix a problem with the Python Imaging Library JPEG setup. I downloaded libjpeg from http://www.ijg.org/files/jpegsrc.v7.tar.gz I then began to setup the config file cp /usr/share/libtool/config.sub . cp /usr/share/libtool/config.guess . ./configure –enable-shared However, the enable-shared fl...

Is there a Python function to determine which quarter of the year a date is in?

Sure I could write this myself, but before I go reinventing the wheel is there a function that already does this? ...

How do I get rid of Python Tkinter root window?

Do you know a smart way to hide or in any other way get rid of the root window (opened by Tk()) that appears (at least on Win32). I would like to use a normal dialog, but it looks like this: (The window on the left is unwanted.) Should I skip the dialog and put all my components in the root window? Is it possible+desirable? Or is ther...

emacs 23 hangs on python mode when typing string block """

My emacs hangs (Ubuntu 9 + emacs 23 + pyflakes) when I type """ quotes for string blocks. anybody experience the same problem? I think, it may not be the emacs problem but some python mode or pyflakes which I use it for error checking. Anybody hot around the issue? It really frustrating experience. ...

Why do I have this TypeError when using tkinter?

so I upgraded to python 3.1.1 from 2.6 and i ran an old program of mine which uses tkinter. I get the following error message which I don't recall getting in the 2.6 version. Exception in Tkinter callback Traceback (most recent call last): File "C:\Python31\lib\tkinter\__init__.py", line 1399, in __call__ return self.func(*args) ...

Splitting a string with no line breaks into a list of lines with a maximum column count

I have a long string (multiple paragraphs) which I need to split into a list of line strings. The determination of what makes a "line" is based on: The number of characters in the line is less than or equal to X (where X is a fixed number of columns per line_) OR, there is a newline in the original string (that will force a new "line"...

Non-critical unittest failures

I'm using Python's built-in unittest module and I want to write a few tests that are not critical. I mean, if my program passes such tests, that's great! However, if it doesn't pass, it's not really a problem, the program will still work. For example, my program is designed to work with a custom type "A". If it fails to work with "A", ...

How do I keep state between requests in AppEngine (Python)?

I'm writing a simple app with AppEngine, using Python. After a successful insert by a user and redirect, I'd like to display a flash confirmation message on the next page. What's the best way to keep state between one request and the next? Or is this not possible because AppEngine is distributed? I guess, the underlying question is whe...

What class to use for money representation?

What class should I use for representation of money to avoid most rounding errors? Should I use Decimal, or a simple built-in number? Is there any existing Money class with support for currency conversion that I could use? Any pitfalls that I should avoid? ...

What is Facebook's new Tornado framework?

Facebook just open-sourced a framework called Tornado. What is it? What does it help a site do? I believe Facebook uses a LAMP structure. Is it useful for smaller sites which are written under the LAMP stack? ...

How to generate basic CRUD functionality in python given a database tables...

Hello, I want to develop a desktop application using python with basic crud operation. Is there any library in python that can generate a code for CRUD functionality and user interface given a database table. ...