Steven W. Orr a écrit :
> On Thursday, Feb 1st 2007 at 21:45 +0100, quoth Bruno Desthuilliers:
>
(snip)
> =>irrational_const = const.__class__()
> =>even_const = const.__class__()
> =>
> =>Now while I find this hack interesting, it's also totally unpythonic
> =>IMHO. The usual convention is to u
On Thursday, Feb 1st 2007 at 21:45 +0100, quoth Bruno Desthuilliers:
=>Steven W. Orr a écrit :
=>> I saw this and tried to use it:
=>>
=>> --><8--- const.py-
=>> class _const:
=>> class ConstError(TypeError): pass
=>> def __setattr__(self,name,v
Steven W. Orr a écrit :
> I saw this and tried to use it:
>
> --><8--- const.py-
> class _const:
> class ConstError(TypeError): pass
> def __setattr__(self,name,value):
> if self.__dict__.has_key(name):
> raise self.ConstError
Paul Rubin a écrit :
> "Steven W. Orr" <[EMAIL PROTECTED]> writes:
>
>>AttributeError: _const instance has no attribute '_const'
>>
>>What am I missing here? (Sorry if it should be obvious)
>
>
> Oh I see. No it's not obvious. module "const" has gotten overwritten
> by the _const instance. I
"Steven W. Orr" <[EMAIL PROTECTED]> writes:
> AttributeError: _const instance has no attribute '_const'
> >>>
> What am I missing here? (Sorry if it should be obvious)
Oh I see. No it's not obvious. module "const" has gotten overwritten
by the _const instance. I think that module author was to
On Thursday, Feb 1st 2007 at 10:36 -0800, quoth Paul Rubin:
=>"Steven W. Orr" <[EMAIL PROTECTED]> writes:
=>> to cause a different instantiation a la
=>> foo = _const()
=>> The goal would be to create different instances of consts.
=>
=>The idea of putting it in sys.modules is so it's visible in a
"Steven W. Orr" <[EMAIL PROTECTED]> writes:
> to cause a different instantiation a la
> foo = _const()
> The goal would be to create different instances of consts.
The idea of putting it in sys.modules is so it's visible in all modules.
> >>> import const
> >>> iii=_const()
You need
iii =
On Thursday, Feb 1st 2007 at 09:25 -0800, quoth Bart Ogryczak:
=>On Feb 1, 5:52 pm, "Steven W. Orr" <[EMAIL PROTECTED]> wrote:
=>> I saw this and tried to use it:
=>>
=>> --><8--- const.py-
=>[...]
=>> sys.modules[__name__]=_const()
=>
=>__name__ == 'con
On Feb 1, 5:52 pm, "Steven W. Orr" <[EMAIL PROTECTED]> wrote:
> I saw this and tried to use it:
>
> --><8--- const.py-
[...]
> sys.modules[__name__]=_const()
__name__ == 'const', so you´re actually doing
const = _const()
--
http://mail.python.org/mail
"Steven W. Orr" <[EMAIL PROTECTED]> writes:
> --><8--- const.py-
> ...
> sys.modules[__name__]=_const()
__name__ is 'const' since this file is const.py. So you've
juset set the const module to actually be a const instance.
> 1. Why do I not have to say
I saw this and tried to use it:
--><8--- const.py-
class _const:
class ConstError(TypeError): pass
def __setattr__(self,name,value):
if self.__dict__.has_key(name):
raise self.ConstError, "Can't rebind const(%s)"%name
11 matches
Mail list logo