python

python get whois

I try to get whois in python. I use this http://code.google.com/p/pywhois/ but it run only in linux. Is it posible to run it on windows? currently i get errors (because internal linux command whois used) ...

Asynchronous PureMVC in Python

Taking the following code from here, from the shortened version at the bottom, exists this proxy: class DataModelProxy(puremvc.patterns.proxy.Proxy): NAME = "DataModelProxy" def __init__(self): super(DataModelProxy, self).__init__(DataModelProxy.NAME, []) self.realdata = Data() self.sendNotification(AppF...

Is there a wxpython event like program_start?

OK, I'm trying to explain what I want to achieve in another way. Here's an example: Say if it's an anti virus program, and user can choose between two ways to run the program, choice one, automatically start to scan disks for virus when the program starts up, choice two, hit the start button to make the program scan disks for virus afte...

TimeUUID with Cassandra and Lazyboy

Hello, I try to insert column with UUID1 keys to be able to sort them by date. I always get the error "cassandra.ttypes.InvalidRequestException: InvalidRequestException(why='UUIDs must be exactly 16 bytes')", and I don't know why. Here is the code generating this error : from lazyboy import * from lazyboy.key import Key import uuid c...

twistd in Twisted cant be run in window

in command prompt i type >>twistd echobot.tac Traceback (most recent call last): File "C:\Python26\Scripts\twistd.py", line 18, in ? from twisted.scripts.twistd import run ImportError: No module named twisted.scripts.twistd the twistd is at C:\Python26\Scripts\twistd.py #!c:\python26\python.exe # Copyright (c) 2001-2009 Twisted ...

Python: determining if an object is file-like?

Hi, I'm writing some unit tests (using the unittest module) for my application, and want to write something which can verify that a method I'm calling returns a "file-like" object. Since this isn't a simple isinstance call, I wonder what the best-practice would be for determining this? So, in outline: possible_file = self.dao.get_fil...

footer on lastpage using reportlab

Hi, Can anyone tell me how to put footer only on last page using reportlab? I am able to put footer on every page, but i want it only on last page. Below is my code, def beforeDrawPage(self, canv, doc): "Decorate the page with an asymetric design" #canv.setFillColor(colors.orange) productpath = os.path.dirname(config.__fil...

Getting current url

I have a couple of views which are rendering the same template and I have some {% url %} tags into that template which needs to point to different location based on the current view. Is there any context variable which gives the name of the view(for named urls), like view-1 view-2, so in my template I can use it like this: {% url url-na...

How to get something random in datastore (AppEngine)?

Currently i'm using something like this: images = Image.all() count = images.count() random_numb = random.randrange(1, count) image = Image.get_by_id(random_numb) But it turns out that the ids in the datastore on AppEngine don't start from 1. I have two images in datastore and their ids are 6001 and 7001. Is there a b...

Unziping files in python

I read through the zipfile modules docs, but couldn't understand how to unzip a file, only zip a file. What is the simplest way to unzip all the contents of a zip file into the same directory? ...

Why should I use python 3.1 instead of python 2.6 ?

Hello, After reading some benchmarks, I noticed that python 3.1 is slower than python 2.6, especially with I/Os. So I wonder what could be the good reasons to switch to Python 3.x ? ...

Python list / sublist selection -1 weirdness

So I've been playing around with python and noticed something that seems a bit odd. The semantics of -1 in selecting from a list don't seem to be consistent. So I have a list of numbers ls = range(1000) The last element of the list if of course ls[-1] but if I take a sublist of that so that I get everything from say the midpoint to t...

How to wrap long lines in a text using Regular Expressions when you also need to indent the wrapped lines?

How can one change the following text The quick brown fox jumps over the lazy dog. to The quick brown fox + jumps over the + lazy dog. using regex? UPDATE1 A solution for Ruby is still missing... A simple one I came to so far is def textwrap text, width, indent="\n" return text.split("\n").collect do |line| line.sc...

How to use named parameters and global vars with same name in Python?

Example code from a module: somevar = "a" def myfunc(somevar = None): # need to access both somevars ??? # ... if somevar was specified print it or use the global value pass if __name__ == '__main__': somevar = "b" # this is just for fun here myfunc("c") myfunc() # should print "a" (the value of global variable...

Sending sqlite db over network

I have an sqlite database whose data I need to transfer over the network, the server needs to modify the data, and then I need to get the db back and either update my local version or overwrite it with the new db. How should I do this? My coworker at first wanted to scrap the db and just use an .ini file, but this is going to be data tha...

how to dynamically create an instance of a class in python?

Hello, I have list of class names and want to create their instances dynamically. for example: names=[ 'foo.baa.a', 'foo.daa.c', 'foo.AA', .... ] def save(cName, argument): aa = create_instance(cName) # how to do it? aa.save(argument) save(random_from(names), arg) How to dynamically create that instances in Python? thanks! ...

Python ftplib timing out

I'm trying to use ftplib to get a file listing and download any new files since my last check. The code I'm trying to run so far is: #!/usr/bin/env python from ftplib import FTP import sys host = 'ftp.***.com' user = '***' passwd = '***' try: ftp = FTP(host) ftp.login(user, passwd) except: print 'Error connecting to FTP se...

ctypes.Structure Modify _fields_ at Run Time

Is it possible to modify the fields definition of the ctypes.Structure after it's been imported? Something like: from ctypes import * class A_STRUCT(Structure): _fields_ = [("one",c_int)] A_STRUCT._fields_.append(("two",c_int)) x = A_STRUCT() print x.one print x.two Not surprisingly this fails with: 0 Traceback (most recent ...

Get_by_key_name doesn't work with unicode key names of several characters

Hello, I'm using unicode strings for non latin characters as key names for my models. I can create objects without problems, and the appengine admin shows key name correctly (I'm using chinese characters, and the right characters) However, MyModel.get_by_key_name() returns None if the key_name is made of several characters. For 1 char...

twisted: Failure vs. Error

When should I use a twisted.python.failure.Failure, and when should I use something like twisted.internet.error.ConnectionDone? Or should I do twisted.python.failure.Failure(twisted.internet.error.ConnectionDone), and if so, in what casese should I do that? ...