write multiple lines in a file in python

前端 未结 8 1846
长情又很酷
长情又很酷 2020-12-03 08:04

I have the following code:

line1 = raw_input(\"line 1: \")
line2 = raw_input(\"line 2: \")
line3 = raw_input(\"line 3: \")
print \"I\'m going to write these          


        
8条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 08:25

    I notice that this is a study drill from the book "Learn Python The Hard Way". Though you've asked this question 3 years ago, I'm posting this for new users to say that don't ask in stackoverflow directly. At least read the documentation before asking.

    And as far as the question is concerned, using writelines is the easiest way.

    Use it like this:

    target.writelines([line1, line2, line3])
    

    And as alkid said, you messed with the brackets, just follow what he said.

提交回复
热议问题