队列模块和Python文档Rant [英] Queue module and Python Documentation Rant

查看:62
本文介绍了队列模块和Python文档Rant的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查看队列的内容?我想验证

队列与已放入

的列表具有相同数量的对象。另外,如果将队列视为静态或动态(在put / /
方面)?你把东西放进去,然后从它里面取出来,直到它空了吗?b $ b或者你一次把东西放进去吗?或者,你能两个都做吗?另外,

队列实际上变小了,因为线程从它那里输入或者确实是这样。

它保持相同的大小并记住它从中得到了什么东西

已经?这是一个创建100,000个项目队列的合适方法吗?


url_queue = Queue.Queue(0)

url in urls:

url_queue.put(url)


< rant>


我问所有这些问题,因为我找到了Python文档

缺乏,至少可以说。 Python是一种最优秀的语言,但

文档太可怕了! IMO,人们可以更多地了解不太合理的语言,比如Perl和PHP,因为他们的文档非常好,所以我可以学习更多... ...特别是PHP。不要误会我的意思,我喜欢Python,只是讨厌

它的文档。对于一个以易用性和新手友好为荣的lang,Python应该为其模块文档感到羞耻


< / rant>


巴特

解决方案

Bart Nessux写道:

如何查看内容队列?


你完全在想全部事情:-)


特别注意,Queue是用于线程的

编程(多生产者,多用户),文件明确指出

我想验证队列是否有相同的编号对象
作为已放入其中的列表。


有一个明确记录的qsize()方法。

有什么问题?

另外,如果有人认为队列是静态的还是动态的(在
方面)?


构造函数文档清楚地描述了它的行为。

你可以限制队列中的项目数量

new puts会阻止,或者你可以拥有默认行为

允许队列中的无限项。

你把东西放进去一次然后从中获取它直到它空的
或者你一次把东西放进去吗?


您将物品放入队列并取出物品。每个项目都是任何类型的

对象。队列不会分割项目。例如

如果你把一个字符串放入队列,你不能只检索字符串的一部分

,然后再检索另一部分。你只得到整个

字符串。

此外,
队列实际上变小了,因为线程从它输入或者它保持不变相同的尺寸,还记得从中得到了什么东西
已经?


这是计算机科学意义上的经典队列。可以添加对象

(通过put方法)并取消(通过get方法)。大小是队列中对象的数量
。订单是FIFO(先进先出)。

对比堆叠是LIFO(最后一个是第一个)。


保持相同的大小您的评论的一部分通常是指

另一种称为循环缓冲区(或循环队列)的数据类型。


我强烈建议您获取一份副本Python Cookbook

并阅读它。内容也可以在线获得,但是

死树版本是更好的阅读。

这是创建100,000个项目队列的合适方法吗?

url_queue = Queue.Queue(0)
url in urls:
url_queue.put(url)


是的。但是在大多数代码中你不太可能这样做。通常

你会有一些代码产生项目,而其他代码消耗

它们。该组中的另一个主题是一个例子。一段

代码正在生成要扫描的IP地址,而单独的一块
代码(例如工作线程)将需要一个工作项和

进行扫描。


因此,物品数量会很小,因为您可以预期

物品的生产率是多少类似的数量级

它们的消耗率。

我问所有这些问题因为我发现缺乏Python文档,比如说最小。


这个课程的文档实际上很短而且很甜,而且我不认为它可以改进。你会如何改进它?


然而,它缺少一个可以让事情变得更加清晰的例子

特别是对于那些习惯不习惯的人来说编程习语。

本教程有点简短,但涵盖了数据结构:
http://docs.python.org/tut/tut.html

特别是PHP。


几乎所有在愤怒中完成PHP的人都对他们的文档赞不绝口(我包括
)。元数据不仅非常好(例如,

项目引入了哪个版本等),而且用户贡献使得

成为最大的差异。另据我所知,每个页面都包含

一个例子。


这里有一个关于以类似的方式做Python文档的讨论<几周前,br />
(特别是用户注释)。据我所知,

