summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authordschult <none@none>2010-06-19 15:10:00 +0000
committerdschult <none@none>2010-06-19 15:10:00 +0000
commit7f59bbd16f46faa56be659a0201fbc28a5bb9f13 (patch)
tree94d36c223440f6c1149985b25464f3df4a5a4473 /examples
parent1ef90fc16dfe858fbe1c608895278dfe8c756c49 (diff)
downloadnetworkx-7f59bbd16f46faa56be659a0201fbc28a5bb9f13.tar.gz
Fix Exceptions to work with Python 2.6.
Fixes #361 --HG-- extra : convert_revision : svn%3A3ed01bd8-26fb-0310-9e4c-ca1a4053419f/networkx/trunk%401745
Diffstat (limited to 'examples')
-rw-r--r--examples/algorithms/blockmodel.py5
-rw-r--r--examples/graph/football.py8
-rw-r--r--examples/graph/knuth_miles.py11
-rw-r--r--examples/graph/roget.py11
-rw-r--r--examples/graph/words.py11
5 files changed, 17 insertions, 29 deletions
diff --git a/examples/algorithms/blockmodel.py b/examples/algorithms/blockmodel.py
index 2e4ff385..cf424926 100644
--- a/examples/algorithms/blockmodel.py
+++ b/examples/algorithms/blockmodel.py
@@ -49,10 +49,7 @@ def create_hc(G):
return partition.values()
if __name__ == '__main__':
- try:
- G=nx.read_edgelist("hartford_drug.edgelist")
- except IOError:
- raise "hartford_drug.edgelist not found"
+ G=nx.read_edgelist("hartford_drug.edgelist")
# Extract largest connected component into graph H
H=nx.connected_component_subgraphs(G)[0]
diff --git a/examples/graph/football.py b/examples/graph/football.py
index c5f3d0d7..95326814 100644
--- a/examples/graph/football.py
+++ b/examples/graph/football.py
@@ -19,20 +19,20 @@ __author__ = """Aric Hagberg (hagberg@lanl.gov)"""
try:
import pyparsing
-except ImportError:
- raise "pyparsing not found: install http://pyparsing.wikispaces.com/"
+except ImportError,e:
+ raise ImportError(str(e)+". Check http://pyparsing.wikispaces.com/")
from networkx import *
url="http://www-personal.umich.edu/~mejn/netdata/football.zip"
-import urllib
+import urllib
import StringIO
import zipfile
sock = urllib.urlopen(url) # open URL
s=StringIO.StringIO(sock.read()) # read into StringIO "file"
-sock.close()
+sock.close()
zf = zipfile.ZipFile(s) # zipfile object
txt=zf.read('football.txt') # read info file
diff --git a/examples/graph/knuth_miles.py b/examples/graph/knuth_miles.py
index 8cd75891..4c5b50e9 100644
--- a/examples/graph/knuth_miles.py
+++ b/examples/graph/knuth_miles.py
@@ -35,13 +35,10 @@ def miles_graph():
"""
# open file miles_dat.txt.gz (or miles_dat.txt)
try:
- try:
- import gzip
- fh = gzip.open('knuth_miles.txt.gz','r')
- except:
- fh=open("knuth_miles.txt","r")
- except IOError:
- raise "File knuth_miles.txt not found."
+ import gzip
+ fh = gzip.open('knuth_miles.txt.gz','r')
+ except:
+ fh=open("knuth_miles.txt","r")
G=nx.Graph()
G.position={}
diff --git a/examples/graph/roget.py b/examples/graph/roget.py
index 01b2b7f6..a6d3526b 100644
--- a/examples/graph/roget.py
+++ b/examples/graph/roget.py
@@ -41,13 +41,10 @@ def roget_graph():
"""
# open file roget_dat.txt.gz (or roget_dat.txt)
try:
- try:
- import gzip
- fh=gzip.open('roget_dat.txt.gz','r')
- except:
- fh=open("roget_dat.txt","r")
- except IOError:
- raise "File roget_dat.txt not found."
+ import gzip
+ fh=gzip.open('roget_dat.txt.gz','r')
+ except:
+ fh=open("roget_dat.txt","r")
G=DiGraph()
diff --git a/examples/graph/words.py b/examples/graph/words.py
index 10900fcb..2f1660d2 100644
--- a/examples/graph/words.py
+++ b/examples/graph/words.py
@@ -60,13 +60,10 @@ def words_graph():
import sys
# open file words_dat.txt.gz (or words_dat.txt)
try:
- try:
- import gzip
- fh=gzip.open('words_dat.txt.gz','r')
- except:
- fh=open("words_dat.txt","r")
- except IOError:
- raise "File words_dat.txt not found."
+ import gzip
+ fh=gzip.open('words_dat.txt.gz','r')
+ except:
+ fh=open("words_dat.txt","r")
G = Graph(name="words")
sys.stderr.write("Loading words_dat.txt: ")