Hướng dẫn how to read last line of a file in python - cách đọc dòng cuối cùng của tệp trong python

Trên các hệ thống có lệnh

res = res.decode[]
print[res]
0, bạn có thể sử dụng
res = res.decode[]
print[res]
0, đối với các tệp lớn sẽ làm giảm sự cần thiết của việc đọc toàn bộ tệp.

from subprocess import Popen, PIPE
f = 'yourfilename.txt'
# Get the last line from the file
p = Popen[['tail','-1',f],shell=False, stderr=PIPE, stdout=PIPE]
res,err = p.communicate[]
if err:
    print [err.decode[]]
else:
    # Use split to get the part of the line that you require
    res = res.decode[].split['location="'][1].strip[].split['"'][0]
    print [res]

Đối với một

res = res.decode[]
print[res]
2 chung:

res = res.decode[]
print[res]

Để điều chỉnh số lượng dòng, hãy thay đổi lệnh

res = res.decode[]
print[res]
0. Trong 10 dòng cuối cùng, bạn sẽ sử dụng
res = res.decode[]
print[res]
4
For the last 10 lines you would use
res = res.decode[]
print[res]
4

Từ dòng thứ n đến cuối:

res = res.decode[]
print[res]
5 trong đó 10.000 là dòng bạn muốn đọc từ
where 10,000 is the line you want to read from

Lưu ý: Lệnh

res = res.decode[]
print[res]
6 chỉ được yêu cầu cho
res = res.decode[]
print[res]
7

res = res.split['location="'][1].strip[].split['"'][0]

sẽ làm việc cho

res = res.decode[]
print[res]
8

  1. Làm thế nào để
  2. Python làm thế nào
  3. Đọc dòng tệp cuối cùng bằng Python

Đã tạo: tháng 10-29 tháng 10 năm 2021

  1. Đọc dòng tệp cuối cùng với vòng lặp
    res = res.decode[]
    print[res]
    
    9 trong Python
  2. Đọc dòng tệp cuối cùng với chức năng
    res = res.split['location="'][1].strip[].split['"'][0]
    
    0 trong Python

Hướng dẫn này sẽ thảo luận về các phương pháp để đọc dòng cuối cùng từ một tệp trong Python.

Đọc dòng tệp cuối cùng với vòng lặp
res = res.decode[]
print[res]
9 trong Python

Đọc dòng tệp cuối cùng với chức năng

res = res.split['location="'][1].strip[].split['"'][0]
0 trong Python

with open['file.txt', 'r'] as f:
    for line in f:
        pass
    last_line = line
print[last_line]

Output:

This is the last file

Hướng dẫn này sẽ thảo luận về các phương pháp để đọc dòng cuối cùng từ một tệp trong Python.

Đọc dòng tệp cuối cùng với chức năng
res = res.split['location="'][1].strip[].split['"'][0]
0 trong Python

Hướng dẫn này sẽ thảo luận về các phương pháp để đọc dòng cuối cùng từ một tệp trong Python.

with open['file.txt', 'r'] as f:
    last_line = f.readlines[][-1]
print[last_line]

Output:

This is the last file

Vòng lặp

res = res.decode[]
print[res]
9 được sử dụng để lặp lại thông qua từng yếu tố của một điều có thể đi được trong Python. Chúng ta có thể sử dụng vòng lặp
res = res.decode[]
print[res]
9 để lặp qua từng dòng bên trong một tệp theo tuần tự và sau đó đọc dòng cuối cùng của tệp. Đoạn mã sau đây chỉ cho chúng ta cách đọc dòng cuối cùng của một tệp với vòng lặp
res = res.decode[]
print[res]
9.

Chúng tôi đã mở tệp

res = res.split['location="'][1].strip[].split['"'][0]
5 trong chế độ
res = res.split['location="'][1].strip[].split['"'][0]
6 và sử dụng vòng
res = res.decode[]
print[res]
9 để lặp qua từng dòng trong tệp. Chúng tôi đã sử dụng từ khóa
res = res.split['location="'][1].strip[].split['"'][0]
8 để giữ cho vòng lặp trống. Từ khóa
res = res.split['location="'][1].strip[].split['"'][0]
8 này hoạt động như một dòng trống trong Python và được sử dụng khi chúng tôi không muốn viết bất kỳ mã nào bên trong một vòng lặp hoặc một câu lệnh có điều kiện. Chúng tôi lưu trữ dòng cuối cùng bên trong biến
with open['file.txt', 'r'] as f:
    for line in f:
        pass
    last_line = line
