Category: python

Class Python Example: String Validation

Hello! It’s Roberts Greibers here. 

Having worked in IT industry as a QA (software engineer) and later as a Python developer for more than 7 years, I’ve gathered numerous Python examples of classes.

I’ll tell you more about my experience as a Software Engineer/Python developer later in the post..  ⚑️

But now, let me list what Python classes examples you’re about learn in this post..

Read and pay ATTENTION!

You’re about to explore the MOST important parts of what is a class in Python! πŸš€

One of the CORE understandings for objects in Python (Object Oriented Programming with Python)

In this post, you’re going to find out:

  • What is a class in Python?
  • How to define a Python class blueprint?
  • How to call Python class method?
  • How to execute Python class as a callable function?

I’ll do my best to make you understand classes in Python from this one blog post!

Also, if you’re coming from Javascript world, a keyword this might be familiar..

.. well in Python there isn’t “Python class this“, but there’s a similar concept we use.

And at the end, I’ll also share more about how my students are using classes in Python training – this might be an OPPORTUNITY FOR YOU to follow their steps!

More on that at the end of the post! πŸ‘‡πŸ»

Continue reading

Python Requests POST GET (HTTP Request Explained)

Welcome back or nice to see you for the first time!

Roberts Greibers here with another experience-based post about Python requests.

I’ve been working professionally as a Python developer for well over 7 years, I’ll share more details about my story later in the post.. (just scroll down the page to find out more about me). 

But before we talk about how qualified I am to write posts about Python requests, I’ll just give you all the answers you’ve been Googling for. πŸš€

WARNING: You’re about to see the most important Python requests library use cases with clearly defined examples. 

This is the BIGGEST breakthrough you’ll ever achieve as a Python developer.

Learning and implementing this way of calling API with a Python request is a major achievement in your career that you’ll use on a daily basis for years to come. 

In this post, you’re going to explore:

🚨 I’ll explain in detail everything you should know about Python3 requests (why Python2 requests are NOT used anymore)

And I’ll show you how API calls in Python are done in a real project (from Django projects I’ve worked on)

The intention here is to give you a real Python HTTP request example you could use in your own projects. 

Just a quick note before we start: At the end of the post I’ll share details about what helped my students to get hired as Python developers, read till the end and see if that helps you too!πŸ‘‡πŸ»

Continue reading

Python Read CSV File (Python Excel Reader)

Hey! It’s Roberts Greibers here.

I’ll share details about my 7+ years of experience as a Python developer with you a bit later in the post (you’ll have to scroll down to find them).

But now, let’s talk about how I came to write my “read from CSV Python example” script.. πŸš€

Firstly, understand that CSV is a file format supported by nearly all platforms..

That’s why for Python programming purposes I’d suggest you use CSV format instead of any other excel format. 

It’s possible to find a Python excel library and use Python for excel files in general, but in this post, we’re going to strictly focus on how to read CSV file in Python. 

Also, we’re going to check:

  • Should you learn Excel or Python? (using Python in Excel?)
  • Are there any ways you can use Python for excel? (e.g. Parsing CSV Python)
  • Any Python excel library you could find and use? (e.g. Python CSV file reader)
  • How to import CSV file in Python? (the process of importing CSV into Python)

If you’ve been Googling for “Python Read CSV” or the typical “Reading CSV file in Python” you’ve found the RIGHT place! πŸŽ‰

I’m about to explain the details of how I optimize my time by parsing spreadsheets in Python (e.g. CSV in Python) and how I avoid manual CSV reading tasks using Python. 

Building a quick CSV file reader in Python can take you up to 30 minutes and save you hours later assuming you’re using the script on a daily basis. 

Let’s get into it and I’ll also share a way that helped me and might even help you to become a professional Python developer at the end of the post πŸ‘‡πŸ»

Continue reading

Subprocess In Python (Run Command Line)

Good evening, Roberts Greibers here.

We will get into my Python subprocess story and how I even got the point of writing blog posts about Python a bit later. 

But at this moment, I want you to pay attention and read very carefully!

What I’m about share with you is a real subprocess Python example! 🚨

How to use subprocess in Python to run command line commands!

The difference between running a shell command in Python with:

Also, a real example of me actually executing a shell command in Python.

Most “Python subprocess example” tutorials you’ll find online won’t give you a REAL project example..

And they won’t tell you what steps you’ll need to take in your specific situation. 

In this post, I’ll share how you should THINK in order to be able to come up with a solution for your own “how to run shell command in Python?” problem.. πŸš€

If this sounds interesting to you, keep on reading, I’ll also give you an opportunity to become a Python developer at the end of the post πŸ‘‡πŸ»

Continue reading

Python XML Parse – ElementTree Reader & Parser

In this Python XML tutorial, you will learn how to use xml.etree.ElementTree package (which is one of the many Python XML parsers) to process XML response.

