这是一个错误,还是我? [英] Is this a bug, or is it me?

查看:70
本文介绍了这是一个错误,还是我?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

出于某种原因,以下情况不起作用:

C级:

TYPES = [无]

DICT = {}

类型为类型:

DICT.update([E]中的E的(E,类型))


>> NameError:全局名称''Type''未定义



您怎么看?这是一个错误吗?

解决方案

1月17日下午4:05,cptnwill ... @ gmail.com写道:
< blockquote class =post_quotes>
大家好,

由于某种原因,以下方法不起作用:


class C:

TYPES = [无]

DICT = {}

输入类型:

DICT.update((E,在[1]中输入E)


> NameError:全局名称''Type''未定义



您怎么看?这是一个错误吗?



不要使用这些名字......选择真的很差......


thingydingy = [无]

my = {}

for thingydingy:

my.update([(E,dingaling)for E in [1]])br />
打印我的


2008年1月17日上午10:05,< cp ********* @ gmail.comwrote:


大家好,

出于某种原因,以下情况不起作用:


class C:

TYPES = [无]

DICT = {}

输入类型:

DICT。更新([E]中的E的(E,类型))


> NameError:全局名称''Type''是未定义




您怎么看?这是一个错误吗?



你不能在它的类声明

范围内访问类的类变量,因为类型的名称在完成课程

声明之后才受约束。


尝试:


C级:

TYPES = [无]

DICT = {}


类型为C.TYPES:

C.DICT.update((E,Type)for E in [1])


-

Neil Cerutti< mr ***** **********@gmail.com>


2008年1月17日上午10:23,Neil Cerutti< mr ***** ***@gmail.com写道:


你不能在它的类声明中访问类的类变量

范围,因为类型的名称在类

语句完成之后才被绑定。



Arrgh!我讨厌制作它的错误。但是我想补充一点,Python的类声明的这个

属性只有在我认为它才会让我困扰

将使用类变量作为默认方法参数

值。幸运的是,我不经常想。 ;)


-

Neil Cerutti< mr *************** @ gmail.com>


Hello all,
For some reason, the following does not work :
class C:
TYPES = [None]
DICT = {}
for Type in TYPES:
DICT.update((E,Type) for E in [1])

>>NameError: global name ''Type'' is not defined


What do you think? Is this a bug?

解决方案

On Jan 17, 4:05 pm, cptnwill...@gmail.com wrote:

Hello all,
For some reason, the following does not work :

class C:
TYPES = [None]
DICT = {}
for Type in TYPES:
DICT.update((E,Type) for E in [1])

>NameError: global name ''Type'' is not defined


What do you think? Is this a bug?

Do not use those names...really poor choice...

thingydingy = [None]
my = {}
for dingaling in thingydingy:
my.update([(E,dingaling ) for E in [1]])
print my


On Jan 17, 2008 10:05 AM, <cp*********@gmail.comwrote:

Hello all,
For some reason, the following does not work :
class C:
TYPES = [None]
DICT = {}
for Type in TYPES:
DICT.update((E,Type) for E in [1])

>NameError: global name ''Type'' is not defined



What do you think? Is this a bug?

You cannot access a class''s class variables in it''s class-statement
scope, since the name of the type is not bound until after the class
statement is completed.

Try:

class C:
TYPES = [None]
DICT = {}

for Type in C.TYPES:
C.DICT.update((E, Type) for E in [1])

--
Neil Cerutti <mr***************@gmail.com>


On Jan 17, 2008 10:23 AM, Neil Cerutti <mr********@gmail.comwrote:

You cannot access a class''s class variables in it''s class-statement
scope, since the name of the type is not bound until after the class
statement is completed.

Arrgh! I hate making the "its" error. But I wanted to add that this
property of Python''s class statement bothers me only when I think it
would be good to use class variables as default method argument
values. Luckily, I don''t think very often. ;)

--
Neil Cerutti <mr***************@gmail.com>


这篇关于这是一个错误,还是我?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