2

I have a function that utilizes both a default parameter and *args:

def greeting(name, *args, exclamation='yo!'):
    for arg in args:
        print(name, arg, exclamation)

This seems to work fine. However, when I check it with flake8, it returns:

1 col 38| E901 SyntaxError: invalid syntax

I am stickler for both following correct practice and having my checks clear. Am I doing this wrong? Is a different method standard?

8
  • 2
    In Python 3, this is legal but exclamation would be a keyword-only argument, meaning it'd have to passed like greeting('Joe', some, args, exclamation='!'). Useful, but not necessarily what you want. Commented Jul 14, 2013 at 19:52
  • @delnan No, you wouldn't have to specify it if it has a default value(like in OP's example). Commented Jul 14, 2013 at 21:06
  • @Bakuriu Yes, my wording was ambiguous. It wouldn't have to be passed, but if it was passed it would have to be passed in this manner rather than positionally. Commented Jul 14, 2013 at 21:09
  • I probably missed the like just before the code :s Commented Jul 14, 2013 at 21:12
  • This is just a long shot, but is flake8 calibrated for Python 3.x? Your code runs fine in Python 3.x but crashes in 2.x, leading me to believe that your version of flake8 is for 2.x. Commented Jul 14, 2013 at 21:43

1 Answer 1

1

As iCodez guessed, this was the result of unintentionally using a version of flake8 designed for Python 2.x. Installing the Python 3 version with sudo pip-3.2 install flake8 solved the problem.

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

Comments

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.