built-in

How to use a custom function in max(x, key=custom_function) function?

喜欢而已 提交于 2019-12-08 06:43:13
问题 I have a custom data type, say: mytime , which represent hours and minutes, such as 29:45, it is 29 hours and 45 minutes. I want to use max built-in function to find the item in a list of lists, whose sum of its elements is the greatest, where all lists contain values of mytime type. x = [[a, b], [c, d]] a,b,c,d are of mytime type. max(x, key=sum) won't work here, because a,b,c,d, are not integers. If I type a + b at python command line, I get the sum of these two time values, result is of

How to disable Excel built-in RibbonButton?

99封情书 提交于 2019-12-07 15:24:18
问题 Is it possible to set an excel 2010 built in RibbonButton to enabled=false from an excel VSTO Add-In? I tried the following: CommandBarControls controlls=Globals.ThisAddIn.Application.CommandBars.FindControls(MsoControlType.msoControlButton, 7374, null, false); /// 7374 is the office control id of the control I want to access foreach (CommandBarControl control in controlls) { control.Enabled = false; } But this seems to work only for the right click context menu. And not for the ribbon

Are built-in intrinsic functions available in Swift 3?

喜欢而已 提交于 2019-12-07 11:19:40
问题 I can see various built-in functions (like __builtin_popount, __builtin_clz, etc) in the Xcode auto-completion pop-up. I'm not sure where these are getting picked up from though. Command clicking doesn't lead to a swift definition or any documentation. Are any __builtin_* or equivalent intrinsic functions available in Swift 3 and if so, what modules do I need to include and how can I call them? 来源: https://stackoverflow.com/questions/41353482/are-built-in-intrinsic-functions-available-in

Replace Pythons builtin type with custom one

不羁的心 提交于 2019-12-07 11:06:58
问题 Is it possible to replace some built-in python types with custom ones? I want to create something like: class MyInt(object): ... __builtin__.int = MyInt x = 5 回答1: Since you want to write a Pythonesque DSL, you have two options: Compile the code to an AST and walk the AST replacing nodes as appropriate. Build your own AST by hand. Once you have the AST you can go ahead and execute it directly. In either case, look at Python's Language Services for generation and manipulation of the AST. 回答2:

Failing to subclass builtin String object

喜你入骨 提交于 2019-12-07 07:13:09
问题 I've been experimenting with subclassing the built-in String object in ES2015 using Node 5.3.0. I'm running the code untranspiled using a bunch of harmony flags. Here's the full command: node --harmony --harmony_modules --harmony_destructuring --harmony_rest_parameters --harmony_arrow_functions --harmony_spreadcalls --harmony_object --harmony_default_parameters --harmony_new_target --harmony_reflect --harmony_modules ~/t.js Given that the spec specifically says the String object is made to be

How to shadow python builtin pwd module

可紊 提交于 2019-12-07 05:40:54
问题 There is some python code that works under Linux. It uses the pwd module in a way like that: import pwd ... def func(): user=pwd.getpwnam(user)[2] Now we have a specific need to cover this code with tests, and tests have to be runnable under Windows. The program itself is intended to run only under Linux. The problem is that pwd module is not available under Windows, so the code under test will fail with ImportError, even if the implementation of pwd functions is mocked using MagicMock. The

“delete” - restore native function not working for changed prototype, how then?

喜你入骨 提交于 2019-12-07 05:39:35
问题 if you change native function like this: window.open= function (a,b,c) { alert(2); } then later you can just delete window.open and it would restore original function, BUT: if you change its prototype like this: window.__proto__.open= function (a,b,c) { alert(3); } then delete won't do anything =\ any ideas how to restore it now? 回答1: When you change window.open to something else, e.g. using window.open = 'something else'; , then you're shadowing the open method from the prototype; // Looking

Does android have a built-in PDF viewer?

拥有回忆 提交于 2019-12-07 04:15:52
问题 I heard something recently about it being included in Froyo and I was wondering if there was any truth to it. If there is, it would help me with an app idea greatly. 回答1: You are probably referring to the Adobe Reader, which is freely available for Android 2.1+. Some devices also have other applications pre-installed for rendering pdf files. See this question on how you can open the default pdf viewer from your application. 回答2: Android has a built in framework from Android 5.0 / Lollipop, it

“Assume” clause in gcc

霸气de小男生 提交于 2019-12-06 19:33:16
问题 Does gcc (latest versions: 4.8, 4.9) have an "assume" clause similar to __assume() built-in supported by icc? E.g., __assume( n % 8 == 0 ); 回答1: In your example you want to inform the compiler that N is a multiple of 8. You can do this simply by inserting the line N = N & 0xFFFFFFF8; in your code (if N is a 32-bit integer). This doesn't change N , because N is a multiple of 8, but since GCC 4.9 the compiler seems to understand that N is a multiple of 8, after this line. This is shown by the

Remove all occurrences of several chars from a string

北城以北 提交于 2019-12-06 17:25:38
问题 Is there a pythonic way to do what the str.strip() method does, except for all occurrences, not just those at the beginning and end of a string? Example: >> '::2012-05-14 18:10:20.856000::'.strip(' -.:') >> '2012-05-14 18:10:20.856000' I want >> '::2012-05-14 18:10:20.856000::'.crazy_function(' -.:') >> '20120514181020856000' Does Python provides me a built-in crazy_function ??? I could easily do it programatically, but I want to know if there is a built-in for that. Couldn't find one. Thank