Skip to main content

Posts

Showing posts with the label Python

Mencari Nilai dalam File Teks Menggunakan Python

Pada banyak kasus, kita mungkin perlu mencari nilai-nilai tertentu dalam satu file berdasarkan isi dari file lainnya. Misalnya, dalam kasus ini, kita ingin mencari kata atau kalimat yang terdapat dalam satu file teks (file1) di dalam file teks lainnya (file2) dan kemudian mencetak nilai-nilai yang tidak ditemukan. Dalam artikel ini, kita akan membahas cara melakukan hal ini menggunakan Python. Langkah Pertama: Membaca Konten dari File Langkah pertama adalah membaca konten dari kedua file yang ingin kita periksa. Kita akan menggunakan fungsi `open()` Python untuk membuka dan membaca isi file. with open(file1_path, 'r') as file1:     content_file1 = file1.readlines() with open(file2_path, 'r') as file2:     content_file2 = file2.read() Pada potongan kode di atas, `file1_path` dan `file2_path` adalah path (alamat) dari file-file yang ingin kita baca. Kita menggunakan `open()` untuk membuka file tersebut dalam mode membaca (`'r'`). Kemudian, kita membaca isi dari fi

Python ModuleNotFoundError: No module named 'Crypto'

Here is what the error looks like:   from Crypto.Cipher import AES   ModuleNotFoundError: No module named 'Crypto' It's because there is a collision between two modules. I worked with the below solutions, run the commands change pip to pip3 if needed pip uninstall crypto pip uninstall pycryptodome pip install pycryptodome May it solves for your case also, Thank you!

Belajar Dasar FastAPI

  FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.7+ based on standard Python type hints. Install framework pip install fastapi You will also need an ASGI server, for production such as  Uvicorn  or  Hypercorn . pip install "uvicorn[standard]" Create a file  main.py  with: from typing import Union from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"Hello": "World"} @app.get("/items/{item_id}") def read_item(item_id: int, q: Union[str, None] = None): return {"item_id": item_id, "q": q} Run the server with: uvicorn main:app --reload