Python Forum

Full Version: Trying to write one line, writes 2
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So the line below is what P is equal to. Everything works (No Errors)
Issue is, this should print in to a text file line by line

Example:
Quote:Choice1 // Choice2 // Choice3
Choice1 // Choice2 // Choice3
Choice1 // Choice2 // Choice3
Choice1 // Choice2 // Choice3


What actually happens:
Quote:Choice1
// Choice2 // Choice3
Choice1 // Choice2 // Choice3
Choice1
// Choice2 // Choice3
Choice1
// Choice2 // Choice3

p = (random.choice(lines) + " // " + PageFormat[random.randrange(0,85)] + " // " + PageType[random.randrange(0,40)] + "\n")
with open("File.txt", 'a') as l:
                    l.write(p)
I guess lines comes from another file? So each line in linew has a new line char on its own. You need to strip that new line char - here or when you create lines