Python Forum
very weird unexpected behaviour, related to prints
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
very weird unexpected behaviour, related to prints
#1
I am seeing a weird behavior and I could not find out why. Here is what I did:

in my_def.py, I have:
tran_counter = 0x11000
def output_status(p_file = sys.stderr):
    global tran_counter

    print "Debug:transaction counter terminal output: ",hex(tran_counter)
    print >> p_file, "transaction count:                ", hex(tran_counter)
this is imported and called in another module:
test.py
import my_def
f_handle = open('run.log','w+')
for i in range(0,100):
    my_def.output_status(f_handle)
    my_def.tran_counter += 4
it's just that simple. The problem is if I run test.py, the counter increment and output as expected.
However, if I run a wrapper script which call's the test.py, the tran_counter magically get changed, and what's even more interesting is that, the value which is printed to terminal with the "Debug" tag, is correct. But the value gets printed into run.log is wrong, and it's starting value is 0x10, and get's incremented by 4 in the loop.

It's driving me crazy and I have no idea how to find the rootcause. Any help would be greatly appreciated.
Reply
#2
Please post the wrapper script as well so that we can reproduce the bug.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  logger behaviour setdetnet 1 891 Apr-15-2023, 05:20 AM
Last Post: Gribouillis
  can someone explain this __del__ behaviour? rjdegraff42 1 719 Apr-12-2023, 03:25 PM
Last Post: deanhystad
  Asyncio weird behaviour vugz 2 1,255 Apr-09-2023, 01:48 AM
Last Post: vugz
  zfill prints extra et the end of a var tester_V 4 903 Mar-24-2023, 06:59 PM
Last Post: tester_V
  Weird behaviour using if statement in python 3.10.8 mikepy 23 3,607 Jan-18-2023, 04:51 PM
Last Post: mikepy
  Generator behaviour bla123bla 2 1,106 Jul-26-2022, 07:30 PM
Last Post: bla123bla
  Inconsistent behaviour in output - web scraping Steve 6 2,548 Sep-20-2021, 01:54 AM
Last Post: Larz60+
  variable prints without being declared. ClockPillow 2 1,810 Jul-11-2021, 12:13 AM
Last Post: ClockPillow
  Adding to the dictionary inside the for-loop - weird behaviour InputOutput007 5 2,716 Jan-21-2021, 02:21 PM
Last Post: InputOutput007
  Behaviour of 2D array SimonB 6 2,825 Jan-21-2021, 01:29 PM
Last Post: SimonB

Forum Jump:

User Panel Messages

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