Feature Requests item #1114404, was opened at 2005-02-01 20:27 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1114404&group_id=5470
Category: Python Interpreter Core Group: None Status: Open Resolution: None Priority: 5 Submitted By: Lenny Domnitser (ldrhcp) Assigned to: Nobody/Anonymous (nobody) Summary: All Statements Should Have Return Values (Syntax Proposal) Initial Comment: Python should allow a return value for some statements or blocks such as `print` or `def`. This should not always happen, but could certainly be useful. This can be used instead of lambdas when something more complex is required (the `def` example.) What seems to me to be the most natural syntax is to simply wrap the statement in parentheses. For example: >>> foo = (print 'bar') bar >>> foo 'bar' >>> f = (def f(x): if x < 0: return -5 return x ** 2 ) >>> f <function f at 0x00A575B0> >>> # A useful example: >>> do_some_sort_of_logging( ( raise SomeSortOfError ) ) It will generally be obvious what should be returned, but why not be more explicit? Here are some loose specs: `def` would return the defined function. `class` would return the defined class. `print` would return the string representation of the printed object. `raise` will return the exception. `import` returns the module or a tuple of modules. This is not mean to be complete or a definitive syntax, but I'd certainly like this discussed and something along the lines of this proposal implemented. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1114404&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com