When a court is trying to decide the meaning of a law, can it consider the discussions which begot it?
Yes. The landmark case in the UK is Pepper (Inspector of Taxes) v Hart, where the House of Lords*:
established the principle that when primary legislation is ambiguous then, in certain circumstances, the court may refer to statements made in the House of Commons or House of Lords in an attempt to interpret the meaning of the legislation. Before this ruling, such an action would have been seen as a breach of parliamentary privilege
*Strictly speaking, the Appellate Committee of the House of Lords, which functioned as the UK's highest court before the creation of the Supreme Court.
See Rizzo & Rizzo Shoes Ltd. (Re),  1 S.C.R. 27, para. 35:
Although the frailties of Hansard evidence are many, this Court has recognized that it can play a limited role in the interpretation of legislation. Writing for the Court in R. v. Morgentaler,  3 S.C.R. 463, at p. 484, Sopinka J. stated:
. . . until recently the courts have balked at admitting evidence of legislative debates and speeches. . . . The main criticism of such evidence has been that it cannot represent the “intent” of the legislature, an incorporeal body, but that is equally true of other forms of legislative history. Provided that the court remains mindful of the limited reliability and weight of Hansard evidence, it should be admitted as relevant to both the background and the purpose of legislation.