python

Python: making your own statements

Is there a way to define new statements like def, with, for,.. of my own in python. Of course, I don't mean to override the existing statements.. Only create some of my own. If so, how do I do it? Can you point me to good docs on the subject? ...

Python dictionary instead of switch/case

I've recently learned that python doesn't have the switch/case statement. I've been reading about using dictionaries in its stead, like this for example: values = { value1: do_some_stuff1, value2: do_some_stuff2, valueN: do_some_stuffN, } values.get(var, do_default_stuff)() What I can't figure out is how to apply thi...

Using Zimbra SOAP API in Python

I'm trying to use the Zimbra SOAP API from Python to programmatically modify & cleanup my contacts but I'm having trouble getting started. What I have so far is: from SOAPpy import SOAPProxy url = 'https://zimbra/service/soap' auth = {"account": "xxxxx", "password": "xxxxx"} zimbra = SOAPProxy(url, 'urn:zimbra') zimbraAuth = SOAPProxy...

Lazy evaluation in Python? Between modules?

I'm not sure if something like this is even possible in Python, but if it is it'd be really useful (at least to me in this instance). I have a test framework in which I want to keep the test configuration separate from the test commands. This is useful because it allows you to mix and match configurations/tests without actually having...

cx_Freeze problem with Tkinter

I'm trying do a executable for windows for a gui aplication in tkinter using the ttk, I made a exe with cx_freeze, but when run the app in the console, it give me the following error. D:\My Dropbox\python\SAR Calculator\src\dist_tk> Traceback (most recent call last): File "C:\Python31\lib\site-packages\cx_Freeze\ 7, in <modul...

How to execute a function asynchronously every 60 seconds in Python?

Hello, I want to execute a function every 60 seconds on Python but I don't want to be blocked meanwhile. How can I do it asynchronously? import threading import time def f(): print("hello world") threading.Timer(3, f).start() if __name__ == '__main__': f() time.sleep(20) With this code, the function f is execut...

A class subclass of itself. Why mutual subclassing is forbidden ?

Complex question I assume, but studying OWL opened a new perspective to live, the universe and everything. I'm going philosophical here. I am trying to achieve a class C which is subclass of B which in turn is subclass of C. Just for fun, you know... So here it is >>> class A(object): pass ... >>> class B(A): pass ... >>> class C(B)...

Is ActiveMQ's failover mechanism supported by C# (openwire) & python (stomp) clients?

I'd like to use ActiveMQ to connect python service with C# clients. Is there a way to specify failover connection in C# (openwire) and python (Stomp)? The ActiveMQ will be configured Shared File System Master Slave. ...

Design pattern for ongoing survey anayisis

I'm doing an ongoing survey, every quarter. We get people to sign up (where they give extensive demographic info). Then we get them to answer six short questions with 5 possible values much worse, worse, same, better, much better. Of course over time we will not get the same participants,, some will drop out and some new ones will si...

Stopping a thread in python

I am creating a thread in my Python app with thread.start_new_thread. How do I stop it if it hasn't finished in three seconds time? ...

Online identity verification solution

Hi, I am building a Python web application and we will need a user identity verification solution... something to verify the users identity during account registration. I was wondering if anyone had any experience in integrating such a solution. What vendors/products out there have worked well with you? Any tips? I don't have any expe...

Tkinter Canvas Does Not Display

I'm attempting to learn some Python and Tkinter. The sample code below is intended to put two windows on the screen, a few buttons, and a Canvas with an image in it and some lines drawn on it. The windows and buttons appear just fine, however I'm not seeing either the canvas image or canvas lines. I'd appreciate some help to figure ou...

iPython demo mode

I'm trying to use the iPython demo mode. I created a file called test.py containing: print 1 print 2 print 3 and then launched iPython and did the following: In [1]: from IPython.demo import LineDemo In [2]: d = LineDemo('test.py') In [3]: d() ********************* <test.py> block # 0 (5 remaining) ********************* p ********...

UnicodeEncodeError when redirecting stdout

I'm having a problem regarding Unicode in Python. I can print the output fine in a regular terminal, but if I redirect stdout elsewhere (or capture it with the subprocess module), I get a UnicodeEncodeError: $ cat example.py print u'Example: \u00F1' $ python example.py Example: ñ $ python example.py > /dev/null Traceback (most recent ...

RSS Feed aggregator using Google App Engine - Python

I am trying to build a GAE app that processes an RSS feed and stores all the data from the feed into Google Datastore. I use Minidom to extract content from the RSS feed. I also tried using Feedparser and BeautifulSoup but they did not work for me. My app currently parses the feed and saves it in the Google datastore in about 25 second...

How to extract signature from function reference in Python?

Let's say I have a function in Python like so: def foo(x): pass According to Python, 'foo' alone is a function reference, right? >>> def foo(x): pass ... >>> foo <function foo at 0xb7f3d1b4> Is there any way I can examine the function reference to determine the number of arguments it expects? Thanks, --Steve ...

python equivalent of GNU 'cat' that shows unique lines

Has anyone written the GNU cat command in python and would be willing to share? GNU cat actually does quite a bit & I don't really feel like re-inventing the wheel today. Yes, I did do a google search & and after reading too many sad stories of kittens vs snakes I decided to try SO. Edit: I'd like to modify it so that it only shows un...

parsing table with BeautifulSoup and write in text file

I need data from table in text file (output.txt) in this format: data1;data2;data3;data4;..... Celkova podlahova plocha bytu;33m;Vytah;Ano;Nadzemne podlazie;Prizemne podlazie;.....;Forma vlastnictva;Osobne All in "one line", separator is ";" (later export in csv-file). I´m beginner.. Help, thanks. from BeautifulSoup import BeautifulS...

Convert dict to array in NumPy

I'd like to take a dictionary of a dictionary containing floats, indexed by ints and convert it into a numpy.array for use with the numpy library. Currently I'm manually converting the values into two arrays, one for the original indexes and the other for the values. While I've looked at numpy.asarray my conclusion has been that I must...

Business days in Python

Hello, I need to subtract business days from the current date. I currently have some code which needs always to be running on the most recent business day. So that may be today if we're Monday thru Friday, but if it's Saturday or Sunday then I need to set it back to the Friday before the weekend. I currently have some pretty clunky cod...