Skip to content

Interactive strings get mangled with "_ip.magic" #114

@ghost

Description

Reported on the user list by Max Bane:
http://mail.scipy.org/pipermail/ipython-user/2010-May/006936.html

See log below. This was somewhat unexpected :). What exactly is going
on here, and is there a quick and dirty way around it? My original
motivation for doing something like this in interactive mode was to
construct a string to execute on a MultiEngineClient. It's not a huge
deal, since I can always do it non-interactively, but still...

[max@radon:~/projects/density]$ ipython
Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27)
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]: facdef = \
  ...: """
  ...: def factorial(x):
  ...:     r = 1
  ...:     for y in xrange(2, x+1):
  ...:         r *= y
  ...:     return r
  ...: """

In [2]: print facdef

def factorial(x):
   r = 1
   for y in xrange(1, x+1):
   _ip.magic("r *= y")
   return r

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions