本文整理汇总了Python中file.File.read方法的典型用法代码示例。如果您正苦于以下问题:Python File.read方法的具体用法?Python File.read怎么用?Python File.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类file.File
的用法示例。
在下文中一共展示了File.read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import read [as 别名]
def main():
#Really important values
showFPS = True
TOTAL_OBJECTS = 1
#Import modules
import pygame, sys, os
from pygame.locals import *
#import custom classes
import background, button, toolbar, selectGun, selectTool, person, powerups, baddieAI
from background import Level_1
from button import Button
from toolbar import Toolbar
from selectGun import selectGunMenu
from selectTool import selectToolMenu
from person import Person
from powerups import Powerups
from baddieAI import AI
from l1 import L1
import load
from screen import Screen
from file import File
#Setup game data
getFiles = File()
highscore, totalscore, firstRun, lockedGuns = getFiles.read()
#Show Important information if program is run for first time
if firstRun:
from installer import Install
firstRun = False
#Setup the main screen display and clock
pygame.init()
os.environ ['SDL_VIDEO_WINDOW_POS'] = 'center'
WINDOWWIDTH = 1200
WINDOWHIEGHT = 600
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHIEGHT), 0, 32)
icon = pygame.image.load('files\\icon.png')
pygame.display.set_caption('The Taco Chronicles')
pygame.display.set_icon(icon)
mainClock = pygame.time.Clock()
load.Credits(windowSurface)
#Setup Colors
BLUE = (0,0,255)
SKY_BLUE = (0, 255, 255)
windowSurface.fill(SKY_BLUE)
lockedTools = {'crowbar':False, 'rope':True, 'key':True, 'TNT':True, 'jetpack':True}
sound = True
gameData = {'sound':sound, 'lockedGuns':lockedGuns, 'lockedTools':lockedTools}
restart = True
start = Screen(windowSurface)
clicked = False
windowSurface.fill((255, 255, 255))
pygame.mixer.music.load('files//sound//gameTheme.mp3')
exit = False
while True:
restart = True
clicked = False
pygame.mixer.music.play(-1, 0.0)
windowSurface.fill((255, 255, 255))
while True:
if exit:
getFiles.write(highscore, totalscore, firstRun, lockedGuns)
pygame.quit()
sys.exit()
clicked, exit = start.startScreen(highscore, clicked)
if clicked:
break
pygame.mixer.music.stop()
load.Load(windowSurface)
#Run the gameplay
count = 0
while True:
level = L1(windowSurface, mainClock, SKY_BLUE, gameData, showFPS)
restart, goBack, highscore, totalscore, exit = level.play(highscore, totalscore)
if goBack:
break
if exit:
break
if totalscore > 10000:
lockedGuns['shotgun'] = False
if totalscore > 15000:
lockedGuns['AK-47'] = False
if totalscore > 30000:
lockedGuns['bazooka'] = False
if totalscore > 35000:
lockedGuns['flamethrower'] = False
示例2: __init__
# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import read [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()