Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError ?
#1
Good.

Can someone give me a hint how do I treat this o 'NoneType' object has no attribute 'string' ? Because I need to print an error message on the screen.

Att,
João Carlos.
Reply
#2
It would help to see the code and the full traceback, but why are you trying to do anything with a None value? If you don't expect it to be None, then work backwards and find out why it is.
Reply
#3
I bet if your go to the error line you'll find a "." where it shouldn't be. It's likely a punctuation typo... my guess.
Reply
#4
(Mar-09-2020, 07:17 PM)ndc85430 Wrote: It would help to see the code and the full traceback, but why are you trying to do anything with a None value? If you don't expect it to be None, then work backwards and find out why it is.

The code below exemplifies the validation of a string through regular expression. If the string is valid it means that the data is safe and if the string is invalid it means unsafe data that is why I need to handle the error for decision making:

import re

ws_string = '/search?keyword=borracha&qt=20&preço=100,00'

ws_text = re.match(r'^[A-ZÁÀÂÃÇÉÊẼÍÓÔÕÚ a-záàâãçéêẽíóôõú0-9/?=&$.,]{1,99}$', ws_string)

ws_output = ws_text.string

if ws_output == ws_string:
    print('Security Data')
else:
    how to handle the error, because it generates the error quoted in the topic in the terminal ?
Reply
#5
re.match returns re.Match if a match is found, else None. None.string returns the message you are seeing.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020