-2

I have this working code:

with my_workflows.ZBX_SSL_CHECK('multiple', 'parameters', 'ZBX_SSL_CHECK') as workflow:
    workflow.run()

and I'd like to write that using inline code, in order to use it inside a gitlab-ci configuration. I tried with no success:

python -m my_workflows -c "with my_workflows.ZBX_SSL_CHECK('multiple', 'parameters', 'ZBX_SSL_CHECK') as workflow: workflow.run()"
Iron Bishop
  • 1,749
  • 1
  • 7
  • 16
  • 1
    Yes, it's possible. Define "no success" – DeepSpace Jul 09 '19 at 10:21
  • 1
    I suspect that `-m my_workflows` does not do what you expect it to – DeepSpace Jul 09 '19 at 10:22
  • @DeepSpace isnt it like using import for the following lines? – Iron Bishop Jul 09 '19 at 11:15
  • No. https://stackoverflow.com/questions/22241420/execution-of-python-code-with-m-option-or-not Importing the module is a side-effect, but what it is actually doing is running the module as a script, which may or may not be the source of your problem. Either way, we can't help you unless you explain what exactly you mean by "no success" and what errors you get – DeepSpace Jul 09 '19 at 11:21
  • What's the correct way to import the module using inline commands? – Iron Bishop Jul 09 '19 at 13:03
  • Using `python -c "import ...` and correcting other errors, fixed the issue. Thank you all. – Iron Bishop Jul 09 '19 at 13:27

1 Answers1

1

Yes, you can.

python -c "with open('foo.yml') as r:print(r.read())" 

Works fine.

Rob
  • 14,746
  • 28
  • 47
  • 65
harshil9968
  • 3,254
  • 1
  • 16
  • 26
  • 1
    This is a comment, not an answer – DeepSpace Jul 09 '19 at 10:21
  • This is a perfectly cromulent answer. – Konrad Rudolph Jul 09 '19 at 10:22
  • @KonradRudolph How so? It does not try to solve OP's problem and asks for more information, which is pretty much the go-to use-case for comments – DeepSpace Jul 09 '19 at 10:23
  • @DeepSpace It answers the question. The fact that OP’s problem is unrelated to their question is a different issue, and reflects badly on the question, not this answer (and it should probably be closed). – Konrad Rudolph Jul 09 '19 at 10:31
  • @KonradRudolph Let's agree to disagree and let the flag reviewer decide... – DeepSpace Jul 09 '19 at 10:32
  • You need to clarify what your answer does and how it answers the question instead of just blurting out code. – Rob Jul 09 '19 at 11:03
  • 1
    Knowing if what I'm trying to do is possible, is exactly what I need. In this case, knowing that the "with" syntax was correct, helped pointing the the error elsewhere. – Iron Bishop Jul 09 '19 at 13:29