Domanda

I'm using AutoKey (not AutoHotKey), and I'm noticing that multiple scripts are using the same python functions I've created. Up until now, I've just been defining the same function in each script that uses it. However, if I have to go back and modify that function, I have to remember each script that uses, and make those modifications for each.

Using AutoKey, how would I have (custom) global function library, that I'd be able to import into each script, so I'll have a centralized place for propagating function modifications to all scripts?

I've just begun using python (because AutoKey uses it for its scripting engine), so I'm not sure how I'd create my own namespace and I'm also not sure how I'd import a custom library into my AutoKey python scripts. Where would I place the code-file? What would the syntax be inside the file that will be encapsulating my function definitions?

È stato utile?

Soluzione

You could write a module and put it in the Lib\site-packages folder of Python.

For example, with this:

def foo():
    print("foo called")

stored as C:\Python32\Lib\site-packages\foo.py:

>>> import foo
>>> foo.foo()
foo called

Altri suggerimenti

Using recent AutoKey versions, you can set the preference "User Module Folder" in the "Script Engine" tab to a folder of your liking.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top