I would like to be able to do the following during an IPython session:

1. Easily save the contents of a variable to disk in an ASCII file
2. Easily re-direct stdout to disk for a given command

by easily I mean for example by using a `magic` (i.e. I would like to **avoid** having to type multi-line statements in IPython, opening file descriptors, etc.). 

[This answer](https://stackoverflow.com/a/13280118/283296) in [this thread](https://stackoverflow.com/questions/13199170/how-to-write-the-output-of-ipython-command-in-python-text-file/13280118#comment25500711_13280118) suggests using

```
%edit some_variable

```

to open the value of a variable in the editor (based on the value of `$EDITOR`) from which I could later save things to disk. This sounds great but when I try it on a regular Python variable

```
> my_variable = 'Hello world'
> %edit a

```

I get `TypeError: 'NoneType'object is not iterable` (By the way, I know that my `$EDITOR` env. variable works well, since other programs I use rely on it. either way `$EDITOR` is `emacsclient` in my case)

I have also tried with:

```
%save 'test.txt' print(my_variable)

```

with the hope that it would re-direct the output of the statement `print(my_variable)` to `test.txt`, but instead I get the following error:

```
'print(a)' was not found in history, as a file, url, nor in the user namespace.

```

Any thoughts on how to accomplish this?