当前位置: 首页>>代码示例>>Python>>正文


Python pkgutil.get_data方法代码示例

本文整理汇总了Python中pkgutil.get_data方法的典型用法代码示例。如果您正苦于以下问题:Python pkgutil.get_data方法的具体用法?Python pkgutil.get_data怎么用?Python pkgutil.get_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pkgutil的用法示例。


在下文中一共展示了pkgutil.get_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_packaged_grammar

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def load_packaged_grammar(package, grammar_source):
    """Normally, loads a pickled grammar by doing
        pkgutil.get_data(package, pickled_grammar)
    where *pickled_grammar* is computed from *grammar_source* by adding the
    Python version and using a ``.pickle`` extension.

    However, if *grammar_source* is an extant file, load_grammar(grammar_source)
    is called instead. This facilitates using a packaged grammar file when needed
    but preserves load_grammar's automatic regeneration behavior when possible.

    """
    if os.path.isfile(grammar_source):
        return load_grammar(grammar_source)
    pickled_name = _generate_pickle_name(os.path.basename(grammar_source))
    data = pkgutil.get_data(package, pickled_name)
    g = grammar.Grammar()
    g.loads(data)
    return g 
开发者ID:remg427,项目名称:misp42splunk,代码行数:20,代码来源:driver.py

示例2: load_wordlist

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def load_wordlist(name):
    """Iterate over lines of a wordlist data file.

    `name` should be the name of a package data file within the data/
    directory.

    Whitespace and #-prefixed comments are stripped from each line.

    """
    text = pkgutil.get_data('pydocstyle', 'data/' + name).decode('utf8')
    for line in text.splitlines():
        line = COMMENT_RE.sub('', line).strip()
        if line:
            yield line


#: A dict mapping stemmed verbs to the imperative form 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:19,代码来源:wordlists.py

示例3: init_jsengine

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def init_jsengine():
    global js_ctx
    if js_ctx is None:
        from ykdl.util.jsengine import JSEngine
        assert JSEngine, "No JS Interpreter found, can't use cmd5x!"
        js_ctx = JSEngine()

        from pkgutil import get_data
        # code from https://zsaim.github.io/2019/08/23/Iqiyi-cmd5x-Analysis/
        try:
            # try load local .js file first
            js = get_data(__name__, 'cmd5x.js')
        except IOError:
            # origin https://raw.githubusercontent.com/ZSAIm/ZSAIm.github.io/master/misc/2019-08-23/iqiyi_cmd5x.js
            js = get_content('https://raw.githubusercontent.com/zhangn1985/ykdl/master/ykdl/extractors/iqiyi/cmd5x.js')
        js_ctx.append(js)

        # code from https://github.com/lldy/js
        try:
            # try load local .js file first
            js = get_data(__name__, 'cmd5x_iqiyi3.js')
        except IOError:
            js = get_content('https://raw.githubusercontent.com/zhangn1985/ykdl/master/ykdl/extractors/iqiyi/cmd5x_iqiyi3.js')
        js_ctx.append(js) 
开发者ID:ForgQi,项目名称:bilibiliupload,代码行数:26,代码来源:util.py

示例4: load_zoo_agent_params

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def load_zoo_agent_params(tag, env_name, index):
    """Loads parameters for the gym_compete zoo agent, but does not restore them.
    :param tag: (str) version of the zoo agent (e.g. '1', '2', '3').
    :param env_name: (str) Gym environment ID
    :param index: (int) the player ID of the agent we want to load ('0' or '1')
    :return a NumPy array of policy weights."""
    # Load parameters
    canonical_env = env_name_to_canonical(env_name)
    agent_dir = os.path.join("agent_zoo", canonical_env)

    if is_symmetric(env_name):  # asymmetric version, parameters tagged with agent id
        symmetric_fname = f"agent_parameters-v{tag}.pkl"
        path = os.path.join(agent_dir, symmetric_fname)
        params_pkl = pkgutil.get_data("gym_compete", path)
    else:  # symmetric version, parameters not associated with a specific agent
        asymmetric_fname = f"agent{index + 1}_parameters-v{tag}.pkl"
        path = os.path.join(agent_dir, asymmetric_fname)
        params_pkl = pkgutil.get_data("gym_compete", path)

    pylog.info(f"Loaded zoo parameters from '{path}'")

    return pickle.loads(params_pkl) 
