TypeError: unsubscriptable object

enas khalil enas_khalil at yahoo.com
Mon Nov 28 18:21:19 EST 2005


when i run this script to make a training of some text and so can use condfreqdistributions to guess text in test , my code isas follows:
  
from nltk.probability import ConditionalFreqDist
from nltk.tokenizer import WhitespaceTokenizer
from nltk.tagger import *
token1 = []
train_tokens = []
cfdist=ConditionalFreqDist()
# open the file containning the training tagged data
dd= open("fataha.txt").readlines() # generate a string 
   
  # open the file containning the training tagged data
data2= (open("besm.txt").read())# generate a string 
  corpus=Token(TEXT=data2)# convert string to token to tokenize it 
WhitespaceTokenizer(SUBTOKENS='WORDS').tokenize(corpus)
#print unicode('\xc8\xd3\xe3','cp1256')
  for xx in corpus['WORDS'] :
     token1.append(xx['TEXT'])
     
for item in dd:
    train_tokens.append(item)
    
    l=len(item)
     i=int(item.find("="))
    
    aa=Token(TEXT=item)
    aa['WORDS']=item[0:i]
     aa['TAG']=item[i+1:l+1]
     j=int(item.find('-'))
    print j
    pos=item[j+1:i]
    
    word=item[:j]
    
    train_tokens.append(aa)
      for xx in token1:
        if  word==xx:
            print 'hi'
            cond=cfdist.conditions()
              for cond in word :cfdist[cond].inc[aa['TAG']]
  i got this error :
  Traceback (most recent call last):
  File "F:\MSC first Chapters\28-11\firstprog1.py", line 53, in -toplevel-
    for cond in word :cfdist[cond].inc[aa['TAG']]
TypeError: unsubscriptable object
   
   what does  unsubscriptable object this means , and how can ihandle it 
   
  also if you please suggest me a good refrence in how to handle different types of objects in python as token ,and how i can generate different token attributes 
  thanks

		
---------------------------------
 Yahoo! Music Unlimited - Access over 1 million songs. Try it free.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051128/08402b57/attachment.html>


More information about the Python-list mailing list