I would like to create a python script that will do 3 things:
The Code as of now:
import os, time
from os.path import walk
mydictionary = {"</i>":"</em>"}
for (path, dirs, files) in os.walk(raw_input('Copy and Paste Course Directory Here: ')):
for f in files:
if f.endswith('.html'):
filepath = os.path.join(path,f)
s = open(filepath).read()
for k, v in mydictionary.iteritems(): terms for a dictionary file and replace
s = s.replace(k, v)
f = open(filepath, 'w')
f.write(s)
f.close()
Now i Have parts 1 and 3, I just need part 2.
for part 2 though I need to confirm that only html files exist in the directory the the user will specified otherwise the script will prompt the user to enter the correct folder directory (which will contain html files)
Thanks
From what I understand, here’s your pseudocode:
I don’t think you actually want a recursive walk here, so first I’ll write that with a flat listing:
Except for having the translate the “repeat from start” into a
while Trueloop with abreak, this is almost a word-for-word translation from the English pseudocode.If you do need the recursive walk through subdirectories, you probably don’t want to write the
allas a one-liner. It’s not that hard to write “all members of the third member of any member of theos.walkresult end with'.html'“, but it will be hard to read. But if you turn that English description into something more understandable, you should be able to see how to turn it directly into code.