Hướng dẫn how do i extract specific portions of a text file using python? - làm cách nào để trích xuất các phần cụ thể của tệp văn bản bằng python?

Gần đây tôi đã chọn Python để thực hiện một số trích xuất văn bản. Tôi có một tập dữ liệu trông như thế này:

    @article{noauthor_collective_nodate,
    title = {Collective teacher efficacy},
    abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},
@article{noauthor_collective_nodate,
    title = {Collective teacher efficacy},
    abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},
}

@article{noauthor_initial_nodate,
    title = {Initial teacher education programs},
    abstract = {Overview Influence: Initial teacher education programs Domain: Teacher Sub-Domain: Teacher Education Potential to Accelerate Student Achievement: Likely to have small positive impact Influence Definition: Initial teacher education or {ITEs} (sometimes at the undergraduate level and sometimes at the post-graduate level) is the entry-level qualification for teaching in numerous countries, including the United States. More recently, there are school-based {ITEs}, non-accredited {ITEs}, and many online {ITE} programs. Evidence Number of meta-analyses: 5 Number of studies: 117 Number of students: 106,016 Number of effects: 509 Effect size: 0.10},
}

@article{noauthor_professional_nodate,
    title = {Professional development programs},
    abstract = {Overview Influence: Professional development programs Domain: Teacher Sub-Domain: Teacher Education Potential to Accelerate Student Achievement: Likely to have positive impact Influence Definition: Professional development relates to courses or interventions aimed to enhance the beliefs, actions, impact of knowledge of teachers and school leaders. Evidence Number of meta-analyses: 21 Number of studies: 1,151 Number of students: 2,321,242 Number of effects: 2,938 Effect size: 0.37},
    keywords = {Program Development},
}

Và tôi muốn trích xuất tiêu đề và một phần của bản tóm tắt từ văn bản này. Tôi đã quản lý để trích xuất đầu ra mong muốn của mình bằng cách sử dụng mã này:

s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"


start = s.find("title = {") + len("title = {")
end = s.find("}, abstract")

start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
end2 = s.find("Evidence Number of meta-analyses:")

substring = s[start:end]
substring2 = s[start2:end2]
print(substring+' - '+substring2+";")

Output:

Collective teacher efficacy - The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. ;

Vấn đề là:

  • Rằng điều này chỉ lấy ra kết quả tìm kiếm đầu tiên
  • Tôi muốn có thể chạy nó trên tệp văn bản gốc thay vì sao chép nó dưới dạng "S".

