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-11-08)

433.   My boss has developers that use SOAP? How can I help them debug their lame web2.0 non-sense? (Or how can i search inside a given http session for a string using tethereal?)   [jake/2006-05-24]
422.   What is a tofinfant?   [jake/2005-02-18]
418.   What is a comfort vegan?   [jake/2004-12-10]
386.   What is Trinux ?   [brad/2003-10-06]
374.   How can I make Gnu/Linux behave like a Real Unix (TM)?   [jake/2003-09-22]
364.   What is the best list of security tools at the moment?   [jake/2003-07-06]
359.   Is Larry Wall on crack?   [strick/2003-04-10]
341.   Can you give me some pointers for using gpg/pgp and other encryption?   [jake/2002-12-19]
333.   what is the orgin of the word family?   [jesse/2002-10-25]
289.   How do I install a CPAN module in Perl?   [rupe/2001-11-21]
271.   I am stupid and forgot my root password for my OpenBSD box. Now what?!?!   [ross/2001-09-05]
262.   Ricochet is dead for now. What are some alternatives?   [rupe/2001-08-07]
260.   What is the best language to search google with?   [kurt/2001-07-23]
254.   how do i setup my orinoco wirelss card with linux 2.4.x?   [jesse/2001-07-03]
244.   Does Jeffrey read too many web comics each day?   [strick/2001-06-06]
124.   How do I make common modifications to my Gnu Emacs .emacs file?   [rupe/2000-09-26]
86.   How do those little Anti-Shoplifting tags work?   [strick/2000-05-02]
85.   What's another good PCS email utility?   [rupe/2001-03-28]
52.   What countries are .HR .SR .TT .LK etc.   [strick/2000-02-07]
24.   Why is the ocean blue?   [simon/2000-01-20]