python

How can I check for a blank image in Qt or PyQt?

I have generated a collection of images. Some of them are blank as in their background is white. I have access to the QImage object of each of the images. Is there a Qt way to check for blank images? If not, can someone recommend the best way to do it in Python? ...

Why does Django's signal handling use weak references for callbacks by default?

The Django docs say this on the subject: Note also that Django stores signal handlers as weak references by default, so if your handler is a local function, it may be garbage collected. To prevent this, pass weak=False when you call the signal’s connect(). I haven't been able to find any justification for why this is the ...

Python subprocess question

I would like to be able to spawn a process in python and have two way communication. Of course, Pexpect does this and is indeed a way I might go. However, it is not quite ideal. My ideal situation would be to have a cross platform generic technique that involved only the standard python libraries. Subprocess gets pretty close, but the f...

python sqlalchemy performance?

HI , I made a ICAPServer (similar with httpserver) for which the performance is very important. The DB module is sqlalchemy. I then made a test about the performance of sqlalchemy, as a result, i found that it takes about 30ms for sqlalchemy to write <50kb data to DB (Oracle), i don`t know if the result is normal, or i did something wron...

Get TZ information of the system in Python?

I want to get the default timezone (PST) of my system from Python. What's the best way to do that? I'd like to avoid forking another process. ...

How to build an Ecommerce Shopping Cart in Django ?

Hello Is there a book or a tutorial which teaches how to build a shopping cart with django or any other python framework ? ...

How do Python and PHP compare for ecommerce?

If I were to start an ecommerce store, which language would you suggest I start with? Python or PHP? And would it be wise to use Python for an ecommerce site in favor of PHP? PHP has lots of shopping carts, both open source and commercial. Is Python the future of Web Development ? Edit: I would like to clear out that i am not ask...

@staticmethod gives SyntaxError: invalid syntax

Hi I have been using a python script for a long while and all of sudden it gives me: File "youtube-dl.py", line 103 @staticmethod ^ SyntaxError: invalid syntax If you want to see the script, its right here: http://bitbucket.org/rg3/youtube-dl/raw/2009.06.29/youtube-dl What could be the reason? Update I am using python ve...

Problem loading a specific website through Qt Webkit

I am currently using the following PyQt code to create a simple browser: import sys from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.QtWebKit import * app = QApplication(sys.argv) web = QWebView() web.load(QUrl("http://www.robeez.com")) web.show() sys.exit(app.exec_()) Websites like google.com or stackoverflow.com work...

How do I print a Python datetime in the local timezone?

Let's say I have a variable t that's set to this: datetime.datetime(2009, 7, 10, 18, 44, 59, 193982, tzinfo=<UTC>) If I say str(t), i get: '2009-07-10 18:44:59.193982+00:00' How can I get a similar string, except printed in the local timezone rather than UTC? ...

Is there anything like HTTP::Recorder for Python?

I really like Perl's HTTP::Recorder. Is there something like it for Python? ...

Is it really OK to do object closeing/disposing in __del__?

I have been thinking about how I write classes in Python. More specifically how the constructor is implemented and how the object should be destroyed. I don't want to rely on CPython's reference counting to do object cleanup. This basically tells me I should use with statements to manage my object life times and that I need an explicit c...

Why is BeautifulSoup throwing this HTMLParseError?

I thought BeautifulSoup will be able to handle malformed documents, but when I sent it the source of a page, the following traceback got printed: Traceback (most recent call last): File "mx.py", line 7, in s = BeautifulSoup(content) File "build\bdist.win32\egg\BeautifulSoup.py", line 1499, in __init__ File "build\bdist.win32...

What are quines? Any specific purpose to have them?

I came across this term - Quine (also called self-reproducing programs). Just wanted to know more on it. How does one write a quine and are they used anywhere or they are just an exercise for fun? I've started with Python, and I might try writing one in Python. Any suggestions? ...

Replace URL with a link using regex in python

Hello, how do I convert some text to a link? Back in PHP, I used this piece of code that worked well for my purpose: $text = preg_replace("#(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\3</a>", $text); $text = preg_replace("#(^|[\n ])((...

Accessing Clipboard in Python version 3.1

Hi all! I want to access the clipboard using Python 3.1. I've obviously come across win32clipboard, but it requires pywin32 and in its site I only found download versions for up to Python 2.13 or so. Bottom line: Is there a way to access the clipboard in Python 3.1 or do I have to revert to an old Python version? ...

What are the different possible values for __name__ in a Python script, and what do they mean?

Checking to see if __name__ == '__main__' is a common idiom to run some code when the file is being called directly, rather than through a module. In the process of writing a custom command for Django's manage.py, I found myself needing to use code.InteractiveConsole, which gives the effect to the user of a standard python shell. In so...

How do I capture SIGINT in Python?

I'm working on a python script that starts several processes and database connections. Every now and then I want to kill the script with a Ctrl-C signal, and I'd like to do some cleanup. In Perl I'd do this: $SIG{'INT'} = 'exit_gracefully'; sub exit_gracefully { print "Caught ^C \n"; exit (0); } How do I do the analogue of th...

Perl equivalent of (Python-) list comprehension

I'm looking for ways to express this Python snippet in Perl: data = {"A": None, "B": "yes", "C": None} key_list = [k for k in data if data[k]] # in this case the same as filter(lambda k: data[k], data) but let's ignore that So looking at it one way, I just want the keys where the values are None or undef. Looking at it another way, ...

os.path.basename works with URLs, why?

>>> os.path.basename('http://example.com/file.txt') 'file.txt' .. and I thought os.path.* work only on local paths and not URLs? Note that the above example was run on Windows too .. with similar result. ...