I need to take a list of files and remove a '.2' from a line in each file. I then need to rewrite the file without the '.2'. Using the code below I am >able to take a single file and do exactly what i need to but when trying to use glob.glob to rewrite a number of files I run into problems and >was wondering if anyone could help.
when i run this code i get the following error.
File "learn.py", line 15, in moduleTypeError: coercing to Unicode: need string or buffer, list found
dwhite12 0 Newbie Poster
Recommended Answers
Jump to Post— Schol-R-LEA 1,446To post a code sample, you can use the Code button on the editing bar just above the editing pane. This should open up a new window where you can paste the code samples. Alternately, you can simply indent the line four spaces, with extra lines between the code and …
Jump to Post— TrustyTony 888for line in files:
It does not make sense to call filename line. Your indention is incorrect.
Jump to Post— Schol-R-LEA 1,446The problem is that you are trying to use
filesas a filename, when it is a list of filenames (well, technically file paths, but anyway). You need to either index the specific one of the list elements you want, or else iterate through the list of filenames.
All 11 Replies
dwhite12 0 Newbie Poster
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster
dwhite12 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
dwhite12 0 Newbie Poster
Schol-R-LEA 1,446 Commie Mutant Traitor Featured Poster
dwhite12 0 Newbie Poster
dwhite12 0 Newbie Poster
dwhite12 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
Lucaci Andrew 140 Za s|n
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.