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()
outputFile.write(str(pid))str. Also, you may consider working with files withwithkey-word. geeksforgeeks.org/with-statement-in-python