473,739 Members | 3,096 Online
Bytes | Software Development & Data Engineering Community
+ 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,st op):
self.start = start
self.stop = stop
self.numgen = (i for in in xrange(start,st op))
def next(self):
return self.numgen.nex t()

Mar 22 '07 #1
3 1152
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,st op):
self.start = start
self.stop = stop
self.numgen = (i for in in xrange(start,st op))
def next(self):
return self.numgen.nex t()
In case you are having problems, "__init(start,s top)" should be spelled
"__init__(s elf, start, stop)".

James
Mar 23 '07 #3
Alan Isaac <ai****@america n.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,st op):
self.start = start
self.stop = stop
self.numgen = (i for in in xrange(start,st op))
def next(self):
return self.numgen.nex t()
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
1742
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
2687
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 open, even though it's at least a year old and Guido doesn't seem very hot on the idea). I'm not too sure of its ideas on raising exceptions in generators from outside (although it looks like it might be convenient in some cases), but being able...
6
375
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 field for each one and be done with it. The challenge however is that there could be hundreds of these options (maybe 300) and a user decides which of these options (actually attributes) that should apply to these db objects. For example, a...
9
2936
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 a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
11
2569
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, update, delete and inserts. I use dataset objects to pass data to and from the DAL. In my GUI (windows forms), I use databinding to bind controls to a datatable
41
2529
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 my purposes. As this code was posted long time ago (November 1998) I would like to ask if the principles used in this code are still valid in the "modern" Python and if/how it can be improved (revrited) using futures of current version of...
19
2517
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 classes that are graphical contain a sprite object.
3
1752
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 method) for its attribute, why not just make the attribute 'public'? It requires less code/typing. Or is there something I am missing? Thank you.
28
1472
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? Thanks, Alan Isaac
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9266
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6054
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3280
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.