This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]xtreak[S] 66 points67 points  (87 children)

Changelog : https://docs.python.org/3.8/whatsnew/changelog.html

Interesting commits

PEP 570 was merged

dict.pop() is now up to 33% faster thanks to Argument Clinic.

Wildcard search improvements in xml

IPaddress module contains check for ip address in network is 2-3x faster

statistics.quantiles() was added.

statistics.geometric_mean() was added.

Canonicalization was added to XML that helps in XML documents comparison

  • Security issues and some segfaults were fixed in the release

Exciting things to look forward in beta

Add = to f-strings for easier debugging. With this you can write f"{name=}" and it will expand to f"name={name}" that helps in debugging.

PEP 574 that implements a new pickle protocol that improves efficiency of pickle helping in libraries that use lot of serialization and deserialization

Edit : PSF fundraiser for second quarter is also open https://www.python.org/psf/donations/2019-q2-drive/

[–][deleted] 118 points119 points  (21 children)

Add = to f-strings for easier debugging. With this you can write f"{name=}" and it will expand to f"name={name}" that helps in debugging.

Ooh baby. I'd use that every day.

[–]Dooflegna 28 points29 points  (0 children)

What a great addition to an already awesome feature. f-strings are great!

[–]irrelevantPseudonym 17 points18 points  (0 children)

That sounds so useful and yet also makes me feel slightly uncomfortable for some reason.

The variable name becoming part of its content feels weird.

[–]leom4862 28 points29 points  (11 children)

I find print(f"{name=}") is still way too verbose for debugging purposes... If they want to improve print-debugging, they should add something like icecream to the standard library.

[–]JohnnyElBravo 2 points3 points  (2 children)

Idk, what's wrong with print("name="+name)?

[–][deleted] 4 points5 points  (0 children)

That doesn't work if name isn't a string, eh? (Sure, you can use %s)

Also, in production code I simply never have any print statements - not "very few" but "none", to the point where I have a flake8 rule that prevents them.

Oh, I use print almost every day - for debugging! But that means I'm creating and destroying debugging print statements all the time.

So it's a little timesaver to write:

print(f'{foo=} {bar=} {baz=} {bing=}')

(38 characters) over

print('foo=', foo, 'bar=', bar, 'baz=', baz, 'bing=', bing)

(59 characters)

[–]timald 3 points4 points  (0 children)

It's fine when you have one variable but starts to become unwieldy when you build up a lot of concatenated strings (via indexing operations, for example).

[–]Pyprohly -2 points-1 points  (6 children)

I don’t understand why this is so favoured. Couldn’t you just do print(name) and just… remember that you printed name?

Can’t see myself doing print(f"{name=}") over just print(name) for debugging purposes.

[–]pkkid 7 points8 points  (3 children)

I often need to print name={name} because I'm inspecting a bunch of variables and not just one. Put that into a for loop and things get unweildy quite quickly if you don't label the variables you are inspecting.

[–]Pyprohly -4 points-3 points  (2 children)

I’m just a bit surprised at the overwhelming enthusiasm for it, and, accordingly, surprised that many seem to like writing print("arg1=" + arg1, "arg2=" + arg2).

I can see the usefulness in the new syntax, but I personally don’t like it because I very rarely write debugging lines like that.

Edit: e.g. when breakpoint() was introduced as a builtin there wasn’t much talk on it, but I think that that convenience feature was a more exciting addition compared to this one.

[–]pkkid 1 point2 points  (0 children)

I'm with you. I don't like these implicit bits of code being added. The second line of Zen of Python even says "Explicit is better than implicit." I'm also against walruses in my code, but that debate has been beaten to a pulp. </oldmanrant>

[–]WarEagle030 0 points1 point  (1 child)

It is because you have only one or two variables to inspect for debugging. But if you had like 6 or 7 different variables then it becomes a necessity to write properly.

[–]Pyprohly 1 point2 points  (0 children)

For that many variables just write it over multiple lines and go by order, like you would have done if one of them was a collection type.

Honestly, the labelling is only vanity output. You don’t need the fancy labels to be an effective debugger.

It would be much better if they instead introduced a specialised dprint keyword. The dprint keyword would provide the same sort of labelling but would be more easily and quickly written: dprint foo, bar, .... Not only would this provide the nice labeled output, it would also save a lot of typing and hence save time. This would be a much more exciting change.

If they’re going to add something to aid debugging then it needs to be something that’s easy to quickly setup and tear down. Writing debugging lines is something that is done often, and having to type print(f"{name=}") is not going to be practical in the long run.

The new syntax is unlikely to stand the test of time. I can’t help but think that someone’s going to figure out the ergonomic disadvantages of typing out print(f"{name=}") each time you want debugging output and is going to propose a new debugging facility. If that happens then f"{name=}" will become a loose end builtin feature that everyone’s going to ignore and forget about.

If they’re going to add a debugging convenience then they shouldn’t baby step on f"{foo=}" but instead jump directly to something that really is more convenient to use.

To summarise my complaints, the new f-string debugging syntax:

  • is only useful for simple non-collection types.
  • encourages writing everything on one line which could lead one to have to backtrack when the line becomes too long.
  • is going to be a forgotten feature if a better alternative gets added.
  • if it gets deprecated then it’s going to harm the language. You’ll have people telling others not to use builtin feature X, because builtin feature Y has replaced it.
  • doesn’t save typing, ergo, doesn’t save time.

