You can do what you ask for:
from os import path
module_type = 'recon'
q = 'shoban.py\nbing.py'
modules = (path.splitext(m)[0] for m in q.split('\n'))
formatted = ('modules/%s/%s' % (module_type, m) for m in modules)
print('\n'.join(formatted))
output:
modules/recon/shodan
modules/recon/bing
But since you are already calling the unix shell from python, you can use sed to process the strings:
print(commands.getoutput("ls modules/recon/ | sed '/.py$/!d; /^__init__.py$/d; s/\.py$//; s/^/modules\/recon\//'"))
"globbing" , , , (, /), , :
print(commands.getoutput("ls modules/recon/*.py | sed 's/.py$//; /\/__init__$/d'"))
- python:
from os import path
import glob
module_type = 'recon'
module_paths = glob.iglob('modules/recon/*.py')
module_files = (m for m in map(path.basename, modules) if m != '__init___.py')
modules = (path.splitext(m)[0] for m in module_files)
formatted = ("modules/%s/%s" % (module_type, m) for m in modules)
print('\n'.join(formatted))