关于Python的小问题

songrongu111 2009-07-15 10:44:10
def builidConnectionString(params):
"""Builid a connection string from a dictionary of parameters.

Return string."""
return":".join(["%s=%s" % (k,v)for k,v in params()])

if__name__=="__main__" :
myParams={"dfdf":"fdfdf",\
"fdfd":"fdfdfdfd"\
}
print buildConnectionString(myParams)



为什么这个程序不能运行 出错误提示我 是 if name ==“ main ” 后面这个 冒号:
...全文
33 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
songrongu111 2009-07-16
  • 打赏
  • 举报
回复
非常感谢
songrongu111 2009-07-16
  • 打赏
  • 举报
回复
我试着做一个备份用Python2.6 ,结果确失败了 , 请指点一下
import os
import time

source=[r'C:\Python26\if.py',r'C:\Python26\for.py']

target_dir=r'C:\Python'

target=target_dir+time.strftime('%Y%m%d%H%M%S')+'.zip'

zip_command="zip -qr '%s' %s" % (target,''.join(source))

if os.system(zip_command)==0:
print 'Successful backup to',target
else:
print 'Backup FAILED'

运行后 Backup FAILED
neverfailor 2009-07-15
  • 打赏
  • 举报
回复
你if后面没加空格
其次
return":".join(["%s=%s" % (k,v)for k,v in params()])
要改成
return ":".join(["%s=%s" % (k,v)for k,v in params.items()])
因为是字典!所以要加item方法!

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