The fragmentation functions of quarks and gluons are measured in a general three-jet topology in Z decays from the data set collected with the OPAL detector at the Z resonance between 1993 and 2000. The dependence of the fragmentation functions on a transverse momentum-like scale is compared with recent NLO QCD calculations and is found in agreement. The scaling violation of the gluon fragmentation function is observed to be stronger than that of the quark over the whole accessible scale range. Also, an agreement with measurements from lower energy e$^+$e$^-$ annihilation experiments is found.