Python Command Line Input Args equivalent to Perl

Discussion in 'Python' started by Edward WIJAYA, Oct 28, 2004.

  1. 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
     
    Edward WIJAYA, Oct 28, 2004
    #1
    1. Advertising

  2. Edward WIJAYA

    Sam Holden Guest

    On Thu, 28 Oct 2004 13:43:46 +0800,
    Edward WIJAYA <-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
     
    Sam Holden, Oct 28, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Varn
    Replies:
    2
    Views:
    658
    Ken Varn
    Jun 22, 2005
  2. Replies:
    3
    Views:
    540
    David Eppstein
    Sep 17, 2003
  3. Pierre Fortin

    args v. *args passed to: os.path.join()

    Pierre Fortin, Sep 18, 2004, in forum: Python
    Replies:
    2
    Views:
    753
    Pierre Fortin
    Sep 18, 2004
  4. er
    Replies:
    2
    Views:
    543
  5. Andrew Tomazos
    Replies:
    5
    Views:
    635
Loading...

Share This Page