0

I tried to read up on how to open files properly in python (concerning formatting of special characters, in this case carriage return) but still can't figure it out.

I'm writing this script in nano on my rpi (over ssh from my pc using putty). The script collects data from sensors connected via I2C and SPI and prints them to logfiles. Any events, anomalies and errors are to be registered in an eventlog, with timestamp. that way, I dont need the ordinary print function and can make the program run in the backround and keep track of what it's doing by looking at the eventlog over FTP.

The following parts of the program gives different line handling

first occasion

second occasion

The first gives a file that gets a ^M at the beginning of each line except the first when i view it in nano, but it looks fine and dandy when i open it in notebook on my PC.

The second looks good in nano, but have no newlines or carriage returns when I open it in notepad and is impossible to read properly.

First: Why are they different? I have looked at it over and over again. Because one is inside a function and the other "raw" in the code (it is inside a while loop)

Second: What does it take to get the files to look proper in both nano and notepad?

Hopefully I've given enough details :)

  • [**Why not upload images of code on SO when asking a question?**](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question) – martineau Dec 04 '17 at 22:34
  • If there is something wrong with the images i uploaded, it would be good to know more specifically what is wrong. – Anders Wadman Dec 05 '17 at 11:50
  • Do not upload images, paste source code instead. Also, use the [`logging`](https://docs.python.org/2/library/logging.html) module and its [`FileHandler`](https://docs.python.org/2/library/logging.handlers.html#filehandler) for logging into files. Lastly, do not use Notepad or any editor/viewer not capable of detecting cross-platform EOL for pretty much anything, let alone viewing logs. – zwer Dec 05 '17 at 13:04
  • Anders: I can only assume you didn't read the answers to the question to which I provided the link. – martineau Dec 05 '17 at 14:03

0 Answers0