[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnubg] Bug: sys.argv not available in gnubg/python?

From: Jim Segrave
Subject: Re: [Bug-gnubg] Bug: sys.argv not available in gnubg/python?
Date: Thu, 18 May 2006 23:56:29 +0200
User-agent: Mutt/

On Thu 18 May 2006 (09:48 -0700), David Levy wrote:
> Øystein posted a similar query for me earlier, but here are more details:
> The doesn't appear to be support for command line arguments to a python
> script under gnubg. 
> >From a cmd window under Windows XP, I type:
> gnubg-cli.exe -p e:\gnubatch\RunGnubg.py  {and want to add args here}
> So I looked for sys.argv as follows:
> (1) run gnubg-cli
> (2) type '>' to enter the python shell
> (3) type 'import sys' to import the sys module
> (4) type 'dir(sys)' to see what objects are there
> I don't see the expected sys.argv.
> Am I missing something?
> Is there another way I can pass command line arguments to a python script
> under gnubg?

I think that sys.argv is set up by the python interpreter when it runs
as a standalone program. gnubg gets the command line arguments and
later starts the python interpreter in another thread. 

I do see that you can do

import os
my_command = os.environ.get('MY_PYTHON_PARAMS', 'nothing in the environment')

this will point my_command at either the contents of the environment
variable 'MY_PYTHON_COMMAND' or, if that variable isn't set,
my_command will be the string 'nothing in the environment'

A scheme like this could be used to set up parameters for a script
(using better names I would hope) and then fetching them during script
execution time. It's a bit crude, but getting sys.argv set up would be
non-trivial: first you'd need to separate out the python script args
from the ones meant for gnubg, then you'd need to change where the
Python interpreter is started up, which currently uses a Python core
function to initialise the interpreter and a second one to run the
interpreter with a file handle on a script or the terminal. The
function used PyRun_AnyFile(), has no provision for passing arguments

Jim Segrave           address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]