Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python Command Line Input Args equivalent to Perl

Reply
Thread Tools

Python Command Line Input Args equivalent to Perl

 
 
Edward WIJAYA
Guest
Posts: n/a
 
      10-28-2004
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.

--
Regards,
Edward WIJAYA
SINGAPORE
 
Reply With Quote
 
 
 
 
Sam Holden
Guest
Posts: n/a
 
      10-28-2004
On Thu, 28 Oct 2004 13:43:46 +0800,
Edward WIJAYA <> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
forwarding Args&&... vs forwarding Args... Andrew Tomazos C++ 5 01-05-2012 11:15 PM
C++0x -- fun(Args&...) and fun(Args const&...) er C++ 2 12-20-2010 07:52 PM
Is there a class or method to construct url args or extract url args? Ken Varn ASP .Net 2 06-22-2005 12:26 PM
args v. *args passed to: os.path.join() Pierre Fortin Python 2 09-18-2004 06:59 PM
When passing functions as args,how to pass extra args for passed function? python@sarcastic-horse.com Python 3 09-17-2003 12:25 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57