小编Gor*_*not的帖子

在python中正确使用subprocess.PIPE?

我正在尝试使用subprocess.Popen构建一个序列来获取视频文件的持续时间.我一直在搜索3天,并且在网上找不到任何原因,为什么这段代码不起作用,但它一直给我一个空白的结果:

import sys
import os
import subprocess

def main():
  the_file = "/Volumes/Footage/Acura/MDX/2001/Crash Test/01 Acura MDX Front Crash.mov"
  ffmpeg = subprocess.Popen(['/opt/local/bin/ffmpeg', '-i', the_file], stdout = subprocess.PIPE, )
  grep = subprocess.Popen(['grep', 'Duration'], stdin = subprocess.PIPE, stdout = subprocess.PIPE, )
  cut = subprocess.Popen(['cut', '-d', ' ', '-f', '4'], stdin = subprocess.PIPE, stdout = subprocess.PIPE, )
  sed = subprocess.Popen(['sed', 's/,//'], stdin = subprocess.PIPE, stdout = subprocess.PIPE, )

  duration = sed.communicate()
  print duration

if __name__ == '__main__':
  main()
Run Code Online (Sandbox Code Playgroud)

python subprocess

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

正确设置willSelectRowAtIndexPath和didSelectRowAtIndexPath以发送单元格选择

觉得我在这里有点疯狂.我有几个独立的详图UITextFieldS,一些UITextFieldsUITAbleViewCellS和一个单一的UITableViewCell,将被用来保存笔记,如果有任何.我只想在编辑模式下选择此单元格.当我不处于编辑模式时,我不希望能够选择它.选择单元格(在编辑模式下)将触发一个初始化视图的方法.我知道这很容易,但我在某处遗漏了一些东西.

以下是我正在使用的当前选择方法:

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!self.editing) {
        NSLog(@"Returning nil, not in edit mode");
        return nil;
    }
    NSLog(@"Cell will be selected, not in edit mode");
    if (indexPath.section == 0) {
        NSLog(@"Comments cell will be selected");
        return indexPath;
    }
    return nil;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!self.editing) {
        NSLog(@"Not in edit mode. Should not have made it this far.");
        return;
    }

    if (indexPath.section == 0)
        [self pushCommentsView];
    else …
Run Code Online (Sandbox Code Playgroud)

iphone uitableview didselectrowatindexpath

10
推荐指数
1
解决办法
1万
查看次数

有没有什么方法可以使用python将终端输出分配给变量?

我需要通过python获取视频文件的持续时间,作为更大脚本的一部分.我知道我可以使用ffmpeg来获取持续时间,但我需要能够将该输出保存为python中的变量.我认为这会起作用,但它给我的值为0:

cmd = 'ffmpeg -i %s 2>&1 | grep "Duration" | cut -d \' \' -f 4 | sed s/,//' % ("Video.mov")
duration = os.system(cmd)
print duration
Run Code Online (Sandbox Code Playgroud)

我在做输出重定向错了吗?或者根本没有办法将终端输出传回到python中?

python terminal redirect ffmpeg

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

使用Ruby解析标记中包含冒号的RSS项目?

我正在尝试解析具有此标记结构的RSS源中的信息:

<dc:subject>foo bar</dc:subject>
Run Code Online (Sandbox Code Playgroud)

使用内置的Ruby RSS库.显然,做的item.dc:subject是抛出错误,但我无法找出任何方法来提取这些信息.有没有办法让这个工作?或者是否可以使用不同的RSS库?

ruby rss parsing

9
推荐指数
1
解决办法
2764
查看次数

与 Jetpack Compose 一起使用时,WebView 在输入时崩溃

WebView使用 Jetpack Compose创建一个非常简单的包装器时,应用程序在我输入任何文本时崩溃。这是一个错误,还是我在做一些愚蠢的事情?相关代码:

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            WebViewC()
        }
    }
}

@Composable
fun WebViewC() {
    return AndroidView(viewBlock = { context ->
        WebView(context).apply {
            layoutParams = ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT
            )
            webViewClient = object : WebViewClient() {
                override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
                    return false
                }
            }
            loadUrl("https://google.com")
        }
    })
}
Run Code Online (Sandbox Code Playgroud)

迷恋;撞车;崩溃:

E/MessageQueue-JNI: java.lang.IllegalStateException: KeyEvent can't be processed because this key input node is not active.
        at androidx.compose.ui.input.key.KeyInputModifier.processKeyInput(KeyInputModifier.kt:62)
        at …
Run Code Online (Sandbox Code Playgroud)

android android-jetpack-compose

6
推荐指数
2
解决办法
1986
查看次数

更改为NSFetchedResultsController后,UITableView不更新DataSource

我有一个UITableView人口NSFetchedResultsController.初始提取工作正常.我可以添加,删除,修改等零问题.但我想在表中添加用户定义的排序.我这样做是通过改变NSFetchedResultsController使用不同的sortDescriptor设置和不同的设置sectionNameKeyPath.这是我更改提取的代码:

-(void)changeFetchData {
    fetchedResultsController = nil;

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Object" inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];

    NSString *sortKey = @"sortKey";
    NSString *cacheName = @"myNewCache";
    BOOL ascending = YES;

    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortKey ascending:ascending];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
    [fetchRequest setSortDescriptors:sortDescriptors];

    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:sortKey cacheName:nil];
    self.fetchedResultsController = aFetchedResultsController;
    fetchedResultsController.delegate = self;

    [aFetchedResultsController release];
    [fetchRequest release];
    [sortDescriptor release];
    [sortDescriptors …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uitableview nsfetchedresultscontroller nsfetchrequest

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

确定 git 存储库是否已取消脚本更改的最快方法?

如果我位于具有远程未拉取更改的 git 存储库中,我想在提示符中添加一个字形。现在,我正在尝试git ls-remote origin -h refs/heads/master检查git rev-parse HEAD。但这真的很慢,而且它只显示远程和本地存储库上的引用是否不同。因此,如果我有未推送的更改,它也会返回 true。有没有更快的方法来检查我的远程存储库以查看是否需要提取更改?

git

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

需要帮助理解python中的"TypeError:default __new__不带参数"错误

出于某种原因,我无法左右让我的头__init____new__.我有一堆从终端运行良好的代码,但当我将其作为Google快速搜索框的插件加载时,我收到错误TypeError: default __new__ takes no parameters.

我一直在读这个错误,这让我的脑子旋转起来.目前我有3个类,没有子类,每个类都有自己def的类.我从不使用def __init__def __new__,但我已经明确感觉这些是给我错误的功能(或缺少它).

我不知道如何将代码汇总到一个在这里有用的代码片段,因为我有点过头,但整个脚本都可以在github上找到.不要指望任何人为我修改我的代码,我只是在我的智慧结束.一个简单的(简单的英语,而不是python文档的引用,我已经阅读了20次,但仍然没有真正理解)探索为什么会出现这个错误,或者为什么我应该,或者不是,使用__init__和/或__new__功能将得到认真的赞赏.

python init typeerror

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

可选地匹配文字字符串

我正在使用以下正则表达式匹配并捕获字符串weather in foo bar:

weather in ([a-z]+|[0-9]{5})\s?([a-zA-Z]+)?
Run Code Online (Sandbox Code Playgroud)

哪个匹配和捕获bar可选,并且foo可以成为城市或拉链.

但是,我很乐意让用户写weather in foo for bar,因为我自己不小心写了几次.有没有办法可选地捕获文字字符串,for而不必诉诸\s?f?o?r?\s?

regex

2
推荐指数
1
解决办法
6516
查看次数

只有在没有关系的情况下才能正确处理对象的删除?

我有一个Person属于Department一对多关系的实体.

我希望能够删除Department时,有没有更多的Person与它(或者通过缺失的相连的S Person实体,或更改了Persondepartment属性).现在,我正在尝试使用以下处理程序NSManagedObjectContextObjectsDidChangeNotification(目前只是尝试查看删除,并正确删除):

- (void)managedObjectDidChange:(NSNotification *)notification {

    NSSet *updatedObjects = [[notification userInfo] objectForKey:NSDeletedObjectsKey];
    for (NSManagedObject *obj in updatedObjects) {
        if ([obj.entity.name isEqualToString:@"Person"]) {
            NSLog(@"Person Changed");

            NSManagedObject *department = [(Person *)obj department];
            NSLog(@"%i", [[department valueForKey:@"person"] count]);

            if ([[department] valueForKey:@"person"] count] == 0) {
                NSLog(@"Department has no more people associated with it");
                // deletion code
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我删除某个人时,与该部门相关联的人数不会改变.我没有对Department实体进行提取.那是我应该做的吗?

cocoa cocoa-touch core-data nsmanagedobject nsmanagedobjectcontext

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