Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python
Python
  1. Copy และ Paste ไปยัง Clipboard ด้วย Pyperclip ใน Python

    บทนำpyperclip คัดลอก/วางข้อความไปยัง clipboard ทำงาน cross-platform (Windows, macOS, Linux) รองรับ Python 2 และ 3การติดตั้งpip install pyperclipการใช้งานCopyimport pyperclip pyperclip.copy(Hello world!)Pastetext = pyperclip.paste() print(text) # Hello world!Wait for New Pastepyperclip.copy(Hello wo

  2. การสร้างเอกสารด้วย Pydoc Module ใน Python

    บทนำpydoc สร้างเอกสารจาก Python modules อัตโนมัติ แสดงได้เป็น: console text, web browser, HTML filesการเริ่มต้นimport pydocInteractive Help Shell pydoc.help() # เข้า interactive help → พิมพ์ชื่อ module/function/classแสดงเอกสารบน Browserpython -m pydoc -b # Server ready at https://localhost:PORT/ → เ

  3. การเข้าถึงและแปลงเวลาด้วย Time Library ใน Python

    บทนำtime module ให้ฟังก์ชันจัดการเวลา: current time, sleep, formatting, struct_time objectการเริ่มต้นimport timeฟังก์ชันหลัก1. เวลาท้องถิ่นปัจจุบันseconds = time.time() # seconds since epoch (Jan 1 1970) local_time = time.ctime(seconds) print(Local time:, local_time) # Local time: Sun Jan

  4. สร้าง GUI Calculator เรียบง่ายด้วย Tkinter ใน Python

    บทนำtkinter เป็น GUI toolkit built-in ของ Python สร้าง desktop apps ได้ง่ายเตรียมความพร้อมpip install Pillow # สำหรับโหลดรูปไอคอนโฟลเดอร์โครงสร้าง:Working Directory/ Calculator.py assets/ Calculator/ Logo.ico, one.PNG, two.PNG, ...ฟังก์ชันหลักtxt = res = False ans = 0 def press(num)

  5. วิธีโหลดและใช้งาน Flower Dataset ด้วย TensorFlow

    บทนำFlower dataset (TensorFlow datasets) มีรูปดอกไม้หลายพันรูป 5 คลาส (daisy, dandelion, roses, sunflowers, tulips) โครงสร้างโฟลเดอร์ต่อคลาสโค้ดตัวอย่างprint(Loading parameters for the loader) batch_size = 32 img_height = 180 img_width = 180 print(Preprocessing the image dataset using Keras) print(

  6. วิธี Visualize Flower Dataset ด้วย TensorFlow และ Matplotlib

    บทนำVisualize ข้อมูลภาพช่วยตรวจสอบว่า loading/preprocessing ถูกต้อง ใช้ matplotlib.pyplot.imshowโค้ดตัวอย่างimport matplotlib.pyplot as plt print(Visualizing the flower dataset) plt.figure(figsize=(10, 10)) for images, labels in train_ds.take(1): for i in range(6): ax = plt.subplot(3, 3,

  7. สร้างฐานข้อมูล SQLite ใน Python: คู่มือพื้นฐาน

    บทนำSQLite เป็น embedded database ไฟล์เดียว ไม่ต้องติดตั้ง server Python มี sqlite3 module built-inเริ่มต้นใช้งานimport sqlite3สร้าง/เชื่อมต่อ Databasedatabase = sqlite3.connect(Student_records.db) print(Connection has been made successfully!) database.close()จะสร้างไฟล์ Student_records.db ใน workin

  8. วิธี Standardize Flower Dataset ด้วย TensorFlow

    บทนำData standardization: ปรับสเกลค่าพิกเซลให้อยู่ในช่วง [0,1] แทนที่จะเป็น [0,255] ช่วย neural network เรียนรู้ได้ดีขึ้นโค้ดตัวอย่างfrom tensorflow.keras import layers print(Standardizing the data using a rescaling layer) normalization_layer = tf.keras.layers.experimental.preprocessing.Rescaling(1.

  9. สร้างเว็บไซต์ด้วย Django ใน Python: คู่มือเริ่มต้น

    บทนำDjango เป็น Python web framework ฟรี open-source คุณสมบัติ: เร็ว, secure (ป้องกัน SQL injection, XSS, CSRF), scalable, มี built-in features (auth, admin, RSS, sitemaps)ตั้งค่าสภาพแวดล้อมpython -m pip install virtualenv mkdir django-intro cd django-intro virtualenv env source env/bin/activate #

  10. วิธี Configure Flower Dataset เพื่อ Performance ด้วย TensorFlow (เวอร์ชัน 2)

    บทนำอีกวิธี configure dataset ให้เร็วขึ้น: ใช้ cache() + prefetch() พร้อมใส่ Rescaling layer เข้าในโมเดลโดยตรงโค้ดตัวอย่างAUTOTUNE = tf.data.AUTOTUNE train_ds = train_ds.cache().prefetch(buffer_size=AUTOTUNE) val_ds = val_ds.cache().prefetch(buffer_size=AUTOTUNE) num_classes = 5 print(A sequential

  11. วิธี Compile และ Fit โมเดลกับ Flower Dataset ด้วย TensorFlow

    บทนำหลังสร้างโมเดล CNN สำหรับ Flower classification (5 คลาส) ขั้นตอนต่อไปคือ compile (กำหนด loss, optimizer, metrics) และ fit (train)โค้ดตัวอย่างprint(The model is being compiled) model.compile( optimizer=adam, loss=tf.losses.SparseCategoricalCrossentropy(from_logits=True), metrics=[accu

  12. ควบคุม Mouse และ Keyboard ด้วย pynput Library ใน Python

    บทนำpynput ควบคุมและฟัง (monitor) อุปกรณ์ input: mouse (pynput.mouse) และ keyboard (pynput.keyboard)การติดตั้งpip install pynputควบคุม Mouse {0}.format(mouse.position)) mouse.move(30, 15) # ย้าย relative mouse.press(Button.left) # กดปุ่มซ้าย mouse.release(Button.left)

  13. วิธีสร้างไฟล์ PowerPoint ด้วย Python (python-pptx)

    บทนำpython-pptx สร้าง/แก้ไข PowerPoint (.pptx) ด้วยโค้ด Python รองรับ Python 2.6–3.6+การติดตั้งpip install python-pptxสร้าง Presentation พื้นฐานfrom pptx import Presentation X = Presentation() # Layout 0 = Title Slide Layout = X.slide_layouts[0] first_slide = X.slides.add_slide(Layout) first_slide.

  14. วิธีเข้ารหัสและถอดรหัสข้อมูลใน Python ด้วย Cryptography Fernet

    บทนำCryptography คือการแปลง plaintext → ciphertext (encrypt) และกลับมา (decrypt) ใช้ Fernet (symmetric encryption) จาก package cryptographyการติดตั้งpip install cryptographyขั้นตอนหลัก1. Generate Keyfrom cryptography.fernet import Fernet key = Fernet.generate_key() f = Fernet(key) print(key.decode()

  15. วิธีสร้าง (Image, Label) Pair จาก File Path สำหรับ Flower Dataset ด้วย TensorFlow

    บทนำสร้าง function process_path(file_path) ที่แปลง path string → (image tensor, label int) ประกอบด้วย 3 sub-functionsโค้ดตัวอย่างprint(Function to convert file path to (image,label) pair) print(First, path is converted to list of path components) print(Then, the second to last value is added to clas

  16. การจับคู่ Pattern และ String ด้วย RegEx Module ใน Python

    บทนำRegular Expressions (RegEx) ใช้ค้นหา แทนที่ ตรวจสอบ pattern ในข้อความ ใช้ใน text editors, search engines, validators ฯลฯการเริ่มต้นmodule re มาพร้อม Python: import reฟังก์ชันหลักFunctionคำอธิบายre.compile(pattern, flags)คอมไพล์ pattern เป็น regex object (reuse ได้)re.search(pattern, string, flag

  17. วิธี Configure Flower Dataset เพื่อ Performance ด้วย TensorFlow

    บทนำเพื่อให้ training เร็วและไม่ bottleneck ที่ I/O ใช้ tf.data API configure dataset: cache, shuffle, batch, prefetchโค้ดตัวอย่างprint(A function is defined that configures the dataset for performance) def configure_for_performance(ds): ds = ds.cache() ds = ds.shuffle(buffer_size=1000)

  18. วิธี Train โมเดลต่อเนื่องกับ Flower Dataset ด้วย TensorFlow

    บทนำหลังสร้างและ compile โมเดลสำหรับ Flower classification (5 คลาส) ใช้ fit() เทรนต่อ พร้อมระบุ epochs และ validation dataโค้ดตัวอย่างprint(The data is fit to the model) model.fit( train_ds, validation_data=val_ds, epochs=3 )ผลลัพธ์The data is fit to the model Epoch 1/3 92/92 [==========

Total 9001 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:228/451  20-คอมพิวเตอร์/Page Goto:1 222 223 224 225 226 227 228 229 230 231 232 233 234