[mod_python] (no subject)

Jeff Hinrichs - DM&T jeffh at dundeemt.com
Fri Jun 2 08:45:17 EDT 2006


This line is requesting the value of the Instance Attribute count
 funcWrite(c.count)    # HERE ERROR OCCURS with count
as opposed to the Class Attribute count

see here:
#!/usr/bin/env python

class foo:
    a = 0     #Class Attribute
    def __init__(self):
        #self.__class__.__dict__['a'] += 1  #Another way to access
Class Attribute
        self.__class__.a += 1   # Inc Class Attribute
        self.a = -1   # Make the instance attribute something different

bar = foo()

print foo.a
print bar.a

foo.a += 1

print foo.a
print bar.a

baz = foo()
print foo.a
print bar.a
print baz.a

print foo.a
print bar.a
print baz.a


-Jeff
p.s. This is with python 2.4

On 6/2/06, S.R.Pardá <linux at qbox.es> wrote:
> Hi,
>
> I am desperated, I can't see the origin of this problem:
>
> I have code like the next, but I receive errors using a class
> attribute.
> Sometimes in __init__ method in Cliente I receive an error  saying
> variable count has not been initiated (but count=0 is there to
> initialize it)
>
> Other times the error is accesing c.count, saying that count is not a
> member of Cliente.
>
>
>
>
> -- modcli.py ----------------------------------------------------------
> class Cliente:
>         "Documentacion"
>         count=0
>
>         def __init__(self, name):
>                 self.__class__.count += 1   # Sometimes ERROR here
>                 self.nombre = name
>
> -- modform.py ------------------------------------------------------
> import modcli
> class Form:
>         def __init__(self, funcWrite):
>                 c = modcli.Cliente('NOMBRE')
>                 .
>                 .
>                 .
>                 #AND I TRY to verify here writing the expected value :
>
>                 funcWrite(c.count)    # HERE ERROR OCCURS with count
>
>                 # else tried:  modcli.Cliente.count
>                 # and:  c.__class__.count
>
>                 return c
>
> -- control.htm -----------------------------------------------------
> <div> or
> <%
> modForm = apache.import_module('modform')
>
> cli = modForm.Form(req.write)
> %>
> <%=cli.nombre%>
> </div>
>
> -- index.psp ----------------------------------------------------
> <BODY ...
> <HTML>
>         <!-- include file="control.htm" -->
> </HTML>
>
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


-- 
Jeff Hinrichs
Dundee Media & Technology, Inc
jeffh at dundeemt.com
402.320.0821



More information about the Mod_python mailing list