For this tutorial, you can use your own XML response or follow the steps below and use the one I have provided.

The Python XML parsing steps I’m about to explain and guide you through were developed alongside a refund payment integration I was working on in Django. 

We’re going to explore the parsing end result for the SOAP XML response I wrote about in the previous post. The SOAP XML parsing post was written with a focus on an actual regex parsing in Python and all the steps before you get to the actual XML scheme style response. 

In this post, I’m about to give you a Python XML tutorial for parsing XML schemes when you already have a decoded version of an XML response and you see the information.

The post here is about extracting specific values from the whole XML tree without using regex or any other typical Python parsing tools, but the actual xml.etree.ElementTree package (the right way)

By the way, Roberts Greibers here – in my day job, I’m working as a Python Django backend developer for a local company in Riga, Latvia, and building a white label payment gateway platform. 

Over the past couple of years, I’ve gathered a lot of experience in the FinTech industry, practical knowledge of how payment systems work, how to develop, test and deploy them with minimal headache. 

Of course, I can’t go into too much detail here in a single blog post, but if you want to build your own portfolio project and become a Python and Django developer, I’d suggest checking out client testimonials here and reaching out to me.

I go very deep and always explain all the steps in detail with specific videos and documents for my clients. So the post here is just a small example of how I could help you out.

Also, I always answer all client questions along the way.. but enough of talking, let’s get into the code. 

Continue reading

Parsing SOAP XML Response In Python

In this tutorial, you will learn how to decode and parse a large SOAP XML response with Python and regular expression, essentially the goal here was to build a Python function to get rid of manually decoding SOAP XML response over and over again.

The Python code I’m about to explain and show you was developed as a part of refund payment integration done in Python and Django. 

We’re going to take a look at an encoded SOAP XML response stdout saved in a text file.

I saved this SOAP response output when I was in a process of developing a payment integration feature for a local bank here in Riga, Latvia, along the way I realized it’s going to be a great learning experience for anyone else who’s going to search for a similar solution on Google. 

I’ve discussed similar text file parsing in Python situations before here on the blog, but the difference here is that this one is way more complicated and involves a bit more decoding and text manipulation as well as extensive knowledge on regex pattern matching. 

Definitely a good Python regular expression practice, even for advanced Python developers. 

Currently, I’m working as a Python Django backend developer (Roberts Greibers) for a local company here in Riga, Latvia – building a white-label payment gateway platform, you can find more about my experience on my Linkedin profile

Give me a follow on Linkedin or send me a DM if you have any questions. 

One of the recent payment integration flows I needed to develop was for a refund payment. Refund payments were supposed to work for multiple banks through one gateway system for this particular client and brand. 

The whole refund payment flow is way more complicated and would take me weeks to write up and explain here on the blog so I’m gonna share a small portion of what actually was very interesting to work on – parsing decoded SOAP XML response with regular expression in Python. 

I go deeper explaining features you can develop for your Python and Django portfolio if you’re working personally with me in one on one Zoom calls (click here to see an example of a LIVE Zoom call). I personally will guide you through the development of each feature and answer all your questions along the way. 

This is what we’re working on with my most successful mentoring clients.

So if the above sounds interesting, let’s get started! 

Continue reading

Python Training: Why You Shouldn’t Attend It (3 Important Reasons)

Good afternoon, Roberts Greibers here, and in this post I’m going to expose the awful truth about python training in NYC (New York City) and also all over the world. 

I’ve been working professionally as a Python developer for more than 5 years and now (see my Linkedin here) I’m also helping people who are in a similar position I was when I first started – to become Python developers. (see a cut from a LIVE mentoring call)

Ever since I started to lean more into the field of helping people, I realized how many horror stories are out there about a common Python training course. 

Every now and then I hear a new story, a new shocking price of a training course, and now it’s no surprise to me that there is a lack of good Python developers out there. 

I used to be a quality assurance engineer (manual tester) – testing website projects and apps so I totally get that a lot of people want to move away from their current job and get into more profitable positions like becoming a Python/Django developer.  

Maybe you’re somebody who wants to become a Python developer, be more independent, more free from a typical 9-5 job, maybe even work remotely from anywhere in the world, and have a higher income than what you’re used to. 

So if that’s you, I want to give you a little bit of a counterbalance to all the wild claims that all these Python training courses out there are currently making. 

Continue reading

Python Regex Groups, Match and Search

Hey, Roberts Greibers here. I’ll give you a brief intro about my 7-year experience as a Python developer down the line – later in this post. 

But now I want you to scroll a bit more and dive right into Python regex groups and the Python regex example I’ve greatly detailed below. 

The following regex Python example is going to show you.. ⚠️

  • What actually is import re in Python and how you can use it!
  • How to THINK and come up with your own Python regex patterns
  • A real-life Python regex example (sent in by a reader of this blog post)

If you’ve been Google searching for Python re examples, you’ve found the RIGHT place!

Most regular expression Python examples you’ll find online are very theoretical, showing you just the concept of a regex capturing group.. but they don’t tell you how to THINK in order to come up with your own solutions – your own regex patterns.

In this post, I’ll take a real Python regex situation and explain what fundamental steps I take to come up with a solution. πŸš€

And if you really think about it…

It’s the ONLY way for you to truly understand regex Python examples and use them for your benefit. You have to understand the fundamental process behind solving a Python problem.

So, if getting deeper into a real regular expression Python example sounds interesting to you – keep on reading!

I’m explaining the whole story of how I came to the following situation in Python where regex capture group was part of the solution down below! πŸ‘‡πŸ»

Continue reading

Log File Parsing In Python

In this tutorial, you will learn how to open a log file, read a log file, and create a log file parser in Python, essentially building a so-called “Python log reader”.

To open a log file in Python, read a log file, and actually parse a log file or any type of text file in order to extract specific information is not that hard if you know a bit of Python log file parsing and regex pattern match usage.

Python itself is a perfect tool to open a log file for parsing and it does not require any third-party modules. Believe me, the first thing I did was a Google search for a “Python log reader” and “Python file parsing” a couple of years ago when I first started to work on parsing text files in Python. Ever since those days, I’ve learned to work with Python and regex very efficiently, see more details in a recent post I did about how to parse XML SOAP response with Python and regex by clicking here.

In my day job, a while back I was working on testing Skype for Business iOS application as a test engineer and it came to the point where I had to open and manually collect the SfB iOS application log files in order to see all HTTP requests and received HTTP responses.

Ever since then I’ve switched to backend development with Python/Django and also helped people to go into a similar path. See a cut from a recent coaching call here. And more about client testimonials here.

Anyways, in this specific situation, I had to figure out a good way to open iOS log files and parse them to search a log file for properties like:

<code><property name="saveMessagingHistory">Enabled</property></code>

Usually, properties were buried under a bunch of other not-so-important log file dumps, for example:

INFO UTILITIES /Volumes/ServerHD2/buildagent/workspace/200615/client_ios_sfb/dependencies/client-shared_framework_sfbplatform/src/dev/lyncMobile/platform/tracing/privateIos/ Information
2016-12-20 13:16:52.303 SfB[417:1af74bc40] INFO UTILITIES CTimer.cpp:657 TimerMap is created 
2016-12-20 13:16:52.342 SfB[417:1af74bc40] INFO UI Application will finish launching with options
2016-12-20 13:16:52.345 SfB[417:1af74bc40] INFO UTILITIES Creating StorageManager
2016-12-20 13:16:52.347 SfB[417:1af74bc40] INFO UTILITIES Initializing StorageManager
2016-12-20 13:16:52.357 SfB[417:1af74bc40] INFO APPLICATION CApplication.cpp:3400 Initialize Internal Begin
2016-12-20 13:16:52.361 SfB[417:1af74bc40] INFO UTILITIES User UI language identifier en was mapped to en-US 1033
2016-12-20 13:16:52.362 SfB[417:1af74bc40] INFO UTILITIES Device Version Info - Model=iPhone, HardwareModel=iPhone9,3, SystemName=iOS, SystemVersion=10.1
2016-12-20 13:16:52.362 SfB[417:1af74bc40] VERBOSE APPLICATION CApplication.cpp:3415 Initialize Internal -- App State Query Established
2016-12-20 13:16:52.363 SfB[417:1af74bc40] INFO UTILITIES CNetworkMonitor.cpp:70 Successfully started listening to network events
2016-12-20 13:16:52.364 SfB[417:1af74bc40] INFO UTILITIES CNetworkMonitor.cpp:229 Reachabilility Flags IsWWAN(0):Reachable(1):TransientConnection(0):ConnectionRequired(0):ConnectionOnTraffic(0):InterventionRequired(0):ConnectionOnDemand(0):IsLocalAddress(0):IsDirect(0)
2016-12-20 13:16:52.364 SfB[417:1af74bc40] INFO UTILITIES CNetworkMonitor.cpp:198 Updated networkAvailableToConnect(NoNetwork) -> WiFi, isInAirplaneMode(0) -> 0
2016-12-20 13:16:52.364 SfB[417:1af74bc40] INFO UTILITIES CTimer.cpp:227 Created timer instance (0x70286428) for runloop (0x7017e780)

While I was searching for specific properties in those log files, I realized it’s going to be really time-consuming to go through everything manually.

In order to save time, I had to come up with a good way to use Python file parsing, and long behold I managed to write code for a log file parsing Python script.

It’s a very simple way of searching a log file with Python.

If you want to test the following Python log parsing script with a similar text file, you have to download Skype for Business iOS log file here:

Continue reading