From: gltewalt@... (illocutionist) Date: 2004-06-06T08:58:40+09:00 Subject: Re: What is the equivalent of Python's "%s" % "MyString"? "Sam Sungshik Kong" wrote in message news:... > Thanks to all who replied to my question. > > I want to mention one thing. > One drawback of ruby's #{name} mechanism is that the variable 'name' must > exist before I setup the format and another drawback is that when I setup > the format the result string is already made (returned) and cannot be > delayed (if I'm correct...). > Sometimes I want to make the format first, especially when I write scripts > for web pages with python (now ruby :-)). > > In python for ASP, for instance, I frequently write the following style > code. > > html = """ > > %(name)s > %(age)d > > """ > di = { > "name": get_name_from_db(), > "age": get_age_from_db() > } > Response.Write(html % di) > > Well, I may change the sequence (get the values first and setup the > formatting string). > However, in the above case, formatting is outer bound and the values are > details. > My brain feels more comfortable in this way...;^) > > Sam > > > what about?... require 'ostruct' di = OpenStruct.new html = """ %s %d """ Response.Write(html % [di.name = "Sam", di.age = 34]) Or, something similar to that.