Skip to content

Add a snippet for the if __name__ == '__main__': block #2242

@d3r3kk

Description

@d3r3kk

We have all sorts of useful snippets in our extension, but I've noticed that we have not added one for the ubiquitous block:

if __name__ == '__main__':

Proposal to add the snippet with the type-ahead identifier __main__.

Acceptance Criteria:

  1. Open a new editor window
  2. Create a new file helloworld.py
  3. Add the following code:
1|  import sys
2|  
3|  def hello_world():
4|      print('Hi there!')
5|      print(f'Python version {sys.version_info}')
6|  
7|
  1. On line 7, begin type __main

Expected Result

Popup with a snippet for the dunder name equals dunder main appears. Pressing Enter will accept the snippet and insert code such as:

6|
7|  if __name__ == '__main__':
8|      $
9|

...where the $ is where the cursor is left such that the user can add whatever call(s) are necessary.

EDIT: Acceptance criteria altered to ensure cursor is placed optimally.

Metadata

Metadata

Assignees

Labels

feature-requestRequest for new features or functionality

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions