Attributes in privates methods
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Fri Feb 19 11:26:53 EST 2010
Yasser Almeida Hernández a écrit :
> Hi all.
>
> I have a class with the attribute 'log_file', opened out of the class:
> class ProteinCluster:
> def __init__(self,cluster_name,log_file):
> ...
> self.log_file = log_file
> ...
> Then i have a private method which write in the log_file:
> def _read_structure(self, pdb_code):
> ...
> ...
> self.log_file.write('blablabla')
> ...
> ...
> When i run the script, it raises the error:
> AttributeError: ProteinCluster instance has no attribute 'log_file'
>
> My question is, the class attributes are valids in private methods, like
> in publics methods?
Diez already answered - the above code seems correct, so the source of
your problem is elsewhere.
For the record, in your code, log_file is an instance attribute - a
'class attribute' is an attribute that is defined on the class object
itself, and is shared by all instances of the class.
Also, Python has no notion of "public" or "private" - at least at the
language level. The '_name' convention is just, well, a naming convention.
This wont solve your problem - sorry, not much we can do here - but at
least it will help wrt/ mutual understanding !-)
More information about the Python-list
mailing list