Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Awk to Python Converter?

1,270 views
Skip to first unread message

Folkert Janssen [Chemie]

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

Hi folks!

I expected this to be an FAQ but i did not find any hint
towards that anywhere.

So, is there something like an awk (or gawk) to python
converter, i.e. a programm that reads in awk code and
spits out a py file?
The only thing I was able to find was awk.py some routines
that enables You to write awk-like python code.

THank You very much in advance.
--Folki
jan...@rhrk.uni-kl.de

Christian Tismer

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

Folkert Janssen [Chemie] wrote:
>
> Hi folks!
>
> I expected this to be an FAQ but i did not find any hint
> towards that anywhere.

This seems natural to me. AWK is much more related to the Perl
world than to Python, and I assume it would be also much
easier to move AWK code to Perl.

Please, for heaven's sake, don't anybody start a discussion
about Perl now!

I just want to say that AWK belongs to the roots of Perl
and not of Python.

> So, is there something like an awk (or gawk) to python
> converter, i.e. a programm that reads in awk code and
> spits out a py file?

Although I would find this quite handy, and although I spent years in
writing AWK code, I do not recommend to implement this.

Afterall I changed to Python, because I wanted to get rid of problems
like global variables which bear all kinds of traps for you, implicit
conversion between strings and numbers, concatenation using white space,
this is all ok for very short programs.

But now: Nobody needs an AWK converter for very short programs, since
you can rewrite it as you read it.
On the other hand, if there is much AWK code and it is converted to
Python, then you have the same ugly things. You have to tweak Python
to accept all kinds of sloppy style. For that reason, I didn't write
a converter, but rewrote my AWK crap.

*******

Another thought: What really would help would be a module which
prepares AWK code to be easily editable for Python. ALso a little
support module for the most needed AWK functions would be helpful
to migrate AWK scripts. Bad concepts like global variables could
be flagged and prepared in a way that you *must* change the code.

Any ideas, would this make sense?

For short: I propose a migration helper, *no* converter since converted
code is at least as bad as the original.

- pirx

--
Christian Tismer :^) <mailto:tis...@appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101 : *Starship* http://starship.skyport.net
10553 Berlin : PGP key -> http://pgpkeys.mit.edu
we're tired of banana software - shipped green, ripens at home

Janko Hauser

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

Ah, haven't looked into the details, but a mix of a converter and a
migration handler is available from David Ascher at starship.

http://starship.skyport.net/~da/

__Janko
--
Institut fuer Meereskunde phone: 49-431-597 3989
Dept. Theoretical Oceanography fax : 49-431-565876
Duesternbrooker Weg 20 email: jha...@ifm.uni-kiel.de
24105 Kiel, Germany

Christian Tismer

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

Janko Hauser wrote:
>
> Ah, haven't looked into the details, but a mix of a converter and a
> migration handler is available from David Ascher at starship.
>
> http://starship.skyport.net/~da/

Right, I know this. But this is rather a toy interpreter which acts
a bit like AWK than a converter. It brings some AWK-like functions to
you and adopts some concepts but has no associative arrays. These
play a central role in AWK and would be the first thing to bring into
a PyAWK runtime library. This feature would be the hardest to be ripped
out and replaced by a different Python structure, therefore I would
start with that.

I think we can use some concepts, but I wouldn't build upon it but
start over.

David Ascher

unread,
Mar 3, 1998, 3:00:00 AM3/3/98
to

> Ah, haven't looked into the details, but a mix of a converter and a
> migration handler is available from David Ascher at starship.
>
> http://starship.skyport.net/~da/

Nope, the original poster had a better description of awk.py -- it's
really just a tool to allow you to write awk-style Python scripts. It
makes no attempt at converting anything to anything else.

--david


Folkert Janssen [Chemie]

unread,
Mar 4, 1998, 3:00:00 AM3/4/98
to

In article <34FC5724...@appliedbiometrics.com> you wrote:
: [...] but has no associative arrays. These

: play a central role in AWK and would be the first thing to bring into
: a PyAWK runtime library.

At the first glance they could be replaced by dictionaries using
ASCII representations of lists as arguments, like in this line

bugaboo = { `i,k,l`: "foobar", `'boo'`: 2.17}

So it seems that the many many internal type conversion done by gawk
are the core problem.


-- Folki

Folkert Janssen [Chemie]

unread,
Mar 4, 1998, 3:00:00 AM3/4/98
to

Christian Tismer (tis...@appliedbiometrics.com) wrote:

: Although I would find this quite handy, and although I spent years in


: writing AWK code, I do not recommend to implement this.

: Afterall I changed to Python, because I wanted to get rid of problems
: like global variables which bear all kinds of traps for you, implicit
: conversion between strings and numbers, concatenation using white space,
: this is all ok for very short programs.

Ciao Christian!

Well, I think everybody that turns from AWK to Python does it for those
very reasons. Of course the best thing would be to rewrite them, but I
take the point of view, that this is done best starting from an equivalent,
though ugly, py-program.

--Folki

Christian Tismer

unread,
Mar 4, 1998, 3:00:00 AM3/4/98
to

> At the first glance they could be replaced by dictionaries using
> ASCII representations of lists as arguments, like in this line
>
> bugaboo = { `i,k,l`: "foobar", `'boo'`: 2.17}

Right. I did it this way, also added spcialities like choosable
sorting order (which is undefined, I know) which was introduced
by Thompson AWK. It will be also possible to to some sort of
analysis with this datatype, i.E. automatically finding out for given
data, if the assoc array was needed in that sense, or if a simple
array would work. Many constructs used in AWK are only used because
you have no choice. But integer-indexed arrays should be identifiably
rather easily.

I'm working - pirx

0 new messages