I recently started using Python 2.6 for Ubuntu Server admin and have two minor issues concerning redundancy:
First thing are imports: They all look something like
import Class from Class
from class import Class
And the second thing are __init__ methods:
__init__(self,arg1,...,argn):
self.arg1 = arg1
...
self.argn = argn
Are there ways to avoid these duplications?
The second thing is not redundancy – it is setting instance attributes. You can do it also like this:
But then you need to call Foo like this:
Also your import seems to have improper syntax. It should be
from Class import Class. This looks redundant to you, because it seems, that you are storing each class in a separate file (module) – and that is exactly redundant. Python is not Java, you should usually hold more objects in one module. Keep in mind, that module itself is an object. Also you should name modules properly – the default code style guide says that modules should be all lowercase with no special chars. Likereorurllibfor example.