Python Forum
'str' object is not callable
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'str' object is not callable
#1
I'm having issues with my code where I'm getting 'str' object is not callable error, but I'm not assigning anything to str, and the rest of the variable assignments look right. Likewise, parentheses are properly placed, so far as I can tell. Strings also seemly properly enclosed with single or double quotes (see code below).

#!/usr/local/bin/python3.4

import re, sys, time, logging, os, platform, pprint, configparser

def ParseSpreadsheet(cfg):

    ranges_per_field = cfg["data"]["cell_ranges"].split('\n')
    flds = ()

    for range in ranges_per_field:
        (cols, start_row, end_row) = range.split()

        #print("Cols is " + str(cols) + ", start row is " + str(start_row) +", end row is " + str(end_row))
        col_list = cols.split(',')
        for row in list(range(int(start_row), int(end_row))):
            print(str(row))


cfg = configparser.ConfigParser()
cfg.read('test.cfg')
ParseSpreadsheet(cfg)
This is the configuration file it reads:

$ cat test.cfg
[input]
infile = Broadcast Server Naming Convention.xlsx
#infile = your_file.xlsx

[data]
tab_name = Field Data
# Format is:
# start column for field  end column for field  end row for field
# For example, B D 380 means data starts in column B, ends in D, and starts row 4, ends at row 380
fld_lengths = 3,3,3,4,2,5,0 # Domain name has no limit
cell_ranges = B,C,D 4 380
              F,G,H 4 380
              J,K,L 4 200
              N,O,P 4 200
              R,S,T 4 4
              V,W,X 4 50
              Y,Z,AA 4 50
And I get this when I run it:

$ ./test.py
Traceback (most recent call last):
  File "./test.py", line 21, in <module>
    ParseSpreadsheet(cfg)
  File "./test.py", line 15, in ParseSpreadsheet
    for row in list(range(int(start_row), int(end_row))):
TypeError: 'str' object is not callable
Any thoughts on why I'm getting this?
Reply
#2
Quote: for range in ranges_per_field:
You are overwriting builtins. Dont use builtin names for variables because range() now is trying to call your variable instead of the builtin
Recommended Tutorials:
Reply
#3
Thanks! Replacing that worked.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  error in class: TypeError: 'str' object is not callable akbarza 2 502 Dec-30-2023, 04:35 PM
Last Post: deanhystad
  TypeError: 'NoneType' object is not callable akbarza 4 986 Aug-24-2023, 05:14 PM
Last Post: snippsat
  [NEW CODER] TypeError: Object is not callable iwantyoursec 5 1,345 Aug-23-2023, 06:21 PM
Last Post: deanhystad
  Need help with 'str' object is not callable error. Fare 4 825 Jul-23-2023, 02:25 PM
Last Post: Fare
  TypeError: 'float' object is not callable #1 isdito2001 1 1,074 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  'SSHClient' object is not callable 3lnyn0 1 1,168 Dec-15-2022, 03:40 AM
Last Post: deanhystad
  TypeError: 'float' object is not callable TimofeyKolpakov 3 1,437 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov
  API Post issue "TypeError: 'str' object is not callable" makeeley 2 1,905 Oct-30-2022, 12:53 PM
Last Post: makeeley
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 5 1,587 Aug-28-2022, 07:11 AM
Last Post: Melcu54
  [split] TypeError: 'int' object is not callable flash77 4 2,751 Mar-21-2022, 09:44 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020