Order in metaclass

Carlos Ribeiro carribeiro at gmail.com
Thu Oct 14 09:10:20 EDT 2004


On Thu, 14 Oct 2004 10:11:37 +0200, Peter Otten <__peter__ at web.de> wrote:
> Carlos Ribeiro wrote:
> 
> > if not isinstance(value, self.mytype):
> >     # if it's a string, tries to convert to the correct
> >     # target type (this is needed because most things read
> >     # from files will be strings anyway)
> >     if isinstance(value, StringType):
> >         value = self.mytype(value)
> 
> I haven't checked if this is relevant in the context, but implicit
> conversion from string is usually a bad thing. E. g.:
> 
> >>> bool("False"), bool("0")
> (True, True)

I had to do it to be able to read values written in configuration
files. When I write the attributes to the text file, I lose the type
information, and all that I have when I re-read them is the string
representation. In this case, the best that I can do is to try to
force the conversion from the string to the correct type.

-- 
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com



More information about the Python-list mailing list