import contents while creating a new openai-gym env - openai-gym

Use gym_soccer as example, when I import gym_soccer, it's a wrapped ENV. Classes defined in soccer_env.py wouldn't show-up.
I think there should be a way to make it work but can't find out.
soccer_env.py
import gym
import logging
logger = logging.getLogger()
class SoccerEnv(gym.Env):
pass
class Dummy(object):
pass
when you run it in python:
import gym_soccer
dir(gym_soccer)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'logger', 'logging', 'register']
I would like to see Dummy and SoccerEnv class available to use. Or is it possible?

OK. It's hide in gym_soccer.envs.Dummy if you add "from gym_soccer.envs.soccer_env import Dummy".

Related

ODI selective Reverse Engineering through groovy script

I try to use ODI-SDK with groovy scripting to automate selective reverse-engineering datastores to model. To do this, i used following script doStandardReverse() method, but getting error. I am trying to execute below script.
I have used API mentioned in below documentation
https://docs.oracle.com/middleware/12211/odi/reference-java-api/oracle/odi/core/service/reverse/ReverseService.html
import oracle.odi.domain.project.finder.IOdiProjectFinder
import oracle.odi.domain.model.finder.IOdiDataStoreFinder
import oracle.odi.domain.model.finder.IOdiModelFinder
import oracle.odi.domain.model.OdiModel
import oracle.odi.domain.model.OdiModelFolder
import oracle.odi.domain.model.OdiModel.ReverseObjectType
import oracle.odi.domain.project.finder.IOdiFolderFinder
import oracle.odi.domain.project.finder.IOdiUserProcedureFinder
import oracle.odi.domain.project.finder.IOdiKMFinder
import oracle.odi.domain.mapping.finder.IMappingFinder
import oracle.odi.domain.adapter.project.IKnowledgeModule.ProcessingType
import oracle.odi.domain.topology.finder.IOdiContextFinder
import oracle.odi.domain.topology.finder.IOdiLogicalSchemaFinder
import oracle.odi.domain.topology.finder.IOdiTechnologyFinder
import oracle.odi.domain.topology.OdiContext
import oracle.odi.domain.topology.OdiTechnology
import oracle.odi.domain.topology.OdiLogicalSchema
import oracle.odi.domain.model.OdiDataStore
import oracle.odi.domain.xrefs.expression.Expression
import oracle.odi.domain.xrefs.expression.Expression.SqlGroupType
import oracle.odi.domain.project.OdiProcedureLine.LogCounter
import oracle.odi.domain.project.OdiProcedureLineCmd
import oracle.odi.domain.project.OdiUserProcedure
import oracle.odi.domain.project.OdiUserProcedureLine
import oracle.odi.domain.project.OdiPackage
import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition
import oracle.odi.core.service.reverse.ReverseService
import oracle.odi.domain.project.StepModel.ReverseModel
txnDef = new DefaultTransactionDefinition()
tm = odiInstance.getTransactionManager()
tme = odiInstance.getTransactionalEntityManager()
txnStatus = tm.getTransaction(txnDef)
def myList = ["SNP_CHECK_TAB","SRC_CITY"]
OdiModel srcModel = ((IOdiModelFinder)tme.getFinder(OdiModel.class)).findByCode("TEST_MOD");
//call reverse engeneering
rs = new ReverseService();
rm = rs.doStandardReverse(odiInstance, srcModel.getModelId(), ReverseService.DataStoreSelection.SELECTED, myList);
println('Data Store/s created.');
tm.commit(txnStatus)
I am getting error below
java.lang.String cannot be cast to oracle.odi.core.service.reverse.OdiDataStoreNameAndType
(Subtract 18 from the error line number to account for the standard imports)
java.lang.ClassCastException: java.lang.String cannot be cast to oracle.odi.core.service.reverse.OdiDataStoreNameAndType
at oracle.odi.core.service.reverse.ReverseService.convertDataStoreListToSnpsStringPair(ReverseService.java:452)
at oracle.odi.core.service.reverse.ReverseService.doStandardReverse(ReverseService.java:169)
at oracle.odi.core.service.reverse.ReverseService$doStandardReverse.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)
at di.run(di.groovy:61)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
at groovy.lang.GroovyShell.run(GroovyShell.java:518)
at groovy.lang.GroovyShell.run(GroovyShell.java:497)
at groovy.lang.GroovyShell.run(GroovyShell.java:170)
at oracle.di.studio.groovy.GroovyScriptRunInstance.run(GroovyScriptRunInstance.java:222)
Script exited.
Your list contains Strings where it should contain OdiDataStore objects.
findByName method of interface IOdiDataStoreFinder can be used to find a specific OdiDataStore object.

