Python功能请求:添加“使用”关键字的作用类似于“with”;在Visual Basic中 [英] Python Feature Request: Add the "using" keyword which works like "with" in Visual Basic

查看:55
本文介绍了Python功能请求:添加“使用”关键字的作用类似于“with”;在Visual Basic中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请检查是否合理并批准在python-dev发布。


在Visual Basic中有关键字with;允许将object-

名称声明为管理以下语句。对于

示例:


with quitCommandButton

.enabled = true

.default = true

结束


这是语法糖:


quitCommandButton.enabled = true

quitCommandButton.default = true


这对于GUI编程非常有用,因为我们必须在后续行中键入相同的对象名称线。我个人发现

必须输入单词self。课堂上非常多次

烦人。这么漂亮的语言是Python,她也应该从VB中获得这个很好的功能。


现在我听到with with这个词。正在讨论由于PEP而在Py 3中用于不同的
目的而且我不想与

冲突。所以我提出使用这个词。作为替代品。这也是类似于C ++使用的b $ b。关键字,它暴露了

命名空间的成员,无需为每个

引用指定命名空间范围。例如,在给出using namespace std;之后。我可以

更改对std :: cout的所有引用到了cout,这类似于我现在为Python提出的建议。


关于这个如何使用的一些想法声明应该表现出来。

使用后面应该跟一个对象名和一个冒号,表示一个块的起始点。

。以使用命名的对象必须确定该块中语句



上下文(或任何技术词)。


self .setFixedSize(200,120)

self.quit = QtGui.QPushButton(" Quit",self)

self.quit.setGeometry(62,40,75, 30)

self.quit.setFont(QtGui.QFont(" Times",18,QtGui.QFont.Bold))

self.connect(self.quit, QtCore.SIGNAL(" clicked()"),QtGui.qApp,

QtCore.SLOT(" quit()"))


被改写为:


使用self:

__setFixedSize(200,120)

__quit = QtGui.QPushButton(" Quit" ,自我)

__使用退出:

____ setGeometry(62,40,75,30)

____ setFont(QtGui.QFont(" Times" ,18,QtGui.QFont.Bold))

__connect(self.quit,QtCore.SIGNAL(" clicked()"),QtGui.qApp,

QtCore .SLOT(" quit()"))


[我不知道usenet是否会保留我的缩进,所以我改变了

标签下划线。]


这个上下文管理可能需要限制在第一个适用的

成员 - 所以在上面的例子中自我管理setFixedSize,

退出,退出并仅在每个句子中连接并退出(self.quit)

仅管理setGeometry和setFont。 (重点是解析器应该不会搜索self.QtGui,self.self或self.QtCore在句子3和

7,以及self.quit.QtGui in句子6.)


由于我缺乏专业经验,我的要求可能是技术上有点粗糙的b $ b,但我相信这是一个非常好的

Python的有用功能,因此请求技术上知识渊博,以便在必要时重新格式化。谢谢。

Please check for sanity and approve for posting at python-dev.

In Visual Basic there is the keyword "with" which allows an object-
name to be declared as governing the following statements. For
example:

with quitCommandButton
.enabled = true
.default = true
end with

This is syntactic sugar for:

quitCommandButton.enabled=true
quitCommandButton.default=true

This can be very useful especially in GUI programming when we have to
type the same object name in line-after-line. I personally found
having to type the word "self" umpteen times inside classes very
irritating. Such a beautiful language is Python, she should have this
good feature from VB too.

Now I hear that the word "with" is being discussed for a different
purpose in Py 3 as a result of a PEP and I don''t want to conflict with
that. So I propose the word "using" as a replacement. This also is
similar to the C++ "using" keyword which exposes the members of a
namespace to access without specifying the namespace scope for each
reference. For example after giving "using namespace std;" I can
change all references to "std::cout" to "cout", which is similar to
what I am proposing for Python now.

Some thoughts about how this "using" statement should behave. The word
using should be followed by an object name and a colon indicating the
start of a block. The object named after "using" must determine the
context (or whatever the technical word is) of the of the statements
in that block.

self.setFixedSize(200, 120)
self.quit = QtGui.QPushButton("Quit", self)
self.quit.setGeometry(62, 40, 75, 30)
self.quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(self.quit, QtCore.SIGNAL("clicked()"), QtGui.qApp,
QtCore.SLOT("quit()"))

to be rewritten as:

