对于想了解具有相同名称的Python模块的读者,本文将是一篇不可错过的文章,我们将详细介绍即,重复使用软件包中的标准模块名称,并且为您提供关于AngularJS具有相同模块名称的两个指令、iphone
对于想了解具有相同名称的Python模块的读者,本文将是一篇不可错过的文章,我们将详细介绍即,重复使用软件包中的标准模块名称,并且为您提供关于AngularJS具有相同模块名称的两个指令、iphone – 在Xcode中使用具有相同名称的资源、java – 具有相同名称的Android gradle模块、LuaXML使用多个具有相同名称的标记解析XML的有价值信息。
本文目录一览:- 具有相同名称的Python模块(即,重复使用软件包中的标准模块名称)
- AngularJS具有相同模块名称的两个指令
- iphone – 在Xcode中使用具有相同名称的资源
- java – 具有相同名称的Android gradle模块
- LuaXML使用多个具有相同名称的标记解析XML
具有相同名称的Python模块(即,重复使用软件包中的标准模块名称)
假设我有一个包含模块的软件包:
SWS/ __init.py__ foo.py bar.py time.py
并且这些模块需要引用彼此包含的功能。似乎我的time.py
模块遇到了问题,因为有一个同名的标准模块。
例如,在我的foo.py
模块同时需要我SWS.time
和标准pythontime
模块的情况下,我会遇到麻烦,因为解释器会在程序包内部查找并找到我的time.py
模块,然后再遇到标准time
模块。
有没有办法解决?这是不可以的情况,并且模块名称不能重复使用吗?
有关封装哲学的任何解决方案和意见在这里都将很有用。
答案1
小编典典重用标准函数/类/模块/软件包的名称从来都不是一个好主意。尽量避免它。但是,有适合您情况的干净解决方法。
您看到的行为是导入SWS.time
而不是stdlib的行为time
,这是由于import
古代python版本(2.x)的语义所致。要解决此问题,请添加:
from __future__ import absolute_import
在文件的最顶部。这会将import
python3.x的语义更改为更有意义。在这种情况下,语句:
import time
将仅引用顶级模块。因此,解释器在执行包内的导入时将 不 考虑您的SWS.time
模块,而只会使用标准库之一。
如果一个模块 内的 软件包需要输入SWS.time
你的选择:
使用 显式 相对导入:
from . import time
使用绝对导入:
import SWS.time as time
因此,您foo.py
将像:
from __future__ import absolute_importimport timefrom . import time as SWS_time
AngularJS具有相同模块名称的两个指令
拥有这两个文件
angular.module('fabTemplate',[]) .directive('fabgallery',[function () { ....
和
angular.module('fabTemplate',[]) .directive('fabVideo',[function () { ...
第二个指令将不被承认.
<fab-video />
不渲染任何东西.通过更改模块名称.
AngularJS的documentation says的参数名称(模块“method”的第一个参数)
The name of the module to create or retrieve.
我想这应该工作,然后…:S
角度不会在控制台中打印任何东西
From the docs:
requires (optional) [Array.] : If specified then new module is being created. If unspecified then the the module is being retrieved for further configuration.
你的代码应该是这样的:
//Module deFinition: angular.module('fabTemplate',[]); //Get the module and add the first directive: angular.module('fabTemplate').directive('fabgallery',function () {}); //Get the module and add the second directive: angular.module('fabTemplate').directive('fabVideo',function () {});
iphone – 在Xcode中使用具有相同名称的资源
例:
我将两个名为icon.png的文件添加到Xcode项目中.它们位于文件系统中的不同文件夹(Folder1 / icon.png和Folder2 / icon.png)以及Xcode中的不同组.有没有办法告诉Xcode让Folder2 / icon.png优先于Folder1 / icon.png?如果只存在1个icon.png,那么就使用那个.
谢谢.
编辑(2010-12-23):
您可以在Xcode项目中拥有多个具有相同名称的文件,即使它们不在单独的文件夹引用中,但它们位于不同的组中.编译完成后,应用程序包(它将是平的,没有文件夹),只有一个文件副本(icon.png).你如何选择使用哪个文件副本?
我被告知你可以为BlackBerry做这个.它的工作原理如下:编译器将沿着项目中的文件列表向下,并开始将它们添加到应用程序包中.如果它看到重复,它将覆盖(或不覆盖),因此底部(或顶部)的文件将具有更高的优先级,并将成为最终的捆绑.
解决方法
java – 具有相同名称的Android gradle模块
<dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>2.17</version> </dependency>
但是,此依赖关系具有模块javax / inject的2个定义,如gradle依赖关系树中所示:
+--- org.glassfish.jersey.core:jersey-client:2.17 | +--- org.glassfish.jersey.core:jersey-common:2.17 | | +--- org.glassfish.hk2:hk2-api:2.4.0-b10 | | | +--- javax.inject:javax.inject:1 | | +--- org.glassfish.hk2.external:javax.inject:2.4.0-b10
在尝试运行Android应用程序时,我收到错误:
com.android.dex.DexException: Multiple dex files define L/javax/inject/Inject
我已经尝试排除这些模块中的任何一个,但这不起作用,因为依赖关系依赖于它们来进行方法调用.
有没有其他解决方案来解决这个冲突?
解决方法
compile ('org.glassfish.jersey.containers:jersey-container-servlet:2.14'){ exclude module: 'javax.inject' } compile 'org.glassfish.hk2.external:javax.inject:2.4.0-b06'
LuaXML使用多个具有相同名称的标记解析XML
<level> <bg>details1</bg> <bg>details2</bg> </level>
有了xml.find(bg)我只能得到1个细节.这是因为xml.find返回匹配搜索条件或nil的第一个(子)表.
如果我想读两个bg.我怎样才能在LuaXML中实现它?或者请介绍其他Lua XML库的工作原理.
插件
我的真实场景是这样的
<a> <b> <level> <bg>details1</bg> </level> <level> <bg>details2</bg> </level> </b> </a>
我知道我需要将整个b对象取出并使用xml.tag来读取级别.但我的尝试失败了.你能帮我解决一下这段代码吗?
根据Mike Corcoran的建议,我终于得到了这样的解决方案.
require ''luaxml'' local text = [[ <a> <bcde> <level> <bg>details1</bg> </level> <level> <bg>details2</bg> </level> </bcde> </a> ]] local txml = xml.eval(text) for _,node in pairs(txml:find("bcde")) do if node.TAG ~= nil then if node[node.TAG] == "level" then local bg = node:find("bg") if bg ~= nil then for i=1,#bg do print( bg[i]) end end end end end
有太多的层次,似乎很慢..任何提高效率的建议?
解决方法
require ''luaxml'' local text = [[ <level> <bg>details1</bg> <bg>details2</bg> </level> ]] local VALUE = 1 local txml = xml.eval(text) for _,node in pairs(txml:find("level")) do if node.TAG ~= nil then print(node[VALUE]) end end
如果您需要过滤除< bg>之外的所有内容标签,你可以稍微修改一下这个循环:
for _,node in pairs(txml:find("level")) do if node.TAG ~= nil then if node[node.TAG] == "bg" then print(node[VALUE]) end end end
今天关于具有相同名称的Python模块和即,重复使用软件包中的标准模块名称的讲解已经结束,谢谢您的阅读,如果想了解更多关于AngularJS具有相同模块名称的两个指令、iphone – 在Xcode中使用具有相同名称的资源、java – 具有相同名称的Android gradle模块、LuaXML使用多个具有相同名称的标记解析XML的相关知识,请在本站搜索。
本文标签: