Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'subject:error': 0.03; 'syntax': 0.04; 'failing': 0.07; 'exec': 0.09; 'function,': 0.09; 'subject:command': 0.09; 'subject:method': 0.09; 'subject:How': 0.10; 'python': 0.11; 'def': 0.12; 'windows': 0.15; '"exec"': 0.16; '.py': 0.16; 'cli': 0.16; 'fine.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'keyword,': 0.16; 'ought': 0.16; 'subject: \n ': 0.16; 'subject:class': 0.16; 'subject:object': 0.16; 'tcl': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'command': 0.22; 'import': 0.22; 'error': 0.23; '2.x': 0.24; 'case.': 0.24; 'gets': 0.27; 'header :In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'that.': 0.31; 'file': 0.32; 'skip:_ 10': 0.34; 'maybe': 0.34; 'problem': 0.35; "can't": 0.35; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; '2.6': 0.36; "i'll": 0.36; 'received:209': 0.37; 'to:addr:python-list': 0.38; 'skip:_ 30': 0.39; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'subject:? ': 0.60; 'simply': 0.61; 'myself': 0.63; 'our': 0.64; 'grab': 0.64; 'mar': 0.68; '26,': 0.68; 'subject:Get': 0.68; "it'd": 0.84; 'kyle': 0.84; 'technically': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; bh=kD5BanCExZvKgykxu1PSz3l+bKIv+nOgkiQSG1ofIzA=; b=W14MhruAqXloDjvFEZ4QDvwQ9Z6+NtOX19ur8PkYCIu52U7ZmIR8ynqw4kp2lVhnsX hvALPaAWtJ4WoU/Xui8cd6hIMBEjYySXHlsPJYtF2bWbt3jGjCYWHb7fdQVJUEsjusRZ ZEST4ag3/6SEfw3H+M8VSbzbR0SW3xOs5V1cSzvdHgFyCsybP3xK0c0sYQo6vgr1aRhE lHhspG8Qj+hTJhKGyQNywSrTEajsT/5u+E1HZIl3k4xOcS2IHdHznObzuls9bFESYPBi 5OcGyBVqCvDQiwaCuQAl9xi9HISjo7LG0I/bJUTi7uWQvpDBoTFmT2wtPKJ9jByBEUhu 3VEg== MIME-Version: 1.0 X-Received: by 10.220.88.145 with SMTP id a17mr17360622vcm.66.1364244225774; Mon, 25 Mar 2013 13:43:45 -0700 (PDT) In-Reply-To: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> References: <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com> Date: Tue, 26 Mar 2013 07:43:45 +1100 Subject: Re: How to define "exec" method on a class object? Get syntax error due to built in command From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364244227 news.xs4all.nl 6913 [2001:888:2000:d::a6]:37497 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41830 On Tue, Mar 26, 2013 at 7:28 AM, Kyle wrote: > I am using swig to generate our CLI for TCL and Python. In this CLI, we h= ave a subcommand "exec" that is failing to compile in the python case. Ther= e 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) In Python 2, exec is a keyword, so you can't do that. In Python 3, exec is simply a built-in function, so it'd work fine. Technically you can get around the problem in 2.x with setattr/getattr, but that may not really be all that useful... def _exec(*args): return _wbt_daemon.dm_cli_exec(*args) ... setattr(dm_cli,"exec",dm_cli._exec) Tested on 2.6 for Windows (I really ought to get myself a 2.7, maybe when 2.7.4 gets released I'll grab it). ChrisA