I assume that you’re writing to the file, then close it (so the user can open it in Excel), and then, before re-opening it for append/write operations, you want to check that the file isn’t still open in Excel?
This is how you could do that:
while True: # repeat until the try statement succeeds try: myfile = open("myfile.csv", "r+") # or "a+", whatever you need break # exit the loop except IOError: input("Could not open file! Please close Excel. Press Enter to retry.") # restart the loop with myfile: do_stuff()
Related Posts:
- MS Excel Scatterplot converts Months to Numbers
- IndexError: too many indices for array
- IndexError: too many indices for array
- Excel to Google Sheets – Error: Formula parse error
- IndexError: too many indices for array
- Swap x and y axis without manually swapping values
- Excel: Calculate the frequency of a particular month in a column of date cells
- Object Required Error in excel VBA
- Insert picture into Excel cell
- What is a correct MIME type for .docx, .pptx, etc.?
- Is there Infinity in Spreadsheets?
- Declaring variables in Excel Cells
- What are .NumberFormat Options In Excel VBA?
- Better way to find last used row
- VBA, if a string contains a certain letter
- How to loop in excel without VBA or macros?
- How can I open an Excel file in Python?
- ValueError: cannot index with vector containing NA / NaN values
- Excel VBA Macro: User Defined Type Not Defined
- What is correct content-type for excel files?
- How do I get countifs to select all non-blank cells in Excel?
- VBA Runtime Error 1004 “Application-defined or Object-defined error” when Selecting Range
- Excel – SUMIFS for multiple columns
- Workaround for “Formula omits adjacent cells”
- Select method of Range class failed via VBA
- Does VBA contain a comment block syntax?
- ImportError: No module named win32com.client
- Why does “Paste Method of Worksheet class failed” occasionally occur?
- How to return a result from a VBA function
- Select all the cells below current cell in excel
- How to clear memory to prevent “out of memory error” in excel vba?
- Use VBA to Clear Immediate Window?
- Excel: Can I create a Conditional Formula based on the Color of a Cell?
- VBA: Else without If Error
- Recommended IDE for VBA
- ByRef argument type mismatch in Excel VBA
- How do I open space-delimited file in Microsoft Excel?
- VBA: Convert Text to Number
- VBA Error: “Compile error: Expected End Sub”
- Python: Pandas pd.read_excel giving ImportError: Install xlrd >= 0.9.0 for Excel support
- Using SUBSTITUTE with wildcard characters
- Change default ‘delimiters’ in excel
- Error: “Could Not Find Installable ISAM”
- Adding a newline character within a cell (CSV)
- VB: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)
- Loop without Do error
- Row count where data exists
- (Excel) Conditional Formatting based on Adjacent Cell Value
- Test or check if sheet exists
- How to detect if user select cancel InputBox VBA Excel
- Shortcut to Apply a Formula to an Entire Column in Excel
- macro run-time error ‘9’: subscript out of range
- How to label scatterplot points by name?
- Why does my VBA code throw an “Invalid outside procedure” error?
- Excel Solver Password: what is it and where can it be acquired/bought?
- Compile error: Next without For || VBA
- Is there a way to crack the password on an Excel VBA Project?
- SyntaxError: unexpected EOF while parsing
- How do I lowercase a string in Python?
- How do I copy a file in Python?
- How can I reverse a list in Python?
- Manually raising (throwing) an exception in Python
- How do I copy a file in Python?
- can’t multiply sequence by non-int of type ‘float’
- Difference between del, remove, and pop on lists
- How can I reverse a list in Python?
- How to use the pass statement
- How to use filter, map, and reduce in Python 3
- What does enumerate() mean?
- Searching the student-t distribution table for values using python
- How to declare an array in Python?
- Does Python have a ternary conditional operator?
- Use Gif Logo For Loading Screen In Kivy
- Praw & Discord.py: The bot keep sending the same meme. I want the bot to send different meme whenever it is asked
- Pig Latin Translator
- What is the difference between Python’s list methods append and extend?
- How can I make a time delay in Python? [duplicate]
- Python – TypeError: ‘int’ object is not iterable
- TypeError: ‘int’ object is not subscriptable
- sphinx.ext.autodoc: Keeping names of constants in signature
- are there dictionaries in javascript like python?
- How do you round UP a number?
- Understanding slice notation
- Iterating over dictionaries using ‘for’ loops
- How to define a two-dimensional array?
- how to sort pandas dataframe from one column
- Why am I seeing “TypeError: string indices must be integers”?
- Understanding the main method of python [duplicate]
- How do you round UP a number?
- Understanding slice notation
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How do I update\upgrade pip itself from inside my virtual environment?
- How to open a file using the open with statement
- How to emulate a do-while loop?
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How do I update\upgrade pip itself from inside my virtual environment?
- How to comment out a block of code in Python [duplicate]
- Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat)
- Using “with open() as file” method, how to write more than once? [duplicate]
- TypeError: list indices must be integers or slices, not str