Skip to content

fix custom codefile execution syntax error#61

Open
odeliap wants to merge 1 commit intoraspishake:masterfrom
odeliap:master
Open

fix custom codefile execution syntax error#61
odeliap wants to merge 1 commit intoraspishake:masterfrom
odeliap:master

Conversation

@odeliap
Copy link
Copy Markdown

@odeliap odeliap commented Dec 11, 2023

I've seen this issue around, where when specifying a custom file the user gets back a syntax error. Tested and verified that the problem is that exec is being called on the filename instead of the file contents. The exec function is meant to execute a string of Python code, not to execute the file by its path. The exec command typically works like:

# Define the path to the file
file_path = 'YOURPATH'

# Read the content of the file
with open(file_path, 'r') as file:
    file_content = file.read()

# Execute the content of the file
exec(file_content)

but it's being called on self.codefile where self.codefile is the file path (and not the actual python code). This would cause a syntax error since exec expects python code and not the file path -- which is exactly what we're seeing.

This fix should resolve this. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant