当前位置: 首页>>代码示例>>Python>>正文


Python FileSystem.getFileContents方法代码示例

本文整理汇总了Python中FileSystem.FileSystem.getFileContents方法的典型用法代码示例。如果您正苦于以下问题:Python FileSystem.getFileContents方法的具体用法?Python FileSystem.getFileContents怎么用?Python FileSystem.getFileContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileSystem.FileSystem的用法示例。


在下文中一共展示了FileSystem.getFileContents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from FileSystem import FileSystem [as 别名]
# 或者: from FileSystem.FileSystem import getFileContents [as 别名]
class Console:

	dateFormat = "%a %b %d %Y";
	timeFormat = "%H:%M:%S";
	completeDateFormat = "%a %b %d %Y %H:%M:%S";
	variableFile = os.path.join(".","misc","variables.txt");
	
	NOT_CONNECTED_MSG = "Not connected to server.";
	
	class RandomGenerator:
		REROLL_CHANCES = (1.00, 0.96, 0.94, 0.85, 0.70, 0.60);
		MAX_REROLLS = 8;
		HISTORY_LEN = 30;
		
		def __init__(self):
			self.rollHistory = []; # in form (lower,upper,result)
		
		def randInt(self, lowerBound, upperBound):
			result = None;
			done = 0;
			rerolls = 0;
			while (not done):
				result = random.randint(lowerBound,upperBound);
				boundMatches = 0;
				done = 1;
				for roll in self.rollHistory:
					if (roll[0] == lowerBound and roll[1] == upperBound):
						boundMatches += 1;
					if (roll[2] == result and boundMatches < len(self.REROLL_CHANCES) and random.random() < self.REROLL_CHANCES[boundMatches-1] and rerolls < self.MAX_REROLLS):
						done = 0;
						rerolls += 1;
						break;
			self.rollHistory = [[lowerBound,upperBound,result],] + self.rollHistory;
			return result;
	
	def __init__(self, logFile):
		self.lastDate = "";
		self.lastLogDate = "";
		
		self.logFile = logFile;
		self.active = 1;
		
		self.threads = {}; # threads and timers
		self.connection = None;
		
		self.fileSystem = FileSystem(self);
		
		self.responseSystem = ResponseSystem();
		self.responseSystem.console = self;
		self.responseSystem.refreshIndex();
		self.responseSystem.fileSystem = self.fileSystem;
		
		self.reconnectAttempts = 0;
		
		self.random = self.RandomGenerator();
		
		self.reloadVariables();
	
	def saveVariables(self):
		""" Saves all of the bot's variables. """
		fileLines = [];
		for varName, varValue in self.variables.items():
			if (varValue != "" and varValue != ""):
				if (type(varValue) == str):
					fileLines.append(varName+" \""+varValue+"\"");
				else:
					fileLines.append(varName+" "+str(varValue));
		self.fileSystem.save(self.variableFile,fileLines);
	
	def reloadVariables(self):
		""" Reloads all of the bot's variables directly from the file. """
		self.variables = {};
		variableFile = self.fileSystem.getFileContents(self.variableFile,0);
		for variableLine in variableFile:
			variableLine = variableLine.split(" ",1);
			if (len(variableLine) > 1):
				self.variables[variableLine[0]] = variableLine[1];
				if (self.variables[variableLine[0]][0:1] == "\"" and self.variables[variableLine[0]][-1:] == "\""):
					self.variables[variableLine[0]] = self.variables[variableLine[0]][1:-1];
				else:
					try:
						if (self.variables[variableLine[0]].count(".")):
							self.variables[variableLine[0]] = float(self.variables[variableLine[0]]);
						else:
							self.variables[variableLine[0]] = int(self.variables[variableLine[0]]);
					except ValueError:
						del(self.variables[variableLine[0]]);
			if (self.variables.has_key(variableLine[0]) and self.variables[variableLine[0]] == ""):
				del self.variables[variableLine[0]];
	
	def getVar(self, varName):
		if (self.variables.has_key(varName)):
			return self.variables[varName];
		else:
			return "";
	
	def setVar(self, varName, varValue):
		if (self.variables.has_key(varName) and varValue == ""):
			del self.variables[varName];
		else:
#.........这里部分代码省略.........
开发者ID:mbkloster,项目名称:platopus,代码行数:103,代码来源:Console.py


注:本文中的FileSystem.FileSystem.getFileContents方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。