print[last_line]
0 khi vòng lặp kết thúc và in giá trị của nó.

Hàm
with open['file.txt', 'r'] as f:
    for line in f:
        pass
    last_line = line
print[last_line]
2 đọc tất cả các dòng của một tệp và trả về chúng dưới dạng một danh sách. Sau đó, chúng ta có thể nhận được dòng cuối cùng của tệp bằng cách tham chiếu chỉ mục cuối cùng của danh sách bằng cách sử dụng
with open['file.txt', 'r'] as f:
    for line in f:
        pass
    last_line = line
print[last_line]
3 làm chỉ mục. Ví dụ mã sau đây cho chúng ta biết cách đọc dòng cuối cùng của một tệp có chức năng Python từ
with open['file.txt', 'r'] as f:
    for line in f:
        pass
    last_line = line
print[last_line]
2.

  • Chúng tôi đã mở tệp
    res = res.split['location="'][1].strip[].split['"'][0]
    
    5 ở chế độ
    res = res.split['location="'][1].strip[].split['"'][0]
    
    6 và sử dụng
    with open['file.txt', 'r'] as f:
        for line in f:
            pass
        last_line = line
    print[last_line]
    
    7 để đọc dòng cuối cùng của tệp. Chúng tôi đã sử dụng
    with open['file.txt', 'r'] as f:
        for line in f:
            pass
        last_line = line
    print[last_line]
    
    8 vì hàm
    res = res.split['location="'][1].strip[].split['"'][0]
    
    0 trả về tất cả các dòng dưới dạng danh sách và chỉ mục
    with open['file.txt', 'r'] as f:
        for line in f:
            pass
        last_line = line
    print[last_line]
    
    8 này cung cấp cho chúng tôi yếu tố cuối cùng của danh sách đó.
  • Trong Python, không có phương thức nào có thể đọc trực tiếp dòng cuối cùng của một tệp. Vì vậy, chúng ta phải đọc toàn bộ tập tin tuần tự cho đến khi chúng ta đạt đến dòng cuối cùng. Phương thức đầu tiên đọc từng dòng tệp, trong khi phương thức thứ hai đọc đồng thời tất cả các dòng.
  • Bài viết liên quan - Tệp Python
  • Nhận tất cả các tệp của một thư mục
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc Read a file line-by-line in Python
    Given a text file fname, a number N, the task is to read the last N lines of the file.
    As we know, Python provides multiple in-built features and modules for handling files. Let’s discuss different ways to read last N lines of a file using Python. 
    File: 
     

    Bàn luận 
    In this approach, the idea is to use a negative iterator with the readlines[] function to read all the lines requested by the user from the end of file.
     

    Python3

    Điều kiện tiên quyết: Đọc từng dòng tệp trong Pythongiven một tệp văn bản fname, một số n, nhiệm vụ là đọc n dòng cuối cùng của tệp. . Hãy để thảo luận về các cách khác nhau để đọc n dòng cuối cùng của một tệp bằng python. & Nbsp; tệp: & nbsp; & nbsp;

    This is the last file
    
    3
    This is the last file
    
    4
    This is the last file
    
    5
    This is the last file
    
    6
    This is the last file
    
    7
    This is the last file
    
    8

    Phương pháp 1: Cách tiếp cận ngây thơ & nbsp; Trong phương pháp này, ý tưởng là sử dụng trình lặp âm với hàm readlines [] để đọc tất cả các dòng được người dùng yêu cầu từ cuối tệp. & Nbsp;

    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    8
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    9
    This is the last file
    
    0
    This is the last file
    
    1
    This is the last file
    
    2

    This is the last file
    
    3
    This is the last file
    
    4
    This is the last file
    
    1
    This is the last file
    
    1
    This is the last file
    
    7
    This is the last file
    
    8

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    0
    This is the last file
    
    1
    Eighth line
    Ninth line
    Tenth line
    2

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    4
    This is the last file
    
    1
    Eighth line
    Ninth line
    Tenth line
    6

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    8
    This is the last file
    
    8

    This is the last file
    
    9
    Eighth line
    Ninth line
    Tenth line
    1

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    3
    This is the last file
    
    8

    This is the last file
    
    9
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    9
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    3
    Eighth line
    Ninth line
    Tenth line
    8

    Output:   
     

    Eighth line
    Ninth line
    Tenth line

    This is the last file
    
    9
    res = res.split['location="'][1].strip[].split['"'][0]
    
    00
    This is the last file
    
    1
    Eighth line
    Ninth line
    Tenth line
    1
    Method 2: Using OS module and buffering policy 
    In this approach, the idea is to work on the buffering policy in the python. A buffer stores a part of data received from a file stream of the operating system for a time period it is used and then more data comes in. 
    The buffer size determines the size of the data that can be stored at a time until it is used. We have the option to pass an integer to buffering in order to set buffering policy and if we do not specify any policy then the size of the buffer depends upon the device’s block size. Usually, the buffer is 4096 or 8192 bytes long. In this approach size of the buffer is 8192 bytes.
    Moreover, the st_size attribute of os.stat[] method in the OS module is used to represent the size of the file in bytes.
    Below is the implementation of the above approach.
     

    Python3

    This is the last file
    
    9
    res = res.decode[]
    print[res]
    
    9
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    1
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    2
    res = res.split['location="'][1].strip[].split['"'][0]
    
    74

    Điều kiện tiên quyết: Đọc từng dòng tệp trong Pythongiven một tệp văn bản fname, một số n, nhiệm vụ là đọc n dòng cuối cùng của tệp. . Hãy để thảo luận về các cách khác nhau để đọc n dòng cuối cùng của một tệp bằng python. & Nbsp; tệp: & nbsp; & nbsp;

    Phương pháp 1: Cách tiếp cận ngây thơ & nbsp; Trong phương pháp này, ý tưởng là sử dụng trình lặp âm với hàm readlines [] để đọc tất cả các dòng được người dùng yêu cầu từ cuối tệp. & Nbsp;

    This is the last file
    
    1
    This is the last file
    
    2

    This is the last file
    
    9
    res = res.decode[]
    print[res]
    
    9
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    1
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    2
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    3
    This is the last file
    
    7
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    5
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    6
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    7

    This is the last file
    
    3
    This is the last file
    
    4
    This is the last file
    
    5
    res = res.decode[]
    print[res]
    
    08

    & nbsp; Phương pháp 2: Sử dụng mô -đun HĐH và chính sách đệm & nbsp; Trong phương pháp này, ý tưởng là thực hiện chính sách đệm trong Python. Một bộ đệm lưu trữ một phần dữ liệu nhận được từ luồng tệp của hệ điều hành trong một khoảng thời gian nó được sử dụng và sau đó nhiều dữ liệu đi vào. & NBSP; Kích thước bộ đệm xác định kích thước của dữ liệu có thể được lưu trữ tại một thời điểm cho đến khi nó Được sử dụng. Chúng tôi có tùy chọn chuyển một số nguyên cho bộ đệm để đặt chính sách đệm và nếu chúng tôi không chỉ định bất kỳ chính sách nào thì kích thước của bộ đệm phụ thuộc vào kích thước khối của thiết bị. Thông thường, bộ đệm dài 4096 hoặc 8192 byte. Trong phương pháp này, kích thước của bộ đệm là 8192 byte.MoreOver, thuộc tính st_size của phương thức Os.stat [] trong mô -đun HĐH được sử dụng để biểu diễn kích thước của tệp trong byte.Below là việc triển khai phương pháp trên & nbsp;

    Eighth line
    Ninth line
    Tenth line
    9
    Eighth line
    Ninth line
    Tenth line
    0

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    4
    This is the last file
    
    1
    Eighth line
    Ninth line
    Tenth line
    6

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    8
    This is the last file
    
    1
    res = res.decode[]
    print[res]
    
    00

    This is the last file
    
    3
    res = res.decode[]
    print[res]
    
    02
    This is the last file
    
    1
    res = res.decode[]
    print[res]
    
    04

    This is the last file
    
    9
    This is the last file
    
    3
    res = res.decode[]
    print[res]
    
    11

    res = res.decode[]
    print[res]
    
    26
    res = res.decode[]
    print[res]
    
    39

    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    8
    Eighth line
    Ninth line
    Tenth line
    4
    This is the last file
    
    1
    res = res.decode[]
    print[res]
    
    15
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    6
    res = res.decode[]
    print[res]
    
    17

    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    8
    res = res.decode[]
    print[res]
    
    19
    This is the last file
    
    1
    res = res.decode[]
    print[res]
    
    21

    res = res.decode[]
    print[res]
    
    52
    res = res.decode[]
    print[res]
    
    58

    This is the last file
    
    3
    This is the last file
    
    4
    This is the last file
    
    1
    This is the last file
    
    1
    This is the last file
    
    7
    This is the last file
    
    8

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    0
    This is the last file
    
    1
    Eighth line
    Ninth line
    Tenth line
    2

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    4
    This is the last file
    
    1
    Eighth line
    Ninth line
    Tenth line
    6

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    8
    This is the last file
    
    8

    This is the last file
    
    9
    Eighth line
    Ninth line
    Tenth line
    1

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    3
    This is the last file
    
    8

    This is the last file
    
    9
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    9
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    3
    Eighth line
    Ninth line
    Tenth line
    8
    res = res.decode[]
    print[res]
    
    37

    Output:   
     

    Eighth line
    Ninth line
    Tenth line

    & nbsp; & nbsp; Phương pháp 3: Thông qua tìm kiếm theo cấp số nhân Phương pháp này, ý tưởng là sử dụng thuật toán tìm kiếm theo cấp số nhân thường được sử dụng để tìm kiếm các danh sách được sắp xếp, không giới hạn hoặc vô hạn. Để có được thông tin về tìm kiếm theo cấp số nhân bấm vào đây. Cách tiếp cận này sử dụng câu lệnh ASPER đóng vai trò là một công cụ gỡ lỗi để kiểm tra một điều kiện. Chương trình sẽ tiếp tục thực thi nếu câu lệnh đã cho là đúng, nó sẽ tạo ra một ngoại lệ AssitSerror. Để có thêm chi tiết về các câu lệnh ASPER, bấm vào đây. Bấm vào đây để làm quen với các loại sử dụng khác nhau của phương thức Seek [] .Below là việc thực hiện phương pháp trên. & NBSP;
    Method 3: Through Exponential search
    In this method, the idea is to use Exponential Search algorithm which is generally used for searching sorted, unbounded or infinite lists. To get information about exponential search click here.
    This approach uses assert statement which acts as a debugging tool to checks a condition. The program will continue to execute if the given statement is true otherwise, it generates an AssertionError exception. To get more details of assert statements click here.
    Click here to get familiar with different kinds of use of seek[] method.
    Below is the implementation of the above approach.
     

    Python3

    This is the last file
    
    1
    This is the last file
    
    2

    This is the last file
    
    3
    res = res.decode[]
    print[res]
    
    89
    res = res.decode[]
    print[res]
    
    90
    This is the last file
    
    1
    res = res.decode[]
    print[res]
    
    04

    This is the last file
    
    3
    res = res.decode[]
    print[res]
    
    94
    This is the last file
    
    1
    Eighth line
    Ninth line
    Tenth line
    4
    res = res.decode[]
    print[res]
    
    28
    res = res.decode[]
    print[res]
    
    17

    This is the last file
    
    3
    res = res.split['location="'][1].strip[].split['"'][0]
    
    00
    This is the last file
    
    1
    res = res.decode[]
    print[res]
    
    21

    This is the last file
    
    3
    This is the last file
    
    4
    This is the last file
    
    5
    res = res.decode[]
    print[res]
    
    08

    This is the last file
    
    9
    res = res.decode[]
    print[res]
    
    23
    res = res.decode[]
    print[res]
    
    42
    res = res.split['location="'][1].strip[].split['"'][0]
    
    10
    This is the last file
    
    1
    res = res.split['location="'][1].strip[].split['"'][0]
    
    12

    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    8
    Eighth line
    Ninth line
    Tenth line
    8
    This is the last file
    
    8

    res = res.decode[]
    print[res]
    
    26
    res = res.split['location="'][1].strip[].split['"'][0]
    
    17
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    6
    res = res.split['location="'][1].strip[].split['"'][0]
    
    19
    res = res.split['location="'][1].strip[].split['"'][0]
    
    20
    res = res.decode[]
    print[res]
    
    37

    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    8
    Eighth line
    Ninth line
    Tenth line
    3
    res = res.split['location="'][1].strip[].split['"'][0]
    
    24

    res = res.decode[]
    print[res]
    
    26
    res = res.split['location="'][1].strip[].split['"'][0]
    
    17
    res = res.decode[]
    print[res]
    
    04
    res = res.decode[]
    print[res]
    
    37

    res = res.decode[]
    print[res]
    
    26
    res = res.decode[]
    print[res]
    
    58

    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    8
    res = res.split['location="'][1].strip[].split['"'][0]
    
    32
    This is the last file
    
    8

    res = res.decode[]
    print[res]
    
    26
    res = res.split['location="'][1].strip[].split['"'][0]
    
    00
    This is the last file
    
    1
    res = res.split['location="'][1].strip[].split['"'][0]
    
    37
    res = res.split['location="'][1].strip[].split['"'][0]
    
    38

    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    8
    res = res.decode[]
    print[res]
    
    94
    res = res.decode[]
    print[res]
    
    35
    This is the last file
    
    1
    res = res.split['location="'][1].strip[].split['"'][0]
    
    20

    This is the last file
    
    3
    res = res.split['location="'][1].strip[].split['"'][0]
    
    45
    res = res.split['location="'][1].strip[].split['"'][0]
    
    46
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    6
    res = res.split['location="'][1].strip[].split['"'][0]
    
    48

    This is the last file
    
    3
    This is the last file
    
    4
    This is the last file
    
    1
    This is the last file
    
    1
    This is the last file
    
    7
    This is the last file
    
    8

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    0
    This is the last file
    
    1
    Eighth line
    Ninth line
    Tenth line
    2

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    4
    This is the last file
    
    1
    Eighth line
    Ninth line
    Tenth line
    6

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    8
    This is the last file
    
    8

    This is the last file
    
    9
    res = res.split['location="'][1].strip[].split['"'][0]
    
    00
    This is the last file
    
    1
    Eighth line
    Ninth line
    Tenth line
    1

    This is the last file
    
    9
    res = res.decode[]
    print[res]
    
    9
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    1
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    2
    res = res.split['location="'][1].strip[].split['"'][0]
    
    74

    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    8
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    9
    This is the last file
    
    0
    This is the last file
    
    1
    This is the last file
    
    2

    This is the last file
    
    3
    Eighth line
    Ninth line
    Tenth line
    3
    This is the last file
    
    8

    This is the last file
    
    9
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    9
    with open['file.txt', 'r'] as f:
        last_line = f.readlines[][-1]
    print[last_line]
    
    3
    Eighth line
    Ninth line
    Tenth line
    8
    res = res.decode[]
    print[res]
    
    37

    Output:   
     

    Eighth line
    Ninth line
    Tenth line

    Làm thế nào để bạn đọc một vài dòng cuối cùng của một tệp trong Python?

    Sử dụng cắt chuỗi để lấy n dòng N cuối cùng của dòng tệp [] để đọc tệp dưới dạng danh sách các chuỗi.Sử dụng cú pháp cắt chuỗi File_String [-N:] trên kết quả của tệp.Readlines [] để có được n dòng cuối cùng của tệp. readlines[] to read the file as a list of strings. Use the string slicing syntax file_string[-n:] on the result of file. readlines[] to get the last n lines of the file.

    Làm cách nào để xem dòng cuối cùng của một tệp?

    Để xem xét một vài dòng cuối cùng của một tệp, hãy sử dụng lệnh đuôi.Đuôi hoạt động theo cách tương tự như đầu: gõ đuôi và tên tệp để xem 10 dòng cuối cùng của tệp đó hoặc nhập tên tệp Đuôi để xem các dòng số cuối cùng của tệp.use the tail command. tail works the same way as head: type tail and the filename to see the last 10 lines of that file, or type tail -number filename to see the last number lines of the file.

    Làm thế nào để bạn tìm thấy kết thúc của một tập tin trong Python?

    Làm thế nào để kiểm tra xem đó là kết thúc của tập tin trong Python..
    open_file = open ["file.txt", "r"].
    Text = Open_File.đọc[].
    EOF = Open_File.đọc[].
    print[text].
    print[eof].

    Làm cách nào để in dòng đầu tiên và cuối cùng của một tệp trong Python?

    Đây là dòng cuối cùng ...
    với Open ["sample.txt", "r"] dưới dạng tệp:.
    First_line = File.ĐỌC LINE [].
    cho Last_line trong tập tin:.
    print[first_line].
    print[last_line].

    Bài Viết Liên Quan

    Chủ Đề