我在python中有一个类,它有一个可迭代的实例变量.我想通过迭代嵌入式迭代来迭代类的实例.
我实现如下:
def __iter__(self):
return self._iterable.__iter__()
Run Code Online (Sandbox Code Playgroud)
我觉得__iter__()在iterable上调用方法并不是很舒服,因为它是一种特殊的方法.这是你如何在python中解决这个问题,还是有更优雅的解决方案?
在版本4.3.0.Final的hibernate文档中,给出了以下代码片段来创建SessionFactory:
package org.hibernate.tutorial.util;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new Configuration().configure().buildSessionFactory();
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Run Code Online (Sandbox Code Playgroud)
这似乎已经过时,因为该方法buildSessionFactory()已被弃用.创建的正确方法是 …