Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid syntax error using := #2

Open
DrBwts opened this issue May 11, 2022 · 2 comments
Open

Invalid syntax error using := #2

DrBwts opened this issue May 11, 2022 · 2 comments

Comments

@DrBwts
Copy link

DrBwts commented May 11, 2022

Pthyon 3.8

I'm using the following code from the examples on the docs page,

import schemdraw
from schemdraw import logic

with schemdraw.Drawing() as d:
    d.config(unit=0.5)
    d += (S := logic.Xor().label('S', 'right'))
    d += logic.Line().left(d.unit*2).at(S.in1).idot().label('A', 'left')
    d += (B := logic.Line().left().at(S.in2).dot())
    d += logic.Line().left().label('B', 'left')
    d += logic.Line().down(d.unit*3).at(S.in1)
    d += (C := logic.And().right().anchor('in1').label('C', 'right'))
    d += logic.Wire('|-').at(B.end).to(C.in2)

This throws the folloiwng error,

  File "D:\Python codes\temp.py", line 11
    d += (S := logic.Xor().label('S', 'right'))
            ^
SyntaxError: invalid syntax

Any idea why this is happening?

@MehdiAitIghil
Copy link

I just tested it (Python 3.9.4, win 10, schemdraw 0.14) and works perfectly fine.
Seem's like you have issues with the walrus operator.
Are you sure you are using Python>3.8 (FYI https://docs.python.org/3/whatsnew/3.8.html)
Anyway, you can circumvent the issue by explicitly declaring de variables before adding it to the drawing :
S = logic.Xor().label('S', 'right')
d += S

@DrBwts
Copy link
Author

DrBwts commented May 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants