Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'subject:error': 0.03; 'languages.': 0.04; 'syntax': 0.04; 'failing': 0.07; 'constructor': 0.09; 'exec': 0.09; 'executed': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; 'subject:command': 0.09; 'subject:method': 0.09; 'yeah,': 0.09; '~ethan~': 0.09; 'subject:How': 0.10; 'python': 0.11; 'def': 0.12; 'suggest': 0.14; "wouldn't": 0.14; '"exec"': 0.16; '.py': 0.16; 'cli': 0.16; 'command.': 0.16; 'lambda': 0.16; 'name)': 0.16; 'received:69.93': 0.16; 'subject: \n ': 0.16; 'subject:class': 0.16; 'subject:object': 0.16; 'suggestion.': 0.16; 'syntaxerror:': 0.16; 'tcl': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'command': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'case.': 0.24; 'looks': 0.24; 'define': 0.26; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'raise': 0.29; '25,': 0.31; 'file': 0.32; 'class': 0.32; 'monday,': 0.33; 'skip:_ 10': 0.34; 'problem': 0.35; 'something': 0.35; 'there': 0.35; 'really': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'should': 0.36; 'easiest': 0.38; 'to:addr:python-list': 0.38; 'skip:_ 30': 0.39; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'commands': 0.60; 'solve': 0.60; 'subject:? ': 0.60; 'march': 0.61; 'name:': 0.61; 'received:173': 0.61; 'name': 0.63; 'our': 0.64; 'different': 0.65; 'between': 0.67; 'invalid': 0.68; 'subject:Get': 0.68; 'commands.': 0.84; 'kyle': 0.84; '2013': 0.98 Date: Tue, 26 Mar 2013 11:36:12 -0700 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How to define "exec" method on a class object? Get syntax error due to built in command References: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> <27d47c3b-18d7-4ef0-b6fb-d99482c72bdd@googlegroups.com> In-Reply-To: <27d47c3b-18d7-4ef0-b6fb-d99482c72bdd@googlegroups.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([173.12.184.235]) [173.12.184.235]:54406 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364323356 news.xs4all.nl 6901 [2001:888:2000:d::a6]:49475 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41938 On 03/26/2013 11:13 AM, Kyle wrote: > On Monday, March 25, 2013 4:28:34 PM UTC-4, Kyle wrote: >> I am using swig to generate our CLI for TCL and Python. In this CLI, we have a subcommand "exec" that is failing to compile in the python case. There seems to be some built-in python command "exec" which is giving a syntax error in the .py file generated by swig when I try to import it: >> >> >> >> def exec(*args): return _wbt_daemon.dm_cli_exec(*args) >> >> ^ >> >> SyntaxError: invalid syntax >> >> >> >> I don't really want to change the CLI commands or make them different between languages. Is there any way to define a method called "exec" on a class? It would be executed as obj.exec() so I don't see why it should conflict with the built in "exec" command. >> >> >> >> class dm_cli(_object): >> >> __swig_setmethods__ = {} >> >> __setattr__ = lambda self, name, value: _swig_setattr(self, dm_cli, name, value) >> >> __swig_getmethods__ = {} >> >> __getattr__ = lambda self, name: _swig_getattr(self, dm_cli, name) >> >> def __init__(self): raise RuntimeError, "No constructor defined" >> >> ... >> >> def exec(*args): return _wbt_daemon.dm_cli_exec(*args) >> >> ... >> >> } > > Thanks for the suggestion. Looks like we currently use 2.3.4. > > This still wouldn't solve the problem because now the user would need to call something like getattr(wbt, "exec")() instead of wbt.exec() like all the other commands. > > I think the easiest thing for me to do would be to just change the command name from exec to something else. Yeah, that's unfortunate. I suggest 'execute'. :) -- ~Ethan~