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


Groups > comp.lang.python > #106464

Re: Request Help With Function

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From MRAB <python@mrabarnett.plus.com>
Newsgroups comp.lang.python
Subject Re: Request Help With Function
Date Mon, 4 Apr 2016 21:02:53 +0100
Lines 75
Message-ID <mailman.33.1459800193.32530.python-list@python.org> (permalink)
References <-JSdnXtfvv0oXp_KnZ2dnUU7-evNnZ2d@giganews.com> <5702C86D.9080308@mrabarnett.plus.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de UOaasOEHj5EEOEhbFVkeIQLqHjzUuuM8JD8hWHh1h0cw==
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'error:': 0.05; 'needed,': 0.05; 'tries': 0.05; 'bash': 0.07; 'strings.': 0.07; 'subject:Function': 0.07; '__init__': 0.09; 'arg': 0.09; 'errread,': 0.09; 'fails.': 0.09; 'typeerror:': 0.09; 'subject:Help': 0.10; 'python': 0.10; 'times,': 0.13; 'def': 0.13; '"/"': 0.16; 'errwrite)': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subprocess,': 0.16; 'wrote:': 0.16; 'string': 0.17; '"you': 0.18; 'passes': 0.18; 'gui': 0.18; 'skip:" 30': 0.20; 'arguments': 0.22; 'os,': 0.22; 'parsing': 0.22; 'pass': 0.22; 'trying': 0.22; 'appears': 0.23; 'wrote': 0.23; 'passing': 0.23; 'import': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'command': 0.26; 'linux': 0.26; 'skip:" 20': 0.26; 'appreciated.': 0.27; 'figure': 0.27; 'skip:# 10': 0.27; 'converting': 0.27; 'function': 0.28; 'btw,': 0.29; 'path,': 0.29; 'raise': 0.29; 'program,': 0.29; "i'm": 0.30; 'code': 0.30; 'error.': 0.31; "can't": 0.32; 'skip:_ 10': 0.32; 'getting': 0.33; 'run': 0.33; 'traceback': 0.33; 'open': 0.33; 'file': 0.34; 'lists': 0.34; 'list': 0.34; 'done': 0.35; 'false': 0.35; 'path': 0.35; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'display': 0.37; 'list.': 0.37; 'button': 0.38; 'several': 0.38; 'mean': 0.38; 'skip:o 20': 0.38; 'why': 0.39; 'test': 0.39; 'received:192': 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'called': 0.40; 'different': 0.63; 'complete': 0.63; 'python-list': 0.66; 'click': 0.76; 'done:': 0.84; 'subject:With': 0.93
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=K//fZHiI c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=KHc6qCvFEaKVZuka9YUA:9 a=QEXdDO2ut3YA:10
X-AUTH mrabarnett@:2500
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1
In-Reply-To <-JSdnXtfvv0oXp_KnZ2dnUU7-evNnZ2d@giganews.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <5702C86D.9080308@mrabarnett.plus.com>
X-Mailman-Original-References <-JSdnXtfvv0oXp_KnZ2dnUU7-evNnZ2d@giganews.com>
Xref csiph.com comp.lang.python:106464

Show key headers only | 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