0

if i try to dump from shell like this python -c 'help("modules")' > ~/Desktop/modules.txt

but if I try to execute from within the python like this
>>os.system("python -c 'help("modules")' > ~/Desktop/modules.txt")
i get error

File "<stdin>", line 1
    os.system("python -c 'help("modules")' > ~/Desktop/modules.txt")
                                      ^
SyntaxError: invalid syntax

once i get to save data to disk I want to populate module names to a list by reading the modules.txt, but it is contained in a way it is a list i pull but combination of strings too..

2
Contributors
2
Replies
31
Views
3 Years
Discussion Span
Last Post by krystosan
0

I suggest

import pkgutil
import os
import sys

L = list(sys.builtin_module_names)
L += list(t[1] for t in pkgutil.iter_modules())
L = sorted(L)
dst = os.path.expanduser("~/Desktop/modules.txt")

with open(dst, "w") as ofh:
    ofh.write('\n'.join(L))

Edited by Gribouillis

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.