小编Dan*_*per的帖子

Python模块的绝对与显式相对导入

我想知道在Python应用程序中导入包的首选方法.我有这样的包结构:

project.app1.models
project.app1.views
project.app2.models
Run Code Online (Sandbox Code Playgroud)

project.app1.views进口project.app1.modelsproject.app2.models.有两种方法可以实现这一点.

绝对进口:

import A.A
import A.B.B
Run Code Online (Sandbox Code Playgroud)

或者使用PEP 328Python 2.5中引入的显式相对导入:

# explicit relative
from .. import A
from . import B
Run Code Online (Sandbox Code Playgroud)

什么是最pythonic的方式来做到这一点?

python package python-import

73
推荐指数
3
解决办法
4万
查看次数

使用Solr为带有页码的PDF编制索引

我正在使用ExtractingRequestHandler为Solr索引PDF.我想在文档中显示页码和点击,例如" 在第2,3和5页foo中找到了术语bar.pdf".

是否可以在查询结果中包含页码?

pdf solr full-text-search solr-cell apache-tika

5
推荐指数
1
解决办法
2577
查看次数

XCode 7.2中的测试包中没有突出显示错误

在Objective-C的iOS应用我的测试包,错误不会自动高亮(喜欢的东西缺少分号等).我必须运行测试,然后在构建失败时检查构建日志.

这是正常的还是我弄乱了配置?对于项目的其余部分,错误突出显示按预期工作.

xcode objective-c

4
推荐指数
1
解决办法
231
查看次数

UITextView上的becomeFirstResponder无法正常工作

出于某种原因,我在将文本字段作为第一响应者时遇到了麻烦.

我有一个UITableView有两行.每行都有一个标签和一个UITextField.文本字段标记为kLoginRowIndex = 0和kPasswordRowIndex = 1.正如您可能已经猜到的那样,我使用它来设置登录名和密码.

如果用户在编辑登录文本字段时点击返回按钮,我希望密码文本字段获得焦点.不幸的是,密码文本字段不接受焦点.这是我的代码:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    NSLog(@"%s:(textField.tag:%d)", __FUNCTION__, textField.tag);
    [textField resignFirstResponder];
    if(textField.tag == kLoginRowIndex) {
        UITableViewCell *cell = [self tableView:self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:kPasswordRowIndex inSection:0]];
        UITextField *nextTextField = (UITextField *)[cell viewWithTag:kPasswordRowIndex];
        NSLog(@"(nextTextField.tag:%d)", nextTextField.tag);
        NSLog(@"canBecomeFirstResponder returned %d", [nextTextField canBecomeFirstResponder]);
        NSLog(@"becomeFirstResponder returned %d", [nextTextField becomeFirstResponder]);
    } else {
        [self validate:textField];
    }
    return NO;
}
Run Code Online (Sandbox Code Playgroud)

这是日志输出:

-[SettingsViewController textFieldShouldReturn:]:(textField.tag:0)
(nextTextField.tag:1)
canBecomeFirstResponder returned 1
becomeFirstResponder returned 0

我尝试了什么:

  • 返回YES而不是NO
  • 删除对canBecomeFirstResponder的调用(仅用于调试目的)

任何提示都表示赞赏!

iphone uitextfield uikit

3
推荐指数
1
解决办法
8480
查看次数