Page 1 of 1
eg.globals. and globals() ?
Posted: Sat May 11, 2013 10:37 pm
by Sem;colon
Hello,
does anyone know if or how it's possible to use globals() with eg.globals. ?
I need to assign variables dynamically; globals() can do that by globals()["nameOfVariable"]=value - but I can't figure out how to use it with eg.globals., I can just use it within a script - which is useless to me.
Re: eg.globals. and globals() ?
Posted: Sun May 12, 2013 3:45 am
by jonib
Both are used to access and create global variables, but from your description I don't get what you are trying to do, so it's impossible to help.
jonib
Re: eg.globals. and globals() ?
Posted: Sun May 12, 2013 8:45 pm
by Sem;colon
Hello jonib,
OK, I'll explain the whole story: I have two PCs with EventGhost installed - now I wanted that these two installations talk to each other, so I used the network event sender/receiver plugin to transmit not only events but values of global variables. So I'm receiving events like: "TCP.variableName=variableValue"
Now I split the event suffix by using: Array=eg.event.suffix.split("=")
So now I have the name in of the variable in Array[0] and the value in Array[1]
Now I would like to use: globals()[Array[0]]=Array[1]
This will create a variable with the name "variableName" and the value "variableValue"
-inside a script this works perfectly with local variables, but a try to change/create variables in eg.globals.
I thought about something like: eg.globals()[Array[0]]=Array[1] but that didn't work...
Re: eg.globals. and globals() ?
Posted: Mon May 13, 2013 5:29 am
by krambriw
Would this work?
eg.globals.var1 = eg.event.suffix.split("=")[1]
Re: eg.globals. and globals() ?
Posted: Mon May 13, 2013 9:24 pm
by jonib
Could this work?
Code: Select all
eg.globals.VarList = {}
eg.globals.VarList[Array[0]]=Array[1]
It creates a "VarList" (You can change it to whatever you want) dict variable that you can store your variables, with name and value.
You access it like this:
Code: Select all
print eg.globals.VarList["Name of variable"]
jonib
Re: eg.globals. and globals() ?
Posted: Tue May 14, 2013 12:04 am
by Sem;colon
Thank you for the answers!
@krambriw: no, this would not create a variable with a "dynamic" name.
@Jonib: I thought about a list too, that would work, I guess, but it would mean I have to restructure my whole config, what is a bigger task... Well, when there's no possibility to use globals() the way I want, I should definatly consider doing it like this

Re: eg.globals. and globals() ?
Posted: Tue May 14, 2013 1:08 am
by jonib
So I found this:
Code: Select all
setattr(eg.globals, Array[0], Array[1])
To access use:
Code: Select all
print eg.globals.(name of variable)
Change "(name of variable)" to the variable name.
Seems to be what your after, it might set the variable in a non standard way so have no idea if there is any side effects and it works correctly. My quick test seemed to work.
Edit: I don't think I fully understand what your doing, maybe the
locals() is something your after its the same as globals() but for local variables.
jonib
Re: eg.globals. and globals() ?
Posted: Tue May 14, 2013 11:15 am
by Sem;colon
Hello jonib,
Code: Select all
setattr(eg.globals, Array[0], Array[1])
that was what I was looking for, thank you!!!

Re: eg.globals. and globals() ?
Posted: Mon May 27, 2013 12:54 pm
by miljbee
If you need to exchange data between two EG TCPEvents is the plugin you need :
viewtopic.php?f=2&p=16803
I am using it for months (years ...) it's rock stable.
plus, it can speak with the good old NER/NES ... give it a try !