python

SendKeys for Python 3.1 on Windows

The latest Python Sendkeys module is for Python 2.6. I can't upgrade it myself as it needs the C module to be recompiled. Does anyone know of a fairly easy alternative way to send keys to a window? Using win32ui.FindWindow() I can find the right window, then make it active with PyCWnd.SetActiveWindow(), so all that's needed is a simple...

Django best practice for displaying mostly read-only form, one field writeable

I have a requirement where one user creates an 'instance' of an object via a ModelForm. Another user of a different group has access to read all of the fields of the form, but has to update only one field. Think of a student who creates an exam object. Then a teach pulls up the exam and just needs to put in a grade, the rest of the exam ...

Overload a method with a function at runtime

OK, I'll admit upfront this is a mega kludge and that I could definately implement this better. It's only morbid curiosity that's driving me to find out how I could do this. class SomeClass(object): def __init__(self): def __(self, arg): self.doStuff(arg) self.overLoaded = __ def doStuff(self, string)...

Self import of subpackages or not ?

Suppose you have the following b b/__init__.py b/c b/c/__init__.py b/c/d b/c/d/__init__.py In some python packages, if you import b, you only get the symbols defined in b. To access b.c, you have to explicitly import b.c or from b import c. In other words, you have to import b import b.c import b.c.d print b.c.d In other cases I s...

How do I query XHTML using python?

I have created a simple test harness in python for my ASP .net web site. I would like to look up some HTML tags in the resulting page to find certain values.\ What would be the best way of doing this in python? eg (returned page): <div id="ErrorPanel">An error occurred......</div> would display (in std out from python): Error: .....

urllib2 not retrieving entire HTTP response

I'm perplexed as to why I'm not able to download the entire contents of some JSON responses from FriendFeed using urllib2. >>> import urllib2 >>> stream = urllib2.urlopen('http://friendfeed.com/api/room/the-life-scientists/profile?format=json') >>> stream.headers['content-length'] '168928' >>> data = stream.read() >>> len(data) 61058 >>...

Get mach_absolute_time/UpTime() in nanoseconds in Python

I need to access the elapsed time since startup in nanoseconds from a Python program running on Mac OS X 10.6. I use the following Carbon calls to get this in C code: AbsoluteTime uptimeAbs = AbsoluteToNanoseconds(UpTime()); uint64_t elapsedTime = ((uint64_t)uptimeAbs.hi << 32) + uptimeAbs.lo; Is it possible to get to these functions...

major changes in python since version 2.2.3

I've written a small python script to create a file and calculate times. I've tested it on Fedora 10, and Ubuntu 8.x and it worked well. the python versions were 2.5.x. I tried to run it on my production server (an old red hat based linux server), the version of python is 2.2.3. the script does not work and raises a syntax error in the ...

A clean, lightweight alternative to Python's twisted?

A (long) while ago I wrote a web-spider that I multithreaded to enable concurrent requests to occur at the same time. That was in my Python youth, in the days before I knew about the GIL and the associated woes it creates for multithreaded code (IE, most of the time, its not really multithreaded!)... I'd like to rework this code to mak...

Inheriting specific parent model attributes in foreignkey->'self' relationship in Django

I have a Django model: class Foo(models.Model): name = models.CharField(unique=True) attribute1 = models.FloatField(null=True, blank=True) attribute2 = models.FloatField(null=True, blank=True) attribute3 = models.BooleanField(null=True, blank=True) attribute4 = models.CharField(null=True, blank=True) inherit = mo...

Python QtreeWidget: return tree hierarchy

Hi Everybody, I got stuck in trying to obtain the hierarchical view of a widget tree. The code works fine and generates a nice tree like that: ROOT(Animal): | | |___Not extinct: . | (red) . |_____BIRD--------------(blue) . | (green) | | ...

Infinity generated in python code

I'm looking over some complex Python 2.6 code which is occasionally resulting in an infinity being generated (at least an Infinity being serialized by the json library -- which checks w/ math.isinf). What is especially baffling is that Python (as far as I can tell) shouldn't be able to ever produce computation results set to infinity. ...

How to print "fuzzy" time/date delta in python?

Possible Duplicate: Natural/Relative days in Python Does anyone know where to find a python module that can print a time tuple in format "5 seconds ago", "2 hours ago", "Yesterday", "3 weeks ago" etc? ...

Is it possible for my linux machine (with no GUI) to hit Twitter sign up page, and then spit out a captcha in a webpage format

So that I can just type in the letters and register (through my linux box's IP)? (twitter uses recaptcha) Is there some way to grab that javascript, output it into a webpage. Then submit it through? ...

Need help with Python/BeautifulSoup

Can I combine these two blocks into one: Edit: Any other method than combining loops like Yacoby did in the answer. for tag in soup.findAll(['script', 'form']): tag.extract() for tag in soup.findAll(id="footer"): tag.extract() Also can I multiple blocks into one: for tag in soup.findAll(id="footer"): tag.extract() for ...

Mark string as safe in Mako

I'm using Pylons with Mako templates and I want to avoid typing this all the time: ${ h.some_function_that_outputs_html() | n } I want to somehow mark the function, or a variable as safe (you can do that in Django) so I don't have to pipe-en all the time. Any ideas? ...

Using super() in nested classes.

Imagine this: class A(object): class B(object): def __init__(self): super(B, self).__init__() This creates an error: NameError: global name B is not defined. I've tried A.B, but then it says that A is not defined. Update: I've found the problem. I've had a class like this: class A(object): class B(o...

Download html page and its content

Does python have any way of downloading entire html page and its contents (images, css) to local folder given a url. And updating local html file to pick content locally. ...

Inheriting methods from a metaclass

In the example enumeration code given in this question, reproduced below, why does TOKEN contain the implementations of __contains__ and __repr__ from the metaclass EnumerationType? from ctypes import * class EnumerationType(type(c_uint)): def __new__(metacls, name, bases, dict): if not "_members_" in dict: ...

Can python send text to the Mac clipboard

I'd like my python program to place some text in the Mac clipboard. Is this possible? ...