This PowerShell Scripting guide to Python is designed to make readers familiar with syntax, semantics and core concepts of Python language, in an approach that readers can totally relate with the concepts of PowerShell already in their arsenal, to learn Python fast and effectively, such that it sticks with readers for longer time.
"Use what you know to learn what you don't. " also known as Associative learning.
Book follows a comparative method to jump start readers journey in Python, but who is the target audience? and who should read this book -
Any System Administrator who want to step into Development or Programming roles, and even if you don't want to be a developer, knowledge of another scripting language will make your skill set more robust.
Python Developers who want to learn PowerShell scripting and understand its ease of user and importance to manage any platform.
This book works both ways: As a reader you can use the book to learn Python if you know PowerShell, or learn PowerShell if you know Python. PowerShell and Python code samples and screenshots next to each other makes it very easy for readers to relate the common concepts and practices and learn the scripting language in no time.
Python is one of the top programming languages and in fast changing IT scenarios to DevOps and Cloud to the future - Data Science, Artificial Intelligence (AI) and Machine Learning Python is a must know.
But this PowerShell Scripting guide to Python would be very helpful for you if you already have some knowledge of PowerShell
NOTE! This is a Leanpub "Agile-published" book. That means the book is currently unfinished and in-progress. As I continue to complete the chapters, we will re-publish the book with the new and updated content. Readers will receive an email once a new version is published!
Prateek Singh is the solo technical founder of Ganak AI Labs, an Indian AI SaaS startup that also runs AI workshops for builders. Its product, Cloudeval AI, runs pre-deployment reviews for Azure, plus AWS CloudFormation (beta), with evidence-backed reports, through the web, a CLI, GitHub and MCP. Before AI, he worked as an infrastructure and cloud developer and was an active PowerShell community writer.
Learning Python becomes simple with this book when you come from the PowerShell world.
Prateek has really done an awesome work of consolidating into one book what will take you several months to acquire this knowledge by yourself. What I like in this book is this approach to learn a new language from a language you know well. A really a good way to grow-up your knowledge in Python very quickly without too many difficulties.
Clisson Florian
Good approach to grow-up your knowledge in Python very quickly
As a regular SysAdmin with some basic PowerShell knowledge who want's to switch to DevOps, this book is building on whatever I already know to help me learn Python.
Miroslav Vasilev
Made for SysAmins who want to learn Python
As a programmer, I wanted to learn python, but since I am already working on Powershell. So this book was suggested to me which can help me learning python through Powershell. I started reading the book and from the 1st day itself, I found it so interesting, short crisp and simple way to learn something new. I must say this book not only helps in learning python but also pushed me to learn more things in PowerShell as well. Great book, recommended!
Manoj Sahoo
PowerShell as a segue to Python
As an Infrastructure developer, you need multiple skills and this one is definitely helpful. Must read this book to upgrade your skills at 2x. Dear Prateek, Keep updating and upgrading us!
Durgesh Patel
Learn 2 scripting languages at 2X speed
Thanks a lot for writing this amazing book that explains the concepts of two popular scripting language. Before reading this book, I was not sure to learn Python but now, not only I am aware of Python programming, also this book helped me to strengthen my basic concepts of PowerShell. If you know a bit about PowerShell and want to learn Python also then this is the right fit for you.
Akshi Srivastava
Amazing book!
Contents
Table of Contents
1Introduction
2About the Book
2.1Why did I write this book
2.2Who is the Target Audience
2.3Prerequisites
2.4Feedback
3The Basics
3.1Version
3.2Case Sensitivity
3.3Indentation
3.4Comments
3.5Variables
Key Pointers
Reading Recommendations
4Console Input/Output
4.1Printing to Console
4.2Reading from Console
4.3Reading from Console Securely
Key Pointers
Reading Recommendations
5Creating your First Script
5.1Saving Commands as a Script File
5.2Running the Script File
Key Pointers
Reading Recommendations
6Passing Command-Line Arguments
6.1‘sys.argv’ in Python
6.2‘$args’ Automatic Variable in PowerShell
6.3‘Params()’ in PowerShell
6.4‘argparse’ Module in Python
6.5Parameter Help
Key Pointers
Reading Recommendations
7Object Introspection
7.1Class, Object, Property, and Method
7.2‘Get-Member’ cmdlet in PowerShell
7.3‘type()’ Method in Python
7.4‘dir()’ Method in Python
7.5‘inspect’ Module in Python
Key Pointers
Reading Recommendations
8The Help System
8.1Get-Help cmdlet in PowerShell
8.2‘help()’ Method in Python
8.3Understanding How a Module Works
9Modules
9.1Modular Programming
9.2Importing Modules
9.3Installing Modules
9.4Creating Modules
10Data Types
10.1Common Data types
10.2Checking the Data Type
10.3Data type casting
11String Manipulations and Formatting
11.1Common String Operations
11.2String Formatting
11.3Substring or String Slicing
11.4Testing String Membership
11.5Built-in methods
12Date and Time
12.1Get Date and Time
12.2Convert String to datetime object
12.3DateTime formatting
12.4Time Span or Time Delta
13File Handling
13.1Reading from a File
13.2File Modes
13.3Create and write to a text File
13.4Appending data to the File
14Arrays, List, ArrayList and Tuples
14.1Arrays
14.2ArrayList (.Net)
14.3Lists
14.4Common PowerShell Array and Python Lists Operations
14.5Tuples
14.6Sets
15Dictionary and Hashtable
15.1Hash Table
15.2Dictionary
16Conditional Statements
16.1If Statement
16.2Else Statement
16.3The elif and ifelse statement
16.4Nested Conditional Statements
17Loops
17.1For Loop
17.2ForEach and ForeEach-Object
17.3While Loop
17.4Loop Control Statements
17.5Nested Loops
18Functions
18.1Types of Functions
18.2Creating a Function
18.3Calling a Function
18.4Functions vs Methods
18.5Parameters and Arguments
18.6Mandatory and Default parameters
18.7The Anonymous Functions
19Handling XML and JSON Data
19.1Difference between JSON and XML
19.2Reading XML from a file
19.3Accessing XML as Objects
19.4Accessing XML with XPath
19.5Using XML for Object Serialization
19.6Parsing JSON
19.7JSON Serialization and De-Serialization
20Reading and Writing CSV Files
20.1What is CSV
20.2Reading CSV File
20.3Writing CSV File
21Error Handling
21.1Types of Errors
21.2Raising an Exception or Throwing an error
21.3Handling Exceptions using Try..catch..finally
22Built-In Functions
22.1Basic Mathematical Operations
22.2Selection and Arrangement
22.3Union and Intersection
22.4Dynamic Execution of Code
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.
You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.