Home Verilog Digital Design Digital Basics Python RF Basics

Legal Disclaimer

Chip Designing for ASIC/ FPGA Design engineers and Students
Digital-logic Design...  Dream for many students… start learning front-end…
Custom Search

Feedback ? Send it to admin@fullchipdesign.com or join me at fullchip@gmail.com

Python File read operations Class & global var File write op's Glob module Conditional stms String 2 hex UNIX in Python Diamond Pattern TypeError - arg TyprError - str TypeError - strconv AttributeError Function call Read bin files

Legal Disclaimer

Topics @TYH :- 4G LTE Tutorial, GVIM editor, Smart-Phone, Cloud Computing
Previous Next
Verilog Tutorial.
Digital Basics Tutorial.

Python common error messages - TypeError-str

TypeError: 'str' object is not callable
Lets run a program to generate the error

import sys
class tables:
   def __init__(self,w):
       # 2.4 Definitions of tables for the FSM
       ans = self.T0_r(w)
       print "Result = %s"  (ans)
    def T0_r(self, w):
       self.w = w
       self.s1_t0_r = self.T0[self.w]
       return self.s1_t0_r
    def tables_ls(self):    
        self.T0 = ['0xFF563C6' ,'0x84FF7CF8'
,'0x897788EE' ,'0x8EFB7BF6',
               '0xFE2F2FF ' ,'0xBCAF6BD6'
,'0xAA6F6FDE' ,'0xFFC5C591']

def main ():
# Read elemant 4 of the table array by calling class
   y = tables(0x4)

Traceback (most recent call last):
 File "calling_classes.py", line 28, in ?
 File "calling_classes.py", line 26, in main
   y = tables(0x4)
 File "calling_classes.py", line 12, in __init__
   print "Result = %s"  (ans)
TypeError: 'str' object is not callable

        print "Result = %s"  (ans)
        Instead of
       print "Result = %s" % (ans)

So the updated code becomes

Python Resources


Open and read file from within the python program as a single string.

Command line arguments lists as string with ‘sys.argv’.


Use of  glob module in Python code 


Read file using classes, global variables and

functions. Program to open and write file.


Specify files to be written from the command

line. File writes using classes and global



Steps for conditional statements, converting

string to hexadecimal value, strip of white space

at end ,converting 12 bit hexadecimal values to

12 bit signed values.


Advanced program to read file, filter text, conversion to HEX, conversion from Hexadecimal to Signed Magnitude


Advanced python code to cover UNIX shell commands, read lines from a text file, ‘sysargv’ command line operations, use of class and multiple functions. 


Write a program to generate diamond pattern.


Python error’s with complete code examples:-

TypeError: __init__() takes exactly 2 arguments (1 given),

TypeError: 'str' object is not callable,

TypeError: not all arguments converted during string formatting,

AttributeError:  ** instance has no attribute **


Implement Python function calls to different classes.


Python read binary files, use of struct.unpack.