Skip to content
Snippets Groups Projects
Commit beedce47 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Added cd context manager

I also added a function in order to avoid too many line changes
for intentation
parent c521126a
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,16 @@
import numpy as np
import plumed
import os
from contextlib import contextmanager
@contextmanager
def cd(newdir):
prevdir = os.getcwd()
os.chdir(newdir)
try:
yield
finally:
os.chdir(prevdir)
def read_xyz(filename):
xyz = open(filename)
......@@ -68,8 +78,7 @@ def create_plumed_var( p, name, command ):
p.cmd("setMemoryForData " + name, data )
return data
def test():
os.chdir('test/')
def runtest():
os.system('rm -f bck.*')
# Output to four decimal places only
np.set_printoptions(precision=4)
......@@ -152,6 +161,10 @@ def test():
of.close()
def test():
with cd('test/'):
runtest()
if __name__ == "__main__":
test()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment