CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
FileUtils Namespace Reference

Functions

def loadListFromFile
 
def save_history
 
def sectionNofTotal
 

Variables

tuple historyPath = os.path.expanduser("~/.pyhistory")
 

Function Documentation

def FileUtils.loadListFromFile (   filename)
Loads a list of strings from file.  Will append to given list
if asked.

Definition at line 6 of file FileUtils.py.

References print().

6 
7 def loadListFromFile (filename):
8  """Loads a list of strings from file. Will append to given list
9  if asked."""
10  retval = []
11  filename = os.path.expanduser (filename)
12  if not os.path.exists (filename):
13  print("Error: file '%s' does not exist."%(filename))
14  raise RuntimeError("Bad filename")
15  source = open (filename, 'r')
16  for line in source.readlines():
17  line = re.sub (r'#.+$', '', line) # remove comment characters
18  line = line.strip()
19  if len (line):
20  retval.append (line)
21  source.close()
22  return retval
23 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def loadListFromFile
Definition: FileUtils.py:6
def FileUtils.save_history (   historyPath = historyPath)

Definition at line 60 of file FileUtils.py.

60 
61  def save_history(historyPath=historyPath):
62  import readline
63  readline.write_history_file(historyPath)
64  if os.path.exists(historyPath):
65  readline.read_history_file(historyPath)
66 
def save_history
Definition: FileUtils.py:60
def FileUtils.sectionNofTotal (   inputList,
  currentSection,
  numSections 
)
Returns the appropriate sublist given the current section
(1..numSections)

Definition at line 24 of file FileUtils.py.

24 
25 def sectionNofTotal (inputList, currentSection, numSections):
26  """Returns the appropriate sublist given the current section
27  (1..numSections)"""
28  currentSection -= 1 # internally, we want 0..N-1, not 1..N
29  size = len (inputList)
30  perSection = size // numSections
31  extra = size % numSections
32  start = perSection * currentSection
33  num = perSection
34  if currentSection < extra:
35  # the early sections get an extra item
36  start += currentSection
37  num += 1
38  else:
39  start += extra
40  stop = start + num
41  return inputList[ start:stop ]
42 
def sectionNofTotal
Definition: FileUtils.py:24

Variable Documentation

tuple FileUtils.historyPath = os.path.expanduser("~/.pyhistory")

Definition at line 57 of file FileUtils.py.