473,795 Members | 2,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

iterator clone

Whats is the way to clone "independen t" iterator? I can't use tee(),
because I don't know how many "independen t" iterators I need. copy and
deepcopy doesn't work...

--pavel
Jul 13 '08
13 6367
On 15 Jul., 08:16, Yosifov Pavel <b...@ngs.ruwro te:
cloning of iterators in this manner is bad, more good is to use one,
single list(my_iter) instead of (seehttp://aquagnu.blogspo t.com/2008/07/self-repair-iterator-in-python.html).
This won't work for "big" iterators as mentioned by Peter Otten. With
this recipe you can't even clone generator objects ( which are
iterators ) that produce Fibonaccis in a lazy manner.

Regards, Kay

Jul 15 '08 #11
Kay, can you show example of such generator? ReIter, for example, work
with usual generators.

But for "big" iterator, I think is no any good solutions. IMHO we can
discern 2 types of iterators: re-startable (based on internal Python
objects) and not re-startable (with an external state, side-
effects)...

Best regards, Pavel
Jul 16 '08 #12
On Tue, 15 Jul 2008 19:54:30 -0700, Yosifov Pavel wrote:
Kay, can you show example of such generator? ReIter, for example, work
with usual generators.

But for "big" iterator, I think is no any good solutions. IMHO we can
discern 2 types of iterators: re-startable (based on internal Python
objects) and not re-startable (with an external state, side-
effects)...
Has nothing to do with internal vs. external.
Examples: ``itertools.cou nt(1)``, ``itertools.cyc le(iterable)``, or

def fib():
a, b = 0, 1
while True:
yield a
a, b = b, a + b

Ciao,
Marc 'BlackJack' Rintsch
Jul 16 '08 #13
On 16 ÉÀÌ, 11:32, Marc 'BlackJack' Rintsch <bj_...@gmx.net wrote:
On Tue, 15 Jul 2008 19:54:30 -0700, Yosifov Pavel wrote:
Kay, can you show example of such generator? ReIter, for example, work
with usual generators.
But for "big" iterator, I think is no any good solutions. IMHO we can
discern 2 types of iterators: re-startable (based on internal Python
objects) and not re-startable (with an external state, side-
effects)...

Has nothing to do with internal vs. external.
Examples: ``itertools.cou nt(1)``, ``itertools.cyc le(iterable)``, or

def fib():
a, b = 0, 1
while True:
yield a
a, b = b, a + b

Ciao,
Marc 'BlackJack' Rintsch
Yes. So, I'm disconcerted: what Python "means" about iterators. Why
iterator's are not clonable in default?.. ``itertools.cou nt(it) ``
"suppose" ``it`` will be restarted after count? So ``count(it)``
"suppose" ``it`` is restarable and therefore clonable (why not?!).
Generator is only function, so can be restarted/cloned. Generator
keeps "position" and can't be iterated again. But this position can be
reseted (main rule: if generator function has not side-effects/
external state, see below)!

Iterator, I think, is more general method (for naturally serial
access). For example, you can read values from some device (RS323 or
other) and represent it in program like iterator. In this case,
``__iter__()`` make some preparation, ``next()`` read next value from
RS232. In this case, iterator can't be restarted and really cloned. It
has external state (state of device) and can't to return it at start.
But when series of values are generated (are born) in the program: no
problem to have the feature of clone/restart iterator.

And is very interesting to research Icon iterators. Is possible to
create something in Python such theirs, for non-deterministic solving
purpose... :-)

--pavel
Jul 16 '08 #14

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

Similar topics

0
2672
by: Jason Evans | last post by:
Hi All, I am writing my own implementation of queue via a linked list, note not a LinkedList, and was running into trouble with the clone method. I was wondering if anyone could point out some not so obvious errors I have made.. Cheers
38
3693
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages mentioned: I characterized one way of looking at languages in this way: a lot of them are either the agglutination of features or they're a crystallization of style. Languages such as APL, Lisp, and Smalltalk are what you might call style...
6
2151
by: Steve | last post by:
I can't find a straight answer on what to use? I need a deep copy, so I implemented IConeable and the Clone() method. However, I'm not sure I did it correct. Is it suposed to be an allocation of a new object, then the assignment of each member? Is that all or is there something else I need to do? Here is my code <code> public Object Clone() {
4
4322
by: Brian Keating | last post by:
Hi there, Consider this from MSDN *Notes to Inheritors When you derive from DataGridViewCheckBoxCell and add new properties to the derived class, be sure to override the Clone method to copy the new properties during cloning operations. You should also call the base class's Clone method so that the properties of the base class are copied to the new cell. * How should I do this? a)
1
3822
by: Alex D. | last post by:
hi guys. I need to clone multiple times an object and I am succesfully cloning using the regular serialization process, using a MemoryStream. My problem is that after cloning the object more that 7 or 10 times then my computer's memory gets flooded and every time I call the Clone() method the processor resources gets consumed 100% for like 30 seconds. And this problem increases as the amount of clones are created increases. I read some...
2
11470
by: Steven | last post by:
Hi, I have created my own node (class MyNode : TreeNode) for a TreeView. To populate the treeview, i use something like MyNode newNode = new MyNode("Bla bla bla","0","1") for example. But, to move the nodes in the treeview, i use the clone() method... : MyNode theCopy = (MyNode)theTreeView.SelectedNode.Clone();
16
2518
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some of properties or assign event handlers. I need to be able to clone the manipulated control at runtime. I could use the Clone method of some objects (like Font, Style, String,
14
8642
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event handlers are set like the old one. Is there a way to do this job? For example, is there a way to use EventInfo object to get all event handlers of the old control in runtime and set my new cloned control events to the event handlers of the old...
7
2845
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds to support cloning: Public Class RefClass Public tcp As TcpClient Public name As String End Class Public Class RefClassList Inherits List(Of RefClass) Implements ICloneable
0
9672
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
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10436
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
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
10000
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...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
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();...
1
4113
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
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.