print problem

58 views
Skip to first unread message

Sumant Shenoy

unread,
Jun 3, 2015, 11:30:21 PM6/3/15
to python_in...@googlegroups.com
ok i am trying to print this out in note pad line by line but but for some reason "\n"is not working am i doing some thing wrong because all the other commands like "\t" are  working 

import maya.cmds as cmds
path=cmds.internalVar(upd=True)+"preset.txt"
file=open(path,'w')
file.write("i am line 1"+"\n")
file.write("i am line 2")
file.close()

Justin Israel

unread,
Jun 3, 2015, 11:47:28 PM6/3/15
to python_in...@googlegroups.com

I don't know what this means. What do you mean by "printing this out in note pad" and "not working" and "other commands like \t"?

Please be very specific about what exactly you are trying to do, what you expect, and what exactly the results were.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAGhqNnn75f%3DBRq6aQV34fZWE0MCraOxHrXWYxFwjSVqOnXZ%2BjA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Sumant Shenoy

unread,
Jun 4, 2015, 12:09:18 AM6/4/15
to python_in...@googlegroups.com
ah sorry for not being clear what i am  trying to do is save preset .so read all the values from option box and check boxes and save it to the notpad file the "/n"
 command is what i found online to type it in the next line and "/t" is is the tab command on the keyboard for indentation 

so when i run the comand it should do the following things 
create a note pad file  in the user pref dir called preset
open the file in write mode
type "i am line 1" (go to next line)
type "i am line 2 "
close file

but in my case every thing is happening properly except for the type in the next line part
hope i am clear this time 
Thank you for your time 

Justin Israel

unread,
Jun 4, 2015, 12:26:04 AM6/4/15
to python_in...@googlegroups.com

Again, when you say something is not working properly, it isn’t clear what your result is (error, or new second line not printing at all, or second print not printing on a new line). I am just going to assume you mean it didn’t print on its own new line…

“\n” and “\t” are special characters (as opposed to commands). The newline character is platform specific, and on Windows you probably want “\r\n”. Python gives you a platform independent way to do it. Give this a try and see if it fixes your problem?

import os
...
# platform specific line separator command via os.linesep
file.write("i am line 1" + os.linesep)

Also, if you want to clean up your snippet a bit, you could write it like this:

import os
import maya.cmds as cmds

path=cmds.internalVar(upd=True)+"preset.txt"
with open(path, 'w') as f:
    f.write("i am line 1" + os.linesep)
    f.write("i am line 2")

Sumant Shenoy

unread,
Jun 4, 2015, 1:45:02 AM6/4/15
to python_in...@googlegroups.com
hey justin 
once again than you  worked like a charm :D will do a better job with explaining the problem next time...

Justin Israel

unread,
Jun 4, 2015, 1:59:00 AM6/4/15
to python_in...@googlegroups.com
Hey no worries. If you just make sure to show any errors, and be very specific about what you expected to see, and what you are actually seeing, then you will probably get an answer on the first reply.

Glad it is working now!

Reply all
Reply to author
Forward
0 new messages