use pythons string manipulation: http://docs.python.org/2/library/stdtypes.html#string-formatting
usually the% operator is used to put a variable in a string,% i for integers,% s for strings and% f for floats, NB: there is also another type of formatting (.format), which is also described in the link above, which allows you to pass to a dict or list, a little more elegant than what I will show below, it may be something that you should use in a long run, since the% operator gets confused if you have 100 variables that you want to put in a string, although using dicts (my last example) like this negates u about.
code_str = "super duper heading" html = "<h1>%s</h1>" % code_str # <h1>super duper heading</h1> code_nr = 42 html = "<h1>%i</h1>" % code_nr # <h1>42</h1> html = "<h1>%s %i</h1>" % (code_str, code_nr) # <h1>super duper heading 42</h1> html = "%(my_str)s %(my_nr)d" % {"my_str": code_str, "my_nr": code_nr} # <h1>super duper heading 42</h1>
it is very simple and only works with primitive types, if you want to be able to store dicts, lists and possible objects, I suggest you use cobvert them for jsons http://docs.python.org/2/library/json.html and https : //stackoverflow.com/questions/4759634/python-json-tutorial are good sources of inspiration.
Hope this helps
source share