Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41830

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>
Date 2013-03-26 07:43 +1100
Subject Re: How to define "exec" method on a class object? Get syntax error due to built in command
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3700.1364244227.2939.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Mar 26, 2013 at 7:28 AM, Kyle <stalkernew@gmail.com> 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)

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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to define "exec" method on a class object? Get syntax error due to built in command Kyle <stalkernew@gmail.com> - 2013-03-25 13:28 -0700
  Re: How to define "exec" method on a class object? Get syntax error due to built in command Chris Angelico <rosuav@gmail.com> - 2013-03-26 07:43 +1100
  Re: How to define "exec" method on a class object? Get syntax error due to built in command Kyle <stalkernew@gmail.com> - 2013-03-26 11:13 -0700
    Re: How to define "exec" method on a class object? Get syntax error due to built in command Ethan Furman <ethan@stoneleaf.us> - 2013-03-26 11:36 -0700
    Re: How to define "exec" method on a class object? Get syntax error due to built in command Chris Angelico <rosuav@gmail.com> - 2013-03-27 05:43 +1100
      Re: How to define "exec" method on a class object? Get syntax error due to built in command Kyle <stalkernew@gmail.com> - 2013-03-26 12:24 -0700
        Re: How to define "exec" method on a class object? Get syntax error due to built in command Chris Angelico <rosuav@gmail.com> - 2013-03-27 06:39 +1100
          Re: How to define "exec" method on a class object? Get syntax error due to built in command Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-26 23:19 +0000
            Re: How to define "exec" method on a class object? Get syntax error due to built in command Chris Angelico <rosuav@gmail.com> - 2013-03-27 12:27 +1100

csiph-web