python module.py
but with 'tg-admin shell'. I tried
tg-admin shell module.py
but that had no effect, the code in module.py did not get executed.
Cheers,
Daniel
$ tg-admin shell
then in the shell
>>> import module
>>> module.main()
Yes, I know, although I sometimes ask stupid questions but I'm not
*that* stupid :))
So basically the answer is that it is not possible to feed the module
on the command line? I'm on linux by the way. The reason I need this
is that it would simplify testing my database quite a bit because for
that I don't need a web interface, browser, etc, and I usually just
put a couple of lines of code into a module and want to execute that
from the command line. Without being able to feed the module from the
command line I always have to enter into the tg-admin shell and type
stuff.
Cheers,
Daniel
I'm doing this the same way, but you get command-history on the shell,
so at least it's only
up-up-return
up-up-return
Not ideal, but ok.
Diez
I see. I haven't tried tg2 yet but if paster has the same issue I'd
like to propose this as a future enhancement.
Cheers,
Daniel
Why don't you use jsut import the database in your modules/scripts with
"a couple of lines of code"?
http://docs.turbogears.org/1.0/ModelOutsideTG#preview
Then you won't need tg-admin. If you want an interactive interpreter
after running the script, use IPython's/Python's -i option.
When you still want to be able to use the scripts as modules, use the
normal technique:
def run_database_stuff(args)
pass
if __name__ == '__main__':
import sys
run_database_stuff(sys.argv[1:])
Chris
Thanks a lot, this exactly answers my question!
Cheers,
Daniel
And the content of pythonfile.py is executed?
Try putting this into pythonfile.py to see for yourself:
if __name__ == '__main__':
print 'Boooo'
Are the outputs from 'python pythonfile.py' and 'tg-admin shell
pythonfile.py' the same?
Cheers,
Daniel
P.S. Chris' answer actually solves my problem, here I'm just wondering
if ipython makes any difference to the behavior of tg-admin shell.