On 14/03/17 14:26, padawanweb...@gmail.com wrote:
As an example, If I have the excel file open and there is data that needs to be 
written to the excel file than the exception will catch this error:

IOError: [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'

Ah yes, you did say that, sorry I missed it.

essentially, because the excel file is open during the process of writing to the excel 
file the "try" will keep attempting to write to the excel until its closed. So, 
if there were 5 attempts to write the data to the excel file, then after the excel file 
is closed that data will be written to the excel file n+1  times (6 times). When this 
happens it shows 6 rows of the newly written data, however, it's the same data. To 
illustrate this here is the output from the shell line while the excel file is open and 
when it's closed. Note, When I close it it will say Report Updated.

Ah, no. According to your code, successfully writing to the file is what causes "Report Updated" to be printed, not the closing of the file. It's important to be accurate about things like that, otherwise you spend hours looking for a connection in entirely the wrong place.


Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on 
win32
Type "copyright", "credits" or "license()" for more information.
================================ RESTART ================================

-1
Test = True

error [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'
-1
Test = True

error [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'
-1
Test = True

error [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'
-1
Test = True

error [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'
-1
Test = True

error [Errno 13] Permission denied: 
'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx'
-1
Test = True

Report Updated

This is what's written to the excel file:

3       NB19097 24.221.51.225   376_SouthYard   373_Reseda      03-14-2017      
07:03:46
4       NB19097 24.221.51.225   376_SouthYard   373_Reseda      03-14-2017      
07:04:07
5       NB19097 24.221.51.225   376_SouthYard   373_Reseda      03-14-2017      
07:04:27
6       NB19097 24.221.51.225   376_SouthYard   373_Reseda      03-14-2017      
07:04:47
7       NB19097 24.221.51.225   376_SouthYard   373_Reseda      03-14-2017      
07:05:07
8       NB19097 24.221.51.225   376_SouthYard   373_Reseda      03-14-2017      
07:05:28

As you can see from the shell line the number of attempts made, and from the 
excel file the number of rows taken, that there is a correlation between the 
attempts and what gets written to the excel file.

The interesting thing is that there is only one write. This suggests that the information is being appended to another file somewhere, or held in some other way that persists between invocations of assetMapping.py.

Now I'm not going to hunt through your code for the answer, because there's too much of it and frankly the overly long lines don't survive email well on my machine. However, you should look for the tidying up in your code that doesn't get done because the attempted write throws an exception.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to