Constructor call in the same class?

Discussion in 'Python' started by Karsten Wutzke, Jul 25, 2010.

  1. What's wrong with:

    class Enum(RootFragment):
    __jpaTypes = {
    # complete!
    'CascadeType': Enum("javax.persistence.CascadeType"),
    'DiscriminatorType':
    Enum("javax.persistence.DiscriminatorType"),
    'EnumType': Enum("javax.persistence.EnumType"),
    'FetchType': Enum("javax.persistence.FetchType"),
    'FlushModeType': Enum("javax.persistence.FlushModeType"),
    'GenerationType': Enum("javax.persistence.GenerationType"),
    'InheritanceType': Enum("javax.persistence.InheritanceType"),
    'LockModeType': Enum("javax.persistence.LockModeType"),
    'PersistenceContextType':
    Enum("javax.persistence.PersistenceContextType"),
    'TemporalType': Enum("javax.persistence.TemporalType"),
    }

    # constructor
    def __init__(self, package, modifiers, name, superInterfaces = [],
    annotations = [], innerClasses = [], properties = [],
    methods = []):
    RootFragment.__init__(self, packageName, modifiers, "enum",
    name, superInterfaces, annotations, innerClasses, properties, methods)


    ?

    I get

    'CascadeType': Enum("javax.persistence.CascadeType"),

    NameError: name 'Enum' is not defined

    What's wrong with calling a constructor in a dict initializer? How do
    I solve this?

    Karsten
     
    Karsten Wutzke, Jul 25, 2010
    #1
    1. Advertisements

  2. On 07/25/2010 05:41 PM, Karsten Wutzke wrote:
    > What's wrong with:
    >
    > class Enum(RootFragment):
    > __jpaTypes = {
    > # complete!
    > 'CascadeType': Enum("javax.persistence.CascadeType"),
    > 'DiscriminatorType':
    > Enum("javax.persistence.DiscriminatorType"),
    > 'EnumType': Enum("javax.persistence.EnumType"),
    > 'FetchType': Enum("javax.persistence.FetchType"),
    > 'FlushModeType': Enum("javax.persistence.FlushModeType"),
    > 'GenerationType': Enum("javax.persistence.GenerationType"),
    > 'InheritanceType': Enum("javax.persistence.InheritanceType"),
    > 'LockModeType': Enum("javax.persistence.LockModeType"),
    > 'PersistenceContextType':
    > Enum("javax.persistence.PersistenceContextType"),
    > 'TemporalType': Enum("javax.persistence.TemporalType"),
    > }
    >
    > # constructor
    > def __init__(self, package, modifiers, name, superInterfaces = [],
    > annotations = [], innerClasses = [], properties = [],
    > methods = []):
    > RootFragment.__init__(self, packageName, modifiers, "enum",
    > name, superInterfaces, annotations, innerClasses, properties, methods)
    >
    >
    > ?
    >
    > I get
    >
    > 'CascadeType': Enum("javax.persistence.CascadeType"),
    >
    > NameError: name 'Enum' is not defined


    well, within the class statement, it's not defined. So you can't call
    Enum yet.

    You have to create your dict somewhere else. You can either set it from
    outside:

    class Enum(RootFragment):
    ...

    Enum._jpaTypes = { ... }


    Or, do exactly the same thing, but within a class method:

    class Enum(bla):
    @classmethod
    def contruct_jpatypes(cls):
    cls.__jpaTypes = { ... }

    Enum.construct_jpatypes()

    >
    > What's wrong with calling a constructor in a dict initializer? How do
    > I solve this?
    >
    > Karsten
     
    Thomas Jollans, Jul 25, 2010
    #2
    1. Advertisements

  3. >
    > You have to create your dict somewhere else. You can either set it from
    > outside:
    >
    > class Enum(RootFragment):
    >     ...
    >
    > Enum._jpaTypes = { ... }
    >


    THANKS for the quick help.

    Karsten
     
    Karsten Wutzke, Jul 25, 2010
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Graham
    Replies:
    3
    Views:
    678
    Matt Graham
    Feb 7, 2004
  2. mrstephengross
    Replies:
    5
    Views:
    834
    Larry I Smith
    May 18, 2005
  3. Replies:
    9
    Views:
    1,265
    Alf P. Steinbach
    Mar 6, 2006
  4. Taran
    Replies:
    6
    Views:
    613
    Default User
    Apr 20, 2006
  5. ali
    Replies:
    4
    Views:
    842
    David Harmon
    Mar 5, 2007
  6. Rahul
    Replies:
    16
    Views:
    1,518
    terminator
    Nov 7, 2007
  7. Generic Usenet Account
    Replies:
    10
    Views:
    2,938
  8. Ciro De Martino

    call constructor class of class father

    Ciro De Martino, Jul 19, 2011, in forum: C++
    Replies:
    1
    Views:
    403
    Victor Bazarov
    Jul 19, 2011
Loading...