r/Python • • Sep 15 '20

Resource Python 3.9: All You need to know 👊

https://ayushi7rawat.hashnode.dev/python-39-all-you-need-to-know
1.2k Upvotes

204 comments sorted by

240

u/kankyo Sep 15 '20

PEP 616, String methods to remove prefixes and suffixes

This is the big feature right here.

2

u/Umlautica Sep 16 '20

I was wondering how the old str.rstrip("end") and new str.removesuffix("end") differ, and found the explanation in the pep

Because lstrip takes a string as its argument, it could be viewed as taking an iterable of length-1 strings. The API could, therefore, be generalized to accept any iterable of strings, which would be successively removed as prefixes. While this behavior would be consistent, it would not be obvious for users to have to call 'foobar'.lstrip(('foo',)) for the common use case of a single prefix.

Source: https://www.python.org/dev/peps/pep-0616/#expand-the-lstrip-and-rstrip-apis

1

u/ogahozy Sep 16 '20

Very good features

0

u/[deleted] Sep 15 '20

[deleted]

142

u/kankyo Sep 15 '20

Those people would have done s[:-4] previously anyway. Using the new stuff is WAY WAY better.

16

u/enjoytheshow Sep 15 '20

I feel personally attacked

1

u/garbagekr Sep 15 '20

I’m one of those but I’m new. Can you give a quick example of what I should be doing using pathlib ?

10

u/kankyo Sep 15 '20

Path('foo.txt').stem

1

u/garbagekr Sep 15 '20

Oh so this is like for file extension management primarily?

10

u/kankyo Sep 15 '20

It's all path management.

1

u/toyg Sep 15 '20

That also doesn’t work with .tar.gzsadly. It shows as much in the doc. To be safe, you should loop on Path(‘foo.txt’).suffixes until you encounter something that’s not a recognised extension. Bleh.

Really there should be a wrapper method that uses mimetypes.guess_type() and mimetypes.guess_all_extensions() behind the scenes. It would be slower, so it should be an opt-in, but it’s definitely missing.

4

u/kankyo Sep 15 '20

Well... That's a matter of definition. Tar gz is literally a tar inside a gz so I would argue it's correct. It's just a super stupid format.

→ More replies (1)

0

u/[deleted] Sep 15 '20

[deleted]

52

u/Ph0X Sep 15 '20 edited Sep 15 '20

I'm a man of culture, I do s.rsplit('.', 1)[0]

5

u/I_Say_Fool_Of_A_Took Sep 15 '20

This is the way. I'd never trust that the extension is going to be 3 chars. Aiff, wave, for instance.

15

u/super-porp-cola Sep 15 '20

I mean you don't even have to get obscure, there's .jpeg, .docx, and of course .py.

4

u/mipadi Sep 15 '20

Actually, the way is os.path.splitext(s)[0]. ;-)

1

u/JZirkel Sep 16 '20

Thank God I'm not the only one. I was really proud of myself when I discovered I could just add "/" to URLs in my web crawlers and get data from after a certain /. Looking forward to using the new method, but using split for this purpose will be kept in good memory.

→ More replies (12)

0

u/[deleted] Sep 15 '20

[deleted]

13

u/kankyo Sep 15 '20

I think that's worse :P

0

u/[deleted] Sep 15 '20

[deleted]

19

u/Enzyesha Sep 15 '20

I mean, you just moved the magic number. And now it's wordier, and you're passing a non-index value to the [] operator, which looks really alien. I agree, this is much worse

13

u/kankyo Sep 15 '20

You can do

s[:-len('.txt')]

which is way nicer.

4

u/tjthejuggler Sep 15 '20

Oh cool, I really like this. I hope I remember it when the opportunity arises.

→ More replies (1)

2

u/lordrashmi Sep 15 '20

Didn't know about named slices, thanks!

1

u/Mateorabi Sep 15 '20

Wait till you learn about...AIRSHIP SLICE!

0

u/[deleted] Sep 15 '20

[deleted]

5

u/[deleted] Sep 15 '20

[removed] — view removed comment

4

u/xwp-michael Sep 15 '20

