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


Groups > comp.lang.python > #103812

Re: Request More Help With XBM Image

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: Request More Help With XBM Image
Date Tue, 01 Mar 2016 19:26:55 +0100
Organization None
Lines 72
Message-ID <mailman.77.1456856833.20602.python-list@python.org> (permalink)
References <8rKdnb6SKYLRIEnLnZ2dnUU7-f3NnZ2d@giganews.com> <mailman.60.1456822634.20602.python-list@python.org> <34GdnUOxhd5vS0jLnZ2dnUU7-Y3OydjZ@giganews.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de hCrXxXb3PypNBlCtHcb7lgMJs76kn7b0x+p4hxTsAEZw==
Return-Path <python-python-list@m.gmane.org>
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; 'executable': 0.07; 'filename': 0.07; '__init__': 0.09; 'callback': 0.09; 'command.': 0.09; 'errread,': 0.09; 'expected.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'way:': 0.09; 'subject:Help': 0.10; 'python': 0.10; 'exception': 0.13; 'question.': 0.13; 'argument': 0.15; '2016': 0.16; 'err': 0.16; 'errwrite)': 0.16; 'oserror:': 0.16; 'presume': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:More': 0.16; 'subprocess': 0.16; 'wrote:': 0.16; "shouldn't": 0.18; 'shell': 0.18; 'runs': 0.18; '>>>': 0.20; 'skip:" 30': 0.20; '(the': 0.22; '"",': 0.22; 'tkinter': 0.22; 'pass': 0.22; 'split': 0.23; '(most': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'command': 0.26; 'header:X-Complaints-To:1': 0.26; 'linux': 0.26; 'skip:" 20': 0.26; 'error': 0.27; 'executing': 0.27; 'looks': 0.29; 'convert': 0.29; 'raise': 0.29; 'window': 0.30; 'error.': 0.31; 'guess': 0.31; 'post': 0.31; 'skip:_ 10': 0.32; 'run': 0.33; 'raised': 0.33; 'skip:/ 20': 0.33; 'traceback': 0.33; 'tue,': 0.34; 'file': 0.34; 'previous': 0.34; 'skip:c 30': 0.35; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'why': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'received:de': 0.40; 'called': 0.40; 'mar': 0.65; 'python- list': 0.66; '3.4': 0.84; '__call__': 0.84; 'directory:': 0.84; 'otten': 0.84; 'subject:With': 0.93
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd89c3.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
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>
Xref csiph.com comp.lang.python:103812

Show key headers only | View raw


Wildman via Python-list wrote:

> On Tue, 01 Mar 2016 09:56:56 +0100, Peter Otten wrote:

>> Wildman via Python-list wrote:

>>> convert = "convert " + fileName + " -resize 48x48! -threshold 55% xbm:-"
>>> p = subprocess.Popen([convert], stdout=subprocess.PIPE, shell=True)
>>> xbmFile, err = p.communicate()

>> Why would you need a shell?

Just in case the example in my previous post has not made it clear: that was 
a rhetorical question. You do not need the shell, and in fact shouldn't use 
it.

> I guess it is a Linux thing.  If I don't use it, I get
> the below error.  A shell window does not actually open.
> I presume it runs in the background while executing the
> subprocess command.

> Exception in Tkinter callback
> Traceback (most recent call last):
> File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
> return self.func(*args)
> File "./test.py", line 59, in open_image
> p = subprocess.Popen(command, stdout=subprocess.PIPE)
> 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
> OSError: [Errno 2] No such file or directory
 
An exception is raised because you pass the command as a single argument 
like in

[Python 2.7]
>>> subprocess.Popen("ls /usr/share/dict/words")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

This looks for an executable called "ls /usr/share/dict/words" (the whole 
shebang!) where you actually want to run "ls" with the argument 
"/usr/share/dict/words". 

Once you split the parts

>>> subprocess.Popen(["ls", "/usr/share/dict/words"])
<subprocess.Popen object at 0x7fa6286d6250>
>>> /usr/share/dict/words

everything works as expected.

The error message in Python 3.4 would have given you a clue, by the way:

[Python 3.4]
>>> subprocess.Popen("ls /usr/share/dict/words")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/subprocess.py", line 859, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.4/subprocess.py", line 1457, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'ls 
/usr/share/dict/words'

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


Thread

Request More Help With XBM Image Wildman <best_lay@yahoo.com> - 2016-02-29 15:51 -0600
  Re: Request More Help With XBM Image Peter Otten <__peter__@web.de> - 2016-03-01 09:56 +0100
    Re: Request More Help With XBM Image Wildman <best_lay@yahoo.com> - 2016-03-01 11:52 -0600
      Re: Request More Help With XBM Image Peter Otten <__peter__@web.de> - 2016-03-01 19:26 +0100
        Re: Request More Help With XBM Image Wildman <best_lay@yahoo.com> - 2016-03-01 12:56 -0600
          Re: Request More Help With XBM Image Wildman <best_lay@yahoo.com> - 2016-03-01 18:09 -0600
  Re: Request More Help With XBM Image Christian Gollwitzer <auriocus@gmx.de> - 2016-03-01 20:30 +0100
    Re: Request More Help With XBM Image Wildman <best_lay@yahoo.com> - 2016-03-01 14:24 -0600

csiph-web