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


Groups > comp.lang.python > #106464

Re: Request Help With Function

From MRAB <python@mrabarnett.plus.com>
Newsgroups comp.lang.python
Subject Re: Request Help With Function
Date 2016-04-04 21:02 +0100
Message-ID <mailman.33.1459800193.32530.python-list@python.org> (permalink)
References <-JSdnXtfvv0oXp_KnZ2dnUU7-evNnZ2d@giganews.com> <5702C86D.9080308@mrabarnett.plus.com>

Show all headers | View raw


On 2016-04-04 20:42, Wildman via Python-list wrote:
> I am working on a Linux gui program where I want to be able
> to click a Help button and open a man page using a viewer.
> I wrote a search function that can be called several times,
> if needed, with different arguments.  I wrote a test program
> that tries to open the Bash man page in a terminal and will
> display a message box if the search fails.  It passes the
> system path, terminal emulators and command line arguments
> to the search function.  I appears that you can't pass a list
> to a function so I am passing the arguments as strings and then
> converting them to lists for parsing in the search function.
>
> When I run the test program, I get this error:
>
> Traceback (most recent call last):
>    File "./man.py", line 38, in <module>
>      launch_help()
>    File "./man.py", line 10, in launch_help
>      if search(pathlist, executelist, commandlist):
>    File "./man.py", line 27, in search
>      subprocess.Popen(command)
>    File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
>      errread, errwrite)
>    File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
>      raise child_exception
> TypeError: execv() arg 2 must contain only strings
>
> I have not been able to figure out why I'm getting the error.
> Any help would be appreciated.  Below is the complete code for
> the test program:
>
> #!/usr/bin/env python
>
> import os, subprocess, tkMessageBox
>
> def launch_help():
>      pathlist = os.environ["PATH"]
>      executelist = "xvt,xfce4-terminal"
>      commandlist = "-e,man bash"
>      if search(pathlist, executelist, commandlist):
>          return None
>      message = "Open a terminal and enter:  man bash"
>      tkMessageBox.showinfo("Help", message)
>
> def search(pathlist, executelist, commandlist):
>      pathlist = pathlist.split(":")
>      executelist = executelist.split(",")
>      commandlist = commandlist.split(",")
>      done = False
>      for path in pathlist:
>          for execute in executelist:
>              target = path + "/" + execute
>              if os.path.isfile(target):
>                  done = True
>                  command = [target, commandlist]
>                  subprocess.Popen(command)
>              if done:
>                  break
>          if done:
>              break
>      if done:
>          return True
>      else:
>          return False
>
>
> launch_help()
>
.Popen will accept either a string or a list of strings.

You're giving it a list that contains a string and a list.

BTW, I don't know what you mean by "you can't pass a list to a 
function", because you can. How were you trying to do it?

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


Thread

Request Help With Function Wildman <best_lay@yahoo.com> - 2016-04-04 14:42 -0500
  Re: Request Help With Function Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-04 13:54 -0600
    Re: Request Help With Function Wildman <best_lay@yahoo.com> - 2016-04-04 19:26 -0500
  Re: Request Help With Function MRAB <python@mrabarnett.plus.com> - 2016-04-04 21:02 +0100
    Re: Request Help With Function Wildman <best_lay@yahoo.com> - 2016-04-04 19:38 -0500

csiph-web