{"id":117656,"date":"2026-05-11T18:25:57","date_gmt":"2026-05-11T12:55:57","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/?page_id=117656"},"modified":"2026-05-11T18:23:03","modified_gmt":"2026-05-11T12:53:03","slug":"python-program-file-copy-utility","status":"publish","type":"page","link":"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/","title":{"rendered":"Python Program File Copy Utility"},"content":{"rendered":"\n<link rel=\"stylesheet\" href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/codemirror\/5.65.16\/codemirror.min.css\" \/>\n<link rel=\"stylesheet\" href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/codemirror\/5.65.16\/theme\/eclipse.min.css\" \/>\n<link rel=\"stylesheet\" href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/font-awesome\/6.4.0\/css\/all.min.css\">\n\n<style>\n    .py-filecopy-wrapper {\n        --py-bg-app: #f9fafb;\n        --py-bg-panel: #ffffff;\n        --py-border: #e5e7eb;\n        --py-text-primary: #1f2937;\n        --py-text-secondary: #6b7280;\n        --py-primary-blue: #2563eb;\n        --py-primary-hover: #1d4ed8;\n        --py-header-height: 50px;\n        --py-footer-height: 60px;\n\n        font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, sans-serif;\n        background-color: var(--py-bg-app);\n        color: var(--py-text-primary);\n        width: 100%;\n        border: 1px solid var(--py-border);\n        box-sizing: border-box;\n        display: flex;\n        flex-direction: column;\n        min-height: 85vh;\n    }\n\n    .py-filecopy-wrapper * { box-sizing: border-box; }\n\n    .py-filecopy-top-nav {\n        display: flex;\n        align-items: center;\n        justify-content: space-between;\n        height: var(--py-header-height);\n        padding: 0 20px;\n        background: var(--py-bg-panel);\n        border-bottom: 1px solid var(--py-border);\n        min-width: 100%;\n    }\n    .py-filecopy-nav-title { font-weight: 600; color: var(--py-text-secondary); font-size: 14px; }\n\n    .py-filecopy-ide-container {\n        display: flex;\n        flex: 1;\n        height: auto;\n        min-width: 100%;\n        background: white;\n        overflow: hidden;\n    }\n\n    .py-filecopy-left-pane {\n        width: 45%;\n        border-right: 1px solid var(--py-border);\n        background: var(--py-bg-panel);\n        display: flex;\n        flex-direction: column;\n    }\n\n    .py-filecopy-tabs-header {\n        height: var(--py-header-height);\n        border-bottom: 1px solid var(--py-border);\n        display: flex;\n        align-items: center;\n        padding: 0 20px;\n        gap: 25px;\n        font-size: 14px;\n        font-weight: 500;\n        color: var(--py-text-secondary);\n    }\n\n    .py-filecopy-tab-item { cursor: pointer; padding: 14px 0; border-bottom: 2px solid transparent; }\n    .py-filecopy-tab-item.active { color: var(--py-text-primary); border-bottom-color: var(--py-primary-blue); }\n    .py-filecopy-tab-item:hover { color: var(--py-text-primary); }\n\n    .py-filecopy-pane-content { flex: 1; overflow-y: auto; padding: 25px; display: none; }\n    .py-filecopy-pane-content.active { display: block; }\n\n    .py-filecopy-wrapper h1 { margin-top: 0; font-size: 22px; font-weight: 600; color: var(--py-text-primary); margin-bottom: 1rem; }\n    .py-filecopy-wrapper p { line-height: 1.6; color: #374151; margin-bottom: 1rem; }\n    .py-filecopy-wrapper ul { margin-bottom: 20px; color: #374151; line-height: 1.6; padding-left: 20px; }\n    .py-filecopy-wrapper li { margin-bottom: 5px; }\n    .py-filecopy-wrapper h3 { font-size: 16px; margin-top: 15px; margin-bottom: 10px; }\n\n    .py-filecopy-solution-block {\n        background: #f8f9fa; border: 1px solid var(--py-border); padding: 15px;\n        border-radius: 6px; font-family: 'Consolas', monospace; font-size: 14px;\n        color: #333; white-space: pre-wrap; overflow-x: auto;\n    }\n\n    .py-filecopy-sample-box { background-color: #f3f4f6; border: 1px solid var(--py-border); border-radius: 6px; margin-top: 20px; overflow: hidden; }\n    .py-filecopy-sample-header { display: flex; background-color: #e5e7eb; font-size: 13px; font-weight: 600; color: var(--py-text-primary); }\n    .py-filecopy-sample-col-title { width: 50%; padding: 8px 15px; border-right: 1px solid #d1d5db; }\n    .py-filecopy-sample-col-content { width: 50%; padding: 15px; font-family: 'Consolas', monospace; font-size: 14px; border-right: 1px solid var(--py-border); white-space: pre-wrap; color: #333; }\n    .py-filecopy-sample-body { display: flex; }\n\n    .py-filecopy-right-pane {\n        width: 55%; display: flex; flex-direction: column; background: var(--py-bg-panel);\n    }\n\n    .py-filecopy-editor-top-bar {\n        height: var(--py-header-height); border-bottom: 1px solid var(--py-border);\n        display: flex; align-items: center; justify-content: space-between;\n        padding: 0 15px; background-color: #f9fafb;\n    }\n\n    .py-filecopy-lang-label { font-weight: 600; font-size: 14px; background: #e5e7eb; padding: 4px 12px; border-radius: 4px; }\n    .py-filecopy-editor-settings i { color: var(--py-text-secondary); margin-left: 15px; cursor: pointer; font-size: 16px; }\n\n    .py-filecopy-code-area { flex: 1; display: flex; flex-direction: column; position: relative; }\n    .py-filecopy-code-area .CodeMirror { flex: 1; height: 100%; position: absolute; top: 0; bottom: 0; left: 0; right: 0; font-family: 'Source Code Pro', monospace; font-size: 15px; }\n\n    .py-filecopy-console-section {\n        border-top: 1px solid var(--py-border); background: #f9fafb;\n        display: flex; flex-direction: column; height: 35%;\n    }\n    .py-filecopy-console-header { padding: 8px 15px; background: #e5e7eb; font-size: 12px; font-weight: 600; color: var(--py-text-secondary); text-transform: uppercase; }\n    .py-filecopy-console-body { display: flex; flex: 1; overflow: hidden; }\n    .py-filecopy-input-wrapper, .py-filecopy-output-wrapper { flex: 1; display: flex; flex-direction: column; padding: 10px; border-right: 1px solid var(--py-border); }\n    .py-filecopy-output-wrapper { border-right: none; }\n    .py-filecopy-console-label { font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--py-text-secondary); }\n\n    textarea.py-filecopy-custom-input-area { flex: 1; border: 1px solid var(--py-border); border-radius: 4px; resize: none; padding: 8px; font-family: monospace; width: 100%; }\n\n    .py-filecopy-output-display {\n        flex: 1; background: white; border: 1px solid var(--py-border);\n        border-radius: 4px; padding: 8px; font-family: monospace;\n        white-space: pre-wrap; overflow-y: auto; font-size: 13px;\n        line-height: 1.15;\n    }\n\n    .py-filecopy-footer-actions {\n        height: var(--py-footer-height);\n        border-top: 1px solid var(--py-border);\n        display: flex;\n        align-items: center;\n        justify-content: flex-end;\n        padding: 0 20px;\n        background-color: var(--py-bg-panel);\n    }\n\n    .py-filecopy-execution-group { display: flex; gap: 12px; align-items: center; }\n\n    .py-filecopy-btn {\n        padding: 8px 20px; border-radius: 4px; font-size: 14px; font-weight: 600;\n        cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;\n        justify-content: center; transition: 0.2s; height: 38px; box-shadow: none; border: none;\n    }\n\n    .py-filecopy-btn-secondary { background: transparent; border: 1px solid var(--py-border); color: var(--py-text-primary); }\n    .py-filecopy-btn-secondary:hover { background: #f3f4f6; }\n    .py-filecopy-btn-primary { background: var(--py-primary-blue); border: 1px solid var(--py-primary-blue); color: white; }\n    .py-filecopy-btn-primary:hover { background: var(--py-primary-hover); }\n\n    .py-filecopy-spinner {\n        display: none; width: 14px; height: 14px;\n        border: 2px solid #fff; border-top-color: transparent;\n        border-radius: 50%; animation: py-filecopy-spin 0.8s linear infinite; margin-left: 8px;\n    }\n    @keyframes py-filecopy-spin { 100% { transform: rotate(360deg); } }\n\n    .py-filecopy-hidden { display: none !important; }\n    .py-filecopy-btn-mobile { display: none !important; }\n\n    @media (max-width: 768px) {\n        .py-filecopy-wrapper { display: block; height: auto; min-height: auto; }\n        .py-filecopy-ide-container { flex: none; height: auto; }\n        .py-filecopy-top-nav { display: none; }\n        .py-filecopy-ide-container { flex-direction: column; overflow-y: auto; height: auto; }\n        .py-filecopy-left-pane, .py-filecopy-right-pane { width: 100%; height: auto; }\n        .py-filecopy-left-pane { border-right: none; border-bottom: 8px solid #f3f4f6; min-height: auto; max-height: 400px; }\n        .py-filecopy-right-pane { display: flex; flex-direction: column; }\n        .py-filecopy-console-section, .py-filecopy-console-body, .py-filecopy-footer-actions { display: contents; }\n        .py-filecopy-console-header { display: none; }\n        .py-filecopy-editor-top-bar { order: 1; }\n        .py-filecopy-code-area { order: 2; height: 500px; flex: none; }\n        .py-filecopy-code-area .CodeMirror { position: relative; height: 500px; }\n        .py-filecopy-input-wrapper { order: 3; width: 100%; height: auto; min-height: 280px; border-right: none; border-top: 8px solid #f3f4f6; border-bottom: 1px solid var(--py-border); }\n        .py-filecopy-execution-group { order: 4; width: 100%; display: flex; padding: 15px; gap: 10px; border-bottom: 1px solid var(--py-border); background: #fff; }\n        .py-filecopy-execution-group .py-filecopy-btn { flex: 1; }\n        .py-filecopy-output-wrapper { order: 5; width: 100%; height: auto; min-height: 300px; max-height: 500px; border-right: none; background: #fff; }\n        .py-filecopy-btn-mobile { display: inline-flex !important; order: 6; width: 48%; margin: 15px 1%; box-sizing: border-box; text-align: center; }\n        a.py-filecopy-hidden { display: none !important; }\n    }\n<\/style>\n\n<div class=\"py-filecopy-wrapper\">\n    <div class=\"py-filecopy-top-nav\">\n        <a id=\"py-filecopy-btn-prev-top\" class=\"py-filecopy-btn py-filecopy-btn-secondary py-filecopy-hidden\" href=\"#\">&larr; Previous<\/a>\n        <span class=\"py-filecopy-nav-title\">Module 7: File Handling &amp; Error Handling<\/span>\n        <a id=\"py-filecopy-btn-next-top\" class=\"py-filecopy-btn py-filecopy-btn-primary py-filecopy-hidden\" href=\"#\">Next &rarr;<\/a>\n    <\/div>\n\n    <div class=\"py-filecopy-ide-container\" id=\"py-filecopy-ideContainer\">\n\n        <div class=\"py-filecopy-left-pane\">\n            <div class=\"py-filecopy-tabs-header\">\n                <div class=\"py-filecopy-tab-item active\" onclick=\"pyFileCopySwitchTab('statement')\">Statement<\/div>\n                <div class=\"py-filecopy-tab-item\" onclick=\"pyFileCopySwitchTab('solution')\">Solution<\/div>\n            <\/div>\n\n            <div id=\"py-filecopy-tab-statement\" class=\"py-filecopy-pane-content active\">\n                <h1 id=\"python-exercise-7-3-file-copy-utility\">Python Exercise 7.3: File Copy Utility<\/h1>\n                <p>File I\/O is a fundamental skill in Python. Write a program that reads content from a source file, converts all text to uppercase, and writes the result to a destination file \u2014 simulating a basic file copy utility with transformation.<\/p>\n\n                <p>Your program should:<\/p>\n                <ul>\n                    <li>Ask the user to enter a <strong>source filename<\/strong> and a <strong>destination filename<\/strong>.<\/li>\n                    <li>Use a <code>try\/except<\/code> block to open and read the source file.<\/li>\n                    <li>Convert the entire file content to <strong>uppercase<\/strong> using <code>.upper()<\/code>.<\/li>\n                    <li>Write the transformed content to the destination file.<\/li>\n                    <li>Print a success message confirming the copy operation.<\/li>\n                    <li>Catch a <code>FileNotFoundError<\/code> if the source file does not exist and print an appropriate error message.<\/li>\n                    <li>Catch any other unexpected errors using a generic <code>Exception<\/code> handler.<\/li>\n                <\/ul>\n\n                <p><strong>Note:<\/strong> Since this environment simulates file I\/O, use the custom input box to provide the filenames. The grader will use pre-created test files (<code>source.txt<\/code>, <code>missing.txt<\/code>) to validate your logic.<\/p>\n\n                <h3 id=\"sample-interaction-1-success\">Sample Interaction 1 (Success):<\/h3>\n                <div class=\"py-filecopy-sample-box\">\n                    <div class=\"py-filecopy-sample-header\">\n                        <div class=\"py-filecopy-sample-col-title\">Input<\/div>\n                        <div class=\"py-filecopy-sample-col-title\">Output<\/div>\n                    <\/div>\n                    <div class=\"py-filecopy-sample-body\">\n                        <div class=\"py-filecopy-sample-col-content\">source.txt\ndestination.txt<\/div>\n                        <div class=\"py-filecopy-sample-col-content\">Enter source filename: source.txt\nEnter destination filename: destination.txt\nSuccess: Content copied to 'destination.txt' in uppercase.<\/div>\n                    <\/div>\n                <\/div>\n\n                <h3 id=\"sample-interaction-2-filenotfounderror\">Sample Interaction 2 (FileNotFoundError):<\/h3>\n                <div class=\"py-filecopy-sample-box\">\n                    <div class=\"py-filecopy-sample-header\">\n                        <div class=\"py-filecopy-sample-col-title\">Input<\/div>\n                        <div class=\"py-filecopy-sample-col-title\">Output<\/div>\n                    <\/div>\n                    <div class=\"py-filecopy-sample-body\">\n                        <div class=\"py-filecopy-sample-col-content\">missing.txt\ndestination.txt<\/div>\n                        <div class=\"py-filecopy-sample-col-content\">Enter source filename: missing.txt\nEnter destination filename: destination.txt\nError: Source file 'missing.txt' not found.<\/div>\n                    <\/div>\n                <\/div>\n            <\/div>\n\n            <div id=\"py-filecopy-tab-solution\" class=\"py-filecopy-pane-content\">\n                <h1 id=\"solution\">Solution<\/h1>\n                <p>We use a <code>try\/except<\/code> block to safely handle file operations. The <code>with<\/code> statement ensures files are properly closed even if an error occurs during reading or writing.<\/p>\n                <div class=\"py-filecopy-solution-block\">try:\n    source = input(\"Enter source filename: \")\n    destination = input(\"Enter destination filename: \")\n\n    with open(source, 'r') as src_file:\n        content = src_file.read()\n\n    uppercase_content = content.upper()\n\n    with open(destination, 'w') as dest_file:\n        dest_file.write(uppercase_content)\n\n    print(f\"Success: Content copied to '{destination}' in uppercase.\")\n\nexcept FileNotFoundError:\n    print(f\"Error: Source file '{source}' not found.\")\nexcept Exception as e:\n    print(f\"Error: An unexpected error occurred: {e}\")<\/div>\n\n                <p style=\"margin-top:20px\"><strong>Key Concepts:<\/strong><\/p>\n                <ul>\n                    <li>The <code>with open()<\/code> statement (context manager) automatically closes the file after the block executes.<\/li>\n                    <li><code>'r'<\/code> mode opens a file for reading; <code>'w'<\/code> mode opens a file for writing (creates if it doesn't exist).<\/li>\n                    <li><code>.read()<\/code> reads the entire file content as a single string.<\/li>\n                    <li><code>.upper()<\/code> converts all characters in a string to uppercase.<\/li>\n                    <li><code>FileNotFoundError<\/code> is raised when Python cannot locate the specified file path.<\/li>\n                    <li>A generic <code>except Exception as e<\/code> block catches any other unexpected errors and lets you inspect the error message.<\/li>\n                <\/ul>\n            <\/div>\n        <\/div>\n\n        <div class=\"py-filecopy-right-pane\">\n            <div class=\"py-filecopy-editor-top-bar\">\n                <span class=\"py-filecopy-lang-label\">Python 3<\/span>\n                <div class=\"py-filecopy-editor-settings\">\n                    <i class=\"fas fa-expand\" id=\"py-filecopy-fullscreenBtn\" title=\"Toggle Fullscreen\"><\/i>\n                <\/div>\n            <\/div>\n\n            <div class=\"py-filecopy-code-area\">\n                <div id=\"py-filecopy-code-editor-div\"><\/div>\n            <\/div>\n\n            <div class=\"py-filecopy-console-section\">\n                <div class=\"py-filecopy-console-header\">Test Console<\/div>\n                <div class=\"py-filecopy-console-body\">\n                    <div class=\"py-filecopy-input-wrapper\">\n                        <label class=\"py-filecopy-console-label\">Custom Input (Stdin)<\/label>\n                        <textarea id=\"py-filecopy-custom-input\" class=\"py-filecopy-custom-input-area\" placeholder=\"Enter each input on a new line&#10;e.g.&#10;source.txt&#10;destination.txt\"><\/textarea>\n                    <\/div>\n                    <div class=\"py-filecopy-output-wrapper\">\n                        <label class=\"py-filecopy-console-label\">Output<\/label>\n                        <div id=\"py-filecopy-output-console\" class=\"py-filecopy-output-display\">Run code to see output...<\/div>\n                    <\/div>\n                <\/div>\n            <\/div>\n\n            <div class=\"py-filecopy-footer-actions\">\n                <a id=\"py-filecopy-btn-prev-mobile\" class=\"py-filecopy-btn py-filecopy-btn-secondary py-filecopy-hidden py-filecopy-btn-mobile\" href=\"#\">&larr; Previous<\/a>\n\n                <div class=\"py-filecopy-execution-group\">\n                    <button class=\"py-filecopy-btn py-filecopy-btn-secondary\" onclick=\"pyFileCopyResetCode()\">Reset<\/button>\n                    <button class=\"py-filecopy-btn py-filecopy-btn-primary\" onclick=\"pyFileCopyRunCode()\">\n                        <span id=\"py-filecopy-btn-text\">Run Code<\/span>\n                        <span class=\"py-filecopy-spinner\" id=\"py-filecopy-btn-spinner\"><\/span>\n                    <\/button>\n                <\/div>\n\n                <a id=\"py-filecopy-btn-next-mobile\" class=\"py-filecopy-btn py-filecopy-btn-primary py-filecopy-hidden py-filecopy-btn-mobile\" href=\"#\">Next &rarr;<\/a>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n\n<script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/codemirror\/5.65.16\/codemirror.min.js\"><\/script>\n<script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/codemirror\/5.65.16\/mode\/python\/python.min.js\"><\/script>\n<script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/codemirror\/5.65.16\/addon\/edit\/closebrackets.min.js\"><\/script>\n\n<script>\n    var pyFileCopyEditor;\n    var pyFileCopyStarterCode;\n\n    const pyFileCopyPrevLink = \"\";\n    const pyFileCopyNextLink = \"\";\n\n    document.addEventListener(\"DOMContentLoaded\", function() {\n        const prevBtnTop = document.getElementById('py-filecopy-btn-prev-top');\n        const nextBtnTop = document.getElementById('py-filecopy-btn-next-top');\n        const prevBtnMobile = document.getElementById('py-filecopy-btn-prev-mobile');\n        const nextBtnMobile = document.getElementById('py-filecopy-btn-next-mobile');\n\n        if (pyFileCopyPrevLink && pyFileCopyPrevLink.trim() !== \"\") {\n            prevBtnTop.href = pyFileCopyPrevLink;\n            prevBtnMobile.href = pyFileCopyPrevLink;\n            prevBtnTop.classList.remove('py-filecopy-hidden');\n            prevBtnMobile.classList.remove('py-filecopy-hidden');\n        }\n\n        if (pyFileCopyNextLink && pyFileCopyNextLink.trim() !== \"\") {\n            nextBtnTop.href = pyFileCopyNextLink;\n            nextBtnMobile.href = pyFileCopyNextLink;\n            nextBtnTop.classList.remove('py-filecopy-hidden');\n            nextBtnMobile.classList.remove('py-filecopy-hidden');\n        }\n    });\n\n    function pyFileCopySwitchTab(tabName) {\n        document.querySelectorAll('#py-filecopy-tab-statement, #py-filecopy-tab-solution').forEach(el => el.classList.remove('active'));\n        const headerTabs = document.querySelector('#py-filecopy-ideContainer .py-filecopy-tabs-header').children;\n        Array.from(headerTabs).forEach(el => el.classList.remove('active'));\n        document.getElementById('py-filecopy-tab-' + tabName).classList.add('active');\n        if (tabName === 'statement') headerTabs[0].classList.add('active');\n        if (tabName === 'solution') headerTabs[1].classList.add('active');\n    }\n\n    const pyFileCopyFullscreenBtn = document.getElementById('py-filecopy-fullscreenBtn');\n    const pyFileCopyIdeContainer = document.getElementById('py-filecopy-ideContainer');\n\n    if (pyFileCopyFullscreenBtn) {\n        pyFileCopyFullscreenBtn.addEventListener('click', () => {\n            if (!document.fullscreenElement) {\n                pyFileCopyIdeContainer.requestFullscreen().catch(err => alert(`Error: ${err.message}`));\n                pyFileCopyFullscreenBtn.classList.replace('fa-expand', 'fa-compress');\n            } else {\n                document.exitFullscreen();\n                pyFileCopyFullscreenBtn.classList.replace('fa-compress', 'fa-expand');\n            }\n        });\n    }\n\n    pyFileCopyStarterCode = `# Exercise 7.3: File Copy Utility\n# Read from a source file, convert to uppercase, and write to a destination file\n\n# Wrap your code in a try block\n# try:\n\n    # Get source filename from user\n    # source = input(\"Enter source filename: \")\n\n    # Get destination filename from user\n    # destination = input(\"Enter destination filename: \")\n\n    # Open and read the source file\n\n\n    # Convert content to uppercase\n\n\n    # Write uppercase content to the destination file\n\n\n    # Print success message\n\n\n# Catch FileNotFoundError\n# except FileNotFoundError:\n\n\n# Catch any other unexpected errors\n# except Exception as e:\n\n`;\n\n    pyFileCopyEditor = CodeMirror(document.getElementById(\"py-filecopy-code-editor-div\"), {\n        value: pyFileCopyStarterCode,\n        mode: \"python\",\n        theme: \"eclipse\",\n        lineNumbers: true,\n        indentUnit: 4,\n        autoCloseBrackets: true\n    });\n\n    function pyFileCopyResetCode() {\n        pyFileCopyEditor.setValue(pyFileCopyStarterCode);\n        document.getElementById(\"py-filecopy-output-console\").innerText = \"Run code to see output...\";\n    }\n\n    function pyFileCopyRunCode() {\n        const spinner = document.getElementById('py-filecopy-btn-spinner');\n        const btnText = document.getElementById('py-filecopy-btn-text');\n        const outputBox = document.getElementById('py-filecopy-output-console');\n\n        spinner.style.display = \"inline-block\";\n        btnText.innerText = \"Running \";\n        outputBox.innerText = \"Processing...\";\n        outputBox.style.color = \"#6b7280\";\n\n        const pythonCode = pyFileCopyEditor.getValue();\n        const userInput = document.getElementById(\"py-filecopy-custom-input\").value;\n\n        fetch(\"https:\/\/blogsupport123-python-compiler.hf.space\/api\/run-python\", {\n            method: \"POST\",\n            headers: { \"Content-Type\": \"application\/json\" },\n            body: JSON.stringify({ code: pythonCode, input: userInput }),\n        })\n        .then(response => response.json())\n        .then(data => {\n            if (data.output) {\n                outputBox.innerText = data.output;\n                outputBox.style.color = \"#1f2937\";\n            } else if (data.error || data.errors) {\n                outputBox.innerText = data.error || data.errors;\n                outputBox.style.color = \"#ef4444\";\n            } else {\n                outputBox.innerText = \"No output returned.\";\n            }\n        })\n        .catch(err => {\n            outputBox.innerText = \"Error: \" + err.message;\n            outputBox.style.color = \"#ef4444\";\n        })\n        .finally(() => {\n            spinner.style.display = \"none\";\n            btnText.innerText = \"Run Code\";\n        });\n    }\n<\/script>\n","protected":false},"excerpt":{"rendered":"<p>&larr; Previous Module 7: File Handling &amp; Error Handling Next &rarr; Statement Solution Python Exercise 7.3: File Copy Utility File I\/O is a fundamental skill in Python. Write a program that reads content from a source file, converts all text to uppercase, and writes the result to a destination file \u2014 simulating a basic file [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":0,"parent":114145,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36796,36895],"class_list":["post-117656","page","type-page","status-publish","hentry","category-software","tag-python","tag-python-exercise"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Program File Copy Utility - Great Learning Blog: Free Resources what Matters to shape your Career!<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Program File Copy Utility\" \/>\n<meta property=\"og:description\" content=\"&larr; Previous Module 7: File Handling &amp; Error Handling Next &rarr; Statement Solution Python Exercise 7.3: File Copy Utility File I\/O is a fundamental skill in Python. Write a program that reads content from a source file, converts all text to uppercase, and writes the result to a destination file \u2014 simulating a basic file [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-exercise\\\/python-program-file-copy-utility\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-exercise\\\/python-program-file-copy-utility\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Python Program File Copy Utility\",\"datePublished\":\"2026-05-11T12:55:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-exercise\\\/python-program-file-copy-utility\\\/\"},\"wordCount\":404,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"keywords\":[\"python\",\"python-exercise\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-exercise\\\/python-program-file-copy-utility\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-exercise\\\/python-program-file-copy-utility\\\/\",\"name\":\"Python Program File Copy Utility - Great Learning Blog: Free Resources what Matters to shape your Career!\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"datePublished\":\"2026-05-11T12:55:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-exercise\\\/python-program-file-copy-utility\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-exercise\\\/python-program-file-copy-utility\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-exercise\\\/python-program-file-copy-utility\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Exercises\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python-exercise\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Program File Copy Utility\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Program File Copy Utility - Great Learning Blog: Free Resources what Matters to shape your Career!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/","og_locale":"en_US","og_type":"article","og_title":"Python Program File Copy Utility","og_description":"&larr; Previous Module 7: File Handling &amp; Error Handling Next &rarr; Statement Solution Python Exercise 7.3: File Copy Utility File I\/O is a fundamental skill in Python. Write a program that reads content from a source file, converts all text to uppercase, and writes the result to a destination file \u2014 simulating a basic file [&hellip;]","og_url":"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","twitter_card":"summary_large_image","twitter_site":"@Great_Learning","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Python Program File Copy Utility","datePublished":"2026-05-11T12:55:57+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/"},"wordCount":404,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"keywords":["python","python-exercise"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/","url":"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/","name":"Python Program File Copy Utility - Great Learning Blog: Free Resources what Matters to shape your Career!","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"datePublished":"2026-05-11T12:55:57+00:00","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/python-program-file-copy-utility\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python Exercises","item":"https:\/\/www.mygreatlearning.com\/blog\/python-exercise\/"},{"@type":"ListItem","position":3,"name":"Python Program File Copy Utility"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"web-stories-poster-portrait":false,"web-stories-publisher-logo":false,"web-stories-thumbnail":false},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"&larr; Previous Module 7: File Handling &amp; Error Handling Next &rarr; Statement Solution Python Exercise 7.3: File Copy Utility File I\/O is a fundamental skill in Python. Write a program that reads content from a source file, converts all text to uppercase, and writes the result to a destination file \u2014 simulating a basic file&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/117656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=117656"}],"version-history":[{"count":1,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/117656\/revisions"}],"predecessor-version":[{"id":117657,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/117656\/revisions\/117657"}],"up":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/114145"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=117656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=117656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=117656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}