显然,我可以在Python 2.7中做到这一点:
value = '??'
Run Code Online (Sandbox Code Playgroud)
似乎Python正在使用编码将字符串文字中的字符编码为字节字符串.什么是编码?这是sys.getdefaultencoding()源文件的编码,或其他什么定义的编码?
谢谢
刚开始使用Flask,请访问http://flask.pocoo.org/docs/views/
假设我有一个基本的REST api,在这种情况下用于症状:
/
GET - list
POST - create
/<symptomid>
GET - detail
PUT - replace
PATCH - patch
DELETE - delete
Run Code Online (Sandbox Code Playgroud)
我可以用Flask的MethodView方法很好地实现这个,如下所示:
from flask import Blueprint, request, g
from flask.views import MethodView
#...
mod = Blueprint('api', __name__, url_prefix='/api')
class SymptomAPI(MethodView):
""" ... """
url = "/symptoms/"
def get(self, uid):
if uid is None:
return self.list()
else:
return self.detail(uid)
def list(self):
# ...
def post(self):
# ...
def detail(self, uid):
# ...
def put(self, uid):
# …Run Code Online (Sandbox Code Playgroud) 如何在测试方法之间删除,删除或回滚或断开H2数据库?
这是我的一些hibernate测试配置:
<property name="connection.driver_class">org.h2.Driver</property>
<property name="connection.url">
jdbc:h2:mem:test;DB_CLOSE_DELAY=0;INIT=RUNSCRIPT FROM './h2-ext/add_to_date.sql'
</property>
<property name="hbm2ddl.auto">create</property>
Run Code Online (Sandbox Code Playgroud)
我有一个基类,我将继承我的所有测试:
public abstract class BaseTest {
@After
public void drop() throws Exception {
System.out.println("!!!!!! DROP !!!!!!&&&&&&&&&&&&&&&&&&&&&&");
// this seems to do nothing
//org.h2.store.fs.FileUtils.deleteRecursive("mem:test", true);
//org.h2.store.fs.FileUtils.deleteRecursive("NoTellingwhatThisdoes", true);
// the schema does not get recreated, it seems
//Session sess = DB.sf.openSession();
//sess.createSQLQuery("DROP ALL OBJECTS;").executeUpdate();
// org.h2.jdbc.JdbcSQLException: Cannot truncate "PUBLIC.FOO";
//Session sess = DB.sf.openSession();
//sess.createSQLQuery("TRUNCATE TABLE FOO;").executeUpdate();
//sess.createSQLQuery("TRUNCATE TABLE BAR;").executeUpdate();
}
}
Run Code Online (Sandbox Code Playgroud)
似乎应该有一种简单的方法来执行这样的集成测试?
也许我可以使用某种某种Transactional注释?但是,我想知道如何用相对香草的球衣+ JUnit做到这一点.
泽西岛是2.12,Java 1.7,H2是1.4.181,JUnit是4.11.
版本可以协商.
我正在尝试fig up使用最小的节点应用程序运行.
(编辑:从fig.yml删除卷)
fig.yml:
example:
build: .
command: node server.js
ports:
- "4000:4000"
links:
- postgres
postgres:
image: postgres
Run Code Online (Sandbox Code Playgroud)
Dockerfile:
FROM node
ADD . /src
WORKDIR /src
RUN npm install
Run Code Online (Sandbox Code Playgroud)
server.coffee:
express = require 'express'
app = express()
app.get "/", (req, res) ->
res.send "Hello World"
server = app.listen 4000, () ->
console.log 'Listening on port %d', server.address().port
Run Code Online (Sandbox Code Playgroud)
fig build按预期进行.fig up失败了:
example_1 | module.js:340
example_1 | throw err;
example_1 | ^
example_1 | Error: Cannot …Run Code Online (Sandbox Code Playgroud) 有一个函数在R被调用pf,源是在这里.
我正在尝试使用emscripten将此函数转换为JavaScript.我这样调用:
emcc -s EXPORTED_FUNCTIONS="['pf']" nmath/pf.c \
-Ignuwin32/fixed/h/ \
-I/usr/local/Cellar/r/3.1.1/include/ \
-I/usr/local/Cellar/r/3.1.1/R.framework/Versions/3.1/Resources/include/
Run Code Online (Sandbox Code Playgroud)
我收到警告:
WARNING root: function requested to be exported, but not implemented: "pf"
Run Code Online (Sandbox Code Playgroud)
并且,pf在输出js中没有任何暗示.根据emcc,为什么这个功能"没有实现"?
编辑(根据zakki的答案它应该是_pf,-s EXPORTED_FUNCTIONS="['_pf']"但问题仍然存在):
有关绝对包含路径的事先警告.但是,我假设它可以被忽略?也许它至关重要:
emcc -s EXPORTED_FUNCTIONS="['_pf']" nmath/pf.c -Ignuwin32/fixed/h/ -I/usr/local/Cellar/r/3.1.1/include/ -I/usr/local/Cellar/r/3.1.1/R.framework/Versions/3.1/Resources/include/
WARNING root: -I or -L of an absolute path "-I/usr/local/Cellar/r/3.1.1/include/" encountered. If this is to a local system header/library, it may cause problems (local system files make sense for compiling natively on your …Run Code Online (Sandbox Code Playgroud) 我有一个以制表符分隔的数据文件,其中包含200多万行和19列.你可以在US.zip找到它:http://download.geonames.org/export/dump/.
我开始运行以下但是for l in f.readlines().我知道只是迭代文件应该更有效,所以我在下面发布.尽管如此,通过这个小优化,我在这个过程中使用了30%的内存,并且只完成了大约6.5%的记录.看起来,按照这种速度,它将像以前一样耗尽内存.而且,我的功能非常慢.我能做些什么来加快速度吗?del每次for循环都会对对象有帮助吗?
def run():
from geonames.models import POI
f = file('data/US.txt')
for l in f:
li = l.split('\t')
try:
p = POI()
p.geonameid = li[0]
p.name = li[1]
p.asciiname = li[2]
p.alternatenames = li[3]
p.point = "POINT(%s %s)" % (li[5], li[4])
p.feature_class = li[6]
p.feature_code = li[7]
p.country_code = li[8]
p.ccs2 = li[9]
p.admin1_code = li[10]
p.admin2_code = li[11]
p.admin3_code = li[12]
p.admin4_code = li[13]
p.population = …Run Code Online (Sandbox Code Playgroud) 我正在尝试IntentService从我的主要活动中的点击处理程序开始。我现在正在学习Intents,但还不太明白。我不确定我应该如何在这里实例化我的意图并将其传递给startService. 我不知道为什么我必须做这样的事情,Intent据我所知,这不会在我的服务中使用。我不知道如何调试这个问题。
来自点击回调:
\n\n this.commute = new Commute();\n\n locationService = new LocationService();\n locationService.setCommute(commute);\n // com.orm.SugarApp@8b2e18f is this.getApplicationContext() ...\n Context context = this.getBaseContext();\n System.out.println("!!!!!!!!!!!!!!!!!!!!!");\n System.out.println(context);\n Intent intent = new Intent(context, LocationService.class);\n System.out.println(locationService);\n System.out.println(intent);\n locationService.startService(intent); // <---- OFFENDING LINE\n System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@");\n\n chronometer.setBase(SystemClock.elapsedRealtime());\n chronometer.start();\n commute.start();\nRun Code Online (Sandbox Code Playgroud)\n\nlogcat 在回溯之前,没有任何对象是null...:
01-27 09:53:44.465 2718-2718/org.skyl.commutetracker I/System.out\xef\xb9\x95 !!!!!!!!!!!!!!!!!!!!!\n01-27 09:53:44.466 2718-2718/org.skyl.commutetracker I/System.out\xef\xb9\x95 android.app.ContextImpl@8b2e18f\n01-27 09:53:44.466 2718-2718/org.skyl.commutetracker I/System.out\xef\xb9\x95 org.skyl.commutetracker.services.LocationService@387dcc1c\n01-27 09:53:44.466 2718-2718/org.skyl.commutetracker I/System.out\xef\xb9\x95 Intent { cmp=org.skyl.commutetracker/.services.LocationService }\n01-27 09:53:44.466 2718-2718/org.skyl.commutetracker D/AndroidRuntime\xef\xb9\x95 Shutting …Run Code Online (Sandbox Code Playgroud)