fbpx
Categories
Dev365TH Python tips

การใช้งาน Python

มาเรียนรู้พื้นฐานการใช้งาน python ในบทความนี้เราจะเรียนรู้ชุดคำสั่งทั่วไปที่เราใช้งานกันบ่อย ๆ ครับ

Avatar photo

By OTTO

I'm a graphics design, 3d model, game apps developer. I'm very young programmer. Thank for everyone support me. งานและชีวิตของผม เริ่มต้นจากสิ่งที่ผมรัก ครอบครัวที่คอยสนับสนุนผมครับ

5 replies on “การใช้งาน Python”

This somewhat depends on what platform you are on. The most common way to do this is by printing ANSI escape sequences. For a simple example, here’s some Python code from the Blender build scripts:

class bcolors:
HEADER = ‘\033[95m’
OKBLUE = ‘\033[94m’
OKCYAN = ‘\033[96m’
OKGREEN = ‘\033[92m’
WARNING = ‘\033[93m’
FAIL = ‘\033[91m’
ENDC = ‘\033[0m’
BOLD = ‘\033[1m’
UNDERLINE = ‘\033[4m’
To use code like this, you can do something like:

print(bcolors.WARNING + “Warning: No active frommets remain. Continue?” + bcolors.ENDC)
Or, with Python 3.6+:

print(f”{bcolors.WARNING}Warning: No active frommets remain. Continue?{bcolors.ENDC}”)
This will work on unixes including OS X, Linux and Windows (provided you use ANSICON, or in Windows 10 provided you enable VT100 emulation). There are ANSI codes for setting the color, moving the cursor, and more.

If you are going to get complicated with this (and it sounds like you are if you are writing a game), you should look into the “curses” module, which handles a lot of the complicated parts of this for you. The Python Curses HowTO is a good introduction.

If you are not using extended ASCII (i.e., not on a PC), you are stuck with the ASCII characters below 127, and ‘#’ or ‘@’ is probably your best bet for a block. If you can ensure your terminal is using a IBM extended ASCII character set, you have many more options. Characters 176, 177, 178 and 219 are the “block characters”.

Some modern text-based programs, such as “Dwarf Fortress”, emulate text mode in a graphical mode, and use images of the classic PC font. You can find some of these bitmaps that you can use on the Dwarf Fortress Wiki see (user-made tilesets).

The Text Mode Demo Contest has more resources for doing graphics in text mode.

การเรียกใช้งาน pandas
#python code

import pandas as pd
df = pd.read_csv (‘ชื่อไฟล์.csv’)
print(df)

ติดตั้ง pandas ถ้ากรณีรันบน jupyter notebook ให้ใส่เครื่องหมาย ! นำหน้า

ตัวอย่าง !pip3 install pandas

$ pip3 install pandas

Leave a Reply

Your email address will not be published. Required fields are marked *