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..

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))

yes i got it this way !!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.