Posts: 470
Threads: 29
Joined: Sep 2016
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?
Posts: 12,031
Threads: 485
Joined: Sep 2016
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.
Posts: 2,125
Threads: 11
Joined: May 2017
Jun-29-2017, 11:00 AM
(This post was last modified: Jun-29-2017, 11:02 AM by DeaD_EyE.)
Things I like since Python 3.x and special since 3.6:
- New String formatting
- preserved order in dicts; an implementation detail, but if we rely on it, they'll may be guarantee it in 3.7.. maybe
- smaller size of dicts and the speed optimization
- 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'})
- preserved order of kwargs, they guarantee it since Python 3.6
- modules: ipaddress, pathlib, secrets, hashlib.pbkdf2,
- async stuff: async with, async for, async generator support, not yet used it, but it sounds cool
- more stuff i can't remind now
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
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.
Posts: 1,298
Threads: 38
Joined: Sep 2016
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
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
Posts: 2,125
Threads: 11
Joined: May 2017
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.
Posts: 5,151
Threads: 396
Joined: Sep 2016
Jul-05-2017, 02:01 PM
(This post was last modified: Jul-05-2017, 02:02 PM by metulburr.)
(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:
Posts: 12,031
Threads: 485
Joined: Sep 2016
My rule is simple, and rather cowardly. I simply wait for others to start using it.
Posts: 3,458
Threads: 101
Joined: Sep 2016
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.
|