programowanie:python:start

Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

Poprzednia rewizja po obu stronach Poprzednia wersja
Nowa wersja
Poprzednia wersja
programowanie:python:start [2024/09/09 14:52] sasesprogramowanie:python:start [2024/10/09 19:18] (aktualna) sases
Linia 2: Linia 2:
 \\ \\
  
-===== HTTP ===== +===== Środowisko wirtualne ===== 
-[[https://www.w3schools.com/python/module_requests.asp]]\\ +  * Utworzenie i uruchomienie 
-[[https://requests.readthedocs.io/en/latest/]]\\ +<code> 
-\\ +python -m venv env 
- +source env/bin/activate 
-=== request === +</code>
-<code python> +
-import requests +
- +
-html = requests.get("https://sases.pl")+
  
-print(html.text)+  * Opuszczenie 
 +<code> 
 +deactivate
 </code> </code>
 \\ \\
Linia 73: Linia 71:
 | ValueError | Raised when there is a wrong value in a specified data type | | ValueError | Raised when there is a wrong value in a specified data type |
 | ZeroDivisionError | Raised when the second operator in a division is zero | | ZeroDivisionError | Raised when the second operator in a division is zero |
 +\\
 +\\
  
 +===== MySQL =====
  
 +Instalacja biblioteki: ''pip install mysql-connector-python''\\
 +Oficjalna dokumentacja: [[https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html]]\\
  
 +Przykład:
 +<code python>
  
 +DB_CONFIG = {
 +  'user': 'scott',
 +  'password': 'password',
 +  'host': '127.0.0.1',
 +  'database': 'employees',
 +  'raise_on_warnings': True
 +}
 +
 +db = mysql.connector.connect(**DB_CONFIG)
 +cursor = db.cursor(buffered=True)
 +
 +cursor.execute(f"SELECT * FROM ...;")
 +result = cursor.fetchall()
 +result = cursor.fetchone()
 +cursor.close()
 +
 +sql = "INSERT INTO books (url, isbn) VALUES (%s, %s)"
 +val = ('url_val', 'isbn_val')
 +cursor.execute(sql, val)
 +db.commit()
 +added_id = cursor.lastrowid
 +
 +db.close()
 +</code>
 \\ \\
 \\ \\
  
 ===== Obiektowo ===== ===== Obiektowo =====
-W Python nie ma czegoś takiego jak prywatne/publiczne. Stosowane są podkreślniki przez nazwą aby wskazać, że to jest używane jak prywatne.+W Python nie ma czegoś takiego jak prywatne/publiczne. Stosowane są podkreślniki przed nazwą aby wskazać, że to jest używane jak prywatne.
  
 <code python> <code python>
  • programowanie/python/start.1725886345.txt.gz
  • ostatnio zmienione: 2024/09/09 14:52
  • przez sases