I think it's already written here and there, but Python 3.4.0 was released on 3/16. The first of the 3.4 series.
Since the first Python 3 (3.0.0) came out in December 2008, is it more than five years old? The first release of 2.7, the last 2.x series, was also in July 2010, so it's been almost four years since then.
I kept using 2.7 for various reasons such as slowness, instability, and lack of libraries. However, there was also a saying, "Look at people and re-turn me," and I first thought that the library I would write would support both.
So I started using 3, but while doing so, 3.4 came out. First of all, there are changes to the 3.3 series because it has to be seen since it came out.
It's faster to look at https://www.python.org/download/releases/3.4.0/ because it's listed with a link, but just reading the docs doesn't really come to mind.
If so, it's best to use it, but I can't do it all at once (and the reader gets tired), so I'll try using it one by one.
From top to bottom, this time about pathlib. Pathlib seems to be an "object-oriented module that handles file system paths". I haven't used it, but it's also on pypi, and it seems that Python2,7, 3,2, 3.3 can be used by pip install.
Try some by browsing the documentation. First, the code to get the list of directories under the current directory.
#Import Path class
from pathlib import Path
#Create a Path object that represents the current directory
p = Path('.')
#Turn with a for statement and print out
for p in p.iterdir():
if x.is_dir():
print (x)
#Get in list for later use
dirlist = [x for x in p.iterdir() if x.is_dir()]
...
What's interesting is that you can access the hierarchy using the division operator. For example, you can do the following:
#Import Path class
from pathlib import Path
#Create Path object by specifying absolute path
usr_local_path = Path('/usr/local')
#Path object that represents files in the lower hierarchy
python_path = usr_local_path / 'bin' / 'python'
#In case of Symbolic link, you can also get the path of the original file
python_real_path = python_path.resolve()
In addition, there are open () and stat () as methods of Path object, and it seems that you can do everything you can do with file operations.
I'm worried about how to live separately from os.path, but I wonder if pathlib will be used gradually. It's a little time out so I'll try again next time. Just in case, the description of pathlib in the standard documentation is here.
And I would like to try the remaining "3.4 New addition functions", but if I write at this pace, the next release may have come out by the end (?)
Recommended Posts