Skip to content

Latest commit

 

History

History
532 lines (278 loc) · 15 KB

File metadata and controls

532 lines (278 loc) · 15 KB

SDLC: Software Development Life Cycle (SDLC): we must fllow SDLS lifecycle before starting in writing code

The 7 Phases Of SDLC (Software Development Life Cycle)

Phase Detail
Stage 1 Project Planning. ...
Stage 2 Gathering Requirements & Analysis. ...
Stage 3 Design. ...
Stage 4 Coding or Implementation. ...
Stage 5 Testing. ...
Stage 6 Deployment. ...
Stage 7 Maintenance.

Is python working on linux or windows: NO

It is working based on interpretor, interpretor فاصل between the code and operating system
Compiler: It is code that convert the code to code that Operating system can understand and respond ( program will work on specific OS)

Interpretor: the program will work on all platform, interpretor define the OS

we have two type of python have different instruction:

python 2.7: work as statement (end of support)
python 3: work as functions

Python IDLE: Tool can be used for python scripting, but not recommended (Cannot define the errors).

it is better to use Python IDE or use text editor like: Notepad++ or sublime.

Pycharm IDE: very good environement for python programming.

python pip: python installer package: use it when need to install a new Library.

Pylint library: Pylint analyses your code without actually running it. It checks for errors, enforces a coding standard, looks for code smells, and can make suggestions about how the code could be refactored.

Pylint can infer actual values from your code using its internal code representation (astroid).
Mingw: C++ Compiler

البايثون لايهتم بنوع ال variables float or integer لكن ببقية لغات البرمجه لازم نحدد النوع

Python Daya Types:

Boolean: True or False

اي رقم ماعدى صفر هو ترو

What is concatenated:

Two strings can be concatenated in Python by simply using the '+' operator between them. More than two strings can be
concatenated using '+' operator

use int: how many

use float: how much

Condition Statement: حالة يدخل فيها الكود
While
For
Switch Case: only C++
If
while: اعمل هاي الوظيفة الى ان تلكه قيمة معينه او يتحقق شرط معين

اذا ماصار الشرط راح يستمر بهاي الوظيفة مدى الحياة



فكشن Range دائما يرجع List ويستثني آخر رقم.

for: ex: for number in range(1,10):
number: variable
range: command for python only, use 1 as intial value, and 10 as the end value, and dynimaclly know that the conditional statement is
                        increase value + 1 
range exlude the last number (10)
                        ex: for number in range(1,10,2): 
2: increase number by 2
range: is one python data types


Nested if statement: if statement inside other if statement

Special Operator: AND, OR: elif area > 100 and area < 200:

                        print("This is medium area")
Casting error: غلط بالأقواس

Conditional Parameter:

Parameter Detail
== equal
!= unequal
>= greater than or equal to
<= less than or equal to

Logical Operater: and & or

Visual code studio اختصارات

ctrl + / : make # for all selected code

ctrl + \ : separate the cli


إذا اريد اعرف ال datatype لمتغير معين, فقط اطلب type للمتغير:

                        numbers = range(1,11)
                        print(type(numbers))
output: <class 'range'>

show the data type of numbers


\n: ينزل صطر

%.2f: يبين رقمين فقط بعد الفارزة مثلا 1.11


Aray in python can have multiple data types

Aray in all other programming languages must have one data type like: string

               mylist = ["apple","bannana","Cherry"]: this called " array(list) of string"
               name = "mohammed": this called " array of charachter 
               print(len(name)) : len used to find the size of the name. 


               name = "mohammed"
               print(name[0])
               Output: m

                         list3= [True, False, False] : This called " list of boolean
                         list1 = ['abc', 34, True, 40, "male"]
                         print(type(list1[1])) : find the clss of datatype

               thislist = ["apple", "banana", "cherry"]
               # print(len(thislist))
               print(thislist[len(thislist) -1])

list: تحسب ارقام المصفوفه من الصفر

len: تحسب من الواحد

لذلك لازم انقص واحد من البرنت حتى تصير 3-1, تصير 2 وينطبع اخر سترنك

               print(thislist[-1]) يسوي نفس شغل الفوك بس هاي ابسط 

