Untitled
unknown
python
2 years ago
908 B
12
Indexable
import sqlite3
import csv
# Replace 'your_realm_file.realm' with the actual Realm file name
realm_file = 'your_realm_file.realm'
# Replace 'your_table_name' with the actual table name
table_name = 'your_table_name'
# Connect to SQLite (Realm files can be treated as SQLite databases)
connection = sqlite3.connect(realm_file)
cursor = connection.cursor()
# Fetch data from the SQLite table
cursor.execute('SELECT * FROM {}'.format(table_name))
data = cursor.fetchall()
# Replace 'output.csv' with the desired CSV file name
csv_file = 'output.csv'
# Write data to a CSV file
with open(csv_file, 'w', newline='') as csvfile:
csv_writer = csv.writer(csvfile)
# Write header
csv_writer.writerow([description[0] for description in cursor.description])
# Write data
csv_writer.writerows(data)
print('Data exported to {}'.format(csv_file))
# Close the SQLite connection
connection.close()Editor is loading...
Leave a Comment