[Tutor] What kind of approach
Alan Gauld
alan.gauld at btinternet.com
Tue Mar 27 19:22:22 CEST 2007
"Utkarsh Tandon" <utkarsh.tandon at gmail.com> wrote
> Alan Gauld wrote:
>> Thats a very long winded and difficult way to do a fairly simple
>> Python task. Don't try to write Python like a C programmer.
>
> I'm really new to python. And I don't have much experience in
> programming either
Ok, My mistake. The code you had was very like the way
experienced C programmers typically start using Python;
as if it was C. That's not a good way.
> what kind of approach should I have when coding programs
> in Python ?
Python is often described as coming "with batteries included"
This is because of the 100 plus modules in the standard library
that provide tools to do most things more easily. The Pythonic
approach is to leverage those modules, plus the higher level
data structures within Python to maximum advantage.
The best solution for stripping C comments is probably to
use a re module's regular expressions. Define a regex that
matches a C comment, then replace all occurrences of the
regex with an empty string. Of course defining the regex
can be a challenge in itself, but it's a different challenge! :-)
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list