sالبايثون اخر رقم بيه هو 0, لما يشوف -1 راح مباشرة يعرف نريد نسوي reverse array, يعني يبلش من الاخير

          thislist = ["apple", "banana", "cherry", "orange", "kiwi", "melon", "mango"]
          print(thislist[2:5])

هذا راح يطبع فقط: "cherry", "orange", "kiwi" البايثون بطبيعة يستثني اخر رقم الى هو 5 لذلك ازيد المصفوفة حتى اطبع الرقم الاخير الي اريده

                     print(thislist[2:6])
                     print(thislist[0:-1]): print all list exclude last one 
                     print(thislist[:4]): print from 0 until 3 
                     print(thislist[2:]): start from 2 until end of list

There are multiple functions in Python:

     thislist = ["apple", "banana", "cherry"]
     print("before change:", thislist)
       thislist.insert(len(thislist), "Melon") : insert used to add value in one of index
       print("after change", thislist)
         thislist.append("Melon") : append add the value to the end of index
         print("after change2", thislist)

     thislist = ["apple", "banana", "cherry"]
     tropical = ["mango", "pineapple", "papaya"]
      thislist.extend(tropical): extend: add list to other list
      print(thislist)
   output: ['apple', 'banana', 'cherry', 'mango', 'pineapple', 'papaya']

     thislist = ["apple", "banana", "cherry"]
     print("before change:", thislist)
       thislist.remove("banana") : remove index    or use: thislist.pop(1)    or use statement del thislist[1]
       print("after change:", thislist)
     output: before change: ['apple', 'banana', 'cherry']
     after change: ['apple', 'cherry']

     thislist.clear() : clear the list 
     output after change: [] 

            fruits = ["apple","banana","cherry","kiwi","mango"]
              newlist = [x for x in fruits if x.startswith("a")]   : find only word that start with " a "
                newlist= [x for x in fruits if "a" in x]             : find any word contain " a "
                  newlist = [x for x in fruits if x != "apple"]        : get all word except apple 

     newlist = [x.upper() for x in fruits if x != "apple"]       :change all letter to capital 
      newlist = [x.capitalize() for x in fruits if x != "apple"]  : change only first letter to capital

            number = [100,50,62,82,23]
              number.sort()      : ترتيب تصاعدي
                number.reverse()   : ترتيب تنازلي

                     mylist = fruits.copy() :: copy from other list
                        mylist = list(fruits)   same upper

     list1 = ["a","b","c"]
       print(list1.index("b"))   : find number of index = output= 2
         print(list1.index("b"))   : يحسبلي كم مره مكرره هاي القيمة باللست

Function: جزء من الكود انادي عليه كل ما أحتاجه

يعني هو برنامج داخل الكود دائما اعتبر الفاكشن هو برنامج منفصل عن البرنامج الرئيسي في بعض الفكشن ماتخذ انبوت وفيه ماتطلع اوتبوت واكو ماتسوي لااوتبوت ولا انبوت كل وحده وشغله



Dictionaries: Data type

        contacts = {"mostafa":"0123456789", "amr":"9876543210"}

هي عبارة عن key:value مثلا اطبع الكي راح تطلعلي الفاليو

        print(contacts["mostafa"])
          output: 0123456789
        print(contacts.values()): print the vlaues only
          output: (['0123456789', '9876543210'])

def my_function(os="win"): "win" هاي ديفلت فاليو اذا ماحطيت القيمة مالته لما استدعي الفكشن راح يطبع الديفلت

اذا حطيت قيمته راح يهمل هاي الديفلت فاليو مثل برنامج بالويندوز اول ماتشغله يكلك تريد اسويلك سكان للدفلت مثلا حرف سي او انت حدد

        my_function() : راح يستخدم الديفلت
         my_function("linux") :  راح يستخدم لنكس ويترك ويندوز
"linux" هذا يسمى argument
"win" " default argument

لايفضل عمل برنت داخل الفكشن

not recommended use print inside the functions.

الفاكشن الغرض منه طلعلي قيمة ومثلا اخليه بفايربل فالبرنت راح تخرب البرنامج الغرض من الفاكشن طلعلي فاليو اخليه لحاجة ثانية, مثلا انادي الفكشن واخلي الناتج يروح لبرنامج ثاني او يروح ل فكشن الثاني, او الاوتبوت يروح لفريابل ثاني. دائما اخلي الفاكشن يطلع فاليو معينة

          def even_or_odd(number):
            if number % 2 == 0:
             return True  : replace print by return 
          # print("Even")

