Question: So I am working on a console based python(python3 actually) program where I use `input(">")`to get the command from user.

Now I want to implement the "last command" function in my program - when users press the up arrow on the keyboard they can see their last command.

After some research I found I can use curses lib to implement this but there are two problems.

1. Curses are not available on Windows.
2. The other parts of my program use `print()` to do the output. I don't want to rewrite them with curses.

So are there any others ways to implement the "last command" function? Thanks.

Answer: 
Until someone with better information looks at this question, I did some research:

> 
> Is this feature already implemented, and if so, how do I use it?
> 
> 
> 

It is implemented, but it doesn't seem to be exposed (e.g `ruby --dump-bytecode` doesn't exist). Also there's not very much [documentation](http://www.ruby-doc.org/core-2.0/RubyVM/InstructionSequence.html). As far as I can tell, what you are looking for is something like:

```
seq = RubyVM::InstructionSequence.compile_file("./example.rb")

```

`seq.disassemble` will give you a nicely formatted string that you could dump to a file, or `seq.to_a` will generate an an array that looks like:

```
["YARVInstructionSequence/SimpleDataFormat",
 2,
 0,
 1,
 {:arg_size=>0, :local_size=>1, :stack_max=>2},
 "<main>",
 "./example.rb",
 "./example.rb",
 1,
 :top,
 [],
 0,
 [],
 [[:trace, 1],
  [:putspecialobject, 3],
  [:putnil],
  [:defineclass,
   :User,
   ["YARVInstructionSequence/SimpleDataFormat",
    2,
    0,
    1,
    {:arg_size=>0, :local_size=>1, :stack_max=>6},
    "<class:User>",
    ....

```

If you want to persist this to a file, you can do something like:

```
File.write("out.dump", Marshal.dump(seq.to_a))

```

And then to load again:

```
arr = Marshal.load(File.read("out.dump"))

```

Unfortunately I can't seem to figure out how to create a new `InstructionSequence` given the array loaded above.

> 
> I'm also wondering about some of the details. Is YARV-bytecode supposed to be platform-independent? Are all gems automatically included in the bytecode?
> 
> 
> 

In the example above, gems are not included. Your `InstructionSequence` would include the bytecode equivalent of a `require 'active_record'` or what have you. I suspect that if dumping and loading of bytecode were provided directly by a `ruby` executable, this behavior would stay the same.

If anyone else has more information I'd love to see it!
Unfortunately it looks like the verifier didn't get implemented in 2.0-p0, and as a result the load functionality is still commented out (from iseq.c, line 2260):

```
/* disable this feature because there is no verifier. */
/* rb_define_singleton_method(rb_cISeq, "load", iseq_s_load, -1); */

```