diff --git a/gnubg.c b/gnubg.c
index 271557c..f313316 100644
--- a/gnubg.c
+++ b/gnubg.c
@@ -4673,6 +4673,10 @@ int main(int argc, char *argv[])
 	GError *error = NULL;
 	GOptionContext *context;
 
+#if USE_PYTHON
+  PyArg* py_arg;
+#endif
+        
 #if USE_MULTITHREAD
 	MT_InitThreads();
 #endif
@@ -4687,7 +4691,10 @@ int main(int argc, char *argv[])
 	textdomain(PACKAGE);
 	bind_textdomain_codeset(PACKAGE, GNUBG_CHARSET);
 
-	/* parse command line options */
+  /* parse command line options*/
+#if USE_PYTHON
+  py_arg = PythonArgNew(&argc, &argv);
+#endif
 	context = g_option_context_new("[file.sgf]");
 	g_option_context_add_main_entries(context, ao, PACKAGE);
 #if USE_GTK
@@ -4777,7 +4784,8 @@ int main(int argc, char *argv[])
 
 #if USE_PYTHON
 	PushSplash(pwSplash, _("Initialising"), _("Python"));
-	PythonInitialise(argv[0]);
+  PythonInitialise(py_arg);
+  PythonArgFree(py_arg);
 #endif
 
 	SetExitSoundOff();
diff --git a/gnubgmodule.c b/gnubgmodule.c
index be89c77..ae74f78 100644
--- a/gnubgmodule.c
+++ b/gnubgmodule.c
@@ -2330,8 +2330,85 @@ PyMethodDef gnubgMethods[] = {
 
 };
 
-extern void PythonInitialise(char *argv0)
-{
+#if HAVE_LIBREADLINE
+
+#if 0
+static char *
+PythonReadline( char *p ) {
+
+  char *pch;
+  int l;
+
+  pch = (char *) readline( p );
+
+  l = pch ? strlen( pch ) : 0;
+
+  pch = (char *) realloc( pch, l + 1 );
+
+  if( l )
+    strcat( pch, "\n" );
+  else
+    strcpy( pch, "" );
+
+  return pch;
+
+}
+#endif
+
+#endif
+
+extern PyArg*
+PythonArgNew(int *argc, char ***argv) {
+  PyArg* py_arg;
+  char* script_name;
+  int i, j;
+  int old;
+
+  Py_SetProgramName((*argv)[0]);
+
+  py_arg = (PyArg*)malloc(sizeof(PyArg));
+  if (!py_arg){
+    return NULL;
+  }
+
+  old = *argc;
+  for( i = 0 ; i < old ; i++ ) {
+    if ( 0==strcmp((*argv)[i], "-p") ) {
+      i++ ;
+      if ( i == old) {
+        /* not valid option! abort by g_option_context_parse. */
+        return NULL;
+      }
+      script_name = g_strdup((*argv)[i]);
+      py_arg->fArgv[0] = script_name; 
+      i++ ;
+      *argc = i;
+      /* found args for python script , copy and zap. */
+      for (py_arg->fArgc = 1; i < old; i++, (py_arg->fArgc)++) {
+        py_arg->fArgv[py_arg->fArgc] = g_strdup((*argv)[i]);
+        (*argv)[i] = NULL;
+      };
+      return py_arg;
+    }else{
+      /* Do nothing. These options are for gnubg itself. */
+    };
+  };
+  return NULL;
+}
+
+extern void
+PythonArgFree(PyArg *py_arg) {
+  //if ( FALSE) {
+  if ( py_arg ) {
+    //g_strfreev(py_arg->fArgv);
+    free(py_arg);
+  }
+}
+
+extern void
+PythonInitialise(PyArg* py_arg) {
+  char *pch;
+  char *working_dir = g_get_current_dir();
 
 #ifdef WIN32
 {	/* Setup python to look in the pythonlib directory if present */
@@ -2350,17 +2427,23 @@ extern void PythonInitialise(char *argv0)
 	g_free(python_dir);
 	g_free(working_dir);
 }
-
 #endif
-  Py_SetProgramName(argv0);
+
   Py_Initialize();
 
+  if ( py_arg ) {
+    int i;
+    PySys_SetArgv(py_arg->fArgc, py_arg->fArgv);
+  }
+
   /* ensure that python know about our gnubg module */
   Py_InitModule( "gnubg", gnubgMethods );
   PyRun_SimpleString( "import gnubg\n" );
 
   /* run gnubg.py start up script */
-  LoadPythonFile("gnubg.py");
+  /* pch = g_strdup( "gnubg.py" ); */
+  /* CommandLoadPython( pch ); */
+  /* g_free( pch ); */
 }
 
 #endif /* USE_PYTHON */
diff --git a/gnubgmodule.h b/gnubgmodule.h
index 5446403..aebc392 100644
--- a/gnubgmodule.h
+++ b/gnubgmodule.h
@@ -32,9 +32,23 @@
 #include <Python.h>
 #endif
 
-extern void PythonInitialise(char *argv0);
+typedef struct {
+  int fArgc;
+  char* fArgv[20]; // Ugh!
+} PyArg;
+
+extern PyArg*
+PythonArgNew(int *argc, char **argv[]);
+
+extern void
+PythonArgFree(PyArg *py_arg);
+
+
+extern void
+PythonInitialise(PyArg * py_arg);
 extern void PythonShutdown(void);
 extern void PythonRun(const char *sz);
 extern int LoadPythonFile(const char *sz);
 
 #endif /* _PYTHONMODULE_H_ */
+
