简体   繁体   中英

Python double quotation syntax issue

This is my code:

for i in range(0, row_count):
    if counter<row_count-1:
        lines.append(""" var flightPlanCoordinates = [
                {lat:""" + latitude[i] + """, lng: """ + longitude[i] + """}
                {lat:""" + latitude[i + 1] + """, lng: """ + longitude[i + 1] + """}
            ];
            """)
        lines.append("""var flightPath"""+i+""" = new google.maps.Polyline({
                path: flightPlanCoordinates,
                geodesic: true,
                strokeColor: '#FF0000',
                strokeOpacity: 1.0,
                strokeWeight: 5
            });""")
        counter += 1

I'm trying to figure out why this isn't compiling(I'm getting a syntax error). This is a string that will be part of the code to an html page. I want to create i flight path variables, each named flightpathi. So flightpath0, flightpath1 and so forth. When using """+i+""" or any other variable inside triple quotations on other lines, this works. I know this is probably something pretty simple that I'm overlooking, but I'm stuck and I'd appreciate any help!

Triple quotes are for multiline comments in python. I would use "var flightPath" + str(i) . You may also want to look into enumerate for your loop. If you need the extra quotes as part of your string for some reason you need to escape them so they are not comments.

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