benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf e4909d57-eeae-5854-ba16-abb48502ca00

Problem

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

complete prompt

import codecs
import os
import glob

# Constants
DIRECTORY_PATH = './files/'

def task_func(directory=DIRECTORY_PATH, from_encoding='cp1251', to_encoding='utf8'):
    """
    Convert the encoding of all text files in a specified directory from one encoding to another. 
    The function modifies the files in-place.
    
    Parameters:
    - directory (str): The directory where the text files are located. Default is './files/'.
    - from_encoding (str): The original encoding of the text files. Default is 'cp1251'.
    - to_encoding (str): The encoding to which the text files should be converted. Default is 'utf8'.
    
    Returns:
    - None
    
    Requirements:
    - codecs
    - os
    - glob
    
    Example:
    >>> task_func('./files/', 'cp1251', 'utf8')  # Converts all .txt files in './files/' from 'cp1251' to 'utf8'
    >>> task_func('./other_files/', 'utf8', 'ascii')  # Converts all .txt files in './other_files/' from 'utf8' to 'ascii'
    """

instruct prompt

Convert the encoding of all text files in a specified directory from one encoding to another. The function modifies the files in-place.
The function should output with:
    None
You should write self-contained code starting with:

Code

import codecs
import os
import glob
# Constants
DIRECTORY_PATH = './files/'
def task_func(directory=DIRECTORY_PATH, from_encoding='cp1251', to_encoding='utf8'):

code prompt

Code

import codecs
import os
import glob
# Constants
DIRECTORY_PATH = './files/'
def task_func(directory=DIRECTORY_PATH, from_encoding='cp1251', to_encoding='utf8'):

entry point

task_func

libs

  • codecs
  • glob
  • 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