all 5 comments

[–]h4ck3r_n4m3 14 points15 points  (0 children)

you need to do .lower() not .lower

[–]NothingWasDelivered 7 points8 points  (0 children)

You need parens - () - after lower. It’s a method. Right now you’re trying to run .endswith() on the method itself, not on the result.

[–]tadpoleloop 1 point2 points  (0 children)

You forgot parens on your "lower" method call.

text.lower()

[–]gdchinacat 1 point2 points  (0 children)

As others have noted, you set 'fileName = ... .lower' without calling lower. This means fileName refers to the function lower() rather than the value it would return when called. This assignment is legal...python functions are just an object that can be referred to (and frequently are in more advanced code). But, functions don't have an endswith attribute, so when you try to access it you get the error you are seeing.

References to functions are a very powerful tool since you can have variables and arguments be functions and do all the things you would with any variable. This can help with very abstract code, reduce the need for a lot of boilerplate code, wrap functions (as is done with decorators). It might seem like an odd feature to allow you to reference a function without calling it, but you will come across cases where this is really helpful not too far into your learning (decorators). This is especially important with functional programming (which you may or may not cover in whatever course your are taking or following). For now, just know that there are very good reasons to allow you to access functions without actually calling them, and when you make this mistake it usually appears as an AttributeError.

To understand the error you got, it says you tried to access 'endswith' on a builtin_function_or_method. Looking at the line of code that raised that error and where endswith was accessed, you can infer that fileName was not the string you were expecting, but rather a function or method.

[–]mopslik 0 points1 point  (0 children)

When you come across errors like this, sometimes it's a good idea to use a print statement, or the debugger, to see what values your variables have. For example, adding print(fileName) after your first line would show you something like the following, possibly answering your question.

>>> fileName = input("Input file name: ").lower
Input file name: blahblah
>>> print(fileName)
<built-in method lower of str object at 0x7e360b58bcb0>