git-diff to ignore ^M

GitHub suggests that you should make sure to only use \n as a newline character in git-handled repos. There’s an option to auto-convert: $ git config –global core.autocrlf true Of course, this is said to convert crlf to lf, while you want to convert cr to lf. I hope this still works … And then … Read more

What’s the strategy for handling CRLF (carriage return, line feed) with Git?

Almost four years after asking this question, I have finally found an answer that completely satisfies me! See the details in github:help‘s guide to Dealing with line endings. Git allows you to set the line ending properties for a repo directly using the text attribute in the .gitattributes file. This file is committed into the … Read more

Difference between \n and \r?

In terms of ascii code, it’s 3 — since they’re 10 and 13 respectively;-). But seriously, there are many: in Unix and all Unix-like systems, \n is the code for end-of-line, \r means nothing special as a consequence, in C and most languages that somehow copy it (even remotely), \n is the standard escape sequence … Read more

Writing a list to a file with Python, with newlines

Use a loop: with open(‘your_file.txt’, ‘w’) as f: for line in lines: f.write(f”{line}\n”) For Python <3.6: with open(‘your_file.txt’, ‘w’) as f: for line in lines: f.write(“%s\n” % line) For Python 2, one may also use: with open(‘your_file.txt’, ‘w’) as f: for line in lines: print >> f, line If you’re keen on a single function … Read more

Git replacing LF with CRLF

These messages are due to an incorrect default value of core.autocrlf on Windows. The concept of autocrlf is to handle line endings conversions transparently. And it does! Bad news: the value needs to be configured manually. Good news: it should only be done one time per Git installation (per project setting is also possible). How … Read more

Why should text files end with a newline?

Because that’s how the POSIX standard defines a line: 3.206 Line A sequence of zero or more non- <newline> characters plus a terminating <newline> character. Therefore, lines not ending in a newline character aren’t considered actual lines. That’s why some programs have problems processing the last line of a file if it isn’t newline terminated. … Read more

How do I remove a trailing newline?

Try the method rstrip() (see doc Python 2 and Python 3) >>> ‘test string\n’.rstrip() ‘test string’ Python’s rstrip() method strips all kinds of trailing whitespace by default, not just one newline as Perl does with chomp. >>> ‘test string \n \r\n\n\r \n\n’.rstrip() ‘test string’ To strip only newlines: >>> ‘test string \n \r\n\n\r \n\n’.rstrip(‘\n’) ‘test … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)