generator

Can iterators be reset in Python?

Can I reset an iterator / generator in Python? I am using DictReader and would like to reset it (from the csv module) to the beginning of the file. thanks. ...

Why does rails generate object instance variables in controllers

Why does rails use @poop object instance variables instead of just a local poop variable in the generated code? Is there some foreseen common situation where it's useful rather than simply using a local variable here? I would think it makes sense to use a local variable and not attach something to the object namespace unless you need it ...

Does python yield imply continue?

I have a for loop that checks a series of conditions. On each iteration, it should yield output for only one of the conditions. The final yield is a default, in case none of the conditions are true. Do I have to put a continue after each block of yields? def function(): for ii in aa: if condition1(ii): yield som...

Python: is it possible to mix generator and a recursive function ?

Is there a way to make the something like the following code work? add = lambda n: (yield n) or add(n+1) (answers don't need to be in functional style) ...

Symfony admin generator - add link on title

I am currently using the Symfony admin generator to implement a management web application. I would like to know if there is a way to add a link on the title section of the generator.yml file. As example: edit: title: Configurations > Officials | "link to another module" ...

Skipping an new/transient NHibernate entity's ID generator strategy when an ID is already provided

Hi all Just a quickie ... I have the following ID generator strategy for one of my mapped classes: <id name="UID" type="System.Guid"> <column name ="UID" sql-type ="uniqueidentifier" /> <generator class="guid.comb" /> </id> The entity in question is involved in synchronisation / merging behaviours from which it is necessary t...

Python generator that returns the same thing forever

I'm looking for a standard function that does this: def Forever(v): while True: yield v It seems so trivial I can't believe there isn't a standard version. For that matter anyone know of a good link to a list of all the standard generator functions? ...

How to extend pretty print module to tables?

I have the pretty print module, which I prepared because I was not happy the pprint module produced zillion lines for list of numbers which had one list of list. Here is example use of my module. >>> a=range(10) >>> a.insert(5,[range(i) for i in range(10)]) >>> a [0, 1, 2, 3, 4, [[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3],...

Recursion Recursion Recursion --- How can i Improve Performance? (Python Archive Recursive Extraction)

I am trying to develop a Recursive Extractor. The problem is , it is Recursing Too Much (Evertime it found an archive type) and taking a performance hit. So how can i improve below code? My Idea 1: Get the 'Dict' of direcories first , together with file types.Filetypes as Keys. Extract the file types. When an Archive is found Extract ...

Yielding until all needed values are yielded, is there way to make slice to become lazy

Is there way to stop yielding when generator did not finish values and all needed results have been read? I mean that generator is giving values without ever doing StopIteration. For example, this never stops: (REVISED) from random import randint def devtrue(): while True: yield True answers=[False for _ in range(randint(1...

Looking for a smart command-line tool in Linux which can generate xsd out of xml.

I can also settle for a web-based interface, but a good command-line tool is preferable. Now, I have tried to use xsd.exe that comes with mono-devel, but that skipped a whole bunch of stuff that was mentioned in the xml file. I understand that I will need to hand-tweak the output, but I do want something decent to start with. ...

Solaris dev/random

Hallo, Which algorithm implements dev/random of Solaris? Is taht Yarrow-160 or Yarrow-256 or is the algorithm the same as in Linux? Is there documentation / link ? I have already looked a lot, but I couldn't find it. Thanks in advance. ...

How can I generate a random English "sounding" word in .Net?

I know there have been several posts about random word generation based on large dictionaries or web lookups. However, I'm looking for a word generator which I can use to create strong password without symbols. What I'm looking for is a reliable mechanism to generate a random, non recognised, English word of a given length. An example ...

enumerate()-ing a generator in Python

I'd like to know what happens when I pass the result of a generator function to python's enumerate(). Example: def veryBigHello(): i = 0 while i < 10000000: i += 1 yield "hello" numbered = enumerate(veryBigHello()) for i, word in numbered: print i, word Is the enumeration iterated lazily, or does it slurp ...

Using the boost random number generator with OpenMP

I would like to parallelize my boost random number generator code in C++ with OpenMP. I'd like to do it in way that is both efficient and thread safe. Can someone give me pointers on how this is done? I am currently enclosing what I have below; this is clearly not thread safe since the static variable in the sampleNormal function is like...

Python permutation generator puzzle

I am writing a permutation function that generate all permutations of a list in Python. My question is why this works: def permute(inputData, outputSoFar): for elem in inputData: if elem not in outputSoFar: outputSoFar.append(elem) if len(outputSoFar) == len(inputData): print outputSoF...

Generating random tree branch

I want to generate (an image of) a single branch of a tree (the "woody plant" kind). Maybe similar to this branch, or this one. I need it to be interesting but simple, so just one branch, with a few turns, and only a few splits (where it changes from one limb into two). It should start with one fat branch and split off into a few thin b...

In-place dictionary inversion in Python

I need to invert a dictionary of lists, I don't know how to explain it in English exactly, so here is some code that does what I want. It just takes too much memory. def invert(oldDict): invertedDict = {} for key,valuelist in oldDict.iteritems(): for value in valuelist: try: entry = invertedDi...

Generator in if-statement in python

Or How to if-statement in a modified list. I've been reading StackOverflow for a while (thanks to everyone). I love it. I also seen that you can post a question and answer it yourself. Sorry if I duplicate, but I didn't found this particular answer on StackOverflow. How do you verify if a element is in a list but modify it in the sa...

print each item of array in order - one per page refresh

Like a random image generator (ex: http://www.dustindiaz.com/a-simple-php-image-rotator/), only in a sequential order. Im running banner ads, and the client would like them run 1,2,3,4,5 in order per page load. So they just go round robin. 5 page loads, then the cycle start again. Any ideas? I've googled for a while, and i'm not finding...