"'NoneType' object has no attribute 'action'" error when looping over objects with Python
Add keyframes to all objects.  Keyframes are associated with actions.  Simplified explanation.  

You have stated you 4 days of experience with Python, if I understand you correctly.  Thus my answer is based on working with that context.  Keyframes may be more familiar to you than Python. You may prefer to know more about Python slowly.  The choice is yours.

Remember you can pose related [idea questions] here at BSE with a single web page but try to limit it to a reasonable small task.

On the other hand some people actually get lucky and get people to write the entire script for them.

The following search here at Blender Stack Exchange with keywords

animation_data is not none

can you show you different approaches to handling the problem situation via Python.

I do have concern about the Python in the question with regard to file writing.  But you may consider asking that as a separate question.  One file name is used for writing in the Python at this point.  The file seems to be rewritten every time with only the last write being actually being persistent. That seems defective. I imagine you want to have data for all objects in the same file.

I suggest when the file writing is top priority, you pose another question.  The changes needed seem achievable in 88 seconds.  You should consider how many times you open the file.  I believe it should be one file open per invocation.  You know how to use for loops so if you think about it you will find the better placement of existing Python.

The file mode is 'w' which can mean ... delete and create fresh. 
I would suggest you change it to 'a' for append. Once the code is more correct you may decide to use 'w' with a different filename everytime. The filename can include the time and date.  blender_data_D20180318_T120037.txt as as example you can improve. D for Date. T for time including seconds. Thus you would have a history to compare file versions.

You can delete parts of the file or the whole file for testing. I have not executed the Python so this is just a computer simulation mental simulation.  Currently the Python seems to write info for the last object only which seems defective.