【发布时间】:2022-07-04 19:25:30
【问题描述】:
给定一个文件夹 myproj 和一个文件 myclass.py
myproj
-- __init__.py
-- myclass.py
其中myclass.py 包含以下类定义
class MyClass:
pass
我想用rope 将课程从MyClass 重命名为MyClass2。
如果我知道类名的偏移量是6,那么我可以重命名类如下
import rope.base.project
import rope.refactor.rename
proj = rope.base.project.Project('myproj')
res = proj.get_module('myclass').get_resource()
change = rope.refactor.rename.Rename(proj, res, 6).get_changes('MyClass2')
print(change.get_description())
问题:如何只知道类名称MyClass(但不知道MyClass 的偏移量)用rope 重命名一个类?
编辑:
这是一种方法
offset = res.read().index('MyClass')
【问题讨论】:
标签: python refactoring rename offset rope