本文整理汇总了Python中file.File.open方法的典型用法代码示例。如果您正苦于以下问题:Python File.open方法的具体用法?Python File.open怎么用?Python File.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类file.File
的用法示例。
在下文中一共展示了File.open方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import open [as 别名]
class Plugin:
def __init__(self):
self.windowsManager = WM.WindowsManager(self)
self.coqManager = CM.CoqManager(self.windowsManager)
self.instance = None
self.launched = False
def launch(self):
# Don't relaunched if it is already running !
if self.launched == True:
return False
self.launched = True
vim.command(":call MapVcoq()")
self.windowsManager.setupWindows()
self.coqManager.launchCoqtopProcess()
self.instance = File(self, (self.windowsManager.windowBuffers['__Edit__'],
self.windowsManager.windowBuffers['__Compiled__']))
self.windowsManager.focusWindow("__Edit__")
def shutdown(self):
self.launched = False
error("Stopping vcoq ...")
vim.command('windo bd') # Close every windows
def next(self):
if self.instance != None:
self.instance.next()
def prev(self):
if self.instance != None:
self.instance.prev()
################
## Vim events ##
################
def onBufferFocus(self, entered, buffer):
""" This function is called when the user enter or leave a buffer.
It setups (and removes) the special maps for this buffer.
It also perform extra actions, depending on the buffer. """
if self.launched == False:
return 0
if buffer == '__Input__':
cmd = 'imap <buffer> <CR> <Esc>:py vcoq.main.coqManager.sendQueryCommand()<CR>a' if entered else 'mapclear <buffer>'
vim.command(cmd)
return 1
def onVimResized(self):
if self.launched == False: return 0
self.windowsManager.updateWindows()
return 0
def onEnter(self, buffer):
if self.launched == False: return 0
self.windowsManager.onEnter(buffer)
return 0
def onWrite(self, filename):
if self.launched == False:
error("Vcoq isn't running", prompt=False)
return 0
self.instance.write(filename)
return 0
def onOpen(self, filename):
if self.launched == False:
error("Vcoq isn't running", prompt=False)
return 0
self.instance.open(filename)
return 0
示例2: enumerate
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import open [as 别名]
import csv
import numpy
from dtw import DTW
from file import File
__author__ = 'phizaz'
# open training files
training = File.open('Coffee_TRAIN')
training_with_label = []
for each in training:
training_with_label.append({
"label": each[0],
"data": each[1:]
})
# open testing file
testing = File.open('Coffee_TEST')
result = {
'title': 'Coffee',
}
# using Euclidean
print('using Euclidean...')
correctness = 0
for i, each in enumerate(testing):
print(i, "of", len(testing))
label = each[0]
示例3: __init__
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import open [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()