TypeError: 'file' object is not subscriptable python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gonzalo Gonza
    New Member
    • Nov 2010
    • 16

    TypeError: 'file' object is not subscriptable python

    When I execute this code (if the number finishes in 2 returns true, else none)

    Code:
    def asdf(n):
    	n=str(m)
    	elif m[-1]==2:
    		return True

    I get the following Error:
    Code:
    Traceback (most recent call last):
    File "C:\***\***.py", line 3, in asdf
        elif int(m[-1])==2:
    TypeError: 'file' object is not subscriptable

    I also tried
    Code:
    elif int(m[-1])==2:
    But's the same
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Variable m is not defined in function asdf(). Maybe you meant def asdf(m):?

    To return an index of an object, the object must be a sequence type such as a string, list or tuple.

    Comment

    Working...