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.2010-02-10)

359.   Is Larry Wall on crack?   [strick/2003-04-10]
344.   Why are you upset?   [jake/2003-01-29]
285.   I use gnome, my soundcard died, lots of things need sound to run! what do i do?   [jesse/2001-11-13]
280.   How do i stop konqueror from opening a new window when i go to a site using a plugin i dont have?   [jesse/2001-10-30]
261.   Which companies belong to the DVD Copy Control Association (DVD CCA) as of 08-2001?   [rupe/2001-08-03]
220.   Where can I find serial/parallel controllable, backlit LCD screens?   [rupe/2001-05-30] ( sidd/2001-05-30 )
201.   Where are Mir, the Shuttle, and the ISS right now?   [rupe/2001-03-22]
183.   What are the real lyrics for the poem "Big Rock Candy Mountains"?   [rupe/2001-02-19] ( jesse/2001-06-29 )
130.   How do I resolve the incompatibility of many older Mac applications with OS9?   [rupe/2000-10-08]
108.   How can i get custom ring tones onto my cell phone?   [jesse/2000-07-09]
103.   Where can I find information on how much I'm worth?   [rupe/2000-06-17]
98.   What are the rules for SHOTGUN?   [strick/2000-05-18]
96.   Where can I find information on in-vehicle computer systems?   [rupe/2000-05-24]
73.   How many Zelda games are there?   [vonguard/2001-06-25] ( combee/2001-07-10 mennonite/2001-03-27 )
46.   What is Ross' natural hair color?   [macki/2000-02-03]
45.   Do I have JAVASCRIPT on?   [strick/2000-02-03]
44.   What web pages are by VONGUARD?   [strick/2000-02-02]
18.   Where have all the flowers gone?   [datavortex/2000-01-18]
9.   Where is matt.html's home page?   [strick/2000-01-18]