[Tutor] upper and lower case input for file name

Tiger12506 keridee at jayco.net
Sat Dec 15 19:14:25 CET 2007


> "earlylight publishing" <earlylightpublishing at yahoo.com> wrote
>
>>I don't know if this'll help or not but I just learned about this:
>>
>>  file = raw_input(info).lower
>
> file = raw_input(prompt).lower()     # note the parens!
>
>>  The .lower is supposed to convert any input to lower case.
>
> It will indeed. There is also an upper() if you want to make it
> uppercase instead.

And not just input either. All strings have this method. (just for those who 
are not aware)
>>> a = "JaCoB"
>>> a.lower()
"jacob"
>>> a.upper()
"JACOB"
>>> dir(a)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', 
'__
ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', 
'__g
t__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', 
'__mul__
', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 
'__rmod__', '
__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 
'decode',
'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 
'isdi
git', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 
'lst
rip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 
'rsplit'
, 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 
'title', '
translate', 'upper', 'zfill']
>>>

Just look at all the possibilities! ;-) 



More information about the Tutor mailing list