我正在尝试从数组中向我的数据库插入记录:
for string in self.FinalMailsArray:
c.execute("""INSERT INTO table (email) VALUES(%s) """,(string))
Run Code Online (Sandbox Code Playgroud)
问题是,我希望字段电子邮件是唯一的,所以我在数据库中启用了它.当我开始插入时,我得到重复输入值的错误.
有没有办法我可以说,"如果抛出重复的错误,只需转到数组中的下一个字符串"?
我已经用Java编写了一个IRC机器人,但是我遇到了以下问题:我有一个帮助函数,该函数会以私人消息的形式将机器人的所有功能(用法,例如...)返回给用户。
问题是,如果我逐行发送此消息,则消息会排队,并且最多可能需要10秒才能发送一个帮助请求。
现在,我通过将所有帮助功能放在一条消息中解决了这个问题,但是所有内容当然都放在一行上。这对可读性不利。
有没有一种使用irc协议格式化消息的方法,尤其是换行符吗?(来自Java的/ n不起作用)
如果没有这样的选择,最好的方法是使其更具可读性?
我做了一个简单的烧瓶应用:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.1
host:google.be
HTTP/1.0 404 NOT FOUND
Content-Type: text/html
Content-Length: 233
Server: Werkzeug/0.9.6 Python/2.7.6
Date: Mon, 08 Dec 2014 19:15:43 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
Connection closed by foreign host.
Run Code Online (Sandbox Code Playgroud)
我希望改变的一件事是服务器标题,此刻被设置为Werkzeug/0.9.6 Python/2.7.6我自己的选择.但我似乎无法在文档中找到有关如何执行此操作的任何内容.
我试图删除除字符串空格以外的所有非字母数字字符,但似乎无法弄清楚我是如何排除空格的.我现在这样做:
re.sub('[\W_]+', '', text).lower().strip()
Run Code Online (Sandbox Code Playgroud)
但运行我的函数会产生以下结果:
print removePunctuation('Hi, you!')
print removePunctuation(' No under_score!')
hiyou
nounderscore
Run Code Online (Sandbox Code Playgroud)
我希望它在哪里:
hi you
no underscore
Run Code Online (Sandbox Code Playgroud)
那么如何排除空间被替换?
我目前的最佳选择是:
re.sub('[^\s\w]+', '', text).lower().strip().replace('_','')
Run Code Online (Sandbox Code Playgroud) 嗨,我想知道是否有一种简单的方法来逃避PHP中的字符串.
在python中我使用"""""",并且之间的所有内容都被转义.所以当使用特殊字符时,它会被忽略.
我有一些文字要回声,手动逃避一切只需要永远.
php内置了类似的功能吗?
谢谢!
我想弄清楚如何防止sqlinjection,我写了这个基本功能:function
antiInjectie($inputfromform){
$temp = str_replace("'", "`",$inputfromform);
$temp = str_replace("--", "~~",$temp);
return htmlentitites($temp);
}
Run Code Online (Sandbox Code Playgroud)
然而有人告诉我也要考虑十六进制值,但我该怎么做?
更新 我坚持使用MDB2和pgsql
我有使用perl编写脚本的经验,这使我可以通过使用反向标记来轻松执行linux命令.我想知道,我该怎么做这个Python?是否有一种特殊的方法来捕获命令(输出)的结果?
谢谢 :)
我写了这个脚本来tar一些备份:
date = str(now.year)+str(now.month)+str(now.day)
tar="tar -pczf "+date+"backup_lucas.tar.gz /home/lucas/backup/"
subprocess.Popen(tar)
Run Code Online (Sandbox Code Playgroud)
但后来我得到:
File "test.py", line 21, in <module>
subprocess.Popen(tar)
File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1141, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Run Code Online (Sandbox Code Playgroud)
当我向Popen命令添加add shell = True时,它可以工作:
subprocess.Popen(tar,shell=True)
Run Code Online (Sandbox Code Playgroud)
但是我听说shell = True应该避免,因为它有时是不安全的(?).
如何在不使用shell = True的情况下成功发出命令?
如何将自定义参数添加到flask_wtf表单字段中的字段。我的要求之一是向autocomplete="off"所有密码字段添加 ,但是我似乎无法找出如何将该参数添加到flast_wtf生成形式的密码字段中。
我在 Powershell 中有一个函数,它用字典填充列表。
Function Process-XML-Audit-File-To-Controls-List($nodelist){
#Keep an array list to track the different controls
$control_list = New-Object System.Collections.ArrayList
foreach($var in $nodelist)
{
$lines = [string]($var.InnerText) -split '[\r\n]'
$control_dict = @{}
foreach($line in $lines){
$line_split = $line.Trim() -split ':',2
if($line_split.Length -eq 2){
$control_dict.Add($line_split[0],$line_split[1])
}
}
$control_list.Add($control_dict)
}
return $control_list
}
Run Code Online (Sandbox Code Playgroud)
它不是接收只返回 Hashtables 的 ArrayList,而是返回一个包含 Int32 和 Hashtable 的列表,其中每个哈希表元素都有一个 Int32:
True True Int32 System.ValueType
True True Int32 System.ValueType
True True Int32 System.ValueType
True True Hashtable System.Object
True True Hashtable System.Object
True True …Run Code Online (Sandbox Code Playgroud) python ×6
flask ×2
php ×2
arraylist ×1
autocomplete ×1
bots ×1
escaping ×1
irc ×1
java ×1
mdb2 ×1
mysql ×1
mysql-python ×1
popen ×1
postgresql ×1
powershell ×1
sys ×1
tar ×1
werkzeug ×1