change the first character of the line to uppercase in a text file
wong_powah at yahoo.ca
Sat Jun 27 03:58:27 CEST 2009
On Jun 26, 4:51 pm, Chris Rebert <c... at rebertia.com> wrote:
> On Fri, Jun 26, 2009 at 12:43 PM, powah<wong_po... at yahoo.ca> wrote:
> > How to change the first character of the line to uppercase in a text
> > file?
> > e.g.
> > input is:
> > abc xyz
> > Bd ef
> > gH ij
> > output should be:
> > Abc xyz
> > Bd ef
> > GH ij
> 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. `afile`
> is the file object and `line` gets assigned each line in turn.
> `s[x]` gets you the (x+1)-th character in the string `s` (e.g.
> "abcd" --> "c")
> And here are the docs on working with files:http://docs.python.org/library/functions.html#openhttp://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:
More information about the Python-list