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

  • Home
  • SEARCH
  • 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 8082981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:18:30+00:00 2026-06-05T17:18:30+00:00

When error occured Python prints something like this: Traceback (most recent call last): File

  • 0

When error occured Python prints something like this:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "<stdin>", line 8, in m
  File "<stdin>", line 5, in exec_st
  File "<stdin>", line 9, in exec_assign
  File "<stdin>", line 48, in ref_by_id
IndexError: list index out of range

where 2, … , 48 are relative line numbers which are not very convenient. How to print absolute line numbers in such error messages?

EDIT:
Maybe it’s a dumb question, but answer will facilitate development a little.
I’m printing text in several files. When done, press shortcut which runs python and copies contents of current file to console. Proposed solution forces to press excess keystrokes (Ctrl+S, Alt+Tab) and create additional files. I hope I have put it clear.

  • 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-05T17:18:33+00:00Added an answer on June 5, 2026 at 5:18 pm

    A few minutes of hacking around gives me this Read-Eval-Print Loop in Python 2.7:

    #!/usr/bin/env python
    import code
    import sys
    
    LINE_NUMBER=0
    
    def reset_linenum():
        global LINE_NUMBER
        LINE_NUMBER=-1
    
    def resettable_REPL():
        global LINE_NUMBER
        BUFFERED_LINES=[]
        ii=code.InteractiveInterpreter({"reset_linenum":reset_linenum})
        while True:
            try:
                BUFFERED_LINES.append(raw_input("!"+sys.ps1)+'\n')
                while (BUFFERED_LINES[-1][:1] in " \t" or
                       ii.runsource("\n"*LINE_NUMBER+"".join(BUFFERED_LINES), "console")):
                    BUFFERED_LINES.append(raw_input("!"+sys.ps2)+'\n')
                LINE_NUMBER+=len(BUFFERED_LINES)
                BUFFERED_LINES=[]
            except EOFError:
                break
    
    if __name__=='__main__':
        resettable_REPL()
    

    It’s a bit hackish, but it keeps track of line numbers as the session continues, and allows the current count to be reset by a call to reset_linenum(). An example session:

    !!!> print "hello"              # line 1
    hello
    !!!> def badfunc():             # line 2
    !...     raise Exception("doh") # line 3
    !!!> badfunc()                  # line 4
    Traceback (most recent call last):
      File "console", line 4, in <module>
      File "console", line 3, in badfunc
    Exception: doh
    !!!> ?                          # line 5
      File "console", line 5
        ?
        ^
    SyntaxError: invalid syntax
    !!!> reset_linenum()            # RESET
    !!!> raise Exception("!")       # line 1
    Traceback (most recent call last):
      File "console", line 1, in <module>
    Exception: !
    !!!> 
    

    EDIT: Fixed REPL to not execute indented blocks quite so prematurely.

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

Sidebar

Related Questions

I encountered this error: Cannot implicitly convert type System.Web.UI.WebControls.LoginView to Login The error occured
An error occurred at line: 9 in the jsp file: /Test1.jsp The method addURL(String,
I got this error An error occurred while parsing EntityName. Line 1, position 61.
I am trying to look a file that looks who's path looks like this.
I tried to use pp(Parallel Python) like this: import glob import subprocess import pp
Occured error(return 403 Forbidden) when upload a Photo without metadata to Picasa web album.
I'm getting an odd error with Google App Engine devserver 1.3.5, and Python 2.5.4,
I have created a python web app with this directory structure: # cd /usr/local/www/myapp
Okay so this is what I'm trying to do in my python socket server.
I'm trying to crate a data structure sort of like a dictionary in Python,

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.