| Reply | « Previous Thread | Next Thread » |
|
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 Code:
from Types import * 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 Also to change the input like this Code:
import types Code:
if type(rules) not in (types.NoneType, types.DictType): Code:
AttributeError: 'module' object has no attribute 'NoneType' kindest regards, Magnus Agust Skulason |
|
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
Code:
if type(rules) != types.NoneType and type(rules) != types.DictType:
# handle
Code:
if not type(rules) in (types.NoneType, types.DictType): |
|
Quote:
@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/ |
|
Hi Cyke64,
Welcome Home my friend ![]() Really missed you here. Best Regards Croozeus |
|
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 Code:
if type(rules) == type([]) or type(rules) == type(()): 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 |
|
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 |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
Offline
Forum Nokia Champion
|
|
|
Quote:
Code:
>>>a=[1,2,3] >>>isinstance(a, list) True >>>b=12.4 >>>isinstance(b, float) True Code:
if isinstance(obj, type): STATEMENT1 else: STATEMENT2 ![]() |
|
Hi bogdan.galiceanu,
Thank you, this was what I needed and seems to work perfectly. regards, Magnus |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| 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 |