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?
- numpy max vs amax vs maximum
- What does “while True” mean in Python?
- TypeError: ‘str’ object is not callable (Python)
- Converting string into datetime
- ValueError: invalid literal for int() with base 10: ”
- How do I list all files of a directory?
- Print string to text file
- How can I implement a tree in Python?
- write() versus writelines() and concatenated strings
- Why is it string.join(list) instead of list.join(string)?
- Importing class from another file [duplicate]
- Pandas group-by and sum
- Is it possible to compile a program written in Python?
- Python List vs. Array – when to use?
- How can I flush the output of the print function?
- Python calling method in class
- No module named pkg_resources
- Opening a .ipynb.txt File
- How do I remove all packages installed by PIP?
- Replace and overwrite instead of appending
- module ‘pandas’ has no attribute ‘rolling_mean’
- What is the grep equivalent in Python?
- pip install mysql-python fails with EnvironmentError: mysql_config not found
- Type error Unhashable type:set
- Saving a Numpy array as an image
- TypeError: ‘bool’ object is not callable
- ValueError: zero length field name in format in Python2.6.6
- Python NameError, variable ‘not defined’
- Cannot import cv2 in python in OSX
- numpy-equivalent of list.pop?
- How to get row number in dataframe in Pandas?
- Difference between Python’s Generators and Iterators
- “Unorderable types: int() < str()"
- Disable / Enable Button in TKinter
- How do I find the time difference between two datetime objects in python?
- How to strip a specific word from a string?
- Installing MySQL-python causes command ‘clang’ failed with exit status 1 on Mac OS 10.13.15
- Get difference between two lists
- how to build .exe for python 3.5+, 3.6 if possible?
- How to query as GROUP BY in django?
- Paste Special error 1004 PasteSpecial method of Range class failed
- How do I restart a program based on user input?
- Python Pandas : pivot table with aggfunc = count unique distinct