By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,675 Members | 2,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,675 IT Pros & Developers. It's quick & easy.

TypeError: 'file' object is not subscriptable python

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

Expand|Select|Wrap|Line Numbers
  1. def asdf(n):
  2.     n=str(m)
  3.     elif m[-1]==2:
  4.         return True

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

I also tried
Expand|Select|Wrap|Line Numbers
  1. elif int(m[-1])==2:
But's the same
Nov 16 '10 #1

✓ answered by bvdet

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.

Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
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.
Nov 17 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.