1
$\begingroup$

In order to read in a definition with certain parameters replaced by appropriate values I can use for example

Block[{a=1.1,b=2.2}, Get["file"]]

where "file" is a file containing the definitions (which contain a and b on the RHS). This works well and is fast. Now is there a way to do something similar if I want to replace a string. So basically, Block[{"string"="bla"},Get["file"]] (but then in a way that actually works of course).

$\endgroup$
2
$\begingroup$

Try this:

Get @ StringToStream @ StringReplace["\"string\"" -> "\"bla\""] @ Import["file", "Text"]

Alternatively you can read a package step by step like in a/124670 but instead of:

Sow[ Interpretation @@ {withContext[expr], expr} ];
ReleaseHold[expr];

do

ReleaseHold[expr /. "string" -> "bla"]
$\endgroup$

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.