ReinforcementLearning icon indicating copy to clipboard operation
ReinforcementLearning copied to clipboard

May I ask why "'type' object is not subscriptable" appears when running the code?

Open growlsls opened this issue 3 years ago • 5 comments

May I ask why "'type' object is not subscriptable" appears when running the code?

growlsls avatar Feb 28 '23 07:02 growlsls

May I ask why "'type' object is not subscriptable" appears when running the code?

Phoenix-Shen avatar Feb 28 '23 07:02 Phoenix-Shen

This is caused by python3.8 or previous versions, I wrote the code using python3.9. You can upgrade the python to 3.9.

Here is an example:

def func(li:list[str])->list[str]: # this will cause error in python 3.8 , but is right in 3.9

Phoenix-Shen avatar Feb 28 '23 07:02 Phoenix-Shen

May I ask why "'type' object is not subscriptable" appears when running the code?

I have explained the cause of the error. The easiest way is to create a new python environment and install the dependencies under my repository.

run this command

conda create -n rl python=3.9
pip install -r requirements.txt

Or, you must modify all

def func(li:list[str])->list[str]:

to

def func(li):

I write the code in such a way that I can know what the type of each variable is. I hope my answer is helpful =-=.

Phoenix-Shen avatar Feb 28 '23 07:02 Phoenix-Shen

thanks you. Can you give me an example? For example, "def sample(self) -> tuple[np.ndarray, t.ensor, t.ensor, t.ensor, t.ensor, t.ensor, t.ensor]: "What to change to

growlsls avatar Feb 28 '23 07:02 growlsls

thanks you. Can you give me an example? For example, "def sample(self) -> tuple[np.ndarray, t.ensor, t.ensor, t.ensor, t.ensor, t.ensor, t.ensor]: "What to change to

Just delet all the return values!

def sample(self): 

Phoenix-Shen avatar Feb 28 '23 08:02 Phoenix-Shen