Notices
 

Extracting edge information from ".gml" file

For page specific messages
For page author info

Hello friends,

I am working with 'networkx". I am using .gml file for storing my node and egde information of Social network graph. My supervisior was in need of edge information of my Social network graph. So, i have written this script for him.

 


#!/usr/bin/python
#Filename:trim.py
#open edgelist file

f=open("edge_new.gml","r")
#open destination file
h=open("final1.txt","w")
c=0
while True:
    l=f.readline()
    l1=len(l)
    if l1==0:
        break
    if l1 > 9:
        if l[2]=='s' and l[3]=='o':
            i=9
            while True:
                if l[i]=="\n":
                    break
                h.write(l[i])
                i=i+1
            h.write(" ")
        if l[2]=='t' and l[3]=='a':
           i=9
           while True:
               if l[i]=="\n":
                   break
               h.write(l[i])
               i=i+1
           h.write("\n")
f.close()
h.close()

 

Since, Python uses whitespace indentation. An increase in indentation comes after certain statements(i.e. Control Statement), a decrease in indentation signifies the end of the current block. So, it is possible that above code gives aome indentation error.Any one can download code from attachment of this post

Attachments for download: 

 
X