Is there a way to, using the modules
Name:
8 or Name:
9, get smart completion when reading an input string that only matches a specific set of values? Nội dung chính
- Sơ lược về Python
- Giới thiệu về ngôn ngữ
- Basic stuffs
- Biến [variable]
- Vòng lặp
- Đối tượng
- Bài tập 2: echo
- Now let's get dirty
- Bài tập 1: cat
- Bài tập 2: echo
- Bài tập 2: echo
Now let's get dirty
read_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
Bài tập 1: cat
Name:
For instance:
Ad
will create prompt
Adam
If I enter
and press complete [typically via Tab-key] I getAs a bonus it shouldn't even be possible to enter a string other than
Ad
0, Ad
1 or Ad
2 together with a set of all their prefixes.Update: In essence I want a Python 3 variant of Emacs's
Nội dung chính
- Sơ lược về Python
- Giới thiệu về ngôn ngữ
- Basic stuffs
- Biến [variable]
- Vòng lặp
- Đối tượng
- Now let's get dirty
- Bài tập 1: cat
- Bài tập 2: echo
- Now let's get dirty
Nội dung chính
- Sơ lược về Python
- Giới thiệu về ngôn ngữ
- Basic stuffs
- Biến [variable]
- Vòng lặp
- Đối tượng
- Now let's get dirty
- Bài tập 1: cat
- Bài tập 2: echo
- Now let's get dirty
Nội dung chính
- Sơ lược về Python
- Giới thiệu về ngôn ngữ
- Basic stuffs
- Biến [variable]
- Vòng lặp
- Đối tượng
- Now let's get dirty
- Bài tập 1: cat
- Bài tập 2: echo
- Now let's get dirty
Sơ lược về Python
Giới thiệu về ngôn ngữ
- //code.google.com/edu/languages/google-python-class/
- Basic stuffs
- //www.python.org/doc/
Giới thiệu về ngôn ngữ
Basic stuffs
Biến [variable]
For instance: Nên phân biệt 2 khái niệm ở đây là ngôn ngữ Python viết hoa chữ cái đầu bằng text thường và
will create promptĐối tượng
Now let's get dirty
Bài tập 1: cat
Basic stuffs
Biến [variable]
Vòng lặp
Đối tượng
Now let's get dirty
Bài tập 1: cat
Bài tập 2: echo
Now let's get dirty
Bài tập 1: cat
For instance:
3Name:
will create prompt
If I enter
and press complete [typically via Tab-key] I getAs a bonus it shouldn't even be possible to enter a string other than
will create promptIf I enter
If/else
and press complete [typically via Tab-key] I get
Name:
1VD:
read_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
0As a bonus it shouldn't even be possible to enter a string other than
Ad
0, Ad
1 or Ad
2 together with a set of all their prefixes.8 chạy lệnh sau Ad
9 Trong Python không
dùng begin/end hay {} để đánh dấu code block mà dùng indentation [việc thụt đầu dòng] để đánh dấu. Thường dùng 4 dấu cách hoặc một phím tab để indent. Không cần đóng code block vì chỉ cần khác indent tức là khác level rồi.VD:
Name:
0Vòng lặp
Đối tượng
4read_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
Now let's get dirty
0Name:
Bài tập 1: cat
1Name:
VD:
2Name:
For instance: Python có hàm range[] để tạo list tự động rất phù hợp để dùng chung với
37.Name:
Now let's get dirty
Đối tượng
Now let's get dirty
Bài tập 1: cat
Bài tập 2: echo
Now let's get dirty
VD:
Bài tập 1: cat
For instance:
will create prompt
Now let's get dirty
Bài tập 1: cat
Bài tập 1: cat
For instance:Thường dùng để:
Tạo file mới
3Name:
[khi chạy lệnh, cat sẽ đợi input, gõ văn bản vào và nhấn Control-D để kết thúc]
In nội dung file text ra màn hình
4Name:
Ý tưởng:
- Nếu có argument là file thì mở file và in ra màn hình.
- Nếu không thì lặp vô hạn việc đọc input và ghi ra output.
NOTE Để làm được bài tập này thì cần biết thêm một số khái niệm sau Để làm được bài tập này thì cần biết thêm một số khái niệm sau Để làm được bài tập này thì cần biết thêm một số khái niệm sau
Module
78 dùng để giao tiếp với hệ thống. Nó có một số hàm và biến khá hay ho:Name:
00 dùng để thoát chương trình khi cần.read_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
01 là một list chứa các argument của chương trình. Hãy tưởng tượng chương trình là một hàm, được hệ thống gọi, có đối số,read_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
01 cho ta truy cập các đối số đó.read_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
VD: Nếu chạy lệnh sau trong terminal
03 thì sys.argv sẽ chứa giá trịread_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
04read_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
Hàm
05 dùng để nhập dữ liệu từ người dùng, luôn return một string. Có thể so sánh vớiread_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
0 6 của C vàread_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
07 của Pascal.read_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
Hàm
05 dùng để nhập dữ liệu từ người dùng, luôn return một string. Có thể so sánh vớiread_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
0 6 của C vàread_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
07 của Pascal.read_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
read_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
08 dùng để mở file. Return một đối tượng file.Name:
5Code mẫu:
Bài tập 2: echoÝ tưởng:
- Nếu có argument là file thì mở file và in ra màn hình.
- Nếu không thì lặp vô hạn việc đọc input và ghi ra output.
NOTE Để làm được bài tập này thì cần biết thêm một số khái niệm sau Để làm được bài tập này thì cần biết thêm một số khái niệm sau Để làm được bài tập này thì cần biết thêm một số khái niệm sau
- Module
read_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
00 dùng để thoát chương trình khi cần.read_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
08 dùng để mở file. Return một đối tượng file.Name:
7Code mẫu:
Bài tập 2: echoread_from_list[prompt"Name:", allowed_values=["Adam", "Bert", "Cesar"]]
09 là lệnh để in ra màn hình. Cách dùng:Name:
6