Reputation: 11711
my code is,
import MySQLdb
import collections
from pymongo import Connection
from config.MySQLdb import *
from config.MongoDB import *
from config.SyncTables import *
db = MySQLdb.connect(DB_HOST,DB_USR,DB_PWD,DB_NAME)
cursor = db.cursor()
query = "SELECT * FROM table_name WHERE userid = 1"
cursor.execute(query)
row = cursor.fetchall()
mconn = Connection(MONGODB_HOST,MONGODB_PORT)
mdb = mconn[MONGODB_DBNAME]
#col = mdb[trngl_advertiser_agegroup]
db.trngl_advertiser_agegroup .insert({'id': row[0],'userid':row[1], 'ageid':row[2], 'age_value':row[3], \ 'created':row[4], 'modified':row[5]})
print "after update"
but I'm getting this error,
[email protected] [~/download/DataInsertionScript]# python IngestDataToMongo.py
File "IngestDataToMongo.py", line 21
db.table_name.insert({'id': row[0],'userid':row[1], 'ageid':row[2], 'age_value':row[3],\ 'created':row[4], 'modified':row[5]})
^
SyntaxError: unexpected character after line continuation character
But I don't see any unexpected character after . So please tell me, why I'm getting this error
The error image is,
Upvotes: 2
Views: 18506
Reputation: 3655
You don't need line continuation characters inside [], {}, or (). Feel free to put the arguments in multiple lines if you want without \
Upvotes: 1
Reputation: 1123400
Your code is all on one line, but you are using a line continuation escape character (\
). Remove that character:
db.trngl_advertiser_agegroup .insert({'id': row[0],'userid':row[1], 'ageid':row[2], 'age_value':row[3], 'created':row[4], 'modified':row[5]})
You do not need to use such a line continuation trick at all when you break the line inside parenthesis or brackets, you can safely put the statement on multiple lines without it:
db.trngl_advertiser_agegroup .insert({
'id': row[0],
'userid':row[1],
'ageid':row[2],
'age_value':row[3],
'created':row[4],
'modified':row[5]
})
Upvotes: 6