Skip to content
Advertisement

Tag: exec

How can I handle eval() exec() multiline as first in first out

I have code from this Question: Why is Python’s eval() rejecting this multiline string, and how can I fix it? When I use this code: The result is: I am expecting this: How can I change the code? I tried to change the code, but I was not successful. Answer The code you’ve posted sorts the ast tree body in

Execute f-string in function

I have a and want to replace all tokens starting with with a new token I wrote a function: If I execute the lines separately it works. But the function itself doesn’t work. I’d expect How can I “exec” f-string in a function? Answer You are overcomplicating this. Simply reassign x: But it’s probably easier to rewrite the function similar

Syntax error calling Python from C with fork-execv

I want to call a Python script as a child process from a C program using fork and execv. I have tested it calling bin/ls and it works: So I changed the C code to call the Create_Buffer() function in this Python file: The Python script has two functions; I want to call Create_Buffer(), so I changed my C file

async exec in python

I’d like to call exec in an async function and do something like the following code (which is not valid): More precisely, I’d like to be able to wait for a future inside the code that runs in exec. How can this be achieved? Answer Note: F-strings are only supported in python 3.6+. For older versions, use %s, .format() or

Python3 exec, why returns None?

When the code below this text, and returns the result None why? Result: Module code exx.py: Answer The problem of course is not only that print returns None, it is that exec returns None, always. If you’d need the return value, you’d use eval: after which you’d notice that print still returns None…

Advertisement