Just can't stay away
Joined: 2009/2/9 19:32 Last Login
: 2020/12/21 15:57
From Brussels Belgium
Group:
Registered Users
|
@afxgroup The script was suggested to me and it would take me too long to shorten it with my present python knowledge
Outputhelp.py ------------------- # pipe the output of Python help() to a string
import subprocess
code_str = """\ help("print") """
# save the code filename = "help_code.py" fout = open(filename, "w") fout.write(code_str) fout.close()
# execute the .py code and pipe the result to a string # give the full path of python.exe (here Windows path) test = "Python" + filename process = subprocess.Popen(test, shell=True, stdout=subprocess.PIPE) # important, wait for external program to finish process.wait() print process.returncode # 0 = success, optional check # read the result to a string help_str = process.stdout.read()
# the result of the code is now in help_str print('-'*70) print(help_str) # test
# optionally write to a file # change the filename as needed fname = "help_print.txt" fout = open(fname, "w") fout.write(help_str) fout.close() print('-'*70) print("file %s written" % fname)
gives me the following errors
1.Amiga OS 4:System/Python/Scripts> python Outputhelp.py Traceback (most recent call last): File "Outputhelp.py", line 18, in <module> process = subprocess.Popen(test, shell=True, stdout=subprocess.PIPE) File "PYTHON:Lib/subprocess.py", line 594, in __init__ errread, errwrite) File "PYTHON:Lib/subprocess.py", line 1010, in _execute_child self._set_cloexec_flag(errpipe_write) File "PYTHON:Lib/subprocess.py", line 973, in _set_cloexec_flag old = fcntl.fcntl(fd, fcntl.F_GETFD) IOError: [Errno 78] Function not implemented
|