473,473 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

design question: generator object with other attributes

Essentially I want a generator that I can query about
its characteristics. (E.g., a random number generator
that I want to be able to ask about is distributional
parameters.)

I am thinking of a class that wraps a generator.
An object of this class will have a ``next`` method that simply
returns the value the object get by calling the wrapped
generator.

A reasonable approach?

Thanks,
Alan Isaac

PS Here is a useless class to illustrate the basic idea
that you could have both attribute access and a
generator-connected ``next`` method.

class Start2Stop:
def __init(start,stop):
self.start = start
self.stop = stop
self.numgen = (i for in in xrange(start,stop))
def next(self):
return self.numgen.next()

Mar 22 '07 #1
3 1135
Alan Isaac wrote:
Essentially I want a generator that I can query about
its characteristics. (E.g., a random number generator
that I want to be able to ask about is distributional
parameters.)

I am thinking of a class that wraps a generator.
An object of this class will have a ``next`` method that simply
returns the value the object get by calling the wrapped
generator.
You will probably also need to define

def __iter__(self):
return self

if I remember correctly.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Mar 22 '07 #2
Alan Isaac wrote:
Essentially I want a generator that I can query about
its characteristics. (E.g., a random number generator
that I want to be able to ask about is distributional
parameters.)

I am thinking of a class that wraps a generator.
An object of this class will have a ``next`` method that simply
returns the value the object get by calling the wrapped
generator.

A reasonable approach?

Thanks,
Alan Isaac

PS Here is a useless class to illustrate the basic idea
that you could have both attribute access and a
generator-connected ``next`` method.

class Start2Stop:
def __init(start,stop):
self.start = start
self.stop = stop
self.numgen = (i for in in xrange(start,stop))
def next(self):
return self.numgen.next()
In case you are having problems, "__init(start,stop)" should be spelled
"__init__(self, start, stop)".

James
Mar 23 '07 #3
Alan Isaac <ai****@american.eduwrote:
Essentially I want a generator that I can query about
its characteristics. (E.g., a random number generator
that I want to be able to ask about is distributional
parameters.)

I am thinking of a class that wraps a generator.
An object of this class will have a ``next`` method that simply
returns the value the object get by calling the wrapped
generator.

A reasonable approach?
Sure, given the undiscussed constraints.
>
Thanks,
Alan Isaac

PS Here is a useless class to illustrate the basic idea
that you could have both attribute access and a
generator-connected ``next`` method.

class Start2Stop:
def __init(start,stop):
self.start = start
self.stop = stop
self.numgen = (i for in in xrange(start,stop))
def next(self):
return self.numgen.next()
Don't forget to add:

def __iter__(self): return self
Alex.
Mar 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Danimal | last post by:
I have been using PHP for a long time... since it was called PHP/FI. I have a programming design question: Let say I have this class: class attrib { var $lenght; var $type; ... }
9
by: Francis Avila | last post by:
A little annoyed one day that I couldn't use the statefulness of generators as "resumable functions", I came across Hettinger's PEP 288 (http://www.python.org/peps/pep-0288.html, still listed as...
6
by: Tim Mavers | last post by:
I have a series of database objects that represent things such as people, accounts, etc. I have a set of options (boolean) that I need to add to these objects. Normally I would just create a bit...
9
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with...
11
by: Peter M. | last post by:
Hi all, I'm currently designing an n-tier application and have some doubts about my design. I have created a Data Access layer which connects to the database (SQL Server) and performs Select,...
41
by: Petr Jakes | last post by:
Hello, I am trying to study/understand OOP principles using Python. I have found following code http://tinyurl.com/a4zkn about FSM (finite state machine) on this list, which looks quite useful for...
19
by: Chocawok | last post by:
Some of the classes in my app are graphical. To encapsulate the graphical side of things I had created a class called "sprite" which holds a bit map and knows how to draw itself etc. The...
3
by: Allerdyce.John | last post by:
I have a design type of quesiton. What is the advantages of using accessor (a getter/setter method) instead of making the attribute 'public'? If a class has public accessor (a getter/setter...
28
by: Alan Isaac | last post by:
I have a class whose instances should only receive attribute assignments for attributes that were created at inititialization. If slots are not appropriate, what is the Pythonic design for this? ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.