Python Forum
Interesting new features in python3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interesting new features in python3
#1
I love that PEP 498: Formatted string literals are coming in python 3.6 !

>>> import datetime
>>> name = 'Fred'
>>> age = 50
>>> anniversary = datetime.date(1991, 10, 12)
>>> f'My name is {name}, my age next year is {age+1}, my anniversary is {anniversary:%A, %B %d, %Y}.'
'My name is Fred, my age next year is 51, my anniversary is Saturday, October 12, 1991.'
>>> f'He said his name is {name!r}.'
"He said his name is 'Fred'."
Which are your favorite new python features since 2.x?
Reply
#2
I also like the string formatting, but don't use them because if someone is running python older than 3.6 they won't work
The ordering of dictionaries is a welcome addition, but not sure what it does to performance.
The natural hashing algorithm does not by nature order by key. The only way that I know how to do this (and I have used it in my C code),
is to keep a separate index that is sorted with a cross reference to the hashed entry.
Reply
#3
Things I like since Python 3.x and special since 3.6:

  1. New String formatting
  2. preserved order in dicts; an implementation detail, but if we rely on it, they'll may be guarantee it in 3.7.. maybe
  3. smaller size of dicts and the speed optimization
  4. generalized unpacking:
    first, *middle, last = iterable
    def func(*args, **kwargs):
        return args, kwargs
    
    args1 = (1,2,3)
    args2 = (4,5,6)
    kwargs1 = {'foo': 'bar'}
    kwargs2 = {'boo': 'baz'}
    output = func(*args1, *args2, **kwargs1, **kwargs2)
    print(output)
    Output:
    ((1, 2, 3, 4, 5, 6), {'foo': 'bar', 'boo': 'baz'})
  5. preserved order of kwargs, they guarantee it since Python 3.6
  6. modules: ipaddress, pathlib, secrets, hashlib.pbkdf2,
  7. async stuff: async with, async for, async generator support, not yet used it, but it sounds cool
  8. more stuff i can't remind now
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#4
1. so how long must a feature be in python for you to start using it? 2, or what percentage of your user base needs to be using a python version that include a feature for you to start using it?

for me: 1. a few years unless i have been asking for the feature and then fewer years. 2. 57-85%
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#5
It depends on the feature. If it is something useful, I will use it right away. Since I am my own user base, the only stumbling block is the OS. In Windows I'm using Python v 3.6.1 (soon to upgrade to 3.6.2?) while two of the Linux machines and the RaspberryPi are running 3.4 (though I did manually install 3.6.1 on the Pi) so I sort of have to keep an eye on that if I write something cross platform. Also, to be honest, I probably have never used and maybe never will about 50% of the core library's. I suppose I really should broaden my horizons LOL
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#6
For your own private projects without given dependencies to other modules, you should take the newest.

There is a simple solution for it: pyenv and pyenv-installer.
I'm using for my projects at work currently the newest Python version because I do also build and install the hardware.
Currently I have a bigger Project, which have to be ported from Python 2.7 to 3.x.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#7
(Jun-29-2017, 01:16 AM)Larz60+ Wrote: I also like the string formatting, but don't use them because if someone is running python older than 3.6 they won't work
Ditto
(Jul-05-2017, 06:13 AM)Skaperen Wrote: 1. so how long must a feature be in python for you to start using it? 2, or what percentage of your user base needs to be using a python version that include a feature for you to start using it?
I wouldnt use them because there is still a large base on 2.x As well as anyone using 3.0-3.5. I like to write my code where 2.x or 3.x (any version) can run it. I will probably wait to use them till after 2.x is dead in a couple years. By then all would have moved to 3.x and most moved to a version after 3.6.

I am just now favoring 3.x since 2011, so i suspect it will take awhile before i use new features.
Recommended Tutorials:
Reply
#8
My rule is simple, and rather cowardly. I simply wait for others to start using it.
Reply
#9
What version am I using? That's what I use.
Am I distributing something for other people? Then I'll make minor modifications so it works with a wider range of versions.

Normally, I'm not going to waste my time to accommodate a version of python I'm never going to use. ESPECIALLY if I'm not even going to share what I'm writing. I'd rather just play more Stardew Valley.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  An interesting BUG with double assignment Gribouillis 2 739 Oct-08-2023, 01:56 PM
Last Post: Gribouillis
  Key features of Python Frameworks JahnviK 0 748 Sep-24-2022, 06:09 AM
Last Post: JahnviK
  features examples by release costa_shul 2 2,497 Sep-06-2020, 11:35 AM
Last Post: costa_shul
  most interesting or useful modules? t4keheart 7 3,408 Jan-20-2020, 06:03 AM
Last Post: wavic
  Interesting/Fun Scripts? ejected 2 2,368 Mar-27-2019, 07:49 AM
Last Post: Skaperen
  Interesting article on PyTourch Larz60+ 0 2,274 Jan-03-2018, 09:06 PM
Last Post: Larz60+
  Any interesting works in progress? mpd 5 3,732 Dec-15-2017, 09:34 PM
Last Post: wavic
  An interesting blog wavic 0 2,380 Dec-12-2017, 09:09 PM
Last Post: wavic
  interesting gotcha Skaperen 11 6,479 Nov-30-2017, 03:53 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020