Programming and animation
Programming and animation ideas, articles, tutors, scripts, plugins in the 3d
-
Python. Writing to text file
Posted on 9 July 2009 Neill No commentsRecord some information to the file could be very usefull. For example, in order to debug or output statistics.
This is done in a few trivial steps:
1) open a file for writing
open() – This function returns a file object
For example,
f = open( ‘<filename>’, ‘<mode>’ ),
where filename – text file name
mode - ‘w’ for writing, ‘r’ – for reading
2) to output data, use the command write
f.write( ‘This is a test\n’ )
in this case, the flag ‘\n’ means that after the outputed line, a next line will be a new line. These flags are standard in general, you can watch them in any programming manual.
3) to complete the work with a file, it should be close
f.close()
MotionBuilder Python, Script, TutorialsLeave a Reply
You must be logged in to post a comment.

English
Russian
Recent Comments