New in Python 3.4.0 (1)-pathlib

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

New in Python 3.4.0 (1)-pathlib
What's new in Python 3.5
What's new in Python 3.6
What's new in Python 3.10 (Summary)
What's new in Python 3.4.0 (2) --enum
What's new in Python 3.9 (Summary)
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Python pathlib memorandum
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
New in Python 3.9 (2)-Sort directed acyclic graphs in Python
New features in Python 3.4.0 (3)-Single-dispatch generic functions
Use pathlib in Maya (Python 2.7) for upcoming Python 3.7
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Edit fonts in Python