module 'subprocess' has no attribute '_subprocess'

I used python3.7 in windows7.
When I tried to run this line: suinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
error occurs: module 'subprocess' has no attribute '_subprocess'
import os
import sqlite3
import subprocess
import time
import re
from django.core.mail import send_mail
from django.http import HttpResponse
suinfo = subprocess.STARTUPINFO()
suinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
How to deal with that?
There is no such thing as subprocess._subprocess, the constant is straight under subprocess:
suinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
See the docs: https://docs.python.org/3/library/subprocess.html#subprocess.STARTF_USESHOWWINDOW

ModuleNotFoundError using items.py

Trying to implement an Item Loader.
my class name in items.py:
SiemensLinkcontentItem
my import statements inside my spider:
import scrapy
from scrapy.loader import ItemLoader
from siemens_linkcontent.siemens_linkcontent.items import SiemensLinkcontentItem
I get the following error:
No module named 'siemens_linkcontent.siemens_linkcontent'
My path diagramm is the following:
Use This One
- from siemens_linkcontent.items import SiemensLinkcontentItem

Python module not accessible to function inside class

Code below works as expected. It prints 5 random numbers.
import numpy as np
class test_class():
def __init__(self):
self.rand_nums = self.create_rand_num()
def create_rand_num(self):
numbers = np.random.rand(5)
return numbers
myclass = test_class()
myclass.rand_nums
However, the following does not work. NameError: name 'np' is not defined
import numpy as np
from test.calc import create_rand_num
class test_class():
def __init__(self):
self.rand_nums = create_rand_num()
myclass = test_class()
myclass.rand_nums
# contents of calc.py in test folder:
def create_rand_num():
print(np.random.rand(5))
But, this works:
from test.calc import create_rand_num
class test_class():
def __init__(self):
self.rand_nums = create_rand_num()
myclass = test_class()
myclass.rand_nums
# contents of calc.py in test folder:
import numpy as np
def create_rand_num():
print(np.random.rand(5))
Why must I have 'import numpy as np' inside calc.py? I already have this import before my class definition. I am sure I am misunderstanding something here, but I was trying to follow the general rule to have all the import statements at the top of the main code.
What I find confusing is that when I say "from test.calc import create_rand_num," how does Python know whether "import numpy as np" is included at the top of calc.py or not? It must know somehow, because when I include it, the code works, but when I leave it out, the code does not work.
EDIT: After reading the response from #DeepSpace, I want to ask the following:
Suppose I have the following file.py module with contents listed as shown:
import numpy as np
import pandas as pd
import x as y
def myfunc():
pass
So, if I have another file, file1.py, and in it, I say from file.py import myfunc, do I get access to np, pd, and y? This is exactly what seems to be happening in my third example above.
In my third example, notice that np is NOT defined anywhere in the main file, it is only defined in calc.py file, and I am not importing * from calc.py, I am only importing create_rand_num. Why do I not get the same NameError error?
Python is not like C. Importing a module does not copy-paste its source. It simply adds a reference to it to the locals() "namespace". import numpy as np in one file does not make it magically available in all other files.
You have to import numpy as np in every file you want to use np.
Perhaps a worthwhile reading: https://docs.python.org/3.7/reference/simple_stmts.html#the-import-statement

python relative import not working as expected

I have the following module package organization
models
├── __init__.py
├── __pycache__
│   ├── __init__.cpython-34.pyc
│   ├── model.cpython-34.pyc
│   └── user.cpython-34.pyc
└── user.py
1 directory, 5 files
following are the contents of my __init__.py:
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
from .user import User
on running
>>> from models import *
>>> dir()
['SQLAlchemy', 'User', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'db', 'user']
Notice that user is also in the list, whereas I explicitly did from .user import User inside __init__.py.
I am not able to understand this behavior, because if I simply do
>>> from models.user import User
>>> dir()
['User', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
I only get User.
How to achieve the same result with the __init__.py file, i.e. how to import only db and User and not user.
Note: user is the module user.py and User is the class inside it.
Add the line:
__all__ = ['User', 'db']
at the beginning of your __init__.py.
__all__ whitelists the names that will be imported by from module import *.
From the docs:
Modules can now control which names are imported when from module import * is used, by defining an __all__ attribute containing a list of names that will be imported. One common complaint is that if the module imports other modules such as sys orstring, from moduleimport * will add them to the importing module’s namespace. To fix this, simply list the public names in __all__:
# List public names
__all__ = ['Database', 'open']

Resources