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
#3
(Nov-20-2020, 11:17 PM)deanhystad Wrote: 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".
THANK YOU SO MUCH! IT WORKED!!!
Reply


Messages In This Thread
RE: Python reading variable in another py file wrongly - by _vertig0 - Nov-21-2020, 07:19 AM

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