python class question

Axel Bock news-and-lists at the-me.de
Fri Jul 26 13:32:39 EDT 2002


On Fri, 26 Jul 2002 09:53:09 +0200, Jonathan Hogg wrote:

> On 25/7/2002 19:38, in article Xns9256D2197BD87cliechtigmxnet at 62.2.16.82,
> "Chris Liechti" <cliechti at gmx.net> wrote:
> 

> Because that won't work. Look again at the code above. It gets an
> attribute of self with the *name* stored in 'connection'. I don't know
> where 'connection' comes from here. The code that you've shown us Axel
> would never have worked, so I'm guessing it is the result of playing with
> the original code.
> 
> I'm guessing it should have read something along the lines of:
> 
>     dbc = getattr( self, self.connection )

 

yeah, sorry, this is like it looks. I forgot the "self".
 


>>> Now I tried to modify the last line as follows:
>>>           self.DB = dbc()
>>> and getting a very strange error (Error Type: UnpickleableError Error
>>> Value: Cannot pickle <type 'type'> objects).
>> 
>> don't know Zope but it look like that it uses pickle to store your
>> instaces and the DB object cannot be picked. thats probably because the
>> connection to a database cannot be stored, it must be terminated and
>> rebuild, but thats doesn't seem to be supported by the db object.


 
But what am I trying to do? I try to assign the reference to a new object
to a member variable - so why does this not work??
 









> No, I'd say (as above) that 'self.connection' is a string, which means
> that 'self' has a method (or instance variable that refers to a class?)
> called 'MySQL_database_connection'. See what
> 'self.MySQL_database_connection' is.


 
This is an instance of "Connection". But why can "dbc()" deliver an
instance of "DB" ??? (DB is a class, I checked)
 
> Then perhaps you should just do the same in the member functions, i.e.,
> call the machinery that creates a database connection. You could always
> wrap it in a method that returns a database connection.

 
I can always ... how? ;-)) 
 

 

Thanks a lot, 
 


		Axel. 





More information about the Python-list mailing list