我不知道这是 IronPython 问题、Revit API 程序集问题还是其他问题。任何有关可能导致这种情况的信息/想法表示赞赏。
我知道这可以通过再次重新导入相同的命名空间来解决,但我很想知道为什么会这样。
下面是正在发生的事情的简短示例。图像显示 RevitPythonShell 控制台输出。
import clr
clr.AddReference('RevitAPI') # Contains Imports Autodesk.Revit.DB
from Autodesk.Revit import DB # OK
DB.Element.Name # OK
DB.Element.Name.GetValue() # OK: Method exists. As Expected
Run Code Online (Sandbox Code Playgroud)
from File1 import DB
DB.Element.Name # OK, Property Exists
DB.Element.Name.GetValue() # *** Method DOES NOT Exist, Attribute Error is raised
from Autodesk.Revit import DB # Re-import the same namespace again
DB.Element.Name.GetValue() # OK: Method Exists
Run Code Online (Sandbox Code Playgroud)
我查看了一些与使用带有描述符的打字相关的 SO 帖子和 github 问题,但我无法解决我的问题。
我有包装类,我想将属性定义为可以获取和“转换”内部数据结构的属性的描述。
class DataDescriptor(object):
def __init__(self, name: str, type_):
self.name = name
self.type_ = type_
def __get__(self, instance, cls):
if not instance:
raise AttributeError("this descriptor is for instances only")
value = getattr(instance._data, self.name)
return self.type_(value)
class City(object):
zip_code: str = DataDescriptor("zip_code", str)
# mypy: Incompatible types in assignment
population: float = DataDescriptor("population", float)
# mypy: Incompatible types in assignment
def __init__(self, data):
self._data = data
class InternalData:
# Will be consumed through city wrapper
def __init__(self): …
Run Code Online (Sandbox Code Playgroud) 我使用这个问题在 Django 应用程序中的 mysql 数据库上启用全文搜索。
# models.py
class CaseSnapshot(BaseModel):
text = models.TextField(blank=True)
class Search(models.Lookup):
lookup_name = "search"
def as_mysql(self, compiler, connection):
lhs, lhs_params = self.process_lhs(compiler, connection)
rhs, rhs_params = self.process_rhs(compiler, connection)
params = lhs_params + rhs_params
return f"MATCH (%s) AGAINST (%s IN BOOLEAN MODE)" % (lhs, rhs), params
models.TextField.register_lookup(Search)
Run Code Online (Sandbox Code Playgroud)
因为Django不支持mysql上的全文搜索,所以我们必须添加我们的索引,所以我们修改生成的迁移文件:
# Generated by Django 2.2 on 2020-04-28 03:41
from django.db import migrations, models
# Table details
table_name = "by_api_casesnapshot"
field_name = "text"
index_name = f"{table_name}_{field_name}_index"
class Migration(migrations.Migration):
dependencies …
Run Code Online (Sandbox Code Playgroud) 任何想法为什么 sphinx 不创建交叉引用链接?
我已经尝试了所有可能的组合来尝试获得工作链接,但没有运气。我试过napoleon_google_docstring
打开和关闭。
其他自动创建的引用工作正常。