开发者ID:HumanCompatibleAI,项目名称:adversarial-policies,代码行数:24,代码来源:gym_compete.py

示例5: get_data

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def get_data():
		'''
		Returns
		-------
		pd.DataFrame

		I.e.,
		>>> convention_df.iloc[0]
		category                                                    plot
		filename                 subjectivity_html/obj/2002/Abandon.html
		text           A senior at an elite college (Katie Holmes), a...
		movie_name                                               abandon
		'''
		try:
			data_stream = pkgutil.get_data('scattertext', 'data/rotten_tomatoes_corpus.csv.bz2')
		except:
			url = ROTTEN_TOMATOES_DATA_URL
			data_stream = urlopen(url).read()
		return pd.read_csv(io.BytesIO(bz2.decompress(data_stream))) 
开发者ID:JasonKessler,项目名称:scattertext,代码行数:21,代码来源:SampleCorpora.py

示例6: get_full_data

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def get_full_data():
		'''
		Returns all plots and reviews, not just the ones that appear in movies with both plot descriptions and reviews.

		Returns
		-------
		pd.DataFrame

		I.e.,
		>>> convention_df.iloc[0]
		category                                                             plot
		text                    Vijay Singh Rajput (Amitabh Bachchan) is a qui...
		movie_name                                                        aankhen
		has_plot_and_reviews                                                False
		Name: 0, dtype: object
		'''
		try:
			data_stream = pkgutil.get_data('scattertext', 'data/rotten_tomatoes_corpus_full.csv.bz2')
		except:
			url = ROTTEN_TOMATOES_DATA_URL
			data_stream = urlopen(url).read()
		return pd.read_csv(io.BytesIO(bz2.decompress(data_stream))) 
开发者ID:JasonKessler,项目名称:scattertext,代码行数:24,代码来源:SampleCorpora.py

示例7: chars

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def chars(self, category=None):
        """
        This module returns a list of characters from  the Perl Unicode Properties.
        They are very useful when porting Perl tokenizers to Python.

            >>> from sacremoses.corpus import Perluniprops
            >>> pup = Perluniprops()
            >>> list(pup.chars('Open_Punctuation'))[:5] == [u'(', u'[', u'{', u'\u0f3a', u'\u0f3c']
            True
            >>> list(pup.chars('Currency_Symbol'))[:5] == [u'$', u'\xa2', u'\xa3', u'\xa4', u'\xa5']
            True
            >>> pup.available_categories[:5]
            ['Close_Punctuation', 'Currency_Symbol', 'IsAlnum', 'IsAlpha', 'IsLower']

        :return: a generator of characters given the specific unicode character category
        """
        relative_path = os.path.join("data", "perluniprops", category + ".txt")
        binary_data = pkgutil.get_data("sacremoses", relative_path)
        for ch in binary_data.decode("utf-8"):
            yield ch 
开发者ID:alvations,项目名称:sacremoses,代码行数:22,代码来源:corpus.py

示例8: populate_pod_charge

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def populate_pod_charge(self, cpu_temp_table, mem_temp_table):
        """Populate the memory and cpu charge on daily summary table.

        Args:
            cpu_temp_table (String) Name of cpu charge temp table
            mem_temp_table (String) Name of mem charge temp table

        Returns
            (None)

        """
        table_name = OCP_REPORT_TABLE_MAP["line_item_daily_summary"]

        daily_charge_sql = pkgutil.get_data("masu.database", "sql/reporting_ocpusagelineitem_daily_pod_charge.sql")
        charge_line_sql = daily_charge_sql.decode("utf-8")
        charge_line_sql_params = {"cpu_temp": cpu_temp_table, "mem_temp": mem_temp_table, "schema": self.schema}
        charge_line_sql, charge_line_sql_params = self.jinja_sql.prepare_query(charge_line_sql, charge_line_sql_params)
        self._execute_raw_sql_query(table_name, charge_line_sql, bind_params=list(charge_line_sql_params)) 
