<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adam Lombard</title>
    <description>The latest articles on DEV Community by Adam Lombard (@adamlombard).</description>
    <link>https://dev.to/adamlombard</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F74285%2Fa72e683b-bf73-485b-93c0-ed0265d14f73.jpeg</url>
      <title>DEV Community: Adam Lombard</title>
      <link>https://dev.to/adamlombard</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adamlombard"/>
    <language>en</language>
    <item>
      <title>MacOS: Make Paste and Match Style the default Paste hotkey behavior</title>
      <dc:creator>Adam Lombard</dc:creator>
      <pubDate>Tue, 18 Nov 2025 18:08:59 +0000</pubDate>
      <link>https://dev.to/adamlombard/macos-make-paste-and-match-style-the-default-paste-hotkey-behavior-a6i</link>
      <guid>https://dev.to/adamlombard/macos-make-paste-and-match-style-the-default-paste-hotkey-behavior-a6i</guid>
      <description>&lt;p&gt;When copying and pasting in most applications, the default behavior is to paste not only the &lt;em&gt;content&lt;/em&gt; from one document into another, but also the &lt;em&gt;styling&lt;/em&gt;. Font, color, text size, etc. will not match the target document.&lt;/p&gt;

&lt;p&gt;This is almost never the outcome I want.&lt;/p&gt;

&lt;p&gt;Many applications have an option called 'Paste and Match Style', which &lt;em&gt;does&lt;/em&gt; properly adopt the styling of the target document. But I find this option frustrating because I prefer keyboard shortcuts to menu clicks, and I can never remember the hotkey. It's long, and turns my hand into a pretzel.&lt;/p&gt;

&lt;p&gt;On Mac, the 'Paste' hotkey is simply &lt;code&gt;Command-V&lt;/code&gt; (⌘-V).&lt;br&gt;
The 'Paste and Match Style' hotkey (the one I want) is &lt;code&gt;Option-Shift-Command-V&lt;/code&gt; (⌥-⇧-⌘-V). 😣&lt;/p&gt;

&lt;p&gt;You can see these settings in the edit menu of many applications:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3bogdh8u08z97e5iwa27.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3bogdh8u08z97e5iwa27.png" alt="The top of the default Edit menu in Pages for Mac"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to swap the default paste behaviors
&lt;/h2&gt;

&lt;p&gt;Here's how to swap the two hotkeys, so &lt;code&gt;Command-V&lt;/code&gt; will paste and match style, while also leaving normal 'Paste' in your menu (or available for finger contortions), if you ever need it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open System Settings and search for &lt;code&gt;Keyboard&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;In the Keyboard settings click &lt;code&gt;Keyboard Shortcuts&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;App Shortcuts&lt;/code&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fot907jr6g4tg20j0cxcl.png" alt="The System Settings Keyboard Shortcuts modal window, with App Shortcuts selected"&gt;
&lt;/li&gt;
&lt;li&gt;Click the &lt;code&gt;+&lt;/code&gt; button&lt;/li&gt;
&lt;li&gt;Leave &lt;code&gt;All Applications&lt;/code&gt; selected&lt;/li&gt;
&lt;li&gt;For the &lt;code&gt;Menu Title&lt;/code&gt; enter &lt;code&gt;Paste and Match Style&lt;/code&gt;. Spelling, spacing, and capitalization are important, because the name &lt;em&gt;must&lt;/em&gt; match the default application menu item name.&lt;/li&gt;
&lt;li&gt;For &lt;code&gt;Keyboard Shortcut&lt;/code&gt; press &lt;code&gt;Command-V&lt;/code&gt; (⌘-V) on your keyboard.&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndlm2vgg2gkoudf59647.png" alt="The modal window for setting a new keyboard shortcut, with new settings for Paste and Match Style"&gt;
&lt;/li&gt;
&lt;li&gt;Click &lt;code&gt;Done&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Repeat the process for &lt;code&gt;Paste&lt;/code&gt; with the shortcut &lt;code&gt;Option-Shift-Command-V&lt;/code&gt; (⌥-⇧-⌘-V).&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4fn1cpddru2f4522eaht.png" alt="The modal window for setting a new keyboard shortcut, with new settings for Paste"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Done!
&lt;/h2&gt;

&lt;p&gt;Now, in most Mac applications, &lt;code&gt;Command-V&lt;/code&gt; will paste and match the style of your target document.&lt;/p&gt;

&lt;p&gt;Here's a typical Edit menu, after the changes we made:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37vuceh4u7e3ew85l7bu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37vuceh4u7e3ew85l7bu.png" alt="The Edit menu of Pages for Mac, after the changes made in this article"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Was this helpful? Did I save you some time?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.adamlombard.com/support-me" class="crayons-btn crayons-btn--primary" rel="noopener noreferrer"&gt;🫖 Buy Me A Tea! ☕️&lt;/a&gt;

&lt;/h2&gt;




</description>
      <category>osx</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Python: class vs. instance vs. static methods</title>
      <dc:creator>Adam Lombard</dc:creator>
      <pubDate>Fri, 20 Nov 2020 22:03:47 +0000</pubDate>
      <link>https://dev.to/adamlombard/python-class-vs-instance-vs-static-methods-2cd0</link>
      <guid>https://dev.to/adamlombard/python-class-vs-instance-vs-static-methods-2cd0</guid>
      <description>&lt;p&gt;In Python, a &lt;em&gt;method&lt;/em&gt; provides functionality to a Class.&lt;/p&gt;

