how to implement a queue-like container with sort function

Ned Batchelder ned at nedbatchelder.com
Mon Dec 2 06:58:11 EST 2013


On 12/2/13 6:41 AM, iMath wrote:
> 在 2013年11月29日星期五UTC+8下午10时57分36秒,Mark Lawrence写道:
>> On 29/11/2013 12:33, iMath wrote:
>>
>>>
>>
>>> BTW ,the Queue object has an attribute 'queue' ,but I cannot find it described in the DOC ,what it means ?
>>
>>>
>>
>>
>>
>> Really? AttributeError: type object 'Queue' has no attribute 'queue'
>>
>>
>>
>> --
>>
>> Python is the second best programming language in the world.
>>
>> But the best has yet to be invented.  Christian Tismer
>>
>>
>>
>> Mark Lawrence
>
> you can do a check by hasattr()
>

Yes, a Queue object has a queue attribute:

     >>> import Queue
     >>> q = Queue.Queue()
     >>> q.queue
     deque([])

But you shouldn't use it.  It's part of the implementation of Queue, not 
meant for you to use directly.  In particular, if you use it directly, 
you are skipping all synchronization, which is the main reason to use a 
Queue in the first place.

It should have been named "_queue". We'll add that to the list of PEP-8 
violations in the Queue module! :)

--Ned.




More information about the Python-list mailing list