python

Python: how do I implement 'pop' in this class?

I'd like this class to act like a list. It's data resides in the attribute self.data. If I have an instance, pp = population, does defining __getitem__ mean I can refer to pp instead of pp.data? Or is it the defining of __repr__ that does that? Would deriving this class from list instead of object provide me with 'pop'. Right now I n...

Google App Engine - Request class query_string

Hi all, In Python and GAE, I would like to ask how to get the parameters of a query string in the url. As I know, the query_string part returns all the part after the "?" in the url. So what I have to do is to split the query string with "&", and use the variables. Is there any other convinient way to manage the query string? How do yo...

function decorators in c#

Is there a C# analog for Python's function decorators? It feels like it's doable with attributes and the reflection framework, but I don't see a way to replace functions at runtime. Python decorators generally work this way: class decorator(obj): def __init__(self, f): self.f = f def __call__(self, *args, **kwargs): ...

Pyqt GroupBox parenting

In Python and Pyqt - I've got a simple class which instantiates a Label class and a GroupBox class. According to docs, passing the Groupbox to the Label upon creation should make the Groupbox the parent of Label. However, I must be missing something simple here. When I create the GroupBox it's fine, when I create the Label however - it...

Application Structure for GUI & Functions

I'm starting a basic application using Python and PyQt and could use some experienced insight. Here's the structure I was thinking. This is understandably subjective, but is there a better way? myApp/GUI/__init__.py mainWindow.py subWindow1.py subWindow2.py myApp/Logic/__init__.py setOfMethods1...

similar function to php's str_replace in python?

is there a similar function in python that takes search(array) and replace(array) as a parameter? Then takes a value from each array and uses them to do search and replace on subject(string). I know I can achieve this using for loops, but just looking more elegant way. ...

easy way of installing python apps without using PYTHON path or muli symlink in site-package

Hi, I didn't want to install python modules using easy install, symlinks in site-packages or PYTHONPATH. So, I am trying something that I do wants system wide, then any application installation is done locally. Note, the root password is required only once here. First create a symblink of.../pythonX.Y/site-packages/mymodules -> /home/...

Django: How to create a leaderboard

Lets say I have around 1,000,000 users. I want to find out what position any given user is in, and which users are around him. A user can get a new achievement at any time, and if he could see his standing update, that would be wonderful. Honestly, every way I think of doing this would be horrendously expensive in time and/or memory. Id...

Is it possible to deploy one GAE application from another GAE application?

In order to redeploy a GAE application, I currently have to install the GAE deployment tools on the system that I am using for deployment. While this process is relatively straight forward, the deployment process is a manual process that does not work from behind a firewall and the deployment tools must be installed on every machine that...

Python web scraping involving HTML tags with attributes

I'm trying to make a web scraper that will parse a web-page of publications and extract the authors. The skeletal structure of the web-page is the following: <html> <body> <div id="container"> <div id="contents"> <table> <tbody> <tr> <td class="author">####I want whatever is located here ###</td> </tr> </tbody> </table> </div> </div> </...

How can I run gtk.main() asynchronsly in pygtk?

The basic code that I have so far is below. How do I thread gtk.main() so that the code after Display is initialized runs asynchronously? import pygtk pygtk.require("2.0") import gtk class Display(): def __init__(self): self.fail = "This will fail to display" window = gtk.Window(gtk.WINDOW_TOPLEVEL) window....

What are some small, fast and lightweight open source applications (µTorrent -esque)?

Possible duplicate What is the best open source example of a lightweight Windows Application? µTorrent is a small bit-torrent client, a really small one. It doesn't come with an installer, just a exe, you drop in your PATH somewhere. It's super lightweight and yet feature rich. Plus it is the work of one man. It's also close...

how to encode a key in mime format

if the key is in ascii armored form ,taken by any pgp public key server and i want to convert it in mime encoded format.how to do ?is there any python api methods ? thnks a lot ...

Advantages of UserDict class in Python

What are advantages of using UserDict class? I mean, what I really get if instead of class MyClass(object): def __init__(self): self.a = 0 self.b = 0 ... m = MyClass() m.a = 5 m.b = 7 I will write the following: class MyClass(UserDict): def __init__(self): UserDict.__init__(self) self["a"] = 0...

Calculating a directory size using Python?

Before i re-invent this particular wheel, has anybody got a nice routine for calculating the size of a directory using Python? It would be very nice if the routine would format the size nicely in Mb/Gb etc. Thanks. ...

Python: Why is ("hello" is "hello")?

Why is "hello" is "hello" == True in Python? I read the following here: "If two string literals are equal, they have been put to same memory location. A string is an immutable entity. No harm can be done." So there is one and only one place in memory for every Python string? Sounds pretty strange. What's going on here? ...

What python data structure and parser should I use with Apple's system_profiler?

My problem is one like a simulated problem from http://my.safaribooksonline.com/0596007973/pythoncook2-CHP-10-SECT-17 which eventually made its way into Python Cookbook, 2nd Edition using an outdated xpath method from 2005 that I haven't been able to get to work with 10.6's build-in python(nor installing older packages) I want to ......

Django template, how to make a dropdown box with the predefined value selected?

Hi all, I am trying to create a drop down list box with the selected value equal to a value passed from the template values, but with no success. Can anyone take a look and show me what I am doing wrong. <select name="movie"> {% for movie in movies %} {% ifequal movie.id selected_movie.id %} <option value="{{movie.k...

Problem with subprocess.call

In my current working directory I have the dir ROOT/ with some files inside. I know I can exec cp -r ROOT/* /dst and I have no problems. But if I open my Python console and I write this: import subprocess subprocess.call(['cp', '-r', 'ROOT/*', '/dst']) It doesn't work! I have this error: cp: cannot stat ROOT/*: No such file or dire...

using RSPython in MacOSX

Dear all, I am trying to install the R/SPlus - Python Interface (RSPython) on my Mac OS X 10.4.11 with R version 2.7.2 (2008-08-25) and python 2.6.2 from fink. The routine: sudo R CMD INSTALL -c RSPython_0.7-1.tar.gz produced this error message: * Installing to library '/Library/Frameworks/R.framework/Resources/library' * Installin...