在Python中使用SQLite3,我试图存储一段UTF-8 HTML代码的压缩版本.
代码如下所示:
...
c = connection.cursor()
c.execute('create table blah (cid integer primary key,html blob)')
...
c.execute('insert or ignore into blah values (?, ?)',(cid, zlib.compress(html)))
Run Code Online (Sandbox Code Playgroud)
在这一点上得到错误:
sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.
Run Code Online (Sandbox Code Playgroud)
如果我使用'text'而不是'blob'并且不压缩HTML片段,那么它可以很好地工作(尽管db很大).当我使用'blob'并通过Python zlib库压缩时,我收到上面的错误消息.我环顾四周,但找不到这个简单的答案.
strftime(),根据cpan.org:
print strftime($template, @lt);
Run Code Online (Sandbox Code Playgroud)
我只是想不出这个正确的Perl代码配方.它一直报告我调用strftime()的错误:
...
use Date::Format;
...
sub parse_date {
if ($_[0]) {
$_[0] =~ /(\d{4})/;
my $y = $1;
$_[0] =~ s/\d{4}//;
$_[0] =~ /(\d\d)\D(\d\d)/;
return [$2,$1,$y];
}
return [7,7,2010];
}
foreach my $groupnode ($groupnodes->get_nodelist) {
my $groupname = $xp->find('name/text()', $groupnode);
my $entrynodes = $xp->find('entry', $groupnode);
for my $entrynode ($entrynodes->get_nodelist) {
...
my $date_added = parse_date($xp->find('date_added/text()', $entrynode));
...
$groups{$groupname}{$entryname} = {...,'date_added'=>$date_added,...};
...
}
}
...
my $imday = $maxmonth <= 12 ? 0 : 1;
...
while …Run Code Online (Sandbox Code Playgroud)