473,484 Members | 1,638 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: Linux.com: Python 3 makes a big break

On Sat, 18 Oct 2008 15:30:23 -0400, Terry Reedy <tj*****@udel.eduwrote:
>http://www.linux.com/feature/150399
Interesting article with one minor incompleteness.
"For instance, the print statement got turned into a print function; you
must now put parentheses around what you want to print to the screen. The
change allows developers to work with print in a more flexible and uniform
way. If someone needs to replace the print function with some other action,
it can be done with a universal search and replace, rather than rewriting
each print statement by hand."

Even easier, print as a function can be replaced simply by defining a new
version with the same name. No search/replace is needed. And reversion to
the built-in only requires commenting out the replacement.
Perhaps it also omitted the fact that nothing prevents you from defining a
function to write things to stdout (or elsewhere) in Python 2.5, making the
Python 3.x change largely a non-feature. ;)

Jean-Paul
Oct 18 '08 #1
8 1161
On 18 Okt., 22:01, Jean-Paul Calderone <exar...@divmod.comwrote:
Perhaps it also omitted the fact that nothing prevents you from defining a
function to write things to stdout (or elsewhere) in Python 2.5, making the
Python 3.x change largely a non-feature. ;)

Jean-Paul
Even more. If someone had solved the hard problem of finding a less
cumbersome way of writing sys.stdout.write(...) the request for
multiline lambdas ( multi expression lambdas actually ) could have
been decreased about 75-80%.

Oct 19 '08 #2
In message
<de**********************************@g61g2000hsf. googlegroups.com>, Kay
Schluehr wrote:
If someone had solved the hard problem of finding a less
cumbersome way of writing sys.stdout.write(...) ...
I don't see what the big deal is. I regularly write things like

sys.stdout.write \
(
"<INPUT TYPE=\"RADIO\" NAME=\"%(name)s\""
" ID=\"%(name)s[%(value)s]\" VALUE=\"%(value)s\"%(checked)s>"
"<LABEL FOR=\"%(name)s[%(value)s]\">%(title)s</LABEL>\n"
# using LABEL lets user click on text to select button
%
{
"name" : EscapeHTML(Name),
"value" : EscapeHTML(Value),
"title" : Title,
"checked" : ("", " CHECKED")[Checked],
}
)

Oct 19 '08 #3
On Sat, 18 Oct 2008 21:34:13 -0700, Kay Schluehr wrote:
On 18 Okt., 22:01, Jean-Paul Calderone <exar...@divmod.comwrote:
>Perhaps it also omitted the fact that nothing prevents you from
defining a function to write things to stdout (or elsewhere) in Python
2.5, making the Python 3.x change largely a non-feature. ;)

Jean-Paul

Even more. If someone had solved the hard problem of finding a less
cumbersome way of writing sys.stdout.write(...) the request for
multiline lambdas ( multi expression lambdas actually ) could have been
decreased about 75-80%.

Er, am I missing something? How about this?

import sys
pr = sys.stdout.write

pr('Is this less cumbersome enough for you?')

But of course, that doesn't really help you avoid multi-expression
lambdas, unless you want to write obfuscated code:

def foo(x):
y = x+1
print y
return y

is roughly, but inefficiently, equivalent to:

lambda x: sys.stdout.write(x+1) or x+1

But that's cumbersome and obfuscated, and not scalable at all.

--
Steven
Oct 19 '08 #4
In article <gd**********@lust.ihug.co.nz>,
Lawrence D'Oliveiro <ld*@geek-central.gen.new_zealandwrote:
>In message
<de**********************************@g61g2000hsf .googlegroups.com>, Kay
Schluehr wrote:
>>
If someone had solved the hard problem of finding a less
cumbersome way of writing sys.stdout.write(...) ...

I don't see what the big deal is. I regularly write things like

sys.stdout.write \
(
"<INPUT TYPE=\"RADIO\" NAME=\"%(name)s\""
" ID=\"%(name)s[%(value)s]\" VALUE=\"%(value)s\"%(checked)s>"
"<LABEL FOR=\"%(name)s[%(value)s]\">%(title)s</LABEL>\n"
# using LABEL lets user click on text to select button
%
{
"name" : EscapeHTML(Name),
"value" : EscapeHTML(Value),
"title" : Title,
"checked" : ("", " CHECKED")[Checked],
}
)
Why are you using a backslash?
--
Aahz (aa**@pythoncraft.com) <* http://www.pythoncraft.com/

