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$

1 Answer 1

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$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.