python - How do I escape Trackback or any kind of errors Errors? -


How to write a proper statement to avoid an error in Python ... Suppose

Example

  import base64 encode = base64.b64encode (raw_input ('insert data:')) data = base 64.b64 dxod (encode) print 'Your encoded message is:' + encode Print '.' Print '.' Print '.' Print '.' Print '.' Decode = base64.b64decode (raw_input (enter 'encoded data:')) data2 = base64.b64decode print ('encoded') is your encoded message: '+ decode  

now this script only The raw data encodes and decodes the error occurs when I enter the normal data in 'enter encoded data': ' I anticipate some errors, such as sorry!

What you are looking for is a try - splitting: statement

 < Code> decode = there is no decode: try: decode = base64.b64decode (raw_input (enter 'encoded data:')) except data2 = base64.b64decode (encoded): print 'sorry! The data you entered is to be encoded. 'Print' is your encoded message: '+ Decode  

Comments