[Tutor] String switch
bob gailer
bgailer at gmail.com
Thu Oct 6 17:38:52 CEST 2011
On 10/5/2011 5:51 PM, 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.
What you've told us so far may make total sense to you, but it is not
enough information for us to act on.
We need (at least) an example of a program that you want to modify.
From that we /might /be able to tell what you mean by "print" and "all
strings".
I can hear you now "what's the matter with these guys - what part of
print and strings do they not understand?".
Humor us. It is not a lack of understanding. "print and strings" have(to
me) multiple meanings.
Currently we are guessing, as Alan has done, and we may be way off the
mark. Guessing takes extra time and energy.
Having said that I will offer an alternative guess: assuming you are
using Python 3 and you are using the built-in print function to "print
strings", then you could redefine print by ading (at the top) (untested):
def print(something, **args): __builtins__.print(something.swapcase(),
**args)
You can't do this with Python 2, as print is a statement and can't be
redefined. You could alter the program - find all occurrences of "print"
used as a statement, and replace them with a function call. So
print "asdf" would become swapprint("asdf")
and at the top you'd add (untested):
def swapprint(something): print something.swapcase()
--
Bob Gailer
919-636-4239
Chapel Hill NC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111006/bca30433/attachment.html>
More information about the Tutor
mailing list