python

state of HTML after onload javascript

hi there, many webpages use onload JavaScript to manipulate their DOM. Is there a way I can automate accessing the state of the HTML after these JavaScript operations? A took like wget is not useful here because it just downloads the original source. Is there perhaps a way to use a web browser rendering engine? Ideally I am after a s...

Fixing broken urls

Does anyone know of a library for fixing "broken" urls. When I try to open a url such as http://www.domain.com/../page.html http://www.domain.com//page.html http://www.domain.com/page.html#stuff urllib2.urlopen chokes and gives me an HTTPError traceback. Does anyone know of a library that can fix these sorts of things? ...

Python - Iterate over all classes

How can I iterate over a list of all classes loaded in memory? I'm thinking of doing it for a backup, looking for all classes inheriting from db.Model (Google App Engine). Thanks, Neal Walters ...

long-index arrays in python

I'm attempting to shorten the memory footprint of 10B sequential integers by referencing them as indexes in a boolean array. In other words, I need to create an array of 10,000,000,000 elements, but that's well into the "Long" range. When I try to reference an array index greater than sys.maxint the array blows up: x = [False] * 100000...

Better to install MySQL 32bit or 64bit on my 64bit Intel-based Mac (Perl/Python user)?

I have had numerous headaches trying to get the MySQL APIs for Perl and Python working on my 64 bit Macbook Pro (Leopard). I installed the 64 bit version of MySQL, but Googling around now I have the impression that this could be the source of my pain. None of the various blogs and SO answers quite seem to work (for example here on SO) ...

Python: Passing a class name as a parameter to a function?

class TestSpeedRetrieval(webapp.RequestHandler): """ Test retrieval times of various important records in the BigTable database """ def get(self): commandValidated = True beginTime = time() itemList = Subscriber.all().fetch(1000) for item in itemList: pass endTime = time() self....

Sharing widgets between PyQT and Boost.Python

Hello, I was wondering if it was possible to share widgets between PyQt and Boost.Python. I will be embedding a Python interpreter into an application of mine that uses Qt. I would like users of my application to be able to embed their own UI widgets into UI widgets programmed in C++ and exposed via Boost.Python. Is this possible and ...

GAE - How Do i edit / update the datastore in python

I have this datastore model class Project(db.Model) projectname = db.StringProperty() projecturl = db.StringProperty() class Task(db.Model) project = db.ReferenceProperty(Project) taskname= db.StringProperty() taskdesc = db.StringProperty() How do I edit the value of taskname ? say I have task1 and i want to change it to task1-project...

unique pin generator

The task is to generate a given number of numeric pins of a given length. Here's the code I came up with for a particular case of numeric pins that don't start with 0: def generate_pins(length, count): return random.sample(range(int('1' + '0' * (length - 1)), int('9' * length)), count) How would you implement it? EDIT: Pins shoul...

Difference between __str__ and __repr__ in Python

What is the difference between __str__ and __repr__ in Python? ...

Python sort() method on list vs builtin sorted() function

I know that __builtin__ sorted() function works on any iterable. But can someone explain this huge (10x) performance difference between anylist.sort() vs sorted(anylist) ? Also, please point out if I am doing anything wrong with way this is measured. """ Example Output: $ python list_sort_timeit.py Using sort method: 20.0662879944 Us...

Python HTML Minimizer

I have a cherrypy web server that uses larges amounts of HTML data. Is there anyway in Python to minimize the HTML so that all comments, spaces, ext, are removed? ...

How to install iPython on Snow Leopard

Does iPython work on Mac OS X 10.6.1 Snow Leopard? I'm python noob, how can I install iPython on my Mac? Links? suggestions? Thanks ...

What are the risks (if any) of mixing Psyco into my project?

I work on a large financial pricing application in which some long running calculations. We have identified some functions which can be sped up by the selective application of psyco. My management have requested an assessment of the costs & benefits of adding psyco into our stack. Given the critical nature of my project, it's not acce...

Python library for (n)curses widgets

While Python's standard library has a module for curses, that seems to require a lot of fairly low-level handling. Is there a simpler way to get started with writing a basic curses UI which includes standard elements like checkboxes, input fields etc.? I've found urwid, but not sure whether that's the state of the art. ...

Encoding problems in PyQt

My program stores file index in file packed by cPickle. There are non-english filenames. When I just do this print f [0] where f [0] is "\xc2\xe8\xf1\xee\xea\xee\xf1\xed\xfb\xe9 \xe3\xee\xe4" ("Високосный год" in normal view), it prints the string in proper way — in russian. When the program manually adds the string u'Високосный год'...

Why does Psyco use a lot of memory?

Psyco is a specialising compiler for Python. The documentation states Psyco can and will use large amounts of memory. What are the main reasons for this memory usage? Is substantial memory overhead a feature of JIT compilers in general? Edit: Thanks for the answers so far. There are three likely contenders. Writing multiple spec...

Installing Python Imaging Library (PIL) on Snow Leopard with updated Python 2.6.2

I have a fresh install (started with a wiped drive) of Snow Leopard with the developer tools installed during the Snow Leopard installation. I then installed Python 2.6.2, replacing the Snow Leopard default python 2.6.1. I've tried to install PIL by (1) easy_install (2) pip and (3) downloading source and running "python setup.py build" m...

pygresql - insert and return serial

I'm using PyGreSQL to access my DB. In the use-case I'm currently working on; I am trying to insert a record into a table and return the last rowid... aka the value that the DB created for my ID field: create table job_runners ( id SERIAL PRIMARY KEY, hostname varchar(100) not null, is_available boolean default...

Google App Engine urlfetch to POST files

I am trying to send a file to torrage.com from an app in GAE. the file is stored in memory after being received from a user upload. I would like to be able to post this file using the API available here: http://torrage.com/automation.php but i am having some problems undestanding how the body of the post should be encoded, the most i go...