You need to use the 'self' keyword. So inside the function variable, you'd say self.f = 5 . Then when you call printf, you'd say print(self.f) .
By not making the variable a property of the class by using 'self', you're just making it in the local scope of the function. And, when you call a class' functions from within itself, you also need to attach 'self' in front. Like if within a function on class W, you wanted to make a call to its printf function, you'd use self.printf() .
Here's is the documentation about scopes and name spaces regarding classes in Python: http://docs.python.org/tutorial/classes.html#python-scopes-and-name-spaces .
Hope that helped!