Linked Questions
19 questions linked to/from python: get the print output in an exec statement
1 vote
2 answers
4k views
How to get execution of python print statements as a string? [duplicate]
I am writing a python script which contains a list containing python print statements as a string. In my function, I am using a for loop to run exec function to run those statements. Here is my ...
0 votes
2 answers
871 views
How do I test what the output is of a Python Script [duplicate]
Hey I have been messing around on Python and I need to know if there is a way of testing if the output of a Python Script equals something. Heres what I have been trying: a = """ print("Hey") b = 5 ...
0 votes
0 answers
203 views
How can I get the output of a function without the 'return' statement? [duplicate]
I have recently been building a discord bot that is, apart from being a small IDE, trains and teaches you Python, by asking you questions about it. But I am stuck on the IDE part. The problem is that ...
60 votes
11 answers
72k views
How do I get the return value when using Python exec on the code object of a function?
For testing purposes I want to directly execute a function defined inside of another function. I can get to the code object of the child function, through the code (func_code) of the parent function, ...
9 votes
1 answer
6k views
Execute a block of python code with exec, capturing all its output?
What's a good way to exec a bunch of python code, like exec mycode, and capture everything it prints to stdout into a string?
5 votes
3 answers
5k views
Run a dynamic multi-line string of code in python at runtime
How can I run a multi-line string of code from inside python, additionally the string is generated at runtime and stored in either a string or an array. Background I have a function which ...
5 votes
4 answers
432 views
Retain environment of helper python script in main script
I've one helper script which I want to call from main script which is acting as a Server. This main script looks like this: Class Stuff(): def __init__(self, f): self.f = f self....
7 votes
4 answers
962 views
Python write both commands and their output to a file
Is there any way to write both commands and their output to an external file? Let's say I have a script outtest.py : import random from statistics import median, mean d = [random.random()**2 for _ ...
1 vote
1 answer
1k views
Is it possible to stop exec or eval in Python after a certain amount of time?
I want to stop the execution of the exec or eval commands if they take too long to complete. I know how to do it using multiprocessing but I was wondering if there's an easier solution. Any ideas?
1 vote
4 answers
992 views
How to display python input code along side output
I was wondering if there was away to redirect both the input and output of a python script to a file so that they were interlaced. Essentially say I have the following code: x = 1 print("hello, ...
0 votes
1 answer
829 views
Is there any way I can print the output of a code to a tkinter text box?
I am making a python IDE and I wanted to print the output of a file's code to the output text box. My current code doesnt work, it executes in the shell and the output is to the box is "None"...
1 vote
1 answer
1k views
Mounting Virtual Directory, or Running Code in Memory for python 3
I'm making a program that generates code randomly in batches, and given an input, tests to see if that code generates the desired output. I'm wanting to make the batches of generated code pretty large,...
2 votes
1 answer
631 views
Send `exec()` output to another stream without redirecting stdout
I'm writing a Sublime Text plugin that provides multiple Python shells accessible via UNIX sockets. Each shell should act as a standalone REPL running on its own thread. (It is undesirable for these ...
0 votes
0 answers
298 views
exec() with StringIO() in python
I would like to change the standard output from a terminal to a string. I could use the instruction by Frédéric Hamidi in the web page: python: get the print output in an exec statement , and it works....
2 votes
2 answers
124 views
how to convert a string to the desired form?
Good day! I'm trying to implement a module for testing knowledge. The user is given the task, he wrote the decision that is being sent and executed on the server. The question in the following. There ...