结果是任何想要提交更改的人必须通过

SourceForge错误并等待一段时间(几个月)更改显示,

或构建一个与文档分开的wiki。

Python应该为其模块文档感到羞耻



文档很好。对于构建的文档而言,这是非常标准的

cathedral样式。我希望它更像是PHP的市场风格,但我没有时间或倾向于帮助建立基础设施

。你好吗?


Roger


Roger Binns写道:

有一个明确记录的qsize()方法。
有什么问题?


哪里???名为Queue的模块的文档在

中没有说明这一切...

http://docs.python.org/lib/module-Queue.html

[Python]文档很好。




文档没用。人们需要CS中的Master'才能阅读模块

索引。总的来说,它太抽象了。很多人都没有

实际*用法*的例子。阅读教程中有关课程的部分...

你能保持清醒多长时间?这是如此抽象和学术,以至于它是无用的寄宿生。


CS应用数学。但是,Python并不认为自己应用的是b $ b,而是理论上的。如果你是一名拥有博士学位的极客,那就太好了,但是如果你是普通的系统管理员试图解决每天的问题,那就不好了。
问题。


Python为初学者和高级用户提供了很好的语法。一个

可以用它进行顺序,程序和OO编程。此外,它可以在大多数平台上应用于大多数任何问题。但是,文件

是徒劳的。他们让我想起了我在法学院读到的那些问题......经常谈论事情,而不是讨论事情。


如果每个人都具有相同的高级知识,那么这是很好的,但是对于编程语言来说不是很好(想想应用的解决问题的方法)

巨大的潜力,并被吹捧为用户友好的

非程序员。难怪有这么多人使用Perl。和Perl一样糟糕,

它没有自己的学术意见,因此可以接近

并且可用。


原谅我,我很沮丧。


巴特


Bart Nessux写道:
< blockquote class =post_quotes> Roger Binns写道:

有一个明确记录的qsize()方法。
有什么问题?



哪里???名为Queue的模块的文档没有说明这一切......

http://docs.python.org/lib/module-Queue.html




你对了......在页面底部,有一个小节。

qsize()就在那里。在沮丧中,我忽略了它。


How can one view the contents of a queue? I''d like to verify that the
queue has the same number of objects as the list that has been put into
it. Also, should one think of a queue as static or dynamic (on the put
side)? Do you put stuff in it once and then get from it until it''s empty
or do you put stuff in it a bit at a time? Or, can you do both? Also,
does the queue actually get smaller as the threads feed from it or does
it stay the same size and remember what stuff has been gotten from it
already? Is this an appropriate way to create a queue of 100,000 items?

url_queue = Queue.Queue(0)
for url in urls:
url_queue.put(url)

<rant>

I ask all of these questions because I find the Python documentation
lacking, to say the least. Python is a most excellent language, but the
docs are horrible! IMO, one can learn more about less sane languages
such as Perl and PHP simply because their documentation is so well
done... PHP especially. Don''t get me wrong, I love Python, just hate
it''s documentation. For a lang that prides itself on ease of use and
newbie-friendliness, Python should be ashamed of its module documentation

</rant>

Bart

解决方案

Bart Nessux wrote:

How can one view the contents of a queue?
You are over thinking the whole thing :-)

Especially note that the Queue is intended to be used in threaded
programming (multi-producer, multi-consumer) which the doc clearly
states.
I''d like to verify that the queue has the same number of objects
as the list that has been put into it.
There is a qsize() method clearly documented. What is wrong with
that?
Also, should one think of a queue as static or dynamic (on the put
side)?
The constructor documentation clearly describes how it behaves.
You can limit the number of items in the Queue at which point
new puts will block, or you can have the default behaviour which
allows unlimited items in the queue.
Do you put stuff in it once and then get from it until it''s empty
or do you put stuff in it a bit at a time?
You put items into the Queue and get items out. Each item is an
object of any type. The Queue does not split up items. For example
if you place a string into the queue, you cannot retrieve just part
of the string first and another part later. You only get the whole
string out.
Also,
does the queue actually get smaller as the threads feed from it or does
it stay the same size and remember what stuff has been gotten from it
already?
It is a classic queue in the computer science sense. Objects can be added
(via the put method) and taken off (by the get method). The size is the
number of objects in the queue. The order is FIFO (first in first out).
Contrast with a stack which is LIFO (last in is the first out).

