Click here to Skip to main content
15,036,363 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If I run this script from Spyder, it runs just fine.

If I run it from command line with this:
python "C:\Users\Jonathan\OneDrive - Mazars in Oman\Trading\Systems\FibMatrix\Testing Trade Analysis\Python Codes\CreateDataTablePythonScriptv2.py" -a='USDJPY


It gives this error:
Traceback (most recent call last):
  File "C:\Users\Jonathan\OneDrive - Mazars in Oman\Trading\Systems\FibMatrix\Testing Trade Analysis\Python Codes\CreateDataTablePythonScriptv2.py", line 12, in <module>
    cursor.execute("""CREATE TABLE IF NOT EXISTS {}
sqlite3.OperationalError: near "-": syntax error


Here is the script:
import sqlite3
import sys

PairName = sys.argv[1]
DTBLocation = 'C:/Users/Jonathan/OneDrive - Mazars in Oman/Trading/Systems/FibMatrix/Testing Trade Analysis//SQLite/Trade Analysis.db'
connection = sqlite3.connect(DTBLocation)
cursor = connection.cursor()

TableName = PairName+'_DATA'
cursor.execute("""CREATE TABLE IF NOT EXISTS {}
(
    Date_Time INTEGER,
    Open REAL,
    Max_60m_Box REAL

 )""".format(TableName))
connection.commit()
connection.close()


What am I doing wrong? Thanks for the assistance!

What I have tried:

I tried running the code in Spyder and it works.
Posted
Updated 12-Feb-21 1:45am

1 solution

The PairName variable is taken from the input parameter whih is "-a='USDJPY". So TableName becomes "-a='USDJPY_DATA". And the SQL becomes:
Python
CREATE TABLE IF NOT EXISTS -a='USDJPY_DATA

As you can see the table name is not valid.
   
Comments
Member 15071189 12-Feb-21 12:14pm
   
Richard is correct. So this code worked:"python "CreateDataTablePythonScriptv2.py" USDJPY"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900