Reikriam

Edit file python

Jul 15th, 2019
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import importlib
  2. uproot = importlib.import_module("uproot")
  3. t = uproot.open("test.root")["hvar"]
  4.  
  5. for i in range(0, 400):
  6. with open('/home/reik/HEP/uproot-dev/uproot/uproot/write/objects/TH.py', 'r') as file:
  7. # read a list of lines into data
  8. data = file.readlines()
  9.  
  10. # now change the 2nd line, note that you have to add a newline
  11. data[229] = ' self.start = {}\n'.format(i)
  12.  
  13. # and write everything back
  14. with open('/home/reik/HEP/uproot-dev/uproot/uproot/write/objects/TH.py', 'w') as file:
  15. file.writelines(data)
  16.  
  17. try:
  18. print(i)
  19. uproot = importlib.reload("uproot")
  20. print("Hi")
  21. with uproot.recreate("example.root") as f:
  22. f["test"] = t
  23. f = uproot.open("example.root")["test"]
  24. except:
  25. continue
  26. break
Advertisement
Add Comment
Please, Sign In to add comment