If you don’t need atomicity you can use os module:
import os if not os.path.exists('/tmp/test'): os.mknod('/tmp/test')
UPDATE:
As Cory Klein mentioned, on Mac OS for using os.mknod() you need a root permissions, so if you are Mac OS user, you may use open() instead of os.mknod()
import os if not os.path.exists('/tmp/test'): with open('/tmp/test', 'w'): pass
Related Posts:
- Converting dictionary to JSON
- Saving and loading objects and using pickle
- numpy: Invalid value encountered in true_divide
- Invalid character in identifier
- Is “from matplotlib import pyplot as plt” == “import matplotlib.pyplot as plt”?
- ‘str’ object does not support item assignment
- What does `ValueError: cannot reindex from a duplicate axis` mean?
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- How to print an exception in Python?
- What are “named tuples” in Python?
- What do these operators mean (** , ^ , %, //)? [closed]
- Python open() gives FileNotFoundError/IOError: Errno 2 No such file or directory
- Jupyter Notebook not saving: ‘_xsrf’ argument missing from post
- FileNotFoundError: [Errno 2] No such file or directory
- ImportError: No module named requests
- ValueError: all the input arrays must have same number of dimensions
- Get the data received in a Flask request
- Python function execution
- Where do I find the bashrc file on Mac?
- ValueError: setting an array element with a sequence
- Why does num = 100?
- How do order of operations go on Python?
- Python group by
- What is the difference between pip and conda?
- How to clear variables in ipython?
- How does the “view” method work in PyTorch?
- TypeError: generatecode() takes 0 positional arguments but 1 was given
- python – if not in list
- syntaxError: ‘continue’ not properly in loop
- How to get the ASCII value of a character
- How do I set the figure title and axes labels font size in Matplotlib?
- How to raise a numpy array to a power? (corresponding to repeated matrix multiplications, not elementwise)
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- TypeError(“‘bool’ object is not iterable”,) when trying to return a Boolean
- Flask Template Not found
- Making a collatz program automate the boring stuff
- Reverse / invert a dictionary mapping
- using pip3: module “importlib._bootstrap” has no attribute “SourceFileLoader”
- TypeError: unsupported operand type(s) for -: ‘list’ and ‘list’
- What’s the difference between a Python module and a Python package?
- How to overcome “datetime.datetime not JSON serializable”?
- AttributeError: ‘datetime’ module has no attribute ‘strptime’
- Where does this come from: -*- coding: utf-8 -*-
- Open file in a relative location in Python
- Python add item to the tuple
- How to print a dictionary’s key?
- Selenium using Python – Geckodriver executable needs to be in PATH
- Spark RDD to DataFrame python
- Running an outside program (executable) in Python?
- SyntaxError invalid token
- TypeError: ‘type’ object is not iterable – Iterating over object instances
- How to check the version of scipy
- How to check if type of a variable is string?
- How to print colored text to the terminal
- Understanding NumPy’s einsum
- For loop and ‘numpy.float64’ object is not iterable error
- What are the causes of overflow encountered in double_scalars besides division by zero?
- Creating a dictionary from a csv file?
- How can I check for NaN values?
- Viewing all defined variables
- Difference between two dates in Python
- ImportError: No module named win32com.client
- Error message “Linter pylint is not installed”
- AttributeError: ‘Tensor’ object has no attribute ‘_keras_history’
- pip install -r requirements.txt [Errno 2] No such file or directory: ‘requirements.txt’
- Zsh: Conda/Pip installs command not found
- Find the nth occurrence of substring in a string
- How to convert ‘binary string’ to normal string in Python3?
- If statement for strings in python?
- How to create a numpy array of all True or all False?
- What is the quickest way to HTTP GET in Python?
- Pandas index column title or name
- Removing nan values from an array
- Python – While-Loop until list is empty
- ImportError: No module named xgboost
- How to properly create a HeatMap with Bokeh
- How to detect key presses?
- NaN loss when training regression network
- Building multi-regression model throws error: `Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).`
- TypeError: ‘set’ object does not support indexing
- Python 3.6 No module named pip
- Replacing Pandas or Numpy Nan with a None to use with MysqlDB
- How do I merge lists in python? [duplicate]
- creating a reverse method for a python list from scratch
- What does on_delete do on Django models?
- Convert floats to ints in Pandas?
- Unable to import tweepy module
- pandas comparison raises TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]
- NameError: name ‘python’ is not defined
- TypeError: got multiple values for argument
- How can I recover the return value of a function passed to multiprocessing.Process?
- Python Remove last char from string and return it
- NameError: name ‘reduce’ is not defined in Python
- numpy : calculate the derivative of the softmax function
- Difference between exit(0) and exit(1) in Python
- IOError: [Errno 32] Broken pipe when piping: `prog.py | othercmd`
- Python ‘while’ with two conditions: “and” or “or”
- How to pass a list by reference?
- i want to run python script in wordpress