pythontex - reading data from a file

This is about a file location problem while using pythontex (which works great!)

I have some python code within \begin{pylabblock} \end{pylabblock} where I am reading in data from a file in the current directory

code fragment

filename = str(os.getcwd()+'/testdata1.dat')



the xyread fails - it cannot find the file in the getcwd()

BUT if I place a copy of the testdata1.dat in a subdirectory that pythontex creates during compile, it works

(my tex file is named test3.tex and pythontex creates pythontex-files-test3/ and if testdata1.dat is in that directory, it works)

By default, the directory that pythontex creates is the working directory. This keeps everything created by pythontex isolated. If you want to use the document directory as the working directory, you can use \setpythontexworkingdir{.} in your preamble, or os.chdir('..') in your Python code.
Starting with version 0.14, pythontex's default working directory is the document directory. This simplifies directory handling. This can still be changed from the TeX side with \setpythontexworkingdir or the Python side with os.chdir().
• Another option is just to use ../filename everywhere, both for reading as well as writing. This will work on Unix-like systems, at least. – Faheem Mitha Mar 10 '15 at 8:31