[New-bugs-announce] [issue18419] For reasons I can't explain Python in some cases says that getstatusoutput is not an attribute of the commands module but it is and should be

Georgiy Treyvus report at bugs.python.org
Wed Jul 10 01:17:19 CEST 2013


New submission from Georgiy Treyvus:

Basically in a lot of situations in recent times I've had to make sure a bunch of files are all the same. Now diff is great but it only lets me pass two files. diff3 and sdiff also aren't what I'm looking for. So I decided to write my own little script that does that.

I was doing a few crude preliminary tests on an early version of the utility and that's when shit hit the fan. For reasons I can't explain Python 2.7.5 in some circumstances said that getstatusoutput wasn't an attribute of the commands module. The program executed fine though under Python 3.3.2.

Anyway here's some shell output which will leave you folks scratching your head as much as I am. I have several times checked the syntax and I just simply don't think I'm doing anything wrong. What are your thoughts?

=======SHELL OUTPUT=======

[georgiy at PANTHER mess]$ python
Python 2.7.5 (default, May 16 2013, 13:44:12) 
[GCC 4.8.0 20130412 (Red Hat 4.8.0-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import commands as run
>>> run.getstatusoutput
<function getstatusoutput at 0x247a9b0>
>>> 
[georgiy at PANTHER mess]$ python3
Python 3.3.2 (default, May 20 2013, 12:05:55) 
[GCC 4.8.0 20130412 (Red Hat 4.8.0-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess as run
>>> run.getstatusoutput
<function getstatusoutput at 0x7f5880225ef0>
>>> 
[georgiy at PANTHER mess]$ cat allthesame.py 
import sys
if sys.version_info==2:
	import commands as run
else:
	import subprocess as run
baseCommand='diff --recursive '+sys.argv[1]+' '
for item in sys.argv[2:]:
	if run.getstatusoutput(baseCommand+item)[0]!=0:
		print('not all the same')
		exit(1)
print('all the same')
exit(0)
[georgiy at PANTHER mess]$ cat a
test
[georgiy at PANTHER mess]$ cat b
test
[georgiy at PANTHER mess]$ python allthesame.py a b
Traceback (most recent call last):
  File "allthesame.py", line 8, in <module>
    if run.getstatusoutput(baseCommand+item)[0]!=0:
AttributeError: 'module' object has no attribute 'getstatusoutput'
[georgiy at PANTHER mess]$ python3 allthesame.py a b
all the same

----------
messages: 192782
nosy: wfatp
priority: normal
severity: normal
status: open
title: For reasons I can't explain Python in some cases says that getstatusoutput is not an attribute of the commands module but it is and should be
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18419>
_______________________________________


More information about the New-bugs-announce mailing list