This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
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
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, wfatp
Priority: normal Keywords:

Created on 2013-07-09 23:17 by wfatp, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg192782 - (view) Author: Georgiy Treyvus (wfatp) Date: 2013-07-09 23:17
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@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@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@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@PANTHER mess]$ cat a
test
[georgiy@PANTHER mess]$ cat b
test
[georgiy@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@PANTHER mess]$ python3 allthesame.py a b
all the same
msg192785 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-07-09 23:31
That's because subprocess.getstatusoutput exists only in Python 3, and not Python 2.7.  The "if sys.version_info==2:" is also wrong, so subprocess is always selected, resulting in an error when the program is run with Python 2.
msg192788 - (view) Author: Georgiy Treyvus (wfatp) Date: 2013-07-10 01:23
I realized my mistake too late. It should have been

if sys.version_info[0]==2:

On the other hand

if sys.version_info==2:

while syntactically correct wasn't semantically correct.

My apologies for wasting your time and for my stupidity.
History
Date User Action Args
2022-04-11 14:57:47adminsetgithub: 62619
2013-07-10 01:23:24wfatpsetmessages: + msg192788
2013-07-09 23:31:10ezio.melottisetstatus: open -> closed

type: behavior
components: + Library (Lib)

nosy: + ezio.melotti
messages: + msg192785
resolution: not a bug
stage: resolved
2013-07-09 23:17:19wfatpcreate