I want to be able to use a variable to output some text in IPython Notebook. I can write to a file from within IPython Notebook using the %%writefile command. I can also use a variable to name the file using $varaible_name.
file_name = "file.out"
some_variable = "text"
New cell
%%writefile $file_name
????some_varaible #<-what command goes here
So that the output file (named "file.out") looks like this:
text
%%writefile lets you output code developed in a Notebook to a Python module. The sys library connects a Python program to the system it is running on. The list sys. argv contains the command-line arguments that a program was run with.
Both ! and % allow you to run shell commands from a Jupyter notebook. % is provided by the IPython kernel and allows you to run "magic commands", many of which include well-known shell commands. ! , provided by Jupyter, allows shell commands to be run within cells.
Now this is possible using the following command::
%store varname > filename.txt
More about %store
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With