Manyfile Processing
Peter Otten
__peter__ at web.de
Fri Dec 4 10:42:59 EST 2009
user at domain.invalid wrote:
> On 12/04/2009 12:58 PM, Dan Sommers wrote:
> > On Fri, 04 Dec 2009 10:00:53 +0200, user wrote:
> >
> >> sorry if i bother you with a beginners question but i have an issue
> >> with processing a bunch of files. They are some arithmetic lists the
> >> processing of one file is an easy task but how do i process many files?
> >> I tried reading that files in to a list and looping over the list
> >> elements but the function won't accept any arguments other than a
> >> string.
> >
> > Maybe the fileinput module can help.
> >
> > Dan
> >
>
> Hi,
>
> seems like the fileinput module works fine for me though i am having
> quite an issue with the paths.
>
> if i do:
>
>
> something = fileinput.input("/some/absolute/path/to/list/file.txt")
> #the text file contains absolute paths
> for line in something:
> data=scipy.io.array_import.read_array(line)
> print data
>
> it claims that the paths given in the textfiles don't exist "no file or
> directory" though taking one entry from the textfile and inserting it
> directly to the command does its job...
>
> Any idea?
line includes a trailing newline. You can see that if you modify your code
to
for line in something:
print repr(line)
Use
line = line.strip()
to remove the newline (in fact all leading and trailing whitespace).
Peter
More information about the Python-list
mailing list