Python, .write question

I am trying to write out attribute values from maya nodes to a text file. I have this working almost. I just need to know how to write a list of values to the file. I get the following error:

# Error: argument 1 must be string or read-only character buffer, not list

Here is the code:

 import maya.cmds as mc
 myFileObject=open('/data/keyFrames.txt', 'w')
 obs = mc.ls(sl=True)
 myY = []
 for selection in obs:
     myAtF = mc.getAttr(selection + '.ty')
     myAt = str(myAtF)
     myY.append(myAt +'\n')
 myFileObject.write(myY)
 myFileObject.close()

I guess the problem lies here:

myFileObject.write(myY)

I need to know how to convert myY (['1.32054365278\n', '9.59632723791\n', '5.49012983596\n']), which is a list, to a string?

What I am trying to end up with raw values, formatted like below, in a text file.

1.32054365278
9.59632723791
5.49012983596

These are the y translate values of three selected spheres, just for example.

myFileObject.write("".join(myY))

tough its easier to write:

import maya.cmds as mc

myFileObject=open('/data/keyFrames.txt', 'w')
strData = [str(i) for i in mc.getAttr('.ty')]
myFileObject.write("\n".join(strData))

pyton 101 please read: http://diveintopython.org/ will cut your devtime considerably

PS: maya treats selection as input list allready no need to loop the loop tehce no need for mc.getAttr(selection + '.ty'). List comprehension is faster than looping btw!

PPS: use the csv module.

That is some clean code Joojaa, thanks. I'll read the link, merci.