Args:
path: the path of the file to delete
+ Raises:
+ FileNotFoundError: the path to remove does not exist
+
>>> import os
>>> filename = '/tmp/file_utils_test_file'
>>> os.system(f'touch {filename}')
>>> remove(filename)
>>> does_file_exist(filename)
False
+
+ >>> remove("/tmp/23r23r23rwdfwfwefgdfgwerhwrgewrgergerg22r")
+ Traceback (most recent call last):
+ ...
+ FileNotFoundError: [Errno 2] No such file or directory: '/tmp/23r23r23rwdfwfwefgdfgwerhwrgewrgergerg22r'
"""
os.remove(path)
Args:
path: the path to attempt to create
- on_error: If set, it's invoked on error conditions and passed then
- path and OSError that it caused.
+ on_error: if provided, this is invoked on error conditions and
+ passed the path and OSError that it caused
Raises:
- OSError: an exception occurred and on_error not set.
+ OSError: an exception occurred and on_error was not set.
See also :meth:`does_file_exist`.
.. warning::
-
Files are created with mode 0o0777 (i.e. world read/writeable).
>>> import uuid
Returns:
True if filename exists and is a normal file.
+ .. note::
+ A Python core philosophy is: it's easier to ask forgiveness
+ than permission (https://docs.python.org/3/glossary.html#term-EAFP).
+ That is, code that just tries an operation and handles the set of
+ Exceptions that may arise is the preferred style. That said, this
+ function can still be useful in some situations.
+
See also :meth:`create_path_if_not_exist`, :meth:`is_readable`.
>>> does_file_exist(__file__)
True if file exists, is a normal file and is writable by the
current process. False otherwise.
+ .. note::
+ A Python core philosophy is: it's easier to ask forgiveness
+ than permission (https://docs.python.org/3/glossary.html#term-EAFP).
+ That is, code that just tries an operation and handles the set of
+ Exceptions that may arise is the preferred style. That said, this
+ function can still be useful in some situations.
+
See also :meth:`is_readable`, :meth:`does_file_exist`.
"""
return os.access(filename, os.W_OK)
True if file exists, is a normal file and is executable by the
current process. False otherwise.
+ .. note::
+ A Python core philosophy is: it's easier to ask forgiveness
+ than permission (https://docs.python.org/3/glossary.html#term-EAFP).
+ That is, code that just tries an operation and handles the set of
+ Exceptions that may arise is the preferred style. That said, this
+ function can still be useful in some situations.
+
See also :meth:`does_file_exist`, :meth:`is_readable`,
:meth:`is_writable`.
"""
Returns:
True if filename is a normal file.
+ .. note::
+ A Python core philosophy is: it's easier to ask forgiveness
+ than permission (https://docs.python.org/3/glossary.html#term-EAFP).
+ That is, code that just tries an operation and handles the set of
+ Exceptions that may arise is the preferred style. That said, this
+ function can still be useful in some situations.
+
See also :meth:`is_directory`, :meth:`does_file_exist`, :meth:`is_symlink`.
>>> is_normal_file(__file__)
Returns:
True if filename is a directory
+ .. note::
+ A Python core philosophy is: it's easier to ask forgiveness
+ than permission (https://docs.python.org/3/glossary.html#term-EAFP).
+ That is, code that just tries an operation and handles the set of
+ Exceptions that may arise is the preferred style. That said, this
+ function can still be useful in some situations.
+
See also :meth:`does_directory_exist`, :meth:`is_normal_file`,
:meth:`is_symlink`.
Returns:
True if filename is a symlink, False otherwise.
+ .. note::
+ A Python core philosophy is: it's easier to ask forgiveness
+ than permission (https://docs.python.org/3/glossary.html#term-EAFP).
+ That is, code that just tries an operation and handles the set of
+ Exceptions that may arise is the preferred style. That said, this
+ function can still be useful in some situations.
+
See also :meth:`is_directory`, :meth:`is_normal_file`.
>>> is_symlink('/tmp')