Not really, the "proper" way of doing it is to declare a variable and assign the magic number to it, thus removing the magic number and making your intent clear. Though I think your example already kind of does it with the suffix_position = slice(-3, None) bit.

7

u/ianliu88 Sep 15 '20

Nice! Didn't know about pathlib.

3

u/eldrichride Sep 15 '20

VFX folk here are stuck in 2.7 and can only dream of Pathlib.

4

u/c00lnerd314 Sep 15 '20

Out of curiosity, is there a downside to using this?

file_name.split('.')[-1]

13

u/call_me_arosa Sep 15 '20

Files don't necessarily have extensions

1

u/Ph0X Sep 15 '20

replace split with partition

12

u/DarFtr Sep 15 '20

I don't know for sure, but files can have multiple extension such as file that are in download state that are something.mp4.crowndowload It's just a guess anyway, I think it would usually work

8

u/scruffie Sep 15 '20
path.with.dots/file
../file
.dotfile
...manydots
..

If you're not using pathlib, you should be using os.path.splitext, which handles all the above cases (and works with both bytes and strings).

1

u/copperfield42 python enthusiast Sep 15 '20 edited Sep 15 '20

If you want the extension only, this approach fail if you give it a file that doesn't have it for whatever reason, and if you want the name without the extension, doing file_name.split(".")[0] for example fail to consider that there's absolutely nothing stopping you, your user or anything else from using "." in the file name (or path) for whatever reason, for example "my.test.file.txt" is a perfectly valid file name.

Is better to use a function that already have all those things in consideration like os.path.splitext

1

u/yvrelna Sep 16 '20

It'll break if you have something like file_name = "/etc/nginx/conf.d/foobar".

1

u/super-porp-cola Sep 15 '20

Probably should do .split('.')[1:] instead for the reasons others have mentioned.

24

u/[deleted] Sep 15 '20

[removed] — view removed comment

1

u/13steinj Sep 16 '20

I mean in this case it's valid-- it's a .gz file, that when deflated gives you a .tar file.

1

u/copperfield42 python enthusiast Sep 15 '20 edited Sep 15 '20

Since I founded it, I always use os.path.splitext for those things... I didn't know about pathlib

0

u/[deleted] Sep 15 '20

[deleted]

9

u/kankyo Sep 15 '20

Yea this blog spam is incorrect. Not super surprising. It's blog spam.

0

u/[deleted] Sep 15 '20

[deleted]

1

u/kankyo Sep 16 '20 edited Sep 16 '20

No. It checks prefix/suffix and if needed slices. This is faster than the regex.

125

u/Hopeful-Guess5280 Sep 15 '20

The new syntax for dictionary unions is looking cool.

50

u/Sigg3net Sep 15 '20

For a second I read that as dictionary unicorns and I shuddered. It's some mythological, elusive key that might not exist.

4

u/olaf_svengaard Sep 15 '20

Have you not seen “The Last Unicorn”? Where you see a bug I see a feature :)

17

u/anyonethinkingabout Sep 15 '20

It looks cool, but it's yet another unneeded feature that isn't clear upon reading the code. There already is a method, and you could do it in a short snippet as well. So why add it?

13

u/notarealrobotboi Sep 15 '20

You can already use the same operator with sets some other things.

52

u/energybased Sep 15 '20

It replaces {**a, **b} with a | b. That's clearly much better.

84

u/its_a_gibibyte Sep 15 '20

The first one is clearly better. It shows that you're building a new dictionary { } and you want to include all the elements of a and the elements of b.

The second one looks like a boolean expression for or.

57

u/vaevicitis Sep 15 '20

It also looks like a set Union, which is essentially what the operation is for dicts

2

u/I_LIKE_FACE_TATTOOS Sep 15 '20

Wait what? Isn't set union "∪"? Is there an alternative symbol I'm unaware of? 😶

12

u/bakery2k Sep 15 '20

Isn't set union "∪"?

Not in Python.

2

u/copperfield42 python enthusiast Sep 15 '20

