简体   繁体   中英

Python 3.4 Syntax error and how to fix it

While the following line is accepted on Python 3.6, On Python 3.4 I am getting a syntax error:

struct.pack_into('q' * len(GeoFence_lat_list)*2,buff,264,*GeoFence_lat_list, *GeoFence_lon_list)

Where GeoFence_lon_list is an array declared as:

Geo_Fence_list = []
GeoFence_lat_list = []

GeoFence_lon_list = []

Here is more code to review:

if (Polygon_available_size == 0):
    buff = ctypes.create_string_buffer(workzone_size)
    struct.pack_into('q' * 33, buff, 0, Speed_limit, Speed_Zone_lat, Speed_Zone_longi, Speed_Zone_heading_radians,
            Speed_Zone_ITIS_CODE, Speed_Zone_2_lat, Speed_Zone_2_longi, Speed_Zone_2_heading_radians, Speed_Zone_2_ITIS_CODE,G20_lat, G20_longi,
            G20_heading_radians, G20_ITIS_CODE,W20_lat, W20_longi, W20_heading_radians ,W20_ITIS_CODE,W21_5BR_lat,W21_5BR_longi, W21_5BR_heading_radians,
            W21_5BR_ITIS_CODE,W21_5AR_lat,W21_5AR_longi, W21_5AR_heading_radians, W21_5AR_ITIS_CODE,First_Taper_lat,First_Taper_longi,
            Last_Taper_lat, Last_Taper_longi, 2020, 2456,60, Polygon_available_size)
elif (int(Polygon_available_size) > 0):
    geo_fence_size = struct.calcsize('q' * len(GeoFence_lat_list)*2)
    #print("geo_fence_size", geo_fence_size)
    workzone_size = workzone_size + geo_fence_size
    buff = ctypes.create_string_buffer(workzone_size)
    struct.pack_into('q' * 33, buff, 0, Speed_limit, Speed_Zone_lat, Speed_Zone_longi, Speed_Zone_heading_radians,
            Speed_Zone_ITIS_CODE, Speed_Zone_2_lat, Speed_Zone_2_longi, Speed_Zone_2_heading_radians, Speed_Zone_2_ITIS_CODE,G20_lat, G20_longi,
            G20_heading_radians, G20_ITIS_CODE,W20_lat, W20_longi, W20_heading_radians ,W20_ITIS_CODE,W21_5BR_lat,W21_5BR_longi, W21_5BR_heading_radians,
            W21_5BR_ITIS_CODE,W21_5AR_lat,W21_5AR_longi, W21_5AR_heading_radians, W21_5AR_ITIS_CODE,First_Taper_lat,First_Taper_longi,
            Last_Taper_lat, Last_Taper_longi, 2020, 2456,60, Polygon_available_size)
    struct.pack_into('q', * len(GeoFence_lat_list)*2,buff,264,*GeoFence_lat_list, *GeoFence_lon_list)
    GeoFence_lat_list.clear()
    GeoFence_lon_list.clear()
packed_flag = 1

Python 3.4 only allows one unpacked argument per call.

Your original code is using multiple unpackings simply to append multiple lists into the byte buffer. You can achieve the same thing simply by calling struct.pack_into() multiple times, with appropriate offsets for each part.

start = 264
struct.pack_into(str(len(GeoFence_lat_list)) + 'q', buff, start, *GeoFence_lat_list);
start += 8 * len(GeoFence_lat_list)
struct.pack_into(str(len(GeoFence_lon_list)) + 'q', buff, start, *GeoFence_lon_list);

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