On Fri, 26 Jun 2009 18:58:27 -0700 (PDT), powah <wong_po...@yahoo.ca> wrote:
>On Jun 26, 4:51 pm, Chris Rebert <c...@rebertia.com> wrote: >> On Fri, Jun 26, 2009 at 12:43 PM, powah<wong_po...@yahoo.ca> wrote: >> > How to change the first character of the line to uppercase in a text >> > file? >> > [...] >> >> We're not in the business of doing homework. Some hints though: >> >> `s.upper()` converts the string in variable `s` to all upper case >> (e.g. "aBcD".upper() --> "ABCD") >> `for line in afile:` iterates over each line in a file object. >> [...] >> >> And here are the docs on working with files: >> http://docs.python.org/library/functions.html#open >> http://docs.python.org/library/stdtypes.html#file-objects >> >> That should be enough to get you started. > >Thank you for your hint. >This is my solution: >f = open('test', 'r') >for line in f: > print line[0].upper()+line[1:], I know this is homework, so I didn't want to say anything (especially as I'm a newcomer, also just starting to learn the language), but it seems OK to mention that if you hunt around some more in the standard library documentation, you'll find an even shorter way to write this. -- Angus Rodgers -- http://mail.python.org/mailman/listinfo/python-list