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


Groups > comp.lang.python > #41934

Re: How to define "exec" method on a class object? Get syntax error due to built in command

Newsgroups comp.lang.python
Date 2013-03-26 11:13 -0700
References <2461da1a-d7d8-465b-8c12-6dc78398ef79@googlegroups.com>
Message-ID <27d47c3b-18d7-4ef0-b6fb-d99482c72bdd@googlegroups.com> (permalink)
Subject Re: How to define "exec" method on a class object? Get syntax error due to built in command
From Kyle <stalkernew@gmail.com>

Show all headers | View raw


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")(<args>) instead of wbt.exec(<args>) 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.

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