Problem with global variables

27 views
Skip to first unread message

Mr.SpOOn

unread,
Jul 5, 2009, 6:32:12 PM7/5/09
to py...@googlegroups.com
Hi,
sorry if this is not a Pyke-related problem, but I'm pretty sure this
code worked before and now I just don't get what's happening.

What I'm trying to do is getting some input from the keyboard, store
in a list and then fire pyke rules for the elements in this list.
I'm actually doing this with three files: main.py, global_var.py and notes.krb

In global_var I just define two empty lists:

input_notes = []
input_num = []


In main.py I do this:

global_var.input_notes = raw_input('insert input ').split(' ')
engine = knowledge_engine.engine(m_ia)
engine.reset()
engine.activate('notes')

And then in notes.krb:

third
foreach
python print 'bla'
$A in global_var.input_notes
python print $A

fc_extras
from m_ia import global_var


I trimmed a lot of code away, to show the important parts. Anyway, the
raw_input() is working and I'm sure that before it printed the $A
variable correctly. Now it just prints "bla".

Any idea?

Thanks.

Bruce Frederiksen

unread,
Jul 5, 2009, 7:08:43 PM7/5/09
to py...@googlegroups.com
It looks like you're importing two different copies of the global_var module.  Try looking at global_var.__name__, or id(global_var) in main.py and in the fc_extras clause (just put a print after the import) and see if you get the same results.  You might also try global_var.__file__.

Mr.SpOOn

unread,
Jul 6, 2009, 10:45:58 AM7/6/09
to py...@googlegroups.com
2009/7/6 Bruce Frederiksen <dang...@gmail.com>:

> It looks like you're importing two different copies of the global_var
> module.  Try looking at global_var.__name__, or id(global_var) in main.py
> and in the fc_extras clause (just put a print after the import) and see if
> you get the same results.  You might also try global_var.__file__.

Thanks, you're right.
In a file I was doing:

from global_var import input_notes

and in the rule base:

from m_ia import global_var

Thanks again,
Carlo

Reply all
Reply to author
Forward
0 new messages