-1

I want to read a file from command line first, then run my script and output a file with a different extension.

for example: if I do python script.py apple.java there should be an output file called banana.md

I do not want to rename the file. Dont worry about path or anything.

n= sys.argv[-1]
base = os.path.splitext(n)[0]


os.rename(n,base + ".md")
ahri
  • 387
  • 1
  • 5
  • 11

1 Answers1

0

you can copy the file : you can use shutil.copyfile which will do the job just fine.

or you can just try to read it and write it:

with open (input,'r') as in:
    with open(output,'w') as out:
        out.write(in.read())
Bruce
  • 7,094
  • 1
  • 25
  • 42