Newbie Questions: Swithing from Perl to Python

Luther Barnum SpamSucks at rr.com
Sat Oct 25 20:34:23 EDT 2003


I am a new Python programmer and I am having a few difficulties. I love Perl
and I am just trying to learn Python because it is used heavily at work. It
looks pretty cool so I am diving in. I'm sure they are easy but I not sure
how to proceed.

1. How can I run a program and modify the output on the fly then send it to
standard output.

Example in Perl:

ex. open(LS_PIPE, "/usr/bin/ls |");
     while(<LS_PIPE>) {
     s/this/that/g;
     print;
     }
     close(LS_PIPE);


2. How can I sort and print out a hash.

Example in Perl:

ex. foreach $string (sort keys %hash) {
     print("$string = $hash{$string}\n");
     }

In Perl these are very easy tasks, but I am finding it a little difficult to
understand.






More information about the Python-list mailing list