Iterating through list of list

This traverse generator function can be used to iterate over all the values: def traverse(o, tree_types=(list, tuple)): if isinstance(o, tree_types): for value in o: for subvalue in traverse(value, tree_types): yield subvalue else: yield o data = [(1,1,(1,1,(1,”1″))),(1,1,1),(1,),1,(1,(1,(“1”,)))] print list(traverse(data)) # prints [1, 1, 1, 1, 1, ‘1’, 1, 1, 1, 1, 1, 1, 1, ‘1’] … Read more

How to run IPython magic from a script

It depends on which version of IPython you have. If you have 1.x: from IPython import get_ipython ipython = get_ipython() If you have an older version: import IPython.core.ipapi ipython = IPython.core.ipapi.get() or import IPython.ipapi ipython = IPython.ipapi.get() Once that’s done, run a magic command like this: ipython.magic(“timeit abs(-42)”) Note: The script must be run via … Read more

How to resolve URLError:

The error code 10060 means it cannot connect to the remote peer. It might be because of the network problem or mostly your setting issues, such as proxy setting. You could try to connect the same host with other tools(such as ncat) and/or with another PC within your same local network to find out where … Read more