using self:
__setFixedSize(200,120)
__quit = QtGui.QPushButton("Quit", self)
__using quit:
____setGeometry(62, 40, 75, 30)
____setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
__connect(self.quit, QtCore.SIGNAL("clicked()"), QtGui.qApp,
QtCore.SLOT("quit()"))

[I don''t know whether usenet will retain my indenting, so I changed
the tabs to underscores.]

This context governing may need to be limited to the first applicable
member - so that in the above example "self" governs setFixedSize,
quit, quit and connect only in each sentence and quit (self.quit)
governs setGeometry and setFont only. (Point is that the parser should
not search for self.QtGui, self.self or self.QtCore in sentences 3 and
7, and self.quit.QtGui in sentence 6.)

Due to my absence of professional experience, my request may be
somewhat unpolished technical-wise, but I believe that this is a very
useful feature for Python and hence request the technically-
knowledgeable to reformat it as necessary. Thank you.

推荐答案

sa ** ***@gmail.com 写道:

请检查是否合理并批准在python-dev发布。


在Visual Basic中,有关键字with;允许将object-

名称声明为管理以下语句。对于

示例:


with quitCommandButton

.enabled = true

.default = true

结束


这是语法糖:


quitCommandButton.enabled = true

quitCommandButton.default = true


这对于GUI编程非常有用,因为我们必须在后续行中键入相同的对象名称线。我个人发现

必须输入单词self。课堂上非常多次

烦人。这么漂亮的语言是Python,她也应该从VB中获得这个很好的功能。


现在我听到with with这个词。正在讨论由于PEP而在Py 3中用于不同的
目的而且我不想与

冲突。所以我提出使用这个词。作为替代品。这也是类似于C ++使用的b $ b。关键字,它暴露了

命名空间的成员,无需为每个

引用指定命名空间范围。例如,在给出using namespace std;之后。我可以

更改对std :: cout的所有引用到了cout,这类似于我现在为Python提出的建议。


关于这个如何使用的一些想法声明应该表现出来。

使用后面应该跟一个对象名和一个冒号,表示一个块的起始点。

。以使用命名的对象必须确定该块中语句



上下文(或任何技术词)。


self .setFixedSize(200,120)

self.quit = QtGui.QPushButton(" Quit",self)

self.quit.setGeometry(62,40,75, 30)

self.quit.setFont(QtGui.QFont(" Times",18,QtGui.QFont.Bold))

self.connect(self.quit, QtCore.SIGNAL(" clicked()"),QtGui.qApp,

QtCore.SLOT(" quit()"))


被改写为:


使用self:

__setFixedSize(200,120)

__quit = QtGui.QPushButton(" Quit" ,自我)

__使用退出:

____ setGeometry(62,40,75,30)

____ setFont(QtGui.QFont(" Times" ,18,QtGui.QFont.Bold))

__connect(self.quit,QtCore.SIGNAL(" clicked()"),QtGui.qApp,

QtCore .SLOT(" quit()"))


[我不知道usenet是否会保留我的inde nting,所以我改变了

标签下划线。]


这个上下文管理可能需要限制在第一个适用的

成员 - 所以在上面的例子中自我管理setFixedSize,

退出,退出并仅在每个句子中连接并退出(self.quit)

仅管理setGeometry和setFont。 (重点是解析器应该不会搜索self.QtGui,self.self或self.QtCore在句子3和

7,以及self.quit.QtGui in句子6.)


由于我缺乏专业经验,我的要求可能是技术上有点粗糙的b $ b,但我相信这是一个非常好的

Python的有用功能,因此请求技术上知识渊博,以便在必要时重新格式化。谢谢。
Please check for sanity and approve for posting at python-dev.

In Visual Basic there is the keyword "with" which allows an object-
name to be declared as governing the following statements. For
example:

with quitCommandButton
.enabled = true
.default = true
end with

This is syntactic sugar for:

quitCommandButton.enabled=true
quitCommandButton.default=true

This can be very useful especially in GUI programming when we have to
type the same object name in line-after-line. I personally found
having to type the word "self" umpteen times inside classes very
irritating. Such a beautiful language is Python, she should have this
good feature from VB too.

Now I hear that the word "with" is being discussed for a different
purpose in Py 3 as a result of a PEP and I don''t want to conflict with
that. So I propose the word "using" as a replacement. This also is
similar to the C++ "using" keyword which exposes the members of a
namespace to access without specifying the namespace scope for each
reference. For example after giving "using namespace std;" I can
change all references to "std::cout" to "cout", which is similar to
what I am proposing for Python now.

Some thoughts about how this "using" statement should behave. The word
using should be followed by an object name and a colon indicating the
start of a block. The object named after "using" must determine the
context (or whatever the technical word is) of the of the statements
in that block.

