At this stage of the lecture, you are now equipped to write more complex scripts and algorithms. You know everything you need to know about the syntax (almost ;-)), but you might be a little lost in all the possibilities the language is now offering to you. Which tool should I use to do this and that? How was this function signature again? This chapter will briefly give you some tips to help you out during your assignments.
You may have read this expression ("batteries included") during your research about the Python language. It is widely used to indicate that if you choose python, it's not only for it's syntax: it is for all the tools that come with it. And there are PLENTY.
Spend a minute or two to scroll through the list of tools available in the standard library. The standard library is available per default with any python installation. It is very robust and provides the core functionality of the language.
As you will see, there is not much for us scientists in this list though. This is why third party packages were developed. And there are so many of them that one can easily be overwhelmed: for this week's assignment we will use the standard library only.
In order to become a good programmer, nothing is more important than being able to find help, either online or with your friends and colleagues.
Fortunately, getting help has become quite easy nowadays. Here are some resources to get you started:
Here is a general rule. When you encounter a problem, ask yourself the following question: is it likely that someone else had this problem before me? In a large majority of the cases, the answer will be "yes" (believe me on this one). The trick is to find the answer to your question: use as few words as possible, but put in all the keywords that makes your question unambiguous. Here is the example outcome of two google searches:
The latter is the one you want and will lead you to the right answer. With time, you are going to get used to using the search engine more efficiently, but if everything else fails, then you might have to as ask a question yourself.
If you want to ask a question on stackoverflow or somewhere else (e.g. by sending an email at your teacher), please spend some time reading this resource. Believe me, this will help you to get better answers!
I'll make a confession: without an internet connection, I am a very bad python programmer. And I don't expect you to learn all the python commands by heart and solve the assignments without online help. However, there is a difference between "getting help to find how to realize a specific task" and "asking for someone to do my homework for me". The border between the two might be subtle, but I'm sure you'll know when you cross it: at the moment you stopped to use your brain and simply copy/pasted code from one site to your assignment script, you crossed it.
While it is possible to write python programs using a basic text editor, the majority of you will find it useful to use an integrated development environment (short: IDE) instead. The advantages of IDEs is that they ship with tools that make your life easier when programming. Here is a non-exhaustive list of the tools a good IDE should have:
There are many Python IDEs, but here are some of the ones that come up most often as recommendations on forums or blogposts:
$ spyder &
). It is my recommended IDE for this semester's course.Back to the table of contents, or jump to this week's assignment.