benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 84388054-03e3-5f1d-9a63-866674614530

Problem

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

complete prompt

import csv
import json
import os


def task_func(file_name):
    """
    Convert a csv file to a json file.
    
    Parameters:
    file_name (str): The name of the csv file.
    
    Returns:
    str: The file name of the created json file.

    Requirements:
    - csv
    - json
    - os

    Raises:
    FileNotFoundError: If the file does not exist.
    
    Example:
    >>> import tempfile
    >>> FILE_NAME = tempfile.NamedTemporaryFile(prefix='report_', suffix='.csv', dir='/tmp').name
    >>> with open(FILE_NAME, 'w', newline='') as csvfile:
    ...     fieldnames = ['id', 'name', 'age']
    ...     writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
    ...     _ = writer.writeheader()
    ...     _ = writer.writerow({'id': '1', 'name': 'John', 'age': '25'})
    ...     _ = writer.writerow({'id': '2', 'name': 'Doe', 'age': '30'})
    >>> json_file = task_func(FILE_NAME)
    >>> print(json_file.startswith('/tmp/report_') and json_file.endswith('.json'))
    True
    """

instruct prompt

Convert a csv file to a json file.
The function should raise the exception for: FileNotFoundError: If the file does not exist.
The function should output with:
    str: The file name of the created json file.
You should write self-contained code starting with:

Code

import csv
import json
import os
def task_func(file_name):

code prompt

Code

import csv
import json
import os
def task_func(file_name):

entry point

task_func

libs

  • csv
  • json
  • os

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