How to skip the line in writing the files?

Asked

Viewed 2,703 times

4

Well, basically, I need to skip a line, after certain writing.

insira o código aqui
print("+---------------------+")
print("|DEMONSTRAÇÃO DA LINHA|")
print("+---------------------+")

print()

arqTeste = open("ArquivoTeste.txt", "w")



arqTeste.write("Python")

#Tentativa de Pular linha
arqTeste.write("")

arqTeste.write("Python 3")
arqTeste.close()

Well, another question, how can I use two objects in writing a file? For example:

insira o código aqui
nome = "Ana"
idade = "20"

arqTest2 = open("arqTest2.txt", "w")

#É essa a minha outra dúvida, não sei como fazer isso!
arqTest2.write("Nome =", nome)
arqTest2.write("Idade =", idade)

arqTest2.close()

2 answers

3


To skip a line when writing a file:

...
#Tentativa de Pular linha
arqTeste.write("\n")
...

To concatenate variables to a string you can do so:

...
#É essa a minha outra dúvida, não sei como fazer isso!
arqTest2.write("Nome = {}".format(nome))
arqTest2.write("Idade = {}".format(idade))
...

Although there are more manners, this is the most "versatile"/advised at the moment

  • Thank you, it worked friend, but, there are no other ways to do these two things(as a matter of curiosity, rsrs)?

  • As for the first one I’m pretty sure no, as for the second one there are more ex: arqTest2.write("Idade = " +str(idade)) , but I advise to use format. @Kappa, if I helped mark sff the answer as accepted, below the arrows above/below the left of the answer

  • Thank you, you took away all my doubts!!

  • @No Kappa, I’m glad you solved

0

Let me get this straight, in case this isn’t it, I’m sorry, buddy! I have an In and Out program, from which I print the BD in ". txt" Here is an idea of the project: (In VB)

 Private Sub btListarValores_Click(sender As Object, e As EventArgs) Handles btListarValores.Click
    Try
        Dim ENTRA(5) As String
        Dim itm As ListViewItem
        ENTRA(0) = TextDesc.Text
        ENTRA(1) = TextMes.Text
        ENTRA(2) = TextData.Text
        ENTRA(3) = TextValor.Text
        ENTRA(4) = TextNota.Text
        itm = New ListViewItem(ENTRA)
        ListViewEntradas.Items.Add(itm)

        'AGORA NO ListTextEntradas...........
        ListTextEntrada.Items.Add(TextDesc.Text)
        ListTextEntrada.Items.Add(TextMes.Text)
        ListTextEntrada.Items.Add(TextData.Text)
        ListTextEntrada.Items.Add(TextValor.Text)
        ListTextEntrada.Items.Add(TextNota.Text)
        ListTextEntrada.Items.Add("__________________________________________________________________")

    Catch ex As Exception
        MsgBox("Erro ao transportar suas digitações para a Lista de Entrada!", MsgBoxStyle.Critical, "Erro: 0Txt:Lst")
    End Try

End Sub

The Print View looks like this: (Print the same way)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.