Skip to content

Commit 0627390

Browse files
guitargeekdpiparo
authored andcommitted
[PyROOT] Don't access deleted object in PyROOT tutorial
Accessing deleted objects is not supported anymore, so it should not be shown. (cherry picked from commit b7956d2)
1 parent 77c6567 commit 0627390

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

tutorials/pyroot/pyroot005_tfile_context_manager.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@
4242

4343
# When the TFile.Close method is called, the current directory is automatically
4444
# set again to ROOT.gROOT. Objects that were attached to the file inside the
45-
# context are automatically deleted and made 'None' when the file is closed.
45+
# context are automatically deleted, so they can't be accessed anymore after
46+
# the file is closed.
4647
print("Status after the first TFile context manager:")
4748
print(" Current directory: '{}'.".format(ROOT.gDirectory.GetName()))
48-
print(" Accessing 'histo_2' gives: '{}'.\n".format(histo_2))
49+
# print(histo_2) # the object is deleted at this point, so don't use it anymore!
4950

5051
# Also reading data from a TFile can be done in a context manager. Information
5152
# stored in the objects of the file can be queried and used inside the context.

0 commit comments

Comments
 (0)