[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

2013-07-09 Thread Georgiy Treyvus

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@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

>>> 
[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

>>> 
[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 
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

--
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 
<http://bugs.python.org/issue18419>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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

2013-07-09 Thread Georgiy Treyvus

Georgiy Treyvus added the comment:

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.

--

___
Python tracker 
<http://bugs.python.org/issue18419>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Georgiy Treyvus

New submission from Georgiy Treyvus:

The conditions under which this bug occurs I can't explain. I will provide as 
much other information as I can.

This is an issue with both Python2 and Python3. More specifically Python 2.7.3 
and Python 3.2.3 as those are what come with the Fedora 17 repositories. Not 
that it matters I made sure my program is written portably and so works on 
both. This involved stunts like:

if sys.version_info[0]==2:
input=raw_input

Getting back to the point since strings in Python are immutable I instead have 
code that tries to assign a character string to a list of one character strings 
at a given index in that list. Now normally this works quite splendidly. For 
example:

[georgiy@PANTHER mess]$ python
Python 2.7.3 (default, Jul 24 2012, 10:05:38) 
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> l=list('test')
>>> l
['t', 'e', 's', 't']
>>> l[0]='b'
>>> l
['b', 'e', 's', 't']
>>> 
[georgiy@PANTHER mess]$ python3
Python 3.2.3 (default, Jun  8 2012, 05:36:09) 
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> l=list('test')
>>> l
['t', 'e', 's', 't']
>>> l[0]='b'
>>> l
['b', 'e', 's', 't']
>>> 
[georgiy@PANTHER mess]$ 

See all is well.

However when I attempt to do the same exact thing namely assign a one character 
string to a list of one character strings at a given index in that list I get 
an error.

Here's what happens when I run my program:

[georgiy@PANTHER mess]$ python gcipher.py

Enter a command. Valid ones are "encrypt", "decrypt", and "exit".
command: encrypt

Enter plaintext. Only alphabetic characters allowed.
plaintext: secretmessagehere

Enter the encryption key. Only alphabetic characters allowed.
key: secretkeyhere

The encrypted version of your input with the given key is:
Traceback (most recent call last):
  File "gcipher.py", line 214, in 
print(encrypt(inText,encryptionKey))
  File "gcipher.py", line 127, in encrypt
letters[index]=letterAdd(letters[index],keystream[index])
TypeError: 'str' object does not support item assignment
[georgiy@PANTHER mess]$ python3 gcipher.py

Enter a command. Valid ones are "encrypt", "decrypt", and "exit".
command: encrypt

Enter plaintext. Only alphabetic characters allowed.
plaintext: secretmessagehere

Enter the encryption key. Only alphabetic characters allowed.
key: secretkeyhere

The encrypted version of your input with the given key is:
Traceback (most recent call last):
  File "gcipher.py", line 214, in 
print(encrypt(inText,encryptionKey))
  File "gcipher.py", line 127, in encrypt
letters[index]=letterAdd(letters[index],keystream[index])
TypeError: 'str' object does not support item assignment
[georgiy@PANTHER mess]$ 


Anyway here is the final proof that we have a bug here and that I am not a 
complete moron that assigned to a string. It says there's a problem on line 
127. Well here are are few very relevant lines 120-126 right before 127 you 
might want to take a look at:

assert(type(plaintext)==str)
letters=list(plaintext) 
assert(type(letters)==list)
assert(type(letters[0])==str)
assert(len(letters[0])==1)
for roundNumber in range(17):
for index in range(plaintextLength):

The point is that all the assertions in the above assert statements held true. 
No AssertionErrors were raised. What was instead raised is a TypeError because 
Python thought I was assigning to an index in a string. Yet clearly right 
before that we have asserted that the variable "letters" is bound to a list 
type. And in line 127 I was assigning a one character string to an index in 
"letters" which again is a list and not a string.

Please look into this. If you need more information let me know and I will do 
my best to provide it. If you want I can also provide you folks with the 
complete source code if you feel it will help you. (I do warn in advance that 
it is quite messy/hacky/unPythonic to the point of me quite possibly becoming 
the laughingstock of the Python developer community. Of course considering the 
rather complicated nature of the transformations made on text during 
(en|de)cryption I'd like to see any critics do it better. Please do not laugh 
too hard when I show it.)

--
components: Interpreter Core
messages: 184501
nosy: wfatp
priority: normal
severity: normal
status: open
title: I can't make assignments to a list.

___
Python tracker 
<http://bugs.python.org/issue17466>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Georgiy Treyvus

Georgiy Treyvus added the comment:

Yes the assert statements are executed. They are not in any sort of if block or 
anything like that. When the encrypt function is called and it was in the above 
examples the assert statements execute period. They really don't have much else 
of a choice. Look at the attached source code and see for yourself.

--
Added file: http://bugs.python.org/file29451/gcipher.py

___
Python tracker 
<http://bugs.python.org/issue17466>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Georgiy Treyvus

Georgiy Treyvus added the comment:

wait why was this closed?

--

___
Python tracker 
<http://bugs.python.org/issue17466>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Georgiy Treyvus

Georgiy Treyvus added the comment:

ok will try

--

___
Python tracker 
<http://bugs.python.org/issue17466>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17466] I can't make assignments to a list.

2013-03-18 Thread Georgiy Treyvus

Georgiy Treyvus added the comment:

@Mark: You're right. Sorry for the erroneous bug report.

--
resolution: invalid -> 
status: closed -> open

___
Python tracker 
<http://bugs.python.org/issue17466>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com