I have some packages that uses database connections inside it, let's call it ConnPackage
. The connection IP is a public package variable, and has a default value:
$connectionIP="127.0.0.1".
This variable is used to read database values when the package is loading. So change it value after package load don't solve the problem. The problem is similar to pass args in shell wolfram script, but must be done in the notebook.
The question is:
How could I read the ConnPackage
, using Needs[]
, but setting $connectionIP
to be another value?
UPDATE
I can solve the problem defining a variable in System
. But I don't feel it's a good pattern. Here is my attempt. Inside ConnPackage
I can do:
$connectionIP=If[StringQ[#],#,"127.0.0.1"]&[System`$argConnectionIP]
So, if there is no value in System`$argConnectionIP
, the standard IP will be load, otherwise it will use System`$argConnectionIP
.
SetDelayed
help in your case? $\endgroup$$connectionIP
as it runs to load other definitions. @OleksandrR. I made an update with how I solved it, but I don't fell it's a good way. $\endgroup$System`
? Cannot you useConnPackage`$connectionIP
too? Perhaps I don't actually understand what you wish to accomplish; if that's the case pardon me. $\endgroup$ConnPackage
, I forgotBeginPackage
readsSystem
and the loaded package. $\endgroup$ConnPackage
. $\endgroup$