[Networkit] Error on writing

Maximilian Vogel maximilian.vogel at student.kit.edu
Mon Jul 6 15:35:32 CEST 2015


"the best way to check the path" is/has been discussed on SO. I think, 
these two discussion give some insight:
http://stackoverflow.com/questions/82831/check-whether-a-file-exists-using-python
http://stackoverflow.com/questions/2259382/pythonic-way-to-check-if-a-file-exists

There are two options, one should at least do:
Either, use os.path.exists/isfile(path) in an if-clause OR
surround the writer.write(...)-call with a try-except block catching the 
matching error.


On 06.07.2015 15:24, Christian Staudt wrote:
> Apparently a typo in the file path leads to an error like this, which 
> should not happen. What is the best way to check the path and throw a 
> meaningful error?
>
>
> On 06 Jul 2015, at 15:07, Christian Staudt <christian.staudt at kit.edu 
> <mailto:christian.staudt at kit.edu>> wrote:
>
>> Hi NetworKit developers,
>> now I have a support question too: I want to write a weighted graph 
>> to an edge list of the format
>> uv w
>> where u and v are the end nodes and w is an edge weight. If I try to 
>> do that graphio.EdgeListWriter throws an error with empty text:
>>
>>
>>
>>
>> In [*2*]: G = 
>> readGraph("/Users/cls/Downloads/opsahl-usairport/out.opsahl-usairport", 
>> Format.KONECT)
>>
>> In [*3*]: U = G.toUndirected()
>>
>> In [*4*]: writeGraph(U, "airtraffic.graph", Format.EdgeListTabZero)
>> ---------------------------------------------------------------------------
>> RuntimeError                             Traceback (most recent call 
>> last)
>> <ipython-input-4-3f775e968492> in <module>()
>> ----> 
>> 1writeGraph(U,"/Users/cls/workspace/AlgoIProgrammieraufgabe/data/airtraffic.graph", Format.EdgeListTabZero)
>>
>> /Users/cls/workspace/NetworKit/networkit/graphio.py in writeGraph(G, 
>> path, fileformat, **kwargs)
>> *    209*"""
>> *  210*         writer = getWriter(fileformat, **kwargs)
>> --> 211writer.write(G, path)
>> *  212*         logging.info("wrote graph {0} to file 
>> {1}".format(G, path))
>> *    213*
>>
>> _NetworKit.pyx in _NetworKit.EdgeListWriter.write 
>> (networkit/_NetworKit.cpp:21233)()
>>
>> RuntimeError:
>>
>> I’ve also modified the writer so that it writes the desired format, 
>> but I keep getting the error.
>>
>> Best,
>> Chris
>>
>> <signature.asc><ATT00001.c>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ira.uni-karlsruhe.de/mailman/private/networkit/attachments/20150706/55fa73a3/attachment-0001.html>


More information about the NetworKit mailing list