I have a .dos script that runs fine in the DolphinDB GUI but fails when executed via the Python API's session.run. The error goes away when I manually remove all comments from the script.

Script (simplified):

// initialize parameters start_date = 2024.01.01 end_date = 2024.12.31 /* load data */ t = loadTable("dfs://mydb", "mytable") select * from t where date between start_date:end_date

Python call:

with open("my_script.dos", "r") as f: code = f.read() s.run(code)

Syntax error pointing at the comment line

Using session.runFile("my_script.dos") works without modification.

Does session.run not strip // or /* */ comments before sending code to the server? If not, is runFile the recommended approach for executing script files, or should I preprocess comments on the Python side?

Jane's user avatar

Yes. For file-sized .dos scripts, Session.runFile() is the right approach.

DolphinDB’s Python API docs describe Session.run(script, ...) as executing a script string, while runFile(filePath) “runs a local DolphinDB script file on the server,” with the important note that the path is local to the Python client.

I don't recommend preprocessing comments unless you have to. For executing full DolphinDB script files, use runFile(); reserve run() for inline snippets or expressions.

kingsbane's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.