python

Thread Finished Event in Python

Hello, I have a PyQt program, in this program I start a new thread for drawing a complicated image. I want to know when the thread has finished so I can print the image on the form. The only obstacle I'm facing is that I need to invoke the method of drawing from inside the GUI thread, so I want a way to tell the GUI thread to do someth...

How to debug wxpython applications?

I'm trying wxpython for the first time. I've wrote a GUI for a python program and when I run it, it produces some error in the GUI, but the GUI disappears very quickly, quickly enough for me to be unable to read the error info. Is there any log that I can check for the error message? (I'm running Mac OS X) or any other way? Thanks in a...

I want to make a temporary answerphone which records MP3s

An artistic project will encourage users to ring a number and leave a voice-mail on an automated service. These voice-mails will be collected and edited into a half-hour radio show. I want to make a temporary system (with as little as possible programming) which will: Allow me to establish a public telephone number (preferably in the...

Does Python have properties?

So something like: vector3.Length that's in fact a function call that calculates the length of the vector, not a variable. ...

Ruby String Translation

I want to find the successor of each element in my encoded string. For example K->M A->C etc. string.each_char do |ch| dummy_string<< ch.succ.succ end However this method translates y->aa. Is there a method in Ruby that is like maketrans() in Python? ...

Embedding a Python shell inside a Python program

I am making a sort of a science lab in Python, in which the user can create, modify and analyze all sorts of objects. I would like to put a Python shell inside the program, so the user could manipulate the objects through the shell. (Note: He could also manipulate the objects through the usual GUI.) A mockup that illustrates this: How...

Is there a way to check whether function output is assigned to a variable in Python?

In Python, I'd like to write a function that would pretty-print its results to the console if called by itself (mostly for use interactively or for debugging). For the purpose of this question, let's say it checks the status of something. If I call just check_status() I would like to see something like: Pretty printer status check 0....

If I want to use a pylons app with Apache, should I use mod_wsgi or proxy to paste?

Or should I be using a totally different server? ...

How to Fix the Broken BSDDB Install in the Default Python Package on Mac OS X 10.5 Leopard?

Do the following on the default Python install on Mac OS X 10.5 (Leopard) w/ Developer Tools: noel ~ : python Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import bsddb Traceback (most recent call last): File "<s...

PY2EXE: How to output "*_D.PYD" file (debug) and use MSVCR80D.DLL?

The debug configuration of my app is built against: PYTHON25_D.DLL MSVCR80D.DLL We use Python .PYD files in our application. Some of these .PYD are .PY converted by PY2EXE to .PYD. When I run PY2EXE on MYSCRIPT.PY, I get the following .PYD and dependencies: MYSCRIPT.PYD PYTHON25.DLL MSVCR71.DLL KERNEL32.DLL What I want i...

easiest way to rm -rf in python

What is the easiest way to do the equivalent of rm -rf in python? ...

Python lxml screen scraping?

I need to do some HTML parsing with python. After some research lxml seems to be my best choice but I am having a hard time finding examples that help me with what I am trying to do. this is why i am hear. I need to scrape a page for all of its viewable text.. strip out all tags and javascript.. I need it to leave me with what text is vi...

Python regex parsing

I have an array of strings in python which each string in the array looking something like this: <r n="Foo Bar" t="5" s="10" l="25"/> I have been searching around for a while and the best thing I could find is attempting to modify a HTML hyperlink regex into something that will fit my needs. But not really knowing much regex stuff I ...

google app engine - design considerations about cron tasks

I'm developing software using the google app engine. I have some considerations about the optimal design regarding the following issue: I need to create and save snapshots of some entities at regular intervals. in the conventional relational db world, I would create db jobs which would insert new summary records. for example, a job w...

python regular exp. with a unicode char

I need a reg exp that will parse something like- "2 * 240pin" where the * can be either the regular star or unicode char \u00d7 or just an x. This is what I have but its not working: multiple= r'^(\d+)\s?x|*|\\u00d7\s?(\d+)(\w{2,4})$' multiplepat= re.compile(multiple, re.I) print multiplepat.search(u'1 X 240pin').groups() returns ...

Can not clone mercurial (hg) repository via http.

I can't clone my repository via http: abort: 'http://MYREPO' does not appear to be an hg repository! Firstly, I created a new repo by hg init MYREPO followed by adding some file and commit. The dir with my repo is password protected but there is no sign of problem because of it, I tried both methods of cloning: (on my local machine) ...

Is there a decorator to simply cache function return values?

Consider the following: @property def name(self): if not hasattr(self, '_name'): # expensive calculation self._name = 1 + 1 return self._name I'm new, but I think the caching could be factored out into a decorator. Only I didn't find one like it ;) PS the real calculation doesn't depend on mutable values ...

How to designate unreachable python code

What's the pythonic way to designate unreachable code in python as in: gender = readFromDB(...) # either 'm' or 'f' if gender == 'm': greeting = 'Mr.' elif gender == 'f': greeting = 'Ms.' else: # What should this line say? ...

Detecting Retweets using computationally inexpensive Python hashing algorithms

In order to be able to detect RT of a particular tweet, I plan to store hashes of each formatted tweet in the database. What hashing algorithm should I use. Cryptic is of course not essential. Just a minimal way of storing a data as something which can then be compared if it is the same, in an efficient way. My first attempt at this wa...

Python imports from crossreferencing packages

Currently I'm trying to write my first Python library and I've encountered the following problem: I have the following import in my package myapp.factories: from myapp.models import * And the following in my package myapp.models: from myapp.factories import * I need the models in my factories package but inside one model I also ne...