return ماتظهر اي قيمة ولو اريد اطلع البرنت print(even_or_odd(2)) اخلي البرنت خارج الفكشن

return: stop function and return the value


Built in Functions:

Object file Handler:

file object allows us to use, access and manipulate all the user accessible files. One can read and write any such files.

         my_file = open(file="key.txt", mode="r")
open return file handler: IOWrapper in this example

open (): Function in Python: The open () function opens a file and returns a file object as a result


      print(dir(open)) 

Dir: show all functions that can do in open as example

pid: process id: get pid of any program

ppid parent process id: get the pid of the program the open the program

s مثلا فتحت نوتباد من السي ام دي, هنا راح يكون

pid: notepad, ppid: cmd



Object Oriented Programming: هي طريقة لكتابة الكود بشكل منظم واسرع

نقلب كلشي بالبرنامج الى اوبجكت كل وضيفة بالبرنامج نعبر عنها بأوبجت من مزاياه انه اكتب البرنامج بأكثر من مكان مو بفايل واحد

note: اي فكشن داخل اوبجكت نسمي ميثود

     class student:
       def __init__(self, name, age):    this is method

     import FileOps.FileSearch   :

FileOps: is folder and FileSearch: is python code

if we need to import python from other folder we need to put . between folder and python file name

  from fileOps.FileSearch import GetFiles   :  get only GetFiles function. 

Program to view files in windows

     import os

       def GetFiles(FilesPath, Extension="", isRecursive=False):  
       (Extension="" meaning we can put input or not اكدر احد الايكستينشن او لا اذا اشيل "" راح يجبرني احدد حتى يشتغل البرنامج)
       ( isRecursive=False  هنا الديفلت لا يعني لتبحث داخل الفولدرات الموجودة بالفولدر اذا اريده يبحث اخلي بالبرنامج yes )
FilesList = []
for file in os.listdir(FilesPath):
     if file.endswith(Extension):
        FilesList.append(file)
return FilesList

Program Code

       import Create_Modules
       myfiles = Create_Modules.GetFiles("C:\\windows")
       print(myfiles)


Python Modules

os.walk : looking as recursive on the files يبحث بالملفات الموجودة داخل الملف

          for file in os.walk("C:\\"):
            print(file)

os.walk get three types of files

Root: Dirs: File:

Ex: Root = C:
Dirs = [] folder in C directory Files = [] Files in C:\

C:\Windows Root = C:\Windows




Error Handling

read file from txt file ( not recommended in huge size of file, will put directly all size in the memory like 10 gbps ) so we can use read by context manager with

         read_file = open(r"C:\Windows\System32\drivers\etc\hosts", 'r' )
         print(read_file.read())  read directly from memory
     for line in read_file.readlines():   read line by line will also cause low processing in memory
         print(line)   will be there empty line between each word
	 print(line.strip()) Erase any empty character
	 
     with open("subdomains.lst", 'r') as read_file: read line using context manager 
          for line in read_file.readlines():
	      print(line.strip())

type: we can use type in cmd to view file contain like txt or python file

          write_file = open(r"C:\Windows\System32\drivers\etc\hosts", 'a' )
          write_file.write("192.168.1.13   my-pc.com")

if we use upper python code, the permission error will display and we need to use somthing to except the error

فكرة error handling اذا الكود صار بيه error راح يسوي pass ويكمل بقية الكود

          try:
              write_file = open(r"C:\Windows\System32\drivers\etc\hosts", 'a' )
              write_file.write("192.168.1.13   my-pc.com")
          except PermissionError:
              pass
          except FileNotFoundError:
              pass
          for number in range(10):
              print(number)

هتا سويت except اذا طلع الايرور PermissionError هنا راح يتخطاه واذا طلع FileNotFoundError ايضا راح يتخطاه. استخدمه مثلا اذا الفايل ماموجود اكله الفايل ماموجود تريد اسويلك واحد جديد

           import socket
socket: give domain or sub domain and return ip address