init

flatMap and `Ambiguous reference to member` error

断了今生、忘了曾经 提交于 2019-12-24 10:24:12
问题 Consider the following code: typealias PersonRecord = [String : AnyObject] struct Person { let name: String let age: Int public init(name: String, age: Int) { self.name = name self.age = age } } extension Person { init?(record : PersonRecord) { guard let name = record["name"] as? String, let age = record["age"] as? Int else { return nil } self.name = name self.age = age } } Now I want to create an array of Person s from an array of Record s: let records = // load file from bundle let persons

Python2 and Python3: __init__ and __new__

…衆ロ難τιáo~ 提交于 2019-12-24 03:47:15
问题 I have read other questions which explain the difference between __init__ and __new__ but I just do not understand why in the following code with python 2 out: init and Python3: new init The sample code: class ExampleClass(): def __new__(cls): print ("new") return super().__new__(cls) def __init__(self): print ("init") example = ExampleClass() 回答1: To use __new__ in Python 2.x, the class should be new-style class (class derived from object ). And call to super() is different from that of

Howto disable the emacs site-start files permanently?

与世无争的帅哥 提交于 2019-12-23 21:26:35
问题 When solving this problem I figured out that I need to disable the site-wise init files in order to get my emacs + CEDET running (everything works nicely when starting emacs using emacs --no-site-file but is broken without the additional argument). I'd like to disable the site-wise init files permanently but as I'm using several different approaches/methods when launching emacs (launcher/panel/terminal) I don't think aliasing it in my .zshrc won't work. I require a method to permanently

Custom init method in Objective-C, how to avoid recursion?

[亡魂溺海] 提交于 2019-12-23 20:11:46
问题 I want to create a subclass of UINavigationController which always starts with the same root controller. Nothing special, so (to me) it makes perfect sense to override the init method like this: - (id) init { rootController = [[MyController alloc] init]; if (self = [super initWithRootViewController:rootController]) { // do some more initialization } return self; } This obviously creates a problem, because [super initWithRootViewController] will call [UINavigationController init], which is of

What Is -[NSURL _fastCharacterContents]:?

梦想的初衷 提交于 2019-12-23 17:24:31
问题 So I'm calling this in a method: -(id)initWithContentURL:(NSString *)url { if (self = [super init]) { NSLog(@"xSheetMusicViewController - %@",url); // Casting an NSString object pointer to a CFStringRef: CFStringRef cfString = (CFStringRef)url; CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cfString, NULL, NULL); pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL); } return self; } Which crashes right at the NSLog at the line marked: CFURLRef pdfURL =

Debug init on Qemu using gdb

假装没事ソ 提交于 2019-12-23 13:12:48
问题 i am trying to emulate cavium octeon's mips64 linux kernel on Qemu.I am currently having some issues with use mode init code and want to debug init.i am starting the Qemu using -s -S option in the command line and running the gdb using command ddd --debugger /OCTEON-SDK/tools/bin/mips64-octeon-linux-gnu-gdb /OCTEON-SDK/linux/kernel_2.6/linux/vmlinux and then attaching the gdb with command target remote localhost:1234 The gdb is currently showing only the instructions running in kernel space.

Python initialization

浪子不回头ぞ 提交于 2019-12-23 09:49:56
问题 I have this code: def __init__(self, a, b, c, d...): self.a = a self.b = b etc I'm thinking of replacing it with: def __init__(self, a, b, c, d...): args=locals() for key in args: self.__dict__[key] = args[key] Is this a bad idea? Are there any better ways to do this? 回答1: Building on @ThiefMaster's comment about **kwargs : If you are taking in 20 arguments, it might make more sense to require your users to send arguments via keyword instead of position: with 20 arguments, there is a decent

What is the purpose of calling __init__ directly?

核能气质少年 提交于 2019-12-23 09:32:20
问题 I am having a hard time figuring out the purpose some code that I've come across. The code has a class Foo , which has an __init__ method that takes multiple arguments. From what I've learned of Python so far, by calling Foo('bar') , it will pass this string as a parameter to __init__ (which I think is supposed to be the equivalent of a constructor). But the issue I am having is that the code I am looking at is calling Foo.__init__('bar') directly. What is the purpose of this? I almost feel

How to create a custom UIView?

跟風遠走 提交于 2019-12-23 04:26:15
问题 I've created a UIView subclass and corresponding xib file where I've laid out some UILabels and UIImageViews. I want to then put multiple copies of this custom UIView into a UIViewController. When I do that they appear blank in interface builder and don't appear when the app loads. What methods do I need to implement on the UIView subclass to make this work? 回答1: The easiest method by far is to create a nib with File's Owner set to NSObject, containing one view containing your layout element.

Blender Python `bpy` `__init__.py`, apparently importing from a non-existent module `_bpy`

六月ゝ 毕业季﹏ 提交于 2019-12-23 02:25:10
问题 I'm using Mac OS X with PyCharm and Python 3.5.1 and Blender 2.77. I'm using Blender with Python scripts. I understand that in order to run Python scripts that use Blender (i.e. that imports bpy ), I need to run it from command line using blender -b -P /path/to/my_python_script.py (although I don't really know why). That's all fine and it works, but I wish I could just run it from inside Python, because I use these scripts with other non-Blender Python code and I like to use PyCharm to debug