Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Subprocess for Notepad

I am trying to open Notepad using popen and write something into it. I can't get my head around it. I can open Notepad using command:

notepadprocess=subprocess.Popen('notepad.exe')

I am trying to identify how can I write anything in the text file using python. Any help is appreciated.

like image 510
Bash Noob Avatar asked Sep 27 '26 03:09

Bash Noob


1 Answers

You can at first write something into txt file (ex. foo.txt) and then open it with notepad:

import os

f = open('foo.txt','w')
f.write('Hello world!')
f.close()
os.system("notepad.exe foo.txt")
like image 142
Timur Osadchiy Avatar answered Sep 29 '26 17:09

Timur Osadchiy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!