最近在学习python,楼主练习写个程序遇到个问题,好像是全局变量的问题吧,我用return时能正常,但写GUI时不会用return了,结果读不进数据,有python高手请指导下。
普通程序:(能正常执行)
#读取路权矩阵
def readdata(D0,S0,D1,S1,list):
fpr=open("d.txt")
k=0
for line in fpr:
k+=1
D0[k]={}
S0[k]={}
S1[k]={}
......................
阅读全部
|
lenhal
贴于 2012年12月16日 00:17
hide
bbsi
# 在这里找到一个解决方案 http://www.linuxdiyf.com/viewarticle.php?id=145791
# 不过几十个文件挨个改太麻烦了,用这个脚本可以自动修改,放在/usr/share/applications/kde4/里面运行
# 记得运行前备份kde4文件夹
import os
for f in os.listdir('.'):
s = open(f).read()
if not 'OnlyShowIn=KDE' in s:
s = s + "\nOnlyShowIn=KDE"
file(f, 'w').write(s)
print f
......................
阅读全部
|
静夜思
贴于 2012年3月28日 23:07
hide
bbsi
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
from django import template
from django.conf import settings
register = template.Library()
class SassNode(template.Node):
def __init__(self, format_string):
self.format_string = format_string
......................
阅读全部
|
静夜思
贴于 2012年3月15日 21:46
hide
bbsi
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
from django import template
from django.conf import settings
register = template.Library()
class SassNode(template.Node):
def __init__(self, format_string):
self.format_string = format_string
......................
阅读全部
|
静夜思
贴于 2012年3月15日 08:16
hide
bbsi
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import commands
import os
import re
import urllib
import urllib2
"""
这段脚本能帮你自动下载安装最新版的rails,如果缺少相关的gem包则递归下载相应的gem包,直到安装成功为止
by BCCN.静夜思 2011.11.11
......................
阅读全部
|
静夜思
贴于 2011年11月12日 09:01
hide
bbsi
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
检测XP系统进程和系统服务
把可疑的进程和服务列出来(以我自己的电脑为参考)
启动项检测挺麻烦的,我的电脑上只有3个(只有一个ctfmon.exe是必需的,另两个是google相关的update程序),到“CCleaner-工具-启动”查看和设置可以了
使用本脚本可以一定程度上检测恶意程序,追求更高的安全还得靠杀毒软件
2011.11.07 BCCN.静夜思
'''
import os
......................
阅读全部
|
静夜思
贴于 2011年11月7日 12:35
hide
bbsi
#!/usr/bin/python
# -*- coding: UTF-8 -*
'''
传言需要写10万行代码才能真正熟手,统计一下你写了多少行代码了
把本代码保存为.py为后缀的文件放在你要统计的文件夹里面,双击运行即可,前提是你的系统装了python
注意要保存为UTF-8编码的文件
by BCCN.静夜思
'''
import os
......................
阅读全部
|
静夜思
贴于 2011年10月28日 09:24
hide
bbsi
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#方法一
l = ['aadfds','dsa', 'dcver','weiry','11111']
l = [x for x in l if 'a' not in x] #列表解析
print l
#方法二
l = ['aadfds','dsa', 'dcver','weiry','11111']
l = filter(lambda x:'a' not in x, l) #filter
print l
......................
阅读全部
|
静夜思
贴于 2011年10月28日 06:15
hide
bbsi
#!/usr/bin/python
# -*- coding: UTF-8 -*-
def subString(s, length):
us = unicode(s, 'utf-8')
gs = us.encode('gb2312')
n = int(length)
t = gs[:n]
while True:
try:
unicode(t, 'gbk')
break
......................
阅读全部
|
静夜思
贴于 2011年10月28日 06:14
hide
bbsi
# Author: Fred L. Drake, Jr.
# fdrake@acm.org
#
# This is a simple little module I wrote to make life easier. I didn't
# see anything quite like it in the library, though I may have overlooked
# something. I wrote this when I was trying to read some heavily nested
# tuples with fairly non-descriptive content. This is modeled very much
# after Lisp/Scheme - style pretty-printing of lists. If you find it
# useful, thank small children who sleep at night.
"""Support to pretty-print lists, tuples, & dictionaries recursively.
......................
阅读全部
|
静夜思
贴于 2011年10月28日 06:13
hide
bbsi