[IMP] odoo shell: set expected __name__ for scripts read from stdin
Name of scripts piped to `odoo shell` were `__builtin__` (`builtins` in python3), which is not really obvious (and awful if your script must handle python2 and python3). Change it to `__main__`, allowing to use to common pattern `if __name__ == '__main__':`
This commit is contained in:
@@ -34,6 +34,7 @@ class Shell(Command):
|
||||
|
||||
def console(self, local_vars):
|
||||
if not os.isatty(sys.stdin.fileno()):
|
||||
local_vars['__name__'] = '__main__'
|
||||
exec sys.stdin in local_vars
|
||||
else:
|
||||
if 'env' not in local_vars:
|
||||
|
||||
Reference in New Issue
Block a user