[IPython-user] Using __IP.push()
Frédéric Mantegazza
mantegazza at ill.fr
Wed Mar 23 09:37:54 CST 2005
Le Mercredi 23 Mars 2005 15:58, Fernando Perez a écrit :
> I think you misunderstood something. Do you want access to push() from
> an outside program, or from within ipython itself? If the above line is
> run within ipython itself, it will obviously produce something very
> bizarre, since ipython will try to use push() on your own call to push().
> This is recursive, and will likely blow up.
Ok, I understand the recursion problem !
> Now, the restriction of this not working from inside ipython itself
> remains, because of the recursive problem. However, if for some reason
> you do need to access runlines from within a running ipython, you can
> write a magic to do so.
Yes, I would like to have it works from inside ipython. I already have a
magic called 'do' which takes a batch file as argument. At the moment, the
batch file can only contain magics, because I use the magic() method to
execute lines. Here is the code :
def magic_do(self, parameter_s=''):
""" do magic command.
"""
myParser = ILLParserTPG()
cmd = 'do ' + parameter_s
try:
command = myParser(cmd)
fileName = command['fileName']
file_ = open(fileName, "r")
for line in file_:
if line[0] != '#':
args = line.split()
ipmagic(args[0], ' '.join(args[1:]))
except SyntacticError:
MessageLogger().error(sys.exc_info()[1])
InteractiveShell.magic_do = magic_do
del magic_do
I would like to treat both magic and python code here. But even in this
magic, I get a recursion problem.
--
Frédéric
More information about the IPython-user
mailing list