In C++, I could imagine constructing with a reference to a counter ( see below ), and then a function would just dereference the address to get a value. Is something similar possible in python?
Something like:
import time
class Count_Watcher:
def __init__( self, to_watch ):
self.to_watch = to_watch
sleep_watch()
def sleep_watch( self ):
time.sleep( 5 )
print( self.to_watch )
line_counter = 0
separate_thread_printer = Count_Watcher( (?some operator) line_counter )
for line in some_file:
line_counter += 1
and the "current" value of line_counter ( as in, current to the for loop ) is printed every five seconds
'line_counter'), and then you'd have to know what namespace to look it up in (e.g., the global namespace in this case).