Newbie asks(2): How to do this line of C in Py?

Peter Hansen peter at engcorp.com
Wed Jul 11 15:19:48 CEST 2001


Joe Potter wrote:
> 
> On 10 Jul 2001 20:29:23 -0400, David Bolen <db3l at fitlinxx.com> wrote:
> 
> >"Steve S.L. Wong" <sailwong at alumni.cuhk.edu.hk> writes:
> >
> >> if sscanf(command,"%c%d",&c,&d) != 2 {
> >> }
> >
> >You seem to be posting a lot of one line translation requests - are
> >you trying to get a program translated to Python one line at a time?
> >
> >If so, perhaps you could just post the whole thing and we'd have a
> >shot at it in one pass and save some electrons :-)
> 
> I have followed these questions with great interest. I hope he keeps asking for a
> while --- and folks here keep answering.
> 
> As a newbie to Python, I find that the one liners in c are easy to follow and the
> translation into Python show me where I am missing Python techniques.
> 
> My purpose in writing this is simply to say you are not just helping Mr. Wong when
> you respond.

Good point, Joe.  My slightly boorish response failed to consider that fact.

On the other hand, posting obscure one-liners from C is not necessarily
the best way to learn much, if anything about Python.  Context is always
useful, and the response might be different if more of the original
C code were made available.  I think this is similar to an attempt
to translate from one spoken language into another, one word at a time,
which looks like it works for a while but doesn't withstand serious
scrutiny.

(As it stands, Steve kindly wrote to me off-line and mentioned he was
attempting to port GnuGo from C to Python as a learning exercise.  If
we want "context" we can always go look at the source ourselves. :-)

Joe (and other self-professed newbies), why don't you find some other
interesting one-liners (or two, or three-liners) and post them here?

Maybe the code base for GnuGo is not one of the best sources of example
code for conversion to Python...  Based on a sample size of three,
it consists of 33% strtok() calls and 67% sscanf() calls, making it
one of the all-time poorest C programs! ;-)

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list