The negation operator in Python is not
. Therefore just replace your !
with not
.
For your example, do this:
if not os.path.exists("/usr/share/sounds/blues") : proc = subprocess.Popen(["mkdir", "/usr/share/sounds/blues"]) proc.wait()
For your specific example (as Neil said in the comments), you don’t have to use the subprocess
module, you can simply use os.mkdir()
to get the result you need, with added exception handling goodness.
Example:
blues_sounds_path = "/usr/share/sounds/blues" if not os.path.exists(blues_sounds_path): try: os.mkdir(blues_sounds_path) except OSError: # Handle the case where the directory could not be created.
Related Posts:
- Multiplication function with recursion in Python
- How can I reverse a list in Python?
- Searching the student-t distribution table for values using python
- How to declare an array in Python?
- Praw & Discord.py: The bot keep sending the same meme. I want the bot to send different meme whenever it is asked
- What does ** (double star/asterisk) and * (star/asterisk) do for parameters?
- How to reset index in a pandas dataframe? [duplicate]
- Python: Find in list
- pandas read_json: “If using all scalar values, you must pass an index”
- Web scraping redoc web api
- Why am I getting “IndentationError: expected an indented block”? [duplicate]
- TypeError: cannot perform reduce with flexible type
- syntaxerror: “unexpected character after line continuation character in python” math
- ValueError : I/O operation on closed file
- How to set environment variables in Python?
- I keep getting this error for my simple python program: “TypeError: ‘float’ object cannot be interpreted as an integer”
- Numpy std calculation: TypeError: cannot perform reduce with flexible type
- Regex: AttributeError: ‘NoneType’ object has no attribute ‘groups’
- Internal Redirect in Flask
- ValueError: shape mismatch: objects cannot be broadcast to a single shape
- ImportError: No module named ‘Tkinter’
- ImportError: numpy.core.multiarray failed to import
- How to make a class property?
- Matplotlib automatic legend outside plot
- Syntax behind sorted(key=lambda: …)
- convert nan value to zero
- How to install pip3 on Windows?
- Is there a NumPy function to return the first index of something in an array?
- Tkinter scrollbar for frame
- Python Setup Disabling Path Length Limit Pros and Cons?
- How to add a string in a certain position?
- This can be done without regex:
- matplotlib error – no module named tkinter
- Python Error io.UnsupportedOperation: not readable
- Create own colormap using matplotlib and plot color scale
- The difference between ‘+=’ and ‘=+’?
- How to fix “Attempted relative import in non-package” even with __init__.py
- Sorting a set of values
- Git Bash won’t run my python files?
- Can only use .dt accessor with datetimelike values
- Convert XML to CSV file
- Checking whether pip is installed?
- How to install xgboost in Anaconda Python (Windows platform)?
- 3-dimensional array in numpy
- AttributeError: Module Pip has no attribute ‘main’
- Best way to replace multiple characters in a string?
- from PIL import Image – ImportError: No module named PIL
- Decoding UTF-8 strings in Python
- Pandas join issue: columns overlap but no suffix specified
- How to downgrade python from 3.7 to 3.6
- How to turn on line numbers in IDLE?
- OpenCV NoneType object has no attribute shape
- How to use an image for the background in tkinter?
- Python locale error: unsupported locale setting
- sklearn Logistic Regression “ValueError: Found array with dim 3. Estimator expected <= 2."
- Sqlite3, OperationalError: unable to open database file
- What does ‘index 0 is out of bounds for axis 0 with size 0’ mean?
- How to return dictionary keys as a list in Python?
- Python Error – int object has no attribute
- How to save a dictionary to a file?
- How to get JSON from webpage into Python script
- Moving average or running mean
- ImportError: libGL.so.1: cannot open shared object file: No such file or directory
- Python List object attribute ‘append’ is read-only
- Infinite for loops possible in Python?
- RuntimeError: module compiled against API version a but this version of numpy is 9
- Python3 Error: TypeError: Can’t convert ‘bytes’ object to str implicitly
- How to run Pip commands from CMD
- Sorting and Grouping Nested Lists in Python
- Python Subprocess: Too Many Open Files
- urllib2.HTTPError: HTTP Error 403: Forbidden
- .write not working in Python
- Coalesce values from 2 columns into a single column in a pandas dataframe
- Unknown format code ‘f’ for object of type ‘str’- Folium
- Pyinstaller setting icons don’t change
- No module named ‘tqdm’
- Compute a confidence interval from sample data
- Can’t get Python to import from a different folder
- How to crop an image in OpenCV using Python
- convert csv file to list of dictionaries
- What’s the difference between “virtualenv” and “-m venv” in creating Virtual environments(Python)
- OperationalError: database is locked
- Decode Hex String in Python 3
- Python ImportError: No module named wx
- Accessing a class’ member variables in Python?
- Declaring a multi dimensional dictionary in python
- Usage of sys.stdout.flush() method
- set object is not JSON serializable
- How to convert an integer to a string in any base?
- Count Vowels in String Python
- install csv package in pycharm
- How to print the full NumPy array, without truncation?
- dump() missing 1 required positional argument: ‘fp’ in python json
- TypeError: module.__init__() takes at most 2 arguments (3 given)
- coercing to Unicode: need string or buffer, NoneType found when rendering in django admin
- Python-3.2 coroutine: AttributeError: ‘generator’ object has no attribute ‘next’
- OCaml mod function returns different result compared with %
- What does the “w” mean in open(filename, “w”)?
- Test Average and Grade – Python
- Cannot remove entries from nonexistent file