0

I'm getting an invalid syntax error on the "for account in accounts" loop, why?

Please help, I've been struggling with this for a bit now

app.send(
    functions.channels.InviteToChannel(
        channel=app.resolve_peer("xyz123"), 
        users=[
            for account in accounts:
                app.resolve_peer(accounts)
        ]
    )
)
1
  • 1
    [app.resolve_peer(accounts) for account in accounts] is a list comprehension, not a for-loop. You're confusing the two. A list comprehension is an expression which returns a list of some sort. A for-loop is a command, not an expression. Commented Aug 14, 2018 at 7:09

1 Answer 1

2

You want to use list comprehension:

app.send(
    functions.channels.InviteToChannel(
        channel=app.resolve_peer("xyz123"), 
        users=[
            app.resolve_peer(account) for account in accounts     
        ]
    )
)
Sign up to request clarification or add additional context in comments.

4 Comments

You have an extra colon at the end of your comprehension
Presumably you mean app.resolve_peer(account), not app.resolve_peer(accounts)
Yes that would make more sense :)
Thank you so much.

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.