Python
This course is made under the direction of Dr. Patrick Fuchs with Amelie Bacle and Caroline Senac in University Paris 7 – Diderot.
This page will contain tips, documents and advises that we can give during lesson.
Tips
MultiProcessing / MultiThreading.
Be careful with that. I saw some group using MultiThreading for their project, but in Python Multithreading is not always well adapted. Most of the time your calculation will take more time. Prefer using MultiProcessing instead of MultiThreading. Check this two links for explanations and example :
- http://eli.thegreenplace.net/2012/01/16/python-parallelizing-cpu-bound-tasks-with-multiprocessing/
- http://www.fevrierdorian.com/blog/post/2012/04/04/Python-multiprocessing-vs-threading (French)
Transform a Windows style textfile to a Unix style textfile
If your program doesn’t work on Unix (you have something like « command not found »). Maybe it’s because the file has a Windows format (for Cariage Return). To convert your file you have several ways :
On Linux:
- If dos2unix is installed :
dos2unix file_windows.txt
-
tr -d '\r' < file_win.txt > file_unix.txt
On windows : you can used notepad ++:
Edit menu -> EOL convertion -> Convert to Unix format
And : Voilà !
Before (Windows format) : | After (Unix format): |
Advices
Module installation
If you want to install locally a python module you can use pip with this command in a shell :
pip install --user [packagename]
You can also apply with method within a script :
try: import mdtraj except: pip.main(['install', '--user','mdtraj')]) import mdtraj
UTF-8 Coding (short method):
If you want to use accent in your comments within your script, add in the script header (juste after the shebang) :
# coding: utf-8