comparison docs/freefeatures.rst @ 328:7b2bca3951a7

locals_in_py
author cat@eee
date Fri, 12 Feb 2010 15:35:48 -0500
parents 4172feeddf76
children c69ad8418d39
comparison
equal deleted inserted replaced
327:e9eea93c777c 328:7b2bca3951a7
32 32
33 33
34 Commands at invocation 34 Commands at invocation
35 ====================== 35 ======================
36 36
37 TODO: broken!? 37 You can send commands to your app as you invoke it by
38 including them as extra arguments to the program.
39 ``cmd2`` interprets each argument as a separate
40 command, so you should enclose each command in
41 quotation marks if it is more than a one-word command.
42
43 ::
44
45 cat@eee:~/proj/cmd2/example$ python example.py "say hello" "say Gracie" quit
46 hello
47 Gracie
48 cat@eee:~/proj/cmd2/example$
38 49
39 Python 50 Python
40 ====== 51 ======
52
53 ::
54
55 The ``py`` command will run its arguments as a Python
56 command. Entered without arguments, it enters an
57 interactive Python session. That session can call
58 "back" to your application with ``cmd("")``. Through
59 ``self``, it also has access to your application
60 instance itself. (If that thought terrifies you,
61 you can set the ``locals_in_py`` parameter to ``False``.
62 See see :ref:`parameters`)
63
64 ::
65
66 (Cmd) py print("-".join("spelling"))
67 s-p-e-l-l-i-n-g
68 (Cmd) py
69 Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
70 [GCC 4.4.1] on linux2
71 Type "help", "copyright", "credits" or "license" for more information.
72 (CmdLineApp)
73
74 py <command>: Executes a Python command.
75 py: Enters interactive Python mode.
76 End with `Ctrl-D` (Unix) / `Ctrl-Z` (Windows), `quit()`, 'exit()`.
77 Non-python commands can be issued with `cmd("your command")`.
78
79 >>> import os
80 >>> os.uname()
81 ('Linux', 'eee', '2.6.31-19-generic', '#56-Ubuntu SMP Thu Jan 28 01:26:53 UTC 2010', 'i686')
82 >>> cmd("say --piglatin {os}".format(os=os.uname()[0]))
83 inuxLay
84 >>> self.prompt
85 '(Cmd) '
86 >>> self.prompt = 'Python was here > '
87 >>> quit()
88 Python was here >
41 89
42 Searchable command history 90 Searchable command history
43 ========================== 91 ==========================
44 92
45 All cmd_-based applications have access to previous commands with 93 All cmd_-based applications have access to previous commands with