[issue5675] string module requires bytes type for maketrans, but calling method on regular string does not

2009-04-02 Thread MechPaul

New submission from MechPaul :

I was making a simple Caesarian cipher when this issue came up.

#Following code here

>>> import string
>>> CAESER_SHIFT = 13
>>> TranslationTableUpper = [string.ascii_uppercase[(index +
CAESER_SHIFT) % 26] for index in range(26)]
>>> TranslationTableLower = [string.ascii_lowercase[(index +
CAESER_SHIFT) % 26] for index in range(26)]
>>> TranslationTableCipher = ''.join(TranslationTableUpper +
TranslationTableLower)
>>> TranslationTableRegular = string.ascii_uppercase[0:27] +
string.ascii_lowercase[0:27]
>>> Trans = ''.maketrans(TranslationTableCipher, TranslationTableRegular)
>>> print(Trans)
{65: 78, 66: 79, 67: 80, 68: 81, 69: 82, 70: 83, 71: 84, 72: 85, 73: 86,
74: 87, 75: 88, 76: 89, 77: 90, 78: 65, 79: 66, 80: 67, 81: 68, 82: 69,
83: 70, 84: 71, 85: 72, 86: 73, 87: 74, 88: 75, 89: 76, 90: 77, 97: 110,
98: 111, 99: 112, 100: 113, 101: 114, 102: 115, 103: 116, 104: 117, 105:
118, 106: 119, 107: 120, 108: 121, 109: 122, 110: 97, 111: 98, 112: 99,
113: 100, 114: 101, 115: 102, 116: 103, 117: 104, 118: 105, 119: 106,
120: 107, 121: 108, 122: 109}
>>> #Okay... so maketrans() is working okay when calling it on an empty
string, bt if called from the string module...
>>> Trans = string.maketrans(TranslationTableCipher,
TranslationTableRegular)
Trans = string.maketrans(TranslationTableCipher,
TranslationTableRegular)
  File "D:\Python31\lib\string.py", line 55, in maketrans
raise TypeError("maketrans arguments must be bytes objects")
TypeError: maketrans arguments must be bytes objects

--
components: Interpreter Core
messages: 85280
nosy: MechPaul
severity: normal
status: open
title: string module requires bytes type for maketrans, but calling method on 
regular string does not
versions: Python 3.1

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



[issue5749] Allow bin() to have an optional "Total Bits" argument.

2009-04-13 Thread MechPaul

New submission from MechPaul :

As it stands right now, bin() only shows the minimum number of bits to
display the number, however I think having a "Total Bits" argument would
be very, very useful for bin().

bin(value, [Total bits to display])

"Total bits to display" is an integer.

Here's how it should work:

>>> bin(0x7F)
'0b111'
>>> #Note, there are seven 1's there to represent the value 127
>>> bin(0x7F, 8)
'0b0111'
>>> #Now there are eight bits displayed.
>>> bin(0xFF, 16)
'0b'
>>> #This makes it a lot easier to read and compare binary numbers!

--
components: Interpreter Core
messages: 85956
nosy: MechPaul
severity: normal
status: open
title: Allow bin() to have an optional "Total Bits" argument.
type: feature request
versions: Python 3.1

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