Yes, in symbolic notation, but you can't easily type this "∪" with your keyboard, so | is used instead because is available in every keyboard and doesn't need to know some esoteric key combination for it.

Same with the rest of set operation like intersection, and etc.

2

u/ianliu88 Sep 15 '20

Although it is not commutative.

19

u/bakery2k Sep 15 '20

Set union isn't always commutative either:

>>> class A:
...     def __init__(self, x, y):
...             self.x, self.y = x, y
...     def __eq__(self, other):
...             return self.x == other.x if isinstance(other, A) else NotImplemented
...     def __hash__(self):
...             return hash(self.x)
...     def __repr__(self):
...             return f'A({self.x}, {self.y})'
...
>>> {A(0, 0)} | {A(0, 1)}
{A(0, 0)}
>>> {A(0, 1)} | {A(0, 0)}
{A(0, 1)}

12

u/scruffie Sep 15 '20

However, that's commutative with respect to the equality you defined, which is all we can expect.

1

u/ianliu88 Sep 16 '20

Well, I guess if you define dictionary equality by their keys, then the operation would be commutative, but that's generally not the case.

5

u/stevenjd Sep 16 '20

Although it is not commutative.

Neither is {**a, **b}.

Do you do arithmetic on floats? Even addition on floats isn't commutative: a + b + c is not always the same as c + b + a.

Commutativity is over-rated.

1

u/ianliu88 Sep 16 '20

I only pointed out the fact that {**a, **b} isn't a union operation, as stated by the previous comment. It is a dict update, and it is expected for it not to be commutative.

→ More replies (1)

9

u/KFUP Sep 15 '20

The second one looks like a boolean expression for or.

It kinda acts like an 'or', since it is getting elements that are in either a 'or' b, it would be cool if it has an 'and' operator that only gets what is shared between the two.

6

u/energybased Sep 15 '20 edited Sep 15 '20

That operator exists for sets, but for dictionaries, what is {1: 'a'} & {1: 'b'}? I guess it should prefer the second value to stay consistent? (== {1: 'b'})

I think it's better to be explicit here and use a dict comprehension.

5

u/XtremeGoose f'I only use Py {sys.version[:3]}' Sep 15 '20

Check the pep, they talk about dict intersections.

{**x, **y} is ugly IMO, if you don't like the union operator, use

d = d1.copy()
d.update(d2)

A dict comprehension is really hard to read

{k: v for k, v 
 in itertools.chain(d1.items(), d2.items())}
→ More replies (1)

24

u/energybased Sep 15 '20

In that case, you don't like the set union operator either, which has been in Python for at least a decade. This operator replaces set(*a, *b) with a | b.

→ More replies (1)

2

u/SeanBrax Sep 15 '20

In what sense? Conciseness, sure. Readability? Definitely not.

4

u/energybased Sep 15 '20

I agree that it's a personal question. I find | more readable, especially in multiline expressions.

1

u/SeanBrax Sep 15 '20

How does | read more clearly as a union than the proposed alternative?

2

u/energybased Sep 15 '20

I agree that it's a personal question. I find | more readable, especially in multiline expressions.

1

u/SeanBrax Sep 15 '20

I didn’t ask you to repeat yourself. I just asked why in your opinion that’s more readable.

2

u/energybased Sep 15 '20

It's a preference. I guess if I'm forced to think about it, I see dictionary union as a binary operation, so it makes sense to me for it to be encoded using a binary operator.

Also, at the outset of the generalized unpacking syntax ({**, **}, etc.) people on Python ideas did not like its use as a dictionary union.

1

u/flying-sheep Sep 16 '20

I think it's equally clear, and more consistent with the already existing set operations.

1

u/arijit079 Sep 15 '20

Totally agree with you

8

u/Weerdo5255 Sep 15 '20

Ugh, I'm such a nerd but I'm excited as hell for the dictionary unions. Make life so much easier!

1

u/Pythonistar Sep 15 '20

Initially, I was excited, but then I wondered:

What if the keys are the same? which K/V gets kept?

Apparently, K/V pairs with the same key from the 2nd dict overwrite values from the first. Makes sense if you think about it...

But that's kinda side-effect-y and not necessarily obvious.

I agree with /u/XtremeGoose in that d = d1.copy(); d.update(d2) is clearer.

You're very clearly copying dictionary 1 to a new dict and then merging dictionary 2 into 1 overwriting any duplicate keys.

I favor 2 lines of clear code over 1 line of syntactic sugar which is much less obvious.

8

u/XtremeGoose f'I only use Py {sys.version[:3]}' Sep 15 '20

I'm not saying it's cleaner ;) just better thank the {**d1, **d2}.

I'm definitely happy with right associative unions. As said elsewhere in the comments, set unions also act this way.

4

u/Pythonistar Sep 15 '20

Yeah, I think I agree. The ** unpack operator has never pleased me with how it looks. I mean, I know what it does, but it doesn't look clean...

happy with right associative unions. As said elsewhere in the comments, set unions also act this way.

Yeah, it makes sense. The left side gets copied first, the right side overwrites if there are any "same" sets/keys. (for whatever definition of equality that you're using...) You just have to know that's the behavior.

0

u/stevenjd Sep 16 '20

Apparently, K/V pairs with the same key from the 2nd dict overwrite values from the first. Makes sense if you think about it... But that's kinda side-effect-y and not necessarily obvious.

As opposed to your suggestion:

d = d1.copy()
d.update(d2)

which is totally side-effect-y and not necessarily obvious, plus it isn't an expression so it requires an unnecessary temporary variable d.

1

u/Pythonistar Sep 16 '20 edited Sep 16 '20

which is totally side-effect-y and not necessarily obvious

Well, they're all side-effect-y. Any merging of a dictionary is side-effect-y. (in contrast, Merging of Sets is not since ostensibly you can test for equality and remove duplicates.)

plus it isn't an expression so it requires an unnecessary temporary variable d.

What's that got to do with the price of tea in china?

Expression or no, there's always a new variable whether you see it or not.

d = d1.copy()
d.update(d2)

No, that's abundantly clear.

  1. Copy dict to new variable

  2. Update all the key values in that copy with the key values from the second one (because it comes second!)

It's crystal clear.

The former method is unclear just by looking at it. Instead you have to know how it works.

1

u/stevenjd Sep 18 '20

Expression or no, there's always a new variable whether you see it or not.

What? No. Just no.

Here is a thing with a temporary variable:

x = 1+1
print(x)

And here is one without:

print(1+1)

There is no "x" variable, or any other variable, created in the second example. You can inspect locals() or the byte-code if you don't believe me.

Instead you have to know how it works.

As opposed to copy and update, which as we all know, little babies too young to walk or talk are born knowing how they work. /s

-2

u/[deleted] Sep 15 '20

The feature is great, but I don't get the decision to add a new operator for such a simple operation, they could've just used a +.

15

u/bakery2k Sep 15 '20

It's not a new operator. | is already used for bitwise-or of integers, e.g. 5 | 3 == 7.

0

u/[deleted] Sep 15 '20

[deleted]

14

u/Mateorabi Sep 15 '20

What a dict move.

10

u/xigoi Sep 15 '20

The operator has already existed for sets.

0

u/[deleted] Sep 15 '20

[deleted]

4

u/troyunrau ... Sep 15 '20 edited Sep 15 '20

Has existed for ages. I implemented a geometry routine in python 2.7 which used it in the context of computational solid geometry. If you had to solid objects defined by a a collection of polygons, you could take the union or intersection of those objects using the overloaded python set syntax. Made for really clean code. Pity I never did anything with it.

a = sphere(r=1)
b = cube(1,1,1)
c = a & b # intersection of
d = a + b # union of
e = a - b # difference of

Etc. The goal was to create a library that would act sort of like openscad in python. Honestly, I should return to it some day, but I saw my tail and got distracted

1

u/dbulger Sep 16 '20

If you do return to it, and you want a collaborator, message me!

4

u/mipadi Sep 15 '20

There already is: You can implement __or__ in your class.

62

u/xX__NaN__Xx Sep 15 '20

Yooo.. when did this happen!!? I just recently upgraded to 3.8, and 3.9 has already been launched

15

u/[deleted] Sep 15 '20

I’m still in 3.7....

18

u/wxtrails Sep 15 '20

😅 2.7

52

u/mogoh Sep 15 '20

F

6

u/[deleted] Sep 15 '20

U

14

u/[deleted] Sep 15 '20

Corporate legacy code or academic legacy code?

8

u/WillardWhite import this Sep 15 '20

Stuck with VFX programs that are still holding on to 2.7 T.T (cries in Autodesk)

5

u/wxtrails Sep 15 '20

Corporate. Simultaneously hearing different teams shout "That's out of date and insecure, you must upgrade!" and "Ain't nobody got time for that!". So it sits.

1

u/[deleted] Sep 15 '20

Academic legacy code is an oft overlooked problem

1

u/i4mn30 Sep 15 '20

Hobby project for me

20

u/DuskLab Sep 15 '20

Ehhh not much of an excuse there at this point

3

u/Lonke Sep 15 '20

But why

2

u/i4mn30 Sep 16 '20

I just don't work on it actively any more.

It's a simple app, and porting to 3 would not benefit me at all. Just syntax change and a few goodies wouldn't make a huge improvement as it's not for some client and needs constant maintenance which would obviously require me to port it to 3

0

u/[deleted] Sep 15 '20

[deleted]

26

u/Lewistrick Sep 15 '20

The release date for 3.9 final is October 5th.

0

u/[deleted] Sep 15 '20

[deleted]

2

u/caldog20 Sep 16 '20

Damn I was too late.

1

u/[deleted] Sep 15 '20

Arch Linux laughs in you

12

u/SomeShittyDeveloper Sep 15 '20

So will there still be a need for pytz after Python 3.9?

4

u/raziel2p Sep 15 '20

pytz might get more frequent updates. haven't looked into if zoneinfo supports updating in other ways than upgrading python itself.

11

u/DDFoster96 Sep 15 '20

Python will get its timezone info from the operating system if it provides it, or from the core dev-supported tzdata package on PyPI if not (e.g. Windows).

4

u/PeridexisErrant Sep 16 '20

No, and I'd recommend against pytz due to incompatibilities with PEP495 (which, in fairness, it predates).

See https://blog.ganssle.io/articles/2018/03/pytz-fastest-footgun.html for details - Paul Ganssle is the maintainer of dateutil, a CPython core dev, and author of the new zoneinfo library!

20

u/HughMacdonald Sep 15 '20

In your type hinting example, you're missing a d from the start of the function definition

9

u/jabbalaci Sep 15 '20

The International Sniper Academy offers you a one-year scholarship.

7

u/master3243 Sep 15 '20

I actually kept staring at that "ef" wondering what the hell kind of type hinting that was. Thanks for clarifying

7

u/[deleted] Sep 15 '20

Type hinting without importing a library is a great feature

3

u/BAG0N Sep 15 '20

That's pretty dope. BTW can someone explain that performance boost with vectorcall easier?..

2

u/U5efull Sep 15 '20

Being able to update dictionaries using that operator is pretty cool.

2

u/jzia93 Sep 15 '20

I'm still on 3.6 and I can't quite move off it, had a lot of 3.8 problems with Redis in particular and trying to run Unix commands on Windows 10.

Can anyone recommend why should we upgrade earlier than needed?

2

u/proverbialbunny Data Scientist Sep 16 '20

3.8 was a large change causing some services difficulty due to asyncio changes. Some of my code is on 3.7 currently for this reason. (And some on 3.8.) I would need to update my multiprocess code as for some sort of undocumented reason 3.8 breaks it.

However, it's been long enough that large name packages and services should work just fine with 3.8 now. I would hope at this point Redis would have no problem.

I would give it another try at least once every 12 if not 6 months. It's probably fine now.

1

u/jzia93 Sep 16 '20

Thanks, good summary.

Actually this was last week. It's to do with running Ubuntu on Windows. Not ideal I know, but it's an officially supported extension by Microsoft so it's a shame they haven't fixed this.

0

u/[deleted] Sep 16 '20

[deleted]

2

u/jzia93 Sep 16 '20

Cutting me deep 😭

12

u/productive_guy123 Sep 15 '20

Crazy how some companies are on python 2.0 while we're so close to 4.0

53

u/Bahet Sep 15 '20

I don’t think there’s been any confirmation of Python 4

48

u/[deleted] Sep 15 '20 edited Jun 20 '23

Unfortunately Reddit has choosen the path of corporate greed. This is no longer a user based forum but a emotionless money machine. Good buy redditors. -- mass edited with https://redact.dev/

12

u/productive_guy123 Sep 15 '20

Ahh, misunderstood the release transition thanks

18

u/kankyo Sep 15 '20

Afaik the plan is to go to 4.0 just to trigger the removal of the deprecated stuff that is scheduled for 4.0. So it can really happen at any time when the core devs feel like it. There will be no big disruption.

0

u/[deleted] Sep 15 '20

[deleted]

9

u/kankyo Sep 15 '20

There are depreciation warnings in python NOW about 4.0. It's happening. It's just going to be a non-event, the way it should be.

1

u/Mezzomaniac Sep 16 '20

I haven’t come across those deprecation warnings. What do they relate to?

2

u/kankyo Sep 16 '20

Hmm... Seems like they've changed them so now they are about python 3.10. I am not a fan of that. https://www.python.org/dev/peps/pep-0563/

→ More replies (2)

4

u/toyg Sep 15 '20

there is no substantial language change that would justify rewrites to an incompatible python version

4.0 will likely NOT be an incompatible version at all. Nobody wants to repeat 3.0. The most they’ll do is removing long-deprecated features. Code that runs “4.0 - 0.1” will work fine on 4.0, whenever that comes.

31

u/[deleted] Sep 15 '20

None of my customers are on 2.x anymore. I make it a requirement that they upgrade to 3.x and I do not write them anything in 2.x compatibility syntax. I'm doing my part to help fix the world one server at a time.

11

u/[deleted] Sep 15 '20

You’re doing God’s work thank you. I’m in academia and it has been a nightmare. I force everyone I work with to be in python 3. I will not budge, nor accept absolutely anything in python 2.

1

u/Bahet Sep 15 '20

Out of curiosity, what do you do? I’ve never done things server-related with Python

8

u/[deleted] Sep 15 '20

I work for a company that develops software... Sorry that I can't share what software.

I only write Python when a customer needs a custom scripted solution to integrate our software with other items in their environment. Sometimes it's via API, sometimes it's parsing other data files and ingesting them into our software, sometimes it's just automating activity within our software to custom tailor it to their environment. I do this same work on bash/powershell based on their requirements, but when they say Python, I tell them that it's a waste of their money to pay for custom work to be written in a deprecated and unsupported version of a language that is being actively discontinued. Nobody ever argues because they recognize that having longer living code is a better use of their money.

5

u/[deleted] Sep 15 '20

But that isn't particularly controversial, since there isn't a bunch of legacy code that your work depends on. Most people starting new projects will do so in Python 3. It's the millions of lines of code in legacy projects that still need to be maintained that's the showstopper.

1

u/[deleted] Sep 15 '20

No, my work often depends on legacy code.

2

u/[deleted] Sep 15 '20

Yes, but does it operate in the same environment? If you are adding code to a legacy Python 2 project or importing it as a library, you must also be on Python 2. If you are accessing legacy code through REST, a message queue, or a job queue, then the two can operate independently.

If your application is in fact adding code to a legacy project, I would argue you are losing revenue by forcing clients to Python 3. I have worked at large F500 companies with so many LOC in Python 2 that such a requirement would be an instant deal breaker - you would lose the sale.

3

u/[deleted] Sep 15 '20

Not quite. We are deprecating and replacing old sections at times. Code bases I work with aren't millions of lines individually, usually around 500-5k for a single thing. Updating from dead python to current isn't as big of an ask and it's something they are eventually going to have to do so it gets added in as part of the project scope when doing new work or additions.

5

u/sdf_iain Sep 15 '20 edited Sep 15 '20

Python uses does not use semantic versioning, but rather it’s own versioning scheme (assuming I’m reading that PEP right, it’s written to be broadly applicable).

However, the same point stands numbering in any particular spot may exceed ten (I.e. 0.11.13) without automatically incrementing any other section.

EDIT: assumptions changed to be, hopefully, more accurate

9

u/bakery2k Sep 15 '20 edited Sep 15 '20

Python uses semantic versioning

Not exactly. Minor releases often contain some breaking changes.

2

u/[deleted] Sep 15 '20

Basically every project in the history of the world that “adheres to semver”

1

u/muntoo R_{μν} - 1/2 R g_{μν} + Λ g_{μν} = 8π T_{μν} Sep 16 '20

That's because semantic versioning is way too idealistic. It equates all breaking changes to each other. But some breaking changes are much more significant than others. (57 -> 58): dropped support for x86 might be a much more significant change than (56 -> 57): dropped support for Z80 but they look almost the same as each other from the version numbering.

2

u/[deleted] Sep 15 '20

[Citation needed]

1

u/[deleted] Sep 15 '20

Comment to your edit:

"This PEP describes a scheme for identifying versions of Python software distributions, and declaring dependencies on particular versions."

That has nothing to do with Python itself.

https://www.python.org/dev/peps/pep-0440/#abstract

1

u/sdf_iain Sep 15 '20

Is Python not a Python software distribution?

It seems to be written broadly enough to apply to the entire ecosystem, depending on how you read it. And Python versions seem (I didn’t look in detail) to fit with the constraints specified. Of course I could be totally wrong, but then what PEP covers the versioning of Python itself.

1

u/[deleted] Sep 15 '20

Did you read the definitions? Nowhere is Python itself mentioned.

3

u/sdf_iain Sep 15 '20

We could go on about this for a while, but given that this PEP defines how to do versioning for a "Project" (software components that are made available for integration) and PEP20 says "There should be one-- and preferably only one --obvious way to do it", unless you can find a PEP that defines how to version Python itself, PEP-440 probably applies.

→ More replies (1)

1

u/proverbialbunny Data Scientist Sep 16 '20

Really? Isn't Python 2 officially EOL at this point? Many services have stopped supporting it recently. If companies do not upgrade they'll find themselves in the Isles of Legacy. (Which I just made up.)

0

u/[deleted] Sep 15 '20

[deleted]

2

u/PeridexisErrant Sep 16 '20

And you can use flake8-2020 to check for uses of sys.version or sys.version_info that will break with a two-digit minor version!

1

u/ZarsBars Sep 15 '20

Is python 4 close to release or something? Seems like the updates are getting up there

9

u/[deleted] Sep 15 '20

Nope, we'll just go to Python 3.10 at that point. There will probably not be a Python 4.

2

u/[deleted] Sep 15 '20

Got a notice in a python.org email saying 3.6 was EOL.

1

u/ton1czech Sep 16 '20

Very helpful. Thank you

1

u/accept-the-mystery Sep 16 '20

how is removesuffix different from the existing rstrip/lstrip? perhaps the new function only applies to the first occurrence?

in any case, great to see the new version 🙂🙂

0

u/lzantal Sep 15 '20

Not too crazy about dictionary unions syntax. It seems cryptic. I am glad they are making it in but I wish there was cleaner way.

4

u/mipadi Sep 15 '20

I love the idea, but I think it should be a method, e.g, c = a.merge(b), instead.

0

u/[deleted] Sep 15 '20

[deleted]

2

u/mipadi Sep 15 '20

| isn't; update() corresponds to |=.

Anyway, that's my point: I think it should be a method, rather than an operator.

1

u/ThePoulpator Sep 15 '20 edited Sep 15 '20

I have not tested it myself, but since operator are overloaded, methods should work too:

a | n is equivalent to a.__xor__(b)

a |= n is equivalent to a.__ixor__(b)

edit:__or__ actually

3

u/mipadi Sep 15 '20

| is implemented using __or__, and |= is implemented using __ior__. (__xor__ is ^).

And I mean...yeah, that's how Python works, you overload special methods to overload operators. I just mean that I'd prefer a method called, e.g., merge(), to form parity with update(), instead of using operators. Explicit is better than implicit, right everyone? That's what Pythonists always exclaim, right? :-)

(In general I have no problem with overloaded operators, but I don't think the use here is very elegant.)

1

u/its_Aqdas Sep 16 '20

List=[1,1,2,3,5,8,13] print(list[list[4]])

Please explain how the answer is 8

4

u/illpicknamelater Sep 16 '20

list[list[4]] -> list[5] -> 8

Explanation:

list[4] returns 5 which is the 4th (the first index is 0, remember?) element of the list sequence. Hence, list[5] returns 8

3

u/its_Aqdas Sep 16 '20

Oh thanks man

-13

u/KripC2160 Sep 15 '20

Can’t wait for 4.0 (unless it’s going to be 3.9.1 lol)

19

u/Peanutbutter_Warrior Sep 15 '20

3.9.1 will probably be bug fixes and the like, nothing major. It'll be 3.10 for the next major release. It'll only become python 4 when big changes are made that make it not backwards compatible

6

u/metaliving Sep 15 '20

There's going to be a 3.10. There's also no information on python 4.0 ever coming out. After 3.10 there can always be 3.11, 3.12, ... 3.infinity.

Also, just curious, why can't you wait for 4.0?

4

u/saihemanth121 Sep 15 '20

It'll become 4.x only if there are breaking changes and it's no longer backward compatible. It will go to 3.10, 3.11,....3.21 and so on. It's not decimal notation, the dot seperates integers in decreasing order of impact

0

u/[deleted] Sep 16 '20

[deleted]

1

u/gmes78 Sep 16 '20

No, some stuff has been deprecated and removed.

1

u/Caligatio Pythonista Sep 16 '20

Several things have been deprecated but I'm unaware of any removals. Have things actually been removed? I've seen conditional module dependencies check for minimum version, never maximum version.

1

u/gmes78 Sep 16 '20

Yes, they have. You can check the release notes, it's all detailed there. For this release, there were quite a bunch of removals.

Another way is to run your code passing -X dev to the interpreter. You'll be able to see the deprecation warnings, as well as which version those deprecated items will be removed.

1

u/Caligatio Pythonista Sep 16 '20

That was a much larger list than anticipated!

0

u/[deleted] Sep 15 '20

[deleted]

39

u/XtremeGoose f'I only use Py {sys.version[:3]}' Sep 15 '20

Or even better, the what's new in python 3.9 page

13

u/Ph0X Sep 15 '20

Yeah that's much closer. Actual PEPs are very hard to parse for normal people and I definitely would not recommend those as a way to find out what's new for everyone.

I would consider this blog post one level simpler than What's New, with clean examples. There's nothing wrong with having various level of complexity for various needs.

63

u/energybased Sep 15 '20

Yes, but this is still a well-written, well-presented, succinct article. I think some people might prefer it.

28

u/[deleted] Sep 15 '20

Be grateful it's not a YouTube video.

2

u/[deleted] Sep 15 '20

The official release is much more difficult to read in my experience.

1

u/TheIncorrigible1 `__import__('rich').get_console().log(':100:')` Sep 15 '20

Good link. I'm disappointed that they don't separate the words for some reason in removeprefix/suffix. Why do they constantly make inconsistent decisions like this?

4

u/miggaz_elquez Sep 15 '20

Because it's consistent with all str methods :

str.isupper, str.startswith, ...

0

u/[deleted] Sep 15 '20

[deleted]

3

u/TheIncorrigible1 `__import__('rich').get_console().log(':100:')` Sep 15 '20

remove_prefix, yes. removePrefix would really break me just like using the logging package does already.

0

u/[deleted] Sep 15 '20

[deleted]

0

u/[deleted] Sep 15 '20

[deleted]

0

u/[deleted] Sep 15 '20

[deleted]

2

u/execrator Sep 15 '20

Not for your own code of course, but we're talking about the standard library here. If every contributor used their own style things would be a mess (not that there aren't a couple of messes already!)

→ More replies (1)