本文整理汇总了Python中util.readfile函数的典型用法代码示例。如果您正苦于以下问题:Python readfile函数的具体用法?Python readfile怎么用?Python readfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了readfile函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, client, *args, **kwargs):
BaseClass.__init__(self, *args, **kwargs)
self.setupUi(self)
self.client = client
self.client.coopTab.layout().addWidget(self)
#Dictionary containing our actual games.
self.games = {}
#Ranked search UI
self.ispassworded = False
self.loaded = False
self.coop = {}
self.cooptypes = {}
self.canChooseMap = False
self.options = []
self.client.showCoop.connect(self.coopChanged)
self.client.coopInfo.connect(self.processCoopInfo)
self.client.gameInfo.connect(self.processGameInfo)
self.coopList.header().setResizeMode(0, QtGui.QHeaderView.ResizeToContents)
self.coopList.setItemDelegate(CoopMapItemDelegate(self))
self.gameList.setItemDelegate(GameItemDelegate(self))
self.gameList.itemDoubleClicked.connect(self.gameDoubleClicked)
self.coopList.itemDoubleClicked.connect(self.coopListDoubleClicked)
self.coopList.itemClicked.connect(self.coopListClicked)
self.client.coopLeaderBoard.connect(self.processLeaderBoardInfos)
self.tabLeaderWidget.currentChanged.connect(self.askLeaderBoard)
self.linkButton.clicked.connect(self.linkVanilla)
#Load game name from settings (yay, it's persistent!)
self.loadGameName()
self.loadPassword()
self.leaderBoard.setVisible(0)
self.stylesheet = util.readstylesheet("coop/formatters/style.css")
self.FORMATTER_LADDER = unicode(util.readfile("coop/formatters/ladder.qthtml"))
self.FORMATTER_LADDER_HEADER = unicode(util.readfile("coop/formatters/ladder_header.qthtml"))
self.leaderBoard.setStyleSheet(self.stylesheet)
self.leaderBoardTextGeneral.anchorClicked.connect(self.openUrl)
self.leaderBoardTextOne.anchorClicked.connect(self.openUrl)
self.leaderBoardTextTwo.anchorClicked.connect(self.openUrl)
self.leaderBoardTextThree.anchorClicked.connect(self.openUrl)
self.leaderBoardTextFour.anchorClicked.connect(self.openUrl)
self.replayDownload = QNetworkAccessManager()
self.replayDownload.finished.connect(self.finishRequest)
self.selectedItem = None
开发者ID:AThorley,项目名称:lobby,代码行数:60,代码来源:_coopwidget.py
示例2: __init__
def __init__(self, resource):
template = resource['body']
self.errors = []
#For compatibility with older versions, we provide defaults
#In case some attributes are missing
if 'require-permissions' in resource:
self.permissions = resource["require-permissions"]
else:
self.permissions = []
if 'require-method' in resource:
self.methods = resource['require-method']
else:
self.methods = ['POST','GET']
#Yes, I know this logic is ugly.
if 'no-navheader' in resource:
if resource['no-navheader']:
header = util.readfile(os.path.join(directories.htmldir,'pageheader_nonav.html'))
else:
header = util.readfile(os.path.join(directories.htmldir,'pageheader.html'))
else:
header = util.readfile(os.path.join(directories.htmldir,'pageheader.html'))
if 'no-header' in resource:
if resource['no-header']:
header = ""
footer = util.readfile(os.path.join(directories.htmldir,'pagefooter.html'))
templatesource = header + template + footer
self.template = mako.template.Template(templatesource)
开发者ID:volturius,项目名称:KaithemAutomation,代码行数:33,代码来源:usrpages.py
示例3: __init__
def __init__(self, uid, small = False, *args, **kwargs):
QtGui.QListWidgetItem.__init__(self, *args, **kwargs)
self.uid = uid
self.name = None
self.price = None
self.activation = None
self.description = None
self.owned = 0
self.disabled = False
self.small = small
self.reinforcementType = ""
self.canmove = False
if small:
self.FORMATTER_REINFORCEMENT = unicode(util.readfile("galacticwar/formatters/reinforcementSmall.qthtml"))
self.TEXTWIDTH = 100
self.ICONSIZE = 64
self.PADDING = 10
self.WIDTH = self.ICONSIZE + self.TEXTWIDTH
self.HEIGHT = 100
else:
self.FORMATTER_REINFORCEMENT = unicode(util.readfile("galacticwar/formatters/reinforcement.qthtml"))
self.TEXTWIDTH = 370
self.ICONSIZE = 64
self.PADDING = 10
self.WIDTH = self.ICONSIZE + self.TEXTWIDTH
self.HEIGHT = 100
self.setFlags(QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsDropEnabled | QtCore.Qt.ItemIsDragEnabled)
self.setHidden(True)
开发者ID:AThorley,项目名称:lobby,代码行数:31,代码来源:reinforcementItem.py
示例4: page
def page(self,module,dummy2,page,*args,**kwargs):
#Permission handling for pages
if 'require-permissions' in modules.ActiveModules[module][page]:
for i in modules.ActiveModules[module][page]['require-permissions']:
pages.require(i)
with modules.modulesLock: #need to find an alternaive to this lock
if modules.ActiveModules[module][page]['resource-type'] == 'page':
#Allow a page to specify that it can only be accessed via POST or such
if "require-method" in modules.ActiveModules[module][page]:
if cherrypy.request.method not in modules.ActiveModules[module][page]['require-method']:
#Raise a redirect the the wrongmethod error page
raise cherrypy.HTTPRedirect('/errors/wrongmethod')
#This is pretty much the worst perfoming piece of code in the system.
#Every single request it compiles a new template and renders that, but not before loading two files from
#Disk. But I don't feel like writing another ten pages of bookkeeping code today. []TODO
if 'no-navheader' in modules.ActiveModules[module][page]:
if modules.ActiveModules[module][page]['no-navheader']:
header = util.readfile('pages/pageheader_nonav.html')
else:
header = util.readfile('pages/pageheader.html')
else:
header = util.readfile('pages/pageheader.html')
return mako.template.Template(
header+
modules.ActiveModules[module][page]['body']+
util.readfile('pages/pagefooter.html')
).render(
kaithem = kaithem.kaithem,
request = cherrypy.request,
)
开发者ID:JigsawRenaissance,项目名称:KaithemAutomation,代码行数:34,代码来源:usrpages.py
示例5: __init__
def __init__(self, client, *args, **kwargs):
logger.debug("Lobby instantiating.")
BaseClass.__init__(self, *args, **kwargs)
SimpleIRCClient.__init__(self)
self.setupUi(self)
# CAVEAT: These will fail if loaded before theming is loaded
import json
self.OPERATOR_COLORS = json.loads(util.readfile("chat/formatters/operator_colors.json"))
self.client = client
self.channels = {}
#avatar downloader
self.nam = QNetworkAccessManager()
self.nam.finished.connect(self.finishDownloadAvatar)
#nickserv stuff
self.identified = False
#IRC parameters
self.ircServer = IRC_SERVER
self.ircPort = IRC_PORT
self.crucialChannels = ["#aeolus"]
self.optionalChannels = []
#We can't send command until the welcom message is received
self.welcomed = False
# Load colors and styles from theme
self.specialUserColors = json.loads(util.readfile("chat/formatters/special_colors.json"))
self.a_style = util.readfile("chat/formatters/a_style.qss")
#load UI perform some tweaks
self.tabBar().setTabButton(0, 1, None)
#add self to client's window
self.client.chatTab.layout().addWidget(self)
self.tabCloseRequested.connect(self.closeChannel)
#add signal handler for game exit
self.client.gameExit.connect(self.processGameExit)
self.replayInfo = fa.exe.instance.info
#Hook with client's connection and autojoin mechanisms
self.client.connected.connect(self.connect)
self.client.publicBroadcast.connect(self.announce)
self.client.autoJoin.connect(self.autoJoin)
self.client.channelsUpdated.connect(self.addChannels)
self.channelsAvailable = []
self.timer = QtCore.QTimer(self)
self.timer.timeout.connect(self.poll)
# disconnection checks
self.canDisconnect = False
开发者ID:AThorley,项目名称:lobby,代码行数:58,代码来源:_chatwidget.py
示例6: _matcheol
def _matcheol(file, origfile):
"Convert EOL markers in a file to match origfile"
tostyle = _eoltype(util.readfile(origfile))
if tostyle:
data = util.readfile(file)
style = _eoltype(data)
if style:
newdata = data.replace(style, tostyle)
if newdata != data:
util.writefile(file, newdata)
开发者ID:ZanderZhang,项目名称:Andriod-Learning,代码行数:10,代码来源:filemerge.py
示例7: post_run
def post_run():
docs = readfile(corpus_path)
clusters, centers = read_clusters()
voca = readvoca()
outf = open(new_cluster_path, "w")
for i in range(0, len(centers)):
c = clusters[i]
# outf.write( 30*'#'+'cluster '+str(i)+30*'#'+'\n' )
# # subsitute wordid
# words = sorted(centers[i].items(),key=lambda d:d[1],reverse=True)
# outf.write("# ")
# for wid,weight in words[:num_center_words]:
# outf.write( voca[ wid ].encode('gb2312') )
# outf.write( '[%f] ' % weight )
# pass
# outf.write("\n")
tmp_li = sorted(c.items(), key=lambda d: d[1], reverse=True)
for doc_id, sim in tmp_li:
outf.write(docs[doc_id].encode("gb2312") + "\n")
# outf.write( '[%f]\n' % sim )
pass
# the other cluster
c = clusters[-1]
# outf.write( 30*'#'+'cluster others'+30*'#'+'\n' )
tmp_li = sorted(c.items(), key=lambda d: d[1], reverse=True)
for doc_id, sim in tmp_li:
outf.write(docs[doc_id].encode("gb2312"))
# outf.write( '[%f]\n' % sim )
print "[finished]result has been writen to %s" % new_cluster_path
开发者ID:l0he1g,项目名称:codecloud,代码行数:31,代码来源:postprocess.py
示例8: get_item_count
def get_item_count():
reader = readfile(new_train_file)
item_count = defaultdict(lambda: defaultdict(int))
time_item_count = defaultdict(lambda:defaultdict(lambda: defaultdict(int)))
idx = 0
for (__user, sku, category, __query, click_time) in reader:
time_block = get_time_feature(click_time)
idx += 1
item_count[category][sku] += magic_num
time_item_count[time_block][category][sku] += magic_num
item_sort = dict()
for category in item_count:
item_sort[category] = sorted(item_count[category].items(), \
key=lambda x: x[1], reverse=True)
smooth_time_item_count = defaultdict(lambda:defaultdict(lambda: defaultdict(int)))
for time_block in time_item_count:
for cat in time_item_count[time_block]:
for sku in time_item_count[time_block][cat]:
smooth_time_item_count[time_block][cat][sku] = item_count[cat][sku] * 3.0 / block_size
for time_block in time_item_count:
for cat in time_item_count[time_block]:
for sku in time_item_count[time_block][cat]:
smooth_time_item_count[time_block][cat][sku] = time_item_count[time_block][cat][sku]
if time_block == 0 or time_block == MAX_BLOCK:
smooth_time_item_count[time_block][cat][sku] += time_item_count[time_block][cat][sku]
if time_block >= 1:
smooth_time_item_count[time_block][cat][sku] += time_item_count[time_block - 1][cat][sku]
if time_block < MAX_BLOCK:
smooth_time_item_count[time_block][cat][sku] += time_item_count[time_block + 1][cat][sku]
return item_count, item_sort, smooth_time_item_count
开发者ID:harixxy,项目名称:solutions,代码行数:30,代码来源:main.py
示例9: get_bigram_model
def get_bigram_model(item_word, item_sort, cat_count):
hot_sku_words = defaultdict(lambda: defaultdict(set))
for cat in item_word:
for sku in item_word[cat]:
hots = item_word[cat][sku].items()
hot_sku_words[cat][sku] = set([i[0] for i in hots if i[1] >= GLOBAL_BIGRAM_QUERY])
hot_words = dict()
for cat in hot_sku_words:
hot_words[cat] = set()
for sku in hot_sku_words[cat]:
hot_words[cat] = hot_words[cat].union(hot_sku_words[cat][sku])
reader = readfile(new_train_file)
bigram_item_word = defaultdict(lambda: defaultdict(lambda: defaultdict(int)))
idx = 0
for (__user, sku, category, raw_query, ___click_time) in reader:
idx += 1
bound = cat_count[category][HOT_SIZE]
popular = [i[0] for i in item_sort[category][0:bound]]
if sku in popular:
bigram = get_bigram_word(raw_query, hot_words, category)
for w in bigram:
bigram_item_word[category][sku][w] += magic_num
cat_count[category][BIGRAM_HOT] += magic_num
return bigram_item_word, cat_count, hot_words
开发者ID:harixxy,项目名称:solutions,代码行数:27,代码来源:main.py
示例10: read_clusters
def read_clusters():
data = readfile(cluster_path)
clusters = []
centers = []
for line in data: # 每一行一个cluster
if line.startswith("center:"): # 这是一个类中心
center = {}
items = line[8:-1].split(",")
for item in items:
item = item.strip()
if item:
wid, weight = item.split(":")
center[int(wid.strip())] = float(weight.strip())
pass
centers.append(center)
else:
c = {}
docs = line.split(",")
for doc in docs:
id, sim = doc.split(":")
id = int(id)
sim = float(sim)
c[id] = sim
pass
clusters.append(c)
return clusters, centers
开发者ID:l0he1g,项目名称:codecloud,代码行数:26,代码来源:postprocess.py
示例11: lint_file
def lint_file(path, kind):
def import_script(import_path):
# The user can specify paths using backslashes (such as when
# linting Windows scripts on a posix environment.
import_path = import_path.replace('\\', os.sep)
import_path = os.path.join(os.path.dirname(path), import_path)
return lint_file(import_path, 'js')
def _lint_error(*args):
return lint_error(normpath, *args)
normpath = util.normpath(path)
if normpath in lint_cache:
return lint_cache[normpath]
print normpath
contents = util.readfile(path)
lint_cache[normpath] = _Script()
script_parts = []
if kind == 'js':
script_parts.append((None, contents))
elif kind == 'html':
for script in _findhtmlscripts(contents):
if script['type'] == 'external':
other = import_script(script['src'])
lint_cache[normpath].importscript(other)
elif script['type'] == 'inline':
script_parts.append((script['pos'], script['contents']))
else:
assert False, 'Invalid internal script type %s' % \
script['type']
else:
assert False, 'Unsupported file kind: %s' % kind
_lint_script_parts(script_parts, lint_cache[normpath], _lint_error, conf, import_script)
return lint_cache[normpath]
开发者ID:christian-oudard,项目名称:jsl,代码行数:35,代码来源:lint.py
示例12: transform_docs
def transform_docs():
docs = readfile( corpus_path )
outf = open( new_docs_path,'w')
voca = readvoca()
outf.write( "# docs num %d,voca num:%d\n" % (len(docs),len(voca)) )
i = 0
for doc in docs:
doc = doc.split()[-1] # input format has been changed
doc_wn = {} # 统计doc中的每个词的词频
for ch in doc:
if is_ch_char( ch ) and ch in voca:
v_id = voca.index( ch )
if doc_wn.has_key( v_id ):
doc_wn[v_id] += 1 # 第i个词又一次出现
else:
doc_wn[v_id] = 1 # 第i个词第一次出现
pass
# 将doc_wn写文档
#print "write new doc:%d" % i
words_li = ["%d:%d" % (w,n) for w,n in doc_wn.items() ]
words_str = ','.join( words_li )
outf.write( "%d\t%s\n" % (i,words_str) )
i += 1
pass
outf.close()
开发者ID:fangzheng354,项目名称:codecloud,代码行数:25,代码来源:preprocess.py
示例13: loader
def loader():
docdir = os.path.join(util.datapath, 'help')
path = os.path.join(docdir, topic + ".txt")
doc = gettext(util.readfile(path))
for rewriter in helphooks.get(topic, []):
doc = rewriter(topic, doc)
return doc
开发者ID:pierfort123,项目名称:mercurial,代码行数:7,代码来源:help.py
示例14: invoke_mutabelle
def invoke_mutabelle(theory, env, case, paths, dep_paths, playground):
"""Mutant testing for counterexample generators in Isabelle"""
(loc_isabelle,) = paths
(dep_isabelle,) = dep_paths
more_settings = '''
ISABELLE_GHC="/usr/bin/ghc"
'''
prepare_isabelle_repository(loc_isabelle, dep_isabelle, more_settings = more_settings)
os.chdir(loc_isabelle)
(return_code, log) = env.run_process('bin/isabelle',
'mutabelle', '-O', playground, theory)
try:
mutabelle_log = util.readfile(path.join(playground, 'log'))
except IOError:
mutabelle_log = ''
mutabelle_data = dict(
(tool, {'counterexample': c, 'no_counterexample': n, 'timeout': t, 'error': e})
for tool, c, n, t, e in re.findall(r'(\S+)\s+: C: (\d+) N: (\d+) T: (\d+) E: (\d+)', log))
return (return_code == 0 and mutabelle_log != '', extract_isabelle_run_summary(log),
{'mutabelle_results': {theory: mutabelle_data}},
{'log': log, 'mutabelle_log': mutabelle_log}, None)
开发者ID:ghosthamlet,项目名称:isabelle,代码行数:27,代码来源:mira.py
示例15: read_pls
def read_pls(self, plsname):
"""
This is the (pls) playlist reading function.
Arguments: plsname - the playlist filename
Returns: The list of interesting lines in the playlist
"""
try:
lines = util.readfile(plsname)
except IOError:
print String(_('Cannot open file "%s"')) % list
return 0
playlist_lines_dos = map(lambda l: l.strip(), lines)
playlist_lines = filter(lambda l: l[0:4] == 'File', playlist_lines_dos)
for line in playlist_lines:
numchars=line.find("=")+1
if numchars > 0:
playlist_lines[playlist_lines.index(line)] = \
line[numchars:]
(curdir, playlistname) = os.path.split(plsname)
os.chdir(curdir)
for line in playlist_lines:
if line.endswith('\r\n'):
line = line.replace('\\', '/') # Fix MSDOS slashes
if line.find('://') > 0:
self.playlist.append(line)
elif os.path.isabs(line):
if os.path.exists(line):
self.playlist.append(line)
else:
if os.path.exists(os.path.abspath(os.path.join(curdir, line))):
self.playlist.append(os.path.abspath(os.path.join(curdir, line)))
开发者ID:golaizola,项目名称:freevo1,代码行数:35,代码来源:playlist.py
示例16: readvoca
def readvoca():
voca = []
lines = readfile( voca_path )
for line in lines:
id,w,n = line.split()
n = int(n)
if n>1:
voca.append( w )
return voca
开发者ID:fangzheng354,项目名称:codecloud,代码行数:9,代码来源:preprocess.py
示例17: load
def load(self, t):
'''Get the template for the given template name. Use a local cache.'''
if not t in self.cache:
try:
self.cache[t] = util.readfile(self.map[t][1])
except KeyError, inst:
raise util.Abort(_('"%s" not in template map') % inst.args[0])
except IOError, inst:
raise IOError(inst.args[0], _('template file %s: %s') %
(self.map[t][1], inst.args[1]))
开发者ID:rybesh,项目名称:mysite-lib,代码行数:10,代码来源:templater.py
示例18: read_ssr
def read_ssr(self, ssrname):
"""
This is the (ssr) slideshow reading function.
File line format::
FileName: "image file name"; Caption: "caption text"; Delay: "sec"
The caption and delay are optional.
@param ssrname: the slideshow filename
@returns: the list of interesting lines in the slideshow
"""
(curdir, playlistname) = os.path.split(ssrname)
os.chdir(curdir)
out_lines = []
try:
lines = util.readfile(ssrname)
except IOError:
print String(_('Cannot open file "%s"')) % list
return 0
playlist_lines_dos = map(lambda l: l.strip(), lines)
playlist_lines = filter(lambda l: l[0] != '#', lines)
# Here's where we parse the line. See the format above.
for line in playlist_lines:
tmp_list = []
ss_name = re.findall('FileName: \"(.*?)\"', line, re.I)
ss_caption = re.findall('Caption: \"(.*?)\"', line, re.I)
ss_delay = re.findall('Delay: \"(.*?)\"', line, re.I)
if ss_name != []:
if ss_caption == []:
ss_caption += [""]
if ss_delay == []:
ss_delay += [5]
for p in self.get_plugins:
if os.path.isabs(ss_name[0]):
curdir = ss_name[0]
else:
curdir = os.path.abspath(os.path.join(curdir, ss_name[0]))
for i in p.get(self, [curdir]):
if i.type == 'image':
i.name = Unicode(ss_caption[0])
i.duration = int(ss_delay[0])
self.playlist.append(i)
break
self.autoplay = True
开发者ID:golaizola,项目名称:freevo1,代码行数:52,代码来源:playlist.py
示例19: __init__
def __init__(self, client):
super(BaseClass, self).__init__()
self.setupUi(self)
self.client = client
client.ladderTab.layout().addWidget(self)
self.client.statsInfo.connect(self.processStatsInfos)
self.client = client
self.webview = QtWebKit.QWebView()
self.globalTab.layout().addWidget(self.webview)
self.loaded = False
self.client.showLadder.connect(self.updating)
self.webview.loadFinished.connect(self.webview.show)
self.leagues.currentChanged.connect(self.leagueUpdate)
self.pagesDivisions = {}
self.pagesDivisionsResults = {}
self.pagesAllLeagues = {}
self.floodtimer = time.time()
self.currentLeague = 0
self.currentDivision = 0
self.FORMATTER_LADDER = unicode(util.readfile("stats/formatters/ladder.qthtml"))
self.FORMATTER_LADDER_HEADER = unicode(util.readfile("stats/formatters/ladder_header.qthtml"))
self.stylesheet = util.readstylesheet("stats/formatters/style.css")
self.leagues.setStyleSheet(self.stylesheet)
#setup other tabs
self.mapstat = mapstat.LadderMapStat(self.client, self)
开发者ID:IDragonfire,项目名称:modular-client,代码行数:38,代码来源:_statswidget.py
示例20: get_unigram_model
def get_unigram_model(item_sort, cat_count):
reader = readfile(new_train_file)
item_word = defaultdict(lambda: defaultdict(lambda: defaultdict(int)))
cat_word = defaultdict(lambda: defaultdict(int))
idx = 0
for (__user, sku, category, raw_query, ___click_time) in reader:
idx += 1
bound = cat_count[category][HOT_SIZE]
popular = [i[0] for i in item_sort[category][0:bound]]
if sku in popular:
words = get_words(raw_query)
for w in words:
item_word[category][sku][w] += magic_num
cat_word[category][w] += magic_num
return item_word, cat_word
开发者ID:harixxy,项目名称:solutions,代码行数:15,代码来源:main.py
注:本文中的util.readfile函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论