简体   繁体   中英

Python: Invalid syntax when creating a dictionary with dates

I enter a date followed by time using Python and flask. What is the problem?

from flask import Flask,render_template,request,jsonify
import datetime

app=Flask(__name__)


calendrier=[
{
    'start':2013-9-22 16:19:43,
    'end':2015-8-11 13:30:00
}}

As the title of your question asks for why is there an invalid syntax error then that is cause you are using a curly } brace to close your calendrier list instead of a square ] bracket as well as the way you are storing the dates.

You should either store the date in string format as suggested by S3DEV or as you have imported the datetime module use a datetime object to store the date which is recommended for you. Try:

from flask import Flask,render_template,request,jsonify
import datetime

app=Flask(__name__)


calendrier=[
{
    'start': datetime.datetime(2013,9,22,16,19,43),
    'end': datetime.datetime(2015,8,11,13,30,0)
}]

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