A about python built-in packages are transferred to pycharm
- problem:python has some third-party libraries installed, but it can't be called in Pycharm?
- Answer: Because third- party libraries are stored in the system environment after they are installed through Pip, and pycharm is a virtual environment, you need to add the third-year library you need to your project.
- action:file-setting-python file-python interpreter- Click +to search for the required package -install Packing, you can use this new package.
Two Python vs . MySQL operations
- The relationship between Python and the database is linked through the associated APIs . Depending on the database and different versions of python, the required APIs are different . Take the native installation as an example:python3.6+mysql, so the installation is pymysql. Installation can also be done via pip.exe install pymysql or download package directly.
- The general idea is: Open database connection, database related operations , close the connection
- Example:
- (1). Open a database connection
- The. Connect () function is used to create a connection, write the host, username, password, existing database, port number
(2). Create a table
(3), inserting data
. Cursor () is the method used to get Python to execute the MySQL command, that is, to obtain an operation cursor; The Execute () function is the command used to execute the SQL statement, the. Commit () function is used to commit the transaction, and only after the transaction has been committed for the database to take effect; rollback () Is that when the database is modified, uncommitted (commit) can be returned to the pre-unmodified state by rolling back (rollback).
- After you have finished working with the database, you need to close the connection and use the. Close () method. If you do not close the connection, it will cause the system to crash when more people are using it.
- Other operations on the database are not listed, as above.
- There are several other commonly used commands in database operations:
- (1). Fetchall (): Used to receive all of the returned result rows (rows), which returns multiple tuples if NULL is returned ();
- (2). Fetchone (): Returns a single tuple, which is a record (row), and returns none if no result is found
- Summary: The first time to write these a bit of chaos, every day to take some time out of the record, hope to solid foundation!!!
Learn about Python's database of those things