f



C/C++, Perl, etc. to Python converter

Is there a Perl to Python converter?
Or in general: a XY to Python converter?

Is see, that Python is much better then Perl anyway.
But for beginners, they whant to konw how is this done with Python etc.

Sure, there are some docus out there in the internet. But a converter?
0
1/3/2007 3:36:18 PM
comp.lang.python 77058 articles. 6 followers. Post Follow

10 Replies
577 Views

Similar Articles

[PageSpeed] 5

mm wrote:

> 
> Is there a Perl to Python converter?
> Or in general: a XY to Python converter?
> 
> Is see, that Python is much better then Perl anyway.
> But for beginners, they whant to konw how is this done with Python etc.
> 
> Sure, there are some docus out there in the internet. But a converter?

Nope. Different languages have different idioms, translating them to each
other - while technically possible, at least to some extend - won't result
in anything that a human being can work with.

Diez
0
deets (3351)
1/3/2007 3:53:22 PM
I don't know of a converter, one may exist. I have seen similar
requests though and will give you a similar response to what I have
seen. A converter, if it exists, may be able to produce working code
but _not_ readable code. Python is a language whose strength comes
from, among other things, its readability and conventions. Learning
python is best done by using the online documentation
(http://docs.python.org/tut/tut.html) and reading existing code (take a
look at the built in modules).

My biggest fear of teaching someone to program by using a program to
convert perl to python is that they will end up writing python that
still looks like perl.

I don't know if it helps, but I know others will give you similar
advice.

-Matt

0
mccredie (321)
1/3/2007 3:53:49 PM
Yes, I konw what you mean. And thats the right way to do it - for 
beginners. --But not for someone who allready know programmings things 
for many years.

They ask themself: How can I do this in Python? I can remember, it was 
that-way with Perl or C or C++ or whatever.

So, not only a ververter can be useful, also a translation table.
(Maybe just a table for print out.)

LangX <-> LangY



Matimus wrote:

> I don't know of a converter, one may exist. I have seen similar
> requests though and will give you a similar response to what I have
> seen. A converter, if it exists, may be able to produce working code
> but _not_ readable code. Python is a language whose strength comes
> from, among other things, its readability and conventions. Learning
> python is best done by using the online documentation
> (http://docs.python.org/tut/tut.html) and reading existing code (take a
> look at the built in modules).
> 
> My biggest fear of teaching someone to program by using a program to
> convert perl to python is that they will end up writing python that
> still looks like perl.
> 
> I don't know if it helps, but I know others will give you similar
> advice.
> 
> -Matt
> 
0
1/3/2007 4:05:19 PM
mm wrote:
> Is there a Perl to Python converter?
> Or in general: a XY to Python converter?
>
> Is see, that Python is much better then Perl anyway.
> But for beginners, they whant to konw how is this done with Python etc.
>
> Sure, there are some docus out there in the internet. But a converter?
I don't know of any converter, but I have seen a number of tutorials
that show how to do OO things in both perl and python for example.
Avi Kak of Purdue U. has one such tutorial.
When I took his class, he had a large package of notes that he said was
the basis for his next book.  It doesn't look like he ever got around
to publishing that one.
However, if you google his homepage, he does have at last one tutorial
posted for Perl vs. Python.

0
1/3/2007 4:18:47 PM
Matimus schrieb:
> I don't know of a converter, one may exist. I have seen similar
> requests though and will give you a similar response to what I have
> seen. A converter, if it exists, may be able to produce working code
> but _not_ readable code. Python is a language whose strength comes
> from, among other things, its readability and conventions. Learning
> python is best done by using the online documentation
> (http://docs.python.org/tut/tut.html) and reading existing code (take a
> look at the built in modules).
> 
> My biggest fear of teaching someone to program by using a program to
> convert perl to python is that they will end up writing python that
> still looks like perl.
> 
> I don't know if it helps, but I know others will give you similar
> advice.
> 
> -Matt
> 

I think that it *is* possible to do it, but a whole lot of work had to
be done to achieve this. It is all about how many rules (like how to
convert this block of unreadable code of language X into a readable
python block) you are willing to find/program (and these are a lot). It
is a almost gigantic task to make this work proper, but it definitely
*is* possible.

Something like this doesn't exist yet, but people (especially
Computational Linguists) are working on this.

Thomas
0
1/3/2007 4:29:00 PM
> 
> I think that it *is* possible to do it, but a whole lot of work had to
> be done to achieve this. It is all about how many rules (like how to
> convert this block of unreadable code of language X into a readable
> python block) you are willing to find/program (and these are a lot). It
> is a almost gigantic task to make this work proper, but it definitely
> *is* possible.

It is definitely _not_ possible. There are so many design decisions that 
are differing based on what a language offers - e.g. generators, garbage 
collection, precise control over memory layout and so on.

Projects like jython or ironpython show that to some degree at least 
binary compatibility is feasible - but beyond that, machine generated 
cod will always be that, and by no means idiomatic.

Diez
0
deets (3351)
1/4/2007 1:52:07 AM
Diez B. Roggisch wrote:
> 
>>
>> I think that it *is* possible to do it, but a whole lot of work had to
>> be done to achieve this. It is all about how many rules (like how to
>> convert this block of unreadable code of language X into a readable
>> python block) you are willing to find/program (and these are a lot). It
>> is a almost gigantic task to make this work proper, but it definitely
>> *is* possible.
> 
> 
> It is definitely _not_ possible. There are so many design decisions that 
> are differing based on what a language offers - e.g. generators, garbage 
> collection, precise control over memory layout and so on.

    Inter-language translators have been written.  There's usually
a performance penalty, which can be severe when the idioms of
the languages are quite different.

    Perl to Python translation might be worth doing.  The
languages have quite different syntax, but roughly the same
functionality.  You'd probably have to write a set of libraries
in Python with the equivalent definitions to their Perl
counterparts, but that's just time-consuming, not difficult.

				John Nagle
0
nagle (1119)
1/4/2007 8:06:48 AM
mm wrote:

> Is there a Perl to Python converter?
> Or in general: a XY to Python converter?
>
> Is see, that Python is much better then Perl anyway.
> But for beginners, they whant to konw how is this done with Python etc.
>
> Sure, there are some docus out there in the internet. But a converter?
Try this page:
http://wiki.python.org/moin/PerlPhrasebook

- Paddy.

0
paddy3118 (377)
1/5/2007 8:06:43 AM
>> It is definitely _not_ possible. There are so many design decisions 
>> that are differing based on what a language offers - e.g. generators, 
>> garbage collection, precise control over memory layout and so on.
> 
>    Inter-language translators have been written.  There's usually
> a performance penalty, which can be severe when the idioms of
> the languages are quite different.

The point discussed here was not the feasibility of language-translators 
per se. These are certainly possible, yet I doubt that e.g. C++2Python 
would really come to existence.

Thomas expressed his belief that a _idiomatic_ translator was possible. 
And that certainly isn't the case.

Diez
0
deets (3351)
1/5/2007 8:11:28 AM
mm wrote:
> 
> Is there a Perl to Python converter?
> Or in general: a XY to Python converter?
> 
> Is see, that Python is much better then Perl anyway.
> But for beginners, they whant to konw how is this done with Python etc.
> 
> Sure, there are some docus out there in the internet. But a converter?

Maybe this can help in converting from prel to python:
http://www.crazy-compilers.com/bridgekeeper/

Uwe
0
news5853 (30)
1/5/2007 2:30:10 PM
Reply: