benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf d50b3b67-334f-5a39-8237-ea64c88f01db

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import os
import sys
import importlib
from pkgutil import iter_modules


def task_func(package_name):
    """
    Adds all modules of a specified package to the system path. This function is useful for dynamically
    importing modules from a package that might not be on the standard path.

    Parameters:
    package_name (str): The name of the package whose modules are to be added to the system path.

    Returns:
    list: A list of module names that were added to the system path.

    Raises:
    ImportError: If the package is not installed or cannot be found. The exception message should contain
                 the instruction to install the package (i.e., f"pip install {package_name}").

    Requirements:
    - os
    - sys
    - importlib
    - pkgutil.iter_modules

    Examples:
    Assuming 'pandas' is a valid package with modules 'module1' and 'module2',

    >>> len(task_func('pandas')) >= 2
    True

    Verify that 'numpy' (a common package) modules are added to the path,
    >>> 'random' in task_func('numpy')
    True
    """

instruct prompt

Adds all modules of a specified package to the system path. This function is useful for dynamically importing modules from a package that might not be on the standard path. >>> len(task_func('pandas')) >= 2 True Verify that 'numpy' (a common package) modules are added to the path, >>> 'random' in task_func('numpy') True
The function should raise the exception for: ImportError: If the package is not installed or cannot be found. The exception message should contain the instruction to install the package (i.e., f"pip install {package_name}").
The function should output with:
    list: A list of module names that were added to the system path.
You should write self-contained code starting with:

Code

import os
import sys
import importlib
from pkgutil import iter_modules
def task_func(package_name):

code prompt

Code

import os
import sys
import importlib
from pkgutil import iter_modules
def task_func(package_name):

entry point

task_func

libs

  • importlib
  • pkgutil
  • os
  • sys

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import