[英]TypeError: 'type' object is not subscriptable web3.py
Hey I am getting TypeError: 'type' object is not subscriptable when trying to print SimpleStorage.I am using env, my python version is 3.10.0 n the library is web3.py idk if this is enough this is my first q on stakeoverflow嘿,我收到 TypeError:'type' object 在尝试打印 SimpleStorage 时不可下标。我正在使用 env,我的 python 版本是 3.10.0 n 库是 web3.py idk 如果这足够了,这是我在 stakeoverflow 上的第一个 q
from solcx import compile_standard, install_solc
import json
from web3 import Web3
with open("./SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
print("Installing...")
install_solc("0.6.0")
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {
"*": ["abi", "metadata", "evm.bytecode", "evm.bytecode.sourceMap"]
}
}
},
},
solc_version="0.6.0",
)
with open("compiled_code.json", "w") as file:
json.dump(compiled_sol, file)
# get the bytecode
bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][
"bytecode"
]["object"]
# get abi
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]
w3 = Web3(Web3.HTTPProvider["http://127.0.0.1:7545"])
chain_id = 5777
my_address = "0x4bAB8D6D8b8959B1B7DaBd40B39eDFA8C07144C8"
private_key = "0xa5311c1f5d113053b3cfd4ef7ad1375a4030825d2f6bdf4131f28ae2331e1b6c"
# Create the contract in python
SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
print(SimpleStorage)
use ()
instead of []
.使用
()
而不是[]
。 Using []
treats it as a subscriptable object/container, meaning they contain other objects.使用
[]
将其视为可下标的对象/容器,这意味着它们包含其他对象。 Like strings, lists, tuples, and dictionaries.像字符串、列表、元组和字典一样。
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))
The “TypeError: 'type' object is not subscriptable” error is raised when you try to access an object using indexing whose data type is “type”.当您尝试使用数据类型为“type”的索引访问 object 时,会引发“TypeError: 'type' object is not subscriptable”错误。 To solve this error, ensure you only try to access iterable objects, like tuples and strings, using indexing.
要解决此错误,请确保您仅尝试使用索引访问可迭代对象,例如元组和字符串。
What is the data type stored in w3? w3中存储的数据类型是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.