uarray issues

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
emp20
Posts: 3
Joined: Fri Apr 24, 2020 5:15 pm

uarray issues

Post by emp20 » Fri Apr 24, 2020 5:27 pm

Hello, I have an issue with uarray on pyboard. Here is some code which I try to implement:

import uarray as array

data_array = array.array('f',[])
for i in range (counter, counter+N_SAMPLE):
data_array=data_array.append(float(f.readline()))

I have an issue in the last line and the error in REPL is that data_array does not have the attribute append
In the documentation, I see that attribute exists but I am not sure why do I get the error. I tried reading from file separately and that is a correct value. Can anyone give me some help or suggest another alternative I may use?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uarray issues

Post by pythoncoder » Fri Apr 24, 2020 5:45 pm

The following works here on a Pyboard:

Code: Select all

>>> from array import array
>>> a = array('f',[])
>>> a.append(1.0)
>>> a.append(1.0)
>>> a
array('f', [1.0, 1.0])
>>> 
Peter Hinch
Index to my micropython libraries.

emp20
Posts: 3
Joined: Fri Apr 24, 2020 5:15 pm

Re: uarray issues

Post by emp20 » Fri Apr 24, 2020 6:54 pm

Dear Peter,

Thank you for your quick reply. I modified my code according to your code (which also worked on my pyboard) to:
from array import array

data = array('f',[])

for i in range (counter, counter+N_SAMPLE):
data=data.append(float(f.readline()))

and I still get the AttributeError : NoType object has no attribute append. Unfortunately I cannot see why is that
When I check the counter, N_SAMPLE they are all initialised but the error is still in the last line...

emp20
Posts: 3
Joined: Fri Apr 24, 2020 5:15 pm

Re: uarray issues

Post by emp20 » Fri Apr 24, 2020 7:41 pm

Dear Peter,

your comment was very useful. I used data_array=data_array.append(float(f.readline())) when I should have used data_array.append(float(f.readline()))
A rookie mistake.

best wishes,

emp20

Post Reply