Issue
How can we use python run its script in line ? e.g.
from modulefinder import ModuleFinder
finder = ModuleFinder()
finder.run_script("test-script.py")
for name, mod in finder.modules.items():
print(name)
Have tried such its one line:
$ python -c 'from modulefinder import ModuleFinder; finder = ModuleFinder(); finder.run_script("/usr/bin/xbacklight"); for name, mod in finder.modules.items(): print(name)'
File "<string>", line 1
from modulefinder import ModuleFinder; finder = ModuleFinder(); finder.run_script("/usr/bin/xbacklight"); for name, mod in finder.modules.items(): print(name)
^^^
SyntaxError: invalid syntax
How to do it finely working? Thanks before
Solution
You can wrap your for-each inside a list comprehension in order to make it work using a single-line instruction.
The command becomes
python -c 'from modulefinder import ModuleFinder; finder = ModuleFinder(); finder.run_script("/usr/bin/xbacklight"); [print(name) for name, mod in finder.modules.items()]'
Answered By - canta2899 Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.