×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    47

    Using declarations from types.py

    Hi

    I am trying to use a python module on a N95 phone that has PyS60 v1.4.2

    I am getting a error on this line
    Code:
    if type(rules) not in (NoneType, DictType):
    
    NameError: global name 'NoneType' is not defined
    At the top of the module file there is
    Code:
    from Types     import *
    that should include everything from the types.py file that is in the PyS60 distribution (I have checked).

    I have tried several things to get this to work, for example to include the types like this
    Code:
    from types import NoneType
    from types import DictType
    (Then I got a error that this could not be imported)

    Also to change the input like this
    Code:
    import types
    and have the if condition like
    Code:
    if type(rules) not in (types.NoneType, types.DictType):
    but then I get
    Code:
    AttributeError: 'module' object has no attribute 'NoneType'
    Anyone who knows what I am doing wrong or how this could be fixed.

    kindest regards,
    Magnus Agust Skulason

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: Using declarations from types.py

    It looks ok, but maybe you can change the logic...

    Code:
    import Types
    
    if type(rules) in (types.NoneType, types.DictType):
        pass
    else:
        # handle here NoneType and DictType
    or maybe

    Code:
    if type(rules) != types.NoneType and type(rules) != types.DictType:
        # handle
    or changing negation location

    Code:
    if not type(rules) in (types.NoneType, types.DictType):
    Disclaimer: I didn't put any of this through python interpreter, just looked at it and turned some lines around... Anyway, please report how did you finally solve this problem!

  3. #3
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    Thumbs up Re: Using declarations from types.py

    Quote Originally Posted by maggias View Post
    Hi

    I am trying to use a python module on a N95 phone that has PyS60 v1.4.2

    I am getting a error on this line
    Code:
    if type(rules) not in (NoneType, DictType):
    
    NameError: global name 'NoneType' is not defined
    At the top of the module file there is
    Code:
    from Types     import *
    that should include everything from the types.py file that is in the PyS60 distribution (I have checked).

    I have tried several things to get this to work, for example to include the types like this
    Code:
    from types import NoneType
    from types import DictType
    (Then I got a error that this could not be imported)

    Also to change the input like this
    Code:
    import types
    and have the if condition like
    Code:
    if type(rules) not in (types.NoneType, types.DictType):
    but then I get
    Code:
    AttributeError: 'module' object has no attribute 'NoneType'
    Anyone who knows what I am doing wrong or how this could be fixed.

    kindest regards,
    Magnus Agust Skulason
    Hello everybody ,

    @magnus : Look below and find THE SOLUTION :-D


    @everybody loving PyS60 : I'm back for PyS60 :-)

    Best Regards
    Cyke64

    Code:
    from types import *  
    
    rules=[] 
    #rules=None
    #rules=()
    #rules={}
    
    print type(rules)
    
    # deprecated but works with PyS60 (Python 2.2)
    # dont use   type(rules) != type(NoneType) !
    if type(rules) != type(None) and type(rules) != type({}):
       print u"OK deprecated type 1"
    
    # deprecated but works with PyS60 (Python 2.2)
    if (type(rules) is not type(None)) and type(rules) is not type({}):
       print u"OK deprecated type 2"
    
    # recommended for Python >= 2.2 and also PyS60 !
    if not isinstance(rules, (NoneType, DictType)):
       print u"OK isinstance"
    pys60 1.4.5 and 2.0.0, pygame, PyS60 CE on E90 and 5800 !

    Find my pys60 extension modules on cyke64.googlepages.com

  4. #4
    Wiki Moderators
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,779

    Smile Re: Using declarations from types.py

    Hi Cyke64,

    Welcome Home my friend
    Really missed you here.

    Best Regards
    Croozeus
    Pankaj Nathani
    www.croozeus.com

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    47

    Re: Using declarations from types.py

    Hi cyke64,

    Thank you very much
    if type(rules) != type(None) and type(rules) != type({}):
    seems to work

    But brought me a similar error on
    Code:
    if type(name) in (ListType, TupleType):
    
    NameError: global name 'ListType' is not defined
    am I right to asume that that this should work correctly?
    Code:
    if type(rules) == type([]) or type(rules) == type(()):
    I first tried to use
    if not isinstance (rules, (NoneType, DictType)):
    for the first error, but that still resulted in the error
    NameError: global name 'NoneType' is not defined

    Thanks again,
    Magnus Agust Skulason

  6. #6
    Registered User
    Join Date
    Mar 2008
    Posts
    47

    Re: Using declarations from types.py

    hi

    any one who knows how to successfully do the following check in PyS60?

    if type(obj) == InstanceType:
    STATEMENT1
    else:
    STATEMENT2

    fails with a type exception when done like this, I probably have to create some empty Instance and do type() on it. But not sure how that is best done.

    Thanks in advance
    Magnus

  7. #7
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Using declarations from types.py

    Quote Originally Posted by maggias View Post
    hi

    any one who knows how to successfully do the following check in PyS60?

    if type(obj) == InstanceType:
    STATEMENT1
    else:
    STATEMENT2

    fails with a type exception when done like this, I probably have to create some empty Instance and do type() on it. But not sure how that is best done.

    Thanks in advance
    Magnus
    I'm not sure I understand your question, but from what I do understand, you want to check if a variable is of a certain type. If so, try this example:
    Code:
    >>>a=[1,2,3]
    >>>isinstance(a, list)
    True
    >>>b=12.4
    >>>isinstance(b, float)
    True
    So basically for you that would be:
    Code:
    if isinstance(obj, type):
       STATEMENT1
    else:
       STATEMENT2
    Hope that helps

  8. #8
    Registered User
    Join Date
    Mar 2008
    Posts
    47

    Re: Using declarations from types.py

    Hi bogdan.galiceanu,

    Thank you, this was what I needed and seems to work perfectly.

    regards,
    Magnus

Similar Threads

  1. Forward declarations
    By ovvenkatesan in forum Symbian
    Replies: 3
    Last Post: 2007-10-16, 09:21
  2. Replies: 3
    Last Post: 2004-04-14, 08:36
  3. _LIT macro and variable declarations
    By mprix in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2003-10-16, 09:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •