You Are Here:

Community: Developer Discussion Boards

#1 Old Using declarations from types.py - 2008-03-25, 00:38

Join Date: Mar 2008
Posts: 47
maggias
Offline
Registered User
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
Reply With Quote

#2 Old Re: Using declarations from types.py - 2008-03-25, 08:37

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
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!
Reply With Quote

#3 Old Thumbs up Re: Using declarations from types.py - 2008-03-26, 11:55

Join Date: Feb 2005
Posts: 1,353
Location: Belgium (Europe)
cyke64's Avatar
cyke64
Offline
Super Contributor
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,1.9.7,pygame,PyS60 CE on E90 , N810 with Python 2.5.2 and ... last PyS60 1.9.7 with touch ui on 5800 !

pys60 extension modules on http://cyke64.googlepages.com/
Reply With Quote

#4 Old Smile Re: Using declarations from types.py - 2008-03-26, 12:14

Join Date: May 2007
Posts: 2,738
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Hi Cyke64,

Welcome Home my friend
Really missed you here.

Best Regards
Croozeus
Reply With Quote

#5 Old Re: Using declarations from types.py - 2008-03-26, 18:17

Join Date: Mar 2008
Posts: 47
maggias
Offline
Registered User
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
Reply With Quote

#6 Old Re: Using declarations from types.py - 2008-04-26, 16:44

Join Date: Mar 2008
Posts: 47
maggias
Offline
Registered User
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
Reply With Quote

#7 Old Re: Using declarations from types.py - 2008-04-27, 14:09

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
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
Reply With Quote

#8 Old Re: Using declarations from types.py - 2008-04-27, 20:09

Join Date: Mar 2008
Posts: 47
maggias
Offline
Registered User
Hi bogdan.galiceanu,

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

regards,
Magnus
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Forward declarations ovvenkatesan General Symbian C++ 3 2007-10-16 10:21
菜鸟问题, 有关forward declarations l2mz Symbian 2 2006-08-09 02:50
Fixed arrays: what are the problems with standard c declarations? AusPaco General Symbian C++ 3 2004-04-14 09:36
_LIT macro and variable declarations mprix Symbian Tools & SDKs 1 2003-10-16 10:35

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia