inspect

How print every line of a python script as its being executed (including the console)?

浪子不回头ぞ 提交于 2021-02-20 17:55:23
问题 I'd like to print every line of python script as it's being executed, as well as the log from the console as every line is being executed. For example, for this script: import time print 'hello' time.sleep(3) print 'goodbye' I'd like it to generate the following in the console: line 1: import time line 2: print 'hello' hello line 3: time.sleep(3) line 4: print 'goodbye' goodbye See below for my attempt import subprocess as subp python_string = """ import sys import inspect class SetTrace

How print every line of a python script as its being executed (including the console)?

浪子不回头ぞ 提交于 2021-02-20 17:55:02
问题 I'd like to print every line of python script as it's being executed, as well as the log from the console as every line is being executed. For example, for this script: import time print 'hello' time.sleep(3) print 'goodbye' I'd like it to generate the following in the console: line 1: import time line 2: print 'hello' hello line 3: time.sleep(3) line 4: print 'goodbye' goodbye See below for my attempt import subprocess as subp python_string = """ import sys import inspect class SetTrace

How print every line of a python script as its being executed (including the console)?

旧城冷巷雨未停 提交于 2021-02-20 17:54:14
问题 I'd like to print every line of python script as it's being executed, as well as the log from the console as every line is being executed. For example, for this script: import time print 'hello' time.sleep(3) print 'goodbye' I'd like it to generate the following in the console: line 1: import time line 2: print 'hello' hello line 3: time.sleep(3) line 4: print 'goodbye' goodbye See below for my attempt import subprocess as subp python_string = """ import sys import inspect class SetTrace

Find all function calls by a function

◇◆丶佛笑我妖孽 提交于 2021-02-08 11:11:33
问题 What is the best way to find all function calls that a function makes? I want to do this at runtime (likely with a decorator). Is the best way to retrieve the source code with inspect (this means that I will have to have access to the source code...so no interactive interpreter support) and then parse it with ast ? Is there a better way? Python 2.7 preferred, but not required. I'd like it to be simple enough to do myself. If others have done it, I would look at the source code so I could

Find all function calls by a function

北慕城南 提交于 2021-02-08 11:05:34
问题 What is the best way to find all function calls that a function makes? I want to do this at runtime (likely with a decorator). Is the best way to retrieve the source code with inspect (this means that I will have to have access to the source code...so no interactive interpreter support) and then parse it with ast ? Is there a better way? Python 2.7 preferred, but not required. I'd like it to be simple enough to do myself. If others have done it, I would look at the source code so I could

Chrome://inspect without internet connection

折月煮酒 提交于 2021-02-07 09:58:44
问题 I have been developing a website for a project targeting mobile phones and tablets, currently focusing on using the chrome browser. Much of this development has been done on one phone using a laptop. I had been using the "chrome://inspect/#devices" quite painlessly until I came to test on a different phone, when clicking "inspect" resulted in a white page. The problem seemed to be that as I happened to have no network connection at the time, chrome couldn't access some repository and so didnt

Chrome://inspect without internet connection

倾然丶 夕夏残阳落幕 提交于 2021-02-07 09:58:04
问题 I have been developing a website for a project targeting mobile phones and tablets, currently focusing on using the chrome browser. Much of this development has been done on one phone using a laptop. I had been using the "chrome://inspect/#devices" quite painlessly until I came to test on a different phone, when clicking "inspect" resulted in a white page. The problem seemed to be that as I happened to have no network connection at the time, chrome couldn't access some repository and so didnt

How to find out if (the source code of) a function contains a loop?

允我心安 提交于 2021-02-04 14:51:26
问题 Let's say, I have a bunch of functions a , b , c , d and e and I want to find out if they directly use a loop: def a(): for i in range(3): print(i**2) def b(): i = 0 while i < 3: print(i**2) i += 1 def c(): print("\n".join([str(i**2) for i in range(3)])) def d(): print("\n".join(["0", "1", "4"])) def e(): "for" I want to write a function uses_loop so I can expect these assertions to pass: assert uses_loop(a) == True assert uses_loop(b) == True assert uses_loop(c) == False assert uses_loop(d)

How to find out if (the source code of) a function contains a loop?

匆匆过客 提交于 2021-02-04 14:51:26
问题 Let's say, I have a bunch of functions a , b , c , d and e and I want to find out if they directly use a loop: def a(): for i in range(3): print(i**2) def b(): i = 0 while i < 3: print(i**2) i += 1 def c(): print("\n".join([str(i**2) for i in range(3)])) def d(): print("\n".join(["0", "1", "4"])) def e(): "for" I want to write a function uses_loop so I can expect these assertions to pass: assert uses_loop(a) == True assert uses_loop(b) == True assert uses_loop(c) == False assert uses_loop(d)