raspishake / rsudp

Continuous visual display, sudden motion monitoring, and historical replay of Raspberry Shake data
https://raspishake.github.io/rsudp/
GNU General Public License v3.0
55 stars 32 forks source link

fix custom codefile execution syntax error #61

Open odeliap opened 10 months ago

odeliap commented 10 months ago

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!