python字符串类在源代码中的位置 [英] Location of python string class in the source code
问题描述
我正在考虑为特定字符串重载 +
运算符,因此我考虑将字符串类子类化,然后将代码添加到新类中。但是我想先看一下标准的字符串类,但是似乎找不到...愚蠢的吗?
I'm looking into overloading the +
operator for a certain string so I was thinking of subclassing the string class then adding the code in the new class. However I wanted to take a look at the standard string class first but I can't seem to find it... stupid eh?
有人可以指出路吗?甚至是源代码的在线文档。
Can anyone point the way? Even online documentation of the source code.
推荐答案
此处。主要实现在 Objects / stringobject.c
。不过,子类化 str
可能不是您想要的。我倾向于这里的构图。有一个带有字符串字段的对象,并且具有特殊的行为。
It's documented here. The main implementation is in Objects/stringobject.c
. Subclassing str
probably isn't what you want, though. I would tend to prefer composition here; have an object with a string field, and special behavior.
这篇关于python字符串类在源代码中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!