Sorry no as that would often leave out data that I consider important.
I have no interest in whether or not you agree with my opinion.
On 05/01/2016 00:53, Steven D'Aprano wrote:
On Mon, Jan 04, 2016 at 07:50:59PM +, Mark Lawrence wrote:
On 03/01/2016 13:12, Alan Gauld wrote:
[snip unnec
On Mon, Jan 04, 2016 at 07:50:59PM +, Mark Lawrence wrote:
> On 03/01/2016 13:12, Alan Gauld wrote:
[snip unnecessary quoting]
> >There are several reasons although your technique is far from
> >the worst way of doing things. And the format string here would probably
> >be better written as:
On 04/01/16 19:50, Mark Lawrence wrote:
> Three reasons for why it's better but it doesn't actually work as given.
>
> >>> island = "Isle Of Wight"
> >>> new = "Isle of Wong"
> >>> print("You've visited {0} & {2}.".format(island, new))
> Traceback (most recent call last):
>File "", line 1,
On 04/01/2016 21:54, Bod Soutar via Tutor wrote:
On 4 January 2016 at 19:50, Mark Lawrence
Three reasons for why it's better but it doesn't actually work as given.
island = "Isle Of Wight"
new = "Isle of Wong"
print("You've visited {0} & {2}.".format(island, new))
Traceback (most recent call
On 4 January 2016 at 19:50, Mark Lawrence
>
> Three reasons for why it's better but it doesn't actually work as given.
>
island = "Isle Of Wight"
new = "Isle of Wong"
print("You've visited {0} & {2}.".format(island, new))
> Traceback (most recent call last):
> File "", line 1, in
On 03/01/2016 13:12, Alan Gauld wrote:
On 03/01/16 12:27, yehudak . wrote:
Hi there,
In a program I wrote the following line (Python 3.5):
print("You've visited", island, '&', new + ".")
A programmer told me that it's a bad habit, and I should have used instead:
print("You've visited {0} {1}
On 04/01/16 03:46, Steven D'Aprano wrote:
>> fmtString = "You've visited {0} & {2}."
>> if foo:
>> print(fmtString.format(foo,bar))
>> else:
>> print(fmtString.format(baz,bad))
>
> I wouldn't write it like that. I'd write:
>
> if foo:
> args = (foo, bar)
>
On Sun, Jan 03, 2016 at 01:12:41PM +, Alan Gauld wrote:
> Why is it better?
> 1) It is slightly more performant.
Consider that format has to build the entire output as a new string in
advance:
"You've visited {0} & {2}.".format(island, new)
gets generated before being passed to print for
On Sun, Jan 03, 2016 at 02:04:22PM +0100, Chris Warrick wrote:
> Here are a couple of reasons:
> * String formatting works everywhere, but this syntax is specific to
> print() — if you use something else, you might end up producing faulty
> code
That argument doesn't make sense to me. I think you
On Sun, Jan 03, 2016 at 02:27:01PM +0200, yehudak . wrote:
> Hi there,
> In a program I wrote the following line (Python 3.5):
>
> print("You've visited", island, '&', new + ".")
>
> A programmer told me that it's a bad habit, and I should have used instead:
>
> print("You've visited {0} {1} {2}
On 03/01/16 13:09, Peter Otten wrote:
> In future versions of Python you can simplify it to
>
> print(f"You've visited {island}, & {new}.")
>
> https://www.python.org/dev/peps/pep-0498/
I hadn't seen that before. Interesting link, thanks.
I think I like it but only time and experience will
Important point. Thanks again.
Yehuda
On Sun, Jan 3, 2016 at 3:10 PM, Francois Dion
wrote:
> And as Chris points out, if there is any possibility that the words will
> be in a different order in a different language, use {0}, {1} instead of {}.
>
>
> Francois
>
> On Sun, Jan 3, 2016 at 8:04 AM,
On 03/01/16 12:27, yehudak . wrote:
> Hi there,
> In a program I wrote the following line (Python 3.5):
>
> print("You've visited", island, '&', new + ".")
>
> A programmer told me that it's a bad habit, and I should have used instead:
>
> print("You've visited {0} {1} {2}{3}".format(island, "&"
And as Chris points out, if there is any possibility that the words will be
in a different order in a different language, use {0}, {1} instead of {}.
Francois
On Sun, Jan 3, 2016 at 8:04 AM, Chris Warrick wrote:
> On 3 January 2016 at 13:27, yehudak . wrote:
> > Hi there,
> > In a program I w
yehudak . wrote:
> Hi there,
> In a program I wrote the following line (Python 3.5):
>
> print("You've visited", island, '&', new + ".")
>
> A programmer told me that it's a bad habit, and I should have used
> instead:
>
> print("You've visited {0} {1} {2}{3}".format(island, "&", new, "."))
>
The answer is neither. The second shows the intent in part but doesn't
quite get it right.
The intent is to have a string template and insert values in that template:
print("You've visited {} & {}.".format(island, new)
This is totally clear what is going to happen. I'm not relying on the
behavio
On 3 January 2016 at 13:27, yehudak . wrote:
> Hi there,
> In a program I wrote the following line (Python 3.5):
>
> print("You've visited", island, '&', new + ".")
>
> A programmer told me that it's a bad habit, and I should have used instead:
>
> print("You've visited {0} {1} {2}{3}".format(isla
17 matches
Mail list logo