13 model = DiscountCode
14
15 marketer = factory.RelatedFactory(UserFactory)
16 code = factory.Sequence(lambda n: 'john%s' % n)17 discount_url = common.url_
18 value = common.float_
19 type = "amount"
52 )
53 time_diff = current_time - created_at_db
54 allowed_time_lag = timedelta(milliseconds=400)
55 message = "created_at not set" " to current time in {} \n".format(56 model_factory
57 )
58 assert time_diff <= allowed_time_lag, message
33 )
34 connection_record.connection = connection_proxy.connection = None
35 raise exc.DisconnectionError(
36 "Connection record belongs to pid %s, "37 "attempting to check out in pid %s" % (connection_record.info['pid'], pid)
38 )
39
17 anonymous_user = db.Column(db.Boolean)
18
19 def __repr__(self):
20 return '<UserPerm %r>' % self.name
14 user = db.relationship("User", backref="alternate_emails", foreign_keys=[user_id])
15
16 def __repr__(self):
17 return '<Email %r>' % self.email_address
f-strings are the fastest way to format strings as compared to the following methods:
%
format()
str.join
+
operator to concatinate stringTemplate.substitute
Some less preferred ways to format strings are the following:
from string import Template
menu = ('eggs', 'spam', 42.4)
old_order = "%s and %s: %.2f ¤" % menu # [consider-using-f-string]
beginner_order = menu[0] + " and " + menu[1] + ": " + str(menu[2]) + " ¤"
joined_order = " and ".join(menu[:2])
format_order = "{} and {}: {:0.2f} ¤".format(menu[0], menu[1], menu[2])
named_format_order = "{eggs} and {spam}: {price:0.2f} ¤".format(eggs=menu[0], spam=menu[1], price=menu[2])
template_order = Template('$eggs and $spam: $price ¤').substitute(eggs=menu[0], spam=menu[1], price=menu[2])
Consider using f-strings as shown below:
menu = ('eggs', 'spam', 42.4)
f_string_order = f"{menu[0]} and {menu[1]}: {menu[2]:0.2f} ¤"