We derive the analog of Belavin-Knizhnik formula for both orientable and nonorientable open bosonic strings. At the order 2g of perturbation theory, the open string partition function is given for orientable and non-orientable topologies as an integral over a subvariety of the moduli space of genus g Riemann surfaces. The integrand is the modulus of the holomorphic function of Belavin and Knizhnik multipied by ( det Im T)−13 where T is obtained from the period matrix.