Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: isgenerator(...) - anywhere to be found?

Reply
Thread Tools

Re: isgenerator(...) - anywhere to be found?

 
 
Jean-Paul Calderone
Guest
Posts: n/a
 
      01-22-2008
On Tue, 22 Jan 2008 15:15:43 +0100, "Diez B. Roggisch" <> wrote:
>Jean-Paul Calderone wrote:
>
>> On Tue, 22 Jan 2008 14:20:35 +0100, "Diez B. Roggisch"
>> <> wrote:
>>>For a simple greenlet/tasklet/microthreading experiment I found myself in
>>>the need to ask the question
>>>
>>> [snip]

>>
>> Why do you need a special case for generators? If you just pass the
>> object in question to iter(), instead, then you'll either get back
>> something that you can iterate over, or you'll get an exception for
>> things that aren't iterable.

>
>Because - as I said - I'm working on a micro-thread thingy, where the
>scheduler needs to push returned generators to a stack and execute them.
>Using send(), which rules out iter() anyway.


Sorry, I still don't understand. Why is a generator different from any
other iterator?

Jean-Paul
 
Reply With Quote
 
 
 
 
Diez B. Roggisch
Guest
Posts: n/a
 
      01-22-2008
Jean-Paul Calderone wrote:

> On Tue, 22 Jan 2008 15:15:43 +0100, "Diez B. Roggisch"
> <> wrote:
>>Jean-Paul Calderone wrote:
>>
>>> On Tue, 22 Jan 2008 14:20:35 +0100, "Diez B. Roggisch"
>>> <> wrote:
>>>>For a simple greenlet/tasklet/microthreading experiment I found myself
>>>>in the need to ask the question
>>>>
>>>> [snip]
>>>
>>> Why do you need a special case for generators? If you just pass the
>>> object in question to iter(), instead, then you'll either get back
>>> something that you can iterate over, or you'll get an exception for
>>> things that aren't iterable.

>>
>>Because - as I said - I'm working on a micro-thread thingy, where the
>>scheduler needs to push returned generators to a stack and execute them.
>>Using send(), which rules out iter() anyway.

>
> Sorry, I still don't understand. Why is a generator different from any
> other iterator?


Because you can use send(value) on it for example. Which you can't with
every other iterator. And that you can utizilize to create a little
framework of co-routines or however you like to call it that will yield
values when they want, or generators if they have nested co-routines the
scheduler needs to keep track of and invoke after another.

I'm currently at work and can't show you the code - I don't claim that my
current approach is the shizzle, but so far it serves my purposes - and I
need a isgenerator()

Diez
 
Reply With Quote
 
 
 
 
Steven Bethard
Guest
Posts: n/a
 
      01-22-2008
Diez B. Roggisch wrote:
> Jean-Paul Calderone wrote:
>
>> On Tue, 22 Jan 2008 15:15:43 +0100, "Diez B. Roggisch"
>> <> wrote:
>>> Jean-Paul Calderone wrote:
>>>
>>>> On Tue, 22 Jan 2008 14:20:35 +0100, "Diez B. Roggisch"
>>>> <> wrote:
>>>>> For a simple greenlet/tasklet/microthreading experiment I found myself
>>>>> in the need to ask the question
>>>>>
>>>>> [snip]
>>>> Why do you need a special case for generators? If you just pass the
>>>> object in question to iter(), instead, then you'll either get back
>>>> something that you can iterate over, or you'll get an exception for
>>>> things that aren't iterable.
>>> Because - as I said - I'm working on a micro-thread thingy, where the
>>> scheduler needs to push returned generators to a stack and execute them.
>>> Using send(), which rules out iter() anyway.

>> Sorry, I still don't understand. Why is a generator different from any
>> other iterator?

>
> Because you can use send(value) on it for example. Which you can't with
> every other iterator. And that you can utizilize to create a little
> framework of co-routines or however you like to call it that will yield
> values when they want, or generators if they have nested co-routines the
> scheduler needs to keep track of and invoke after another.


So if you need the send() method, why not just check for that::

try:
obj.send
except AttributeError:
# not a generator-like object
else:
# is a generator-like object

Then anyone who wants to make an extended iterator and return it can
expect it to work just like a real generator would.

STeVe
 
Reply With Quote
 
TezZ Da Sp@cE MaN
Guest
Posts: n/a
 
      01-23-2008


-----Original Message-----
From: python-list-bounces+dhwani006=
[mailtoython-list-bounces+dhwani006=] On Behalf Of
Diez B. Roggisch
Sent: 22 January 2008 20:22
To: python-
Subject: Re: isgenerator(...) - anywhere to be found?

Jean-Paul Calderone wrote:

> On Tue, 22 Jan 2008 15:15:43 +0100, "Diez B. Roggisch"
> <> wrote:
>>Jean-Paul Calderone wrote:
>>
>>> On Tue, 22 Jan 2008 14:20:35 +0100, "Diez B. Roggisch"
>>> <> wrote:
>>>>For a simple greenlet/tasklet/microthreading experiment I found myself
>>>>in the need to ask the question
>>>>
>>>> [snip]
>>>
>>> Why do you need a special case for generators? If you just pass the
>>> object in question to iter(), instead, then you'll either get back
>>> something that you can iterate over, or you'll get an exception for
>>> things that aren't iterable.

>>
>>Because - as I said - I'm working on a micro-thread thingy, where the
>>scheduler needs to push returned generators to a stack and execute them.
>>Using send(), which rules out iter() anyway.

>
> Sorry, I still don't understand. Why is a generator different from any
> other iterator?


Because you can use send(value) on it for example. Which you can't with
every other iterator. And that you can utizilize to create a little
framework of co-routines or however you like to call it that will yield
values when they want, or generators if they have nested co-routines the
scheduler needs to keep track of and invoke after another.

I'm currently at work and can't show you the code - I don't claim that my
current approach is the shizzle, but so far it serves my purposes - and I
need a isgenerator()

Diez
--
http://mail.python.org/mailman/listinfo/python-list

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
USB config for Windows Connect Now. Did this go anywhere? glenn.woodruff@gmail.com Wireless Networking 2 09-01-2005 10:12 AM
PC Anywhere vs Wireless Paul King Wireless Networking 0 06-12-2005 11:29 PM
PC Anywhere setup Jim Wireless Networking 3 10-19-2004 02:46 PM
3620, rommon, and xmodeming an ios to it .. cannot find help for this anywhere. Volatileacid Cisco 1 07-30-2004 04:03 AM
PIX 501 and PC Anywhere the_poet Cisco 0 02-05-2004 10:38 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57