Hello. I am working on an App. I am sending inputs from the user to the ServerModule and assigning that value to other variables. And later, i am calling a function “math” that uses those variables to perform specific equations. But while doing this, in getting a NameError. Here is a code:
NameError: name 'icontact' is not defined
at ServerModule1, line 22
I found that is is showing only the ‘icontact’ variable is error as it is the first one mentioned in the “math” function. So, all the other variables are also not declared (Why?).So, can anyone please tell me how to fix this Error…Thank You
On the face of it, looking at the code you’ve pasted here, that’s a scope thing.
You are defining the variable inside a function. Once that function completes, the variable is no longer visible.
I would do something like this :
# In your form ...
icontact = anvil.server.call("contact", con)
infection_rate = ... etc.
...
result = anvil.server.call("math", icontact, infection_rate, ... etc)
Also, if the functions are doing no more than just those simple assignments, I would just send the user inputs to the math function directly. That would save a lot of server calls.
Hello David, actually I am calling the math function from an other form. So, to access that variables, i just need to type “from Form1 import Form1”, in the top right?
Edit: But im getting the NameError again. I think it is because I got the “from Form1 import Form1” syntax, wrong.
The name of your module and the name you use in your import must match exactly. Doesn’t matter what they are called as long as they are exactly the same.
Also, make sure this is a client module, not a server module.
Hi @aadhiarun2007,
please be aware that the server does not store state. Only if you have the “keep server running”-option in your plan and activated. And only if you have declared them in a global scope and not just in a funtion. So you either need to call the server funtion with several arguments or just don’t use the server at all. The calculations of a SIR model are so simple, that you can do them in a client module.
Ok. But I am not using the paid version so i guess i have to do it in the client code. But I am getting the same error I got first and since i cannot use a Module, how do i fix it? Is there a way I can send Info between Forms without a module?