0

I have python code that excepts to get arguments from CLI ( command line ). for an example :

python.py my_code first_arg

I am trying to build a script that get a long string of the above python code, then to compile it using the next functions: complile() && exec().

my problem is that I am not sure how should I use those function, in order to pass the compile code object the arguments that it excepts to get from Command line.

SomeOne
  • 1
  • 1
  • 1
    I assume you aware that `exec` is a security risk. What you want to do is _possible_, but not very practical, because it's very annoying trying to put multi-line Python code on one line with correct indentation. – PM 2Ring Nov 06 '17 at 12:58
  • thanks for the answer. first of all, I am aware that `exec` function isn't safe function, but it is doesn't matter for my purpose. maybe you have any other suggestion that can help me to implement what I am trying to do ( even with using other functions ) – SomeOne Nov 06 '17 at 13:51
  • You can find a lot of great info about `compile` and `exec`, with a few examples, [here](https://stackoverflow.com/a/29456463/4014959). But depending on what you're doing, you might not need that: you can run Python code in the command line with the `-c` option to the `python` command. – PM 2Ring Nov 06 '17 at 13:55

0 Answers0