From 278c5c555576fc788d5a01f0c6eeb2f8add2ef61 Mon Sep 17 00:00:00 2001 From: Christoph Deil Date: Wed, 8 Jan 2014 14:11:24 +0100 Subject: [PATCH] No `from gammalib import *` in Python examples --- examples/python/models_howto.py | 13 +++++++------ examples/python/xml_howto.py | 34 +++++++++++++++++----------------- examples/python/xml_html_create.py | 14 +++++++------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/examples/python/models_howto.py b/examples/python/models_howto.py index e7b346f..b5d4c65 100755 --- a/examples/python/models_howto.py +++ b/examples/python/models_howto.py @@ -26,7 +26,7 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * +import gammalib # =========================================== # @@ -36,14 +36,15 @@ def create_models(): """ """ # Create model container - models = GModels() + models = gammalib.GModels() # Create a power law model for the Crab - crabdir = GSkyDir() + crabdir = gammalib.GSkyDir() crabdir.radec_deg(83.6331, 22.0145) - spatial = GModelSpatialPointSource(crabdir) - spectral = GModelSpectralPlaw(5.7e-16, -2.48, GEnergy(100.0, "MeV")) - model = GModelSky(spatial, spectral) + spatial = gammalib.GModelSpatialPointSource(crabdir) + energy = gammalib.GEnergy(100.0, "MeV") + spectral = gammalib.GModelSpectralPlaw(5.7e-16, -2.48, energy) + model = gammalib.GModelSky(spatial, spectral) models.append(model) # Return models diff --git a/examples/python/xml_howto.py b/examples/python/xml_howto.py index d2352c2..aa62150 100755 --- a/examples/python/xml_howto.py +++ b/examples/python/xml_howto.py @@ -26,7 +26,7 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * +import gammalib # =================== # @@ -51,7 +51,7 @@ def create_xml(): (GXmlComment) """ # Allocate XML document - xml = GXml() + xml = gammalib.GXml() # Append first child element to XML document root. The first child # element contains a single child which is an empty-element tag. @@ -64,21 +64,21 @@ def create_xml(): level1 = xml.append('element') level2 = level1.append('list') level3 = level2.append('string') - level4 = level3.append(GXmlText("This is a text")) + level4 = level3.append(gammalib.GXmlText("This is a text")) level3 = level2.append('integer') - level4 = level3.append(GXmlText("17")) + level4 = level3.append(gammalib.GXmlText("17")) # Append third child element to XML document root. The third child # element contains a single Processing Instruction. level1 = xml.append('processing-instruction') - level2 = level1.append(GXmlPI('')) + level2 = level1.append(gammalib.GXmlPI('')) # Append forth child element to XML document root. The forth child # element contains two comments. The first comment is a single-line # comment while the second comment runs over multiple lines. level1 = xml.append('comment') - level2 = level1.append(GXmlComment('This is a comment')) - level2 = level1.append(GXmlComment('This is a\ntwo line comment')) + level2 = level1.append(gammalib.GXmlComment('This is a comment')) + level2 = level1.append(gammalib.GXmlComment('This is a\ntwo line comment')) # Return XML document return xml @@ -101,7 +101,7 @@ def manipulate_xml(xml): # Insert now at the location where we just removed the processing # instruction a new child element named 'replacement'. This new # child element will have four levels of child nodes. - level0 = xml.insert(2, GXmlElement('replacement')) + level0 = xml.insert(2, gammalib.GXmlElement('replacement')) level1 = level0.append('level1') level2 = level1.append('level2') level3 = level2.append('level3') @@ -110,7 +110,7 @@ def manipulate_xml(xml): # Set now a text node at the place of the level4 child node (the # level4 child node was sitting in the first slot of the level3 # node, hence we have to set the text using the index 0) - level4 = level3.set(0, GXmlText('This text replaces the level 4 child node')) + level4 = level3.set(0, gammalib.GXmlText('This text replaces the level 4 child node')) # We extend the level2 child node by adding four further child nodes # containg a text node, one comment and one processing instruction. @@ -124,17 +124,17 @@ def manipulate_xml(xml): # will contain a text node. We furthermore append one comment and one # processing instruction. Once this is setup we call the extend() method # to extend the level2 child node. - ext = GXmlElement('level2 extension="yes"') + ext = gammalib.GXmlElement('level2 extension="yes"') element1 = ext.append('level3') element2 = ext.append('level3') element3 = ext.append('level3') element4 = ext.append('level3') - comment = ext.append(GXmlComment('This is a comment')) - pi = ext.append(GXmlPI('')) - element1.append(GXmlText('This is the first element')) - element2.append(GXmlText('This is the second element')) - element3.append(GXmlText('This is the third element')) - element4.append(GXmlText('This is the forth element')) + comment = ext.append(gammalib.GXmlComment('This is a comment')) + pi = ext.append(gammalib.GXmlPI('')) + element1.append(gammalib.GXmlText('This is the first element')) + element2.append(gammalib.GXmlText('This is the second element')) + element3.append(gammalib.GXmlText('This is the third element')) + element4.append(gammalib.GXmlText('This is the forth element')) level2.extend(ext) # Now we replace the text of the last element in the level2 childs. @@ -215,7 +215,7 @@ def show_xml(xml): Show XML document on the screen. """ # Allocate string URL - url = GUrlString() + url = gammalib.GUrlString() # Write XML document in URL xml.write(url) diff --git a/examples/python/xml_html_create.py b/examples/python/xml_html_create.py index 95d6f5d..1205d95 100755 --- a/examples/python/xml_html_create.py +++ b/examples/python/xml_html_create.py @@ -25,7 +25,7 @@ # along with this program. If not, see . # # ========================================================================== -from gammalib import * +import gammalib # ==================== # @@ -47,7 +47,7 @@ def create_html(): that is placed in the top-right corner of the page. """ # Allocate XML document - xml = GXml() + xml = gammalib.GXml() # Creates HTML base html = xml.append('html') @@ -57,7 +57,7 @@ def create_html(): meta = header.append('meta content="text/html; charset=ISO-8859-1" ' 'http-equiv="content-type"') title = header.append('title') - text = title.append(GXmlText('GammaLib')) + text = title.append(gammalib.GXmlText('GammaLib')) # Writes body body = html.append('body') @@ -66,10 +66,10 @@ def create_html(): big = image.append('big') bigger = big.append('big') span = bigger.append('span style="font-family: Arial; font-weight: bold;"') - text = span.append(GXmlText('Gammalib')) - text = image.append(GXmlText('
')) + text = span.append(gammalib.GXmlText('Gammalib')) + text = image.append(gammalib.GXmlText('
')) span = image.append('span style="font-family: Arial;"') - text = span.append(GXmlText('A versatile toolbox for the scientific analysis ' + text = span.append(gammalib.GXmlText('A versatile toolbox for the scientific analysis ' 'of astronomical gamma-ray data')) # Return XML document @@ -84,7 +84,7 @@ def show_xml(xml): Show XML document on the screen. """ # Allocate string URL - url = GUrlString() + url = gammalib.GUrlString() # Write XML document in URL xml.write(url) -- libgit2 0.21.4