lmorgh
Posts: 3
Joined: Sun Jan 10, 2016 10:58 am

Change of encoding while writing to file

Thu Aug 10, 2017 7:00 am

Dear all!

I am reading data from Sense Hat accelerometer and writing it to file.
Can someone explain why, at some point encoding of the written file changes?

First 10 lines of the output file are ok:
2017-08-09 15:41:35.299113,0.0592413879931,0.00484891841188,1.13197183609
2017-08-09 15:41:35.322011,0.058755800128,-0.0619557499886,0.975518465042
2017-08-09 15:41:35.344613,0.0611837282777,-0.0130822891369,0.977468073368
2017-08-09 15:41:35.367283,0.0592413879931,-0.0113544398919,0.972837805748
2017-08-09 15:41:35.389731,0.0609409362078,-0.0118481107056,0.972350418568
2017-08-09 15:41:35.412242,0.0604553483427,-0.0128354532644,0.973325252533
2017-08-09 15:41:35.435372,0.0606981404126,-0.0140696316957,0.971375644207
2017-08-09 15:41:35.458535,0.0609409362078,-0.0123417824507,0.970400869846
2017-08-09 15:41:35.481643,0.0606981404126,-0.0120949465781,0.970157146454
2017-08-09 15:41:35.504780,0.0597269758582,-0.0140696316957,0.971619307995

then after few hours I get this:

/�*}��������l�����!��
��4u��ҁ���ńQ�ý�����ӀY}Ł{������Yx�*��������n�!N�,zо��-�6#����;�����B����꼄~҃����F���ЇڿoyN*�����5�{u�3����

�v��g����o�N�c���A�#�a�����ˁ�H���o�����^�ǃ�*�����wτ
���ڿJ�*����� ���&���P��5$�Q�o�o����������4�ٿP�l*�����ؽp�����Ի��p�K{A���� �u�� *�������Ç���"���B�΂n���*����������y�F�g�<��1~��ɂؾ��]����y����=�ۀ�z������h���������E�Ո.�7~���}m��$���������{�6���������z��{�q*����
�U��u������Ku���k�t��h}{��}��� }�Tv��ya�K
J��̾��u��|*�����~1����I��Xzw��G�9�N�:��`|���"�[����7�#�<�� \��w��[�@*����TzӼ:�ւ��b�g�C�ڄ���sv�y������Q�e�����PzF�Ռ��,{8�����;*������X�����t���B
�VzĀ��i������O�ޅ||��΋L�kw�r�@���H��+*����f[���Y��}m�U��������i���������������:���c�T�ā���*�����ӿ|܀�⅌y����=�����RɁu���&�[����vk�������L��]����h|���}Ҁ��6��-��g���)��'�������{ȸC�Ń*yR*���� ځ��ހ7 �sP������׾
�f��'��:�
�J}��M������;���0*����a�A��0��+���������̅|�/���J���� ��G�򀩂꿕���D���`*�������ψ�w}n�]�/��j�$���̀+��sN��

�$��|;�c�d��2�G�Q���*������i�ڽ����܀��1�À;D���ڃ���Su���
w�{�ҁ��?�ͽx*����/������m�`�Ux�� �Px��ς�x𽏊��5|��C~|�y����{�^�j��*����{�������~��?���G�^�$�y�`�`���9�{�P��E}I��i��u߆�y�=9��������/�����/
��;��������D�r�ļ�>��|�Ƃ����ׅ����Ê�U*����$uk��~Ȁ�~��3��C�
��r���|��|��[޾����U��z�*����� �0�?������
����އ�y��_���d�����>�4���`�K�������G}R�=����ڿ�~�6e*����J��$|o� ��������{
��˻������f}������u�x�ֻ�� �r}W*����B�ZҦÅ�����7���
�Y�s���F��D��������ʽj��x�����hK���*�������ف���{o������Z�޺�
m����@�E���K~������sf�H���*����1��ui��
O�Ay'�������w�������P�'�m$��������>!���@�v�,193080D POST SLZRF��
�T� @0�8

�dc#?�����r��J�!�,�����C�J�B�I�ف�'y���r���f�����"xL�z+�~�z*��������rw������{؂��j��n���V���j��{캋� �Vz7���������v�`*������W�)z7�q�[�փ��N�2��t�����9���~��L}��ἣ��� ~Z��}��p��*����b�3���VyՁ(���;k���-�A�e�"һ��|���9˿v���t���R�߼q�C*��������{ ��1�i�"���=�0� ��{��>؀u�ƀ��Nŀ��!��{;�;���D*���������X�9��
�̓�a|�p���l�6t€�H�I1*�����x4�`���Yv������{�����8|��e���M�_�Y�Wz1�5����{��z�[�({��������^�){��
����x����g��\~1�߁��焹�>�=��Ͼ�zy��-�&��*����8r���B������yЀ�����{ԁπ�w��:�2�������d����V��{*����[� |��̀؁�|�J�{�`��~���~���������!�2�>
l���+�����Bx*����*�2�
�3�ց���

I am writting the data with python3 with
data.write(str(x)+","+str(y)+"\n")

Thanks!

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1665
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Change of encoding while writing to file

Thu Aug 10, 2017 8:27 am

Can you post the full code of your program, or a link to it please?

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Change of encoding while writing to file

Thu Aug 10, 2017 1:43 pm

Is your SDCard a fake?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Astro Pi”