9

Given:

import gym
env = gym.make('CartPole-v0')

How do I get CartPole-v0 in a way that works across any Gym env?

Andrew Schreiber
  • 14,344
  • 6
  • 46
  • 53

1 Answers1

16

Unwrap the environment and get the id from the spec

name = env.unwrapped.spec.id

print(name)
# 'CartPole-v0'

In vectorized environments, access the first sub-environment:

name = env.envs[0].unwrapped.spec.id
Andrew Schreiber
  • 14,344
  • 6
  • 46
  • 53