본문 바로가기

python79

[Python] Underscore Usage I'll post about the underscore(_) in Python. Basic Usage Previous Value If you use underscore in REPL, it points to the previous result. >>> 3 + 5 8 >>> _ 8 >>> _ + 7 15 Ignoring Value You can use underscore for ignoring values. a, _, b = (1, 2, 3) print(f"{a}, {b}") # 1, 3 a, *_, b = (1, 2, 3, 4, 5, 6, 7) print(f"{a}, {b}") # 1, 7 If you use underscore in a loop, it indicates the current value .. 2021. 4. 26.
[Flask] Using Markdown on Flask In this posting, I'll show you how to use markdown on Flask. Installation $ pip install flask flask-markdown flask-simplemde Install Flask and Flask-Markdown, Flask-SimpleMDE. Create an Application 2020/10/11 - [Python] - [Python] Getting Started with Flask app.py from flask import Flask, render_template app = Flask(__name__) @app.route("/") def index(): return render_template("index.html") if _.. 2021. 3. 1.
[Flask] Send Email on Flask using Flask-Mail In this posting, we will figure out how to send an email on Flask. Installation First of all, we need flask and flask-mail. $ pip install flask flask-mail Create Flask Application Now, it's Flask time. You can refer to the basics of Flask in the below links. 2020/10/11 - [Python] - [Python] Getting Started with Flask 2020/10/23 - [Python] - [Python] Templates Static Files in Flask app.py from fl.. 2021. 2. 28.
Draw Graph with MatPlotLib in Python matplotlib is used for data visualization in Python. Especially, this library is lively used in data engineering. Installation If you want to locally install this library, you can use pip. $ pip install matplotlib I will use Google's Colab for further posting. Requirements import numpy as np import matplotlib.pyplot as plt from PIL import Image import cv2 %matplotlib inline I will use those pack.. 2021. 2. 25.
[Python] Introduce to DearPyGui 그동안 Python GUI 툴로 PyQt5를 사용하고 있었는데, 디자인에 대한 갈증을 계속 느꼈었습니다. 다른 프레임워크나 라이브러리들도 투박하기는 매 한가지고, QtDesigner는 번거롭고 불편해서 차라리 그냥 코딩해서 디자인 해왔었어요. dearpygui는 알고는 있었는데 크게 흥미가 가지 않아 사용하지 않았다가 얼마전 주말에 심심해서 잠깐 갖고 놀아보니 할만 하더라고요. 자료가 워낙 부족해서 삽질을 좀 했네요. 그러고나니 불가능 한 것과 가능한 것, 꼼수로 할 수 있는 것들을 좀 알겠더라고요. 그래서, 퇴근 후 한 두시간씩 틈틈히 삽질해서 간단하게 로또번호 추출기를 한 번 만들어 봤어요. 하는 김에 요즘 파이썬 진영에도 점점 확산되고 있는 type hint도 사용해봤고요. 아직 numpy나 ker.. 2021. 2. 11.
[Python] argparse module The argparse module makes it easy to write user-friendly command-line interfaces. Basics of argparse Module Let's make the application for argparse module, and using it. main.py import argparse if __name__ == '__main__': parser = argparse.ArgumentParser() args = parser.parse_args() That's it. How easy and how simple! Now, use our application. $ python main.py xxx $ python main.py -h This is the .. 2021. 2. 3.
[PyCharm] Run Flask Application on PyCharm In this posting, I explain how to run the Flask application on PyCharm. Installation On Mac I used the HomeBrew for installation. $ brew insstall --cask pycharm-ce On Windows I used the Chocolatey for installation. $ choco install -y pycharm-community Flask Application Let's make a very simple application for testing. from flask import Flask app = Flask(__name__) @app.route('/') def hello(): ret.. 2021. 1. 26.
[Python] Non-Keyword Arguments and Keyword Arguments Python has methods to pass a number of arguments to a function. Let's figure it out. Non-Keyword Arguments It is not compulsory, but it is mainly used in the form *args. This is the basic usage. def testArgs(*args): for arg in args: print(arg) testArgs('hello', 'world', 7, 3.14) # hello # world # 7 # 3.14 You can pass a number of arguments with this method. Let's test with the normal arguments. .. 2021. 1. 22.
[Python] 3 Ways of Formatted String There are 3 ways to write a formatted string in Python3. Let's check it one by one. Formatted String with Placeholder This method seems like a C language. It uses string-formatting operator %. print("String: %c, %s" % ('h', 'python')) # String: hello, python print("Integer: %d, %i" % (3, 7)) # Integer: 3, 7 print("Floating: %f, %F, %3.2f" % (2.818, 1.414, 3.14159)) # Floating: 2.818000, 1.414000.. 2021. 1. 22.
[Python] List (Array) Data Structure List is a data structure like Array. Elements in the List can be duplicated. Creating List ### [] method emptyList = [] weekdayList = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'] nameList = ['Kim', 'Lee', 'Park', 'Kim'] ### list() function emptyList = list() testList = list('cat') # from String print(testList) # ['c', 'a', 't'] testTuple = ('red', 'green', 'blue') testList = list(testTuple) # from Tuple .. 2020. 12. 7.
[Python] Dictionary Data Structure Dictionary is a data structure with key and value. Dictionary is internally implemented as hash table, so dictionary is a fast data structure. Dictionary is unordered before Python 3.6, and ordered after Python 3.7. The key of dictionary must be unique. Creating Dictionary There are many ways to create dictionary. ### {} method emptyDict = {} testDict = { "key1": "value1", "key2": "value2", "key.. 2020. 12. 6.
[Python] Templates Static Files in Flask Templates Overview Templates are files that contain static data as well as placeholders for dynamic data. A template is rendered with specific data to produce a final document. Flask uses the Jinja template library to render templates. In the application, we will use templates to render span style="color: #0593d3;">HTML which will display in the user's browser. In Flask, Jinja is configured to a.. 2020. 10. 23.