-2

My code is this:

highpri = yesno_prompt(
    ["1"], "Flag this message/s as high priority? [yes|no]")
if not "YES" in highpri:
    prioflag1 = ""
    prioflag2 = ""
else:
    prioflag1 = ' 1 (Highest)'
    prioflag2 = ' High'

But when I run it, I get:

Traceback (most recent call last):
  File "mailerproj.py", line 138, in <module>
    highpri = yesno_prompt(
NameError: name 'yesno_prompt' is not defined

So I tried:

highpri = input(

But it gives issue this issue:

Traceback (most recent call last):
  File "mailerproj.py", line 139, in <module>
    ["1"], "Flag this message/s as high priority? [yes|no]")
TypeError: [raw_]input expected at most 1 arguments, got 2

So in this case, is input the best but structured wrong or is yes/no prompt right but structured wrong?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    No idea what `yesno_prompt` is supposed to be, or what its arguments represent. `input` (or `raw_input`, in Python 2) takes only one argument, the prompt string `"Flag this message ... "`. – chepner Jul 13 '16 at 13:42
  • See http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input – cdarke Jul 13 '16 at 13:49

1 Answers1

0

This code shows a fundamental misunderstanding of how input() works in Python 3.

First, the input() function in Python 3 is equivalent to raw_input() in Python 2. Your error shows that you are using Python 2.

So let's read the error message you got:

We know what line the error is on:

  File "mailerproj.py", line 139, in <module>

And it shows us the line:

    ["1"], "Flag this message/s as high priority? [yes|no]")

And then it explains the issue:

TypeError: [raw_]input expected at most 1 arguments, got 2

This means you've given input() the wrong arguments - you've given it two ["1"] and "Flag this message/s as high priority? [yes|no]" and it expects one.

Here is the python help on raw_input:

Help on built-in function raw_input in module builtin:

raw_input(...)
    raw_input([prompt]) -> string

    Read a string from standard input.  The trailing newline is stripped. If the
    user hits EOF (Unix: Ctl-D, Windows: Ctl-Z+Return), raise EOFError. On Unix,
    GNU readline is used if enabled. The prompt string, if given, is printed
    without a trailing newline before reading.

So you need to give it one argument as input. This can be a string (e.g. "Hello") an integer (e.g. 125), a float (e.g. 3.14), a list, a tuple, a boolean and others. It returns a string into the variable.

You need your code to look more like this:

highpri = raw_input("[1] Flag this message as high priority? [yes|no] > ")
highpri = highpri.upper()  # Make the input uppercase for the if
if highpri != 'YES':       # If it is not yes, remove the flags.
    prioflag1 = ''
    prioflag2 = ''
else:                      # If the input is yes, set the flags.
    prioflag1 = '1 (Highest)'
    prioflag2 = 'High'
Tim
  • 2,563
  • 1
  • 23
  • 31
  • That fixed my issue. I didn't realize it was taking [1] as it's own argument. Just removing `[1],` fixed the error and runs the script in terminal. Thanks for the breakdown! – JDerringer Jul 13 '16 at 14:14