[Tutor] String switch

bob gailer bgailer at gmail.com
Mon Oct 3 07:32:10 CEST 2011


On 10/2/2011 8:33 PM, Christopher King wrote:
> Dear Tutors,
>     I was wondering how one would make it so all the cases of all the 
> strings in a python file where switched. I know that 
> for individual strings, you can use .swapcase(), but I'm making a 
> program to edit others, so it would be easier to just do something at 
> the top that would switch all other strings.

This is (to me) vague. What do you mean by "at the top" and "all other 
strings"?

Other than that I interpret: given a file xxx.py switch case of every 
character in every character string in the file."

This requires reading the file into a string, then searching it for the 
start of a string, the end of that string, then applying swapcase() to 
to the string between the start and end delimiters the, writing out the 
result.

Recall that string delimiters include " ' """ and ''' and that \" and \' 
are escaped and therefore not delimiters.

Write a program that attempts to meet these requirements, show it to us, 
tell us that is succeeds or where it fails and let's go from there.

-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list