Python的保留字是否保留在他们不需要的地方? [英] Are Python's reserved words reserved in places they dont need to be?

查看:134
本文介绍了Python的保留字是否保留在他们不需要的地方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- python -i

-- python -i


>> class =" algebra"
>>class = "algebra"



文件"< stdin>",第1行

class =" algebra"

^

语法错误:语法无效

File "<stdin>", line 1
class = "algebra"
^
SyntaxError: invalid syntax


>>>
>>>



为什么解析器不够聪明,看不到后面跟着一个

标识符的类用于类定义,但是后跟equals的类是

a简单赋值?


另外,我有一个错误,我尝试设置属性user和并且传递

在一个对象中但是传递不行,因为它是一个保留字。

再次传递应该在某些情况下保留,但不能保留其他。


Python 3k是否会修复这种情况事情?


Why isn'' t the parser smart enough to see that class followed by an
identifier is used for class definition but class followed by equals is
a simple assignment?

Also, I had a bug where I tried to set the attributes "user" and "pass"
in an object but "pass" would not work because it is a reserved word.
Again pass should be reserved in certain contexts but not others.

Is Python 3k going to fix this sort of thing?

推荐答案

metaperl schrieb:
metaperl schrieb:

- python -i
-- python -i

>>> class =" algebra"
>>>class = "algebra"



文件"< stdin>",第1行

class =" algebra"

^

语法错误:语法无效


为什么解析器不够聪明,看不到该类后跟

标识符用于类定义,但是后跟equals的类是

a简单赋值?


另外,我有一个错误,我尝试设置属性用户并且传递

在一个对象中但是传递不会起作用,因为它是一个保留字。

再次传递应该在某些情况下保留,但不能在其他情况下保留。

File "<stdin>", line 1
class = "algebra"
^
SyntaxError: invalid syntax
Why isn'' t the parser smart enough to see that class followed by an
identifier is used for class definition but class followed by equals is
a simple assignment?

Also, I had a bug where I tried to set the attributes "user" and "pass"
in an object but "pass" would not work because it is a reserved word.
Again pass should be reserved in certain contexts but not others.



大多数解析器都以保留关键字的方式编写,

,无论它们是否出现。那是因为它更容易做到

所以。而少数保留字通常不重要。

Most parsers are written in a way that makes keywords reserved,
regardless of their occurrence. That is because it is way easier to do
so. And the few reserved words won''t matter usually.


Python 3k是否会解决这类问题?
Is Python 3k going to fix this sort of thing?



别这么认为。


Diez

Don''t think so.

Diez




" metaperl" < me ****** @ gmail.com写信息

news:11 ********************** @ p79g2000cwp .googlegr oups.com ...

"metaperl" <me******@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...

为什么解析器不够智能,看不到后面跟着一个

标识符的类用于类定义,但是后跟equals的类是

a简单赋值?
Why isn'' t the parser smart enough to see that class followed by an
identifier is used for class definition but class followed by equals is
a simple assignment?



因为在过去和将来的所有用例中,保留单词比担心可能更容易

模糊不清。如果您可以使用

作为标识符,则该术语的正常

定义不会是保留字。

Because it''s simpler to reserve words than worry about possible
ambiguities in all past and future use cases. If you could use it
as an identifier, it wouldn''t be a reserved word by the normal
definition of the term.


metaperl写道:
metaperl wrote:

- python -i
-- python -i

> class =" algebra"
>class = "algebra"



文件"< stdin>",第1行

class =" algebra"

^

语法错误:语法无效

File "<stdin>", line 1
class = "algebra"
^
SyntaxError: invalid syntax



设计语法以避免所有可能的新手错误是不切实际的

因为一旦你完成了一次迭代,新的新手

将开始犯下不同类型的错误...


在事实中获得安慰当你修复时,你已经立即注意到

错误:重命名传递给passwd是微不足道的......


i。

Designing a syntax to avoid all possible newbie errors is impractical
because as soon as you are finished with one iteration the new newbies
will start making different kinds of errors...

Take solace in the fact that you''ve been immediately notifed of the
error while its fix: renaming pass to passwd is trivial ...

i.


这篇关于Python的保留字是否保留在他们不需要的地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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