escaping

decode(unicode_escape) in python 3 a string

放肆的年华 提交于 2020-04-06 11:23:09
问题 I've checked this solution but it doesn't work in python3. I've an escaped string of this kind: str = "Hello\\nWorld" and I want to obtain the same string unescaped: str_out = Hello\nWorld I tried with this without succes: AttributeError: 'str' object has no attribute 'decode' Here my sample code: str = "Hello\\nWorld" str.decode('unicode_escape') 回答1: decode applies to bytes , which you can create by encoding from your string. I would encode (using default) then decode with unicode-escape >>

Please explain this unexpected \b (backspace) behavior

我的未来我决定 提交于 2020-03-22 09:47:11
问题 Expected: >>> print "I print\b\b Backspace\b\b!" I pri Backspa! >>> print "I print\b\b Backspace\b\b\b!" I pri Backsp! Observed: >>> print "I print\b\b Backspace\b\b!" I pri Backspa!e >>> print "I print\b\b Backspace\b\b\b!" I pri Backsp!ce Why does is 'e' and 'ce' not erased and '!' inserted? 回答1: The \b also termed as back space moves back the cursor by 1. The backspace doesn't delete anything, it moves the cursor to the left and it gets covered up by what you write afterwards. Let's

Please explain this unexpected \b (backspace) behavior

前提是你 提交于 2020-03-22 09:47:06
问题 Expected: >>> print "I print\b\b Backspace\b\b!" I pri Backspa! >>> print "I print\b\b Backspace\b\b\b!" I pri Backsp! Observed: >>> print "I print\b\b Backspace\b\b!" I pri Backspa!e >>> print "I print\b\b Backspace\b\b\b!" I pri Backsp!ce Why does is 'e' and 'ce' not erased and '!' inserted? 回答1: The \b also termed as back space moves back the cursor by 1. The backspace doesn't delete anything, it moves the cursor to the left and it gets covered up by what you write afterwards. Let's

Create a bat file with variables from another bat file

时光毁灭记忆、已成空白 提交于 2020-03-18 09:19:49
问题 I want to create a bat file with set variables from another bat file. This is for a startup .bat file that maps network drives and copies some files to the local computer and looks at the system services that needs to run. It also needs to create a log file every time the logon .bat file runs. Here is a sample what I have done. ECHO set SERVER IP=>>"V:\GENESIS\GENESIS INSTALL FILES\GenesisLogonUser.bat" ECHO set DRIVE1=V>>"V:\GENESIS\GENESIS INSTALL FILES\GenesisLogonUser.bat" ECHO set

Create a bat file with variables from another bat file

那年仲夏 提交于 2020-03-18 09:19:32
问题 I want to create a bat file with set variables from another bat file. This is for a startup .bat file that maps network drives and copies some files to the local computer and looks at the system services that needs to run. It also needs to create a log file every time the logon .bat file runs. Here is a sample what I have done. ECHO set SERVER IP=>>"V:\GENESIS\GENESIS INSTALL FILES\GenesisLogonUser.bat" ECHO set DRIVE1=V>>"V:\GENESIS\GENESIS INSTALL FILES\GenesisLogonUser.bat" ECHO set

Writing special characters from one batch file to another

人走茶凉 提交于 2020-03-16 08:34:12
问题 I am trying to write one batch file from another, using echo . However, there is one line with special characters that I cannot work out how to write. I have the following line: echo >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" >> "c:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\OrchestrationCleanUp.bat" But what gets written to the target file is: "C:\Windows\system32\cacls.exe" "C:\Windows\system32\config\system" It should be: >nul 2>&1 "

How can I insert a variable containing a backslash in sed?

不打扰是莪最后的温柔 提交于 2020-03-16 08:01:50
问题 Please see these simple commands: $ echo $tmp UY\U[_ $ echo "a" | sed "s|a|${tmp}|g" UY[_ The \U is eaten. Other backslashes won't survive either. How can I make the above command work as expected? 回答1: If it's only backslash that is "eaten" by sed and escaping just that is enough, then try: echo "a" | sed "s|a|${tmp//\\/\\\\}|g" Confusing enough for you? \\ represents a single \ since it needs to be escaped in the shell too. The inital // is similar to the g modifier in s/foo/bar/g , if you

How can I insert a variable containing a backslash in sed?

血红的双手。 提交于 2020-03-16 08:01:10
问题 Please see these simple commands: $ echo $tmp UY\U[_ $ echo "a" | sed "s|a|${tmp}|g" UY[_ The \U is eaten. Other backslashes won't survive either. How can I make the above command work as expected? 回答1: If it's only backslash that is "eaten" by sed and escaping just that is enough, then try: echo "a" | sed "s|a|${tmp//\\/\\\\}|g" Confusing enough for you? \\ represents a single \ since it needs to be escaped in the shell too. The inital // is similar to the g modifier in s/foo/bar/g , if you

How to grep asterisk without escaping?

爷,独闯天下 提交于 2020-02-13 10:25:36
问题 Suppose I have a file abc.txt which contains line ab*cd . When I grep that pattern ab*cd with quotes but without escaping the asterisk it does not work: > grep ab*c abc.txt > grep "ab*c" abc.txt > grep 'ab*c' abc.txt When I use both quotes and escaping it does work > grep "ab\*c" abc.txt ab*cd > grep 'ab\*c' abc.txt ab*cd Now I wonder why the quotes do not work and if I can use only quotes without escaping the asterisk. 回答1: Use the flag -F to search for fixed strings -- instead of regular

What are the matlab equivalent for '\n' '\t' and other escape characters? [duplicate]

巧了我就是萌 提交于 2020-02-08 04:12:46
问题 This question already has answers here : Escape characters in Matlab (2 answers) Closed 2 years ago . I am reading a file using fileread() which returns me the entire file. Now I need to read line by line and convert them into process the data. Can I know how I would be able to detect the newline character in Matlab? I tried '\n' and '\r\n' and it doesn't work. Thanks in advance 回答1: I already replied here (please avoid posting the question twice)Escape characters in Matlab For special