Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trace library
#1
Lightbulb 
Hi, I'm hoping someone could explain how the trace library in Python works. In this class, I am taking a significant portion of it, is tracing my code output to a non-executable markdown file. To show step by step what Python compiles line by line and what the final result of code is. Below is an example of what I am talking about
for x in [0, 1, 2, 3, 4]:
    value = x / 2 + 1
    print( "Value: %d" % value )
Here is how I am supposed to trace the code
In Memory -----------
line# variables
1 x: 0
2 x: 0 value: 1.0
3 x: 0 value: 1.0
1 x: 1
2 x: 1 value: 1.5
3 x: 1 value: 1.5
1 x: 2
2 x: 2 value: 2.0
...
1 x: 4
2 x: 4 value: 3.0

In Output -----------
Value: 1
Value: 1
Value: 2
...
Value: 3

Would the trace library be a simple way for me to do this?
Reply
#2
There is a good writ-up with lots of examples here: https://pymotw.com/3/trace/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tracing a multiplication table w/ Python trace() NationalRex22 0 1,762 Jun-11-2019, 03:31 AM
Last Post: NationalRex22
  trace invalid pointer simon149 7 5,117 Apr-16-2019, 07:05 AM
Last Post: simon149
  Stack trace shows different exception type than print micseydel 5 4,454 Apr-01-2019, 10:24 PM
Last Post: micseydel
  How to create shadow between two colours and control a line after we trace it? CrazyPythonNerd 0 2,123 Mar-06-2019, 01:31 PM
Last Post: CrazyPythonNerd
  Debug and trace in python quocchi22101262 0 3,498 Jun-20-2017, 09:35 AM
Last Post: quocchi22101262
  PyInstaller, how to create library folder instead of library.zip file ? harun2525 2 4,820 May-06-2017, 11:29 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

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