Python Forum
Python reading variable in another py file wrongly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python reading variable in another py file wrongly
#1
I have 2 .py files below (Both shortened and include the problem sections):
engine.py
import events

running = False;

def start():
    boot() #Can be safely ignored all it does is call pygame.init()
    running = True;

    while running:
        events.update_events()
        if events.exit_request is not None:
            running = False

    #Logic here

    shutdown()
events.py
import pygame

exit_request = None

def update_events():
    for event in pygame.event.get():
        if(event.type == pygame.QUIT):
            exit_request = event
While I am using pygame, that isn't where the problem lies, I have tested it and the problem is that if I access the exit_request variable in the events file from engine.py, it will always show up as None even if there is an exit event, but if I print exit_request from inside events.py, it will show up appropriately as pygame_exit_blah blah blah if the user clicked the x button, but like I said will show up as "None" if printed from engine.py. Does anyone know why this is happening?
Reply


Messages In This Thread
Python reading variable in another py file wrongly - by _vertig0 - Nov-20-2020, 06:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Sad problems with reading csv file. MassiJames 3 633 Nov-16-2023, 03:41 PM
Last Post: snippsat
  Reading a file name fron a folder on my desktop Fiona 4 916 Aug-23-2023, 11:11 AM
Last Post: Axel_Erfurt
  Trouble with threading and reading variable from a different script Lembas 14 3,048 Apr-26-2023, 11:21 PM
Last Post: Lembas
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,106 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Reading a file JonWayn 3 1,095 Dec-30-2022, 10:18 AM
Last Post: ibreeden
  Reading Specific Rows In a CSV File finndude 3 989 Dec-13-2022, 03:19 PM
Last Post: finndude
  Excel file reading problem max70990 1 898 Dec-11-2022, 07:00 PM
Last Post: deanhystad
  Replace columns indexes reading a XSLX file Larry1888 2 989 Nov-18-2022, 10:16 PM
Last Post: Pedroski55
  Failing reading a file and cannot exit it... tester_V 8 1,821 Aug-19-2022, 10:27 PM
Last Post: tester_V
Sad What did I do wrongly? Tomi 1 935 Aug-07-2022, 08:05 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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