[Tutor] String switch

Alan Gauld alan.gauld at btinternet.com
Thu Oct 6 10:56:55 CEST 2011

On 05/10/11 22:51, Christopher King wrote:
> There is a program that will open another program, write code at the top
> of the program. The code at the top will cause the program to print all
> strings afterwards in swap case.

If I understand this correctly you have  mainprog.py and subprog.py.
And you want mainprog.py to modify subprog.py such that when you run 
subprog.py it swaps case of the output?

An easier way to achieve that would be to write a program that simply 
translates its input into a swapcased output. Then you can redirect the 
output of subprog.py into that program:

python subprog.py | python swapcase.py

Now, the fact that these are two python scripts rather than executables 
complicates things slightly so you probably need to experiment with the 
shell syntax to make it work, but that would be my approach.

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list