Python basics

Great Python introductory video for C# developers
https://www.youtube.com/watch?v=jj60geqaP08

__  (double underscore) Starting the attribute name with double underscore attribute makes it private. To expose the private attributes and methods

print(dir(MY_CLASS))

 

Code hierarchy

In Python indentation denotes the hierarchy of the instructions, not curly braces, like in C# or Java.

Directories

When you create a directory in your project, create an empty __init__.py file in the new directory to be able to reference objects from that directory, and avoid

from MY_FOLDER.MY_FILE import MY_CLASS causes an error:
ImportError: No module named MY_FOLDER.MY_FILE

Classes

Predefined methods

__init__(self)  Initializer method (constructor)

__repr__(self)  Representation

__iter__(self)  Method to define hot to iterate through the object

Decorators

@property  Exposes a method as a property of the class

from _04_anonymous.anonobject import AnonObject
ImportError: No module named _04_anonymous.anonobject

{(“Not importing directory ‘/Users/pinterl/Git/devops-scripts/Python_Tutorial/Python/Python_for_C_sharp_developers/_04_anonymous’: missing __init__.py”, <type ‘exceptions.ImportWarning’>, 6): True}

Leave a comment

Your email address will not be published. Required fields are marked *