Skip to content

Tag: python

How do I customize text color in IPython?

I’d like to customize the color of text in IPython, but am not sure how to do it. I know that in Python, I can do this by ending sys.ps1 and sys.ps2 with an ANSI color code such as But the corresponding approach, using PromptManager.in_template, does not work for IPython. For example has no effect on th…

Shared memory in multiprocessing

I have three large lists. First contains bitarrays (module bitarray 0.8.0) and the other two contain arrays of integers. These data structures take quite a bit of RAM (~16GB total). If i start 12 sub-processes using: Does this mean that l1, l2 and l3 will be copied for each sub-process or will the sub-process…

Add SUM of values of two LISTS into new LIST

I have the following two lists: Now I want to add the items from both of these lists into a new list. output should be Answer The zip function is useful here, used with a list comprehension. If you have a list of lists (instead of just two lists):

Cheap mapping of string to small fixed-length string

Just for debugging purposes I would like to map a big string (a session_id, which is difficult to visualize) to a, let’s say, 6 character “hash”. This hash does not need to be secure in any way, just cheap to compute, and of fixed and reduced length (md5 is too long). The input string can ha…

Using sys.exit or SystemExit; when to use which?

Some programmers use sys.exit, others use SystemExit. What is the difference? When do I need to use SystemExit or sys.exit inside a function? Example: or: Answer No practical difference, but there’s another difference in your example code – print goes to standard out, but the exception text goes t…

ImportError: No module named six

I’m trying to build OpenERP project, done with dependencies. It’s giving this error now Could someone guide what’s wrong and how it can be fixed??? Answer You probably don’t have the six Python module installed. You can find it on pypi. To install it: (if you have pip installed, use pi…