Re: Changing functions in a running program?
Wes Turner <[email protected]> Sat, 12 Jan 2019 21:42:18 -0500
| Newsgroups | gmane.comp.python.ipython.devel |
|---|---|
| Message-ID | <CACfEFw9X4dkWYh+TmH9FHfPOBQdnGAGCogOtOBR9=39EuAsOmg@mail.gmail.com> |
--===============7344567172977027935==
Content-Type: multipart/alternative; boundary="0000000000002e5773057f4de1a2"
--0000000000002e5773057f4de1a2
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
In searching for a solution, I found your question here:
https://stackoverflow.com/questions/54153888/how-to-update-nested-functions=
-in-ipdb
It's funny, I've been coding in Python for very many years and I've never
encountered this need.
With TDD, you basically never do this: you write a different function and
test that;
if it needs to be parametrized ("dependency injection"),
you just pass a function reference as an argument.
(If the code is designed to be changed at runtime (polymorphic),
that should be part of the callable parameter spec.)
But that doesn't help with this simple example
(or probably the code you're actually working with).
IIUC, this is ocurring because
print_name in the main() function is already bound to the previous instance=
.
in order to change that reference,
we need to update __self__/__module__.print_name.
Maybe coincidentally I also have no idea how to do this without importing
inspect?
If it was a class method, a simple assignment would accomplish your
objective.
This works:
ipdb> !import inspect; inspect.currentframe().f_globals['print_name'] =3D
lambda: print("Bob")
But there may be a simpler solution?
On Sat, Jan 12, 2019 at 8:57 PM Andreas Yankopolus <[email protected]> wrote:
> Wes,
>
>
> https://stackoverflow.com/questions/48112226/update-a-function-during-deb=
ugging-pdb-or-ipdb
> - Does this work from just a plain ipdb shell (when not sending the
> new function definition from emacs)?
>
>
> This is getting close, but updating the function as proposed doesn=E2=80=
=99t work.
> Using the example code from my previous post:
>
> *ayank@snorri*:*~/Documents*$ ./foo.py
> In main.
> > /home/ayank/Documents/foo.py(16)main()
> 14 print ("In main.")
> 15 Pdb().set_trace()
> ---> 16 name()
> 17
> 18 if __name__ =3D=3D "__main__":
>
> ipdb> print_name()
> Alice
> ipdb> name()
> Alice
> ipdb> !def print_name(): print ("Bob")
> ipdb> print_name()
> Bob
> ipdb> name()
> Alice
>
> We can see that the function is updated, but functions that call it do no=
t
> get updated to use the new definition. Any idea what=E2=80=99s going on h=
ere?
>
> This kind of thing is no problem in Lisp, but its macro facility means
> that support for changing code at runtime is baked deep into the language=
.
> Perhaps there=E2=80=99s something missed in the IPython REPL?
>
> Thanks,
>
> Andreas
>
>
>
On Sat, Jan 12, 2019 at 8:37 PM Wes Turner <[email protected]> wrote:
> https://en.wikipedia.org/wiki/Monkey_patch#Pitfalls
>
> https://pypi.org/search/?q=3Dmonkeypatch
>
>
> https://docs.pytest.org/en/latest/monkeypatch.html#monkeypatching-mocking=
-modules-and-environments
>
>
> https://stackoverflow.com/questions/48112226/update-a-function-during-deb=
ugging-pdb-or-ipdb
> - Does this work from just a plain ipdb shell (when not sending the new
> function definition from emacs)?
>
>
> On Sat, Jan 12, 2019 at 6:11 PM Andreas Yankopolus <[email protected]>
> wrote:
>
>> Is it possible to run a program to a breakpoint in IPython and then
>> change functions within that program? This would be for interactively
>> experimenting with program logic without having to restart the program f=
rom
>> scratch. I=E2=80=99m running IPython3 from Emacs using Elpy for interact=
ing with
>> the IPython3 process.
>>
>> Consider foo.py as follows:
>>
>> #!/usr/bin/env ipython3
>>
>> import sys
>> from IPython.core.debugger import Pdb
>>
>>
>> def print_name():
>> print ("Alice")
>>
>> def name():
>> print_name()
>>
>> def main(argv):
>> print ("In main.")
>> Pdb().set_trace()
>> name()
>>
>> if __name__ =3D=3D "__main__":
>> main(sys.argv[1:])
>>
>> Running it gives me:
>>
>> *ayank@snorri*:*~/Documents*$ ./foo.py
>> In main.
>> > /home/ayank/Documents/foo.py(16)main()
>> 14 print ("In main.")
>> 15 Pdb().set_trace()
>> ---> 16 name()
>> 17
>> 18 if __name__ =3D=3D "__main__":
>>
>>
>> ipdb>
>>
>> I now want to change the definition of print_name() to print =E2=80=9CBo=
b=E2=80=9D
>> instead of =E2=80=9CAlice=E2=80=9D. I can make this change in Emacs, sen=
d the new function
>> to IPython with C-c C-y f, but when I then type name(), I get =E2=80=9CA=
lice=E2=80=9D.
>> The reference to print_name() in name() is not getting updated to point
>> to the new definition of print_name(). Likely I=E2=80=99m going about th=
is
>> process incorrectly, as I can make these kind of changes at an IPython3
>> prompt but not at an ipdb one.
>>
>> Thanks,
>>
>> Andreas
>> _______________________________________________
>> IPython-dev mailing list
>> [email protected]
>> https://mail.python.org/mailman/listinfo/ipython-dev
>>
>
--0000000000002e5773057f4de1a2
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr">In sear=
ching for a solution, I found your question here:</div><div dir=3D"ltr"><a =
href=3D"https://stackoverflow.com/questions/54153888/how-to-update-nested-f=
unctions-in-ipdb">https://stackoverflow.com/questions/54153888/how-to-updat=
e-nested-functions-in-ipdb</a></div><div dir=3D"ltr"><br></div><div dir=3D"=
ltr">It's funny, I've been coding in Python for very many years and=
I've never encountered this need.</div><div dir=3D"ltr">With TDD, you =
basically never do this: you write a different function and test that;</div=
><div dir=3D"ltr">if it needs to be parametrized ("dependency injectio=
n"),</div><div dir=3D"ltr">you just pass a function reference as an ar=
gument.</div><div dir=3D"ltr">(If the code is designed to be changed at run=
time (polymorphic),</div><div dir=3D"ltr">that should be part of the callab=
le parameter spec.)</div><div dir=3D"ltr"><br></div><div dir=3D"ltr">But th=
at doesn't help with this simple example</div><div dir=3D"ltr">(or prob=
ably the code you're actually working with).</div><div dir=3D"ltr"><br>=
</div><div dir=3D"ltr">IIUC, this is ocurring because</div><div dir=3D"ltr"=
>print_name in the main() function is already bound to the previous instanc=
e.</div><div dir=3D"ltr"><br></div><div dir=3D"ltr">in order to change that=
reference,</div><div dir=3D"ltr">we need to update __self__/__module__.pri=
nt_name.</div><div dir=3D"ltr">Maybe coincidentally I also have no idea how=
to do this without importing inspect?</div><div dir=3D"ltr">If it was a cl=
ass method, a simple assignment would accomplish your objective.</div><div =
dir=3D"ltr"><br></div><div dir=3D"ltr">This works:</div><div dir=3D"ltr"><b=
r></div><div dir=3D"ltr">ipdb> !import inspect; inspect.currentframe().f=
_globals['print_name'] =3D lambda: print("Bob")<br></div>=
<div dir=3D"ltr"><br></div><div dir=3D"ltr">But there may be a simpler solu=
tion?<br></div><div dir=3D"ltr"><br></div><br></div><div dir=3D"ltr">On Sat=
, Jan 12, 2019 at 8:57 PM Andreas Yankopolus <<a href=3D"mailto:andreas@=
yank.to">[email protected]</a>> wrote:<br></div><blockquote class=3D"gmail=
_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204=
,204);padding-left:1ex"><div style=3D"overflow-wrap: break-word;"><div>Wes,=
</div><div><br><blockquote type=3D"cite"><div><div><a href=3D"https://stack=
overflow.com/questions/48112226/update-a-function-during-debugging-pdb-or-i=
pdb" target=3D"_blank">https://stackoverflow.com/questions/48112226/update-=
a-function-during-debugging-pdb-or-ipdb</a><br>- Does this work from just a=
plain ipdb shell (when not sending the new=C2=A0function definition from e=
macs)?<br></div></div></blockquote><div><br></div><div>This is getting clos=
e, but updating the function as proposed doesn=E2=80=99t work. Using the ex=
ample code from my previous post:</div><div><br></div></div><div style=3D"m=
argin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family=
:Menlo;color:rgb(47,180,29)"><span style=3D"font-variant-ligatures:no-commo=
n-ligatures"><b>ayank@snorri</b></span><span style=3D"font-variant-ligature=
s:no-common-ligatures;color:rgb(0,0,0)">:</span><span style=3D"font-variant=
-ligatures:no-common-ligatures;color:rgb(64,11,217)"><b>~/Documents</b></sp=
an><span style=3D"font-variant-ligatures:no-common-ligatures;color:rgb(0,0,=
0)">$ ./foo.py=C2=A0</span></div><div style=3D"margin:0px;font-stretch:norm=
al;font-size:11px;line-height:normal;font-family:Menlo"><span style=3D"font=
-variant-ligatures:no-common-ligatures">In main.</span></div><div style=3D"=
margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-famil=
y:Menlo;color:rgb(47,180,29)"><span style=3D"font-variant-ligatures:no-comm=
on-ligatures;color:rgb(0,0,0)">>=C2=A0</span><span style=3D"font-variant=
-ligatures:no-common-ligatures">/home/ayank/Documents/foo.py</span><span st=
yle=3D"font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(16)</s=
pan><span style=3D"font-variant-ligatures:no-common-ligatures;color:rgb(46,=
174,187)">main</span><span style=3D"font-variant-ligatures:no-common-ligatu=
res;color:rgb(64,11,217)">()</span></div><div style=3D"margin:0px;font-stre=
tch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(64=
,11,217)"><span style=3D"font-variant-ligatures:no-common-ligatures;color:r=
gb(47,180,29)">=C2=A0=C2=A0 =C2=A0 14=C2=A0</span><span style=3D"font-varia=
nt-ligatures:no-common-ligatures;color:rgb(180,36,25)">=C2=A0 =C2=A0=C2=A0<=
/span><span style=3D"font-variant-ligatures:no-common-ligatures;color:rgb(0=
,0,0)">print=C2=A0</span><span style=3D"font-variant-ligatures:no-common-li=
gatures">("In main.")</span></div><div style=3D"margin:0px;font-s=
tretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span st=
yle=3D"font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)">=C2=
=A0=C2=A0 =C2=A0 15=C2=A0</span><span style=3D"font-variant-ligatures:no-co=
mmon-ligatures;color:rgb(180,36,25)">=C2=A0 =C2=A0=C2=A0</span><span style=
=3D"font-variant-ligatures:no-common-ligatures">Pdb</span><span style=3D"fo=
nt-variant-ligatures:no-common-ligatures;color:rgb(64,11,217)">().</span><s=
pan style=3D"font-variant-ligatures:no-common-ligatures">set_trace</span><s=
pan style=3D"font-variant-ligatures:no-common-ligatures;color:rgb(64,11,217=
)">()</span></div><div style=3D"margin:0px;font-stretch:normal;font-size:11=
px;line-height:normal;font-family:Menlo;color:rgb(47,180,29)"><span style=
=3D"font-variant-ligatures:no-common-ligatures">---> 16=C2=A0</span><spa=
n style=3D"font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)"=
>=C2=A0 =C2=A0=C2=A0</span><span style=3D"font-variant-ligatures:no-common-=
ligatures;color:rgb(0,0,0)">name</span><span style=3D"font-variant-ligature=
s:no-common-ligatures;color:rgb(64,11,217)">()</span></div><div style=3D"ma=
rgin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:=
Menlo;color:rgb(47,180,29)"><span style=3D"font-variant-ligatures:no-common=
-ligatures">=C2=A0=C2=A0 =C2=A0 17=C2=A0</span></div><div style=3D"margin:0=
px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;=
color:rgb(64,11,217)"><span style=3D"font-variant-ligatures:no-common-ligat=
ures;color:rgb(47,180,29)">=C2=A0=C2=A0 =C2=A0 18 if</span><span style=3D"f=
ont-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">=C2=A0__name__=
=C2=A0</span><span style=3D"font-variant-ligatures:no-common-ligatures">=3D=
=3D</span><span style=3D"font-variant-ligatures:no-common-ligatures;color:r=
gb(0,0,0)">=C2=A0</span><span style=3D"font-variant-ligatures:no-common-lig=
atures">"__main__":</span></div><div style=3D"margin:0px;font-str=
etch:normal;font-size:11px;line-height:normal;font-family:Menlo;min-height:=
13px"><span style=3D"font-variant-ligatures:no-common-ligatures"></span><br=
></div><div style=3D"margin:0px;font-stretch:normal;font-size:11px;line-hei=
ght:normal;font-family:Menlo">ipdb> print_name()</div><div style=3D"marg=
in:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Me=
nlo"><span style=3D"font-variant-ligatures:no-common-ligatures">Alice</span=
></div><div style=3D"margin:0px;font-stretch:normal;font-size:11px;line-hei=
ght:normal;font-family:Menlo"><span style=3D"font-variant-ligatures:no-comm=
on-ligatures">ipdb> name()</span></div><div style=3D"margin:0px;font-str=
etch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span styl=
e=3D"font-variant-ligatures:no-common-ligatures">Alice</span></div><div sty=
le=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font=
-family:Menlo"><span style=3D"font-variant-ligatures:no-common-ligatures">i=
pdb> !def print_name(): print ("Bob")</span></div><div style=
=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-f=
amily:Menlo">ipdb> print_name()</div><div style=3D"margin:0px;font-stret=
ch:normal;font-size:11px;line-height:normal;font-family:Menlo"><span style=
=3D"font-variant-ligatures:no-common-ligatures">Bob</span></div><div style=
=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-f=
amily:Menlo"><span style=3D"font-variant-ligatures:no-common-ligatures">ipd=
b> name()</span></div><div style=3D"margin:0px;font-stretch:normal;font-=
size:11px;line-height:normal;font-family:Menlo"><span style=3D"font-variant=
-ligatures:no-common-ligatures">Alice</span></div><div style=3D"margin:0px;=
font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><b=
r></div><div style=3D"margin:0px;font-stretch:normal;font-size:11px;line-he=
ight:normal;font-family:Menlo"><div style=3D"font-family:Helvetica;font-siz=
e:12px">We can see that the function is updated, but functions that call it=
do not get updated to use the new definition. Any idea what=E2=80=99s goin=
g on here?</div><div style=3D"font-family:Helvetica;font-size:12px"><br></d=
iv><div style=3D"font-family:Helvetica;font-size:12px">This kind of thing i=
s no problem in Lisp, but its macro facility means that support for changin=
g code at runtime is baked deep into the language. Perhaps there=E2=80=99s =
something missed in the IPython REPL?</div><div style=3D"font-family:Helvet=
ica;font-size:12px"><br></div><div style=3D"font-family:Helvetica;font-size=
:12px">Thanks,</div><div style=3D"font-family:Helvetica;font-size:12px"><br=
></div><div style=3D"font-family:Helvetica;font-size:12px">Andreas</div><di=
v><br></div><br class=3D"gmail-Apple-interchange-newline"></div></div></blo=
ckquote></div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Sat,=
Jan 12, 2019 at 8:37 PM Wes Turner <<a href=3D"mailto:wes.turner@gmail.=
com">[email protected]</a>> wrote:<br></div><blockquote class=3D"gmai=
l_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,20=
4,204);padding-left:1ex"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"=
><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><a href=3D"https://en.w=
ikipedia.org/wiki/Monkey_patch#Pitfalls" target=3D"_blank">https://en.wikip=
edia.org/wiki/Monkey_patch#Pitfalls</a><br></div><div dir=3D"ltr"><br></div=
><div dir=3D"ltr"><a href=3D"https://pypi.org/search/?q=3Dmonkeypatch" targ=
et=3D"_blank">https://pypi.org/search/?q=3Dmonkeypatch</a><br><br><a href=
=3D"https://docs.pytest.org/en/latest/monkeypatch.html#monkeypatching-mocki=
ng-modules-and-environments" target=3D"_blank">https://docs.pytest.org/en/l=
atest/monkeypatch.html#monkeypatching-mocking-modules-and-environments</a><=
br><br><a href=3D"https://stackoverflow.com/questions/48112226/update-a-fun=
ction-during-debugging-pdb-or-ipdb" target=3D"_blank">https://stackoverflow=
.com/questions/48112226/update-a-function-during-debugging-pdb-or-ipdb</a><=
/div><div>- Does this work from just a plain ipdb shell (when not sending t=
he new function definition from emacs)?<br><br></div></div></div></div></di=
v></div><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Sat, Jan 12, 201=
9 at 6:11 PM Andreas Yankopolus <<a href=3D"mailto:[email protected]" targ=
et=3D"_blank">[email protected]</a>> wrote:<br></div><blockquote class=3D"=
gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(20=
4,204,204);padding-left:1ex"><div>Is it possible to run a program to a brea=
kpoint in IPython and then change functions within that program? This would=
be for interactively experimenting with program logic without having to re=
start the program from scratch. I=E2=80=99m running IPython3 from Emacs usi=
ng Elpy for interacting with the IPython3 process.<div><br></div><div>Consi=
der foo.py as follows:</div><div><br></div><div><div style=3D"margin:0px;fo=
nt-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><spa=
n style=3D"font-variant-ligatures:no-common-ligatures">#!/usr/bin/env ipyth=
on3</span></div><div style=3D"margin:0px;font-stretch:normal;font-size:11px=
;line-height:normal;font-family:Menlo;min-height:13px"><span style=3D"font-=
variant-ligatures:no-common-ligatures"></span><br></div><div style=3D"margi=
n:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Men=
lo"><span style=3D"font-variant-ligatures:no-common-ligatures">import sys</=
span></div><div style=3D"margin:0px;font-stretch:normal;font-size:11px;line=
-height:normal;font-family:Menlo"><span style=3D"font-variant-ligatures:no-=
common-ligatures">from IPython.core.debugger import Pdb</span></div><div st=
yle=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:normal;fon=
t-family:Menlo;min-height:13px"><span style=3D"font-variant-ligatures:no-co=
mmon-ligatures"></span><br></div><div style=3D"margin:0px;font-stretch:norm=
al;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><sp=
an style=3D"font-variant-ligatures:no-common-ligatures"></span><br></div><d=
iv style=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:norma=
l;font-family:Menlo"><span style=3D"font-variant-ligatures:no-common-ligatu=
res">def print_name():</span></div><div style=3D"margin:0px;font-stretch:no=
rmal;font-size:11px;line-height:normal;font-family:Menlo"><span style=3D"fo=
nt-variant-ligatures:no-common-ligatures">=C2=A0 =C2=A0 print ("Alice&=
quot;)</span></div><div style=3D"margin:0px;font-stretch:normal;font-size:1=
1px;line-height:normal;font-family:Menlo;min-height:13px"><span style=3D"fo=
nt-variant-ligatures:no-common-ligatures"></span><br></div><div style=3D"ma=
rgin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:=
Menlo"><span style=3D"font-variant-ligatures:no-common-ligatures">def name(=
):</span></div><div style=3D"margin:0px;font-stretch:normal;font-size:11px;=
line-height:normal;font-family:Menlo"><span style=3D"font-variant-ligatures=
:no-common-ligatures">=C2=A0 =C2=A0 print_name()</span></div><div style=3D"=
margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-famil=
y:Menlo;min-height:13px"><span style=3D"font-variant-ligatures:no-common-li=
gatures"></span><br></div><div style=3D"margin:0px;font-stretch:normal;font=
-size:11px;line-height:normal;font-family:Menlo"><span style=3D"font-varian=
t-ligatures:no-common-ligatures">def main(argv):</span></div><div style=3D"=
margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-famil=
y:Menlo"><span style=3D"font-variant-ligatures:no-common-ligatures">=C2=A0 =
=C2=A0 print ("In main.")</span></div><div style=3D"margin:0px;fo=
nt-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo"><spa=
n style=3D"font-variant-ligatures:no-common-ligatures">=C2=A0 =C2=A0 Pdb().=
set_trace()</span></div><div style=3D"margin:0px;font-stretch:normal;font-s=
ize:11px;line-height:normal;font-family:Menlo"><span style=3D"font-variant-=
ligatures:no-common-ligatures">=C2=A0 =C2=A0 name()</span></div><div style=
=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-f=
amily:Menlo;min-height:13px"><span style=3D"font-variant-ligatures:no-commo=
n-ligatures"></span><br></div><div style=3D"margin:0px;font-stretch:normal;=
font-size:11px;line-height:normal;font-family:Menlo"><span style=3D"font-va=
riant-ligatures:no-common-ligatures">if __name__ =3D=3D "__main__"=
;:</span></div><div style=3D"margin:0px;font-stretch:normal;font-size:11px;=
line-height:normal;font-family:Menlo"><span style=3D"font-variant-ligatures=
:no-common-ligatures">=C2=A0 =C2=A0 main(sys.argv[1:])</span></div></div><d=
iv><span style=3D"font-variant-ligatures:no-common-ligatures"><br></span></=
div><div><span style=3D"font-variant-ligatures:no-common-ligatures">Running=
it gives me:</span></div><div><span style=3D"font-variant-ligatures:no-com=
mon-ligatures"><br></span></div><div><span style=3D"font-variant-ligatures:=
no-common-ligatures"><div style=3D"margin:0px;font-stretch:normal;font-size=
:11px;line-height:normal;font-family:Menlo;color:rgb(47,180,29)"><span styl=
e=3D"font-variant-ligatures:no-common-ligatures"><b>ayank@snorri</b></span>=
<span style=3D"font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"=
>:</span><span style=3D"font-variant-ligatures:no-common-ligatures;color:rg=
b(64,11,217)"><b>~/Documents</b></span><span style=3D"font-variant-ligature=
s:no-common-ligatures;color:rgb(0,0,0)">$ ./foo.py=C2=A0</span></div><div s=
tyle=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:normal;fo=
nt-family:Menlo"><span style=3D"font-variant-ligatures:no-common-ligatures"=
>In main.</span></div><div style=3D"margin:0px;font-stretch:normal;font-siz=
e:11px;line-height:normal;font-family:Menlo;color:rgb(47,180,29)"><span sty=
le=3D"font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">> </s=
pan><span style=3D"font-variant-ligatures:no-common-ligatures">/home/ayank/=
Documents/foo.py</span><span style=3D"font-variant-ligatures:no-common-liga=
tures;color:rgb(0,0,0)">(16)</span><span style=3D"font-variant-ligatures:no=
-common-ligatures;color:rgb(46,174,187)">main</span><span style=3D"font-var=
iant-ligatures:no-common-ligatures;color:rgb(64,11,217)">()</span></div><di=
v style=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:normal=
;font-family:Menlo;color:rgb(64,11,217)"><span style=3D"font-variant-ligatu=
res:no-common-ligatures;color:rgb(47,180,29)">=C2=A0=C2=A0 =C2=A0 14 </span=
><span style=3D"font-variant-ligatures:no-common-ligatures;color:rgb(180,36=
,25)">=C2=A0 =C2=A0 </span><span style=3D"font-variant-ligatures:no-common-=
ligatures;color:rgb(0,0,0)">print </span><span style=3D"font-variant-ligatu=
res:no-common-ligatures">("In main.")</span></div><div style=3D"m=
argin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family=
:Menlo"><span style=3D"font-variant-ligatures:no-common-ligatures;color:rgb=
(47,180,29)">=C2=A0=C2=A0 =C2=A0 15 </span><span style=3D"font-variant-liga=
tures:no-common-ligatures;color:rgb(180,36,25)">=C2=A0 =C2=A0 </span><span =
style=3D"font-variant-ligatures:no-common-ligatures">Pdb</span><span style=
=3D"font-variant-ligatures:no-common-ligatures;color:rgb(64,11,217)">().</s=
pan><span style=3D"font-variant-ligatures:no-common-ligatures">set_trace</s=
pan><span style=3D"font-variant-ligatures:no-common-ligatures;color:rgb(64,=
11,217)">()</span></div><div style=3D"margin:0px;font-stretch:normal;font-s=
ize:11px;line-height:normal;font-family:Menlo;color:rgb(47,180,29)"><span s=
tyle=3D"font-variant-ligatures:no-common-ligatures">---> 16 </span><span=
style=3D"font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">=
=C2=A0 =C2=A0 </span><span style=3D"font-variant-ligatures:no-common-ligatu=
res;color:rgb(0,0,0)">name</span><span style=3D"font-variant-ligatures:no-c=
ommon-ligatures;color:rgb(64,11,217)">()</span></div><div style=3D"margin:0=
px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;=
color:rgb(47,180,29)"><span style=3D"font-variant-ligatures:no-common-ligat=
ures">=C2=A0=C2=A0 =C2=A0 17=C2=A0</span></div><div style=3D"margin:0px;fon=
t-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:=
rgb(64,11,217)"><span style=3D"font-variant-ligatures:no-common-ligatures;c=
olor:rgb(47,180,29)">=C2=A0=C2=A0 =C2=A0 18 if</span><span style=3D"font-va=
riant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> __name__ </span><spa=
n style=3D"font-variant-ligatures:no-common-ligatures">=3D=3D</span><span s=
tyle=3D"font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </spa=
n><span style=3D"font-variant-ligatures:no-common-ligatures">"__main__=
":</span></div></span><div style=3D"margin:0px;font-stretch:normal;fon=
t-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span sty=
le=3D"font-variant-ligatures:no-common-ligatures"></span><br></div><div sty=
le=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font=
-family:Menlo;min-height:13px"><span style=3D"font-variant-ligatures:no-com=
mon-ligatures"></span><br></div><div style=3D"margin:0px;font-stretch:norma=
l;font-size:11px;line-height:normal;font-family:Menlo"><span style=3D"font-=
variant-ligatures:no-common-ligatures">ipdb>=C2=A0</span></div></div><di=
v style=3D"margin:0px;font-stretch:normal;font-size:11px;line-height:normal=
;font-family:Menlo"><span style=3D"font-variant-ligatures:no-common-ligatur=
es"><br></span></div><div style=3D"margin:0px;font-stretch:normal;line-heig=
ht:normal"><span style=3D"font-family:Helvetica;font-size:12px">I now want =
to change the definition of</span><span style=3D"font-family:Menlo;font-siz=
e:11px">=C2=A0print_name()</span> to print=C2=A0=E2=80=9CBob=E2=80=9D inste=
ad of =E2=80=9CAlice=E2=80=9D. I can make this change in Emacs, send the ne=
w function to IPython with <span style=3D"font-family:Menlo;font-size:11px"=
>C-c C-y f</span>, but when I then type <span style=3D"font-family:Menlo;fo=
nt-size:11px">name()</span>, I get =E2=80=9CAlice=E2=80=9D. The reference t=
o <span style=3D"font-family:Menlo;font-size:11px">print_name()</span> in <=
span style=3D"font-family:Menlo;font-size:11px">name()</span> is not gettin=
g updated to point to the new definition of <span style=3D"font-family:Menl=
o;font-size:11px">print_name</span><font face=3D"Menlo"><span style=3D"font=
-size:11px">(</span>)</font>. Likely I=E2=80=99m going about this process i=
ncorrectly, as I can make these kind of changes at an IPython3 prompt but n=
ot at an ipdb one.</div><div style=3D"margin:0px;font-stretch:normal;line-h=
eight:normal"><br></div><div style=3D"margin:0px;font-stretch:normal;line-h=
eight:normal">Thanks,</div><div style=3D"margin:0px;font-stretch:normal;lin=
e-height:normal"><br></div><div style=3D"margin:0px;font-stretch:normal;lin=
e-height:normal">Andreas</div></div>_______________________________________=
________<br>
IPython-dev mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">IPython-dev@pyt=
hon.org</a><br>
<a href=3D"https://mail.python.org/mailman/listinfo/ipython-dev" rel=3D"nor=
eferrer" target=3D"_blank">https://mail.python.org/mailman/listinfo/ipython=
-dev</a><br>
</blockquote></div>
</blockquote></div>
--0000000000002e5773057f4de1a2--
--===============7344567172977027935==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
IPython-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/ipython-dev
--===============7344567172977027935==--