python

Formatting with mako

Anyone know how to format the length of a string with Mako? The equivalent of print "%20s%10s" % ("string 1", "string 2")? ...

Does python have a "causes_exception()" function?

Hi Folks, I have the following code: def causes_exception(lamb): try: lamb() return False except: return True I was wondering if it came already in any built-in library? Ya'ir Edit: Thx for all the commentary. It's actually impossible to detect whether code causes an exception without running it -- oth...

Does urllib2 in Python 2.6.1 support proxy via https

Does urllib2 in Python 2.6.1 support proxy via https? I've found the following at http://www.voidspace.org.uk/python/articles/urllib2.shtml: NOTE Currently urllib2 does not support fetching of https locations through a proxy. This can be a problem. I'm trying automate login in to web site and downloading document, I have ...

Calling an external program from python

So I have this shell script: echo "Enter text to be classified, hit return to run classification." read text if [ `echo "$text" | sed -r 's/ +/ /g' | bin/stupidfilter data/c_rbf` = "1.000000" ] then echo "Text is not likely to be stupid." fi if [ `echo "$text" | sed -r 's/ +/ /g' | bin/stupidfilter data/c_rbf` = "0.000000" ] then ...

Flash Characters on Screen in Linux

Hi, I have a XFCE 4.6 on kernel 2.6. Is there a quick and easy way to flash a message on the screen for a few seconds? My Thinkpad T60 has 3 volume buttons (up, down, mute). When I pressed the buttons, I would like to flash the volume on the screen for a second on screen. Can it be done with Python? ...

Race conditions in django

Here is a simple example of a django view with a potential race condition: # myapp/views.py from django.contrib.auth.models import User from my_libs import calculate_points def add_points(request): user = request.user user.points += calculate_points(user) user.save() The race condition should be fairly obvious: A user can...

Simple User management example for Google App Engine ?

Hi, I am newbie in Google App Engine. While I was going through the tutorial, I found several things that we do in php-mysql is not available in GAE. For example in dataStore auto increment feature is not available. Also I am confused about session management in GAE. Over all I am confused and can not visualize the whole thing. Please a...

How to Make a PyMe (Python library) Run in Python 2.4 on Windows?

I want to run this library on Python 2.4 in Windows XP. I installed the pygpgme-0.8.1.win32.exe file but got this: >>> from pyme import core Traceback (most recent call last): File "<stdin>", line 1, in ? File "C:\Python24\Lib\site-packages\pyme\core.py", line 22, in ? import pygpgme File "C:\Python24\Lib\site-packages\pyme\p...

Unescape _xHHHH_ XML escape sequences using Python

I'm using Python 2.x [not negotiable] to read XML documents [created by others] that allow the content of many elements to contain characters that are not valid XML characters by escaping them using the _xHHHH_ convention e.g. ASCII BEL aka U+0007 is represented by the 7-character sequence u"_x0007_". Neither the functionality that allow...

When to use a Templating Engine in Python?

As a "newbie" to Python, and mainly having a background of writing scripts for automating system administration related tasks, I don't have a lot of sense for where to use certain tools. But I am very interested in developing instincts on where to use specific tools/techniques. I've seen a lot mentioned about templating engines, includ...

Problem with SQLite executemany

I can't find my error in the following code. When it is run a type error is given for line: cur.executemany(sql % itr.next()) => 'function takes exactly 2 arguments (1 given), import sqlite3 con = sqlite3.connect('test.sqlite') cur = con.cursor() cur.execute("create table IF NOT EXISTS fred (dat)") def newSave(className, fields, objD...

Login input

Suppose My system login ID is tom2deu. i have one Python program. Now i am going to modified this Python program. My question Can we print my login ID to a seprate notepad or any other file ? means can we print any person detail(login ID) who had logged the system and modified the program. ...

what is python equivalent to PHP $_SERVER ?

Hi, I couldn't find out python equivalent to PHP $_SERVER. Is there any? Or, what are the methods to bring equivalent results? Thanks in advance. ...

"Adding" Dictionaries in Python?

Hello, My input is two dictionaries that have string keys and integer values. I want to add the two dictionaries so that the result has all the keys of the input dictionaries, and the values are the sum of the input dictionaries' values. For clarity, if a key appears in only one of the inputs, that key/value will appear in the result,...

Find cpu-hogging plugin in multithreaded python

I have a system written in python that processes large amounts of data using plug-ins written by several developers with varying levels of experience. Basically, the application starts several worker threads, then feeds them data. Each thread determines the plugin to use for an item and asks it to process the item. A plug-in is just a p...

Python/Django or C#/ASP.NET for web development?

Hi, I am a .NET developer. I have no experience on Python. Which platform is more scalable? Which platform is more suitable for large-size high-traffic web sites? If you have any experience about scalability on these platforms, please inform us. Thank you. ...

encyption/decryption of one time password in python

how to encrypt one time password using the public key and again recover it by the private key of the user , i need to do it using python ...

Profiling self and arguments in python?

How do I profile a call that involves self and arguments in python? def performProfile(self): import cProfile self.profileCommand(1000000) def profileCommand(self, a): for i in a: pass In the above example how would I profile just the call to profileCommand? I figured out I need to use runctx for argument, but how...

IPython Modules

I have a few IPython scripts which have redundant functionality. I would like to refactor the common functionality into one module and include that modules in the existing script. The problem is it cannot be made a python module as the code uses Ipython's language extensions (!, $ etc). Is it possible to make a module having IPython code...

python service restart (when compiled to exe)

I have a service, as follows: """ The most basic (working) CherryPy 3.1 Windows service possible. Requires Mark Hammond's pywin32 package. """ import cherrypy import win32serviceutil import win32service import sys import __builtin__ __builtin__.theService = None class HelloWorld: """ Sample request handler class. """ def __i...