开发者ID:project-koku,项目名称:koku,代码行数:20,代码来源:ocp_report_db_accessor.py

示例9: populate_line_item_daily_table

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def populate_line_item_daily_table(self, start_date, end_date, bill_ids):
        """Populate the daily aggregate of line items table.

        Args:
            start_date (datetime.date) The date to start populating the table.
            end_date (datetime.date) The date to end on.
            bill_ids (list)

        Returns
            (None)

        """
        table_name = AWS_CUR_TABLE_MAP["line_item_daily"]

        daily_sql = pkgutil.get_data("masu.database", "sql/reporting_awscostentrylineitem_daily.sql")
        daily_sql = daily_sql.decode("utf-8")
        daily_sql_params = {
            "uuid": str(uuid.uuid4()).replace("-", "_"),
            "start_date": start_date,
            "end_date": end_date,
            "bill_ids": bill_ids,
            "schema": self.schema,
        }
        daily_sql, daily_sql_params = self.jinja_sql.prepare_query(daily_sql, daily_sql_params)
        self._execute_raw_sql_query(table_name, daily_sql, start_date, end_date, bind_params=list(daily_sql_params)) 
开发者ID:project-koku,项目名称:koku,代码行数:27,代码来源:aws_report_db_accessor.py

示例10: __init__

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def __init__(self, root, engine, ctx=None, debug=False):
        self.root = root
        self.engine = engine
        self.ctx = ctx
        self.debug = debug
        self._console_html = string.Template(_decode(
            pkgutil.get_data('hiku.console', 'assets/console.html')
        ))
        self._docs_content = dumps_typedef(root) 
开发者ID:vmagamedov,项目名称:hiku,代码行数:11,代码来源:ui.py

示例11: _static_get

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def _static_get(self, environ, start_response):
        content = pkgutil.get_data('hiku.console', 'assets/console.js')
        start_response('200 OK', [
            ('Content-Type', 'text/javascript; charset=UTF-8'),
            ('Content-Length', str(len(content))),
        ])
        return [content] 
开发者ID:vmagamedov,项目名称:hiku,代码行数:9,代码来源:ui.py

示例12: load_schema

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def load_schema(name):
    """
    Load a schema from ./schemas/``name``.json and return it.

    """

    data = pkgutil.get_data('jsonschema', "schemas/{0}.json".format(name))
    return json.loads(data.decode("utf-8")) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:10,代码来源:_utils.py

示例13: loadFromPackage

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def loadFromPackage(path, withNumbers=True):
    """
    功能:从模块包中加载 YAML 数据库
    输入:路径 path
    输出:yaml 解析器加载后的数据
    """
    return yaml.load(pkgutil.get_data(__package__, path).decode(), Loader=yaml.SafeLoader if withNumbers else yaml.BaseLoader) 
开发者ID:lanluoxiao,项目名称:Chai,代码行数:9,代码来源:tools.py

示例14: load_schema

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def load_schema(name):
    """
    Load a schema from ./schemas/``name``.json and return it.

    """

    data = pkgutil.get_data(__package__, "schemas/{0}.json".format(name))
    return json.loads(data.decode("utf-8")) 
开发者ID:getavalon,项目名称:core,代码行数:10,代码来源:_utils.py

示例15: _extract_from_package

# 需要导入模块: import pkgutil [as 别名]
# 或者: from pkgutil import get_data [as 别名]
def _extract_from_package(resource):
    data = pkgutil.get_data('tempocnn', resource)
    with tempfile.NamedTemporaryFile(prefix='model', suffix='.h5', delete=False) as f:
        f.write(data)
        name = f.name
    return name 
开发者ID:hendriks73,项目名称:tempo-cnn,代码行数:8,代码来源:classifier.py


注:本文中的pkgutil.get_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。