saving output to file
Eric Anechiarico
wedjlok at attbi.com
Mon Apr 28 19:37:39 EDT 2003
Correct, I am just having the results print out directly within the IDE
window.
That looks as if it what I was looking for and I thank you for the response.
I will give it a shot.
One more thing, though. Do I need to specify a path to the resultfile that
I will be writing to, or will it just default to the directory that Python
resides in when I execute it?
Eric
"Irmen de Jong" <irmen at -NOSPAM-REMOVETHIS-xs4all.nl> wrote in message
news:3ead7e89$0$49116$e4fe514c at news.xs4all.nl...
>
> I'm guessing that you are now "print"-ing the results of your calculations
> to the screen, as in:
>
> def fib(n):
> a,b = 0,1
> while b<n:
> print b,
> a,b = b,a+b
>
> Instead of printing them to the screen, print them to a file:
>
> def fib(n, resultfile):
> a,b = 0,1
> while b<n:
> print >>resultfile, b,
> a,b = b,a+b
>
> fib(2000, open("fibonacci_to_2000.txt",'w'))
>
>
> You might also want to check the following parts of the manual:
>
http://www.python.org/doc/current/tut/node9.html#SECTION00920000000000000000
0
> http://www.python.org/doc/current/lib/module-StringIO.html
>
> If you want you can even replace the 'default' standard output (your
> screen) with your own file object:
>
> sys.stdout=open("my_stdout.txt",'w')
>
> Does this make sense?
>
> --Irmen
>
More information about the Python-list
mailing list