1. for loop list 만들기
[bean for bean in beans if bean.type == 'coffee']
2. yeild / next
def permutations_dup(array, r):
for i in range(len(array)):
if r == 1:
yield [array[i]]
else:
for next in permutations_dup(array, r-1):
yield [array[i]] + next
[bean for bean in beans if bean.type == 'coffee']
def permutations_dup(array, r):
for i in range(len(array)):
if r == 1:
yield [array[i]]
else:
for next in permutations_dup(array, r-1):
yield [array[i]] + next
import os정확한 이유는 모르겠는데...
import subprocess
input_path = r"input"
file_list = os.listdir(input_path)
output_path = r"output"
for each_file in file_list:
input_file = os.path.join(input_path, each_file)
output_file = os.path.join(output_path, each_file)
if input_file.endswith(".pcap") is False:
continue
command = f'tshark -r "{input_file} -w "{output_file}" -Y "tcp"'
subprocess.check_output(command, shell=False)
import gnwrapper
import gym
env = gnwrapper.Animation(gym.make('CartPole-v1'))
obs = env.reset()
for _ in range(1000):
next_obs, reward, done, info = env.step(env.action_space.sample())
env.render()
obs = next_obs
if done:
obs = env.reset()
>>> gym.__version__
'0.26.1'
>>> exit()
nitraqu@nitraqu-7c79:~$ uname -ar
Linux nitraqu-7c79 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
print (gym.__version__)import gym
print (gym.__version__)
env = gym.make('CartPole-v1', render_mode='human')
for i_episode in range(20):
# 새로운 에피소드(initial environment)를 불러온다(reset)
observation = env.reset()
for t in range(100):
env.render()
# 행동(action)을 취하기 이전에 환경에 대해 얻은 관찰값(observation)
print('observation before action:')
print(observation)
action = env.action_space.sample()
observation, reward, done, truncated, info = env.step(action)
# 행동(action)을 취한 이후에 환경에 대해 얻은 관찰값(observation)
print('observation after action:')
print(observation)
if done:
print("Episode finished after {} timesteps".format(t+1))
break
최근 덧글