There are a number of problems with your code.
First, there is an array
module and part of it, there is an array.array
class. When you do
from array import *
Romanic=array['str',(...)]
you are treating array.array
as an actual array object, instead of a class. Using []
in Python means accessing an element of something, not for initialization. You should be using ()
:
>>> from array import array
>>>
>>> array['i',(1,2,3)]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable
>>>
>>> array('i',(1,2,3))
array('i', [1, 2, 3])
Now, even if you changed your code to array('str',...)
, it still wouldn't work, because the 1st argument to the class initialization should be a valid typecode
.
https://docs.python.org/3/library/array.html#array.array
class array.array(typecode[, initializer])
A new array whose items are restricted by typecode, and initialized from the optional initializer value, which must be a list, a bytes-like object, or iterable over elements of the appropriate type.
The array
module docs has a table for all the typecodes, and you can also get the valid typecodes by:
>>> from array import typecodes
>>> print(typecodes)
bBuhHiIlLqQfd
and 'str'
is not in that of valid typecode
s. Maybe you are coming from other programming languages that use arrays, but what you seem to need is just a regular list, which in Python is how we represent a mutable "list of things":
>>> Romanic = ['Italian','French','Spanish','Portugese','Romanian']
>>> print('Romanic languages are ', Romanic, 'Want to insert more?')
Romanic languages are ['Italian', 'French', 'Spanish', 'Portugese', 'Romanian'] Want to insert more?
Lastly, don't use from module import *
syntax. See Why is “import *” bad?. It can become confusing, like in this case with an array
module and an array
class. Import the actual things you need from the module, or use module.something
syntax.