Home > Database > Mysql Tutorial > .py extension convention

.py extension convention

Barbara Streisand
Release: 2024-12-05 08:42:10
Original
225 people have browsed it

.py extension convention

Connecting Python libraries is carried out similarly to the standard procedure, be it C /Java/others:

import sys
import openpyxl
from PyQt5 import QtWidgets
from PyQt5.Qt import QTableWidgetItem
from PyQt5.QtWidgets import (
    QApplication,
    QMainWindow,
    QPushButton,
    QVBoxLayout,
    QWidget,
    QTableWidget,
)
Copy after login

Due to the lack of a Python debugger, it is difficult to verify the correctness of the build and the presence of libraries. The command line (CLI) with operating system prompts is very helpful.

def appication():
    app=QApplication(sys.argv)
    window = QMainWindow()

    window.setWindowTitle("Smart home")
    window.setGeometry(300, 250, 300, 200)

    window.show()
    sys.exit(app.exec_())

if __name__=="__main__":
    appication()
Copy after login

The .py file extension occurs where, when you run the file as a command in the terminal, the builder pulls from your project's location path:

  1. Files that complement the main project, namely libraries and XML describing the graphical/integration structure (MySQL including)
  2. The terminal usually stores the path to the executable file in the computer's system storage, as in ArchLinux. The assembly itself pulls up the necessary libraries if they are standard/you placed them there
  3. As a result, make all the necessary extensions in advance by adding them to the root path
  4. Add the path to the admin's security settings, as the security system sometimes ignores undescribed exceptions explicitly (do it in the settings Path)
lass MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setMinimumWidth(1200)
        self.setMinimumHeight(600)

        layout = QVBoxLayout()

        self.table = QTableWidget(self)
        self.table.setRowCount(4)
        self.table.setColumnCount(4)
        layout.addWidget(self.table)

        btn = QPushButton("Download")
        btn.clicked.connect(self.btn_click)
        layout.addWidget(btn)

        widget = QWidget()
        widget.setLayout(layout)
        self.setCentralWidget(widget)

    def btn_click(self):
        wb = load_workbook('./123.xlsx')

        # Get sheet names
        sheet = wb['Sheet1']
        print(sheet.cell(row=2, column=1).value)
        for row in range(1, 5):
            for column in range(1, 5):
                item = QTableWidgetItem()
                item.setText(str(sheet.cell(row=row, column=column).value))
                self.table.setItem(row-1, column-1, item)

app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()
Copy after login

I don’t really believe in graphical shells for the Python environment; more often than not, they complicate interaction with files. Proper installation of libraries with accompanying conventions makes it easier to interact with the code. The lighter the level and more primitive, the better. Evolution informs reality - not the other way around.

The above is the detailed content of .py extension convention. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template