我需要状态从改变DISABLED到NORMAL的Button,当一些事件发生.
这是我的Button的当前状态,目前已禁用:
self.x = Button(self.dialog, text="Download",
state=DISABLED, command=self.download).pack(side=LEFT)
self.x(state=NORMAL) # this does not seem to work
Run Code Online (Sandbox Code Playgroud)
anyonne可以帮助我如何做到这一点?
我想Content-Length从元变量中获取值.我需要获取我要下载的文件的大小.但是最后一行返回错误,HTTPMessage对象没有属性getheaders.
import urllib.request
import http.client
#----HTTP HANDLING PART----
url = "http://client.akamai.com/install/test-objects/10MB.bin"
file_name = url.split('/')[-1]
d = urllib.request.urlopen(url)
f = open(file_name, 'wb')
#----GET FILE SIZE----
meta = d.info()
print ("Download Details", meta)
file_size = int(meta.getheaders("Content-Length")[0])
Run Code Online (Sandbox Code Playgroud) 我正在开发一个下载管理器.使用python中的请求模块来检查有效链接(并希望破坏链接).我检查以下链接的代码:
url='http://pyscripter.googlecode.com/files/PyScripter-v2.5.3-Setup.exe'
r = requests.get(url,allow_redirects=False) #this line takes 40 seconds
if r.status_code==200:
print "link valid"
else:
print "link invalid"
Run Code Online (Sandbox Code Playgroud)
现在,问题是执行此检查需要大约40秒,这是巨大的.我的问题是如何使用urllib2或其他东西加快速度呢?
注意:如果我替换url为实际的URL" http://pyscripter.googlecode.com/files/PyScripter-v2.5.3-Setup.exe ",这需要一秒钟,因此它似乎是请求的问题.
我正在使用该代码块,并由代码验证器告知应该对其进行清理。
它有什么问题,我该如何消毒?
el1 = document.getElementById('quote'); //this is fine
el1.innerHTML = quoteNew; //this should be sanitized
Run Code Online (Sandbox Code Playgroud) 如何在python中为现有文件追加新行?
我的代码是:
status_done="Completed"
f = open("%s\%s%s" % (path,self.filename,filelog_ext),"a")
data=("%s \r" % status_done)
f.writelines(data)
Run Code Online (Sandbox Code Playgroud)
我试过\ r,\n,两个\ r \n都没有工作,它总是附加到现有行的末尾
这是它给我的输出:
我希望Completed在新的一行,即:
第1行:http://www.md5.com
2号线:已完成
好吧,我在.txt文件中有一个电话簿,我想要做的是找到这个模式的所有数字,例如829-2234,并将数字5附加到数字的开头.
所以结果现在变成了5829-2234.
我的代码开头是这样的:
import os
import re
count=0
#setup our regex
regex=re.compile("\d{3}-\d{4}\s"}
#open file for scanning
f= open("samplex.txt")
#begin find numbers matching pattern
for line in f:
pattern=regex.findall(line)
#isolate results
for word in pattern:
print word
count=count+1 #calculate number of occurences of 7-digit numbers
# replace 7-digit numbers with 8-digit numbers
word= '%dword' %5
Run Code Online (Sandbox Code Playgroud)
好吧,我真的不知道如何附加前缀5,然后用7位数字和5前缀覆盖7位数字.我试了几件但都失败了:/
任何提示/帮助将不胜感激:)
谢谢