Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

PEP 428: The pathlib module – object-oriented filesystem paths.

>>> from pathlib import Path
Comment

PEP 428: The pathlib module – object-oriented filesystem paths.

>>> p = Path('.')
>>> [x for x in p.iterdir() if x.is_dir()]
[PosixPath('.hg'), PosixPath('docs'), PosixPath('dist'),
 PosixPath('__pycache__'), PosixPath('build')]
Comment

PEP 428: The pathlib module – object-oriented filesystem paths.

>>> list(p.glob('**/*.py'))
[PosixPath('test_pathlib.py'), PosixPath('setup.py'),
 PosixPath('pathlib.py'), PosixPath('docs/conf.py'),
 PosixPath('build/lib/pathlib.py')]
Comment

PEP 428: The pathlib module – object-oriented filesystem paths.

>>> p = Path('/etc')
>>> q = p / 'init.d' / 'reboot'
>>> q
PosixPath('/etc/init.d/reboot')
>>> q.resolve()
PosixPath('/etc/rc.d/init.d/halt')
Comment

PEP 428: The pathlib module – object-oriented filesystem paths.

>>> q.exists()
True
>>> q.is_dir()
False
Comment

PEP 428: The pathlib module – object-oriented filesystem paths.

>>> with q.open() as f: f.readline()
...
'#!/bin/bash
'
Comment

PEP 428: The pathlib module – object-oriented filesystem paths.

>>> PurePath('setup.py')      # Running on a Unix machine
PurePosixPath('setup.py')
Comment

PEP 428: The pathlib module – object-oriented filesystem paths.

>>> PurePath('foo', 'some/path', 'bar')
PurePosixPath('foo/some/path/bar')
>>> PurePath(Path('foo'), Path('bar'))
PurePosixPath('foo/bar')
Comment

PEP 428: The pathlib module – object-oriented filesystem paths.

>>> PurePath()
PurePosixPath('.')
Comment

PEP 428: The pathlib module – object-oriented filesystem paths.

>>> PurePath('/etc', '/usr', 'lib64')
PurePosixPath('/usr/lib64')
>>> PureWindowsPath('c:/Windows', 'd:bar')
PureWindowsPath('d:bar')
Comment

PEP 428: The pathlib module – object-oriented filesystem paths.

>>> PureWindowsPath('c:/Windows', '/Program Files')
PureWindowsPath('c:/Program Files')
Comment

PREVIOUS NEXT
Code Example
Python :: Solution to Remove Recursion Limitation in python 
Python :: Unpacking list using underscore 
Python :: creating a record in python 
Python :: how list comprehension for 2D works 
Python :: python code for diamond with gap between odd rows 
Python :: BeautifulSoup in pretty way 
Python :: python get pc runtime 
Python :: Python String to array using list comprehension 
Python :: convert multidimentional numpy array to string and back 
Python :: python API translate language into Igbo 
Python :: pyton get minimum value of array 
Python :: if condition in python 1 
Python :: if the answer satisfiest the condition so how to stop it to run further ahead in python 
Python :: python random number generator 
Python :: encanto meaning spanish 
Python :: plot bar chart python with resulting numbers 
Python :: Python - Comment faire pour supprimer les cotes de Chaîne 
Python :: flash not defined python flask 
Python :: how to make celery create missing queue 
Python :: python length checker/fill 
Python :: remove cooldown discord python 
Python :: django time cualtulate 
Python :: Get timestamp with pyrhon 
Python :: loading kivy lang 
Python :: first n lis tpython 
Python :: wx.SingleInstanceCheckerindexmodules 
Python :: colorama input python 
Python :: how to check the version of ployly 
Python :: except Exception, e: suds python 
Python :: how to restore windows security 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =