[Edu-sig] Python @ Education: What are your problems?

Catherine Letondal letondal@pasteur.fr
Fri, 07 Jun 2002 15:35:00 +0200


Ingo Linkweiler wrote:
> What do you like when teaching python?

My answers are related to the course that my colleague Katja announced
yesterday - http://www.pasteur.fr/recherche/unites/sis/formation/python/.

The course is intended for bioinformaticians, most of them having learnt either perl, C 
or Scheme. The last time we taugth this course, it was a 5 half-days course (we did 
not have the time to do the whole course contained on the support, which would need
at least 1 full-time week).


------------------------------------------
> - Lists, Tupels, Dictionaries included
------------------------------------------

This is very important in bioinformatics. You have to manipulate strings, lists
and dictionaries all the time. Biomolecules are indeed represented as string of 
characters: 'atgaagattttgatacttggtatttttctgtttttatgtagtacccc' but you spend your time
converting them into lists or and back into string, etc, ...
Also, the possibility to define the [] operator with
__getitem__ is fantastic. In Biopython (www.biopython.org), they have
defined dictionaries for all big genomic databases, so that by issuing a:
GenBank['HUMCERP'] you fetch a db record from the Web server of the NCBI...

Just one detail which makes things a little difficult. As I said, one very often has
to change strings into lists and back to string in bioinformatics. 

To our knowledge, the only way to do this is with a type converter:
	l = list(s)
then to get the list back (why is it that join is in strings and not in lists?):
	string.join(l)

I don't know how to make this easier, but the difficulty seems to be in the fact that 
there are both object methods (join) and operators (len(), list(), str(),...).
A solution could be to have some syntactic sugar to call the operator when the 
function is called as a method, e.g:
	l = s.list()
would call list(s), or at least, the split method should accept "" separator:
	l = s.split("")
which outputs:
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: empty separator

------------------------------------------
> - interpreter: Everything can be tested
------------------------------------------

This is very important!

Some problems in the interpreter:

- copy&paste of several lines sometimes does not work

- the interpreter should accept a command not exactly beginning at the exact position:
>>> command
when it's a single command. When you enter (by cut&paste)
>>>command
or:
>>>   command
it does not work.
I know it is related to the indentation problem, but for a beginner who already has
difficulties, this is a cause of additional problems (ideally, a workspace as in 
Smalltalk would be marvellous - I haven't seen such thing in IDLE?).

Other suggestions:

- the interpreter could keep an history of the commands *between* sessions. Every one
does this: entering python, trying a module, exiting, re-entering python, re-trying...

- the history could be at first indentation level. I.e, if you enter the 
definition of a whole function in the interpreter, doing a "previous command" 
with the arrow key should return the whole definition, as an editable buffer.

[To give an example, I have built an [not exactly End-] User programming tool with and
editor that you can use to redefine, save, print, debug, run, etc... a method,
without saving it in a file - it's to program in XOtcl (www.xotcl.org) - see:
http://www.pasteur.fr/~letondal/biok/Images/method-editor.gif]

------------------------------------------------------------------------------------
> AND MORE IMPORTANT:
> What are your problems with python? Are pupils/students having any
> problems or often asked questions?

One big problem is the confusion between module names and inner component names.
For instance, when you define a module in a file, say, Dna.py, which defines a
class Dna, you have to do a:
from Dna import Dna
if you want to create Dna objects with: dna = Dna()
or you have to say: dna = Dna.Dna()

I know this is completely coherent, and we spent as much time as needed until they
understood the mechanism, but this was really a major difficulty.

> What do you dislike at python?

I like very much Python for clean and simple object-oriented programming. What I 
dislike:
	- self being mandatory in parameters list
	- no super() method call to call to super-class (AFAIK)
	- incremental and dynamic definition of class methods (I know you can 
	do this by modifying the dictionary)

(items which are probably already in a FAQ)

--
Catherine Letondal -- Pasteur Institute Computing Center
http://www.pasteur.fr/~letondal