Thanks for your helpburque505 wrote: ↑16 Oct 2020, 17:14@songdg, there are a couple of ways at least that you can do that. See the ahk github page, my post here.
Regards,
burque505
Using AutoHotkey from Python
Re: Using AutoHotkey from Python
Re: Using AutoHotkey from Python
I'm shifting to a combination of AHK and python atm so I'll watch this thread
Re: Using AutoHotkey from Python
Hi,burque505 wrote: ↑28 Aug 2020, 10:48Hi @blue83, one simple way (not using @Pythonic's ahk, though you could easily do so) is here, using RunCmd.ahk by @SKAN. Assumes 'varfrompy.py' is in the script directory. By the way, the ahk github page has examples for passing info from AHK to python.
Regards,Code: Select all
#Include RunCmd.ahk avar := RunCmd("python .\varfrompy.py") msgbox %avar% /* varfrompy.py: myvar = "Hello, AHK!" print(myvar) */
burque505
Your code is great for normal purposes.
But I have also a code with python on different path and this code bellow doesnt work, can you help me?
What I am doing wrong?
Code: Select all
avar := RunCmd("C:/Users/%A_UserName%/Desktop/WPy64-3760/python-3.7.6.amd64/python.exe %A_ScriptDir%/varfrompy.py", A_ScriptDir, "UTF-8")
msgbox %avar%
Code: Select all
avar := RunCmd("C:/Users/" A_UserName "/Desktop/WPy64-3760/python-3.7.6.amd64/python.exe .\varfrompy.py", A_ScriptDir, "UTF-8")
Re: Using AutoHotkey from Python
I am really liking @Pythonic's ahk lib! I've been creating some AHK (v1) GUIs that pass dictionaries and lists to Python. I soon discovered I need to massage them into a string to have Python read them using ahk.py.
I started off with obj2str.ahk by @errorseven (many thanks!) but it choked for my purposes on multiline strings and other things. My mod of obj2str (Obj2PyStr.ahk) is below.
(Tested with Python 3.10.4 on Windows 10 Pro 64-bit only, latest ahk.py)
One for dictionaries (i.e. associative arrays in AHK) is below.
AHK:
Python to process that:
Result:
NOTE: The Python creates a really ugly object because of the single quotes and triple single quotes, but I ended up doing it that way so ast.literal_eval() can process the object.
Regards,
burque505
I started off with obj2str.ahk by @errorseven (many thanks!) but it choked for my purposes on multiline strings and other things. My mod of obj2str (Obj2PyStr.ahk) is below.
(Tested with Python 3.10.4 on Windows 10 Pro 64-bit only, latest ahk.py)
Spoiler
There are examples for use in the script, and at the obj2pystr GitHub page.One for dictionaries (i.e. associative arrays in AHK) is below.
AHK:
Code: Select all
#Include obj2pystr.ahk
hughes =
(
John James Hughes
as Trusteee
of the J.J. Hughes Revocable Living Trust
)
MyDict := {borrowers:[{1_FullName:"James Roberts", 2_Street:"346 Cage St", 3_City:"Tarzana", 4_State:"CA", 5_Zip:90111}]
, lenders:[{1_FullName:hughes, 2_Street:"123 Anywhere", 3_City:"Albacore", 4_State:"NT", 5_Zip:80111}]}
;MsgBox % Obj2PyStr(MyDict)
FileAppend, % Obj2PyStr(MyDict), *
Code: Select all
from ahk import AHK
from ast import literal_eval
ahk = AHK()
with open(r"your_script_here4.ahk", 'r') as f:
my_script = f.read()
result = ahk.run_script(my_script)
print(result)
NewStuff = literal_eval(result)
print(type(NewStuff))
print(NewStuff["lenders"][0]["1_FullName"])
Code: Select all
{"borrowers":[{"1_FullName":'''James Roberts''', "2_Street":'''346 Cage St''', "3_City":'''Tarzana''', "4_State":'''CA''', "5_Zip":90111}], "lenders":[{"1_FullName":'''John James Hughes
as Trusteee
of the J.J. Hughes Revocable Living Trust''', "2_Street":'''123 Anywhere''', "3_City":'''Albacore''', "4_State":'''NT''', "5_Zip":80111}]}
<class 'dict'>
John James Hughes
as Trusteee
of the J.J. Hughes Revocable Living Trust
Regards,
burque505
Re: Using AutoHotkey from Python
How to use it in Anaconda with spyder, I place the library(ahk_main) in the directory(C:\ProgramData\Anaconda3\Lib\site-packages) that I can use the code import ahk_main, but when I try ahk = AHK() it doesn't work.
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: Bing [Bot] and 218 guests