Question
Write Python code to perform the following :
a. Reading data from a file
b. Creating a file and add content to it
Answer :
Word Count : 439
___ _________ _______ __________ ___ ________.
___ _______ _______ _______ _______ _________ ____ ____ ____ ___ __________ _______.
_______ __________ __________ _________ _______ _____ __________ _________ ____ _________.
______ ___ ________ _____ __________ _________.
_____ _____ __________ ___ ___.
_________ _________ ______ _______ ______ __________ __________.
__________ ________ ____ ________ __________ ________ __________.
_________ ________ ___ _______ _____.
__________ _______ ______ __________ ______ ______ ____ _________ ___ _________ __________ ___.
_____ ______ __________ ______ ______ __________ __________ ________ _________.
_________ _________ ______ _______ ____ _______.
___ ______ _____ _________ ________ ___ ________.
______ _____ ________ ____ _____ _________.
________ ________ _____ __________ ______ ____ ______ _________ ______ _______.
_______ _______ ____ ____ _______ __________.
_______ ____ ___ ___ ________ _____ _______ _____.
_______ _______ _____ __________ ____ _____ __________ ___ _________ _________ ___.
______ ___ _______ ___ ____.
____ _____ __________ ______ ______ ______ ___ ___ ______ _____ _____ ____.
______ ____ _______ _______ _______ _____ __________ _________.
___ _______ _________ ________ ________.
_______ ________ _______ _____ __________ _____ _________ ___ ___ _____.
_____ ____ _____ __________ _____ _________ _________ ____ _____ ____ _______.
__________ _______ ____ _____ _________.
_____ ______ _______ ____ ____ ________ ________ _____ __________ ________.
___ _______ ____ __________ _______ _________ ____ ____.
_____ _____ _____ __________ _____ ___ _________ _________ _______.
______ ___ __________ ________ ________ _____ _____ _________.
_____ ______ _________ ________ ____ _______ ____ ____ _____.
_____ ________ ______ ______ __________ ______ ______ _____.
______ _______ _________ ___ _____ ______ _________ ____.
_____ _________ __________ ________ ____ ____ _____ ___ ____ __________ ____.
__________ __________ ______ _____ _______ __________ __________ ______.
_______ ________ ___ _______ ____ _______.
____ ___ ____ _____ _______ ____ ___ _______ ___ _________ ______ ____.
__________ _________ _________ ____ __________ ________.
__________ ___ _____ _______ _______ _________ _______ ___ _______ _____ _____ _________.
____ _________ _________ __________ ____ _____.
__________ _________ _______ _____ ______ ___.
Skip in 10
Below are Python code snippets to perform the tasks you've mentioned:
### Reading Data from a File:
```python
# Opening a file in read mode
file_path = 'example.txt' # Replace with your file path
try:
with open(file_path, 'r') as file:
# Reading all lines from the file
lines = file.readlines()
# Printing the content of the file
for line in lines:
print(line.strip())
except FileNotFoundError:
print(f"File not found: {file_path}")
except Exception as e:
print(f"An error occurred: {e}")
```
Explanation:
1. The `open` function is
___ _______ _______ _______ _______ _________ ____ ____ ____ ___ __________ _______.
_______ __________ __________ _________ _______ _____ __________ _________ ____ _________.
______ ___ ________ _____ __________ _________.
_____ _____ __________ ___ ___.
_________ _________ ______ _______ ______ __________ __________.
__________ ________ ____ ________ __________ ________ __________.
_________ ________ ___ _______ _____.
__________ _______ ______ __________ ______ ______ ____ _________ ___ _________ __________ ___.
_____ ______ __________ ______ ______ __________ __________ ________ _________.
_________ _________ ______ _______ ____ _______.
___ ______ _____ _________ ________ ___ ________.
______ _____ ________ ____ _____ _________.
________ ________ _____ __________ ______ ____ ______ _________ ______ _______.
_______ _______ ____ ____ _______ __________.
_______ ____ ___ ___ ________ _____ _______ _____.
_______ _______ _____ __________ ____ _____ __________ ___ _________ _________ ___.
______ ___ _______ ___ ____.
____ _____ __________ ______ ______ ______ ___ ___ ______ _____ _____ ____.
______ ____ _______ _______ _______ _____ __________ _________.
___ _______ _________ ________ ________.
_______ ________ _______ _____ __________ _____ _________ ___ ___ _____.
_____ ____ _____ __________ _____ _________ _________ ____ _____ ____ _______.
__________ _______ ____ _____ _________.
_____ ______ _______ ____ ____ ________ ________ _____ __________ ________.
___ _______ ____ __________ _______ _________ ____ ____.
_____ _____ _____ __________ _____ ___ _________ _________ _______.
______ ___ __________ ________ ________ _____ _____ _________.
_____ ______ _________ ________ ____ _______ ____ ____ _____.
_____ ________ ______ ______ __________ ______ ______ _____.
______ _______ _________ ___ _____ ______ _________ ____.
_____ _________ __________ ________ ____ ____ _____ ___ ____ __________ ____.
__________ __________ ______ _____ _______ __________ __________ ______.
_______ ________ ___ _______ ____ _______.
____ ___ ____ _____ _______ ____ ___ _______ ___ _________ ______ ____.
__________ _________ _________ ____ __________ ________.
__________ ___ _____ _______ _______ _________ _______ ___ _______ _____ _____ _________.
____ _________ _________ __________ ____ _____.
__________ _________ _______ _____ ______ ___.
IGNOU ACADEMY
Your IGNOU journey, made easier.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
Continue Reading — It's Free
Sign in with Google to unlock more of this answer.
✓ Free access
✓ Unlock up to 60% of the answer
✓ No payment required
✓ Unlock up to 60% of the answer
✓ No payment required
Quick Google sign-in. No separate registration form.