thekindlyone
thekindlyone

Reputation: 509

syntax error in trying to create new list

Just trying to write a function that gets clock hand angles, but getting an error where i try to create an empty list. It has worked on other scripts previously without any issues.

def gethandpos():
    now=datetime.datetime.now()
    datetime.time(now.hour,now.minute,now.second)
    m=float(now.minute+now.second/60)
    h=float(now.hour+(m/60))
    hangle=math.fabs(((h*360)/12)-90)
    mangle=math.fabs(((m*360)/60)-90)
    sangle=(math.fabs((float((now.second*360)/60))-90)
    coords=[]
    coords.append((math.cos(math.radians(sangle)),math.sin(math.radians(sangle))))
    coords.append((math.cos(math.radians(mangle)),math.sin(math.radians(mangle))))
    coords.append((math.cos(math.radians(hangle)),math.sin(math.radians(hangle))))
    print coords

output:

coords=[]
     ^
syntax error: invalid syntax

what am I doing wrong?

Upvotes: 0

Views: 1853

Answers (2)

ben w
ben w

Reputation: 2535

sangle=(math.fabs((float((now.second*360)/60))-90)
       1         23     45              1   23   4

Upvotes: 3

Sven Marnach
Sven Marnach

Reputation: 601869

The line

sangle=(math.fabs((float((now.second*360)/60))-90)

has an additional opening parenthesis in the beginning. Try

sangle = math.fabs(float(now.second * 360 / 60) - 90)

instead.

Python ignores linebreaks inside parentheses. That's why the following line was interpreted as part of the assignment to sangle, leading to a syntax error.

I recommend to format your code in a more readable way: use spaces around operators, don't use too many parentheses where they are unnecessary, split complex expression into multiple steps etc.

Upvotes: 1

Related Questions