PyROOT: file->Write(0, TObject::kWriteDelete)

Hi everyone,
I want to do the file->Write(0, TObject::kWriteDelete) Operation but in Python. I dont know what the “translation to python” for the KWriteDelete Command is. Can anybody tell me?

ROOT Version: 6.18/00

Hi @LukasKretschmann ,
and welcome to the ROOT forum.
It should be file.Write(0, ROOT.TObject.kWriteDelete) (which is just an enum value that corresponds to 4):

In [1]: import ROOT
In [2]: ROOT.TObject.kWriteDelete
Out[2]: 4

Cheers,
Enrico

@eguiraud I actually tried this and got an error from the C++ Code of ROOT. But

file.Write("",4)

solved it for me

Uhm what was the error? As far as I know a call like that should work, right @etejedor ?

Yes @eguiraud your suggestion should work.

Traceback (most recent call last):
File “NeuralNetwork2/SanityCheck.py”, line 169, in
Files[temp_counter].Write(0,ROOT.TObject.kWriteDelete)
TypeError: none of the 2 overloaded methods succeeded. Full details:
int TFile::Write(const char* name = 0, int opt = 0, int bufsiz = 0) =>
could not convert argument 1 (bad argument type for built-in operation)
int TFile::Write(const char* name = 0, int opt = 0, int bufsiz = 0) =>
could not convert argument 1 (bad argument type for built-in operation)

Ah maybe it’s the first argument that it doesn’t like (an integer where a pointer is expected). You could try using ROOT.nullptr instead of 0 (or an actual string).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.