yield is a Python keyword that facilitates creation of generator functions.
2
votes
1answer
42 views
Taking up too much memory - python
I wrote a recursive function that exhaustively generates matrices of certain characteristics.
The function is as such:
def heavies(rowSums,colSums,colIndex,matH):
if colIndex == len(colSums) - 1:
...
1
vote
0answers
47 views
Replace String in Yield
Is it possible in Ruby to replace a string within a yield block? For example, if somebody has
drop_down "Dropdown" do
menu_item "Home", "/"
drop_down "Inner" do
menu_item "Inner ...
0
votes
1answer
18 views
Selectively appending elements from a list to a new list
Using a loose definition of the word 'sequence' I have a list with over 2,000 elements (sequence numbers) and for each short sequence I want to append the highest number to a separate list. Here's a ...
1
vote
1answer
19 views
Python - Implement iteration over certain class attributes on given order
I have a Position class, and it has two attributes, Lat and Lon.
I would like the following API by implementing iterator protocol (but some googling just confused me more):
pos = Position(30, 50)
...
0
votes
1answer
40 views
Trying to understand generators / yield in node.js - what executes the asynchronous function?
node.js now has generators.
My understanding is that generators can be used to write code that appears to be much more linear and avoids callback hell and pyramid of doom style coding.
So to this ...
4
votes
2answers
108 views
Implementing yield in C
For example:
int getNext(int n) {
while (TRUE) {
n = n+1;
yield n;
}
}
int main() {
while (TRUE) {
int n = getNext(1);
if (n > 42)
break;
...
0
votes
2answers
31 views
How to modify this function to accept the return in three different variables?
I have a function like this:
import os
import subprocess
def find_remote_files(hostspec):
cmdline = ["rsync", "-e", "ssh", "-r", hostspec]
with open(os.devnull, "w") as devnull:
proc ...
0
votes
2answers
14 views
Floating sidebar next to <% yield %>
I'm trying to float a sidebar nav as a partial in my rails app. Here is the relevant part of my application layout:
<body>
<%= render 'layouts/header' %>
<% flash.each do ...
3
votes
1answer
61 views
Python prime numbers generator yield vs return [duplicate]
Searching for python prime numbers generator, I found:
def primes(n):
if n==2: return [2]
elif n<2: return []
s=range(3,n+1,2)
mroot = n ** 0.5
half=(n+1)/2-1
i=0
m=3
...
2
votes
1answer
37 views
Yield Rails 2 vs Rails 3
I was in process of migrating a rails 2 app to rails 3. While doing this i came accross a wiered behaviour with yield.
I have a code snippet where i get the return value of yield.
x= true if yield ...
1
vote
1answer
50 views
Quickly opening and closing csv?
I'm working on a program in python that converts a csvs to a list of lists. It does this multiple times for different files so I made it into a function. I haven't encountered errors with this, but ...
0
votes
1answer
61 views
Python: yield vs print in a loop
I am a beginner in Python currently working through Project Euler's problems (here for those who have not heard about it). I have solved this particular problem, however it leaves me with some ...
0
votes
1answer
40 views
Where did concept of yield keyword come from?
Similar question to this. Keyword yield is present in three languages I know or I heard of: Python, Ruby, C#. They plan to introduce this keyword also to PHP. Where did it originally come from? I did ...
0
votes
1answer
28 views
Access a variable from within a method when being passed a block that contains the variable
From what I understand every time it runs though run_times it pops off one of the run_times values and adds it to fake_time. And with my measure method I'm supposed to gather those and get the ...
0
votes
1answer
45 views
with adder default blocks exercise. How Do I vary output depending if I get a block to my method or not?
Here is the rspec I need to pass:
describe "adder" do
it "adds one to the value returned by the default block" do
adder do
5
end.should == 6
end
it "adds 3 to the value returned by the ...
1
vote
1answer
36 views
yield inside with block in python function
I don't understand what's happening when the following function is called:
def doSmth(inFile):
print inFile
with open(inFile,'r') as trainSet:
for instLine in trainSet:
# ...
0
votes
1answer
35 views
Recursive call in python seems not to descend
I have a small function to flatten lists and tuples. The recursive call does get invoked, but .. nothing happens.. By "nothing" i mean: the stderr message is not printed and also no results are ...
1
vote
2answers
55 views
Scala Yield behaves differently than Scala Map
I trying to compose and initialize an Array in a single line, roughly equivalent to this:
var characterMap = new Array[List[ActorRef]](sizeX*sizeY)
characterMap.indices.foreach(characterMap(_) = ...
1
vote
2answers
49 views
Dir.glob to get all csv and xls files in folder
folder_to_analyze = ARGV.first
folder_path = File.join(Dir.pwd, folder_to_analyze)
unless File.directory?(folder_path)
puts "Error: #{folder_path} no es un folder valido."
exit
end
def ...
1
vote
1answer
29 views
Javascript yield generator - how to skip values
I've got a collection on items that I'm trying to use yield to create an iterable collection on, but with the added complexity that I want to exclude value that do not match a certain criterion
...
1
vote
1answer
37 views
combine results of multiple python scripts in one statement
I have about 4 different python scripts that all return a list of dictionaries. I would like to combine the results from all of the scripts and then print it out to the console, but if possible I ...
4
votes
4answers
101 views
Scala for-loop. Getting index in consice way
In this code I want to increment index to put it to each yielding result.
var index=0
for(str <- splitToStrings(text) ) yield {
if (index != 0) index += 1 // but index is equal ...
1
vote
1answer
44 views
In Tritium, what does the yield() function do?
I'm looking at the examples on the Tritium API website, and I don't understand what the yield() function does.
http://tritium.io/simple-mobile/1.0.224#yield()%20Text
Can someone explain these ...
0
votes
1answer
42 views
Yield statement blocks recursive function?
I've spent a lot of time on this issue without finding any hint... I don't understand why yield forbid my recursive function to execute, without any outputs at all.
def unlist(l):
if ...
0
votes
1answer
30 views
Balancing memory and performance in using yield in recursion
I have a function that yields out permutation:
def all_perms(str):
if len(str) <=1:
yield str
else:
for perm in all_perms(str[1:]):
for i in range(len(perm)+1):
...
3
votes
4answers
67 views
Yield vs generator expression - different type returned
There is this code:
def f():
return 3
return (i for i in range(10))
x = f()
print(type(x)) # int
def g():
return 3
for i in range(10):
yield i
y = g()
print(type(y)) # generator
Why ...
0
votes
2answers
36 views
Python: how to return from generator function using tornado?
I use yield and task to get four jsons asynchronously:
@gen.engine
def get_user_data(self, sn, snid, fast_withdrawals):
end_timestamp = time.time()
start_timestamp = end_timestamp - ...
2
votes
0answers
46 views
check if function is a generator
I played with generators in Nodejs v0.11.2 and I'm wondering
how I can check that argument to my function is generator function.
I found this way typeof f === 'function' && ...
1
vote
1answer
46 views
“yield”ing a dictionary with keys as lists using mincemeat.py
I am trying to understand the map-reduce concept and looking at implementing small programs using mincemeat.py, an open source library for python.
I have obtained the simple word count for a bag of ...
0
votes
0answers
67 views
yield to maturity - nesting a function?
I cannot get the yield to maturity calculation to work within this function. I have replicated a solution that works outside this function but for some reason it is not working here. The function is ...
0
votes
1answer
54 views
ECMA harmony – callback to generator
First off – we are on untread territory here, so while it works in newest firefoxes, the doc on MDN isn’t ready during the time of writing. I’ll fix the MDN later (maybe, there’s a lot of places that ...
1
vote
1answer
49 views
Does a code that combines single() with yield make any sense?
I came across a code which should return the single object expected in a list, this code has an iterator block which yields the found items, i have simplified the case in the following example:
...
1
vote
4answers
91 views
How yield catches StopIteration exception?
Why in the example function terminates:
def func(iterable):
while True:
val = next(iterable)
yield val
but if I take off yield statement function will raise StopIteration ...
1
vote
1answer
149 views
how to yield lua script in C Function
it works when lua call a C API
if a C function call lua function, and the lua function call C API, longjmp error
lua_yieldk, lua_callk, and lua_pcallk
how does it work?
my c code:
int ...
0
votes
2answers
204 views
too many values to unpack in a yield
this is an exercise where Item is a class, and when I run testAll I have a valueError. The yield is suppose to return just 2 values, the content of 2 bags:
> Traceback (most recent call last):
...
1
vote
2answers
218 views
yield waitforseconds() not working
I have the following code in a player object:
function Start ()
{
GUI = GameObject.FindWithTag("GUI").GetComponent(InGameGUI);
}
function OnCollisionEnter(hitInfo : Collision)
{
...
0
votes
0answers
59 views
rails yield, fixed headers - avoid page reload
In my rails app, my layouts/application.html.erb file consists of a partial called _header, and a div class called 'page-content', which shows my <%= yield %>
My partial _header has a 'header ...
0
votes
2answers
62 views
How do I handle no existing values in a scala for yield loop
I'm pull parsing a xml file that might have or might not have an element called <Popular>
that resides within the element <EName>
example:
<Info>
<Enterprise>
<EName>
...
1
vote
1answer
143 views
Python BadYieldError: yielded unknown object HTTPError('HTTP 599: Connection closed',)
I want to know why in this function:
@tornado.gen.engine
def check_status_changes(netid, sensid):
como_url = "".join(['http://131.114.52:44444/ztc?netid=', str(netid), \
...
2
votes
1answer
41 views
Simple generator seems to be broken
I have written a simple generator:
function geni()
{
for(var i = 0; i < 10; i++)
{
yield i;
}
}
And I get the error:
SyntaxError: missing ; before statement
[Break On ...
0
votes
1answer
78 views
Is there a pretty way to yield if in Python 3.3?
Is there a way to make this code prettier?
strong = li.find_all("strong")
if strong:
yield li.find_all("strong")
I mean something like this:
strong = li.find_all("strong")
yield ...
0
votes
0answers
37 views
why yield in event loop?
anI used a C++ framework, where yield at the end of every loop cycle was mandatory. Now that I'm starting with C# and C++/CLI, I came across the yield function as well. I'm creating an event loop and ...
0
votes
1answer
374 views
Rails yield and content_for in partial
I've got used to use content_for and yield for my views in order to set the page title and other neat stuff, related to view rendering.
And now I got stuck with next scheme: LAYOUT -> VIEW ...
1
vote
3answers
51 views
how to know the number of iterables in a generator in python
I have the following code
>>> x = ['a','b','c','d','e']
>>> def test_yield(lst):
... for el in lst:
... yield el
...
>>> var = test_yield(x)
>>> ...
0
votes
2answers
90 views
MongoDB JavaScript Yield large set of results
I'm trying to query a large set of results from a MongoDB over Python. I do this via JavaScript, because I want to get something like the grandchildren in a tree-like structure. My code looks like the ...
3
votes
2answers
234 views
Yield only if pattern match
I am building a list of different case class objects based on a loop and a pattern match. I want to exclude (skip) the items hitting the default case (essentially filtering the list, and mapping to ...
3
votes
2answers
65 views
Can Python yield into a list be made more efficient?
In Python v2.7, if I have a function like this:
def holes_between(intervals):
# Compute the holes between the intervals, for example:
# given the intervals: ([ 8, 9] [14, 18] [19, 20] [23, 32] ...
0
votes
3answers
130 views
Explain the use of yields in this Game of Life implementation
In this PyCon talk, Jack Diederich shows this "simple" implementation of Conway's Game of Life. I am not intimately familiar with either GoL or semi-advanced Python, but the code seems quite easy to ...
0
votes
1answer
135 views
Why does python statement yield behave this way with cursor?
I have the following code (i know how to do this working and in the right style, but cited it as an example only to ask a question and understand where is mistake):
import MySQLdb
import ...
1
vote
1answer
121 views
The yield + recursion in python annoyed me
It is so complicated for me to understand when yield and recursion happen simultaneously。
I want to traverse file directory with my code:
import os
def doc_iter(fpath):
if os.path.isdir(fpath):
...