I am trying to access a variable from the base class. Here's the parent class:

class Parent(object):
    def __init__(self, value):
        self.some_var = value

And here's the child class:

class Child(Parent):
    def __init__(self, value):
        super(Child, self).__init__(value)

    def doSomething(self):
        parent_var = super(Child, self).some_var

Now, if I try to run this code:

obj = Child(123)

I get the following exception:

Traceback (most recent call last):
  File "test.py", line 13, in <module>
  File "test.py", line 10, in doSomething
    parent_var = super(Child, self).some_var
AttributeError: 'super' object has no attribute 'some_var'

What am I doing wrong? What is the recommended way to access variables from the base class in Python?

I am trying to run to run django and flask on the same apache server.

WSGISocketPrefix /var/www/wsgi
<VirtualHost *:80>
        ServerAdmin name@email.com
        ServerName  domain.com
        ServerAlias www.domain.com
        DocumentRoot /var/www/
        LogLevel warn
        WSGIDaemonProcess apache processes=2 maximum-requests=500 threads=1
        WSGIProcessGroup apache
        Alias /media /var/www/media/

        WSGIScriptAlias / /var/www/djangoapps/django.wsgi
        WSGIScriptAlias /app1 /var/www/flaskapps/app.wsgi
  1. The first WSGIScriptAlias runs a django app in the root: domain.com.
  2. The second instance of WSGIScriptAlias needs to run a flask app in a subdomain: app1.

But since the main site sits over django, when I try to hit: domain.com/app1, django's urls.py tries to handle that url command. But urls.py should not handle it, since its an independent flask app.

Any ideas how can I go about it?

I have a small utility that I use to download an MP3 file from a website on a schedule and then builds/updates a podcast XML file which I've added to iTunes.

The text processing that creates/updates the XML file is written in Python. However, I use wget inside a Windows .bat file to download the actual MP3 file. I would prefer to have the entire utility written in Python.

I struggled to find a way to actually download the file in Python, thus why I resorted to using wget.

So, how do I download the file using Python?

This code works, but I wonder if there is any simpler way:

def center(self):
    qr = self.frameGeometry()
    cp = gui.QDesktopWidget().availableGeometry().center()

What is best pure Python implementation to check if a string contains ANY letters from the alphabet?

string_1 = "(555).555-5555"
string_2 = "(555) 555 - 5555 ext. 5555

Where string_1 would return False for having no letters of the alphabet in it and string_2 would return True for having letter.

What is the best way to write the contents of a StringIO buffer to a file ?

I currently do something like:

buf = StringIO()
fd = open('file.xml', 'w')
# populate buf
fd.write(buf.getvalue ())

But then buf.getvalue() would make a copy of the contents?

I have some global variables in a Python script. Some functions in that script call into C - is it possible to set one of those variables while in C and if so, how?

I appreciate that this isn't a very nice design in the first place, but I need to make a small change to existing code, I don't want to embark on major refactoring of existing scripts.

I'm making dictionary:

d = {"server":"mpilgrim", "database":"master"}
d['mynewkey'] = 'mynewvalue'

But when I display it I saw that this dict is reversed.


{'mynewkey': 'mynewvalue', 'database': 'master', 'server': 'mpilgrim'}

How to reverse it back?

Or if it is true that dictionary is not sortable what I must to use to have collection where the order of that informations matters?

Can I use:

if A:

instead of

if A is not None:

The latter seems so verbose. Is there a difference?

How can I set a figure window's title in pylab/python?

fig = figure(9) # 9 is now the title of the window
fig.set_title("Test") #doesn't work
fig.title = "Test" #doesn't work