Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For illustration, let's take a small excerpt of that bash script:</p> <pre><code>python -c 'print file.shape\n import sys,os\n' </code></pre> <p>In a bash single-quoted string, as you have here, the characters "\n" represent a backslash followed by "n". Python sees this as an "extra backslash" even though you meant "\n" to be interpreted as a newline character. This is what generates errors of the type</p> <pre><code>unexpected character after line continuation character </code></pre> <p>To fix this, try instead:</p> <pre><code>python -c $'print file.shape\n import sys,os\n' </code></pre> <p>Bash treats <code>$'...'</code> strings specially and will, among other things, replace <code>\n</code> sequences with new line characters which python will understand and know how to process.</p> <p>(The above will still give an error because <code>file</code> does not have a <code>shape</code> attribute. More on this below.)</p> <p>There are other issues. Take, for example, this excerpt:</p> <pre><code>python -c 'sys.path.append(os.path.join(os.environ['PETSC_DIR'],'bin','pythonscripts'))' </code></pre> <p>After bash does quote removal, python sees: </p> <pre><code>sys.path.append(os.path.join(os.environ[PETSC_DIR],bin,pythonscripts)) </code></pre> <p>This won't work because python needs <code>PETSC_DIR</code> and <code>bin</code> and <code>pythonscripts</code> to be quoted (with either single or double-quotes: python doesn't care). Try instead:</p> <p>python -c 'sys.path.append(os.path.join(os.environ["PETSC_DIR"],"bin","pythonscripts"))'</p> <p>When bash sees double-quotes inside single quotes, it leaves them alone. Thus, python will receive quoted strings where it needs them.</p> <p>In sum, it looks to me like the error is caused not by your python code but by what bash does to your python code before passing it to python.</p> <p>ADDENDUM: As for the <code>print walls.shape()</code> error where <code>walls</code> is a file handle, the error means what it says: file handles do not have <code>shape</code> attributes. Possibly you want to use the <a href="http://docs.python.org/2/library/os.path.html#os.path.getsize" rel="nofollow"><code>os.path.getsize(path)</code></a> function from the <code>os.path</code> module to get file size in bytes?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload