How do I read files through another file?
ekkanh 0 Newbie Poster
Recommended Answers
Jump to PostDo you have the filenames in a file?
Do you want pipelining, stdout/stdin teeing?
Jump to PostSuppose you have the filenames in the file "names.txt".
for line in open("names.txt") fi=open(line.strip()) # now you can read the file
Jump to PostThen modify the code like this
def thefunction(): filenames = list(x.strip() for x in list(open("name.txt", "rb")) if x.strip()) L = [(n, open(n, "rb").read()) for n in filenames] return [(x, [int(z) for z in y.strip().split()]) for (x,y) in L]
All 11 Replies
slate 241 Posting Whiz in Training
richieking 44 Master Poster
ekkanh 0 Newbie Poster
richieking 44 Master Poster
slate 241 Posting Whiz in Training
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
richieking 44 Master Poster
ekkanh 0 Newbie Poster
Gribouillis 1,391 Programming Explorer Team Colleague
ekkanh 0 Newbie Poster
Gribouillis 1,391 Programming Explorer Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.