Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8298473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:47:12+00:00 2026-06-08T15:47:12+00:00

I am trying to read / count the character on the file (which is

  • 0

I am trying to read / count the character on the file (which is located in line 2)

all the even line of the file looks similar to this:

—————LL—NE–HVKTHTEEK—PF-ICTVCR-KS———-

here is my code so far but I got the error saying:

for character in len[(line2)]:
TypeError: ‘builtin_function_or_method’ object is not subscriptable

 with open(filename) as f:
    for line, line2 in itertools.izip_longest(f, f, fillvalue=''):
        tokenizer=line.split()
        print line, line2
        print tokenizer[4]
        for character in len[(line2)]:
           print 't'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:47:17+00:00Added an answer on June 8, 2026 at 3:47 pm

    the problem is that len is a builtin function (len(mystring) returns an integer which is the number of characters in the string). You can’t subscript it (i.e. using square brackets with it will result in the TypeError you’ve referenced in your question). I’m not really sure what you’re trying to do here, maybe you want:

     for character in line2:
         print character
    

    or maybe you want:

     for i,character in enumerate(line2):
         print i,character
    

    From the comments, I’m still having a hard time picking up what you want, but I think you might want something like this:

    tokenizer = line.replace('-',' ').split()[4]
    idx = line.index(tokenizer)
    count = line[:idx].count('-')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read a line from a file character by character and place
I'm trying to figure out how I would read a file, and then count
I'm trying to write some PHP that will read a CSS file, find all
I'm trying to read a file which is encoded in ISO-8859(ansi), and it contains
I'm trying to read a binary file with the count of the elements at
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =
Iam trying to read a binary file to memory and pass the starting address
I was trying to read a self-extracting zip (located here ftp://ftp.dnr.state.oh.us/OilGas/Download/Production/By_Year/2010Production.exe ) using java
I am trying to read in an XML file that I have saved to
I am trying to read from a file using fgets and sscanf. In my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.