You should run it from command line as
python chext.py . foo java
But really you should fix the function as it is not using the parameters properly:
def change_ext(directory, old_ext, new_ext):
for f in os.listdir(directory):
base, ext = os.path.splitext(f)
if ext[1:] == old_ext:
os.rename(f, "%s.%s" % (base, new_ext))
Also you should fix the hard tabs to 4 space soft tabs.
pyTony
pyMod
6,308 posts since Apr 2010
Reputation Points: 879
Solved Threads: 986
Skill Endorsements: 26
Mixing the two styles produces hard to debug problems in indention and ugly code with big tabs, so Python convention is spaces. It is not an absolute truth as in Go language for example convention is hard tabs. Read PEP8 document and try to use it as long as it makes sense. That makes your code easier to understand for you and others. You might also try to dicipline yourself for few usefull other coding practices, for example using plural names for sequences and verb names for action performing functions.
pyTony
pyMod
6,308 posts since Apr 2010
Reputation Points: 879
Solved Threads: 986
Skill Endorsements: 26
Question Answered as of 1 Year Ago by
pyTony