0

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.

0

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that was it, since I am new at coding and learing "the hard way", I was not aware of this, I really thank you for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.