Created
November 14, 2017 15:34
-
-
Save MattOates/3c3f6ddafcfce1e44c2336bb49da6fe1 to your computer and use it in GitHub Desktop.
The following code doesn't work, but a by hand tailored equivalent `random.choice(None or [None])` works just fine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def random_rows(db, model, columns={}, num=100): | |
column_types = [ {'name': col.name, 'type': str(col.type)} for col in model.__table__.columns] | |
rows = [] | |
for n in range(1, num): | |
rows.append([random.choice(columns.get(col['name']) or [None]) or __random_data(col['type']) for col in column_types]) | |
return rows | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment