ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 22 Oct 2011 00:23:17 +0200Graph 6 string contains "\n"https://ask.sagemath.org/question/8401/graph-6-string-contains-n/I found some graphs with graph 6 string containing "\n" as a substring. But, then
g=Graph('XZ|f|a\nvrMxUrw}~iuhZjV~fxg~s^X[~~XZqlyuT~^~n~nnT~h')
calls an error:
RuntimeError: The string (XZ|f|a) seems corrupt: for n = 25, the string is too short.
Any ideas?
ThanksFri, 21 Oct 2011 13:52:15 +0200https://ask.sagemath.org/question/8401/graph-6-string-contains-n/Comment by John Palmieri for <p>I found some graphs with graph 6 string containing "\n" as a substring. But, then</p>
<pre><code>g=Graph('XZ|f|a\nvrMxUrw}~iuhZjV~fxg~s^X[~~XZqlyuT~^~n~nnT~h')
</code></pre>
<p>calls an error:</p>
<p>RuntimeError: The string (XZ|f|a) seems corrupt: for n = 25, the string is too short.</p>
<p>Any ideas?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/8401/graph-6-string-contains-n/?comment=21069#post-id-21069Can you give an example of a graph whose graph6 string contains "\n"? It's easier to test it out and look for a solution if we have an example to work with.Fri, 21 Oct 2011 14:30:40 +0200https://ask.sagemath.org/question/8401/graph-6-string-contains-n/?comment=21069#post-id-21069Answer by John Palmieri for <p>I found some graphs with graph 6 string containing "\n" as a substring. But, then</p>
<pre><code>g=Graph('XZ|f|a\nvrMxUrw}~iuhZjV~fxg~s^X[~~XZqlyuT~^~n~nnT~h')
</code></pre>
<p>calls an error:</p>
<p>RuntimeError: The string (XZ|f|a) seems corrupt: for n = 25, the string is too short.</p>
<p>Any ideas?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/8401/graph-6-string-contains-n/?answer=12794#post-id-12794I think that the problem is: the Graph constructor should treat "\n" as two characters, but "\n" in Python by default stands for a single character, a newline. If you preface the string with "r", it should work:
sage: Graph(r'XZ|f|a\nvrMxUrw}~iuhZjV~fxg~s^X[~~XZqlyuT~^~n~nnT~h')
(The "r" tells Python that it's a "raw" string and to treat backslashes as actual backslashes, not as a part of a special character like a newline "\n" or a tab "\t".)
Alternatively, if you double the backslash, that should work:
sage: Graph('XZ|f|a\\nvrMxUrw}~iuhZjV~fxg~s^X[~~XZqlyuT~^~n~nnT~h')
Fri, 21 Oct 2011 14:37:17 +0200https://ask.sagemath.org/question/8401/graph-6-string-contains-n/?answer=12794#post-id-12794Comment by G-Sage for <p>I think that the problem is: the Graph constructor should treat "\n" as two characters, but "\n" in Python by default stands for a single character, a newline. If you preface the string with "r", it should work:</p>
<pre><code>sage: Graph(r'XZ|f|a\nvrMxUrw}~iuhZjV~fxg~s^X[~~XZqlyuT~^~n~nnT~h')
</code></pre>
<p>(The "r" tells Python that it's a "raw" string and to treat backslashes as actual backslashes, not as a part of a special character like a newline "\n" or a tab "\t".)</p>
<p>Alternatively, if you double the backslash, that should work:</p>
<pre><code>sage: Graph('XZ|f|a\\nvrMxUrw}~iuhZjV~fxg~s^X[~~XZqlyuT~^~n~nnT~h')
</code></pre>
https://ask.sagemath.org/question/8401/graph-6-string-contains-n/?comment=21066#post-id-21066@John Is this something that should be fixed then?Fri, 21 Oct 2011 22:42:48 +0200https://ask.sagemath.org/question/8401/graph-6-string-contains-n/?comment=21066#post-id-21066Comment by John Palmieri for <p>I think that the problem is: the Graph constructor should treat "\n" as two characters, but "\n" in Python by default stands for a single character, a newline. If you preface the string with "r", it should work:</p>
<pre><code>sage: Graph(r'XZ|f|a\nvrMxUrw}~iuhZjV~fxg~s^X[~~XZqlyuT~^~n~nnT~h')
</code></pre>
<p>(The "r" tells Python that it's a "raw" string and to treat backslashes as actual backslashes, not as a part of a special character like a newline "\n" or a tab "\t".)</p>
<p>Alternatively, if you double the backslash, that should work:</p>
<pre><code>sage: Graph('XZ|f|a\\nvrMxUrw}~iuhZjV~fxg~s^X[~~XZqlyuT~^~n~nnT~h')
</code></pre>
https://ask.sagemath.org/question/8401/graph-6-string-contains-n/?comment=21065#post-id-21065I don't know enough about the graph6 format to say. It looks like newlines are acceptable in that format: you could have several graphs, one line for each. So when you evaluate "Graph(string)", it truncates "string" at the first newline. So how do you tell apart a string containing "\" followed by "n" vs. a string containing an actual newline delimiting the strings for two different graphs?Sat, 22 Oct 2011 00:23:17 +0200https://ask.sagemath.org/question/8401/graph-6-string-contains-n/?comment=21065#post-id-21065Comment by G-Sage for <p>I think that the problem is: the Graph constructor should treat "\n" as two characters, but "\n" in Python by default stands for a single character, a newline. If you preface the string with "r", it should work:</p>
<pre><code>sage: Graph(r'XZ|f|a\nvrMxUrw}~iuhZjV~fxg~s^X[~~XZqlyuT~^~n~nnT~h')
</code></pre>
<p>(The "r" tells Python that it's a "raw" string and to treat backslashes as actual backslashes, not as a part of a special character like a newline "\n" or a tab "\t".)</p>
<p>Alternatively, if you double the backslash, that should work:</p>
<pre><code>sage: Graph('XZ|f|a\\nvrMxUrw}~iuhZjV~fxg~s^X[~~XZqlyuT~^~n~nnT~h')
</code></pre>
https://ask.sagemath.org/question/8401/graph-6-string-contains-n/?comment=21068#post-id-21068Perfect, you're the bomb.Fri, 21 Oct 2011 15:01:26 +0200https://ask.sagemath.org/question/8401/graph-6-string-contains-n/?comment=21068#post-id-21068