我使用python 2.7并试图挑选一个对象.我想知道泡菜协议之间真正的区别是什么.
import numpy as np
import pickle
class data(object):
def __init__(self):
self.a = np.zeros((100, 37000, 3), dtype=np.float32)
d = data()
print "data size: ", d.a.nbytes/1000000.
print "highest protocol: ", pickle.HIGHEST_PROTOCOL
pickle.dump(d,open("noProt", 'w'))
pickle.dump(d,open("prot0", 'w'), protocol=0)
pickle.dump(d,open("prot1", 'w'), protocol=1)
pickle.dump(d,open("prot2", 'w'), protocol=2)
out >> data size: 44.4
out >> highest protocol: 2
Run Code Online (Sandbox Code Playgroud)
然后我发现保存的文件在磁盘上有不同的大小:
noProt
:177.6MB prot0
:177.6MB prot1
:44.4MB prot2
:44.4MB我知道这prot0
是一个人类可读的文本文件,所以我不想使用它.我猜协议0是默认给出的协议.
我想知道协议1和协议2之间的区别是什么,我有理由选择其中一个或另一个吗?
什么是更好用,pickle
或cPickle
?
如果我在一个页面上
http://somesite.com/somepage.php?param1=asdf
在该页面的JavaScript中,我想将一个变量设置为URL的GET部分中的参数值.
所以在JavaScript中:
<script>
param1var = ... // ... would be replaced with the code to get asdf from URI
</script>
Run Code Online (Sandbox Code Playgroud)
会是什么?
我试图找出如何从另一个调用速度模板时传递参数.
它看起来像这样
文件:_reading_tracker.vm
#parse("student/shared/_bio_data.vm")
Run Code Online (Sandbox Code Playgroud)
我需要将一些参数传递给_bio_data.vm.不知道该怎么做
我需要在 PHP 中通过 ODBC 依次调用两个存储过程:
#run stored procedure 1
$query = "Shipped_Not_Shipped_Rep ".$_GET['rep_id'];
$result = odbc_exec($dbh, $query);
odbc_result_all($result);
#run stored procedure 2
$query = "Shipped_Not_Shipped_Account ".$_GET['account_id'];
$result = odbc_exec($dbh, $query);
odbc_result_all($result);
Run Code Online (Sandbox Code Playgroud)
在第二次存储过程调用后,我在 PHP 中收到此错误:
警告:odbc_exec() [function.odbc-exec]:SQL 错误:[unixODBC][FreeTDS][SQL Server]游标状态无效,SQLExecDirect 中的 SQL 状态为 24000
如果我重新安排我调用存储过程的顺序,那么错误总是第二个。有没有办法,idk,重置调用之间的光标位置?这里有点超出我的元素。
>>> s = 'auszuschließen'
>>> print(s.encode('ascii', errors='xmlcharrefreplace'))
b'auszuschließen'
>>> print(str(s.encode('ascii', errors='xmlcharrefreplace'), 'ascii'))
auszuschließen
Run Code Online (Sandbox Code Playgroud)
有没有更漂亮的方法来打印任何字符串b''
?
编辑:
我只是试图从Python中打印转义字符,我唯一的抱怨是当我这样做时,Python会添加"b"'.
如果我想看到像Windows 7这样的哑终端中的实际角色,那么我得到这个:
Traceback (most recent call last):
File "Mailgen.py", line 378, in <module>
marked_copy = mark_markup(language_column, item_row)
File "Mailgen.py", line 210, in mark_markup
print("TP: %r" % "".join(to_print))
File "c:\python32\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2026' in position 29: character maps to <undefined>
Run Code Online (Sandbox Code Playgroud) 我想接受一个参数并创建一个名称为参数本身的类。例如,我以“Int”为参数,创建了一个名为“Int”的类,我的类就是这样的。
class Int :
def __init__(self,param) :
self.value = 3
Run Code Online (Sandbox Code Playgroud)
我就是这样做的。
def makeClass( x ) :
return eval( 'class %s :\n def __init__(self,param) :\n self.type = 3'%(x,))
Run Code Online (Sandbox Code Playgroud)
然后打电话
myClass = makeClass('Int')
myInt = myClass(3)
Run Code Online (Sandbox Code Playgroud)
我收到了一个语法错误。请帮忙。
这有效:
String address1 = HtmlUtil.escape(rs.getString("address1"));
Run Code Online (Sandbox Code Playgroud)
...但我不想显示"null".所以我试过这个,这不起作用:
String address1 = HtmlUtil.escape(rs.getString("address1") || "");
Run Code Online (Sandbox Code Playgroud)
是使用它的最佳选择:?
String address1 = HtmlUtil.escape(rs.getString("address1"));
if (address1 == null) address1 = "";
Run Code Online (Sandbox Code Playgroud) 为什么此匹配符合预期,但无法进行细分?单行s可以正常工作。
import re
s = """<script>
wut</script>"""
print(re.match('<script(.*?)</script>', s, re.DOTALL).groups())
# Returns ('>\nwut',)
print(re.sub('<script(.*?)</script>', '', s, re.DOTALL))
# Returns <script>
# wut</script>
Run Code Online (Sandbox Code Playgroud)
我只想了解这一点;无需建议使用Beautiful Soup或手动解析。
我只想到达['bar']
这里:
>>> re.findall(r"(?<!\bdef )([a-zA-Z0-9.]+?)\(", "def foo(): bar()")
['oo', 'bar']
Run Code Online (Sandbox Code Playgroud)
这在单个正则表达式中可能吗?如果没有,我将首先使用这个:re.sub(r"\bdef [a-zA-Z0-9.]+", "", "def foo(): bar()")
如何访问VM模板中URI中传递的GET变量?
这仅在加载小部件URL时有效:
$request.get("parameters").get("fav").get(0)
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个可以使用友好URL的简洁解决方案.
这是我的测试模板:
<br><br><br>
#set($url = $request.attributes.CURRENT_URL)
<h2>url: $url</h2>
#set($favs = $url.split("fav="))
favs: $favs<br>
favs.size(): $favs.size() <br>
#if($favs.size() > 1)
#set($fav1 = $favs.get(1).split("&").get(0))
fav1: $fav1<br>
#else
No fav!
#end
#if($favs.size() > 2)
#set($fav2 = $favs.get(2).split("&").get(0))
fav2: $fav2<br>
#end
#set($favs2 = $httpUtil.getParameterMap($url, "fav"))
favs2: $favs2
<hr>
<h3>Fav?</h3>
<form method="get">
<input type="checkbox" name="fav" value="dave"/> Dave<br>
<input type="checkbox" name="fav" value="nate"/> Nate<br>
<input type="checkbox" name="fav" value="taylor"/> Taylor<br>
<input type="submit" value="Send"/>
</form>
<hr>
<div style="font-size: 9px;">request: $request</div>
Run Code Online (Sandbox Code Playgroud) <?= x ?>
Run Code Online (Sandbox Code Playgroud)
这是<?php echo x ?>
我的本地Apache与PHP 的简短和工作正常,但服务器上的ISS 7 PHP不处理它.
我错过了一个设置吗?
python ×5
java ×2
oop ×2
php ×2
python-3.x ×2
regex ×2
velocity ×2
c# ×1
cursor ×1
get ×1
iis-7 ×1
javascript ×1
liferay ×1
null ×1
numpy ×1
odbc ×1
pickle ×1
python-2.7 ×1
sql-server ×1
subclassing ×1
url ×1
vtl ×1