built-in

How can I see Python's __builtins__ source code?

青春壹個敷衍的年華 提交于 2020-02-04 01:24:43
问题 Can I get python to print the source code for __builtins__ directly? OR (more preferably): What is the pathname of the source code for __builtins__ ? I at least know the following things: __builtins__ is a module, by typing type(__builtins__) . I have tried the best-answer-suggestions to a more general case of this SO question: "Finding the source code for built-in Python functions?". But no luck: print inspect.getdoc(__builtins__) just gives me a description. inspect.getfile(__builtins__)

How can I see Python's __builtins__ source code?

ε祈祈猫儿з 提交于 2020-02-04 01:24:23
问题 Can I get python to print the source code for __builtins__ directly? OR (more preferably): What is the pathname of the source code for __builtins__ ? I at least know the following things: __builtins__ is a module, by typing type(__builtins__) . I have tried the best-answer-suggestions to a more general case of this SO question: "Finding the source code for built-in Python functions?". But no luck: print inspect.getdoc(__builtins__) just gives me a description. inspect.getfile(__builtins__)

Consequences of shadowing built-in types/functions

喜你入骨 提交于 2020-02-02 05:28:47
问题 I'm wondering what could be some consequences of reusing the names of built-in types or functions. To illustrate what I mean, read the following example: list() is a built-in function. If I create another list() method I suppose it will override the original one so that the mine will be executed instead of the built-in one. But what happen if i do list=[a,z,e,r,t,y] ? Is there a risk for the built-in list type or list() function? I know it's not good to do such a thing. But my goal is only to

Consequences of shadowing built-in types/functions

泄露秘密 提交于 2020-02-02 05:28:08
问题 I'm wondering what could be some consequences of reusing the names of built-in types or functions. To illustrate what I mean, read the following example: list() is a built-in function. If I create another list() method I suppose it will override the original one so that the mine will be executed instead of the built-in one. But what happen if i do list=[a,z,e,r,t,y] ? Is there a risk for the built-in list type or list() function? I know it's not good to do such a thing. But my goal is only to

Python 2's `exceptions` module is missing in Python3, where did its contents go?

帅比萌擦擦* 提交于 2020-01-24 02:52:18
问题 A friend mentioned that with Python 2, (assuming you have it on your path environment variable, on the commandline) $ pydoc exceptions is very useful and knowing it should save him a few minutes of web lookup time a week. I Google the exceptions hierarchy about once a week myself, so this was a helpful reminder for me as well. It is the same documentation that you get with >>> import exceptions >>> help(exceptions) in Python 2, because pydoc uses the exceptions module to provide the online

Subclass builtin List

ε祈祈猫儿з 提交于 2020-01-22 17:28:05
问题 I want to subclass the list type and have slicing return an object of the descendant type, however it is returning a list . What is the minimum code way to do this? If there isn't a neat way to do it, I'll just include a list internally which is slightly more messy, but not unreasonable. My code so far: class Channel(list): sample_rate = 0 def __init__(self, sample_rate, label=u"", data=[]): list.__init__(self,data) self.sample_rate = sample_rate self.label = label @property def nyquist_rate

Built-in functions in c++

﹥>﹥吖頭↗ 提交于 2020-01-13 11:40:25
问题 I was browsing through some codes at the end of the contest and found out that many people were using functions like __gcd(int,int) . What are these functions ? Similar functions include __builtin_popcount(int) __builtin_ctz(int) __builtin_clz(int) Where can I study about these functions ? Googling it didn't help much. 回答1: Those are all GCC specifics. you can read about them here: http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html#C-Extensions - but be aware, they're NOT C/C++ Standards. 来源

How to wrap an already existing function with a new function of the same name

ⅰ亾dé卋堺 提交于 2020-01-09 07:49:11
问题 Is it possible to create a wrapper around a function that has the exact same name as the original function? This would be very useful in circumstances where the user wants to do some additional checks on input variables before they are passed on to the built in function How to interrupt MATLAB IDE when it hangs on displaying very large array? 回答1: Actually alternatively to slayton's answer you don't need to use openvar . If you define a function with the same name as a matlab function, it

What is the purpose of the : (colon) GNU Bash builtin?

一世执手 提交于 2020-01-08 09:30:09
问题 What is the purpose of a command that does nothing, being little more than a comment leader, but is actually a shell builtin in and of itself? It's slower than inserting a comment into your scripts by about 40% per call, which probably varies greatly depending on the size of the comment. The only possible reasons I can see for it are these: # poor man's delay function for ((x=0;x<100000;++x)) ; do : ; done # inserting comments into string of commands command ; command ; : we need a comment in

What is the purpose of the : (colon) GNU Bash builtin?

你。 提交于 2020-01-08 09:29:08
问题 What is the purpose of a command that does nothing, being little more than a comment leader, but is actually a shell builtin in and of itself? It's slower than inserting a comment into your scripts by about 40% per call, which probably varies greatly depending on the size of the comment. The only possible reasons I can see for it are these: # poor man's delay function for ((x=0;x<100000;++x)) ; do : ; done # inserting comments into string of commands command ; command ; : we need a comment in