68 questions
0
votes
0
answers
47
views
Pyinstaller: problem with imports and reading/writting files
I am creating a discord bot for a, private, small server, with friends. I would like the bot to be runable by any of my friends, none of whom know much about programming.
My idea was to bundle it up ...
0
votes
0
answers
186
views
QReader - detect_and_decode opens a copy of the .exe
i have a python project where i use QReader to detect and decode a qr code from images i sent to the app. The problem is, the first time the project runs "qreader.detect_and_decode" it opens ...
0
votes
1
answer
29
views
Need to change Windows NTFS File ID
fsutil file queryfileid hkh
File ID is 0x0000000000000000001e000000001249
can anybody help me , how i can change File ID in Windows system ?
example : 0x0000000000000000001e000000001249 =...
0
votes
1
answer
38
views
Executing modules specified by strings
I am developing a Django backend for an online course platform. The backend runs the code submitted by the student. Here is a working example for running a student code consisting of three modules:
...
-2
votes
1
answer
44
views
Python and VS code
I am trying to run code in VSCode but every time getting an error that I could not resolve.
Here is the error:
python : The term 'python' is not recognized as the name of a cmdlet, function, script ...
-1
votes
2
answers
1k
views
importlib.metadata.PackageNotFoundError: No package metadata was found for djoser pyinstaller
Context
I made a Django react app. Now I want to make it a desktop application so that the user does not have type python manage.py runserver and also activate the environment every time. I used ...
0
votes
1
answer
278
views
using exec how to save variable equal to a string
I am using exec to save a variable equal to a string. I am getting a SyntaxError. I'm assuming exec is getting confused with the value as string. Is this assumption accurate? Would appreciate the ...
0
votes
3
answers
438
views
black console using py-to-exe
i tried to make an executable file from my main_app.py using pyinstaller.
All works but when im duble click the .exe files generated its popping out just a black console, not the app..
This is the ...
0
votes
1
answer
206
views
Isolate state change of chdir within python exec scope
Running a script with exec, how does one "backup" python process global state in its entirety and restores it afterwards?
code example:
import os
print(os.getcwd())
a = 8
print(a)
exec_scope ...
-1
votes
2
answers
563
views
Python script ends instead of restarting (os.execv)
Whenever I run the following file (and main encounters the WebDriverException exception) my program ends instead of restarting. Would anyone know why that's happening? Any help would be greatly ...
0
votes
1
answer
607
views
How to get function value from txt file with exec Python [duplicate]
I want to execute python code from txt file and store it.
In txt file I have this code:
def func(a):
return a
In python:
def random_file_input(file_name):
ran_number = random.randint(0, 100)
...
0
votes
1
answer
35
views
Exec Function, saving Methods/Classes/Variables -> Method
I'm writing a library for creating smaller python modules. I am not sure if I should be using compile() instead of exec(), it currently execute the files(any basic code in the global scope is executed)...
0
votes
1
answer
121
views
How to extend scope to an exec'd function?
I have a module object containing several function definitions. Here is a simplified example.
The source code (makes up the module "my_module")
def functionA():
print("hello")
...
1
vote
1
answer
647
views
Azure Cognitive Services and Python Executable
I am working on creating a program that uses the Speech aspect of Azure's Cognitive Services. When I deploy the executable(.exe) with just console printing, it works as hoped. The program works ...
1
vote
1
answer
1k
views
Command exec in a function, name error - python3
I'm begginer in Python and I'm in front of a problem that I can't understand. I tried to just define a variable with a exec() and then just print it. And it's working well. BUT when I do the same code ...
0
votes
2
answers
898
views
How to run currently opened file in python tkinter?
I have this program written in python tkinter, which has a text box and a menu. The menu has two options, open file and run file.
The open file lets you open python files and writes the contents of ...
1
vote
0
answers
257
views
Why local variables go missing in Python exec while running bytecode?
I've built a function called foo to alter a function's code at bytecode level and execute it before returning to regular function execution flow.
import sys
from types import CodeType
def foo():
...
1
vote
1
answer
226
views
Python NameError in a function body
I have two blocks of python code, one works, and the other doesn't.
Working block:
env = {'user':'xyz'}
for key, value in env.items():
exec("{} = value".format(key))
print(user)
...
0
votes
1
answer
537
views
Handle Python reserved words in a sympy parse_expr?
If I parse an expression containing lambda, I get an error even though Symbol("lambda") is valid:
>>> sympy.Symbol("lambda")
lambda
>>> sympy.parse_expr("1 + ...
0
votes
1
answer
2k
views
Pyinstaller output .exe closes immediately
I am trying to turn a python file into an executable with Pyinstaller.
The file calls onto different modules as well as different libraries.
When executing the command pyinstaller --onefile instabot....
0
votes
1
answer
453
views
Storing stdout from an exec process into a variable
I currently have the following code whereby I am using os.execv() to execute some sort of process. For example:
process_param = [exec_path, f]
pid = os.fork(
try:
if (pid > ...
0
votes
0
answers
14
views
I don't understand how Python 3 exec works [duplicate]
def beat():
exec('nDns=1', locals())
print(nDns)
beat()
Result NameError: name 'nDns' is not defined. When I change locals() to globals() it works, but I don't really want it written to ...
3
votes
2
answers
490
views
Python exec with a function chain producing NameError
Consider the following script, which uses exec to define two functions, one of which calls the other:
def run_code():
code = """
def foo():
print('foo')
return 1
def bar():
...
1
vote
0
answers
18
views
Getting pytest to understand exec built-in function [duplicate]
I have a simple test below that I run with pytest. It works via the built-in function exec:
def test_exec() -> None:
foo = "" # Causes test to fail if not updated by exec
exec(&...
3
votes
1
answer
1k
views
Programmatically execute a Python file from within Python in a fresh-looking Python environment
Let's say I have a file script.py located at path = "foo/bar/script.py". I'm looking for a way in Python to programmatically execute script.py from within my main Python program through a ...
0
votes
1
answer
202
views
Using nonlocal inside exec
Why does the following code:
exec("""
a = 3
def b():
nonlocal a
a = a + 1
b() #error occurs even without this call
print(a)
"""
)
)
give this error:
Traceback (most ...
0
votes
1
answer
69
views
Python exec not picking up scope when called via a function
I have a function test() that should check if a string is a valid Python file. (The string is typically extracted from a readme or so.) Running exec() on the string works well, unless in this ...
0
votes
2
answers
288
views
Python Exec not passing full variables to exec shell - with working errors
Python "Exec" command is not passing local values in exec shell. I thought this should be a simple question but all seem stumped. Here is a repeatable working version of the problem ... it took me a ...
0
votes
2
answers
522
views
How to get the returned value of a function, called by exec() in python?
I have a function called 'somefunc' :
def somefunc():
return "ok"
And i wanted to run it with exec() like :
exec("somefunc()")
That works great. But the problem is, i can't get the returned ...
0
votes
1
answer
807
views
How to hide args to argparse when running script with exec?
I have 2 files, runner.py that runs target.py with subprocess or exec.
They both have command line options.
If runner runs target with subprocess it's ok:
$ python runner.py
run target.py with ...
0
votes
1
answer
371
views
Execute stand alone python script inside another script
I have made a .py file (i call it acomp.py) that reads from and SQL database and after a series of calculations and exports its output to an excel file.Later I sends this .xlsx file by e-mail to ...
1
vote
3
answers
852
views
Python 3 - How to exec a string as if it were substituted directly?
Problem Description
I am curious if it is possible to exec a string within a function as if the string were substituted for exec directly (with appropriate indentation). I understand that in 99.9% of ...
0
votes
1
answer
173
views
How to merge dependent globals from multiple calls to exec with independent globals dicts
This code works fine - it defines do_return as a global, it defines do_proxy as a global, and do_proxy can resolve do_return when called.
g1 = {}
exec("def do_return(): return 1", g1)
exec("def ...
-1
votes
1
answer
299
views
python.exe flashes and close while running from windows scheduler
python.exe flashes and close while running from windows scheduler
Last run result is showing : (0x1)
Everything was working perfect untill i uninstall and reinstall anaconda.
New reinstalled ...
0
votes
0
answers
34
views
Python function not successful to define variable [duplicate]
I have run the below code:
def test(yymm):
exec("test_var_" + yymm + " = 'abc'")
print(test_var_1912)
test('1912')
My expected output is to assign the variable 'test_var_1912' and print out ...
0
votes
0
answers
181
views
Not able to fetch info from database when trying from python through exe
I've converted my Python application to an .exe using the cx_Freeze Library. Now the GUI appears after I run the exe file, but it cannot fetch data from database, everything else is working.
When this ...
-2
votes
3
answers
174
views
c++ version of python's exec() functions
objective:
executing a string of c(++) code with some kind of function comparable to the exec() function in python.
example in python:
exec('print("hello world")')
#out:
#hello world
...
1
vote
1
answer
46
views
Git : few exes not properly checkout
Am using git version 2.21.0.windows.1 with Git Extensions v 2.48.05 on Windows 10.
In our project there are few python executable. After I clone our repository, there are many exe which are not ...
0
votes
1
answer
196
views
exec: name not defined, but works earlier on in the same code
I ran into this when creating a script that exports dirs and mails to another account with exchangelib.
When I run code with "exec" it returns as not defined but earlier on in the same code it works.
...
1
vote
1
answer
224
views
Pyinstaller adddata query
When I am trying to converting my python file into executable and binding with pdf with using command add-data. My pdf file is store no where due to this I cannot open my pdf file while opening ...
0
votes
2
answers
241
views
A dictionary method instead of exec method
I have the following variable:
Output=[{'name': 'AnnualIncome', 'value': 5.0},
{'name': 'DebtToIncome', 'value': 5.0},
{'name': 'Grade', 'value': 'A'},
{'name': 'Home_Ownership', 'value': 'Rent'},
...
0
votes
1
answer
41
views
Python: dynamic initialization of class members from strings holding expressions
This is a pretty general scenario, but to give some context, let's say I am using cvxpy to do some constrained optimization. Now say I want to supply the objective function at runtime, such as func ...
0
votes
2
answers
253
views
Python cannot find the executed function after exec()
I cannot find the executed function even after the excution.
This is the function:
# function illustrating how exec() functions.
def exec_code():
LOC = """
def factorial(num):
fact=1
...
-2
votes
1
answer
74
views
limited exec: can't assign new value to variable?
Having this code:
x = 10
exec('x += 5', {}, {'x': x})
print(x) # prints 10.
# This works of course
exec('x += 5')
print(x) # prints 15.
Why it does ignore my x += 5 expression? Is there something ...
2
votes
1
answer
4k
views
Why do I get "NameError: name is not defined" with exec()?
When I try this code in a console (in PyCharm):
exec("import random")
exec("def f():\n\treturn random.randint(0, 10), random.randint(0, 10)")
locals()['f']()
it works fine. But when I try to do ...
1
vote
1
answer
416
views
Pros and cons of using exec for importing a specific module?
I would like to find out disadvantages of using exec for imports. One of the files serves as interface towards real implementations of specific functionalities depending on chosen project (framework ...
0
votes
2
answers
260
views
Is it possible to access exec-provided globals dictionary from within a function?
Is it possible to access exec-provided globals dictionary from within a function, if the function was defined outside of the exec-ed code (and thus already bound to different __globals__)?
In other ...
0
votes
2
answers
155
views
Defining a Method from A String in Python 3 and Referencing As Method
I have a need to allow the user to define a function that processes data in an object (the wisdom and security implications in this have been discussed at length in another question and would just be ...
6
votes
3
answers
5k
views
assignment within exec in python
I am trying to build calculator using PyQt5 and I get string which I need to evaluate and assign it to a variable so that I can Pass that variable to widgets as an answer . So far I can evaluate the ...
0
votes
0
answers
55
views
What is effect of compile while creating dynamic functions?
While searched for creating dynamic functions in python, i end up with following code.
dynf = types.FunctionType(compile('print "really WoW"', 'dyn.py', 'exec'), {})
dynf()
As python guidelines, it ...