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
#2
This is a scope problem and has nothing to do event_request being in another file. You would have the same probem if this were all in one file.

The problem is you have two exit_request variables. One in events and one in events.update_events. If you want these to reference the same thing you need to rewrite update_events like this:
def update_events():
    global exit_request
    for event in pygame.event.get():
        if(event.type == pygame.QUIT):
            exit_request = event
This tells Python to use events.exit_request instead of creating events.update_events.exit_request when you do this:
exit_request = event
By default assignment inside a function creates a new variable. If this were not the case there would be no way to make "local" variables. To prevent this from happening you need to define the variable as "global".
Reply


Messages In This Thread
RE: Python reading variable in another py file wrongly - by deanhystad - Nov-20-2020, 11:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Sad problems with reading csv file. MassiJames 3 658 Nov-16-2023, 03:41 PM
Last Post: snippsat
  Reading a file name fron a folder on my desktop Fiona 4 931 Aug-23-2023, 11:11 AM
Last Post: Axel_Erfurt
  Trouble with threading and reading variable from a different script Lembas 14 3,081 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,119 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Reading a file JonWayn 3 1,114 Dec-30-2022, 10:18 AM
Last Post: ibreeden
  Reading Specific Rows In a CSV File finndude 3 1,005 Dec-13-2022, 03:19 PM
Last Post: finndude
  Excel file reading problem max70990 1 906 Dec-11-2022, 07:00 PM
Last Post: deanhystad
  Replace columns indexes reading a XSLX file Larry1888 2 998 Nov-18-2022, 10:16 PM
Last Post: Pedroski55
  Failing reading a file and cannot exit it... tester_V 8 1,838 Aug-19-2022, 10:27 PM
Last Post: tester_V
Sad What did I do wrongly? Tomi 1 944 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