Dear all, I'm new to python programming.
I have this problem: I have a list of text files (both compressed and not) and I need to :
- connect to the server and open them
- after the opening of the file, I need to take his content and pass it to another python function that I wrote
def readLogs (fileName):
f = open (fileName, 'r')
inStr...
I want to know everything about the yield statement, in an easy to understand form.
I have read about the yield statement and its ease when implementing the iterator pattern. However, most of it is very dry. I would like to get under the covers and see how Microsoft handles return yield.
Also, when do you use yield break?
...
I recently discovered Ruby's blocks and yielding features, and I was wondering: where does this fit in terms of computer science theory? Is it a functional programming technique, or something more specific?
...
I've got a thread that's polling a piece of hardware.
while not hardware_is_ready():
pass
process_data_from_hardware()
But there are other threads (and processes!) that might have things to do. If so, I don't want to burn up cpu checking the hardware every other instruction. It's been a while since I've dealt with threading, and...
Background: I've got a bunch of strings that I'm getting from a database, and I want to return them. Traditionally, it would be something like this:
public List<string> GetStuff(string connectionString)
{
List<string> categoryList = new List<string>();
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
...
Right now I've got a mod_wsgi script that's structured like this..
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output...
I'm currently trying to create a class which implements IEnumerable<T> in order to construct a Hierarchy from a flat list of objects which have references to each other through a ParentId property. I'd like to write a fluent interface for this so I can do something like this
IEnumerable<Tab> tabs = GetTabs();
IEnumerable<TabNode> tabNo...
After answering this question I put together the following C# code just for fun:
public static IEnumerable<int> FibonacciTo(int max)
{
int m1 = 0;
int m2 = 1;
int r = 1;
while (r <= max)
{
yield return r;
r = m1 + m2;
m1 = m2;
m2 = r;
}
}
foreach (int i in FibonacciTo(56).Where...
I spent a good long while looking for info on the differences between time.h::sleep() and pthread.h::pthread_yield() but was unable to find any solid reference material and so I am posting this question.
What is the difference between time.h::sleep() and pthread.h::pthread_yield()?
Update:
The reason I ask is because I was using sleep...
This question is related to a previous question of mine
That's my current code
IEnumerable<Shape> Get()
{
while(//get implementation
yield return new Shape(//...
}
void Insert()
{
var actual = Get();
using (var db = new DataClassesDataContext())
{
db.Shapes.InsertAllOnSubmit(actual);
...
I've got a tree-like structure. Each element in this structure should be able to return a Enumerable of all elements it is root to. Let's call this method IEnumerable<Foo> GetAll(). So if we have
A <-- topmost root
/ \
B C
/ \ / \
D E F G
a call to GetAll on element C returns {C, F, G} (fixed order of eleme...
I understand Ruby and Python's yield. What does Scala's yield do?
...
This is a sample script to test the use of yield... am I doing it wrong? It always returns '1'...
#!/usr/bin/python
def testGen():
for a in [1,2,3,4,5,6,7,8,9,10]:
yield a
w = 0
while w < 10:
print testGen().next()
w += 1
...
An example:
val l = List(1,2,3)
val t = List(-1,-2,-3)
Can I do something like this?
for (i <- 0 to 10) yield (l(i)) yield (t(i))
Basically I want to yield multiple results for every iteration.
...
Behold the C# code:
IEnumerable<int> innerMethod(int parameter)
{
foreach(var i in Enumerable.Range(0, parameter))
{
yield return i;
}
}
IEnumerable<int> outerMethod(int parameter)
{
foreach(var i in Enumerable.Range(1, parameter))
{
foreach(var j in innerMethod(i))
{
...
Does anyone know of an open source financial library that implements Yield To Maturity and other fixed income calculations? The library needs to be callable from .Net.
...
Is it feasible to use the yield keyword to implement a simple state machine as shown here. To me it looks like the C# compiler has done the hard work for you as it internally implements a state machine to make the yield statement work.
Can you piggy-back on top of the work the compiler is already doing and get it to implement most of th...
I thought it would be nice to do something like this (with the lambda doing a yield return):
public IList<T> Find<T>(Expression<Func<T, bool>> expression) where T : class, new()
{
IList<T> list = GetList<T>();
var fun = expression.Compile();
var items = () => {
foreach (var item in list)
if (fun.Invoke(i...
I have the following function to get validation errors for a card. My question relates to dealing with GetErrors. Both methods have the same return type IEnumerable<ErrorInfo>.
private static IEnumerable<ErrorInfo> GetErrors(Card card)
{
var errors = GetMoreErrors(card);
foreach (var e in errors)
yield return e;
/...
I have generator object returned by multiple yield. Preparation to call this generator is rather time-consuming operation. That is why I want to reuse generator several times.
y = FunctionWithYield()
for x in y: print(x)
#here must be something to reset 'y'
for x in y: print(x)
Of course, I'm taking in mind copying content into simpl...