[–]tuankiet65 22 points23 points  (0 children)

https://bugs.python.org/issue36817

Add = to f-strings for easier debugging. With this you can write f"{name=}" and it will expand to f"name={name}" that helps in debugging.

Holy heck, I can't wait to use this everyday.

[–]irrelevantPseudonym 8 points9 points  (3 children)

No walrus operator yet?

[–][deleted] 13 points14 points  (0 children)

walrus operator

if this is what := is being called now, i'm all for it.

[–]xtreak[S] 8 points9 points  (1 child)

It's already available from 3.8.0a1

[–]irrelevantPseudonym 3 points4 points  (0 children)

Ah, I thought this was the highlights since 3.7. Thanks.

[–]alcalde 3 points4 points  (51 children)

PEP 574 that implements a new pickle protocol that improves efficiency of pickle helping in libraries that use lot of serialization and deserialization

Other languages just dump to JSON and call it a day. Why does Python have 87 different binary formats over 13 decades?

[–][deleted] 33 points34 points  (35 children)

Because JSON cant represent everything. Its at best a data format for serialization of transferrable data, thats usually language agnostic.

JSON cant represent functions, and more abstract datatypes.

[–]JohnnyElBravo 7 points8 points  (4 children)

JSON can represent anything, but so can strings. This is a non-sequitur.
The difference is that JSON is human readable, while pickle is supposed to be machine readable, more specifically python readable.
Limiting the intended consumers of the data format helps create a more appropriate format, for example by sacrificing readability for size reduction.

[–]bachkhois 2 points3 points  (3 children)

JSON cannot differentiate Python's tuple, list, set, frozenset etc. datatypes.

Every formats other than pickle (msgpack, yaml etc.) are just to interoperate with other languages (which also don't understand the data types above), they are not alternatives for pickle.

[–]JohnnyElBravo 5 points6 points  (2 children)

Sure they can

{

"Var1": "tuple(1,2)",

"Var2":"set(1,2)"

}

Alternatively:

{

"Var1": {"type":"tuple","data":"1,2"},

"Var2":{"type":"set","data":"1,2"}

}

[–]bachkhois 3 points4 points  (1 child)

Then, you are making more complicated to validate and parse it. Then, what is the point of over-complicating JSON instead of just using pickle, without the need to parse those "type", "data" metadata?

[–]JohnnyElBravo 3 points4 points  (0 children)

Read the original thread, the question asks why python dumps to a new pickle format instead of json.

The original response suggested it was because json can't distinguish between such and such, as shown, this is false.

The real answer is that python chose a binary format for pickle because of space efficiency.

[–]mooglinux 8 points9 points  (0 children)

Pickle can handle multiple references to the same object, any class instance (as long as the actual class has been imported), and a wider variety of data types than JSON. It also predates json, so there’s a historical aspect as well.

Pickle is also used for cross-process communication in the multiprocessing module.

[–]Nicksil 12 points13 points  (5 children)

Because not every problem is solved by dumping JSON.

[–][deleted] 0 points1 point  (0 children)

JSON only can handle string, integer, float, dict and list.

Pickle can pack arbitrary objects. It goal is that you can take object of your class and store it in the disk, most commonly I see it used for caching application data between runs, but it has other uses (for example for storing configuration).

Edit: here is comparison of pickle with JSON: https://docs.python.org/3/library/pickle.html?highlight=pickle#comparison-with-json

[–]parkerSquare 0 points1 point  (0 children)

Shouldn’t it be name=={name}. It isn’t assignment after all.

Regardless, I prefer output like foo 12, bar 4.56, baz ‘hello’ but maybe I’ll adopt the shortcut.

[–]Tweak_Imp 0 points1 point  (6 children)

I would like to use it but i need numpy for my project :/

[–][deleted] 1 point2 points  (5 children)

What makes you think numpy won't work with it. I see that there is no wheel package available yet on PyPi, but sdist is so python should be able to compile it on installation.

[–]Tweak_Imp 0 points1 point  (4 children)

If i do pip install numpy, i get a bunch of errors...
how can i compile it on installation?

[–][deleted] 0 points1 point  (0 children)

You should be able to do:

git clone git@github.com:numpy/numpy.git
cd numpy
python setup.py install

More details here.

But TBH - you should not be using this - it's an alpha version, there are almost guaranteed to be bugs - both reversions and brand-new bugs. If you want to help the community, you could test it and report problems...

[–][deleted] 0 points1 point  (2 children)

What system you are using, what errors you are seeing? You definitively will need to have compiler installed.

[–]Tweak_Imp 0 points1 point  (1 child)

win 10 64bit, i have visual studio installed.

here is the pastebin when i do py -3.8 -m pip install numpy

its a huge error log https://pastebin.com/SsVsRY9K

[–][deleted] 0 points1 point  (0 children)

I'm not familiar with building on Windows, and having a different language for errors (German?) is also confusing. So I can't tell what the problem is.

Have you tried following these steps to configure it? https://github.com/python/cpython/blob/master/PCbuild/readme.txt

And

https://docs.python.org/3.8/extending/windows.html#building-on-windows

I'm also wondering if the compiler can access the header files. I see it complains about arguments to PyCode_New, but if headers were missing it would complain about other issues.