There is a shopping list. This list also includes a product list. The shopping list lists all purchased items. The product list is the list that shows the information of each purchased product.
resetFile = open("printMachine.txt", "w")
resetFile.write("")
shoppingList = []
for row in enumerate(range(self.arayuz.shop_shoppingListTableWidget.rowCount())):
product_info = []
for col in enumerate(range(self.arayuz.shop_shoppingListTableWidget.columnCount())):
alt_liste.append(self.shop_shoppingListTableWidget.item(row[0], col[0]).text())
shoppingList.append(product_info)
I want to print the information in this list to the file in tabular form. How can I do it?
To put it more simply, I want to print the items in the lists in the shoppingList to the table.
Example shoppingList: [['12', 'Pencil', 'Yok', 'Yok', '1', '2', '21/01/2022'], ['13', 'Bag', 'Yok', 'Yok', '1', '25', '21/01/2022'], ['14', 'Book', 'Yok', 'Yok', '2', '5', '21/01/2022']]
I want it to be written to the file as:
+---------+--------------+-------+------------+-------+---------+------------+
| Barcode | Product Name | Brand | Piece/Gram | Price | Payable | Date |
+---------+--------------+-------+------------+-------+---------+------------+
| 12 | Pencil | None | None | 1 | 2 | 21/01/2022 |
+---------+--------------+-------+------------+-------+---------+------------+
| 13 | Bag | None | None | 1 | 25 | 21/01/2022 |
+---------+--------------+-------+------------+-------+---------+------------+
| 14 | Book | None | None | 2 | 5 | 21/01/2022 |
+---------+--------------+-------+------------+-------+---------+------------+
I tried this code:
df = pd.DataFrame(liste)
df.columns = ["Barkod", "Ürün Adı", "Ürün Markası", "Ürün Kategorisi" "Ürün Adeti/Gramı", "Ürün Fiyatı", "Tarih"]
writeFile.write(tabulate(df, headers='keys', tablefmt='psql'))
writeFile.write("\n\n\nTotal cost::" + self.arayuz.shop_totalCostTextBox.text() + " TL")
writeFile.write("\n\n--------------------------------\n\nBu kağıt, resmi bir belge değildir; sadece bilgilendirme amaçlıdır.")
Error:
tabulate(df, df.columns, tablefmt='psql')
TypeError: 'module' object is not callable