الگو دادن به اسکریپت پایتون برای پیدا کردن قسمتی خاص در متن

ساخت وبلاگ
سلام

دارم یه اسکریپت می‌نویسم که سورسش این شده تا الان:

#!/bin/python3

# Import needed modules
import sys
import os
import re

# clear Screen
os.system("clear")

# Get Video and Sub from Argument
subtitle = (sys.argv[1])
video = (sys.argv[2])

# Get key from user
key_ints = input("What is your Key? ")

# open file and read it
with open(subtitle, 'r') as open_read:
    for line in open_read:
        if key_ints in line:
            print(line)

           

قسمت آخر سورس ما هر کلمه‌ای را که به عنوان key_input داده ایم پیدا می‌کند برای مثال:

[hossein@ArchLinux Scripts]$ ./subvid Gods.of.Egypt.2016.1080p.WEB-DL.DD5.1.H264-RARBG.srt go.go
What is your Key? help
He'll help us with our task.

i need your help. Please!

I thought he was helping you.

please, help us!

Let me help you.

thoth for help.

But you have to help us!

I didn't want her help.

My duty was to help

I'm helping horus.

he's going to help us.

get you to help him?

Perhaps we can help her.

she's trying to help us.

i ask for your help.

want to help her.

to go help a friend.

[hossein@ArchLinux Scripts]$

حالا من می‌خوام به آن الگویی دهم که به جای این که خط را برای من چاپ کند برود و آخرین قسمت عددی را برای من چاپ کند منظورم اینه که اگر کلمه‌ی Egypt را به عنوان Key_input دادم به جای اینکه اون خط را چاپ کند عبارت 00:01:05,499 --> 00:01:08,500 را چاپ کند که آخرین خط عددی من هست, متن اصلی این است:

00:01:05,499 --> 00:01:08,500
<i> Egypt was the birthplace</i>
<i> of all life.</i>

اما اسکریپت من فقط Egypt was the birthplace را چاپ می‌کند!

اوبونتو...
ما را در سایت اوبونتو دنبال می کنید

برچسب : نویسنده : استخدام کار ubuntu بازدید : 157 تاريخ : چهارشنبه 5 خرداد 1395 ساعت: 22:57