0

私はPythonの初心者で、まだ外出先で学習中です...

テスト対象デバイス (DUT) にロードするイメージのリストを持つ Web サーバーがあります ...

要件は次のとおりです。

画像がサーバーに既に存在する場合は、DUT への画像のロードに進みます。

イメージがサーバーに存在しない場合は、イメージのダウンロードに進み、DUT をアップグレードします。

私は次のコードを書きましたが、これを書いた方法にはまったく満足していません.

改善できた箇所とそのテクニックを教えてください。

このメールをお読みいただき、貴重なご意見をお寄せいただきありがとうございます。

import urllib2

url = 'http://localhost/test'
filename = 'Image60.txt'   # image to Verify

def Image_Upgrade():
    print 'proceeding with Image upgrade !!!'

def Image_Download():
    print 'Proceeding with Image Download !!!'

resp = urllib2.urlopen(url)
flag = False
list_of_files = []
for contents in resp.readlines():
    if 'Image' in contents:
        c=(((contents.split('href='))[-1]).split('>')[0]).strip('"')  # The content output would have html tags. so removing the tags to pick only image name
        if c != filename:
            list_of_files.append(c)
        else:
            Image_Upgrade()
            flag = True
if flag==False:
    Image_Download()

ありがとう、ビジェイ・スワミナサン

4

0 に答える 0