简体   繁体   中英

syntax error unexpected character after line continuation character

Can anybody tell me what's wrong in my program? When I run this program I get the following error message:

syntaxerror unexpected character after line continuation character

import sqlite3
sqlite_file = 'my_first_db.sqlite'   # NAME OF THE SQL DATABASE FILE
table_name1 = 'my_table_1'  # NAME OF THE TABLE THAT TO BE CREATED.
table_name2 = 'my_table_2'  # NAME OF THE SECOND TABLE THAT TO BE CREATED.
new_filed = 'my_1st_coulmn' # NAME OF THE COULMN
filed_type = 'INTEGER'      # COULMN DATA TYPE
# CONNECTING TO DATA BASE FILE
conn = sqlite3.connect(sqlite_file)
c =  conn.cursor()
# CREATEING NEW SQLITE TABLE WITH 1 COULMN
c.execute('create table {tn} ({nf}) {ft})'\ .format(tn=table_name1,nf=new_filed,ft=filed_type))
# Creating a second table with 1 column and set it as PRIMARY KEY
# note that PRIMARY KEY column must consist of unique values!
c.execute('create table {tn} ({nf}) {ft} primary key)'\.format(tn=table_name2,nf=new_filed,ft=filed_type))
# Committing changes and closing the connection to the database file
conn.commit()
conn.close()

\\ is used for line continuation while writing long queries. so just remove \\ before .format() at creation and execution of query if you continued the code after .

  # CREATEING NEW SQLITE TABLE WITH 1 COULMN
    c.execute('create table {tn} ({nf}) {ft})'.format(tn=table_name1,nf=new_filed,ft=filed_type))

and for more info read this.. https://pyformat.info/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM