[issue32003] multiprocessing.Array("b", 1), multiprocessing.Array("c", 1 ) wrong value returned

2017-11-10 Thread Samuel Nwokenkwo

New submission from Samuel Nwokenkwo :

1st sequence:

arr = multiprocessing.Array("b", 1)  # byte type

arr[0] = 's'.encode()

print(arr[:]) 

result is [115]

2nd sequence:
arr = multiprocessing.Array("c", 1)  # character type

arr[0] = 's'.encode()

print(arr[:]) 

result is b's'

--
Wrong values for given types.

--
components: asyncio
messages: 306037
nosy: snwokenk, yselivanov
priority: normal
severity: normal
status: open
title: multiprocessing.Array("b", 1), multiprocessing.Array("c",1 )   wrong 
value returned
versions: Python 3.6

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



[issue32003] multiprocessing.Array("b", 1), multiprocessing.Array("c", 1 ) wrong value returned

2017-11-10 Thread Samuel Nwokenkwo

Samuel Nwokenkwo  added the comment:

I completely wrote the wrong code: 

So I'll copy and paste:


Scenario 1
import multiprocessing

br = multiprocessing.Array('c', 1)

br[0] = 's'

print(br[:])

Scenario 1 result = "TypeError: one character bytes, bytearray or integer 
expected"

-

Scenario 2
import multiprocessing

br = multiprocessing.Array('b', 1)

br[0] = 's'.encode()

print(br[:])

Scenario 2 results = "TypeError: an integer is required (got type bytes)"

---

I believe my confusion is that I am thinking more of the python data type byte, 
which takes b'', than C language data type byte (which takes numbers from -127 
to 128. This confusion is compounded when I do something like scenario 3:
---

import multiprocessing

br = multiprocessing.Array('c', 1)

br[0] = 's'.encode()

print(br[:])

scenario 3 results: b's'
--

In the first scenario passing 's' i get an error, even though by definition 's' 
is a c char data type.

--

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



[issue32003] multiprocessing.Array("b", 1), multiprocessing.Array("c", 1 ) wrong value returned

2017-11-10 Thread Samuel Nwokenkwo

Samuel Nwokenkwo  added the comment:

To clarify

my expectation was something like this:

arr = multiprocessing.Array('c', 3) # type char

arr = "Fun" 

which is similar to c implementation:

char arr[3] = "Fun"

AND

arr =  multiprocessing.Array('b', 3) # type byte
arr = b'fun'

Also this website list 'c' as a data type supported:
https://svn.python.org/projects/python/trunk/Lib/multiprocessing/sharedctypes.py

--

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