码:
import urllib2 as u
import os as o
inn = 'dword.txt'
w = open(inn)
z = w.readline()
b = w.readline()
c = w.readline()
x = w.readline()
m = w.readline()
def Dict(Let, Mod):
global str
inn = 'dword.txt'
den = 'definitions.txt'
print 'reading definitions...'
dell =open(den, 'w')
print 'getting source code...'
f = u.urlopen('http://dictionary.reference.com/browse/' + Let)
a = f.read(800)
print 'writing source code to file...'
f = open("dic1.txt", "w")
f.write(a)
f.close()
j = open('defs.txt', 'w')
print 'finding definition is source …Run Code Online (Sandbox Code Playgroud) 有没有人知道如何使用没有黑色控制台的py2exe运行exe?并将所有pyd文件等捆绑到一个exe文件中?
所以我有代码:
import glob,os
import random
path = 'C:\\Music\\'
aw=[]
for infile in glob.glob( os.path.join(path,'*.mp3') ):
libr = infile.split('Downloaded',1)
aw.append(infile)
aww = -1
while 1:
aww += 1
print len(aw),aww
random.shuffle(aw)
awww = aw[aww]
os.startfile(awww)
Run Code Online (Sandbox Code Playgroud)
但它所做的就是不停地浏览所有歌曲.我想如果我能找到当前正在播放的歌曲的长度,我可以使用"时间"模块继续歌曲完成后使用(sleep)属性.但是,我找不到如何在Windows上获取歌曲的长度.有谁知道我的问题的解决方案?
有谁知道如何更换所有\与\\Python中?我试过了:
re.sub('\','\\',string)
Run Code Online (Sandbox Code Playgroud)
但由于逃脱序列,它将其搞砸了.有谁知道我问题的问题?
所以我有这个代码:
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders
import os
def sendMail(to, subject, text, files=[],server="smtp.gmail.com:587"):
assert type(to)==list
assert type(files)==list
fro = "psaoflamand@live.com>"
msg = MIMEMultipart()
msg['From'] = fro
msg['To'] = COMMASPACE.join(to)
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = subject
msg.attach( MIMEText(text) )
a=0
username = 'psaoflamand@gmail.com'
password = 'pass'
# The actual mail send
smtp = smtplib.SMTP(server)
smtp.starttls()
smtp.login(username,password)
for file in files:
a+=1
print a …Run Code Online (Sandbox Code Playgroud) 我制作了一个带有pygame代码的MP3播放器:
from Tkinter import *
import pygame
import glob
import tkFont
songs=[]
for x in glob.glob('C:\WhaleTunes\Downloaded/*mp3'):
songs.append(x)
Admin=Tk()
num=0
plpa=-1
songas=Label(Admin,text='',bg='red')
songas.place(relx=0.0,rely=0.7)
def play(number):
pygame.mixer.music.unpause()
pygame.mixer.music.load(songs[number])
pygame.mixer.music.play()
songas.configure(text=songs[number])
def pause():
pygame.mixer.music.pause()
def Pre():
global num
if num == 0:
z = len(songs)
num=z
num+=1
num-=1
play(num)
def Next():
global num
num+=1
play(num)
#init pygame mixer
pygame.mixer.init()
#atach all buttons & labels
fons=tkFont.Font(family="bold", size=40)
fon=tkFont.Font(family="Helvetica", size=20)
tit=Label(Admin,text='Mp3 Player',font=fons,fg='grey',bg='red')
tit.place(relx=0.2,rely=0.0)
playnpause=Button(Admin,text='Play',command=lambda:play(num),fg='yellow',bg='red',font=fon)
playnpause.place(relx=0.0,rely=0.4)
last=Button(Admin,text='Previous',command=Pre,fg='yellow',bg='red',font=fon)
last.place(relx=0.2,rely=0.4)
first=Button(Admin,text='Next',command=Next,fg='yellow',bg='red',font=fon)
first.place(relx=0.5,rely=0.4)
pauses=Button(Admin,text='Pause',command=pause,fg='yellow',bg='red',font=fon)
pauses.place(relx=0.7,rely=0.4)
Admin.minsize(width=500, height=200)
Admin.maxsize(width=500, height=200) …Run Code Online (Sandbox Code Playgroud) 是否有可能使Tkinter按钮调用两个函数?
这样的事可能吗?:
from Tkinter import *
admin = Tk()
def o():
print '1'
def t():
print '2'
button = Button(admin, text='Press', command=o, command=t)
button.pack()
Run Code Online (Sandbox Code Playgroud) 我有这个代码:
# File: zipfile-example-1.py
import zipfile,os,glob
file = zipfile.ZipFile("Apap.zip", "w")
# list filenames
for name in glob.glob("C:\Users/*"):
print name
file.write(name,os.path.basename(name),zipfile.ZIP_DEFLATED)
file = zipfile.ZipFile("Apap.zip", "r")
for info in file.infolist():
print info.filename, info.date_time, info.file_size, info.compress_size
Run Code Online (Sandbox Code Playgroud)
产生此错误:
raceback (most recent call last):
File "C:/Users/Desktop/zip.py", line 11, in <module>
file = zipfile.ZipFile("Apap.zip", "r")
File "C:\Python27\lib\zipfile.py", line 712, in __init__
self._GetContents()
File "C:\Python27\lib\zipfile.py", line 746, in _GetContents
self._RealGetContents()
File "C:\Python27\lib\zipfile.py", line 761, in _RealGetContents
raise BadZipfile, "File is not a zip file"
BadZipfile: File is …Run Code Online (Sandbox Code Playgroud)