3

Im trying to write and execute a .vbs file with python. When I run the program, the IDE shows an error that the file I tried to make isn't there, so therefore it couldn't be executed. I followed exactly the documentation in python.org and other similar questions in stack overflow but they didn't give a good answer to my problem. Here is the code I tried to run:

import os
a = open('draw.vbs','w+')
a.write('do\nSet oWMP = CreateObject(\"WMPlayer.OCX.7\")\nSet colCDROMs             oWMP.cdromCollection\nif colCDROMs.count >= 1\ncolCDROMs.Item(i).eject\nNext  cdrom\nEnd If\nloop')
b = os.system('draw.vbs')
verymessi
  • 117
  • 1
  • 12

1 Answers1

0

Try using a with statement.

with open('draw.vbs', 'w+') as a:
    a.write('do\nSet oWMP = CreateObject(\"WMPlayer.OCX.7\")\nSet colCDROMs
b = os.system('draw.vbs')
Stephan
  • 16,509
  • 7
  • 35
  • 61