import antigravity
Oct 19 '08 #5
On 19 Oct 2008 07:44:52 -0700
aa**@pythoncraft.com (Aahz) wrote:
sys.stdout.write \
(

Why are you using a backslash?
Because he hasn't opened the paren yet. He could have put the open
paren on the same line as the write obviating the need for the
backslash but then his open/close parens wouldn't line up. It just a
matter of style.

--
D'Arcy J.M. Cain <da***@druid.net | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
Oct 19 '08 #6
In article <ma**************************************@python.o rg>,
D'Arcy J.M. Cain <da***@druid.netwrote:
>On 19 Oct 2008 07:44:52 -0700
aa**@pythoncraft.com (Aahz) wrote:
>> sys.stdout.write \
(

Why are you using a backslash?

Because he hasn't opened the paren yet. He could have put the open
paren on the same line as the write obviating the need for the
backslash but then his open/close parens wouldn't line up. It just a
matter of style.
Well, no, it's not *just* a matter of style. I'm strongly opposed to
backslashes because they break when you get whitespace after them. (And
note carefully that I said "when" and not "if".)
--
Aahz (aa**@pythoncraft.com) <* http://www.pythoncraft.com/

import antigravity
Oct 19 '08 #7
In message <vZ******************************@earthlink.com> , Dennis Lee
Bieber wrote:
There is also the matter that the original material is using " on
each line to delimit the string, and then \" within the line to escape
the desired output "s, rather than either using ' for the string and
bare " for the output characters ...
I prefer using double-quotes universally. One less decision to make.
... or triple quoting the whole block...
Not a good idea.
Oct 19 '08 #8
In message <gd**********@panix3.panix.com>, Aahz wrote:
I'm strongly opposed to backslashes because they break when you get
whitespace after them.
1) I've never had that problem.
2) Even if I did, it would report a syntax error, it's not going to fail
silently and introduce any run-time bugs, is it?
Oct 19 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2993
by: inquirydog | last post by:
Hello- I, the inquirydog, would like to solicit suggestions for a new web page I am making: I am creating a simple website that will translate concepts between windows os's, Linux, and the...
699
33305
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
34
5039
by: Maboroshi | last post by:
Hello My question has to do with python and linux - I was interested in finding out what it would take to reimplement the Linux Kernel in python basically just taking the source code from linux...
0
1634
by: David H | last post by:
Background. I'm running on WinXP w/ MS Services for Unix installed (to give rsh/rlogin ability), both Python 2.3 and 2.4 version. In linux, I'm running RHEE with python2.3 version. The code...
10
1709
by: stylecomputers | last post by:
Hey guys, I am absolutely new to Linux programming, with no w######s programming experience except a small amount of C++ console apps. Reasonably new to Linux, BSD etc, got good sound networking...
53
5276
by: noahmd | last post by:
Okay, once-upon-a-time I tried to start programming by learning C. At the time I was younger and didn't really understand all that C had to offer. I eventually moved over to Microsoft's Visual...
852
27933
by: Mark Tarver | last post by:
How do you compare Python to Lisp? What specific advantages do you think that one has over the other? Note I'm not a Python person and I have no axes to grind here. This is just a question for...
2
20801
jwwicks
by: jwwicks | last post by:
C/C++ Programs and Debugging in Linux This tutorial will give you a basic idea how to debug a program in Linux using GDB. As you are aware Visual Studio doesn’t run on Linux so you have to use...
6
1540
by: Terry Reedy | last post by:
http://www.linux.com/feature/150399 Interesting article with one minor incompleteness. "For instance, the print statement got turned into a print function; you must now put parentheses around what...
0
7083
marktang
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,...
0
6954
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...
0
7106
Oralloy
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,...
0
7146
jinu1996
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...
1
6815
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...
0
5407
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4531
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...
0
3042
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
237
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.