Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28278 > unrolled thread
| Started by | gwhite <gwhite@ti.com> |
|---|---|
| First post | 2012-09-02 10:23 -0700 |
| Last post | 2012-09-02 14:04 -0700 |
| Articles | 6 on this page of 26 — 10 participants |
Back to article view | Back to comp.lang.python
newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 10:23 -0700
Re: newbie ``print`` question Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-02 18:41 +0100
Re: newbie ``print`` question Joel Goldstick <joel.goldstick@gmail.com> - 2012-09-02 13:44 -0400
Re: newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 12:46 -0700
Re: newbie ``print`` question mblume <foobar@invalid.invalid> - 2012-09-02 17:49 +0000
Re: newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 11:51 -0700
Re: newbie ``print`` question Chris Rebert <clp2@rebertia.com> - 2012-09-02 10:55 -0700
Re: newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 11:51 -0700
Re: newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 12:26 -0700
Re: newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 12:34 -0700
Re: newbie ``print`` question Dave Angel <d@davea.name> - 2012-09-02 15:41 -0400
Re: newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 12:50 -0700
Re: newbie ``print`` question Dave Angel <d@davea.name> - 2012-09-02 16:15 -0400
Re: newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 13:58 -0700
Re: newbie ``print`` question MRAB <python@mrabarnett.plus.com> - 2012-09-02 23:43 +0100
Re: newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 16:33 -0700
Re: newbie ``print`` question MRAB <python@mrabarnett.plus.com> - 2012-09-03 01:12 +0100
Re: newbie ``print`` question Terry Reedy <tjreedy@udel.edu> - 2012-09-02 16:49 -0400
Re: newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 14:18 -0700
Re: newbie ``print`` question Chris Angelico <rosuav@gmail.com> - 2012-09-03 07:47 +1000
Re: newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 16:20 -0700
Re: newbie ``print`` question Chris Angelico <rosuav@gmail.com> - 2012-09-03 09:28 +1000
Re: newbie ``print`` question Terry Reedy <tjreedy@udel.edu> - 2012-09-02 14:33 -0400
Re: newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 12:18 -0700
Re: newbie ``print`` question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-02 16:37 -0400
Re: newbie ``print`` question gwhite <gwhite@ti.com> - 2012-09-02 14:04 -0700
Page 2 of 2 — ← Prev page 1 [2]
| From | gwhite <gwhite@ti.com> |
|---|---|
| Date | 2012-09-02 16:20 -0700 |
| Message-ID | <63ca5a36-04d4-489a-b82e-9bb8e86bdc5e@v19g2000pbt.googlegroups.com> |
| In reply to | #28324 |
On Sep 2, 2:47 pm, Chris Angelico <ros...@gmail.com> wrote: > On Mon, Sep 3, 2012 at 7:18 AM, gwhite <gwh...@ti.com> wrote: > > Thanks again, Terry. There is a lot to the language, I am finding > > out. I am a HW engineer, not really a programmer. Python seems a lot > > more sophisticated than MATLAB. > > > I'm kinda thinking `write` is likely to be a little more "stable" than > > `print` (if that is the right characterization) when my eventual > > switch from 2.7 to 3.x happens. You think? > > If you're planning to switch, make use of __future__. It's > specifically to make that job easier. Once you have a future > declaration at the top, print() will be stable across 2.7 and 3.x. I guess you're saying 3.x will just ignore: from __future__ import print_function I'll risk being silly, and thus ask: but what if when I get to 3.x there is no __future__, as it is now "present?" Do I need to strip out the line? What would happen when I finally started running 3.3, and a new __future__ was made that broke the old syntax? Do I need to strip out the line? I'm probably over thinking it. I don't know what I am doing. lol!
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2012-09-03 09:28 +1000 |
| Message-ID | <mailman.120.1346628500.27098.python-list@python.org> |
| In reply to | #28326 |
On Mon, Sep 3, 2012 at 9:20 AM, gwhite <gwhite@ti.com> wrote: > I guess you're saying 3.x will just ignore: > > from __future__ import print_function > > I'll risk being silly, and thus ask: but what if when I get to 3.x > there is no __future__, as it is now "present?" Do I need to strip > out the line? > > What would happen when I finally started running 3.3, and a new > __future__ was made that broke the old syntax? Do I need to strip out > the line? > > I'm probably over thinking it. I don't know what I am doing. lol! The __future__ statement is guaranteed to be supported forever afterwards. And new ones won't do anything unless you explicitly put them into your code. It's quite a good system, imo. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2012-09-02 14:33 -0400 |
| Message-ID | <mailman.99.1346610805.27098.python-list@python.org> |
| In reply to | #28278 |
On 9/2/2012 1:23 PM, gwhite wrote: > I can't figure out how to stop the "add a space at the beginning" > behavior of the print function. > >>>> print 1,;print 2, > 1 2 You have discovered why print is a function in 3.x. >>> print(1, 2, sep='') 12 >>> print(1, end=''); print(2, end='') 12 In 2.6 or 2.7, you can add from __future__ import print_function but I recommend using 3.2 or 3.3 unless you have a reason to use older Python. -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | gwhite <gwhite@ti.com> |
|---|---|
| Date | 2012-09-02 12:18 -0700 |
| Message-ID | <7e3de84a-6704-4a16-a887-04fb22b7f159@v9g2000pbu.googlegroups.com> |
| In reply to | #28287 |
On Sep 2, 11:33 am, Terry Reedy <tjre...@udel.edu> wrote: > On 9/2/2012 1:23 PM, gwhite wrote: > > > I can't figure out how to stop the "add a space at the beginning" > > behavior of the print function. > > >>>> print 1,;print 2, > > 1 2 > > You have discovered why print is a function in 3.x. > >>> print(1, 2, sep='') > 12 > >>> print(1, end=''); print(2, end='') > 12 > > In 2.6 or 2.7, you can add > from __future__ import print_function > but I recommend using 3.2 or 3.3 unless you have a reason to use older > Python. > > -- > Terry Jan Reedy Thanks. I would use 3.2 or 3.3, but I am actually using pythonxy, which hasn't quite gotten there yet, as the bundle of packages has to all play nice together. Or so I am guessing. I have been considering the __future__ technique.
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-09-02 16:37 -0400 |
| Message-ID | <mailman.112.1346618276.27098.python-list@python.org> |
| In reply to | #28278 |
On Sun, 2 Sep 2012 10:23:53 -0700 (PDT), gwhite <gwhite@ti.com>
declaimed the following in gmane.comp.python.general:
>
> "A space is written before each object is (converted and) written,
> unless the output system believes it is positioned at the beginning of
> a line."
>
> So it is apparently doing what it is supposed to do.
>
> Is there a way to stop this? Or is there a different function that
> will only print what you have in the formatted string?
>
E:\UserData\Wulfraed\My Documents>python
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print "1",;sys.stdout.softspace=0;print "2"
12
>>>
>>> sys.stdout.write("1");sys.stdout.write("2");print
12
>>>
In Python 2.x, the equivalent of fprint/fprintf is NOT print but
sys.stdout.write/file_object.write
"print" is just a convenience function that is designed to translate
its arguments into a textual representation, and then drop it to the
screen. Part of the convenience is to separate output items by a space
and to emit a newline at the end.
.write(), OTOH, does no formatting -- not even new lines. You have
to provide all conversion to text, and line endings.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | gwhite <gwhite@ti.com> |
|---|---|
| Date | 2012-09-02 14:04 -0700 |
| Message-ID | <34d3b3b3-e65d-40a0-8b33-17c6b51b13a8@f4g2000pbq.googlegroups.com> |
| In reply to | #28314 |
On Sep 2, 1:37 pm, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote:
> On Sun, 2 Sep 2012 10:23:53 -0700 (PDT), gwhite <gwh...@ti.com>
> declaimed the following in gmane.comp.python.general:
>
>
>
> > "A space is written before each object is (converted and) written,
> > unless the output system believes it is positioned at the beginning of
> > a line."
>
> > So it is apparently doing what it is supposed to do.
>
> > Is there a way to stop this? Or is there a different function that
> > will only print what you have in the formatted string?
>
> E:\UserData\Wulfraed\My Documents>python
> ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
> Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>
> >>> import sys
> >>> print "1",;sys.stdout.softspace=0;print "2"
> 12
>
> >>> sys.stdout.write("1");sys.stdout.write("2");print
> 12
>
> In Python 2.x, the equivalent of fprint/fprintf is NOT print but
> sys.stdout.write/file_object.write
>
> "print" is just a convenience function that is designed to translate
> its arguments into a textual representation, and then drop it to the
> screen. Part of the convenience is to separate output items by a space
> and to emit a newline at the end.
>
> .write(), OTOH, does no formatting -- not even new lines. You have
> to provide all conversion to text, and line endings.
Thanks. I am starting to get it.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.python
csiph-web