&lt;p&gt;There are, broadly, three types of methods:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Class Methods&lt;/em&gt; : Provide functionality to a class itself&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Instance Methods&lt;/em&gt; : Provide functionality to one instance of a class&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Static Methods&lt;/em&gt; : Provide functionality that can be accessed from a class &lt;em&gt;or&lt;/em&gt; from one instance of a class&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Consider the following Python class, which defines a &lt;code&gt;Person&lt;/code&gt; object and the methods which allow that object to say "hello":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
  &lt;span class="c1"&gt;# (Discussing __init__ is beyond the scope of this
&lt;/span&gt;  &lt;span class="c1"&gt;# tutorial)
&lt;/span&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;first_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;first_name&lt;/span&gt;

  &lt;span class="c1"&gt;# Instance methods are the default method type in a
&lt;/span&gt;  &lt;span class="c1"&gt;# class definition. They receive the class instance
&lt;/span&gt;  &lt;span class="c1"&gt;# itself as their first argument. By convention, 
&lt;/span&gt;  &lt;span class="c1"&gt;# the parameter for this argument is labeled 'self'.
&lt;/span&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;say_hi_from_an_instance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello! My name is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;first_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;# Class methods are defined using a special
&lt;/span&gt;  &lt;span class="c1"&gt;# decorator, and receive the class as the first
&lt;/span&gt;  &lt;span class="c1"&gt;# argument. By convention, the parameter for this
&lt;/span&gt;  &lt;span class="c1"&gt;# argument is labeled 'cls'.
&lt;/span&gt;  &lt;span class="nd"&gt;@classmethod&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;say_hi_from_the_class&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cls&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello! I am a &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;cls&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;# Static methods are defined using a special
&lt;/span&gt;  &lt;span class="c1"&gt;# decorator. They are available on the class and on
&lt;/span&gt;  &lt;span class="c1"&gt;# instances of the class.
&lt;/span&gt;  &lt;span class="nd"&gt;@staticmethod&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;say_hi_from_anywhere&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Why, hello!!!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, from the class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# We can call the class method greeting&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Person.say_hi_from_the_class&lt;span class="o"&gt;()&lt;/span&gt;
Hello! I am a Person.

&lt;span class="c"&gt;# But we cannot call the instance method greeting&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Person.say_hi_from_an_instance&lt;span class="o"&gt;()&lt;/span&gt;
Traceback ...
TypeError: say_hi_from_an_instance&lt;span class="o"&gt;()&lt;/span&gt; missing 1 required positional argument: &lt;span class="s1"&gt;'self'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While, from an instance of the class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; a_person &lt;span class="o"&gt;=&lt;/span&gt; Person&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Louise'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# We can call the instance method greeting&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; a_person.say_hi_from_an_instance&lt;span class="o"&gt;()&lt;/span&gt;
Hello! My name is Louise.

&lt;span class="c"&gt;# And we can still call the class method greeting&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; a_person.say_hi_from_the_class&lt;span class="o"&gt;()&lt;/span&gt;
Hello! I am a Person.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Static methods are available on both classes and class instances. They are intended to provide functionality that does not rely on the class or instance itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Person.say_hi_from_anywhere&lt;span class="o"&gt;()&lt;/span&gt;
Why, hello!!!
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; a_person.say_hi_from_anywhere&lt;span class="o"&gt;()&lt;/span&gt;
Why, hello!!!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;See also: &lt;a href="https://dev.to/adamlombard/ruby-class-methods-vs-instance-methods-4aje"&gt;Ruby: class methods vs. instance methods&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Was this helpful? Did I save you some time?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.adamlombard.com/support-me" class="ltag_cta ltag_cta--branded"&gt;🫖 Buy Me A Tea! ☕️&lt;/a&gt;

&lt;/h2&gt;




</description>
      <category>python</category>
      <category>tutorial</category>
      <category>learning</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Python: Assignment Operators</title>
      <dc:creator>Adam Lombard</dc:creator>
      <pubDate>Sat, 25 Jul 2020 19:26:26 +0000</pubDate>
      <link>https://dev.to/adamlombard/python-assignment-operators-dfj</link>
      <guid>https://dev.to/adamlombard/python-assignment-operators-dfj</guid>
      <description>&lt;p&gt;In a programming language, assignment operators are typically used to assign values to variables.&lt;/p&gt;

&lt;p&gt;In Python, the basic assignment operator works like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Assign a value to a variable&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Python also has seven arithmetic assignment operators, which are a sort of shorthand for performing two operations in sequence -- 1) arithmetic between a variable operand on the left of the expression and some other value on the right, and then 2) the assigning of the result back to the original variable:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Equivalent To&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;+=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Add a value to a variable&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x += 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x + 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;-=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Subtract a value from a variable&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x -= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x - 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Multiply a variable by a value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x *= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x * 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;**=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Raise a variable to the power of a value (exponentiation)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x **= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x ** 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Divide a variable by a value&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x /= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x / 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;//=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Divide a variable by a value, and round down (floor division)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x //= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x // 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The remainder of dividing a variable by a value (modulo)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x %= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x % 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Similarly, Python also has five bitwise assignment operators. These perform bitwise operations (the subject of a future article... ) between the left operand variable and a value on the right, assigning the result back to the variable:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operator&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;th&gt;Equivalent To&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;amp;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bitwise AND&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x &amp;amp;= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x &amp;amp; 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;|=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bitwise OR&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x |= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x | 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;^=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bitwise XOR&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x ^= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x ^ 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&amp;gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bitwise right shift&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x &amp;gt;&amp;gt;= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x &amp;gt;&amp;gt; 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&amp;lt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Bitwise left shift&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x &amp;lt;&amp;lt;= 2&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;x = x &amp;lt;&amp;lt; 2&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;Was this helpful? Did I save you some time?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.adamlombard.com/support-me" class="ltag_cta ltag_cta--branded"&gt;🫖 Buy Me A Tea! ☕️&lt;/a&gt;

&lt;/h2&gt;




</description>
      <category>python</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>Python: Formatting dates and times</title>
      <dc:creator>Adam Lombard</dc:creator>
      <pubDate>Tue, 07 Jul 2020 21:37:44 +0000</pubDate>
      <link>https://dev.to/adamlombard/python-formatting-dates-and-times-3ch2</link>
      <guid>https://dev.to/adamlombard/python-formatting-dates-and-times-3ch2</guid>
      <description>&lt;p&gt;Formatting dates and times into human-readable strings is a common programming task, and Python has a comprehensive method for doing so.&lt;/p&gt;

&lt;p&gt;Let's begin by importing the &lt;code&gt;datetime&lt;/code&gt; and &lt;code&gt;tz&lt;/code&gt; (timezone) libraries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; import datetime
&amp;gt;&amp;gt;&amp;gt; from dateutil import tz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://docs.python.org/3/library/datetime.html"&gt;&lt;code&gt;datetime&lt;/code&gt; library&lt;/a&gt; has many useful (and advanced) classes and methods, but exploring them is beyond the scope of this article. To explore formatting dates and times in Python, we will begin by generating a specific datetime, far out in the future. This will provide us with uniquely recognizable string components in our examples below.&lt;/p&gt;

&lt;p&gt;Python &lt;code&gt;datetime&lt;/code&gt; objects contain the following information, in order: &lt;code&gt;Year&lt;/code&gt;, &lt;code&gt;Month&lt;/code&gt;, &lt;code&gt;Day&lt;/code&gt;, &lt;code&gt;Hour&lt;/code&gt;, &lt;code&gt;Minute&lt;/code&gt;, &lt;code&gt;Second&lt;/code&gt;, &lt;code&gt;Millisecond&lt;/code&gt;, and &lt;code&gt;Timezone&lt;/code&gt;. Let's generate the datetime for May 4, 9876, at exactly 1.001 seconds after 3:02AM, in Los Angeles. :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; location = tz.gettz('America/Los_Angeles')
&amp;gt;&amp;gt;&amp;gt; dt = datetime.datetime(9876, 5, 4, 3, 2, 1, 1, tzinfo=location)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To format our datetime, we use its &lt;code&gt;strftime()&lt;/code&gt; method. Let's try a few examples.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dates
&lt;/h3&gt;

&lt;p&gt;Let's format our date per the &lt;a href="https://en.wikipedia.org/wiki/ISO_8601"&gt;ISO 8601 standard&lt;/a&gt;, which is my &lt;a href="https://dev.to/adamlombard/macos-run-a-script-in-any-app-via-custom-hotkey-4n99"&gt;personal favorite&lt;/a&gt; and takes the form "YYYY-MM-DD":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; dt.strftime("%Y-%m-%d")
'9876-05-04'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may notice that the formatting is controlled by characters preceded with a &lt;code&gt;%&lt;/code&gt;. These are called "directives", and allow us to declare formatting for specific parts of the date and time, while mixing in other plaintext characters, like &lt;code&gt;-&lt;/code&gt;. There is a reference chart of most &lt;code&gt;strftime()&lt;/code&gt; directives at the end of this article.&lt;/p&gt;

&lt;p&gt;Let's try another. In many parts of the world, it's common to format dates as "DD.MM.YY":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; dt.strftime("%d.%m.%y")
'04.05.76'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(You may notice that the lowercase &lt;code&gt;y&lt;/code&gt; directive yields a two-character year, instead of the four-character year yielded by the uppercase &lt;code&gt;Y&lt;/code&gt; directive.)&lt;/p&gt;

&lt;p&gt;Finally, let's try a format like "Weekday Name, Month Name (Abbreviated) Date, Year":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; dt.strftime("%A, %b %d, %Y")
'Thursday, May 04, 9876'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Times
&lt;/h3&gt;

&lt;p&gt;Now we'll format the time.&lt;/p&gt;

&lt;p&gt;First, let's try 24-hour time, like "HH:MM:SS":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; dt.strftime("%H:%M:%S")
'03:02:01'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And let's also do 12-hour time, without seconds, showing whether it's AM or PM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; dt.strftime("%-I:%M%p")
'3:02AM'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Directives
&lt;/h3&gt;

&lt;p&gt;By mixing and matching the directives below, we can now freely format dates and times in Python:&lt;/p&gt;

&lt;p&gt;(NOTE: &lt;em&gt;Python implements &lt;code&gt;strftime()&lt;/code&gt; by calling &lt;code&gt;strftime()&lt;/code&gt; in the platform's C library. Not all directives are available on all platforms, and some platforms may have directives not shown here. These directives were tested in Python 3.8 on macOS 10.15.4.&lt;/em&gt;)&lt;/p&gt;

&lt;h4&gt;
  
  
  Dates
&lt;/h4&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Directive&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%C&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Century as a 2-digit decimal number (00-99).&lt;/td&gt;
&lt;td&gt;98&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%Y&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Year (with century) as a decimal number (0001-9999).&lt;/td&gt;
&lt;td&gt;9876&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%G&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;ISO 8601 week-based year (with century) as a decimal number (0001-9999). Represents the year that contains the greater part of the ISO week. See &lt;code&gt;%V&lt;/code&gt;.&lt;/td&gt;
&lt;td&gt;9876&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%y&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Year (without century) as a zero-padded decimal number (00-99).&lt;/td&gt;
&lt;td&gt;76&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%g&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;ISO 8601 week-based year (without century) as a decimal number (00-99).&lt;/td&gt;
&lt;td&gt;76&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%m&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Month as a zero-padded decimal number (01-12).&lt;/td&gt;
&lt;td&gt;05&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%-m&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Month as a decimal number (1-12).&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%B&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Locale's full month name.&lt;/td&gt;
&lt;td&gt;May&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Locale's abbreviated month name.&lt;/td&gt;
&lt;td&gt;May&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%h&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Equivalent to &lt;code&gt;%b&lt;/code&gt;.&lt;/td&gt;
&lt;td&gt;May&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%d&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Day of the month as a zero-padded decimal number (01-31).&lt;/td&gt;
&lt;td&gt;04&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%e&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Day of the month as a space-padded decimal number ( 1-31).&lt;/td&gt;
&lt;td&gt;' 4'&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%-d&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Day of the month as a decimal number (1-31).&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%j&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Day of the year as a zero-padded decimal number (001-366).&lt;/td&gt;
&lt;td&gt;125&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%-j&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Day of the year as a decimal number (1-366).&lt;/td&gt;
&lt;td&gt;125&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%w&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Weekday as a decimal number, where Sunday is &lt;code&gt;0&lt;/code&gt; and the first day of the week (0-6).&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%u&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Weekday as a decimal number, where Monday is &lt;code&gt;1&lt;/code&gt; and the first day of the week (1-7).&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%A&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Locale's full weekday name.&lt;/td&gt;
&lt;td&gt;Thursday&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%a&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Locale's abbreviated weekday name.&lt;/td&gt;
&lt;td&gt;Thu&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%U&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Week of the year as a zero-padded decimal number. Treats Sunday as the first day of the week. All days in a new year preceding the first Sunday are considered to be in week 0. (00-53)&lt;/td&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%W&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Week of the year as a zero-padded decimal number. Treats Monday as the first day of the week. All days in a new year preceding the first Monday are considered to be in week 0. (00-53)&lt;/td&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%V&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;ISO 8601 week of the year as a zero-padded decimal number. Treats Monday as the first day of the week. Week &lt;code&gt;01&lt;/code&gt; is the week containing Jan 4. (01-53)&lt;/td&gt;
&lt;td&gt;18&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Times
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Directive&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%H&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Hour (24-hour clock) as a zero-padded decimal number (00-23).&lt;/td&gt;
&lt;td&gt;03&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%k&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Hour (24-hour clock) as a space-padded decimal number ( 0-23).&lt;/td&gt;
&lt;td&gt;' 3'&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%-H&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Hour (24-hour clock) as a decimal number (0-23).&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%I&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Hour (12-hour clock) as a zero-padded decimal number (01-12).&lt;/td&gt;
&lt;td&gt;03&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%l&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Hour (12-hour clock) as a space-padded decimal number ( 1-12).&lt;/td&gt;
&lt;td&gt;' 3'&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%-I&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Hour (12-hour clock) as a decimal number (1-12).&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%M&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Minute as a zero-padded decimal number (00-59).&lt;/td&gt;
&lt;td&gt;02&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%-M&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Minute as a decimal number (0-59).&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%S&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Second as a zero-padded decimal number (00-59).&lt;/td&gt;
&lt;td&gt;01&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%-S&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Second as a decimal number (0-59).&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%f&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Millisecond as a six-digit, zero-padded decimal number (000000-999999).&lt;/td&gt;
&lt;td&gt;000001&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%p&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Locale's equivalent of either AM or PM.&lt;/td&gt;
&lt;td&gt;AM&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%z&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Locale's UTC offset in the form &lt;code&gt;±HHMM[SS[.ffffff]]&lt;/code&gt;. Empty string if the object is naive.&lt;/td&gt;
&lt;td&gt;-0800&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%Z&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Locale's time zone name.&lt;/td&gt;
&lt;td&gt;PST&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Short Codes
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Directive&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%c&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Locale's preferred date and time representation.&lt;/td&gt;
&lt;td&gt;Thu May  4 03:02:01 9876&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%D&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Equivalent to &lt;code&gt;%m/%d/%y&lt;/code&gt;.&lt;/td&gt;
&lt;td&gt;5/04/76&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%F&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Equivalent to &lt;code&gt;%Y-%m-%d&lt;/code&gt; (the ISO 8601 format).&lt;/td&gt;
&lt;td&gt;9876-05-04&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%r&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Time in locale's preferred AM or PM notation.&lt;/td&gt;
&lt;td&gt;03:02:01 AM&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%R&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Time in 24-hour notation (without seconds). Equivalent to &lt;code&gt;%H:%M&lt;/code&gt;.&lt;/td&gt;
&lt;td&gt;03:02&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%T&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Time in 24-hour notation (with seconds). Equivalent to &lt;code&gt;%H:%M:%S&lt;/code&gt;.&lt;/td&gt;
&lt;td&gt;03:02:01&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%x&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Locale's preferred date representation (without time).&lt;/td&gt;
&lt;td&gt;05/04/76&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%X&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Locale's preferred time representation (without date).&lt;/td&gt;
&lt;td&gt;03:02:01&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Misc
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Directive&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%%&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A literal &lt;code&gt;%&lt;/code&gt; character.&lt;/td&gt;
&lt;td&gt;%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%n&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A newline character.&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%t&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A tab character.&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;%s&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The number of seconds since the &lt;a href="https://en.wikipedia.org/wiki/Unix_time"&gt;Unix Epoch&lt;/a&gt;: &lt;code&gt;1970-01-01 00:00:00 +0000 (UTC)&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;249499998121&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;&lt;a href="https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior"&gt;Documentation for &lt;code&gt;strftime()&lt;/code&gt;.&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Was this helpful? Did I save you some time?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.adamlombard.com/support-me" class="ltag_cta ltag_cta--branded"&gt;🫖 Buy Me A Tea! ☕️&lt;/a&gt;

&lt;/h2&gt;




</description>
      <category>beginners</category>
      <category>python</category>
      <category>learning</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Python: What is an f-string?</title>
      <dc:creator>Adam Lombard</dc:creator>
      <pubDate>Tue, 16 Jun 2020 16:14:46 +0000</pubDate>
      <link>https://dev.to/adamlombard/python-what-is-an-f-string-4ld5</link>
      <guid>https://dev.to/adamlombard/python-what-is-an-f-string-4ld5</guid>
      <description>&lt;p&gt;In Python, &lt;em&gt;f-strings&lt;/em&gt; are a string formatting mechanism that allow us to embed Python expressions in string literals. 'F-string' is short for 'formatted string'.&lt;/p&gt;

&lt;p&gt;They are formatted like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;f"string literal {expression}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Say, for instance, we want to print a user greeting where the username is variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Ellen&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello, Ellen!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any valid Python expression can be used in the f-string brackets:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;year&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2020&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;The year is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;. A decade from now, the year will be &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The year is 2020. A decade from now, the year will be 2030.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;F-strings were &lt;a href="https://www.python.org/dev/peps/pep-0498/"&gt;added in Python 3.6&lt;/a&gt;. &lt;/p&gt;




&lt;p&gt;Was this helpful? Did I save you some time?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.adamlombard.com/support-me" class="ltag_cta ltag_cta--branded"&gt;🫖 Buy Me A Tea! ☕️&lt;/a&gt;

&lt;/h2&gt;




</description>
      <category>python</category>
      <category>beginners</category>
      <category>learning</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Python: What is a Lambda Function?</title>
      <dc:creator>Adam Lombard</dc:creator>
      <pubDate>Sat, 13 Jun 2020 20:41:59 +0000</pubDate>
      <link>https://dev.to/adamlombard/python-what-is-a-lambda-function-3m98</link>
      <guid>https://dev.to/adamlombard/python-what-is-a-lambda-function-3m98</guid>
      <description>&lt;p&gt;In Python, the &lt;code&gt;lambda&lt;/code&gt; keyword is used to define an anonymous (i.e., nameless) function, using the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lambda parameters: expression
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assume we have the following list of fruits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;apple&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;orange&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;grape&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;lemon&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;mango&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;banana&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now imagine we need to filter our list to print only fruit names which are 5 characters long. We &lt;em&gt;could&lt;/em&gt; do so by defining a named function to test word lengths, and then passing it (and our list of fruits) to &lt;code&gt;filter()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;five_letter_words&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;

&lt;span class="n"&gt;five_letter_fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;five_letter_words&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;fruit&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;five_letter_fruits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fruit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apple
grape
lemon
mango
&amp;gt;&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or, the same task can be accomplished directly in &lt;code&gt;filter()&lt;/code&gt; using a &lt;code&gt;lambda&lt;/code&gt; expression, without needing to define a separate named function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;five_letter_fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;fruit&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;five_letter_fruits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fruit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apple
grape
lemon
mango
&amp;gt;&amp;gt;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because lambda functions are Python expressions, they can be assigned to variables.&lt;/p&gt;

&lt;p&gt;So, this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;add_two&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;
&lt;span class="nf"&gt;add_two&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Is equivalent to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;add_two&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;

&lt;span class="nf"&gt;add_two&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Was this helpful? Did I save you some time?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.adamlombard.com/support-me" class="ltag_cta ltag_cta--branded"&gt;🫖 Buy Me A Tea! ☕️&lt;/a&gt;

&lt;/h2&gt;




</description>
      <category>python</category>
      <category>beginners</category>
      <category>learning</category>
      <category>lambda</category>
    </item>
    <item>
      <title>Django: What version do I have?</title>
      <dc:creator>Adam Lombard</dc:creator>
      <pubDate>Wed, 06 May 2020 20:10:00 +0000</pubDate>
      <link>https://dev.to/adamlombard/django-what-version-do-i-have-4a5b</link>
      <guid>https://dev.to/adamlombard/django-what-version-do-i-have-4a5b</guid>
      <description>&lt;p&gt;Here's how to see what version of Django you're using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make sure you're in the virtual environment for your project.&lt;/li&gt;
&lt;li&gt;At the terminal prompt, open the Python shell:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In the Python shell, import the Django module and check the version:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;django&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;django&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__version__&lt;/span&gt;
&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;2.2.9&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Edit: User &lt;a class="mentioned-user" href="https://dev.to/biplov"&gt;@biplov&lt;/a&gt; pointed out that there's an even easier way to see your Django version right from your terminal prompt:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;django-admin &lt;span class="nt"&gt;--version&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Was this helpful? Did I save you some time?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.adamlombard.com/support-me" class="ltag_cta ltag_cta--branded"&gt;🫖 Buy Me A Tea! ☕️&lt;/a&gt;

&lt;/h2&gt;




</description>
      <category>python</category>
      <category>django</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>VSCode: Setting line lengths in the Black Python code formatter</title>
      <dc:creator>Adam Lombard</dc:creator>
      <pubDate>Fri, 01 May 2020 22:28:14 +0000</pubDate>
      <link>https://dev.to/adamlombard/vscode-setting-line-lengths-in-the-black-python-code-formatter-1g62</link>
      <guid>https://dev.to/adamlombard/vscode-setting-line-lengths-in-the-black-python-code-formatter-1g62</guid>
      <description>&lt;p&gt;The docs for the &lt;a href="https://black.readthedocs.io/en/stable/index.html" rel="noopener noreferrer"&gt;Black&lt;/a&gt; Python code formatter say that the formatter &lt;a href="https://black.readthedocs.io/en/stable/the_black_code_style.html?highlight=length#the-black-code-style" rel="noopener noreferrer"&gt;"is not configurable"&lt;/a&gt;. This is largely true, but if you have Black &lt;a href="https://dev.to/adamlombard/how-to-use-the-black-python-code-formatter-in-vscode-3lo0"&gt;set up to work in VSCode&lt;/a&gt;, you &lt;em&gt;can&lt;/em&gt; configure the line length.&lt;/p&gt;

&lt;p&gt;In VSCode, go 'Code -&amp;gt; Preferences -&amp;gt; Settings' and search for "python formatting black args".&lt;/p&gt;

&lt;p&gt;Add two separate arguments, in this order: &lt;code&gt;--line-length&lt;/code&gt; and &lt;code&gt;n&lt;/code&gt;, where "n" is your desired number of allowed characters per line:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6sb8161hjqscv8frvzs8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6sb8161hjqscv8frvzs8.png" alt="Interface for adding Black formatting arguments in VSCode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A few notes about line lengths in Python:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PEP8 recommends a line length of &lt;a href="https://www.python.org/dev/peps/pep-0008/#maximum-line-length" rel="noopener noreferrer"&gt;79 characters&lt;/a&gt; (72 for docstrings)&lt;/li&gt;
&lt;li&gt;Black sets line lengths to &lt;a href="https://black.readthedocs.io/en/stable/the_black_code_style.html?highlight=length#line-length" rel="noopener noreferrer"&gt;88 characters by default&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The Django docs recommend a maximum line length of &lt;a href="https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/coding-style/" rel="noopener noreferrer"&gt;119 characters&lt;/a&gt; (79 for docstrings)&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you are working on a shared project with a team, consider bypassing the VSCode settings entirely, and setting line lengths via the project's &lt;code&gt;pyproject.toml&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;

&lt;span class="nn"&gt;[tool.black]&lt;/span&gt;
&lt;span class="py"&gt;line-length&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;119&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;p&gt;Was this helpful? Did I save you some time?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.adamlombard.com/support-me" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;🫖 Buy Me A Tea! ☕️&lt;/a&gt;

&lt;/h2&gt;




</description>
      <category>vscode</category>
      <category>python</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>VSCode: Using Black to automatically format Python</title>
      <dc:creator>Adam Lombard</dc:creator>
      <pubDate>Thu, 30 Apr 2020 21:40:45 +0000</pubDate>
      <link>https://dev.to/adamlombard/how-to-use-the-black-python-code-formatter-in-vscode-3lo0</link>
      <guid>https://dev.to/adamlombard/how-to-use-the-black-python-code-formatter-in-vscode-3lo0</guid>
      <description>&lt;p&gt;&lt;a href="https://pypi.org/project/black/" rel="noopener noreferrer"&gt;Black&lt;/a&gt; is "the uncompromising Python code formatter." It can be configured to automatically format your code whenever you save a file in &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;VSCode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Install Black in your virtual environment:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

$ pip install black


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Install &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-python.python" rel="noopener noreferrer"&gt;Microsoft's Python extension&lt;/a&gt; in VSCode:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe5eessq5aazplz9l95hr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fe5eessq5aazplz9l95hr.png" alt="Microsoft's Python extension in VSCode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open your VSCode settings, by going 'Code -&amp;gt; Preferences -&amp;gt; Settings'.&lt;/p&gt;

&lt;p&gt;Search for "python formatting provider" and select "black" from the dropdown menu:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftoxplnqx19i402fgmv05.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftoxplnqx19i402fgmv05.png" alt="The VSCode settings interface for the "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the settings, search for "format on save" and enable the "Editor: Format on Save" option:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ddnyrajrv8foanj56pl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1ddnyrajrv8foanj56pl.png" alt="The VSCode settings interface for the "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Black will now format your code whenever you save a &lt;code&gt;*.py&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Before saving:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqk5e0inmye4z8phcc9rv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqk5e0inmye4z8phcc9rv.png" alt="Code before formatting"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After saving:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flgkkpq50djrdkd4husxu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flgkkpq50djrdkd4husxu.png" alt="Code after formatting"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Was this helpful? Did I save you some time? For $1 you can...&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.adamlombard.com/support-me" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;🫖 Buy Me A Tea! ☕️&lt;/a&gt;

&lt;/h2&gt;




&lt;p&gt;More: &lt;a href="https://dev.to/adamlombard/vscode-setting-line-lengths-in-the-black-python-code-formatter-1g62"&gt;How to set Black line lengths in VSCode&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Images from VSCode using &lt;a href="https://marketplace.visualstudio.com/items?itemName=hsnazar.hyper-term-theme" rel="noopener noreferrer"&gt;Hyper Term Theme&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>python</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>CSS: Automatically number subheadings in nested lists</title>
      <dc:creator>Adam Lombard</dc:creator>
      <pubDate>Sat, 11 Apr 2020 17:35:49 +0000</pubDate>
      <link>https://dev.to/adamlombard/css-automatically-number-nested-lists-59ei</link>
      <guid>https://dev.to/adamlombard/css-automatically-number-nested-lists-59ei</guid>
      <description>&lt;p&gt;In documents like technical specifications, academic outlines, contracts, etc., it's not uncommon to find nested lists with numbered headings and subheadings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Heading
  1.1 Subheading
    1.1.1 Sub-subheading
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How do we use CSS to automatically number nested lists?&lt;/p&gt;

&lt;p&gt;Let's start with a nested mix of ordered (&lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt;) and unordered (&lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt;) list elements:&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/AdamLombard/embed/WNQbLrB?height=600&amp;amp;default-tab=html,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;We want to number the ordered items, and not the unordered ones. Let's remove the default number prefixes from our ordered list elements, leaving the bullets for our unordered list elements:&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/AdamLombard/embed/ExVaGXm?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;We'll make a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Lists_and_Counters/Using_CSS_counters"&gt;CSS counter&lt;/a&gt; using a property called &lt;code&gt;counter-reset&lt;/code&gt;, which works like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;counter-reset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;identifier&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;integer&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;identifier&lt;/code&gt; is the name that will hold our counter. The &lt;code&gt;integer&lt;/code&gt; is an optional number to which we would like to initialize (or reset) our counter. By default, &lt;code&gt;integer&lt;/code&gt; is &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We'll pair &lt;code&gt;counter-reset&lt;/code&gt; with &lt;code&gt;counter-increment&lt;/code&gt;, which works like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;counter-increment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;identifier&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;integer&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;identifier&lt;/code&gt; in &lt;code&gt;counter-increment&lt;/code&gt; is the name of the counter to increment; in our case this will match the &lt;code&gt;identifier&lt;/code&gt; we initialize with &lt;code&gt;counter-reset&lt;/code&gt;. The &lt;code&gt;integer&lt;/code&gt; is optional, and determines by how much the counter will be incremented; it defaults to &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In our code we want separate counters for each &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt; element, incremented on each &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt;, but we want to ignore &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; elements completely, and not have them affect the heading counter. We'll target &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; children of &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt; elements like so:&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/AdamLombard/embed/NWGPeBW?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Lastly, we want to prefix our counters to each ordered list item. To do so, we'll target a &lt;code&gt;::before&lt;/code&gt; pseudo-element on our ordered list items, and pass the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/counters"&gt;&lt;code&gt;counters()&lt;/code&gt; function&lt;/a&gt; to their content property. It works like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  counters(&amp;lt;identifier&amp;gt;, &amp;lt;separator-string&amp;gt;, &amp;lt;counter-style&amp;gt;?)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;identifier&lt;/code&gt; here must match an &lt;code&gt;identifier&lt;/code&gt; initialized in &lt;code&gt;counter-reset&lt;/code&gt; and used in &lt;code&gt;counter-increment&lt;/code&gt;. It is technically a list of all the separate instances of &lt;code&gt;identifier&lt;/code&gt; for the current context (there is a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/counter"&gt;&lt;code&gt;counter()&lt;/code&gt; function&lt;/a&gt; for single counters). So, if we are nested three levels deep, there will be three separate &lt;code&gt;identifier&lt;/code&gt;s, and the &lt;code&gt;counters()&lt;/code&gt; function will concatenate them together. &lt;code&gt;separator-string&lt;/code&gt; will be placed between each concatenated &lt;code&gt;identifier&lt;/code&gt; instance. The optional &lt;code&gt;counter-style&lt;/code&gt; can be used to change the counter to, say, Roman numerals. It defaults to integers.&lt;/p&gt;

&lt;p&gt;In our code, we will also pass a &lt;code&gt;' - '&lt;/code&gt; string to the &lt;code&gt;content&lt;/code&gt; property, to separate our numbered prefixes from the rest of the element. Our final CSS will look something like this:&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/AdamLombard/embed/gOabxwQ?height=600&amp;amp;default-tab=css,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Let me know what you make! 🙂&lt;/p&gt;




&lt;p&gt;Was this helpful? Did I save you some time? For just $1 you can:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.adamlombard.com/support-me" class="ltag_cta ltag_cta--branded"&gt;🫖 Buy Me A Tea! ☕️&lt;/a&gt;

&lt;/h2&gt;




&lt;p&gt;Learn more about &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Lists_and_Counters/Using_CSS_counters"&gt;using CSS counters&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>learning</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>macOS: Run a script from any app via custom hotkey</title>
      <dc:creator>Adam Lombard</dc:creator>
      <pubDate>Tue, 07 Apr 2020 03:34:56 +0000</pubDate>
      <link>https://dev.to/adamlombard/macos-run-a-script-in-any-app-via-custom-hotkey-4n99</link>
      <guid>https://dev.to/adamlombard/macos-run-a-script-in-any-app-via-custom-hotkey-4n99</guid>
      <description>&lt;p&gt;In MacOS, it's possible to run a script -- from any application -- via custom hotkeys we set ourselves.&lt;/p&gt;

&lt;p&gt;I use modified &lt;a href="https://en.wikipedia.org/wiki/ISO_8601" rel="noopener noreferrer"&gt;ISO 8601&lt;/a&gt; datetime strings (in a &lt;code&gt;YYYYMMDD_HHMMSS&lt;/code&gt; format) several times a day, for all sorts of things, because they are relatively unique (you get a new one every second), they keep items sorted by creation time, and they're fairly easy to read and/or remember if you have to. Let's set up our Mac to generate these strings on the fly!&lt;/p&gt;

&lt;p&gt;1 - In our Applications, let's open a program called Automator.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fn5uw4yio74pi11pxqhjz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fn5uw4yio74pi11pxqhjz.png" alt="Automator app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2 - Select "Quick Action" and click "Choose". (We may need to go "File -&amp;gt; New" in order to see the "Quick Action" option.)&lt;/p&gt;

&lt;p&gt;3 - In the setup group box for our Quick Action, set "Workflow receives current" to "no input" in "any application".&lt;/p&gt;

&lt;p&gt;4 - In the menu tree on the left-hand side, select "Library -&amp;gt; Utilities".&lt;/p&gt;

&lt;p&gt;5 - In the "Utilities" sub-tree, double-click "Run Shell Script". This will place a shell script interface in the work area on the right of the application.&lt;/p&gt;

&lt;p&gt;6 - In the script interface, enter this shell script:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

date '+%Y%m%d_%H%M%S'


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;7 - At the bottom of the script interface, click "Results" to expand the results panel.&lt;/p&gt;

&lt;p&gt;8 - In the upper right corner of Automator, click "Run (►)". We should see the formatted datetime string appear in the "Results" panel of the script interface.&lt;/p&gt;

&lt;p&gt;At this point, our finished service should look like this in Automator:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq6msp0ocfclknfkmt4z8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq6msp0ocfclknfkmt4z8.png" alt="Finalized service in Automator"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;9 - Save our new service! Name it something nice, like... like... &lt;code&gt;FancyDateStamper&lt;/code&gt; or... &lt;code&gt;Louise&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;10 - Go to "System Preferences -&amp;gt; Keyboard -&amp;gt; Shortcuts".&lt;/p&gt;

&lt;p&gt;11 - Select "Services" from the left-hand menu.&lt;/p&gt;

&lt;p&gt;12 - In the right-hand menu, find our new service, make sure it has a checkmark in front of it, and click "Add Shortcut".&lt;/p&gt;

&lt;p&gt;13 - Now things get hard, because it's really tough to find a shortcut that isn't already used by an app. I went with &lt;code&gt;ctrl+alt+command+D&lt;/code&gt;, but I'm almost certain to regret that someday. 😐&lt;/p&gt;

&lt;p&gt;And that's it! At this point, we should now be able to open almost any app, and, anywhere we can enter text via the keyboard, we should be able to instead run our hotkey combo and get our datetime stamp. If not, we may have some permissions issues...&lt;/p&gt;

&lt;p&gt;14 - Go "System Preferences -&amp;gt; Security &amp;amp; Privacy -&amp;gt; Privacy"&lt;/p&gt;

&lt;p&gt;15 - Select "Accessibility" from the left-hand menu.&lt;/p&gt;

&lt;p&gt;16 - Unlock to make changes, if necessary, then click the "+" sign at the bottom of the right-hand menu.&lt;/p&gt;

&lt;p&gt;17 - Add "Automator" as a trusted app.&lt;/p&gt;

&lt;p&gt;While in Automator, you may have noticed the option to create a service in JavaScript as well! Let me know what you automate! 😊&lt;/p&gt;




&lt;p&gt;Credit to this &lt;a href="https://apple.stackexchange.com/questions/175215/how-do-i-assign-a-keyboard-shortcut-to-an-applescript-i-wrote" rel="noopener noreferrer"&gt;StackExchange&lt;/a&gt; article, where I first learned the general steps involved. &lt;/p&gt;




&lt;p&gt;Was this helpful? Did I save you some time?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.adamlombard.com/support-me" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;🫖 Buy Me A Tea! ☕️&lt;/a&gt;

&lt;/h2&gt;




</description>
      <category>macos</category>
      <category>beginners</category>
      <category>learning</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Git: How to configure repo-specific user settings</title>
      <dc:creator>Adam Lombard</dc:creator>
      <pubDate>Wed, 25 Mar 2020 00:52:34 +0000</pubDate>
      <link>https://dev.to/adamlombard/git-configure-repo-specific-user-settings-270m</link>
      <guid>https://dev.to/adamlombard/git-configure-repo-specific-user-settings-270m</guid>
      <description>&lt;p&gt;Many Git tutorials instruct us to do something like the following when first setting up Git:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"Susanna Bauer"&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.email susanna@example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configures &lt;code&gt;user.name&lt;/code&gt; and &lt;code&gt;user.email&lt;/code&gt; settings globally, for every repo on our machine. &lt;/p&gt;

&lt;p&gt;But, say we use the same computer to work in multiple Git repositories across two or more accounts. Perhaps we have separate professional and hobby &lt;a href="https://about.gitlab.com/"&gt;GitLab&lt;/a&gt; accounts, for instance. How do we override the global settings, and configure &lt;code&gt;user.name&lt;/code&gt; and &lt;code&gt;user.eamil&lt;/code&gt; on a per-repo basis?&lt;/p&gt;

&lt;p&gt;We can &lt;code&gt;cd&lt;/code&gt; into our repo, and re-run the same commands without the &lt;code&gt;--global&lt;/code&gt; flags:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git config user.name &lt;span class="s2"&gt;"sueB"&lt;/span&gt;
&lt;span class="nv"&gt;$ &lt;/span&gt;git config user.email sb@example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The global settings remain unchanged, but &lt;em&gt;this&lt;/em&gt; repository will use the new, local settings. You can see the local configuration at &lt;code&gt;&amp;lt;repo&amp;gt;/.git/config&lt;/code&gt;.&lt;/p&gt;




&lt;p&gt;Learn more about the artwork of &lt;a href="http://www.susannabauer.com/"&gt;Susanna Bauer&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Was this helpful? Did I save you some time?&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;a href="https://www.adamlombard.com/support-me" class="ltag_cta ltag_cta--branded"&gt;🫖 Buy Me A Tea! ☕️&lt;/a&gt;

&lt;/h2&gt;




</description>
      <category>git</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
