News for hackers. Stuff that matters.
Re:Python 3.6.0 released by makecheck on Friday December 23, 2016 @12:09PM (#13245818)
I’m curious actually why an f-string syntax is considered OK when a print-statement is not.

I mean, there’s a precedent for short built-in functions like len(), and apparently 'print "x"' as a statement was terrible so 'print("x")' replaced it. If they wanted such consistency, shouldn’t they have used 'f("{a} {b}")' or something? Or alternately, allow p-strings like 'p"hello, world"' to print?

Re:Python 3.6.0 released by richard_todd on Friday December 23, 2016 @12:14PM (#13245841)
That would not be a traditional function, because you want {a} to be evaluated in the context of the caller, rather than the context of f.
Re:Python 3.6.0 released by sirtaj on Friday December 23, 2016 @12:40PM (#13245996)
As I understand it, print() was created not from a sense of consistency, but because a few awkward cases could be simply solved by turning print from a statement into an expression. Use in lambdas would be one example.
Re:Python 3.6.0 released by mixmastamyk on Friday December 23, 2016 @03:00PM (#13246893)
I don't like the extra parens, but I made an editor shortcut to alleviate that.

Other cases such as redirecting to a file, and changing the line ending are handled much more intuitively with the print function.

Re:Python 3.6.0 released by rtpg on Friday December 23, 2016 @02:49PM (#13246828)
In order to implement `f` as a plain function with same behaviour as g-strings, you would probably have to do some stack trickery to properly capture locals.

In fact, I don't think it would be possible to write such a function in the general case, because it's ambiguous what environment you would need to use.

For example:

def call(func, arg):

    a = 2

    return func(arg)
a = 1

print(call(f, "{a}"))

Does this print 1 or 2?

Re:Python 3.6.0 released by dragonwriter on Friday December 23, 2016 @10:38PM (#13248435)
> I’m curious actually why an f-string syntax is considered OK when a print-statement is not.

One reason might be that f-strings work in expressions, while statements do not. Even with the BDFLs apparent distaste for functional programming constructs, syntax that works within expressions has lots of practical advantages over statements.

Re:Python 3.6.0 released by NegativeLatency on Friday December 23, 2016 @01:06PM (#13246198)
The prefix isn't new, there were already u, b, and r strings.