Indenting in a txt file from python script in terminal -


im trying write python script make txt file if there isn't current 1 , add "indent me somewhere onto next line" text it. wondering how text indented in middle of string onto next line least amount of python. everyone.

    import sys     if not os.path.exists(/users/you/desktop/aimemory.txt) :         memory = open("aimemory.txt","w")         print("created 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 next line") 

you need put tab character , linefeed @ end, like:

memory.write("\tindent me somewhere onto next line\n") 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -