chain

python chain a list from a tsv file

烂漫一生 提交于 2019-12-02 03:29:33
i have this tsv file containing some paths of links each link is seperated by a ';' i want to use: In the example below we can se that the text in the file is seperated and i only want to read through the last column wich is a path starting with '14th' 6a3701d319fc3754 1297740409 166 14th_century;15th_century;16th_century;Pacific_Ocean;Atlantic_Ocean;Accra;Africa;Atlantic_slave_trade;African_slave_trade NULL 3824310e536af032 1344753412 88 14th_century;Europe;Africa;Atlantic_slave_trade;African_slave_trade 3 415612e93584d30e 1349298640 138 14th_century;Niger;Nigeria;British_Empire;Slavery

Chain dynamic iterable of context managers to a single with statement

馋奶兔 提交于 2019-12-01 22:18:01
I have a bunch of context managers that I want to chain. On the first glance, contextlib.nested looked like a fitting solution. However, this method is flagged as deprecated in the documentation which also states that the latest with statement allows this directly: Deprecated since version 2.7: The with-statement now supports this functionality directly (without the confusing error prone quirks). However I could not get Python 3.4.3 to use a dynamic iterable of context managers: class Foo(): def __enter__(self): print('entering:', self.name) return self def __exit__(self, *_): pass def __init_

Execute Process Chain

痞子三分冷 提交于 2019-12-01 07:31:40
public void ExecuteProcessChain(string[] asProcesses, string sInRedirect, string sOutRedirect) { Process p1 = new Process(); p1.StartInfo.UseShellExecute = false; p1.StartInfo.RedirectStandardOutput = true; p1.StartInfo.FileName = asProcesses[0]; p1.Start(); StreamReader sr = p1.StandardOutput; string s, xxx = ""; while ((s = sr.ReadLine()) != null) Console.WriteLine("sdfdsfs"); //xxx += s+"\n"; p1.StartInfo.RedirectStandardInput = true; p1.StartInfo.RedirectStandardOutput = false; p1.StartInfo.FileName = asProcesses[1]; p1.Start(); StreamWriter sw = p1.StandardInput; sw.Write(xxx); sw.Close()

Celery Task Chain and Accessing **kwargs

十年热恋 提交于 2019-11-30 07:06:32
I have a situation similar to the one outlined here , except that instead of chaining tasks with multiple arguments, I want to chain tasks that return a dictionary with multiple entries. This is -- very loosely and abstractly --- what I'm trying to do: tasks.py @task() def task1(item1=None, item2=None): item3 = #do some stuff with item1 and item2 to yield item3 return_object = dict(item1=item1, item2=item2, item3=item3) return return_object def task2(item1=None, item2=None, item3=None): item4 = #do something with item1, item2, item3 to yield item4 return_object = dict(item1=item1, item2=item2,

How better refactor chain of methods that can return null in java?

与世无争的帅哥 提交于 2019-11-29 10:02:32
I have code like: obj1 = SomeObject.method1(); if (obj1 != null) { obj2 = obj1.method2(); if (obj2 != null) { obj3 = obj2.method3(); if (obj3 != null) { ............ return objN.methodM(); } } } .... I have near 10 steps. It seems very fragile and error prone. Is there a better way to check on null chained methods? Thanks. It's common problem for null references in java. I prefer chaining with && : if (obj1 != null && obj1.method1() != null && obj1.method1().method2() != null) More context is necessary to answer this question well. For example, in some cases I'd advocate breaking out the inner

Celery Task Chain and Accessing **kwargs

孤街醉人 提交于 2019-11-29 07:49:29
问题 I have a situation similar to the one outlined here, except that instead of chaining tasks with multiple arguments, I want to chain tasks that return a dictionary with multiple entries. This is -- very loosely and abstractly --- what I'm trying to do: tasks.py @task() def task1(item1=None, item2=None): item3 = #do some stuff with item1 and item2 to yield item3 return_object = dict(item1=item1, item2=item2, item3=item3) return return_object def task2(item1=None, item2=None, item3=None): item4

(Hadoop) MapReduce - Chain jobs - JobControl doesn't stop

…衆ロ難τιáo~ 提交于 2019-11-29 04:14:48
问题 I need to chain two MapReduce jobs. I used JobControl to set job2 as dependent of job1. It works, output files are created!! But it doesn't stop! In the shell it remains in this state: 12/09/11 19:06:24 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same. 12/09/11 19:06:25 INFO input.FileInputFormat: Total input paths to process : 1 12/09/11 19:06:25 INFO util.NativeCodeLoader: Loaded the native-hadoop library 12/09/11 19

How to store data of a functional chain?

萝らか妹 提交于 2019-11-28 12:51:49
A simple function below: const L = a => L; forms L L(1) L(1)(2) ... This seems to form a list but the actual data is not stored at all, so if it's required to store the data such as [1,2] , what is the smartest practice to have the task done? const L = (a) => { // do somthing return L; }; I would prefer this concise arrow function style, and do not want to destroy the outer structure as much as possible. Surely, I understand some outer structure modification is required, but I am curious what is possible especially in functional style not OO. The specification is simply to store data of the

android parcelable referencing another parcelable circular dependence

痴心易碎 提交于 2019-11-28 10:10:50
Rather simple scenario really, but I could not find anything related on Google so here goes: class ContainerClass implements Parcelable { List<ItemClass> _items; (...) public void writeToParcel( Parcel p, int args ) { p.writeList( _items ); (...) } } class ItemClass implements Parcelable { ContainerClass _containerRef; (...) public void writeToParcel( Parcel p, int args ) { p.writeParcelable( _containerRef ); (...) } } This will inevitably loop and overflow the stack. My question: How am I supposed to deal with a situation where I have to pass an object of the above types through to a new

Nodejs / Q : Chaining promises sequentially

落花浮王杯 提交于 2019-11-28 08:50:47
I want to do something really simple, but i don't understand a little thing ... var Q = require('q'); var funcs = ["first", "second", "third", "fourth"]; function main(){ // really don't know how to chain sequentially here ... var result = Q(); funcs.forEach(function (f) { result = treat(f).then(f); }); } function treat(t){ var deferred = Q.defer(); setTimeout(function(){ deferred.resolve("treated "+ t); },2000); return deferred.promise; } main(); I would like each element of my funcs array to be "treated" sequentially, the output would then be something like : treated first //2 seconds later