Python Command Line Input Args equivalent to Perl

Sam Holden sholden at flexal.cs.usyd.edu.au
Thu Oct 28 02:06:59 EDT 2004


On Thu, 28 Oct 2004 13:43:46 +0800,
	Edward WIJAYA <ewijaya at i2r.a-star.edu.g> wrote:
> Hi,
>
> I am new to Python, and I like to
> learn more about it. Since I am
> used to Perl before, I would like
> to know what is Python equivalent
> of Perl code below:
>
>
> $filename = $ARGV[0];
> open (FILE,"$filename") || die "Can't Open $filename:
> $!\n";
> while<FILE>{ #dealing with it per-lines
>     #process something here
> }

An equivalent python program might be:

	a b

It, like the perl code above, doesn't compile.

Python code which does what the perl code is probably meant to do
could be:

import sys
f = open(sys.argv[1])
for line in f:     #f.readlines() in older pythons
    #process something here, such as:
    print line,


> Also where can I find in any pointer/website
> link ofPerl-Python concordance,
> especially to facilitate Perl conversion to Python.

A dictionary would be of much more use than a concordance,
googling for 

	perl python dictionary

actually gives a match, by pure chance, since what you
really want is a "phrasebook' by the title of the match.

-- 
Sam Holden



More information about the Python-list mailing list