newline

How to write list of strings to file, adding newlines?

百般思念 提交于 2019-12-18 13:05:23
问题 def generator(): nums = ['09', '98', '87', '76', '65', '54', '43'] s_chars = ['*', '&', '^', '%', '$', '#', '@',] data = open("list.txt", "w") for c in s_chars: for n in nums: data.write(c + n) data.close() I would like to add a newline after every "c + n". 回答1: Change data.write(c + n) to data.write("%s%s\n" % (c, n)) 回答2: A properly-placed data.write('\n') will handle that. Just indent it appropriately for the loop you want to punctuate. 回答3: As other answers gave already pointed out, you

Git files modified after checkout, reset --hard, etc. even though autocrlf is set to false

眉间皱痕 提交于 2019-12-18 12:16:54
问题 Here is my system dialogue: unrollme-dev-dan:views Dan$ git reset --hard HEAD HEAD is now at 3f225e9 Fix scan titles unrollme-dev-dan:views Dan$ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: app/signup/finish.html # modified: app/signup/scan.html # I have autocrlf set to false: unrollme-dev-dan:unroll-website Dan$ git config

Print empty line?

末鹿安然 提交于 2019-12-18 11:48:15
问题 I am following a beginners tutorial on Python, there is a small exercise where I have to add an extra function call and print a line between verses, this works fine if I print an empty line in between function calls but if I add an empty print line to the end of my happyBirthday() I get an indent error, without the added print line all works fine though, any suggestions as to why? Here is the code: def happyBirthday(person): print("Happy Birthday to you!") print("Happy Birthday to you!")

ASP.NET MVC Html.Encode - New lines

試著忘記壹切 提交于 2019-12-18 11:44:35
问题 Html.Encode seems to simply call HttpUtility.HtmlEncode to replace a few html specific characters with their escape sequences. However this doesn't provide any consideration for how new lines and multiple spaces will be interpretted (markup whitespace). So I provide a text area for the a user to enter a plain text block of information, and then later display that data on another screen (using Html.Encode ), the new lines and spacing will not be preserved. I think there are 2 options, but

New Line in Textarea to be converted to <br/>

我怕爱的太早我们不能终老 提交于 2019-12-18 10:09:41
问题 There's a lot of threads here about converting br/> or preserving newlines across different languages, but not many regarding textarea. I have this script: var boxText = ""; $("textarea.BoxText").live('dblclick', function () { boxText = $(this).val().replace(/ /g, "<br/>"); $(this).replaceWith( '<div class="BoxText">' + $(this).val() + '</div>' ); }); $("div.BoxText").live('dblclick', function () { $(this).replaceWith( '<textarea form="HTML" class="BoxText">' + boxText + '</textarea>' ); });

Remove blank lines with grep

北慕城南 提交于 2019-12-18 09:55:25
问题 I tried grep -v '^$' in Linux and that didn't work. This file came from a Windows file system. 回答1: Try the following: grep -v -e '^$' foo.txt The -e option allows regex patterns for matching. The single quotes around ^$ makes it work for Cshell. Other shells will be happy with either single or double quotes. UPDATE: This works for me for a file with blank lines or "all white space" (such as windows lines with "\r\n" style line endings), whereas the above only removes files with blank lines

How to writefile in new line in WIN32 API

£可爱£侵袭症+ 提交于 2019-12-18 09:41:39
问题 I'm trying to write data to file. However, I want to add new data in new line, but now I can't. HANDLE hFile; hFile = CreateFile(_T("HELLO.txt"), // file to open GENERIC_WRITE, // open for writing 0, // share for writing NULL, // default security // CREATE_NEW, // existing file only OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, // normal file NULL); // no attr. template // Write to File BOOL bErrorFlag = FALSE; DWORD dwPtr = SetFilePointer( hFile, 0, NULL, FILE_END); //set pointer position to end file

Find value of current line of a <textarea> using javascript

吃可爱长大的小学妹 提交于 2019-12-18 09:16:18
问题 How can I find the value of the current line of a textarea? I know I have to find the caret position, but then find everything before it up to the last \n and everything after it to the next \n. How can I do this? 回答1: A simple way would be to just loop: var caretPos = 53, // however you get it start, end ; for (start = caretPos; start >= 0 && myString[start] != "\n"; --start); for (end = caretPos; end < myString.length && myString[end] != "\n"; ++end); var line = myString.substring(start + 1

Using csv module to read ascii delimited text?

戏子无情 提交于 2019-12-18 09:03:35
问题 You may or may not be aware of ASCII delimited text, which has the nice advantage of using non-keyboard characters for separating fields and lines. Writing this out is pretty easy: import csv with open('ascii_delim.adt', 'w') as f: writer = csv.writer(f, delimiter=chr(31), lineterminator=chr(30)) writer.writerow(('Sir Lancelot of Camelot', 'To seek the Holy Grail', 'blue')) writer.writerow(('Sir Galahad of Camelot', 'I seek the Grail', 'blue... no yellow!')) And, sure enough, you get things

How can I prevent Python from inserting a new line after taking user input?

跟風遠走 提交于 2019-12-18 08:49:32
问题 Python inserts a blank line in the console output between every call of the input() function but I don't want that (i.e. I want the input() prompts to be on contiguous lines in the console instead of separated by a blank line). Is there a way to do that? I tried using input("foo", end="") thinking it may work like the print() function but that's not the case... Code: fname = input("Please enter your first name: ") lname = input("Please enter your last name: ") print("Pleased to meet you, " +