Switching between cmd.CMD instances

William Ray Wing wrw at mac.com
Wed Apr 2 08:05:21 EDT 2014


On Apr 2, 2014, at 1:03 AM, Josh English <Joshua.R.English at gmail.com> wrote:

> I have a program with several cmd.Cmd instances. I am trying to figure out what the best way to organize them should be.
> 
> I've got my BossCmd, SubmissionCmd, and StoryCmd objects.
> 
> The BossCmd object can start either of the other two, and this module allows the user switch back and forth between them. Exiting either of the sub-command objects returns back to the BossCmd.
> 
> I have defined both a do_done and do_exit method on the sub-commands.
> 
> Is it possible to flag BossCmd so when either of the other two process do_exit, the BossCmd will also exit?
> 
> Josh
> 

I am anything BUT a super experienced Python programmer, but if it were my problem - and if BossCmd has anything like an event loop in it, then certainly one way to handle this would be to have a Status.py module that contained status flags for each of the modules.  All three modules would "import status” and do_done and do_exit would set status flags in status.py on their way out.

I’m sure there are better answers.  I’ll be interested to see what else is suggested.

-Bill 


More information about the Python-list mailing list