2016-05-28 7 views
-1

Imは、現在のものがない場合はtxtファイルを作成するpythonスクリプトを作成しようとしており、このテキストを次の行に「インデントする」と追加します。私は、文字列の途中でテキストを次の行にどのようにインデントすることができるのだろうかと思っています。みんな、ありがとう。端末のPythonスクリプトからtxtファイルにインデントする

import sys 
    if not os.path.exists(/Users/you/Desktop/AIMemory.txt) : 
     memory = open("AIMemory.txt","w") 
     print("Created A New Memory") 
    else : 
     print("Accessing Memory") 
     memory = open("AIMemory.txt", "r") 
     print(memory.read()) 
     memory.close() 
    memory = open("AIMemory.txt", "a") 
    memory.write("Indent Me Somewhere Onto The Next Line") 
+0

"Ident Me ..."の前に "\ t"を入れようとしています –

+0

それは私のために働いていないようですが、テキストをインデントして新しい行にプッシュしません。 – user3291150

+0

最後に " \ n " –

答えて

1

のようにあなたは、最後にタブ文字や改行を入れる必要があります:あなたは memory.write("\tIndent me onto the next line \n")を配置する必要があり

memory.write("\tIndent Me Somewhere Onto The Next Line\n") 
0

。あなたがしたい場合

OR

memory.write("\n\tIndent me onto the next line ")

、最初の行が空白にします。

関連する問題