victorsionado
victorsionado

Reputation: 99

Attribute Error 'NoneType' object has no attribute

I've been trying this code but I keep getting the same result, which is:

if Prep.endswith ('jpg'): AttributeError:'NoneType' object has no attribute 'endswith'

  import re
result = "hey(14).jpg"

Prep = print(re.sub(r" ?\([^)]+\)", "", result))

if Prep.endswith ('jpg'):
    Caption = print(Prep.replace("jpg", "is jpg"))
elif Prep.endswith ('png'):
    Caption = print(Prep.replace("png", "is png"))
elif Prep.endswith ('gif'):
    Caption = print(Prep.replace("gif", "is gif"))
else :
    Caption = print("Unknown")

I dont know where this comes from.

Any help will be apreciated.

Cheers.

Upvotes: 0

Views: 1384

Answers (1)

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137398

The problem is here:

Prep = print(re.sub(r" ?\([^)]+\)", "", result))

You're assigning the return value of print to Prep and then later trying to use it. The problem is that print doesn't return anything -- in other words, it always returns None.

You want this:

Prep = re.sub(r" ?\([^)]+\)", "", result)
print(Prep)

Upvotes: 2

Related Questions