Python Forum
I need a win! (HELP!) PLZ?
Thread Rating:
  • 3 Vote(s) - 2.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need a win! (HELP!) PLZ?
#11
He can only write code within the sandbox, he's not allowed to alter the functions at the top I don't think.

So def Tracefunc is his own code he has put in. Running that just gives "I sense a disturbance in the code"
Reply
#12
Really? Would I use the same format as well?

So I can technically bypass the
print("I sense a disturbance in the code")
os._exit(1)

print('The code is strong in this one')
So this will run and proceed to def win()?

thesandmanx that is correct I have to run it from line 8 and jump / bypass to line 11 so I can bypass the first print statement and os._exit(1).

I just tried to make a rudimentary goto statement BUTTTT that didn't work.
Sorry, I am so used to c and c++.
Reply
#13
In the pdb library they gave you, their seems to be a function called "do_jump" that lets you set the next line to be executed:

def do_jump(self, arg):
"""j(ump) lineno
Set the next line that will be executed. Only available in
the bottom-most frame. This lets you jump back and execute
code again, or jump forward to skip code that you don't want
to run.
It should be noted that not all jumps are allowed -- for
instance it is not possible to jump into the middle of a
for loop or out of a finally clause.

Have you played with this at all yet?
Reply
#14
Not yet, I thought of it more as a reference than an actual hint/solution to the problem.
Reply
#15
So like, for some pseudo-code, I would try something like:

import pdb
def tracefunc(frame, event, arg)

if event == "line"; (I changed this to line instead of call, the line event checks to see if a new line of code is going to be ran)

if frame.f_code.co_name == 'game_over': (I would set this to game_over instead of win, since it's the first frame being read into the stack)

newStack = pdb.Pdb() (Create a pdb object to start the Python Debugger)

Then from here you use the controls the pdb library gives you to maneuver to where you want to be in the stack. (do_jump, do_continue, etc., It'll take some reading of that pdb library to figure out the controls..... Good luck lol)
Reply
#16
I am doing a similar project and I keep running into an issue when I run pdb.Pdb.do_jump(arg), (right now I have arg set to line 11) I get this error:
AttributeError: 'Pdb' object has no attribute 'curindex'. I found the error in the debugger, but I have no idea how to fix it. Any ideas? Thanks.
Reply
#17
Actually it looks like everything is good, except your forgot to call win(). Or I guess more accurately, you are removing the print function from win(), or only allowing the 2nd print function in game_over() and nothing else. But, I'm new too, and not sure how reliable my conclusions would be.
Reply
#18
tozqo, thank you for the input. If I run the code posted in the beginning, it will work only until the program gets to the os._exit(1). We are trying to use the Pdb class to skip this line, but that is where I am having issues. For some reason if I initialize stack =pdb.Pdb() and then try to call stack.do_jump(line=11) I get the attribute error stated above. Do you have any ideas why it would say AttributeError: 'Pdb' object has no attribute 'curindex'? (For continuity sake, I made my code look similar to the one in the initial post so we could all brainstorm how to work past the conceptual problem)

frame = inspect.currentframe()
stack = pdb.Pdb()
def tracefunc(frame, event, arg):

    if event == "line":
        if frame.f_code.co_name == 'game_over':
           func = frame
           print("============"+func.f_code.co_name+"==============")
           stack.do_jump(11)

    return tracefunc
   
sys.settrace(tracefunc)
Reply


Forum Jump:

User Panel Messages

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