一些事情 [英] Few things

查看:80
本文介绍了一些事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

这里还有四个问题(或建议)的语言

(可能人们已经讨论了一些/所有这些事情:


我见过Python的合同:
http://www.wayforward.net/pycontract/
http://www.python.org/peps/pep-0316.html

它们看起来很有趣,很好,Python开发人员对此感觉如何

用标准语言接受这样的东西?(也许他们

有点复杂)。

我认为它可能是一个有用的统计标准模块计算

排列,组合,中位数(quickselect)等。甚至还有一个

C实现(大多数):
http://probstat.sourceforge.net/

可能有些Win用户可以欣赏这已经编译好了

(和内置)。

这样的命令:

print 0x9f,054135

打印十六进制和八进制。我认为十六进制的语法有点

丑陋;并且八进制的语法看起来很危险(和错误的)

我。

在我找到的一些python源代码中,我发现了一些东西/>
喜欢:

def foo():

''''''这只是一个

愚蠢的文字' '''''

....


因为:

def foo():

''''''这只是一个

愚蠢的文字'''''

print foo .__ doc__


输出:

这只是一个

愚蠢的文本


我认为这种多行字符串的更好的语法可以是某种东西

喜欢:从

后面的所有行开头删除第一个等于
soucecode。

有了这个sintax这样的打印输出:

这只是一个

愚蠢的文字


注意:第一个连续的线的压痕更少

简单地被忽略:

def foo2():

''''''这只是一个

傻傻的文字''''''

打印foo .__ doc__


输出:

这只是一个

愚蠢的文字


您好,

Bearophile

Hello,
here are a four more questions (or suggestions) for the language
(probably people have already discussed some of/all such things:

I''ve seen the contracts for Python:
http://www.wayforward.net/pycontract/
http://www.python.org/peps/pep-0316.html
They look interesting and nice, how Python developers feel about
accepting something like this in the standard language? (Maybe they
are a bit complex).
I think it can be useful a little stat standard module that computes
permutations, combinations, median (quickselect), etc. There is even a
C implementation (of most of them):
http://probstat.sourceforge.net/
Probably some Win users can appreciate to have this already compiled
(and built in).
A command like this:
print 0x9f, 054135
This prints an hex and octal. I think the syntax for the hex is a bit
ugly; and the syntax for the octal looks just dangerous (and wrong) to
me.
In some python source codes that I''m finding around, I find things
like:
def foo():
''''''This is just a
silly text''''''
....

Because:
def foo():
''''''This is just a
silly text''''''
print foo.__doc__

Outputs:
This is just a
silly text

I think a better syntax for such multiline strings can be something
like: remove from all the beginnings of the lines successive to the
first one a number of spaces equal to the position of '''''' in the
soucecode.
With this sintax such print outputs:
This is just a
silly text

Note: even less indentation of the lines successive the first one can
be simply ignored:
def foo2():
''''''This is just a
silly text''''''
print foo.__doc__

Outputs:
This is just a
silly text

Hello,
Bearophile

推荐答案


成为************ @ lycos.com (bearophile)写道:

be************@lycos.com (bearophile) wrote:

你好,
这里有四个问题(或建议)的语言
(可能人们已经讨论了一些/所有这些事情:

我见过Python的合同:
http://www.wayforward.net/pycontract/
http://www.python.org/peps/pep-0316.html
他们看起来很有趣,很好,Python如何发展我们觉得用标准语言接受这样的东西吗? (也许他们
有点复杂)。


装饰者可以在没有其他语法的情况下完成此操作。想想@accepts和

@returns。


我认为它可以用一个小的统计标准模块来计算排列,组合,中位数( quickselect)等等。甚至还有一个实现(其中大部分都是):
http://probstat.sourceforge.net/
可能有些Win用户可以欣赏已经编译好的内容(和内置版本)。


对于排列组合生成''faq''将是99%

。快速选择,真的,并没有给你带来太多。

当然,这是选择中位数的对数因子更快,但许多算法

涉及选择中位数(至少是我在CS中遇到的那个理论)最终反复(logn)时间选择''kth''最小的

元素(变化的k'' s),排序实际上会稍微快一点。


至于其余部分,请具体说明您想要的内容

这个神秘的''statistics''模块(''stat''已用于

文件系统统计模块)。对于这样的模块,已经讨论过单程平均值/标准偏差

,并且给出了这个序列的所有

k最小项目等。 ,但被Raymond抛弃了

Hettinger由于对这种模块的需求有限。


这样的命令:
print 0x9f,054135
这会打印十六进制和八进制。我认为十六进制的语法有点丑陋;而八进制的语法对我来说看起来很危险(而且是错误的)。


在内部这些值是Python整数,需要有一个特殊的方法来将整数标记为最初的十六进制或八进制。或者

pyc需要存储这样的事实:它原本是其中一种专门用于打印声明的其他方法。


执行此类操作的首选方法(通过

某些特殊方法打印一些内部类型)是通过字符串插值:

print" 0x%x 0%o" %(0x9f,054135)


丑陋与否,特殊情况不足以打破规则。

Don''请屏住呼吸,打算用整数做任何特殊的事情。


在我找到的一些python源代码中,我找到了类似的东西:
def foo():
''''''这只是一个愚蠢的文字''''


因为:
def foo():
''''''这只是一个愚蠢的文字'''''
打印foo .__ doc__

输出:
这只是一个愚蠢的文字

我认为一个更好的合成器这样的多线串的斧头可以是这样的东西:从连续的线的所有开始处移除
第一个与 soucecode。
有了这个sintax这样的打印输出:
这只是一个傻傻的文字

注意:连续第一个可以减少线条的缩进
被简单地忽略了:
def foo2():
''''''这只是一个愚蠢的文字'''''
打印foo。 __doc__

输出:
这只是一个愚蠢的文字

Hello,
here are a four more questions (or suggestions) for the language
(probably people have already discussed some of/all such things:

I''ve seen the contracts for Python:
http://www.wayforward.net/pycontract/
http://www.python.org/peps/pep-0316.html
They look interesting and nice, how Python developers feel about
accepting something like this in the standard language? (Maybe they
are a bit complex).
Decorators can do this without additional syntax. Think @accepts and
@returns.

I think it can be useful a little stat standard module that computes
permutations, combinations, median (quickselect), etc. There is even a
C implementation (of most of them):
http://probstat.sourceforge.net/
Probably some Win users can appreciate to have this already compiled
(and built in).
Having a ''faq'' for permutation and combination generation would be 99%
of the way there. Quickselect, really, doesn''t gain you a whole lot.
Sure, it''s a log factor faster to select a median, but many algorithms
involving selecting medians (at least the ones that I run into in CS
theory) end up repeatedly (logn) time selecting the ''kth'' smallest
element (varying k''s), where sorting would actually run slightly faster.

As for the rest of it, be specific with what you would want to be in
this mythical ''statistics'' module (''stat'' is already used for the
filesystem stat module). A single-pass average/standard deviation has
already been discussed for such a module, as well as give me all the
k-smallest items of this sequence, etc., but was tossed by Raymond
Hettinger due to the limited demand for such a module.

A command like this:
print 0x9f, 054135
This prints an hex and octal. I think the syntax for the hex is a bit
ugly; and the syntax for the octal looks just dangerous (and wrong) to
me.
Internally those values are Python integers, there would need to be a
special way to tag integers as being originally hex or octal. Or the
pyc would need to store the fact that it was originally one of those
other methods specifically for the print statement.

The preferred way for doing such things (printing some internal type via
some special method) is via string interpolation:
print "0x%x 0%o"%(0x9f, 054135)

Ugly or not, "Special cases aren''t special enough to break the rules."
Don''t hold your breath for print doing anything special with integers.

In some python source codes that I''m finding around, I find things
like:
def foo():
''''''This is just a
silly text''''''
...

Because:
def foo():
''''''This is just a
silly text''''''
print foo.__doc__

Outputs:
This is just a
silly text

I think a better syntax for such multiline strings can be something
like: remove from all the beginnings of the lines successive to the
first one a number of spaces equal to the position of '''''' in the
soucecode.
With this sintax such print outputs:
This is just a
silly text

Note: even less indentation of the lines successive the first one can
be simply ignored:
def foo2():
''''''This is just a
silly text''''''
print foo.__doc__

Outputs:
This is just a
silly text




这是一个疣。一个选项是使用:

def foo():

'''''\

这只是一个

愚蠢的文字'''''


我,我只是不使用docstrings。我把所有内容放在评论中用代码缩进

。我已经考虑过编写一个导入钩来做

模块的预处理,将这些注释转换为docstrings,但是我没有实际使用docstrings
所以从来没有写过钩子。

- Josiah



It is a wart. An option is to use:
def foo():
''''''\
This is just a
silly text''''''

Me, I just don''t use docstrings. I put everything in comments indented
with the code. I have contemplated writing an import hook to do
pre-processing of modules to convert such comments to docstrings, but I
never actually use docstrings, so have never written the hook.
- Josiah




Josiah Carlson< jc ****** @ uci.edu>写道:

Josiah Carlson <jc******@uci.edu> wrote:
理论)最后重复(logn)时间选择''kth''最小的
元素(变化的k'),其中排序实际上会略微运行更快。
theory) end up repeatedly (logn) time selecting the ''kth'' smallest
element (varying k''s), where sorting would actually run slightly faster.




应该读过:

理论)反复结束(登录时间)选择......


- Josiah



That should have read:
theory) end up repeatedly (logn times) selecting the...

- Josiah


Josiah Carlson写道:
Josiah Carlson wrote:
这样的命令:
print 0x9f,054135
这会打印十六进制和八进制。我认为十六进制的语法有点丑陋;并且八进制的语法对我来说看起来很危险(和错误)。
A command like this:
print 0x9f, 054135
This prints an hex and octal. I think the syntax for the hex is a bit
ugly; and the syntax for the octal looks just dangerous (and wrong) to
me.



在内部这些值是Python整数,需要特殊的
将整数标记为最初为十六进制或八进制的方法。或者
pyc需要存储这样一个事实:它最初是专门用于print语句的其他方法之一。


Internally those values are Python integers, there would need to be a
special way to tag integers as being originally hex or octal. Or the
pyc would need to store the fact that it was originally one of those
other methods specifically for the print statement.




我相信OP反对拼写这个整数文字是十六进制

和这个整数文字是八进制。


Python偷走了这些拼写直接来自C.表示它很丑陋没有

暗示一个替代方案不太可能导致开发人员采取任何

行动。 (不管怎么说,特别是在这一点上,无论如何)


如果拼写确实困扰OP,以下作品:


打印int(" 9f",16),int(" 54135",8)


这个'更难打字,在运行时速度慢很多并且使用更多但是,记忆。


干杯,

尼克。



I believe the OP was objecting to the spelling of "this integer literal is hex"
and "this integer literal is octal".

Python stole these spellings directly from C. Saying it''s ugly without
suggesting an alternative isn''t likely to result in developers taking any
action, though. (Not that that is particularly likely on this point, regardless)

If the spelling really bothers the OP, the following works:

print int("9f", 16), int("54135", 8)

That''s harder to type, is a lot slower at run-time and uses more memory, though.

Cheers,
Nick.


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

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