by rupe

How does the % operator work in Python?

This simple function emulates Python's % operator... % is more efficient, but this code is a good approximation of what it does. The function takes three variables:

value_list, which contains values to be sequentially inserted into a string template.
string_template, a string containing pre-defined values to be replaced.
replace_string, a string that is replaced in string_template, by a value from value_list.

The function returns string_template, a string with replace_string replaced by values from value_list.

def percent_operator_demo(value_list, string_template, replace_string):
    array_len = len(value_list)
    for i in range(array_len):
        string.replace(string_template, replace_string, str(value_list[i]) ,1 )
    return string_template

			

 


 
Read more of   The Yak's Frequently Questioned Answers   (mod.2008-06-12)

440.   What are rainbow tables?   [aestetix/2006-10-06]
429.   why does my 802.11g network seem to die around Uniden 2.4ghz phones?   [jake/2006-05-19]
421.   What is a Brosef?   [jake/2005-02-18]
378.   What is the meaning of MSD in relation to OpenPGP/GnuPG/PGP?   [jake/2003-09-22]
265.   Who is Brad   [brad/2002-07-16]
238.   How does John Horton Conway figure out what day of the week it is?   [strick/2001-06-04] ( rupe/2001-06-05 )
186.   Where can I find some neat open source artwork?   [rupe/2001-02-28]
138.   How can I become an asshole in five easy steps?   [chota/2000-10-22]
137.   where can i find docs for radioshack scanners?   [jesse/2000-10-20]
134.   What are some useful commands for using the SGI VINO video option?   [rupe/2000-10-08]
110.   How can I download a new ringtone to my SMS capable phone without having net access?   [rupe/2000-07-09]
90.   What happened to Jesse and TreesN at sf2600 may2000?   [strick/2000-05-06]
74.   How many roads must a man walk down?   [vonguard/2000-04-04]
70.   How can I get info from my (email-capable) cellfon?   [robey/2000-02-29]
68.   What are Nana's rats names?   [nana/2000-02-28]
51.   I'm playing with dialpad.com -- What's the USGS earthquake info phone #?   [strick/2000-02-06]
37.   What is this "goo" that holds the yak together?   [robey/2000-02-01]
25.   What does CLEC stand for in the telco business?   [simon/2000-01-22] ( jesse/2000-11-22 )