Stuart Young
Stuart Young

Reputation: 13

How to preserve quotes of string during .format

I'm writing a multi-line file, lines like:

workspace -fr "fluidCache" "cache/nCache/fluid";

On some of the lines I need to use a variable containing a file path, when I use the following:

render_output = os.path.join(project_root, r'common\render_output')
ws_file.write("""workspace -fr "images" {0};""".format(render_output))

result:

workspace -fr "images" I:\..\common\render_output;

The result I need is render_output with quotes:

workspace -fr "images" "I:\..\common\render_output";

How might I format the render_output so that the quotations of its string value are maintained in the triple quoted write argument?

Upvotes: 0

Views: 112

Answers (1)

gilch
gilch

Reputation: 11641

ws_file.write("""workspace -fr "images" "{0}";""".format(render_output))

Upvotes: 2

Related Questions