Pee*_*ebl 5 python json attributeerror python-3.x
为什么返回AttributeError:__enter__
排序方法只是根据列表的排序方式创建的字符串,当前时间使用stfttime
current_time = strftime("%Y-%m-%d %H-%M-%S", gmtime())
filename = f"Komplett-{str(sorting_method)}-{str(current_time)}.txt"
if not os.path.exists(f'C:/Users/tagp/OneDrive/Dokumenter/Python/{filename}'):
        open(str(filename), "w+")   
with (filename, "w+") as json_data:
            my_list = {}
            my_list["products"] = []
            for thing in my_products:
                my_list["products"].append({
                    "Product Title":thing.title,
                    "Price":thing.price,
                    "Rating":thing.rating,
                    "Stock":thing.stock
                    })
            json.dump(my_list, json_data, indent = 4)
完整回溯:
Traceback (most recent call last):
    File "komplett.py", line 172, in <module>
        with (filename, "w") as json_data:
AttributeError: __enter__
小智 7
你只是为了使用开放
current_time = strftime("%Y-%m-%d %H-%M-%S", gmtime())
filename = f"Komplett-{str(sorting_method)}-{str(current_time)}.txt"
if not os.path.exists(f'C:/Users/tagp/OneDrive/Dokumenter/Python/{filename}'):
        open(str(filename), "w+")   
with open(filename, "w+") as json_data:
            my_list = {}
            my_list["products"] = []
            for thing in my_products:
                my_list["products"].append({
                    "Product Title":thing.title,
                    "Price":thing.price,
                    "Rating":thing.rating,
                    "Stock":thing.stock
                    })
            json.dump(my_list, json_data, indent = 4)
| 归档时间: | 
 | 
| 查看次数: | 1202 次 | 
| 最近记录: |