是否可以在提供者方法中进行DI?
在这个例子中
angular.module('greet',[])
.provider('greeter',function() {
this.$get=function() {
};
})
.service('greeterService',function($http){
console.log($http);
})
;
Run Code Online (Sandbox Code Playgroud)
注入$http
服务似乎是正确的实现,但它在提供程序方法中不起作用并且它会引发错误:
未知提供商:$ http
提供者方法是否与DI一起注入服务?
例如,
class Lake(Base):
__tablename__ = 'lake'
id = Column(Integer, primary_key=True)
name = Column(String)
geom = Column(Geometry('POLYGON'))
point = Column(Geometry('Point'))
lake = Lake(name='Orta', geom='POLYGON((3 0,6 0,6 3,3 3,3 0))', point="POINT(2 9)")
query = session.query(Lake).filter(Lake.geom.ST_Contains('POINT(4 1)'))
for lake in query:
print lake.point
Run Code Online (Sandbox Code Playgroud)
它回来了 <WKBElement at 0x2720ed0; '010100000000000000000000400000000000002240'>
我也试过做lake.point.ST_X(),但它也没有给出预期的纬度
将值从WKBElement转换为可读和有用的格式的正确方法是什么,比如说(lng,lat)?
谢谢
我正在使用matplotlib和shapely测试多边形点函数.
这是一张包含百慕大三角形多边形的地图.
Google地图的多边形点函数清楚地表明,testsPoint和testingPoint2位于多边形内部,这是正确的结果.
如果我在matplotlib中测试两个点并且形状合理,则只有point2通过测试.
In [1]: from matplotlib.path import Path
In [2]: p = Path([[25.774252, -80.190262], [18.466465, -66.118292], [32.321384, -64.75737]])
In [3]: p1=[27.254629577800088, -76.728515625]
In [4]: p2=[27.254629577800088, -74.928515625]
In [5]: p.contains_point(p1)
Out[5]: 0
In [6]: p.contains_point(p2)
Out[6]: 1
Run Code Online (Sandbox Code Playgroud)
形状上显示与matplotlib相同的结果.
In [1]: from shapely.geometry import Polygon, Point
In [2]: poly = Polygon(([25.774252, -80.190262], [18.466465, -66.118292], [32.321384, -64.75737]))
In [3]: p1=Point(27.254629577800088, -76.728515625)
In [4]: p2=Point(27.254629577800088, -74.928515625)
In [5]: poly.contains(p1)
Out[5]: False
In …
Run Code Online (Sandbox Code Playgroud) python matplotlib point-in-polygon google-maps-api-3 shapely
在步骤8,有一个定义为:
def outer():
x = 1
def inner():
print x # 1
return inner
Run Code Online (Sandbox Code Playgroud)
如果我们运行它:
>>> foo = outer()
>>> foo.func_closure # doctest: +ELLIPSIS
Run Code Online (Sandbox Code Playgroud)
它不打印x.根据解释:
一切都按照Python的范围规则工作 - x是我们函数外部的局部变量.当内部打印x在点#1处Python寻找内部的局部变量而没有找到它在封闭范围内查找外部函数,在那里找到它.
但是从可变寿命的角度来看,事情呢?我们的变量x是函数外部的局部变量,这意味着它只在函数外部运行时存在.我们无法在返回外部之后调用内部,因此根据我们的Python工作原理模型,在我们调用内部时,x应该不再存在,并且可能会发生某种类型的运行时错误.
但是,我真的不明白第二段是什么意思.
我理解inner()确实得到x的值,但为什么它不打印x?
谢谢
更新:
谢谢大家的答案.现在我明白了原因." return inner "只是一个指向 inner()的指针,但它没有被执行,这就是为什么inner()不打印x,因为它根本没有被调用
我有如下三张表
http://sqlfiddle.com/#!2/82212/6:
CREATE TABLE IF NOT EXISTS `cat` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`color_options` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
);
INSERT INTO `cat` (`id`, `color_options`) VALUES (1, '1,2,3,4');
CREATE TABLE IF NOT EXISTS `template` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`cat_id` int(15) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
);
INSERT INTO `template` (`id`, `cat_id`) VALUES (1, 1);
CREATE TABLE IF NOT EXISTS `color` (
`id` int(15) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT …
Run Code Online (Sandbox Code Playgroud) 例如,当使用select2 muti-value时,用户输入' new ',并显示
在选择" New Mexcio "之后,用户想要从剩下的3个中再次选择.为了做到这一点,用户必须再次输入"新".
有没有办法保留结果而不是清除' 查询?
谢谢
python ×3
angularjs ×1
function ×1
geoalchemy2 ×1
javascript ×1
join ×1
matplotlib ×1
mysql ×1
postgis ×1
scope ×1
shapely ×1
sql ×1
sqlalchemy ×1