[Tutor] Using contents of a document to change file names, (was Re: how to extract data only after a certain ...)
alan.gauld at btinternet.com
Mon Oct 11 19:12:26 CEST 2010
"Josep M. Fontana" <josep.m.fontana at gmail.com> wrote
> I tried your suggestion of using .split() to get around the problem
> but I
> still cannot move forward.
> fileNameCentury = open(r
You are trying to split the filename not the contents of the file!
> Interestingly I get closer to the solution but with a little twist:
> ['A-01,1374\n', 'A-02,1499\n', 'A-05,1449\n', 'A-06,1374\n',
> 'B-01,1299\n', 'B-02,1299\n', 'B-06,1349\n'...]
> That is, now I do get a list but as you can see I get the newline
> as part of each one of the strings in the list. This is pretty
> weird. Is
> this a general problem with Macs?
No, this is what you would expect. Reading from a file will give you
character, you can use strip() (or rstrip()) to remove it.
Author of the Learn to Program web site
More information about the Tutor