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 8129523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:20:34+00:00 2026-06-06T08:20:34+00:00

I am just about done writing my first mergesort program and am running into

  • 0

I am just about done writing my first mergesort program and am running into trouble when compiling. I have done a bunch of research on this particular error and it seems I’m being non-specific somewhere in my code. I still cannot find said error and would love your help. I have attached the file contents, code, and traceback. Thanks again.

File:

999 Message C1 
1033 Message C2 
1054 Message C3 
1056 Message C4 
1086 Message C5

Code:

DEBUG = True
out = []

logs = open("C:\Users\----\Desktop\logs.txt", mode ="r")

lines = logs.readline()

def debug(s):
    if DEBUG:
        print "DEBUG: ", s

def get_t (line):
    s = line
    s = s.lstrip()
    debug(s)
    i = s.find(" ")
    debug(s)
    s = s[:i]
    return int(s)

def get_lowest_i(logs):
    lowest_i = -1
    for i in range(len(logs)):
        log = logs[i]
        debug("log=" + repr(log))
        if log:
            t = get_t(log[0])
            debug("t=" + repr(t))
            if lowest_i == -1 or t < lowest_t:
                lowest_i = i
                lowest_t = t
    return lowest_i

def get_line_lowest_t(logs):
    while True:
        i = get_lowest_i(logs)
        if i == -1:
            break
        line = logs[i].pop(0)

def mergesort(logs):
    while True:
        line = get_line_lowest_t(logs)
        if line == None:
            break
        out.append(line)
    return out

print mergesort(logs)

f.close()

Traceback:

Traceback (most recent call last):
  File "<module1>", line 50, in <module>
  File "<module1>", line 44, in mergesort
  File "<module1>", line 37, in get_line_lowest_t
  File "<module1>", line 24, in get_lowest_i
TypeError: object of type 'file' has no len()

Thanks in advance.

  • 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-06T08:20:36+00:00Added an answer on June 6, 2026 at 8:20 am

    TypeError: object of type 'file' has no len() the error says it all you are trying to read the length of a file object … being that logs = open("C:\Users\----\Desktop\logs.txt", mode ="r") is a file maybe you mean to read the lines of the file and sort that … lines = longs.readlines() print mergesort(lines)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just about done writing a killer application for the mac, however I
I'm just about getting into WCF ; but from what I've read so far,
I'm just about to write my first application in a duck typed language (Groovy).
While writing a post about project euler's 14th problem I ran into a difference
I am currenty writing my master's thesis about monitoring of distributed systems. For this
So I'm writing this EXE to process refunds, and when the job's done, we're
Has anyone done something like this? How? I'm just starting a project that will
I'm writing my first NSEntityMigrationPolicy right now and this one is pretty simple. It
Just a quick question about my Domain Layer/ Domain Service... Should I allow this
I'm a student just learning xml and c#. I'm writing a program that will

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.