file = open('Failed.py', 'w')
file.write('whatever')
file.close()
Here is a more pythonic version, which automatically closes the file, even if there was an exception in the wrapped block:
with open('Failed.py', 'w') as file:
file.write('whatever')
More Related Contents:
- How to match a string to pattern “Foo-Bar”, where Bar can be any element of a list? [closed]
- Check if the element is last in the list
- What’s wrong with my Python 2 program?
- Behavior of exec function in Python 2 and Python 3
- Dead simple example of using Multiprocessing Queue, Pool and Locking
- Python: URLError:
- Python: count repeated elements in the list [duplicate]
- Removing unicode \u2026 like characters in a string in python2.7 [duplicate]
- Getting only element from a single-element list in Python?
- Unnamed Python objects have the same id
- Redirecting stdout to “nothing” in python
- How can PySpark be called in debug mode?
- Assigning string with boolean expression [duplicate]
- Why can I pass an instance method to multiprocessing.Process, but not a multiprocessing.Pool?
- How to get Windows short file name in python?
- How to plot a chart in the terminal
- What does the “yield” keyword do in Python?
- Read .doc file with python
- Making HTTP HEAD request with urllib2 from Python 2
- Get a unique list of items that occur more than once in a list
- Python: setting two variable values separated by a comma in python
- I want to multiply two columns in a pandas DataFrame and add the result into a new column
- What is different between makedirs and mkdir of os?
- Python returns length of 2 for single Unicode character string
- TypeError: unsupported operand type(s) for -: ‘list’ and ‘list’
- How to sort list of lists according to length of sublists [duplicate]
- Is there a reason Python 3 enumerates slower than Python 2?
- downloading error using nltk.download()
- Unknown error: Chrome failed to start: exited abnormally
- ImportError: DLL load failed: %1 is not a valid Win32 application for Python Matplotlib