escape

How to detect ESCape keypress in Python?

匿名 (未验证) 提交于 2019-12-03 01:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am running a process in a command window (Windows 7, Python 3.1) where I would like the user to abort the process by pressing the ESCape key. However, pressing the ESCape key doesn't appear to do anything :-(, the loop never breaks. I have also tried running the script from within my IDE (Wing), but again, the loop cannot be interrupted. The following is a stripped-down version of my proof-of-concept test... import msvcrt import time aborted = False for time_remaining in range(10,0,-1): # First of all, check if ESCape was pressed if msvcrt

How to use the ANSI Escape code for outputting colored text on Console

匿名 (未验证) 提交于 2019-12-03 01:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I read about ANSI-C escape codes here . Tried to use it in C/C++ printf/cout to colorize the text outputted to consolde but without sucess. Code: #include #include int main () { int a = 3 , b = 5 ; int & ref = a ; ref = b ; //cout How to use these escape codes to output colored text to console? Am i missing something? EDIT: In some C++ code I saw a call to this function textcolor ( 10 ); But it gives compilation errors in g++ and in Visual Studio. Which compiler had this function available? Any details? 回答1: I'm afraid you forgot

What special characters must be escaped in regular expressions?

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am tired of always trying to guess, if I should escape special characters like ' ()[]{}| ' etc. when using many implementations of regexps. It is different with, for example, Python, sed, grep, awk, Perl, rename, Apache, find and so on. Is there any rule set which tells when I should, and when I should not, escape special characters? Does it depend on the regexp type, like PCRE, POSIX or extended regexps? 回答1: Which characters you must and which you mustn't escape indeed depends on the regex flavor you're working with. For PCRE, and most

How to escape back slash in SQL server

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: DECLARE @Query nvarchar(max) SET @Query ='DECLARE @Test nvarchar(max) SELECT @Test = ''\a'\b'\c'' SELECT @Test PRINT @Query exec sp_executesql @Query I am trying to get an output as \a\b\c. The above error is probably because I am not able to escape the \ character. 回答1: You do not need to escape the backslashes (only the inner single quotes): DECLARE @Query nvarchar(max) SET @Query ='DECLARE @Test nvarchar(max) SELECT @Test = ''\a\b\c'' SELECT @Test' PRINT @Query exec sp_executesql @Query 回答2: There is in fact one place where back slashes

Escape html in python?

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i have a but string might contain ", what should I do to escape it? Example: __string__ = test".jpg doesn't work. 回答1: If your value being escaped might contain quotes, the best thing is to use the quoteattr method: http://docs.python.org/library/xml.sax.utils.html#module-xml.sax.saxutils This is referenced right beneath the docs on the cgi.escape() method. 回答2: In Python 3.2 a new html module was introduced, which is used for escaping reserved characters from HTML markup. It has one function html.escape(s, quote=True) . If the optional flag

Python MySQL escape special characters

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am using python to insert a string into MySQL with special characters. The string to insert looks like so: macaddress_eth0 ; 00 : 1E : 68 : C6 : 09 : A0 ; macaddress_eth1 ; 00 : 1E : 68 : C6 : 09 : A1 Here is the SQL: UPGRADE inventory_server set server_mac = macaddress\_eth0\; 00 \: 1E \: 68 \:C6\: 09 \:A0\;macaddress\_eth1\; 00 \: 1E \: 68 \:C6\: 09 \:A1 ' where server_name = ' myhost . fqdn . com When I execute the update, I get this error: ERROR 1064 ( 42000 ): You have an error in your SQL syntax ; check the manual that

Escape string Python for MySQL

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I use Python and MySQLdb to download web pages and store them into database. The problem I have is that I can't save complicated strings in the database because they are not properly escaped. Is there a function in Python that I can use to escape a string for MySQL? I tried with ''' (triple simple quotes) and """ , but it didn't work. I know that PHP has mysql_escape_string() , is something similar in Python? Thanks. 回答1: conn.escape_string() See MySQL C API function mapping: http://mysql-python.sourceforge.net/MySQLdb.html 回答2: The MySQLdb

Java escape JSON String?

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following JSON string that i am sending to a NodeJS server: String string = "{\"id\":\"" + userID + "\",\"type\":\"" + methoden + "\",\"msg\":\"" + msget + "\", \"name\":\"" + namnet + "\", \"channel\":\"" + activeChatChannel + "\", \"visitorNick\":\"\", \"agentID\":\" " + agentID + "\"}"; PrintWriter pw = new PrintWriter(new OutputStreamWriter(os, "utf-8")); pw.println(string); The problem becomes when the string msget contains the character " and ' On the NodeJS server i am parsing the JSON like this: var obj = JSON.parse

Invalid escape sequence (valid ones are \\b \\t \\n \\f \\r \\\" \\' \\\\ )

匿名 (未验证) 提交于 2019-12-03 01:46:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to read a file into my Java program using java.util.Scanner and I get the above message when I enter the code below (I am new to java) - can anyone help? (I looked at a similar message someone got with their own code, but it was too complex for me to use in my example!). I have Windows 7. BufferedReader job = new BufferedReader ( new FileReader ( "\My Documents\JOBS\newfile.txt" )); 回答1: You need to escape the "\" in the file path. BufferedReader job = new BufferedReader ( new FileReader ( "\\My Documents\\JOBS\\newfile

Can I escape html tags within a class (recreate the xmp tag)?

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: A couple ways to think of this question. Decide for yourself which is most useful for you… Can javascript recreate the deprecated <xmp> tag with an "xmp" class? Can we mimic SO's markdown processor's escaping tags within inline code? (metaSO, I admit) How does SO's md processor escape tags in inline code? Can we escape < in markdown code blocks embedded in HTML? The goal: a class that escapes < , allowing that class to contain the text <html>, <body>, <head>, <script>, <style>, <body>, and any other tags that don't belong inside <body> or