I am trying to write a simple Rot13 Encoder/Decoder that takes a string and encodes/decodes it using the "codecs" module. I am trying to define a function using: codecs.encode('rot13_text', 'rot_13')
I have no problem using using the codecs module outside of a function. When I attempt to define a function using codecs.encode(rot13_text, 'rot_13') I receive a NameError
So far I have attempted many variations of the following code:
import codecs
def rot13_encoder():
rot13_text = input("Type the text to be encoded: ")
codecs.encode(rot13_text, 'rot_13')
print(rot13_text)
Terminal Output
>>> def rot13_encoder():
... rot13_text = input("Type the text to encode and press enter: ")
... codecs.encode(rot13_text, 'rot_13')
... print(rot13_text)
...
>>> rot13_encoder()
Type the text to encode and press enter: HELLO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in rot13_encoder
File "<string>", line 1, in <module>
NameError: name 'HELLO' is not defined
>>>
rot_13encoder/decoder. How have you registered your codec to begin with?rot_13codec, at least in some versions of python. (also, hi :)python-3.xso I assume that's what they're using. (Hi!)python 3.7.3.python-2.xandpython-3.x; I'm not sure when it was introduced to 2.x, but it was apparently missing from 3.x versions before 3.2.