Basically, I have a lot of Python classes (representing our database schema) that look something like this:
from foo import xyz, b, c
class bar(object):
x = xyz()
y = b()
z = c()
...and I want to change it to this:
from foo import b, c
from baz import foobar
class bar(object):
x = foobar()
y = b()
z = c()
Essentially, I just want to replace all instances of xyz
with foobar
. It's acceptable to me to leave the import of a in, so this would also be fine:
from foo import a, b, c
from baz import foobar
class bar(object):
x = foobar()
y = b()
z = c()
It seems trivial to do a sed s/xyz/foobar/
on this, but then I'd still have to go back and change the import statements. I'm fine with doing some manual work, but I'd like to learn new ways to minimize the amount of it.
So how would you do this change? Is there anything I can do with sed to do this? Or rope (I don't see anything obvious that would help me here)?