hello,
one more question i will have!
now i have written a little programm, which delivers me an output on the
shell!
here is the print command, which delivers me the following output (see
below) on the shell:
print '%-30s | %-12d | %-12d |%-12d ' % (typename,
size / count,
count,
size)
--------------NAME-------------|Groesse(Byte)-|----Anzahl----|-Gesamtgroesse
(Byte)-|
----------------------------------------------------------------------------
----------
ADD_REAL_N6 | 4 | 1 |4
AND_BOOL_N10 | 4 | 1 |4
AND_BOOL_N12 | 4 | 1 |4
Is there a way to put this output in an file?!?! i searched about 2h for
this, but i couldn`t find an answer!
thnks, juergen 5 3417
It sounds like you want to use print >>
If you have an open object with a "write" property, you can do
print >> thefile, mystring
and Python will simply redirect the output to "thefile" instead of
sys.stdout.
f = file('output.txt','w')
print >>f, '%-30s | %-12d | %-12d |%-12d ' % (typename,
size / count,
count,
size)
f.close() hello,
one more question i will have!
now i have written a little programm, which delivers me an output on the shell!
here is the print command, which delivers me the following output (see below) on the shell:
print '%-30s | %-12d | %-12d |%-12d ' % (typename, size / count, count, size) --------------NAME-------------|Groesse(Byte)-|----Anzahl----|-Gesamtgroesse (Byte)-| ---------------------------------------------------------------------------- ---------- ADD_REAL_N6 | 4 | 1 |4 AND_BOOL_N10 | 4 | 1 |4 AND_BOOL_N12 | 4 | 1 |4 Is there a way to put this output in an file?!?! i searched about 2h for this, but i couldn`t find an answer!
thnks, juergen
hello,
if i would type in your code, i became the following output in the
"output.txt" - file
BOOL | 4 | 50463 |201852
but why?!
he wouldn´t do that for all the entrys in the csv file! but only for the
first one in the file!
Stephan Wassipaul wrote: f = file('output.txt','w') print >>f, '%-30s | %-12d | %-12d |%-12d ' % (typename, size / count, count, size) f.close() hello,
one more question i will have!
now i have written a little programm, which delivers me an output on the shell!
here is the print command, which delivers me the following output (see below) on the shell:
print '%-30s | %-12d | %-12d |%-12d ' % (typename, size / count, count, size) --------------NAME-------------|Groesse(Byte)-|----Anzahl----|-Gesamtgroe
sse (Byte)-| -------------------------------------------------------------------------
--- ---------- ADD_REAL_N6 | 4 | 1 |4 AND_BOOL_N10 | 4 | 1 |4 AND_BOOL_N12 | 4 | 1 |4 Is there a way to put this output in an file?!?! i searched about 2h for this, but i couldn`t find an answer!
thnks, juergen
Juergen Huber wrote: hello,
one more question i will have!
now i have written a little programm, which delivers me an output on the shell! Is there a way to put this output in an file?!?! i searched about 2h for this, but i couldn`t find an answer!
thnks, juergen
Others have suggested creating a file.
You could also let the shell to do the work.
If you run the program "normally", output goes to screen:
python myprog.py
Run and redirect the output to a file:
python myprog.py > output_of_myprog.txt
This also makes controlling the output filename much easier.
You could find the following useful: http://www.swc.scipy.org/lec/shell01.html
Juergen Huber wrote:
.... here is the print command, which delivers me the following output (see below) on the shell: print '%-30s | %-12d | %-12d |%-12d ' % (typename, size / count, count, size)
.... Is there a way to put this output in an file?!?!
Another way nobody has yet mentioned:
import sys
old_output, sys.stdout = sys.stdout, open('somefile.txt', 'w')
try:
<<<put call to original code here>>>
finally:
old_output, sys.stdout = sys.stdout, old_output
old_output.close()
print 'Output safely written to:', old_output.name
--Scott David Daniels sc***********@acm.org This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eduardo Hercos Rodrigues |
last post by:
Hi,
How to print directly from PHP code using CUPS?
Thanks,
"Eduardo Hercos Rodrigues"
|
by: Darren Dale |
last post by:
I am using Emacs Python mode, and my project involves reading large
datafiles and processing large arrays. I have some code that reports the
progress during these time consuming processes. It works...
|
by: Kartik |
last post by:
Hi,
I have an ASP.NET application using VB.NET.I am sending a DOS command to a
machine on the network to print a file.
This is achieved using xp_cmdshell
Dim str As String = "xp_cmdshell...
|
by: Salty Dog |
last post by:
No error or any feedback that I can work with.
Code:
set objShell = Server.CreateObject("WScript.Shell")
objShell.Run "%comspec% /c NET PRINT \\Garchive\ISLaser
>c:\WUTemp\Printer_Status1.txt",...
|
by: FPGA05 |
last post by:
Hello All,
I am developing a small application in which I would need a C++
application to read the output from a shell script. A shell script
keeps looking for user inputs and once the user...
| |
by: Brian Turner |
last post by:
I have a filenane defined in a table in my database. This filename
field is also displayed on my form. I have place a print button on my
form. I would like to be abel to click the Print button...
|
by: bearophileHUGS |
last post by:
For array.array "B" means unsigned char, and such arrays accept to be
initialized from (str) strings too, this is quite useful:
But it seems such capability isn't shared with the append:
...
|
by: damonwischik |
last post by:
I'd like to print out a unicode string.
I'm running Python inside Emacs, which understands utf-8, so I want to
force Python to send utf-8 to sys.stdout.
From what I've googled, I think I need...
|
by: Samuel A. Falvo II |
last post by:
I have a shell script script.sh that launches a Java process in the
background using the &-operator, like so:
#!/bin/bash
java ... arguments here ... &
In my Python code, I want to invoke...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |