Declaring a class level nested class?

cmckenzie mckenzie.c at gmail.com
Thu Dec 3 10:01:02 EST 2009


On Dec 3, 9:59 am, cmckenzie <mckenzi... at gmail.com> wrote:
> Sigh, I'm using Google Groups and it seems I can't see my original
> post and everyone's replies. I'm really keen to reply back, so I'll
> just re-post my follow up for now and make sure I don't make a habit
> of this. (I'll get a news reader) Here goes:
>
> I agree, I'm C# and Java influenced, but I've got some messy Perl
> experience too.
>
> It was late when I posted my example, so I don't think I made my
> question clear enough. I want to be able to construct a class level
> class variable, so its global to the class, then reference it from a
> class method. I wrote a web server that uses reflection to dynamically
> load modules which are mapped to url paths. e.g. module "search.py"
> maps to "search.html", etc... It all works great, but I want my
> modules to be able to __init__ classes that belong to the module, then
> when a request comes in and is passed to the module, I can reference
> that initialized class.
>
> The declaration of a class level nestedClass class variable is wrong,
> but I was hoping someone could just say, "dummy, this is how to
> declare a class variable when you can't construct it just yet", or
> "you have to construct an empty version of nestedClass at the class
> level, then just re-construct it with any parameters during __init__".
>
> class module:
>   nestedClass
>
>   def __init__():
>      self.nestedClass = nested(10)
>      print self.nestedClass.nestedVar
>
>   def getNestedVar(self):
>      return self.nestedClass.nestedVar
>
>   class nested():
>      nestedVar = 1
>      def __init__(self, value):
>         nestedVar = value
>         print "Initialized..."
>
> Thanks and sorry for double posting, it won't happen again.

Ok, it seems that my original post was present, just not searchable?
Forget my confusion on this. Thanks.



More information about the Python-list mailing list