Issue
I am using the following code:
filename = r'C:/Users/Automated Analysis.ipynb'
dest = r'C:/Users/Automated Analysis.py'
os.system("ipynb-py-convert %s %s" % (filename, dest))
But it give me this error:
raise(Exception('Extensions must be .ipynb and .py or vice versa'))
Exception: Extensions must be .ipynb and .py or vice versa
I am not sure how to make my code above work.
Solution
It's because you have spaces for your filenames.
Your os.system
command becomes:
ipynb-py-convert C:/Users/Automated Analysis.ipynb C:/Users/Automated Analysis.py
...and as you can see, there are now 4 inputs. Running that directly on the command line will produce the same Exception message. It is trying to convert C:/Users/Automated
into Analysis.ipynb
.
Just wrap the filenames in quotes:
os.system("ipynb-py-convert '%s' '%s'" % (filename, dest))
Or you can use subprocess.run
:
import subprocess
filename = r'C:/Users/Automated Analysis.ipynb'
dest = r'C:/Users/Automated Analysis.py'
subprocess.run(['ipynb-py-convert', filename, dest])
See Advantages of subprocess over os.system and Replacing os.system()
.
Answered By - Gino Mempin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.