Ai đó có thể vui lòng cho mượn một bàn tay giúp đỡ không?

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

    Tệp đang sử dụng: test.txt test.txt

    Hướng dẫn how do i extract specific portions of a text file using python? - làm cách nào để trích xuất các phần cụ thể của tệp văn bản bằng python?

    Phương pháp 1: FileObject.ReadLines ()

    Một đối tượng tệp có thể được tạo trong python và sau đó readlines () phương thức có thể được gọi trên đối tượng này để đọc các dòng vào một luồng. Phương pháp này được ưa thích khi một dòng hoặc một phạm vi dòng từ tệp cần được truy cập đồng thời. Nó có thể dễ dàng được sử dụng để in các dòng từ bất kỳ chỉ mục bắt đầu ngẫu nhiên nào sang một số chỉ mục kết thúc. Nó ban đầu đọc toàn bộ nội dung của tệp và giữ một bản sao của nó trong bộ nhớ. Các dòng tại các chỉ số được chỉ định sau đó được truy cập. & NBSP;

    Example:

    Python3

    file = open(____1010

    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    2= file
    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    5

    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    6(
    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    8
    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    1

    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    6
    Collective teacher efficacy - The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. ;
    
    1
    Collective teacher efficacy - The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. ;
    
    2
    Collective teacher efficacy - The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. ;
    
    3

    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    6(
    Collective teacher efficacy - The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. ;
    
    6
    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    1

    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    6
    Collective teacher efficacy - The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. ;
    
    1
    getLine(txt-file, line_number)
    0
    getLine(txt-file, line_number)
    1
    getLine(txt-file, line_number)
    2
    Collective teacher efficacy - The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. ;
    
    3

    Output 

    dòng thứ mười & nbsp;
     

    Đây là dòng 10.

    ba dòng đầu tiên & nbsp;
     

    Đây là dòng 1. Đây là dòng 2. Đây là dòng 3.

    Phương pháp 2: Gói Linecache & NBSP;

    Gói linecache có thể được nhập vào Python và sau đó được sử dụng để trích xuất và truy cập các dòng cụ thể trong Python. Gói có thể được sử dụng để đọc đồng thời nhiều dòng. Nó sử dụng lưu trữ bộ đệm để thực hiện tối ưu hóa nội bộ. Gói này tự mở tệp và đến dòng cụ thể. Gói này có phương thức GetLine () được sử dụng cho cùng. & NBSP;

    Syntax: 

    getLine(txt-file, line_number)

    Example:

    Python3

    getLine(txt-file, line_number)
    4
    getLine(txt-file, line_number)
    5

    getLine(txt-file, line_number)
    6=
    getLine(txt-file, line_number)
    8
    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    0
    This is line 5.
    0
    This is line 5.
    1
    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    1

    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    6
    This is line 5.
    4

    Đầu ra:

    This is line 5.

    Phương pháp 3: Enumate ()

    Phương thức liệt kê () được sử dụng để chuyển đổi một chuỗi hoặc đối tượng danh sách thành chuỗi dữ liệu được lập chỉ mục theo số. Sau đó, nó được sử dụng trong danh sách dữ liệu kết hợp với FOR LOOP. Các dòng tại các chỉ mục cụ thể có thể được truy cập bằng cách chỉ định các số chỉ mục cần thiết trong một mảng. & Nbsp;

    Example:

    Python3

    file = open(

    This is line 5.
    9
    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    1

    This is line 1.
    This is line 8.
    This is line 12.
    1=
    This is line 1.
    This is line 8.
    This is line 12.
    3
    getLine(txt-file, line_number)
    0
    This is line 5.
    0
    This is line 1.
    This is line 8.
    This is line 12.
    6____40
    This is line 1.
    This is line 8.
    This is line 12.
    8
    This is line 1.
    This is line 8.
    This is line 12.
    9

    file0 file1file2 file3(file____6666

    file7file8 file9file2 =1

    =2

    s = "@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}@article{noauthor_collective_nodate, title = {Collective teacher efficacy}, abstract = {Overview Influence: Collective teacher efficacy Domain: Teacher Sub-Domain: Teacher attributes Potential to Accelerate Student Achievement: Potential to considerably accelerate Influence Definition: The shared belief by a group of teachers in a particular educational environment that they have the skills to positively impact student outcomes. Evidence Number of meta-analyses: 2 Number of studies: 61 Number of students: 3,489 Number of effects: 61 Effect size: 1.39},}"
    
    
    start = s.find("title = {") + len("title = {")
    end = s.find("}, abstract")
    
    start2 = s.find("Influence Definition: ") + len("Influence Definition: ")
    end2 = s.find("Evidence Number of meta-analyses:")
    
    substring = s[start:end]
    substring2 = s[start2:end2]
    print(substring+' - '+substring2+";")
    
    6=4

    Đầu ra

    This is line 1.
    This is line 8.
    This is line 12.

    Làm cách nào để đọc một phần cụ thể của một tệp trong Python?

    Phương thức 1: FileObject.ReadLines () Một đối tượng tệp có thể được tạo trong python và sau đó readlines () phương thức có thể được gọi trên đối tượng này để đọc các dòng vào một luồng. Phương pháp này được ưa thích khi một dòng hoặc một phạm vi dòng từ tệp cần được truy cập đồng thời.fileobject.readlines() A file object can be created in Python and then readlines() method can be invoked on this object to read lines into a stream. This method is preferred when a single line or a range of lines from a file needs to be accessed simultaneously.

    Làm thế nào trích xuất dữ liệu cụ thể từ chuỗi trong Python?

    Phương pháp số 1: Sử dụng split () Sử dụng hàm chia, chúng ta có thể chia chuỗi thành một danh sách các từ và đây là phương thức chung và được đề xuất nhất nếu người ta muốn hoàn thành nhiệm vụ cụ thể này.Nhưng nhược điểm là nó thất bại trong các trường hợp chuỗi chứa dấu chấm câu.Using split() Using the split function, we can split the string into a list of words and this is the most generic and recommended method if one wished to accomplish this particular task. But the drawback is that it fails in cases the string contains punctuation marks.

    Làm thế nào để bạn trích xuất một đoạn văn từ một tệp văn bản trong Python?

    Làm thế nào để bạn cạo một đoạn văn trong Python ?..
    Nhập mô -đun ..
    Tạo tài liệu HTML và chỉ định thẻ '' vào mã ..
    Chuyển tài liệu HTML vào hàm đẹp () ..
    Sử dụng thẻ 'P' để trích xuất các đoạn văn từ đối tượng đẹp ..
    Nhận văn bản từ tài liệu HTML bằng get_text () ..

    Làm cách nào để trích xuất dữ liệu từ một tệp văn bản?

    Bạn có thể nhập dữ liệu từ một tệp văn bản vào một bảng tính hiện có.Nhấp vào ô nơi bạn muốn đặt dữ liệu từ tệp văn bản.Trên tab Dữ liệu, trong nhóm dữ liệu bên ngoài, nhấp vào từ văn bản. Trong hộp thoại Nhập dữ liệu, định vị và nhấp đúp vào tệp văn bản mà bạn muốn nhập và nhấp vào Nhập.On the Data tab, in the Get External Data group, click From Text. In the Import Data dialog box, locate and double-click the text file that you want to import, and click Import.