I have a package file mypackage.m with


The file is VCS controlled. For some reason, I need to Get mypackage.m with the effect of tmp being 3 instead of 2, but I'd like to avoid explicitly changing tmp=2 to tmp=3 in the working copy of mypackage.m and having the VCS flagging it as locally modified. Any way I can modify the way of loading the file


so I can get the effect of tmp=3 in loading it?

  • 1
    $\begingroup$ @Yi Wang, your suggestion is incorrect if you mean Block[{tmp = 3}, Get["mypackage.m"]]. Also your comment is too undetailed to be understandable or helpful. $\endgroup$
    – qazwsx
    Sep 16, 2014 at 7:50
  • $\begingroup$ Sorry I misunderstood your question... $\endgroup$
    – Yi Wang
    Sep 16, 2014 at 8:03
  • 1
    $\begingroup$ What's the context of tmp? Suppose it's Global`, then how about tmp = 3; SetAttributes[tmp, Protected]; Get["mypackage.m"]? And tmp in a different context can be modified in a similar way. $\endgroup$
    – xzczd
    Sep 16, 2014 at 8:08
  • $\begingroup$ @xzczd I amended original post to clarify it. $\endgroup$
    – qazwsx
    Sep 16, 2014 at 8:18

1 Answer 1


You can first Protect the tmp (of course with its Context added) and then call the package i.e.:

Foo`Bar`Private`tmp = 3;
(* Or you can use: *)
(* SetAttributes[Foo`Bar`Private`tmp, Protected] *)
<< "mypackage.m"

A warning will come out but it doesn't matter.

  • $\begingroup$ Only thing I added is after Get[], I do SetAttributes[FooBarPrivate`tmp, Unprotected] $\endgroup$
    – qazwsx
    Sep 17, 2014 at 4:27
  • $\begingroup$ @qazwsx I think there's no attribute named Unprotected, to clear the attribute Protected you can use Unprotect[Foo`Bar`Private`tmp] or ClearAttributes[Foo`Bar`Private`tmp, Protected] :) $\endgroup$
    – xzczd
    Sep 17, 2014 at 4:46
  • $\begingroup$ Yes. ClearAttributes[FooBarPrivatetmp, Protected]. Also Quiet[Get["mypackage"], Set::wrsym]. $\endgroup$
    – qazwsx
    Sep 17, 2014 at 5:09
  • $\begingroup$ @qazwsx You can type " \` " instead of " ` " to make it display correctly inside the code block :) $\endgroup$
    – xzczd
    Sep 17, 2014 at 5:17
  • $\begingroup$ Yes, I'm well aware. $\endgroup$
    – qazwsx
    Sep 17, 2014 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.