python - Create a new loop without quotation marks -


i wrote function on python should print sentences below.

def write_to_file(matrix, path):      f = open(path, "w")     f.write('\r\n')     in range (2,5):       item = (bestquarterrate(matrix, i))        item = (str(item))       print item       f.write(item)     f.close() 

the problem this:

('highest quarter rate between', '1/1/15', 'and', '1/3/15', 'with rate:', 924.9966666666666) ('highest quarter average exchange change between', '1/4/15', 'and', '1/6/15', 'with rate:', 598.1673333333333) ('highest quarter volume between', '1/4/13', 'and', '1/6/13', 'with rate:', 158.7078934137758) 

and need change this:

highest quarter rate between 1/1/15 , 1/3/15 rate: 924.996666667  highest quarter average exchange between 1/10/14 , 1/12/14 rate: 1503.67333333  highest quarter volume change rate between 1/4/13 , 1/6/13 rate: 158.707893414  best year 2014 average exchange value of: $1601932.83452 

i help.

your item tuple:

>>> item = ('highest quarter rate between', '1/1/15', 'and', '1/3/15', 'with rate:', 924.9966666666666) 

the string version of tuple representation, example:

>>> str(item) "('highest quarter rate between', '1/1/15', 'and', '1/3/15', 'with rate:', 924.9966666666666)" 

instead, want convert each element in tuple string, join of these strings single string:

>>> ' '.join(map(str, item)) 'highest quarter rate between 1/1/15 , 1/3/15 rate: 924.996666667' 

for further explanation, see documentation on map, str , str.join.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -