最近很多小伙伴都在问如何获取Python当前模块中所有类的列表?和python获取模块下所有对象这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展c#–如何获取文档中所有内容控件的列
最近很多小伙伴都在问如何获取Python当前模块中所有类的列表?和python获取模块下所有对象这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展c# – 如何获取文档中所有内容控件的列表?、ios – 如何获取iPhone中所有视频文件的列表、linux – 如何获取Yocto中所有可用目标的列表?、php – 如何获取laravel中所有服务器会话的列表?等相关知识,下面开始了哦!
本文目录一览:- 如何获取Python当前模块中所有类的列表?(python获取模块下所有对象)
- c# – 如何获取文档中所有内容控件的列表?
- ios – 如何获取iPhone中所有视频文件的列表
- linux – 如何获取Yocto中所有可用目标的列表?
- php – 如何获取laravel中所有服务器会话的列表?
如何获取Python当前模块中所有类的列表?(python获取模块下所有对象)
我已经看到了很多人从一个模块中提取所有类的示例,通常是这样的:
# foo.pyclass Foo: pass# test.pyimport inspectimport foofor name, obj in inspect.getmembers(foo): if inspect.isclass(obj): print obj
太棒了
但是我无法找到如何从当前模块中获取所有类。
# foo.pyimport inspectclass Foo: passdef print_classes(): for name, obj in inspect.getmembers(???): # what do I do here? if inspect.isclass(obj): print obj# test.pyimport foofoo.print_classes()
这可能确实很明显,但是我什么也找不到。谁能帮我吗?
答案1
小编典典尝试这个:
import syscurrent_module = sys.modules[__name__]
在您的情况下:
import sys, inspectdef print_classes(): for name, obj in inspect.getmembers(sys.modules[__name__]): if inspect.isclass(obj): print(obj)
甚至更好:
clsmembers = inspect.getmembers(sys.modules[__name__], inspect.isclass)
因为inspect.getmembers()带谓语。
c# – 如何获取文档中所有内容控件的列表?
public static List<ContentControl> GetAllContentControls(Document wordDocument) { if (null == wordDocument) throw new ArgumentNullException("wordDocument"); List<ContentControl> cclist = new List<ContentControl>(); ; // Body cc var inBodyCc = (from r in wordDocument.ContentControls.Cast<ContentControl>() select r); cclist.AddRange(inBodyCc); // cc within shapes foreach (Shape shape in wordDocument.Shapes) { if (shape.Type == Microsoft.Office.Core.MsoShapeType.msoTextBox) { cclist.AddRange(WordDocumentHelper.GetContentControlsInRange(shape.TextFrame.TextRange)); } } // Get the list of cc in the story ranges : wdFirstPageHeaderStory,wdFirstPageFooterStory,wdTextFrameStory (textBox)... foreach (Range range in wordDocument.StoryRanges) { cclist.AddRange(WordDocumentHelper.GetContentControlsInRange(range)); } return cclist; } public static List<ContentControl> GetContentControlsInRange(Range range) { if (null == range) throw new ArgumentNullException("range"); List<ContentControl> returnValue = new List<ContentControl>(); foreach (ContentControl cc in range.ContentControls) { returnValue.Add(cc); } return returnValue; }
问候.
解决方法
Sub GetCCs() Dim d As Document Set d = ActiveDocument Dim cc As ContentControl Dim sr As Range Dim srs As StoryRanges For Each sr In d.StoryRanges For Each cc In sr.ContentControls ''# do your thing Next Next End Sub
ios – 如何获取iPhone中所有视频文件的列表
我有一个TableViewController,并希望在我的应用程序中显示来自iphone的所有视频文件.
如何获取所有视频文件的列表?
解决方法
- (void)updateAssetsLibrary { loadImgView.hidden = NO; [spinner startAnimating]; //selectVideoBtn .userInteractionEnabled = NO; assetItems = [NSMutableArray arrayWithCapacity:0]; ALAssetsLibrary *assetLibrary = AssetsLibrary; [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group,BOOL *stop) { if (group) { [group setAssetsFilter:[ALAssetsFilter allVideos]]; [group enumerateAssetsUsingBlock:^(ALAsset *asset,NSUInteger index,BOOL *stop) { if (asset) { dic = [[NSMutableDictionary alloc] init]; ALAssetRepresentation *defaultRepresentation = [asset defaultRepresentation]; Nsstring *uti = [defaultRepresentation UTI]; appDelegate.videoURL = [[asset valueForProperty:ALAssetPropertyURLs] valueForKey:uti]; mpVideoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:appDelegate.videoURL]; Nsstring *title = [Nsstring stringWithFormat:@"%@ %i",NSLocalizedString(@"Video",nil),[assetItems count]+1]; [self performSelector:@selector(imageFromVideoURL)]; [dic setValue:title forKey:kName]; [dic setValue:appDelegate.videoURL forKey:kURL]; AssetbrowserItem *item = [[AssetbrowserItem alloc] initWithURL:appDelegate.videoURL title:title]; [assetItems addobject:item]; [appDelegate.videoURLArray addobject:dic]; NSLog(@"Video has info:%@",appDelegate.videoURLArray); } NSLog(@"Values of dictonary==>%@",dic); //NSLog(@"assetItems:%@",assetItems); NSLog(@"Videos Are:%@",appDelegate.videoURLArray); } ]; } // group == nil signals we are done iterating. else { dispatch_async(dispatch_get_main_queue(),^{ //[self updatebrowserItemsAndSignalDelegate:assetItems]; loadImgView.hidden = NO; [spinner stopAnimating]; [loadImgView removeFromSuperview]; //selectVideoBtn .userInteractionEnabled = YES; }); } } failureBlock:^(NSError *error) { NSLog(@"error enumerating AssetLibrary groups %@\n",error); }]; } - (UIImage *)imageFromVideoURL { // result UIImage *image = nil; // AVAssetimageGenerator AVAsset *asset = [[AVURLAsset alloc] initWithURL:appDelegate.videoURL options:nil];; AVAssetimageGenerator *imageGenerator = [[AVAssetimageGenerator alloc] initWithAsset:asset]; imageGenerator.appliesPreferredTrackTransform = YES; // calc midpoint time of video Float64 durationSeconds = CMTimeGetSeconds([asset duration]); CMTime midpoint = CMTimeMakeWithSeconds(durationSeconds/2.0,600); // get the image from NSError *error = nil; CMTime actualTime; CGImageRef halfWayImage = [imageGenerator copyCGImageAtTime:midpoint actualTime:&actualTime error:&error]; if (halfWayImage != NULL) { // cgimage to uiimage image = [[UIImage alloc] initWithCGImage:halfWayImage]; [dic setValue:image forKey:kImage]; NSLog(@"Values of dictonary==>%@",dic); NSLog(@"Videos Are:%@",appDelegate.videoURLArray); CGImageRelease(halfWayImage); } return image; } - (void)AssetsLibraryDidChange:(NSNotification*)changeNotification { [self updateAssetsLibrary]; } - (void)buildAssetsLibrary { AssetsLibrary = [[ALAssetsLibrary alloc] init]; ALAssetsLibrary *notificationSender = nil; Nsstring *minimumSystemVersion = @"4.1"; Nsstring *systemVersion = [[UIDevice currentDevice] systemVersion]; if ([systemVersion compare:minimumSystemVersion options:NSNumericSearch] != NSOrderedAscending) notificationSender = AssetsLibrary; [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(AssetsLibraryDidChange:) name:ALAssetsLibraryChangednotification object:notificationSender]; [self updateAssetsLibrary]; }
此代码将为您提供iPhone的视频列表.
它可能会帮助你感谢:)
linux – 如何获取Yocto中所有可用目标的列表?
我需要向目标fs和工具链添加包.
目前我只是想添加已有配方的包.
例如,通过添加IMAGE_INSTALL =“boost-dev”和TOOLCHAIN_TARGET_TASK =“boost-dev”,我可以为targetfs和工具链添加提升.
我想做的事
Yocto构建的rootfs非常完整,并且有很多库,但工具链只有最基本的库.
我想将缺少的库添加到工具链中.
题:
如何找到可用库的名称?
像boost-dev一样,我做了很多谷歌搜索,通过添加名称boost-dev到TOOLCHAIN_TARGET_TASK,我可以得到我想要的东西.
但是像OpenGL和OpenCL这样的东西,即使我知道它们是由/ Meta-fsl-arm / recipes-graphics / imx-gpu-viv提供的,我怎么能找到我要添加到TOOLCHAIN_TARGET_TASK的包名?
解决方法
通过执行bitbake -g <packagename> -u depexp
,显示了包之间的依赖关系,Yocto构建中涉及的所有包的名称也是如此.
例如,devil包依赖于devil-dev,因此在Meta-toolchain%.bbappend中执行TOOLCHAIN_TARGET_TASK =“devil-dev”会将恶魔添加到工具链中.
以这种方式找到的包名称可能不完整,具体而言,父包中包含的一些子包可能不会在此处显示.
发生这种情况时,首先找到可能包含子包的父包,然后找到它的.bb文件和.inc文件.
在这些文件中,可能有一个PACKAGES变量,用于说明此包提供的子包.然后可以将这些子包添加到TOOLCHAIN_TARGET_TASK.
php – 如何获取laravel中所有服务器会话的列表?
我想知道有多少用户在线,所以我想我可能会计算所有服务器会话.
谁知道我怎么能这样做?
注意:我正在使用’driver’=> ‘file’,在会话配置中.
配置会话的确切方法因您使用的DB类型而异,以下是使用数据库设置会话的指南:http://laravel.com/docs/session/config#database
今天关于如何获取Python当前模块中所有类的列表?和python获取模块下所有对象的分享就到这里,希望大家有所收获,若想了解更多关于c# – 如何获取文档中所有内容控件的列表?、ios – 如何获取iPhone中所有视频文件的列表、linux – 如何获取Yocto中所有可用目标的列表?、php – 如何获取laravel中所有服务器会话的列表?等相关知识,可以在本站进行查询。
本文标签: