How do you cast the wrong text?



  • I have to redo the NameError mistake, but I don't really understand how. ♪ ♪
    I really hope for your help.
    It's a setup:

    try:
       # do something
       pass
    except NameError:
        print('Я такого - НЕ ЗНАЮ!')
    


  • Try this one way:

    try:
        raise NameError
    except NameError:
        raise NameError('Custom NameError Message!')
    

    Test script:

    import sys
    

    print(sys.version)

    try:
    raise NameError
    except NameError:
    raise NameError('Custom NameError Message!')

    Output Python 2.7.8:

    2.7.8 (default, May 19 2015, 02:50:14)
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
    Traceback (most recent call last):
    File "a.py", line 8, in <module>
    raise NameError('Custom NameError Message!')
    NameError: Custom NameError Message!

    Output Python 3.3.2:

    3.3.2 (default, Mar 20 2014, 20:25:51)
    [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]
    Traceback (most recent call last):
    File "a.py", line 6, in <module>
    raise NameError
    NameError

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "a.py", line 8, in <module>
    raise NameError('Custom NameError Message!')
    NameError: Custom NameError Message!




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2