Manyfile Processing

U

user

Hey,

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.

I would appreciate if you could help me.
 
D

Diez B. Roggisch

Hey,

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.

I would appreciate if you could help me.

for filename in list_of_filenames:
do_something_with_one_file(filename)

Unless you disclose more of what your actual code looks like, there
isn't more we can do.

Diez
 
D

Dan Sommers

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
 
U

user

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?

Thanks so far
 
P

Peter Otten

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top