Possible Duplicate:
Automatically load packages at startup
I have made two packages "Package1" and "Package2". Package2 calls Package1. it works fine.But everytime I am reopening Mathematica
,I have to run both packages and then load them by Needs
. I dont want to load packages again and again.
BeginPackage
in Package2. This ensures that you only need to load Package2 manually before using it (and not Package1 as well). $\endgroup$ – Szabolcs Jul 24 '12 at 9:52Needs["Package1`"]
in thePrivate`
section of Package2 is the better method, for the sake of encapsulation and information hiding. $\endgroup$ – Leonid Shifrin Jul 24 '12 at 11:42Private`
section for the import to be private, as it is theEndPackage
of Package2 that removed the Package1 context from the context path. $\endgroup$ – Szabolcs Jul 24 '12 at 11:53BeginPackage
-EndPackage
andBegin
-End
itself (which is a case sometimes), then you will create all its symbols in the public part of Package2 with such an import, and therefore, leak its details to the user. It is not a frequent case, but from the "black box" point of view importing into aPrivate`
subsection adds extra protection. $\endgroup$ – Leonid Shifrin Jul 24 '12 at 12:11Begin["`Private`"]
that makes the imported package private. $\endgroup$ – Szabolcs Jul 24 '12 at 17:37