Python script similar to java version