Category Archives: Language

Python Translator – How to make ? English to Bengali or other Translator

Here I will show how to make a python tanslator. My translate language will be Bengali/Bangla and it will save to a file. Here I have made a short youtube video to show how to do it.

 

Codes:

 

Python Course Zero to Mastery Started at Udemy

Python usually uses an interpreter. The compiler are a little bit different.

Interpret translates line by line.

Compiler takes all lines to machine code.

What is programming language? We give some instruction to translator. They tell the machine what to do. Translator can be interpreter or compiler.

Interpreter:

Compiler:

Python basics till numbers:

Double Slash in Python:


/ -> float division
//-> integer division

don’t memorize which available on the documentation

String type conversation.

Formatted String:

String Index

selfish[start:stop:stepover]

Immutabilty

Built in functions
Booleans

Software to find your current age with python:

#1 “old style” string formatting(% operator)

Source: https://realpython.com/python-string-formatting/

Template string ta pore kokhono hoyto dekhbo, ei ar ki

password length printing code from the course:

List

Matrix

list operations:

we can see the function from online documentation from the official site or other sites

 

 

 

 

Dictionary

Tuple:

Set:

set is an unordered collection of unique objects.

conditional.

 

Truthy and Falsy:

 

Exercise: Logical Operators

Equality

is vs == 
with using ‘is’ it needs to be refers to the same object

with == it needs to be equally same valued

for example:

 

 

Exercise: Counter will print item in list

Range

Enumerate:

while

 

break, pass, continue

Exercise:

Exercise:

Parameters and Arguments:

Return in python:

How it works:

without return it prints none:

 

with return it prints something that I insisted for:

Nested Return:

#issues with print and return

Exercise:

 

Exercise: To find even and max value from a list

 

Abstraction: private vs Public

 

Inheritance:

Polymorphism:

 

no amount of video is enough you have to learn by your way of development projects.

4 pillars in oop Encapsulation, Abstraction, Inherítance, Polymorphism

 

Now i am looking for another video from youtube to learn something about it.

Another youtube playlist I found easy to understand really:

Normal procedural code look like:

Code examples from this video of OOP for future reference:
Class.py

inheritance.py

inheritance_class_init.py

class_init.py

class_init_update.py

class_und_instance_variable.py

class_inherit

 

 

 

Now the exercise from the udemy course:

Super,Object Introspection, Dunder/Magic method

1st example:

 

2nd example:

 

#Multiple Inheritance

#Method Resolution Order(MRO)

Pure Function

 

Map()

filter()

zip()

output: [(1, 10, 5), (2, 20, 4), (3, 30, 3)]

reduce() function and how it works in python:

I have seen two videos here from udemy and youtube to clear this concept for me

code from udemy:

reduce()

Output:

Exercise solutions here in function:

#1 Capitalize all of the pet names and print the list

output:

#2 Zip the 2 lists into a list of tuples, but sort the numbers from lowest to highest.

#3 Filter the scores that pass over 50%

#4 Combine all of the numbers that are in a list on this file using reduce (my_numbers and scores). What is the total?

Output:

Lambda Expressions in python:

Lambda is a computer science term. Which is an anonymous function. Which don’t use more than once for a purpose. Usually in lambda we don’t need to decalre any function name. What happens inside a function we can write in simple line using lambda function.

lambda using map:

lambda using filter:

lambda using reduce:

# Exercises using lambda
1. make a lambda example to squre

2. make a lambda example to make a sorted list

List Comprehension

Set and Dict Comprehension:

#dict comprehension

Comprehension is for shorthand.

Now a small exercise:

Problem: to write a one line code to find duplicate character to show in a answer
Soln code:

Output:

Decorators:

another example:

Higher Order Function HOC

the decorator can supercharge the function and can add an extra feature

Decorator:

Another example:

Practical Application of Decorator:

Exercise:

Need to do later as it is not downloading on my tablet

Error Handling:

error:

custom error in error handling:

Generators:
Range is a generator. Generator is special type in python

generator is iterable but all iterable is not generator
example: range is generator that is always iterable, list is also iterable but not generator

Modules:

Some examples of using modules here:
utility.py : in this file I put all the functions for opertions

Now I am sending values to those function using main :

 

Again another way:
main_buy.py:

shopping_cart.py:

The thing need to remember usually in a package automatically a file __init__.py creates.

Another important thing a successful program without error run with exit code 0
And with error run with exit code 1

Another way of example:

main.py

utility.py

shopping_cart.py

 

__name__:
Again example with names:

__name__

print(__name__)
#if __name__==’__main__’:

why it is used in code, here i found a logical explanation.
link: https://s1s1ty.medium.com/concept-behind-if-name-main-in-python-fbf834d244ee

the code i applied from that link to here.

a.py

b.py

 

 

test.py:

utility.py

Python Built in Modules:

In other language it is known as standard library.
You don’t need to remember all, just know it exists and google it when needful.

https://docs.python.org/3/py-modindex.html

Exercise:

for python library we can use bulit in library or third party library that is available on  pypi.org. for example: email, pdf etc.

File handling in Python:

Reading- reading when file exist code= ‘r
Writing – writing write content in the file code= ‘w’
it will be create a file
Appending -add contents to the file and no overwrite code = ‘a’

Some python code and screenshot with pycharm_
fileobject=0pen(“name of the file”,”mode of the file”)
fileobject.methodname()
method name can be read write append etc.


code:

this two youtube video helped me to learn in details than udemy video:

 

Why we use seek in opening file and how to use it ?
Because the open is only usable once but after that to open the same thing several times we need seek()

example:

another one to read all three lines at once:

3lines.txt

Another example of writing, one thing is r+ means read and write both.

Path are two types in a python system:

Absolute path and Relative path:

File Input output error:

Debugging in Python:

Output in run:

PIP Install in Pycharm on Windows environment:
pip install package-name
In below terminal not in python console

 

Python Job Tricks:
– Show you have real experience by building projects

Regular Expressions:
Regular expressions are langauge independent. It is also available in other languages. It needful to check validation of words.

out put:

it means that ‘this’ start at span 17 and ended in span 21

Nobody remembers regex we learn it when needful. We learn later by email and password checker making.

No one ask you in interview about Regex. Sso you just know how to do it.

This interactive tutorial has been suggested by Androe: https://regexone.com/lesson/wildcards_dot

Now adding with another code for email validation:

Password validation:

Testing:

Testing is not only in python but also for all others platform

We are learning unittesting in this section:
script.py

test.py