self.setFixedSize(200, 120)
self.quit = QtGui.QPushButton("Quit", self)
self.quit.setGeometry(62, 40, 75, 30)
self.quit.setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
self.connect(self.quit, QtCore.SIGNAL("clicked()"), QtGui.qApp,
QtCore.SLOT("quit()"))

to be rewritten as:

using self:
__setFixedSize(200,120)
__quit = QtGui.QPushButton("Quit", self)
__using quit:
____setGeometry(62, 40, 75, 30)
____setFont(QtGui.QFont("Times", 18, QtGui.QFont.Bold))
__connect(self.quit, QtCore.SIGNAL("clicked()"), QtGui.qApp,
QtCore.SLOT("quit()"))

[I don''t know whether usenet will retain my indenting, so I changed
the tabs to underscores.]

This context governing may need to be limited to the first applicable
member - so that in the above example "self" governs setFixedSize,
quit, quit and connect only in each sentence and quit (self.quit)
governs setGeometry and setFont only. (Point is that the parser should
not search for self.QtGui, self.self or self.QtCore in sentences 3 and
7, and self.quit.QtGui in sentence 6.)

Due to my absence of professional experience, my request may be
somewhat unpolished technical-wise, but I believe that this is a very
useful feature for Python and hence request the technically-
knowledgeable to reformat it as necessary. Thank you.



我出于某种原因喜欢这个。只是使用自我可以节省hella

输入很多课程。我赞成一个带有前导点的约定

来消除其他变量的歧义。这与
浮点数不会发生冲突,因为变量名称不能以数字开头。


James

I like this one for some reason. Just the "using self" would save hella
typing in a lot of classes. I would favor a convention with leading dots
to disambiguate from other variables. This wouldn''t conflict with, say,
floats, because variable names can''t begin with a number.

James


出于某种原因,我喜欢这个。只是使用自我会保存hella
I like this one for some reason. Just the "using self" would save hella

输入很多课程。我赞成一个带有前导点的约定

来消除其他变量的歧义。这与
浮点数不会发生冲突,因为变量名称不能以数字开头。
typing in a lot of classes. I would favor a convention with leading dots
to disambiguate from other variables. This wouldn''t conflict with, say,
floats, because variable names can''t begin with a number.



优秀。现在我们不必担心第一个适用的

实例任何以点开头的成员都将拥有由解析器自动加上前缀的上下文

。这意味着使用

语句嵌套应如下所示:


使用self:

__using .quit:


前面的点也退出。优秀!


但你说变量名不能以数字开头。

指出这一点,他们不应该以* * *开头。我们不担心这里的数字,对吗?

Excellent. Now we don''t have to worry about the "first applicable
instance" etc. Any member that begins with a dot will have the context
governer auto-prefixed by the parser. This means that nested using
statements should be like follows:

using self:
__using .quit:

with the dot preceding quit also. Excellent!

But you have said "variable names can''t begin with a number". The
point this, they shouldn''t be able to begin with a *dot*. We are not
worried about numbers here, right?


jamadagni写道:
jamadagni wrote:

>我出于某种原因喜欢这个。只是使用自我会在很多课程中输入hella
。我赞成一个带有前导点的约定来消除其他变量的歧义。这不会与浮动相冲突,因为变量名不能以数字开头。
>I like this one for some reason. Just the "using self" would save hella
typing in a lot of classes. I would favor a convention with leading dots
to disambiguate from other variables. This wouldn''t conflict with, say,
floats, because variable names can''t begin with a number.



非常好。现在我们不必担心第一个适用的

实例任何以点开头的成员都将拥有由解析器自动加上前缀的上下文

。这意味着使用

语句嵌套应如下所示:


使用self:

__using .quit:


Excellent. Now we don''t have to worry about the "first applicable
instance" etc. Any member that begins with a dot will have the context
governer auto-prefixed by the parser. This means that nested using
statements should be like follows:

using self:
__using .quit:



在什么情况下这不意味着使用self.quit?我认为

必须要有一种令人耳目一新的想象力来推断我在提议

我们添加。一般来说,变量名称。这个想法是它

指定使用声明适用的名称。


James

Under what circumstances would this not mean "using self.quit"? I think
one must be refreshingly imaginative to infer that I was proposing that
we add "." to variable names in general. The idea would be that it
specifies to which names the using statement applies.

James


这篇关于Python功能请求:添加“使用”关键字的作用类似于“with”;在Visual Basic中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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