I get the current running script PID by os.getpid(), and try to store it in a file but I get an error that write() only accepts 'string' and not 'int'. So how to pass PID as a string to write()?
My code:
import os
outputFile = open('test.txt', "w")
pid = os.getpid()
outputFile.write(pid)
outputFile.close()
I have to use type convertor str() like this:
import os
with open('test.txt', 'w', encoding='utf-8') as f:
f.write(str(os.getpid()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With