This file contains hidden or 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
layout poetry | |
export PYTHONSTARTUP=`pwd`/_pythonstartup.py | |
export MYOTHERVAR=foobarbaz |
This file contains hidden or 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
import sys | |
from datetime import datetime | |
from os import getcwd | |
from pathlib import Path | |
from colorama import Fore | |
class Ps1: | |
count: int |
This file contains hidden or 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
$ PYTHONSTARTUP=./_pythonstartup.py ipython | |
Python 3.9.0 (default, Nov 19 2020, 14:06:03) | |
Type 'copyright', 'credits' or 'license' for more information | |
IPython 7.24.1 -- An enhanced Interactive Python. Type '?' for help. | |
In [1]: session | |
Out[1]: <sqlalchemy.orm.session.Session at 0x7f1efed0ee50> | |
In [2]: session.execute("SELECT * FROM users").fetchall() | |
Out[2]: [(1, 'johndoe', 'somehash')] |
This file contains hidden or 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
import sys | |
def boostrap(): | |
print("Hello world!") | |
sys.__interactivehook__ = boostrap |
This file contains hidden or 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
$ PYTHONSTARTUP=./_pythonstartup.py python | |
Python 3.9.0 (default, Nov 19 2020, 14:06:03) | |
[GCC 7.5.0] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
Hello world! | |
>>> |
This file contains hidden or 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
print("Hello world!") |
This file contains hidden or 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
from sqlalchemy import create_engine | |
from sqlalchemy.orm import Session | |
engine = create_engine("sqlite:///mydatabase.db") | |
connection = engine.connect() | |
transaction = connection.begin() | |
session = Session(bind=connection) |
This file contains hidden or 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
>>> from fbd.championship.factories import PlayerFactory, ClubFactory | |
>>> club = ClubFactory() | |
>>> player_with_a_picture = PlayerFactory(club=club, picture__filename='chuck.png') | |
>>> player_with_a_picture.picture | |
<ImageFieldFile: player/picture/68/chuck.png> |
This file contains hidden or 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
class PlayerFactory(DjangoModelFactory): | |
# other declarations removed for brevity | |
@post_generation | |
def picture(self, create, extracted, **kwargs): | |
if extracted: | |
self.picture = extracted | |
elif kwargs: | |
assert 'filename' in kwargs, 'You need to pass in the filename' |
This file contains hidden or 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
>>> club = ClubFactory() | |
>>> players = PlayerFactory.create_batch(10, club=club) | |
>>> player_male = next(filter(lambda p: p.sex == SEX_MALE, players)) | |
>>> player_female = next(filter(lambda p: p.sex == SEX_FEMALE, players)) | |
>>> player_male.sex, player_male.dob, player_male.government_id | |
('M', datetime.datetime(1998, 4, 20, 2, 14, 33, tzinfo=<UTC>), 9804200019) | |
>>> player_female.sex, player_female.dob, player_female.government_id | |
('F', datetime.datetime(1991, 2, 3, 16, 41, 55, tzinfo=<UTC>), 9102030002) |
NewerOlder