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. Advertising

  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. Advertising

  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. Advertising

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. mrstephengross
    Replies:
    5
    Views:
    623
    Larry I Smith
    May 18, 2005
  2. Replies:
    9
    Views:
    998
    Alf P. Steinbach
    Mar 6, 2006
  3. ali
    Replies:
    4
    Views:
    629
    David Harmon
    Mar 5, 2007
  4. Rahul
    Replies:
    16
    Views:
    1,249
    terminator
    Nov 7, 2007
  5. Generic Usenet Account
    Replies:
    10
    Views:
    2,349
Loading...

Share This Page