Consider a binary file, items.dat, containing records stored in the given format:
Write a function, Copy\_new(), that copies all records whose amount is greater than 1000 from items.dat to new\_items.dat.
import pickle
def Copy_new():
# Open source file for reading
with open("items.dat", "rb") as source_file:
# Open destination file for writing
with open("new_items.dat", "wb") as dest_file:
try:
while True:
# Load record from source file
record = pickle.load(source_file)
# Check if amount>1000
if record["amount"] > 1000:
# Write to destination file
pickle.dump(record, dest_file)
except EOFError:
pass # End of file reached
The source file items.dat is opened in binary read mode ('rb'), and the destination file new_items.dat is opened in binary write mode ('wb').
Each record is read using pickle.load() and checked if the amount is greater than 1000.
Records satisfying the condition are written to the destination file using pickle.dump().
The SELECT statement when combined with \(\_\_\_\_\_\_\) clause, returns records without repetition.
print(16 * 5 / 4 * 2 / 5 - 8)
myStr[:4] extracts the first 4 characters, which are "MISS".myStr[-5:] extracts the last 5 characters, which are "SIPPI"."#" in between, resulting in "MISS#SIPPI".In SQL, the aggregate function which will display the cardinality of the table is \(\_\_\_\_\_\).
print(16 * 5 / 4 * 2 / 5 - 8)
a = 20
def convert(a):
b = 20
a = a + b
convert(10)
print(a)
Select the correct output from the given options:
Fill in the blank:
\(\_\_\_\_\_\_\_\_\) is a set of rules that needs to be followed by the communicating parties in order to have a successful and reliable data communication over a network.