Output Multiple lines to file in Python 2.7.3 -
I am currently writing a program in Python with pyCLIPS
clip module output me in terminal Allows to print several lines of: clip. Printfix ()
However, I want to output it in a file to save it is the result. I am using the following code:
def print (): f1 = open ('/ var / log / combined / test.log', 'a') Print & gt; & Gt; F1, '- fact - \ n' print & gt; & Gt; F1, Clip Printfix () Print & gt; F1, '\ n- Rule - \ n' Print & gt; & Gt; F1, Clip Print Rule ()
The first and third print command to print your wire file successfully but the second and fourth print command still output the clip results in the terminal. Below is an example of output:
============
root @ Ubuntu: / home / user / desktop # Python program PF-0 0 (Preliminary-Facts) F-1 (Duck) F-2 (Quack) Total for 3 facts Main: Rule 1 Rule 2 Rule 3 Rule 4 Rule 5 Root @ Ubuntu: / home / user / desktop # Cat /var/log/combined/test.log - Fact - None - Rule - No Root @ Ubuntu: / home / user / Desktop #
======== ====
Clip. The printfix ()
section starts at "f-0" while clip. Print rule ()
starts with "MAIN"
Thanks in advance!
Add to use a
file:
f1 = open ('/ var / log / combined / test.log', 'a +') Print & gt; & Gt; F1, clip Printfix ()
You can w
.
Comments
Post a Comment