On Wed, Dec 9, 2009 at 12:49 PM, biboy mendz <bibsmen...@gmail.com> wrote:
> >> Are you aware of how 'join' works? >> > Hi Luke, > > Thank you. To be honest I'm confused of the different string methods like > join(), split(), etc. Anyway I will practice them to see how they work. > > > It's very important to practice these string methods, you should get intimately acquainted with all the builtin objects and functions, they're extremely flexible and usually very fast as well. The main problem with your 'join' is that join takes an interable and creates a new string with the LHS argument in between each iterated item. So if you join 'a' 'b' 'c', with # you will get 'a#b#c'. Note that there is no # at the beginning or end. In your case, you are outputting to a file, and you want every file to end with a newline, so you simply need to append another newline to the end. "#".join(['a','b','c']) + "#" would do the trick for the # example. The result would be "a#b#c#". Just to be clear, make sure you have your extra newline at the end, not the beginning of the print. Otherwise your first line in the file will be blank. So it does matter where you put the newline. HTH, -Luke
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor