0

So I have some code that gives three syntax errors but IT RUNS FINE, it almost like the syntax error are cosmetic or something. Its in a very large project that used googles cloud vision API, I might be giving more code then necessary to diagnose the issue but I think its pretty easy to parse and I figured it might be easy to see the whole method to know what is important

(the code that is erroring is basically just taken from google vision API examples but I did have to adapt it a bit so maybe that is the problem but it works so I am confused)

(it is also worth noting that the problem could be with visual studio code and not the code itself)

def detect_object_cord(path): """Localize objects in the local image.

def detect_object_cord(path): 
    """Localize objects in the local image.
    Args:
    path: The path to the local file.
    """

    client = vision.ImageAnnotatorClient(credentials=GOOGLE_APPLICATION_CREDENTIALS)

    f = 1


    with open(path, 'rb') as image_file: 
        content = image_file.read()
    image = vision.Image(content=content)#content=content

    objects = client.object_localization(image=image).localized_object_annotations

    print('Number of objects found: {}'.format(len(objects)))
    for object_ in objects:
        print('\n{} (confidence: {})'.format(object_.name, object_.score)) 
    
        for vertex in object_.bounding_poly.normalized_vertices:
        
            if FaceCount == 1:
                if f<= 4:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )

            if FaceCount == 2:
                if f<= 8 and f> 4:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 3:
                if f<= 12 and f > 8:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 4:
                if f<= 16 and f > 12:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 5:
                if f<= 20 and f > 16:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 6:
                if f<= 24 and f > 20:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 7:
                if f<= 28 and f > 24:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 8:
                if f<= 32 and f > 28:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 9:
                if f<= 36 and f > 32:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
                
            if FaceCount == 10:
                if f<= 40 and f > 36:
                    cordAryX.append(vertex.x  )
                    cordAryY.append(vertex.y  )
               
            f = f+1

    print()
    print('user selection was: ' + FaceChoice)
    print('x: ', end='')
    print(cordAryX)
    print('y: ', end='')
    print(cordAryY)

the error for all three lines just says "SyntaxError: invalid syntax" and the lines that error are:

"with open(path, 'rb') as image_file:"

"content = image_file.read()"

"for object_ in objects:"

or at least those are the lines that the problems panel

Iv tried looking at it really hard and my brain can't see anything that is wrong. I can't see any out of place indents or spaces. and I don't see anything wrong in general. I have tried deleting and then re-typing out the lines by hand but to no use. As I said earlier the code runs and works as intended but the errors are making me crazy and I just want it to look perfect.

3
  • 2
    Does it run or does it throw a syntax error? Both things can't be happening Commented Apr 4, 2022 at 3:23
  • If I just paste this code into a file and import it, I don't get syntax errors. Are you sure it's this exact code that's causing the problem? Commented Apr 4, 2022 at 3:32
  • yeah I'm pretty sure that it is the exact code. I did realize that at the end the print statement was erroring but it seems unrelated the the lines mentioned in this post. I'm not really sure what is going on but I might just deal with it. Commented Apr 5, 2022 at 17:55

1 Answer 1

0

I figured it out, its listed in this post (SyntaxError : Invalid syntax jedi) and if you're getting the error(s) in visual studio code then basically just disable and then re-enable your packages. worked like a charm for me.

Sign up to request clarification or add additional context in comments.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.