我正在编写一小段代码,将保存的文档中的web服务器页面的etag与服务器上的etag进行比较。如果它们不同,代码将指示这一点。我的密码是下图:-你知道吗
import httplib
def currentTag():
f = open('C:/Users/ME/Desktop/document.txt')
e = f.readline()
newTag(e)
def newTag(old_etag):
c = httplib.HTTPConnection('standards.ieee.org')
c.request('HEAD', '/develop/regauth/oui/oui.txt')
r = c.getresponse()
current_etag = r.getheader('etag').replace('"', '')
compareTag(old_etag, current_etag)
def compareTag(old_etag, current_etag):
if old_etag == current_etag:
print "the same"
else:
print "different"
if __name__ == '__main__':
currentTag()
现在,回顾一下我的代码,实际上没有理由将“etag”从currentTag()
方法传递到newTag()
方法,因为在newTag()
中没有处理预先存在的etag。尽管如此,如果我不这样做,我怎么能把两个不同的值传递给compareTag()
。例如,在定义compareTag()
时,如何从currentTag()
方法传递“etag”和从newTag()
方法传递“current”呢?你知道吗
将主菜单更改为:
然后让
currentTag()
返回e和newTag()
返回当前的etag你不应该像这样链接你的函数调用,有一个连续调用函数的主要代码块,比如:
调整函数以返回相关数据
函数的基本思想是返回数据,通常使用函数进行一些处理并返回值,而不是用于控制流。你知道吗
相关问题 更多 >
编程相关推荐