what am I missing (syntax error)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • orangeDinosaur

    what am I missing (syntax error)

    Here's a section of code:

    for x in occupants:
    if x not in uniqueUsers and not in staff: uniqueUsers.app end(x)
    elif x in staff and not in uniqueStaff: uniqueStaff.app end(x)

    When I try to import the module with the function definition that
    contains this code, I get a syntax error pointing to the 'in' after the
    'and not in staff'. I can't figure out why this is bad syntax. Both
    'uniqueUsers' and 'staff' are lists.

    thanks for your help!

  • James Thiele

    #2
    Re: what am I missing (syntax error)

    Try:
    for x in occupants:
    if x not in uniqueUsers and x not in staff:
    uniqueUsers.app end(x)
    elif x in staff and x not in uniqueStaff:
    uniqueStaff.app end(x)

    Comment

    • Alex Martelli

      #3
      Re: what am I missing (syntax error)

      orangeDinosaur <trevis.crane@g mail.com> wrote:
      [color=blue]
      > Here's a section of code:
      >
      > for x in occupants:
      > if x not in uniqueUsers and not in staff: uniqueUsers.app end(x)
      > elif x in staff and not in uniqueStaff: uniqueStaff.app end(x)
      >
      > When I try to import the module with the function definition that
      > contains this code, I get a syntax error pointing to the 'in' after the
      > 'and not in staff'. I can't figure out why this is bad syntax. Both
      > 'uniqueUsers' and 'staff' are lists.[/color]

      say ...'and x not in staff' -- you need the x between 'and' and 'not',
      and similarly for the elif (and don't use tabs -- they make a mess of a
      display on many newsreaders etc -- fixed to spaces above).


      Alex

      Comment

      • Gerard Flanagan

        #4
        Re: what am I missing (syntax error)


        orangeDinosaur wrote:[color=blue]
        > Here's a section of code:
        >
        > for x in occupants:
        > if x not in uniqueUsers and not in staff: uniqueUsers.app end(x)
        > elif x in staff and not in uniqueStaff: uniqueStaff.app end(x)
        >
        > When I try to import the module with the function definition that
        > contains this code, I get a syntax error pointing to the 'in' after the
        > 'and not in staff'. I can't figure out why this is bad syntax. Both
        > 'uniqueUsers' and 'staff' are lists.
        >
        > thanks for your help![/color]

        I think you're missing an 'x':

        for x in occupants:
        if x not in Users and x not in Staff:
        Users.append(x)

        Gerard

        Comment

        • Jorge Godoy

          #5
          Re: what am I missing (syntax error)

          "orangeDinosaur " <trevis.crane@g mail.com> writes:
          [color=blue]
          > Here's a section of code:
          >
          > for x in occupants:
          > if x not in uniqueUsers and not in staff: uniqueUsers.app end(x)
          > elif x in staff and not in uniqueStaff: uniqueStaff.app end(x)
          >
          > When I try to import the module with the function definition that
          > contains this code, I get a syntax error pointing to the 'in' after the
          > 'and not in staff'. I can't figure out why this is bad syntax. Both
          > 'uniqueUsers' and 'staff' are lists.[/color]

          The question is: "what's not in XXX"? x? Something else? You hve to
          remember that the computer does only what you tell it to do:

          if x not in uniqueUsers and x not in staff: ...

          I also prefer using parenthesis to make things more clear and avoid precedence
          surprises.

          --
          Jorge Godoy <godoy@ieee.org >

          "Quidquid latine dictum sit, altum sonatur."
          - Qualquer coisa dita em latim soa profundo.
          - Anything said in Latin sounds smart.

          Comment

          • orangeDinosaur

            #6
            Re: what am I missing (syntax error)

            OK, thanks!

            Comment

            Working...