[Tutor] Question on a example in the book "Learn to program usingpython" by Alan Gauld

Alan Gauld alan.gauld at blueyonder.co.uk
Tue Aug 3 00:41:15 CEST 2004


> Sorry to bother you guys again with a few more "stupid" questions
> more, just so i understand everything correct.
>
> 1. that there is nothing in this program that "senses" which type
> of file i pass as a parameter?

Nope, the computer is too stupid to know the difference, it just
sees a file full of characters, it has no idea what those
characters mean, the programmer must provide that intelligence.

To the computer a python program file and an html file are
both just plain text files. Windows explorer as an application
has a notion of the diffrence, but really thats just detecting
the file ending and comparing with a database of such endings
in the Windows registry - exactly the kind of thing you would
need to write but on a bigger scale.

> 2. that if you want to analyse a .txt file instead of a .html file,
> you change the last bit from "D = HTMLDocument(sys.argv[1])" to
> "D = TextDocument(sys.argv[1])"?

Correct, either that or you write the extra code to detect
which kind of file it is and select the document type accordingly.
Thats one advantage of the GUI solution - it has a toggle box to
allow the user to select at run time.

Alan G.



More information about the Tutor mailing list