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

Joe Potter jm7potter at hotmail.com
Thu Jul 12 12:57:59 CEST 2001


On 11 Jul 2001 15:46:11 -0400, David Bolen <db3l at fitlinxx.com> wrote:

>Joe Potter <jm7potter at hotmail.com> writes:
>
>> 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.
>
>There is, however, a risk in this technique as a single line
>translation from another language to Python is often a bit too fine
>grained to really serve as a good guide for translation, especially
>from a language such as C.  The two languages do not necessarily
>provide the same functionality per line of code so you risk force
>fitting the translation since you don't have any surrounding context.
>

This is absolutely true.

>
>In these cases so far, it's largely been translating a C library call
>into Python library calls so the one-to-one holds better than usual,
>but I do think that even newbies will be able to get a better grasp of
>the concepts with slightly larger code snippets.  E.g., what you use
>strtok or sscanf in a C program for, you might attack quite
>differently in a Python program, even if direct translations of strtok
>and sscanf exist.  (Then again, you might use the direct translation,
>but making that choice is assisted by more original context).
>

This was my point. Most examples here are of a "better" nature, so a few
one-liners did not hurt any. In fact, it was some fun.

On the other hand, I fully expect that anything I do in Python should be different
from C --- as different as going from assembler to C was back then.

There is a post on the ng today where a fellow relates fixing a newbie's code that
was 100 lines and done in C idiom (python language, of course) with 6 lines that ran
much faster. This is what I would expect.

I just want to know the other ways also.
 

>Note I'm certainly not proposing that such requests not be answered,
>nor that they can't be helpful, but only that I think more benefit
>could be gained (by the original poster as well as other readers) with
>some addition information and/or sample code in the translation
>requests.
>

No argument.

>But c.l.p is certainly one of the best communities in which I've
>participated in this regard - we'll answer just about anything as well
>as possible (even while suggesting better ways to phrase the questions
>

There is a great group of folks here. The worst flame that I have seen would not keep
me warm in winter --- even here in Orlando!

Regards, Joe



More information about the Python-list mailing list