fabric - python string iterpolation on files with % as comment -


this question has answer here:

i use fabric generate custom ejabberd config file , upload server. fabric uses python string interpolation in fabric.contrib.files.upload_template. unfortunately ejabberd config file uses

%%%

for comments

using python string interpolation throws error on following simplified example:

%%% comment

{resurl, %(resturl)s}

valueerror: unsupported format character 't' (0x74) @ index 4 

i replace every non uneven occurence of % > 1 one. or

val = re.sub("%", "??", open("ejabberd.cfg").read()) val = val % {"resturl": "http://localhost:500/"}     val.replace("??", "%") 

there might better solution treat file's having %, maybe telling python use character mark start of specifier.

thanks helping

you need double each %:

%%%%%% comment  {resurl, %(resturl)s} 

this escapes %; output transforms each %% %.

demo:

>>> val = '''\ ... %%%%%% comment ...  ... {resurl, %(resturl)s} ... ''' >>> print val % {"resturl": "http://localhost:500/"}     %%% comment  {resurl, http://localhost:500/} 

Comments

Popular posts from this blog

c++ - Linked List error when inserting for the last time -

java - activate/deactivate sonar maven plugin by profile? -

java - What is the difference between String. and String.this. ? -