line-breaks

How to make a line break on the Python ternary operator?

瘦欲@ 提交于 2019-11-30 04:28:24
Sometimes a line containing a ternary operator in Python gets too long: answer = 'Ten for that? You must be mad!' if does_not_haggle(brian) else "It's worth ten if it's worth a shekel." Is there a recommended way to make a line break at 79 characters with a ternary operator? I did not find it in PEP 8 . You can always extend a logical line across multiple physical lines with parentheses: answer = ( 'Ten for that? You must be mad!' if does_not_haggle(brian) else "It's worth ten if it's worth a shekel.") This is called implicit line joining . The above uses the PEP8 everything-indented-one-step

Normalizing line endings in Ruby

非 Y 不嫁゛ 提交于 2019-11-30 04:26:35
I have a string in Ruby, s (say) which might have any of the standard line endings ( \n , \r\n , \r ). I want to convert all of those to \n s. What's the best way? This seems like a super-common problem, but there's not much documentation about it. Obviously there are easy crude solutions, but is there anything built in to handle this? Elegant, idiomatic-Ruby solutions are best. EDIT: realized that ^M and \r are the same. But there are still three cases. (See wikipedia .) Best is just to handle the two cases that you want to change specifically and not try to get too clever: s.gsub /\r\n?/, "

What can I use to go one line break back in a terminal in Python?

徘徊边缘 提交于 2019-11-30 02:26:24
I can go one caracter back using \b : >>> print("123#456") 123#456 >>> print("123#\b456") 123456 But it doesn't work if a line break is involved : >>> print("123#\n456") 123# 456 >>> print("123#\n\b456") 123# 456 Is there a way to go line break back ? I'm asking this because I have a progress at the previous line: 53% And I use \b to update the value. But if somebody prints something, it breaks it. I tried to create a buffer of strings and print enought '\b' to compensate for it, then print the buffer back. But it doesn't work if there are line breaks. One possible (a bit hacky) solution is to

How to force line break in Symfony2 translation file

穿精又带淫゛_ 提交于 2019-11-30 02:03:54
问题 In my messages.en.yml I have an entry that is used for an email body which is in plaintext, so I cannot use any HTML tags. Now when I need a line break and I add a blank line after, the line break appears in my email body. But when I try to do a line break with a non empty line following, it does not break the lines. email: subject: My Subject message: > Hello %name%, This is my second line Best regards, John Smith Customer Care Arrives like this in my mailbox Hello Tom, This is my second

Specifying a preferred line break point in HTML text in a responsive design [duplicate]

∥☆過路亽.° 提交于 2019-11-29 21:12:38
This question already has an answer here: html (+css): denoting a preferred place for a line break 9 answers I was wondering if there is a CSS or javascript magic that could place a marker in an html text so that the browser know where the line break creation is preffered when the text gets cramped. Is there such thing? I think this works very well: span.line { display: inline-block; } <p> <span class="line">This text should break</span> <span class="line">after the word "break"</span> </p> The text still breaks on other places when there is not enough space: open demo n_ermosh Is the <wbr>

Neatest way to remove linebreaks in Perl

ⅰ亾dé卋堺 提交于 2019-11-29 20:44:58
I'm maintaining a script that can get its input from various sources, and works on it per line. Depending on the actual source used, linebreaks might be Unix-style, Windows-style or even, for some aggregated input, mixed(!). When reading from a file it goes something like this: @lines = <IN>; process(\@lines); ... sub process { @lines = shift; foreach my $line (@{$lines}) { chomp $line; #Handle line by line } } So, what I need to do is replace the chomp with something that removes either Unix-style or Windows-style linebreaks. I'm coming up with way too many ways of solving this, one of the

regex pattern that matches the string at the end of a string but is not followed by line break

不打扰是莪最后的温柔 提交于 2019-11-29 12:22:16
I use a regex pattern i preg_match php function. The pattern is let's say '/abc$/' . It matches both strings: 'abc' and 'abc ' The second one has the line break at its end. What would be the pattern that matches only this first string? 'abc' The reason why /abc$/ matches both "abc\n" and "abc" is that $ matches the location at the end of the string, or (even without /m modifier) the position before the newline that is at the end of the string. You need the following regex: /abc\z/ where \z is the unambiguous very end of the string, or /abc$/D where the /D modifier will make $ behave the same

Removing line break powershell

房东的猫 提交于 2019-11-29 10:10:09
I am having an issue with a line break in my data. The array was made with an out-string followed by -split. If you want to see that part of the script let me know. foreach ($item in $array) { "_"+$item+"_" } Output: _ itemname_ Desired Output: itemname I've tried inserting: $item.replace('`','') Without any change. Any ideas? Okay, I think this should work. I was under the impression you wanted those underscores in the result. $array -replace "`n|`r" By default, 'Get-Content' command has the default delimiter of a new line '\n'. Create a costume parameter and then do your replace command.

jQuery text() function loses line breaks in IE

荒凉一梦 提交于 2019-11-29 07:01:52
This is quite a talked about problem on the jQuery forums but I can't figure out a solution for my situation. I have an unordered list with some text elements in them... the user can create new list items via jQuery, which are saved to an SQL database. They can also edit existing list items. Also, because the text in each list item can get quite long, they have the option of 'hiding' each list item so it shows a truncated version of the string. This is handled by a custom jQuery plugin that truncates list items that are over a certain length... here's what each list item looks like once the

How to preserve newlines when showing a text file with jQuery

亡梦爱人 提交于 2019-11-29 06:24:43
I want to fetch the content of an text file and I have manage to do that. Everything is working except for one thing - detecting new lines. My solution to fetch the content in the text file: $.ajax({ url: '/nhagyavi/files/textfiles/changelog.txt', success: function(data) { $('#load-changelog').html('<div style="font-family: Courier New;">' + data + '</div>'); } }); The content of the text file: 2012-03-15: Snabbfixar - Detta är en fin liten rad som berättar vad som är nytt - En till rad, tillsammans med en <a href="javascript:void(0)">länk</a> How the result looks like on my page: 2012-03-15: