https://hackernoon.com/python-3-7s-new-builtin-breakpoint-a-quick-tour-4f1aebc444c
#python #python37 #breakpoint #pdb #set_trace
#python #python37 #breakpoint #pdb #set_trace
Hackernoon
Python 3.7’s new builtin breakpoint — a quick tour | HackerNoon
Debugging in Python has always felt a bit “awkward” compared with other languages I’ve worked in.
Did you know that python
#python #print #sep #separator
print
command takes sep
argument as a separator between string arguments?print('ali', 'reza', sep=', ') # output: ali, reza
#python #print #sep #separator
As you may already know in
In golang you need to use
#python #golang #go #fmt #sprintf #format
Python
you can format your string using format
as below:file_name = "/root/openvpn/{}.ovpn".format(my_file_name)
// Or
file_name = "/root/openvpn/%s.ovpn" % my_file_name
In golang you need to use
Sprintf
method of fmt
package like follow:var fileName = fmt.Sprintf("/root/openvpn/%s.ovpn", myFileName)
#python #golang #go #fmt #sprintf #format
If you want to implement "Python Capitalize" method in
There is another method called ToTitle which is used for one character long (but to letters):
#python #golang #go #ToLower #Title #strings #capitalize #ToTitle
Go
:strings.Title(strings.ToLower("MYNAME")) // output: Myname
There is another method called ToTitle which is used for one character long (but to letters):
str := "dz"
fmt.Println(strings.ToTitle(str)) // output: Dz
#python #golang #go #ToLower #Title #strings #capitalize #ToTitle
How to add nested documents in
#python #data_class #marshmallow #fields #list #OneOf
Marshmallow
python?books = fields.List(fields.Dict(
keys=fields.String(validate=OneOf(('title', 'author', 'publication_date'))),
values=fields.String(required=True)))
#python #data_class #marshmallow #fields #list #OneOf
In
#python #marshmallow #fields #fields_method
marshmallow
you can have a schema field which can be filled with a method output. Let's see with an example:class AuthorSchema(Schema):As you see
id = fields.Int(dump_only=True)
first = fields.Str()
last = fields.Str()
formatted_name = fields.Method("format_name", dump_only=True)
def format_name(self, author):
return "{}, {}".format(author.last, author.first)
formatted_name
field is filled by a method called format_name
. Examples are endless, you can calculate average score based on the given scores for instance.#python #marshmallow #fields #fields_method
In order to expand a
#python #ipaddress #ipv4 #IPv4Network
CIDR
in python you can use ipaddress
module as below:import ipaddress
available_ips = [str(ip) for ip in ipaddress.IPv4Network('192.0.2.0/28')]
#python #ipaddress #ipv4 #IPv4Network