print with no newline

Larry Bates lbates at swamisoft.com
Fri Sep 3 10:11:37 EDT 2004


Print with no newline only works to stdout.
If you want to write to a file without
newlines use fp.write("text").

import sys
fp=open('jjj','w')
fp.write(sys.version)
fp.write('running on')
fp.write(sys.platform)
fp.close()

after running jjj contains:

2.2.2 (#37, Nov 26 2002, 10:24:37) [MSC 32 bit (Intel)]running onwin32

HTH,
Larry Bates
Syscon, Inc.

"Paul Watson" <pwatson at redlinepy.com> wrote in message
news:2prasrFo4rruU1 at uni-berlin.de...
> I thought that using a comma at the end of a print statement would
suppress
> printing of a newline.  Am I misunderstanding this feature?  How can I use
> print and not have a newline appended at the end?
>
> C:\src\projects\test1>python -c "import sys;print sys.version, 'running
on',
> sys.platform"
> 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] running on
> win32
>
> C:\src\projects\test1>python -c "print 'here'," >jjj
>
> C:\src\projects\test1>od -c jjj
> 0000000   h   e   r   e  \r  \n
> 0000006
>
>
> $ python -c "import sys;print sys.version, 'running on', sys.platform"
> 2.1 (#1, May 23 2003, 11:43:56) [C] running on aix4
>
> $ cat eoltest.py
> #!/usr/bin/env python
> print 'here',
>
> $ ./eoltest.py >jjj
>
> $ od jjj
> 0000000  068 065 072 065 00a
>            h   e   r   e  \n
> 0000005
>
>





More information about the Python-list mailing list