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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:57:03+00:00 2026-06-17T16:57:03+00:00

I am using python’s trace module to trace the execution of some code. I

  • 0

I am using python’s trace module to trace the execution of some code. I notice that when the execution is later printed, it is printed in the following form (min working example follows below):

<filename>(<line number>): <line of code>

Is possible to get the full (either absolute or relative) file path instead of just the file name. It makes sense that there would be a flag somewhere in the call to trace.Trace that should allow me to do this, but I don’t seem to be able to find any such parameter in the docs.

If such a flag does not exist, how would I go about getting the file path? I guess I could check all the directories in sys.path, but how would I then handle cases where two distinct directories have files with the same name?

  • 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-17T16:57:04+00:00Added an answer on June 17, 2026 at 4:57 pm

    It wasn’t very obvious, but I’ve found that if I use the countfuncs parameter in trace, or the --listfuncs parameter if I’m using trace from the command line, I get full path names. Thus, for the program:

    import trace
    from recurse import recurse
    
    tracer = trace.Trace(count=False, trace=True, countfuncs=True)
    tracer.run('recurse(2)')
    tracer.results().write_results()
    

    … (using Doug Hellmann’s example from here) I get the following output:

    functions called:
    filename: <string>, modulename: <string>, funcname: <module>
    filename: C:\Python33\lib\encodings\cp850.py, modulename: cp850, funcname: IncrementalEncoder.encode
    filename: C:\Python33\lib\trace.py, modulename: trace, funcname: _unsettrace
    filename: C:\usr\sjl\dev\test\python\recurse.py, modulename: recurse, funcname: recurse
    

    This isn’t quite what you were looking for because you can see it is ignoring the instruction to trace the lines of code, so it doesn’t give the file path next to those lines of code. However, it does tell you exactly which files were being used by the Python script.

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

Sidebar

Related Questions

Using python 2.7, I have the following code: if result != None: (data,) =
Using Python v2, I have the following code: print (Total of the sale is:
Using Python's csv module, is it possible to read an entire, large, csv file
Using Python module re, how to get the equivalent of the \w (which matches
Using python and wsgiref.handlers, I can get a single variable from a form with
Using python I would like to monitor a .avi raw RGB video file that
Using Python 's PIL module, we can read an digital image into an array
Using Python I want to create a symbolic link pointing to a path that
Using python's optparse module I would like to add extra example lines below the
Using python to pick it some pieces so definitely a noob ? here but

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.