我想知道在Python应用程序中导入包的首选方法.我有这样的包结构:
project.app1.models
project.app1.views
project.app2.models
Run Code Online (Sandbox Code Playgroud)
project.app1.views进口project.app1.models和project.app2.models.有两种方法可以实现这一点.
绝对进口:
import A.A
import A.B.B
Run Code Online (Sandbox Code Playgroud)
或者使用PEP 328在Python 2.5中引入的显式相对导入:
# explicit relative
from .. import A
from . import B
Run Code Online (Sandbox Code Playgroud)
什么是最pythonic的方式来做到这一点?
我正在使用ExtractingRequestHandler为Solr索引PDF.我想在文档中显示页码和点击,例如" 在第2,3和5页foo中找到了术语bar.pdf".
是否可以在查询结果中包含页码?
在Objective-C的iOS应用我的测试包,错误不会自动高亮(喜欢的东西缺少分号等).我必须运行测试,然后在构建失败时检查构建日志.
这是正常的还是我弄乱了配置?对于项目的其余部分,错误突出显示按预期工作.
出于某种原因,我在将文本字段作为第一响应者时遇到了麻烦.
我有一个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
我尝试了什么:
任何提示都表示赞赏!
apache-tika ×1
iphone ×1
objective-c ×1
package ×1
pdf ×1
python ×1
solr ×1
solr-cell ×1
uikit ×1
uitextfield ×1
xcode ×1