日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

python定义了函数却显示未定义_python

發(fā)布時(shí)間:2025/3/11 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python定义了函数却显示未定义_python 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我正在編寫一個(gè)腳本,在我的腳本中,我具有以下功能:

def insert_image(cursor, object_id, sku):

product_obj = core.Object.get(object_id)

string_sku = str(sku)

folder = string_sku[0] + string_sku[1] + string_sku[2]

found_url = False

# KLUDGE This is ugly and redundant, however putting this in an if elif elif else throws error when url not found

# try this url first

try urllib.urlopen("http:///%s/%sPR-IT,PM.jpg" % (folder, sku)):

urllib.URLopener().retrieve("http:///%s/%sPR-IT,PM.jpg" % (folder, sku), "%sPR-IT,PM.jpg" % (sku))

found_url = True

except:

found_url = False

# If that one didn't work try this one

if found_url == False:

try urllib.urlopen("http:///%s/%sPK-PT,PM.jpg" % (folder, sku)):

urllib.URLopener().retrieve("http:///%s/%sPK-PT,PM.jpg" % (folder, sku), "%sPK-PT,PM.jpg" % (sku))

found_url = True

except:

found_url = False

# If still nothing, one last attempt

if found_url == False:

try urllib.urlopen("http:///%s/%sCC-PT,IM.jpg" % (folder, sku)):

urllib.URLopener().retrieve("http:///%s/%sCC-PT,IM.jpg" % (folder, sku), "%sCC-PT,IM.jpg" % (sku))

found_url = True

except:

found_url = False

# We failed to find an image for this product, it will have to be done manually

if found_url == False:

log.info("Could not find the image on notions")

return False

# Hey we found something! Open the image....

send_image = open('%sPK-PT,PM.jpg' % sku, 'r')

# ...and send it for processing

if product_obj.set_image(send_image, 5, 1) == False:

return False

else:

log.debug("Inserted Image")

return True

在我添加嘗試捕獲之前,此方法運(yùn)行良好。 我確實(shí)有if,elif函數(shù)運(yùn)行得很好。 這是我的電話以及在它之前運(yùn)行的代碼的優(yōu)美之處:

if rollback == False:

# Nah -- it's all good SAVE IT!

count += 1

log.debug("INSERT %s" % count)

conn.commit()

else:

# Yeah something went wrong, errors reported why, roll it back

conn.rollback()

log.debug("skipped %s" % skip_count)

# Insert images

if rollback == False:

sku = row[0]

if insert_image(cursor, object_id, sku) == False:

log.error("Could not get the image inserted for product: %s" % object_id)

conn.rollback()

else:

conn.commit()

我的錯(cuò)誤是:

16:33:46,153 DEBUG [pylons-admin] Inserted Description

16:33:46,164 DEBUG [pylons-admin] Inserted Attributes

16:33:46,164 DEBUG [pylons-admin] INSERT 1

Traceback (most recent call last):

File "", line 47, in

NameError: name 'insert_image' is not defined

我不知道第47行是什么意思,因?yàn)樵撜{(diào)用位于第2101行,在我添加嘗試之前,它再次發(fā)現(xiàn)該函數(shù)很好。 當(dāng)我像現(xiàn)在看到的那樣添加嘗試時(shí),我還將第一個(gè)提交切換到insert_image調(diào)用之前,而在我們調(diào)用insert_image之后則提??交之前。 我檢查了縮進(jìn),空格和制表符w /無濟(jì)于事。

我使用TextMate,當(dāng)我從TextMate運(yùn)行腳本時(shí),在這里出現(xiàn)語法錯(cuò)誤:

try urllib.urlopen("http:///%s/%sPR-IT,PM.jpg" % (folder, sku)):

它指向(上的(文件夾。。。但是我看不到語法錯(cuò)誤。請(qǐng)幫忙。我已經(jīng)在這個(gè)腳本上工作了幾周了,這應(yīng)該是最后一次運(yùn)行測(cè)試并稱其為:(

總結(jié)

以上是生活随笔為你收集整理的python定义了函数却显示未定义_python的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。