473,763 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"flushing"/demanding generator contents - implications for injection of control

For this program:

def reverse(data):
for index in range(len(data)-1, -1, -1):
yield data[index]

r = reverse("golf")

for char in r:
print char
I'm wondering if the line:

r = reverse("golf")

"demands" the contents of the function reverse() all at once and if I
must write

for char in reverse("golf") :
print char

if I want the results streamed instead of generated complely.

** CONTEXT **

The simple example above is not what I am really doing. My real
program parses very large
data files using pyparsing. Pyparsing can generate incremental/yielded
results with no problem:

http://pyparsing.wikispaces.com/mess.../248539#248852

but because I believe in injection of control (pushing data around as
opposed to having
the target pull it), I get the parse and then inject it into the
generator:

parse = parsing.parse(f p.read())
txt = textgen.generat e(self.storage. output, patent_key,
parse, f.basename(), debug=False)

Feb 5 '07 #1
3 1329
metaperl kirjoitti:
For this program:

def reverse(data):
for index in range(len(data)-1, -1, -1):
yield data[index]

r = reverse("golf")

for char in r:
print char
I'm wondering if the line:

r = reverse("golf")

"demands" the contents of the function reverse() all at once and if I
must write

for char in reverse("golf") :
print char

if I want the results streamed instead of generated complely.

** CONTEXT **

The simple example above is not what I am really doing. My real
program parses very large
data files using pyparsing. Pyparsing can generate incremental/yielded
results with no problem:

http://pyparsing.wikispaces.com/mess.../248539#248852

but because I believe in injection of control (pushing data around as
opposed to having
the target pull it), I get the parse and then inject it into the
generator:

parse = parsing.parse(f p.read())
txt = textgen.generat e(self.storage. output, patent_key,
parse, f.basename(), debug=False)
I don't know, I'm guessing:

... r = reverse("golf")
... type(r)
<type 'generator'>
... print r.next()
f

So r is not the string 'flog', it is the generator producing it

HTH,
Jussi
Feb 5 '07 #2
En Mon, 05 Feb 2007 16:47:43 -0300, metaperl <me******@gmail .comescribi:

For this program:

def reverse(data):
for index in range(len(data)-1, -1, -1):
yield data[index]

r = reverse("golf")

for char in r:
print char
I'm wondering if the line:

r = reverse("golf")

"demands" the contents of the function reverse() all at once and if I
must write

for char in reverse("golf") :
print char

if I want the results streamed instead of generated complely.
reverse is a generator; it executes one step at a time. That's the whole
point of generators.

--
Gabriel Genellina

Feb 6 '07 #3
On Feb 5, 3:08 pm, Jussi Salmela <tiedon_j...@ho tmail.comwrote:
metaperl kirjoitti:
For this program:
def reverse(data):
for index in range(len(data)-1, -1, -1):
yield data[index]
r = reverse("golf")
for char in r:
print char
I'm wondering if the line:
r = reverse("golf")
"demands" the contents of the function reverse() all at once and if I
must write
for char in reverse("golf") :
print char
if I want the results streamed instead of generated complely.
** CONTEXT **
The simple example above is not what I am really doing. My real
program parses very large
data files using pyparsing. Pyparsing can generate incremental/yielded
results with no problem:
http://pyparsing.wikispaces.com/mess.../248539#248852
but because I believe in injection of control (pushing data around as
opposed to having
the target pull it), I get the parse and then inject it into the
generator:
parse = parsing.parse(f p.read())
txt = textgen.generat e(self.storage. output, patent_key,
parse, f.basename(), debug=False)

I don't know, I'm guessing:

... r = reverse("golf")
... type(r)
<type 'generator'>
very slick! thanks!
... print r.next()
f

So r is not the string 'flog', it is the generator producing it

HTH,
It does!
Jussi

Feb 6 '07 #4

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

Similar topics

9
7425
by: dover | last post by:
For the code, outputfile << *p << endl; Someone suggests: Don't use endl here; it is flushing output stream every time. Use plain '\n'. What's the difference of using "endl" and "\n" above? What's the meaning of flushing output stream? Isn't that what we want? Thanks!
4
5097
by: Rob Freundlich | last post by:
I have some servlet-generated tabular data that I need to present, so I'm using an HTML Table. In some cases, it can be quite large. I'm flushing the servlet output every N lines to push the data to the browser as it generates, and I've used "table-layout: fixed" for the table's CSS class. It works pretty well in Netscape (7.1 and higher) - the table is drawn pretty much as the rows are received by the browser. However, Internet...
7
3373
by: clusardi2k | last post by:
Hello, I have a shared drive on SGI, Linux, and Windows. A second call to fopen doesn't create the file if it has been deleted. I would like to use fopen for its pointer return value to solve this. What is the best way to fix this problem?
15
2141
by: Jiří Paleček | last post by:
Hello, I know the rules for const handling in C++, but I'd like to ask what is the "right" way to use them, eg. when is it appropriate to make a member function const? This came across this question when I was thinking about implementation of a class implementing some lazy data structure or cache. The C++ rules allow among other possibilities making all member functions non-const, or making all member functions const and all members...
10
2270
by: Pete | last post by:
I have the following code: <built-in method close of file object at 0xb7cc76e0> The file "temp.html" is created, but it doesn't look like the page at www.python.org. I'm guessing there are multiple frames and my code did not get everything. Can anyone point me to a tutorial or other reference on how to "get" all of the html contents at a particular page?
9
3382
by: Xian | last post by:
Is there a right and proper (tm) way to end a line? Thinking about portability and the mess that the 'wrong' line endings can cause. E.g. std::cout << "Hello World!\n"; or std::cout << "Hello World!" << std::cout; -- /Xian
5
2866
by: arnuld | last post by:
this is from mentioned section. i did not understand some things here: it means "flushing the buffer" and "writing to output device" are SAME thing, these are just 2 different names for the same thing. ?
94
30348
by: Samuel R. Neff | last post by:
When is it appropriate to use "volatile" keyword? The docs simply state: " The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock Statement (C# Reference) statement to serialize access. " But when is it better to use "volatile" instead of "lock" ?
9
3363
by: andrew.smith.cpp | last post by:
hi, whts the difference between the std::endl or "\n" ? because both do the same work Thanks
0
9563
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10145
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...
0
9998
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
9938
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
9822
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
8822
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 projectplanning, coding, testing, and deploymentwithout 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...
1
7366
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
6642
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
3917
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.