Where is the implementation of the str.casefold() method in the python source code?
I searched for the string "casefold" in the github repository cpython. I found a test but not the definition of the method.
https://docs.python.org/3/library/stdtypes.html#str.casefold
https://github.com/python/cpython
https://github.com/python/cpython/blob/83d544b9292870eb44f6fca37df0aa351c4ef83a/Lib/test/test_unicode.py#L829
The casefold dispatcher is implemented there, you can just look up the functions it dispatches to.
https://github.com/python/cpython/blob/f4c03484da59049eb62a9bf7777b963e2267d187/Objects/unicodeobject.c#L10967
Related
It's easy to find implementation of any library module in python (you just go to CPython repository on Github: https://github.com/python/cpython/), but where could I find implementations of build-in CPython types? It's important for example to prove that complex build-in type is inherited from numbers.Complex abc. Or it is also could be useful to explore attributes of function type.
I wanted to see how a math.py function was implemented, but when I opened the file in PyCharm I found that all the functions are empty and there is a simple pass. For example:
def ceil(x): # real signature unknown; restored from __doc__
"""
ceil(x)
Return the ceiling of x as a float.
This is the smallest integral value >= x.
"""
pass
I guess it is because the functions being used are actually from the C standard library. How does it work?
PyCharm is lying to you. The source code you're looking at is a fake that PyCharm has created. PyCharm knows what functions should be there, and it can guess at their signatures using the function docstrings, but it has no idea what the function bodies should look like.
If you want to see the real source code, you can look at it in the official Github repository in Modules/mathmodule.c. A lot of the functions in there are macro-generated thin wrappers around C functions from math.h, but there's also a bunch of manually-written code to handle things like inconsistent or insufficient standard library implementations, functions with no math.h equivalent, and customization hooks like __ceil__.
There are no source code written in python for some python libraries.
These libraries was written on C or another languages. They are not presented by .py files and PyCharm or any another IDE cannot open their sources in readable view.
You can check sources in ...\AppData\Local\Programs\Python\Python310\Lib\site-packages. Most likely in your-package folder there will be .pui, .pud, .dll and other similiar files
I want to automatically add sphinx comment under head functions and classes.
When I press Enter after head function or class, comment could be implemented like this:
def func(a): #<Enter>
"""
Args:
a (type): The name to use.
Returns:
type. The return
"""
Is it possible to configure .vimrc (.vimrc.local)? Do you know command for this? Or may be plugin?
Though you can do this with the built-in (insert-mode) mappings, you'll soon want to do more advanced insertions.
snippets are like the built-in :abbreviate on steroids, usually with parameter insertions, mirroring, and multiple stops inside them. One of the first, very famous (and still widely used) Vim plugins is snipMate (inspired by the TextMate editor); unfortunately, it's not maintained any more; though there is a fork. A modern alternative (that requires Python though) is UltiSnips. There are more, see this list on the Vim Tips Wiki.
There are two things to evaluate: First, the features of the snippet engine itself, and second, the quality and breadth of snippets provided by the author or others.
I am trying to use the rubypython gem. Not sure how to call standard python functions like len and set. In the python examples I see len(text3) and set(text3).
How do I call these in rubypython?
Here is the link to rubypython: http://rubypython.rubyforge.org/
Well, my Ruby knowledge is limited, and my knowledge of the rubypython gem is non-existent. However, I do know the standard functions you refer to a part of the __builtin__ module, which is automatically imported into the python namespace. Fortunately, there's nothing preventing you from importing it explicitly again (which is perfectly safe in Python). You then might be able do something like __builtin__.set(). No guarantees, though.
RubyPython::PyMainClass has a public instance method builtin()
You can use that to call the standard functions.
I couldn't find a documentation about this function...
I specifically want to know what the parameters are and what do the parameters exactly represent...
using python 3
The convention in Python is to use a single leading _ for non-public methods and instance variables. So, _siftdown is not intended to be called externally and, thus, is not documented in the standard library documentation. If you want to examine how it works, look at the code. Note that the latest Python 3.2 documentation now includes links to the source code; see the link near the top of the page here.