The "staying the same size" part of your comment usually refers to
another data type known as a circular buffer (or circular queue).

I would strongly recommend getting a copy of the Python Cookbook
and reading it. The contents are also available online but the
dead tree version is a better read.
Is this an appropriate way to create a queue of 100,000 items?

url_queue = Queue.Queue(0)
for url in urls:
url_queue.put(url)
Yes. However in most code you are unlikely to do that. In general
you will have some code producing items, and other code consuming
them. Another thread in this group had an example. One piece of
code was producing IP addresses to scan, and a seperate piece of
code (for example a worker thread) would take one work item and
do the scanning.

Consequently the number of items would be small since you would expect
the rate at which items are produced to be a similar order of magnitude
to the rate at which they are consumed.
I ask all of these questions because I find the Python documentation
lacking, to say the least.
The documentation for this class is actually short and sweet and I
don''t think it could be improved. How would you improve it?

It is however missing an example which would make things a lot clearer
especially for people who aren''t used to standard programming idioms.
The tutorial is a little brief but does cover data structures:
http://docs.python.org/tut/tut.html
PHP especially.
Pretty much anyone who has done PHP in anger raves about their docs (me
included). Not only is the meta-data really good (eg which version the
item was introduced in etc), but the user contributions are what makes
the big difference. Also as far as I can tell, every single page includes
an example.

There was a discussion here about doing the Python docs in a similar fashion
(especially the user annotations) a few weeks ago. As far as I could tell,
the results were that anyone who wanted to submit changes had to do it via
SourceForge bugs and wait a fair while (months) for the changes to appear,
or construct a wiki that is seperate from the docs.
Python should be ashamed of its module documentation



The documentation is fine. It is pretty standard for docs constructed
"cathedral" style. I do wish it was more bazaar style like the PHP
ones, but I don''t have the time or inclination to help put the infrastructure
in place. Do you?

Roger


Roger Binns wrote:

There is a qsize() method clearly documented. What is wrong with
that?
Where??? The documentation for the module named Queue says nothing at
all about this...

http://docs.python.org/lib/module-Queue.html
The [Python] documentation is fine.



The docs are useless. One needs a Master''s in CS just to read the module
index. In general, it''s far too abstract. Many have no examples for
actual *usage* at all. Read the section about classes in the tutorial...
how long can you stay awake? It''s so abstract and scholarly that it
boarders on being useless.

CS is applied math. However, Python does not think of itself as being
applied, but theoretical. This is good if you''re a geek with a Ph.D, but
not if you''re the average sys-admin attempting to solve an every-day
problem.

Python has a great syntax for beginners and advanced users alike. One
can do sequential, procedural and OO programming with it. Also, it can
be applied to most any problem on most any platform. However, the docs
are an exercise in futility. They remind me of the circumlocution that I
read about in law school... constantly talking around things instead of
about things.

This is good if everyone is on the same high-level of knowledge, but not
for a programming language (think applied approach to problem solving)
that has tremendous potential and is touted as user friendly for
non-programmers. No wonder so many people use Perl. As bad as Perl is,
it does not have a scholarly opinion of itself and is thus approachable
and usable.

Forgive me, I''m frustrated.

Bart


Bart Nessux wrote:

Roger Binns wrote:

There is a qsize() method clearly documented. What is wrong with
that?


Where??? The documentation for the module named Queue says nothing at
all about this...

http://docs.python.org/lib/module-Queue.html



You''re right... at the bottom of the page, there is a subsection.
qsize() is there. In frustration, I overlooked it.


这篇关于队列模块和Python文档Rant的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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