I am trying to create a PETSC binary file using python. I try to run the script on bash shell but I get an error
$ python -c 'print file.shape\n import sys,os\n sys.path.append(os.path.join(os.environ['PETSC_DIR'],'bin','pythonscripts'))\nimport PetscBinaryIO\nio=PetscBinaryIO.PetscBinaryIO()\nfile_fortran=file.transpose((2,1,0))\n io.writeBinaryFile('my_geometry.dat',(walls_fortran.rave1()).view(PetscBinaryIO.Vec),))'
Unexpected character after line continuation character.
I understand that happens because of an extra \
but my code doesn't seem to have any. I tried running python interactively to find which part of the code is faulty using python -i
>>> walls=open('file.dat','r+')
>>> print walls.shape()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'file' object has no attribute 'shape'
i am new to python so i know this might be an obvious error. but i don't seem to know what this is about
Thanks John for the answer. Now that it recognizes PETSC_DIR i get the error
>>> PETSC_DIR="/home/petsc-3.4.3"
>>> sys.path.append(os.path.join(os.environ["PETSC_DIR"],"bin","pythonscripts"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/UserDict.py", line 22, in __getitem__
raise KeyError(key)
KeyError: 'PETSC_DIR'</code>
It does not recognize PETSC_DIR even though i specify it