Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Python help

Name: Anonymous 2010-10-17 12:08

if operator != ("add"|"sub"):
    print ("Invalid Operator")

Basically I want to check if operator has anything other than "add" or "sub" assigned to it, but python 2.6 is saying

TypeError: unsupported operand type(s) for |: 'str' and 'str'

How should I check if operator is anything other than add or sub?

Name: Anonymous 2010-10-17 12:18

Im looking for a print function, it cant be printufu (thats japanese for printf) or any stdio function. It has to be of 2 or more parameteru (thats japanese for 2 parameters) and has be be chibi (small) sized. And has to be really kawaii (cute). Also It has to be about 10-20 bux. And you have to post documentation of it first (i want to make shure it's kawaii [cute]). And it would be nice if it came with matching input reading (WITH error handling). OH! and it CANNOT have any complicated syntax, or be made out of C. It has to be made of C++, or something like that. Also it would be nice if it was made in japan. and not in china or corea (korea) or whatever. I have found a function similar to the one im describing in sourceforge, but it was 1 parameteru, and i dont want my formatou (formatting) to touch my other things (it can get mixed up and i would not like that, plus 2 paraneters looks more kawaii)

Name: Anonymous 2010-10-17 12:19

nevermind, instead of | i used or.

Name: Anonymous 2010-10-17 12:36

>>2
lol'd, did you edit that yourself?

Name: Anonymous 2010-10-17 13:12

>>3
Protip: it's still not going to work.

Name: Anonymous 2010-10-17 13:15

Name: Anonymous 2010-10-17 16:04

if operator in ("add", "sub"):
    print "IHBT"

Name: Anonymous 2010-10-17 16:13

if not operator in ("add", "sub"):
    print ("Invalid Operator")

Name: Anonymous 2010-10-17 18:05

>>8
That parses to more tokens internally than the canonical
if operator not in ("add", "sub"):
    print("Invalid Operator")

Using the multi-word not in operator is more efficient[citation needed] than an in operator being later negated by a not operator.

Name: Anonymous 2010-10-18 6:05

>>8,9
Mr. 9, you fail.  This is why people take that "compilers" class in CS -- so they don't fail as badly as you do.


>>> import dis
>>> def func8(operator):
...     if not operator in ("add", "sub"):
...         print ("Invalid Operator")
...
>>> def func9(operator):
...     if operator not in ("add", "sub"):
...         print("Invalid Operator")
...
>>> dis.dis(func8)
  2           0 LOAD_FAST                0 (operator)
              3 LOAD_CONST               4 (('add', 'sub'))
              6 COMPARE_OP               7 (not in)
              9 POP_JUMP_IF_FALSE       25

  3          12 LOAD_GLOBAL              0 (print)
             15 LOAD_CONST               3 ('Invalid Operator')
             18 CALL_FUNCTION            1
             21 POP_TOP             
             22 JUMP_FORWARD             0 (to 25)
        >>   25 LOAD_CONST               0 (None)
             28 RETURN_VALUE        
>>> dis.dis(func9)
  2           0 LOAD_FAST                0 (operator)
              3 LOAD_CONST               4 (('add', 'sub'))
              6 COMPARE_OP               7 (not in)
              9 POP_JUMP_IF_FALSE       25

  3          12 LOAD_GLOBAL              0 (print)
             15 LOAD_CONST               3 ('Invalid Operator')
             18 CALL_FUNCTION            1
             21 POP_TOP             
             22 JUMP_FORWARD             0 (to 25)
        >>   25 LOAD_CONST               0 (None)
             28 RETURN_VALUE

Name: Anonymous 2010-10-18 10:17

>>10
YHBT

Name: Anonymous 2010-10-18 10:22

>>11
I hate you :(

Name: Anonymous 2010-11-15 9:26


Don't change these.
Name: Email:
Entire Thread Thread List