导入mechanize时我在python3中出错.
我刚刚在我的virtualenv中安装了机械化,其中安装了python3.
$ which python3
/Users/myname/.virtualenvs/python3/bin/python3
$ pip freeze
mechanize==0.2.5
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在我的python代码中导入mechanize时,我收到此错误.
import mechanize
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-6b82e40e2c8e> in <module>()
----> 1 import mechanize
/Users/myname/.virtualenvs/python3/lib/python3.3/site-packages/mechanize/__init__.py in <module>()
117 import sys
118
--> 119 from _version import __version__
120
121 # high-level stateful browser-style interface
ImportError: No module named '_version'
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?
我是python的新手,这些天我一直在研究如何在python中编程.
感谢您的帮助!
更新
我已经为python3安装了mechanize.现在,我有另一个错误.
In [1]: import mechanize
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-6b82e40e2c8e> in <module>()
----> 1 import mechanize
/Users/myname/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/__init__.py …Run Code Online (Sandbox Code Playgroud) 我想添加一个覆盖整个屏幕的暗视图层.
为了做到这一点,我将UIView对象添加到window属性,UIViewController如下所示.我记得我能够window在ios6中添加这样的视图.但是,它在ios7中不起作用.
我怎么能让它工作?
提前致谢!!
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
overlayView.backgroundColor = [UIColor blackColor];
overlayView.alpha = 0.8;
[self.view.window addSubview:overlayView];
}
Run Code Online (Sandbox Code Playgroud) 我在阅读emberjs.com上的文档时感到困惑 http://emberjs.com/documentation/#toc_reopening-classes-and-instances
在上面的页面上,它解释如下.
Person.reopen({
// override `say` to add an ! at the end
say: function(thing) {
this._super(thing + "!");
}
});
Run Code Online (Sandbox Code Playgroud)
如您所见,重新打开用于向实例添加属性和方法.但是当您需要创建类方法或将属性添加到类本身时,您可以使用reopenClass.
Person.reopenClass({
createMan: function() {
return Person.create({isMan: true})
}
});
Person.createMan().get('isMan') // true
Run Code Online (Sandbox Code Playgroud)
虽然解释说"reopen用于向实例添加属性和方法.",我认为上面显示的两个示例都讨论了如何创建类方法或将属性添加到类本身,而不是实例.
我误解了它的内容吗?我不是一个经验丰富的程序员,所以我可能会被误解......
如果我被误解,请解释何时使用reopen和reopenClass.
提前致谢!
我有一个json字符串,由JSON.Stringify函数从对象转换而来.
我想知道它是json字符串还是只是一个常规字符串.
是否有像"isJson()"这样的函数来检查它是否是json?
当我使用本地存储时,我想使用该功能,如下面的代码.
先感谢您!!
var Storage = function(){}
Storage.prototype = {
setStorage: function(key, data){
if(typeof data == 'object'){
data = JSON.stringify(data);
localStorage.setItem(key, data);
} else {
localStorage.setItem(key, data);
}
},
getStorage: function(key){
var data = localStorage.getItem(key);
if(isJson(data){ // is there any function to check if the argument is json or string?
data = JSON.parse(data);
return data;
} else {
return data;
}
}
}
var storage = new Storage();
storage.setStorage('test', {x:'x', y:'y'});
console.log(storage.getStorage('test'));
Run Code Online (Sandbox Code Playgroud) 我想在ios7的标签栏中更改非活动图标的颜色.
我知道如何将颜色设置为选定的TabBar项目,但我不知道如何将颜色设置为非活动的TabBar项目.
有谁知道怎么做?提前致谢!!
这是我在appDelegate.m中的代码
//tint color for tabbar
[UITabBar appearance].barTintColor = [UIColor colorWithRed:0.077 green:0.411 blue:0.672 alpha:1.000];
//tint color for the text of inactive tabbar item.
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]} forState:UIControlStateNormal];
//tint color for the text of selected tabbar item.
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor orangeColor]} forState:UIControlStateSelected];
//tint color for the selected tabbar item.
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
//tint color for the inactive tabbar items.
//Question:how can I set tint color for the inactive tabbar items???
Run Code Online (Sandbox Code Playgroud) 我正在构建Chrome扩展程序,我编写了此代码.
var Options = function(){};
Options.prototype = {
getMode: function(){
return chrome.storage.sync.get("value", function(e){
console.log(e); // it prints 'Object {value: "test"}'.
return e;
});
},
setMode: function(){
chrome.storage.sync.set({"value": "test"}, function(e) {
})
}
}
var options = new Options();
options.setMode();
console.log(options.getMode()); // it prints 'undefined'.
Run Code Online (Sandbox Code Playgroud)
我希望它能打印出来
Object {value: "set up"}
Run Code Online (Sandbox Code Playgroud)
我打电话的时候options.getMode(),打印出来undefined.
有谁知道如何解决这个问题?
可能重复:
PHP:合并2个多维数组
我有这些数组,我想将它们合并到一个数组中.
$arrayAAA[0]['name'] = "stackoverflow";
$arrayBBB[0]['color'] = "white";
$arrayCCC[0]['media'] = "web";
Run Code Online (Sandbox Code Playgroud)
我想像这样合并这些.
$newArray[0]['name'] //"stackoverflow"
$newArray[0]['color'] //"white"
$newArray[0]['media'] //"web"
Run Code Online (Sandbox Code Playgroud)
如果有人知道怎么做,请给我一个帮助.我以为我可以通过使用合并它们array_merge(),但是这个功能在我的情况下不起作用.
非常感谢提前!
我试图找出装饰器在python中是如何工作的.但是,有两件事我无法说清楚,所以如果有人帮助我理解装饰器在python中是如何工作的,我感激不尽!
这是我刚刚编写的示例代码,用于查看其工作原理.
In [22]: def deco(f):
....: def wrapper():
....: print("start")
....: f()
....: print("end")
....: return wrapper
In [23]: @deco
....: def test():
....: print("hello world")
....:
Run Code Online (Sandbox Code Playgroud)
输出1
In [24]: test()
start
hello world
end
Run Code Online (Sandbox Code Playgroud)
我不明白的第一件事是当我调用test()时它输出"start","hello world","end"的原因.我了解到,当我调用test()时,它会在内部调用"deco(test)".如果是这样,它应该返回一个"包装器"函数对象而不是输出字符串.但是,它会输出字符串作为结果.我想知道它是如何在内部完成工作的.
输出2
In [28]: i = deco(test)
In [29]: i
Out[29]: <function __main__.wrapper>
In [30]: i()
start
start
hello world
end
end
Run Code Online (Sandbox Code Playgroud)
我打电话给"deco(测试)"只是为了看看它输出的结果.如上所示,它返回"包装器"函数对象,在将其分配给变量并调用"包装器"函数后,它输出两个"开始"和一个"hello world"和两个"end".内部发生了什么?为什么"开始"和"结束"分别输出两次?
有谁可以帮我理解这是如何工作的?
我正在开发一个chrome扩展.
我遇到了这个问题,当我访问facebook时,"webNavigation.onComitted"事件在facebook.com上被触发了两次.
这是我现在的代码,但它在控制台中打印了两次"Facebook".
// while logging in facebook.com, it prints "facebook" in console.
chrome.webNavigation.onCommitted.addListener(function(e) {
console.log("Facebook");
}, {url: [{urlPrefix : 'https://www.facebook.com/'}]})
Run Code Online (Sandbox Code Playgroud)
另一方面,这段代码工作正常.当我访问youtube.com时,它会在我预期的控制台中打印一次"youtube".
// on accessing youtube.com, it prints "youtube" in console.
chrome.webNavigation.onCommitted.addListener(function(e) {
console.log("youtube");
}, {url: [{urlPrefix : 'http://www.youtube.com/'}]})
Run Code Online (Sandbox Code Playgroud)
无论如何,我希望它在访问facebook.com时只加载一次.
我怎样才能让它发挥作用?
如果有人知道如何解决这个问题,请帮助我!
提前致谢!!
我尝试了什么
http://developer.chrome.com/extensions/webNavigation.html#events
我尝试了所有其他事件类型,例如"onBeforeNavigate","onCompleted".但它并没有解决我的问题.
stackoverflow上有用的相关帖子
Chrome扩展程序,javascript:为什么这次解雇两次?
此页面与我的问题类似,但此页面正在讨论"tabs.onUpdated"事件.
由于"tabs.onUpdated"事件不提供事件过滤器,我更喜欢使用"webNavigation"API.
我想随机生成这样的东西.
233 + 333 = 566
我的意思是第一个数字,运算符和第二个数字是随机生成的.
所以,我现在写了这个代码.
var x = parseInt(Math.random()*1000),
y = parseInt(Math.random()*1000),
operators = ['+', '-', '*', '/'],
operatorNum = parseInt(Math.random()*4),
operator = operators[operatorNum],
result;
result = x + operator + y;
Run Code Online (Sandbox Code Playgroud)
但这只是给我一个像"748/264"字符串的东西.它没有给我生成计算的结果.
我想我需要将运算符从字符串转换为运算符类型.但是,我认为没有运营商类型.
编辑
我正在构建Chrome扩展程序.根据Chrome扩展程序政策,我不允许使用该eval功能.
我写了一个javascript代码,随机生成一个计算公式.
代码随机生成类似的东西.
134 + 333 = 467
10*3 = 30
9/3 = 3
130 - 20 = 110
为了生成这样的东西,我有如下所示的代码.
var myCal = [
function(a, b){return a + b;},
function(a, b){return a - b;},
function(a, b){return a / b;},
function(a, b){return a * b;}
];
var tempX = parseInt(Math.random()*1000),
tempY = parseInt(Math.random()*1000),
tempNum = parseInt(Math.random()*4),
result;
result = myCal[tempNum](tempX, tempY);
Run Code Online (Sandbox Code Playgroud)
但问题是,当它生成包含"*"或"/"的计算公式时,它会返回错误的答案.
例如,当tempX为393且tempY为334且运算符为*时,它返回1.1766467065868262.
是什么导致了这个问题?
我不知道它有什么问题.
如果你知道如何解决这个问题,请帮帮我.
谢谢!!
PS
由于我正在构建Chrome扩展程序,因此我不允许通过其安全策略使用eval功能.这就是为什么我有自己的myCal功能.
javascript ×6
jquery ×3
ios ×2
ios7 ×2
objective-c ×2
python ×2
arrays ×1
ember.js ×1
iphone ×1
json ×1
mechanize ×1
php ×1
python-3.x ×1