Python Forum
Passing a local variable outside of a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing a local variable outside of a function
#4
I don't understand the WinDLL part but you could try a callable object
def folder_exists(folder):
    enum_func = ctypes.WINFUNCTYPE(wintypes.BOOL,
                                   wintypes.HWND,
                                   wintypes.LPARAM)
    class Query:
        def __call__(self, hwnd, lParam):
            self.found = 0
            length = ctypes.WinDLL('User32').GetWindowTextLengthW(hwnd) + 1
            buf = ctypes.create_unicode_buffer(length)
            ctypes.WinDLL('User32').GetWindowTextW(hwnd, buf, length)
            if buf.value == folder:
                self.found += 1
            return True
    query = Query()
    worker = enum_func(query)
    ctypes.WinDLL('User32').EnumWindows(worker, None)
    print(query.found)
 
folder_exists('Downloads')
Reply


Messages In This Thread
RE: Passing a local variable outside of a function - by Gribouillis - Apr-14-2019, 08:05 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  not able to call the variable inside the if/elif function mareeswaran 3 722 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  creating arbitrary local variable names Skaperen 9 2,099 Sep-07-2024, 12:12 AM
Last Post: Skaperen
  how solve: local variable referenced before assignment ? trix 5 1,943 Jun-15-2024, 07:15 PM
Last Post: trix
  Variable for the value element in the index function?? Learner1 8 3,306 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 1,791 Nov-23-2023, 02:53 PM
Last Post: rob101
  It's saying my global variable is a local variable Radical 5 6,854 Oct-02-2023, 12:57 AM
Last Post: deanhystad
  Printing the variable from defined function jws 7 8,435 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Function parameter not writing to variable Karp 5 2,355 Aug-07-2023, 05:58 PM
Last Post: Karp
  passing dictionary to the function mark588 2 2,121 Dec-19-2022, 07:28 PM
Last Post: deanhystad
  Retrieve variable from function labgoggles 2 1,944 Jul-01-2022, 07:23 PM
Last Post: labgoggles

Forum Jump:

User Panel Messages

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