小编P's*_*sao的帖子

TypeError:'str'对象不可调用(Python)

码:

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)

python

59
推荐指数
10
解决办法
48万
查看次数

在没有控制台的情况下运行py2exe exe?

有没有人知道如何使用没有黑色控制台的py2exe运行exe?并将所有pyd文件等捆绑到一个exe文件中?

python py2exe

15
推荐指数
1
解决办法
1万
查看次数

查找mp3文件的长度

所以我有代码:

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 mp3

14
推荐指数
4
解决办法
2万
查看次数

用"\\"python替换所有"\"

有谁知道如何更换所有\\\Python中?我试过了:

re.sub('\','\\',string)
Run Code Online (Sandbox Code Playgroud)

但由于逃脱序列,它将其搞砸了.有谁知道我问题的问题?

python regex

14
推荐指数
2
解决办法
4万
查看次数

在Tkinter中播放视频文件的方法?

有没有办法播放像AVI,MP4等视频文件?

我尝试使用PyMedia,但显然它只适用于Pygame.

我的问题有什么解决方案?

python video tkinter

13
推荐指数
1
解决办法
3万
查看次数

透明的颜色Tkinter

是否可以将框架背景或任何其他窗口小部件的颜色更改为透明浅蓝色或任何其他透明色?

tkinter

6
推荐指数
1
解决办法
8428
查看次数

如何清除MIMEBase(电子邮件模块)中的所有数据

所以我有这个代码:

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)

python email

5
推荐指数
1
解决办法
2277
查看次数

打开我的Pygame程序的EXE会给我导入错误

我制作了一个带有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)

python pygame py2exe

4
推荐指数
1
解决办法
6102
查看次数

tkinter调用两个函数

是否有可能使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)

python tkinter

3
推荐指数
2
解决办法
1万
查看次数

Zipfile模块错误:文件不是zip文件

我有这个代码:

# 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)

python

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×9

tkinter ×3

py2exe ×2

email ×1

mp3 ×1

pygame ×1

regex ×1

video ×1