Newbie Questions: Swithing from Perl to Python

Harry George harry.g.george at boeing.com
Mon Oct 27 03:00:15 EST 2003


"Luther Barnum" <SpamSucks at rr.com> writes:

> 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.
> 
> 

Like most perl-to-python migrants, yoiu are still thinkiing in perl.
Here is a module to show how to do the std sorts of things:
http://www.seanet.com/~hgg9140/comp/pyperlish-1.2/doc/manual.html
available at:
http://www.seanet.com/~hgg9140/comp/index.html


-- 
harry.g.george at boeing.com
6-6M31 Knowledge Management
Phone: (425) 342-5601




More information about the Python-list mailing list