python

How can I retrieve the page title of a webpage using Python?

How can I retrieve the page title of a webpage (title html tag) using Python? ...

Passing on named variable arguments in python

Say I have the following 2 methods: def methodA(arg, **kwargs): pass def methodB(arg, *args, **kwargs): pass In methodA I wish to call methodB, passing on the kwargs. However, it seems if I simply do: def methodA(arg, **kwargs): methodB("argvalue", kwargs) The second argument will be passed on as positional rather than...

Improving Python readability?

I've been really enjoying Python programming lately. I come from a background of a strong love for C-based coding, where everything is perhaps more complicated than it should be (but puts hair on your chest, at least). So switching from C to Python for more complex things that don't require tons of speed has been more of a boon than a ba...

How to get an absolute file name in Python?

Given a path such as "mydir/myfile.txt" How do I find the absolute filename relative to the current working directory in Python? E.g. on Windows, I might end up with: "C:/example/cwd/mydir/myfile.txt" ...

Why are SQL aggregate functions so much slower than Python and Java (or Poor Man's OLAP)

I need a real DBA's opinion. Postgres 8.3 takes 200 ms to execute this query on my Macbook Pro while Java and Python perform the same calculation in under 20 ms (350,000 rows): SELECT count(id), avg(a), avg(b), avg(c), avg(d) FROM tuples; Is this normal behaviour when using a SQL database? The schema (the table holds responses to a s...

Cross-platform space remaining on volume using python

I need a way to determine the space remaining on a disk volume using python on linux, Windows and OS X. I'm currently parsing the output of the various system calls (df, dir) to accomplish this - is there a better way? ...

Pretty graphs and charts in Python

What are the best libraries for creating pretty charts and graphs in a Python application? ...

Large Python Includes

I have a file that I want to include in Python but the included file is fairly long and it'd be much neater to be able to split them into several files but then I have to use several include statements. Is there some way to group together several files and include all at once? ...

How can I do a line break (line continuation) in Python?

I have a long line of code that I want to break up among multiple lines. What do I use and what is the syntax? For example, adding a bunch of strings: e = 'a' + 'b' + 'c' + 'd' have it like this: e = 'a' + 'b' + 'c' + 'd' ...

Getting international characters from a web page?

I want to scrape some information off a football (soccer) web page using simple python regexp's. The problem is that players such as the first chap, ÄÄRITALO, comes out as ÄÄRITALO! That is, html uses escaped markup for the special characters, such as Ä Is there a simple way of reading the html into the correct python st...

How do you check whether a python method is bound or not?

Given a reference to a method, is there a way to check whether the method is bound to an object or not? Can you also access the instance that it's bound to? ...

What are some good Python ORM solutions?

I'm evaluating and looking at using CherryPy for a project that's basically a javascript front-end from the client-side (browser) that talks to a Python web service on the back-end. So, I really need something fast and lightweight on the back-end that I can implement using Python that then speaks to the PostgreSQL db via an ORM (JSON to ...

Python: What is the best way to check if a list is empty?

For example, if passed the following: a = [] How do I check to see if a is empty? ...

What are some strategies to write python code that works in CPython, Jython and IronPython

Having tries to target two of these environments at the same time I can safely say the if you have to use a database etc. you end up having to write unique code for that environment. Have you got a great way to handle this situation? ...

How do i generate a histogram for a given probability distribution (for functional testing a server)

I am trying to automate functional testing of a server using a realistic frequency distribution of requests. (sort of load testing, sort of simulation) I've chosen the Weibull distribution as it "sort of" matches the distribution I've observed (ramps up quickly, drops off quickly but not instantly) I use this distribution to generate t...

Any good AJAX framework for Google App Engine apps?

I am trying to implement AJAX in my Google App Engine application, and so I am looking for a good AJAX framework that will help me. Anyone has any idea? I am thinking about Google Web Toolkit, how good it is in terms of creating AJAX for Google App Engine? ...

Old style and new style classes in Python

What is the difference between old style and new style classes in Python? Is there ever a reason to use old-style classes these days? ...

What's the best Django search app?

I'm building a Django project that needs search functionality, and until there's a django.contrib.search, I have to choose a search app. So, which is the best? By "best" I mean... easy to install / set up has a Django- or at least Python-friendly API can perform reasonably complex searches Here are some apps I've heard of, please sug...

In Python, how can you easily retrieve sorted items from a dictionary?

Dictionaries unlike lists are not ordered (and do not have the 'sort' attribute). Therefore, you can not rely on getting the items in the same order when first added. What is the easiest way to loop through a dictionary containing strings as the key value and retrieving them in ascending order by key? For example, you had this: d = {...

How can I get Emacs' key bindings in Python's IDLE?

I use Emacs primarily for coding Python but sometimes I use IDLE. Is there a way to change the key bindings easily in IDLE to match Emacs? ...