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…
Tag: python
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…
How to convert unicode accented characters to pure ascii without accents?
I’m trying to download some content from a dictionary site like http://dictionary.reference.com/browse/apple?s=t The problem I’m having is that the original paragraph has all those squiggly lines, and reverse letters, and such, so when I read the local files I end up with those funny escape charac…
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…
Django – referencing static files in templates
I’m having difficulty referencing static files in my templates. I am using Twitter Bootstrap and have the bootstrap files (css, img, js) sitting at mysite/static. I have set the STATIC_URL, STATIC_ROOT and TEMPLATE_CONTEXT_PROCESSORS according to this tutorial. I have run ./manage.py collectstatic which…
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…
How to import a globally installed package to virtualenv folder
So I have a virtualenv folder called venv for my python project. I can run: Which installs all requirements I need for the project except one, M2Crypto. The only way to install it is through apt-get: How can I then add this package installed through apt to venv folder? Answer What I did after all:
(Python) ValueError: Program dot not found in path
I have the following problem: I am on xUbuntu OS and I am trying to use networkx in a Flask application, and I am having the following code: The last line is line 411. I get the following error: What could be causing this problem? I’ve installed networkx and pygraphviz, but I still get this error. Any i…
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…