class has no attribute, even with self given as a parameter - Python -


i have following python class:

import sys import re  class parser:      def __init__(self, filename=""):         self.filename = filename      def parse(self):          try:             table = {}             fp = open(self.filename, 'r')             records = fp.readlines()             record in records:                 (index, column, value) = record.strip().split()                 value = value[:3]                 table[column] = value              return table          except ioerror:             print "could not open file ", self.filename             sys.exit(1)       def organize_map(self, table={}):          new_table = {             'profile_1': [],             'profile_2': [],             'profile_3': [],             'profile_4': []         }          k, v in table.iteritems():              if re.match("profile1", k):                 new_table['profile_1'].append(int(v))             elif re.match("profile2", k):                 new_table['profile_2'].append(int(v))             elif re.match("profile3", k):                 new_table['profile_3'].append(int(v))             elif re.match("profile4", k):                 new_table['profile_4'].append(int(v))            k, v in new_table.iteritems():             v.sort()             v = v[2:len(v)-2]             new_table[k] = v             new_table[k].append(avg(v))             new_table[k].append(std(v))          return new_table  parser = parser() table = parser.parse() print parser.organize_map(table) 

when execute parser.py file, get:

  file "parser.py", line 94, in <module>     print parser.organize_map(table) attributeerror: parser instance has no attribute 'organize_map' 

i don't know why ... defined organized_map() self keyword ... idea? sample file:

1: profile1_test_1 155700802.32 2: profile1_test_2 156129130.88 3: profile1_test_3 155961744.64 4: profile1_test_4 155917583.6 5: profile1_test_5 156193748.16 6: profile1_test_6 155749778.88 7: profile1_test_7 156040104.72 8: profile1_test_8 156934277.68 9: profile1_test_9 156976866.56 

you mix indentation tabs , spaces in source code, python interpreter interpret tabs differently expect. definition of organize_map indented tabs, ends seen local function inside of parse.

don't mix indentation tabs , spaces, leads confusion. can use python's -t parameter when running script warnings inconsistent indentations:

python -t myscript.py 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -