Python Command Line Input Args equivalent to Perl

E

Edward WIJAYA

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
}


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

Thanks so much for your time.
Hope to hear from you again.
 
S

Sam Holden

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top