本文整理汇总了Python中file.File.save方法的典型用法代码示例。如果您正苦于以下问题:Python File.save方法的具体用法?Python File.save怎么用?Python File.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类file.File
的用法示例。
在下文中一共展示了File.save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: consume
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import save [as 别名]
def consume(lock, graphs, done, critical):
while done.empty():
try:
g = graphs.get(block=True, timeout=5)
d = DalGraph(graph=g, logger=LOGGER)
if d.critical_aprox():
f = File(DIRECTORY, G=g, logger=LOGGER)
fp = f.save()
if fp is not None:
critical.put(fp)
except Empty:
#print("Empty")
pass
return
示例2: make_clique
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import save [as 别名]
# create forbidden graph
k4 = make_clique(XCHROMATIC)
co_k4 = complement(make_clique(4))
# these constants are what should change
FAMILY = "Line(Co-K4)-free"
DIRECTORY = join(getcwd(), 'GraphFamilies', FAMILY)
FORBIDDEN = forbidden_line_subgraphs() + [co_k4, k4]
print(FORBIDDEN)
STARTING = make_cycle(7)
BASE = "C5"
logging.basicConfig(filename=FAMILY + BASE + ".log", level=logging.INFO,
format='%(asctime)s %(message)s')
LOGGER = logging.getLogger(__name__)
# processing work
generator = Generator2(STARTING, 10, FORBIDDEN)
index = 0
print("Started")
checked = 0
for graph in generator.iterate():
if len(coloring(graph, logger=LOGGER)) >= XCHROMATIC:
f = File(DIRECTORY, G=graph, logger=LOGGER, base="C5-")
fp = f.save()
if fp is not None:
index += 1
print("Created Graph: %d" % index)
checked += 1
if checked % 100 == 0:
print("Checked %d Graphs" % checked)
LOGGER.info("Complete")
print("Total Graphs Created: %d" % index)
示例3: Game
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import save [as 别名]
class Game():
def __init__(self):
self.config = Config()
self.config.load('config.yaml')
self.cellfont = pygame.font.SysFont('arial',10)
self.file = File()
self.fpsClock = pygame.time.Clock()
self.load()
def setupCell(self, cell, char):
if char == "S":
cell.setStart()
self.grid.startSet = 1
elif char == "F":
cell.setTarget()
self.grid.targetSet = 1
elif char == "#":
cell.wall = 1
def reset(self):
keys = pygame.key.get_pressed()
self.solving = 0
self.openList = []
self.closedList = []
if keys[K_LSHIFT]:
self.grid = Grid(
self.grid.width,
self.grid.height,
self.grid.cell_width,
self.grid.cell_height,
self.surface,
self
)
else:
for cell in self.grid.cells:
cell.path = 0
cell.highlight = 0
cell.current = 0
cell.f, cell.g, cell.h = (0, 0, 0)
cell.neighbours = []
cell.drawText = 0
self.grid.draw()
def start(self):
print 'starting game loop'
while True:
for event in pygame.event.get(QUIT): # get all the QUIT events
print 'quit'
pygame.quit()
sys.exit()
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONUP:
self.grid.handleClick(event)
if event.type == pygame.KEYUP:
if event.key == K_SPACE:
if not self.solving:
self.solve()
if event.key == K_ESCAPE:
self.reset()
if event.key == K_s:
self.save()
if event.key == K_l:
self.surface = None
self.load()
pygame.display.update()
self.fpsClock.tick(self.fps)
def solve(self):
if self.grid.startSet and self.grid.targetSet:
print 'Solving'
self.reset()
# Reset lists
self.openList = []
self.closedList = []
current = False
# Add our start to the closed list and begin
self.openList.append(self.grid.start)
while len(self.openList)>0:
current = self.nextStep()
current.current = 1
current.draw()
if current == self.grid.target:
print 'found path!'
solving = 0
cell = self.grid.target
current.current = 0
current.draw()
path = []
while cell.parent:
path.append(cell)
cell = cell.parent
path = reversed(path)
for cell in path:
cell.path=1
cell.highlight=0
cell.draw()
pygame.time.delay(self.config.found_delay)
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import save [as 别名]
class Editor:
"""Handles the Gtk.Textview and interacts a File"""
def __init__(self, textview):
self.textview = textview
self.textbuffer = self.textview.get_buffer()
self.file_handle = File()
self.textbuffer.set_modified(False)
def set_font(self, font):
pass
def clean_buffer(self):
startIter, endIter = self.textbuffer.get_start_iter(),\
self.textbuffer.get_end_iter()
self.textbuffer.delete(startIter, endIter)
def save_as_file(self, filename):
self.file_handle.close()
self.file_handle.open(filename, flag="CREATE")
self.save()
def open_file(self, filename, flag="READ"):
state = self.file_handle.open(filename, flag)
if state == "INEXISTANT":
return "INEXISTANT"
elif state == True:
self.update_editor()
else:
print("Failed to open: {file}".format(file=filename))
def new_file(self, filename=None):
self.file_handle.close()
self.file_handle.open(filename)
self.clean_buffer()
self.update_editor()
def replace_file(self, filename):
self.file_handle.replace(filename)
self.save()
def update_editor(self):
self.textbuffer.set_text(self.file_handle.read())
def isFileSaved(self):
return not self.textbuffer.get_modified()
def get_text(self):
"""Gets the text inside the TextView and returns it"""
startIter, endIter = self.textbuffer.get_start_iter(),\
self.textbuffer.get_end_iter()
text = self.textbuffer.get_text(startIter, endIter, True)
return text
def _set_text(self, text):
self.textbuffer.set_text(text)
def save(self):
"""Get textbuffer data and send it to File.save(text)"""
#Check if we dont have a opened file handle
if(self.file_handle.save(self.get_text()) == "SELECT_FILE"):
#If not file is open select one and retry save
return 'SELECT_FILE'
else:
self.textbuffer.set_modified(False)
def save_and_close(self):
"""Saves and closes without caring about file existance"""
if self.isFileSaved():
self.file_handle.close()
else:
self.file_handle.save_and_close(self.get_text())
self.textbuffer.set_modified(False)
def exit(self):
if not self.isFileSaved():
self.save()
self.file_handle.close()