├── 10prime.py ├── 11palindom.py ├── 12histogram.py ├── 13fiborecursion.py ├── 14factrecursion.py ├── 1stack.py ├── 2queue.py ├── 3merge.py ├── 4bubbol.py ├── 5knapsack.py ├── 6fib.py ├── 7cal.py ├── 7fact.py ├── 8maxodd.py ├── 9armstrong.py ├── DBOperation.java ├── LICENSE.txt ├── NEWS.txt ├── README.md ├── appending_to_files.py ├── built_in_functions.py ├── cal.py ├── class_py.py ├── cx_freeze_python_to_exe.py ├── cx_setup.py ├── dictionaries.py ├── eval_py.py ├── example.txt ├── example1.txt ├── examples.csv ├── exec_py.py ├── for_loop.py ├── ftplib_py.py ├── function.py ├── function_with_parameter.py ├── function_with_parameter_default.py ├── getting_user_input.py ├── global_and_local_variables.py ├── hibernate.cfg.xml ├── if_elif.py ├── if_else.py ├── input.py ├── list_manipulation.py ├── lists_and_tuples.py ├── makemodule.py ├── math_py.py ├── matplotlib_py.py ├── multi_dimensional_list.py ├── multiline_print.py ├── os_module.py ├── p1.py ├── parsing_website_with_re_and_urllib.py ├── pic.jpg ├── pickle_py.py ├── print_funtion.py ├── read_to_files.py ├── reading_from_CSV_spreadsheet.py ├── regular_expression.py ├── socket_binding_listening.py ├── sockets_py.py ├── sqlite3_py.py ├── statistics_py.py ├── sys_module.py ├── threading_module.py ├── tkinter_adding_button.py ├── tkinter_adding_images_and_text.py ├── tkinter_exe.py ├── tkinter_menu_bar.py ├── tkinter_module_making_windows.py ├── tkinter_setup.py ├── tutorial.db ├── urllib_module.py ├── usemodule.py ├── variables.py ├── vcruntime140.dll ├── while_loop.py ├── withHeaders.txt └── writing_to_file.py /10prime.py: -------------------------------------------------------------------------------- 1 | # Python program to display all the prime numbers within an interval 2 | 3 | # change the values of lower and upper for a different result 4 | lower = 900 5 | upper = 1000 6 | 7 | # uncomment the following lines to take input from the user 8 | #lower = int(input("Enter lower range: ")) 9 | #upper = int(input("Enter upper range: ")) 10 | 11 | print("Prime numbers between",lower,"and",upper,"are:") 12 | 13 | for num in range(lower,upper + 1): 14 | # prime numbers are greater than 1 15 | if num > 1: 16 | for i in range(2,num): 17 | if (num % i) == 0: 18 | break 19 | else: 20 | print(num) 21 | 22 | 23 | 24 | 25 | - > spring starter project 26 | - > dependencies = mysql driver, spring boot devtools, spring data jpa, spring web starter 27 | - > copy from web = tomcat embed jasper, jstl (remove version tag) 28 | - > version tag 2.1.4 29 | - > then application.properties - 30 | spring.prefix=/WEB-INF/ 31 | spring.suffix.jsp 32 | spring.datasource.url=jdbc:mysql://localhose:3306/databasename 33 | spring.datasource.username=root 34 | spring.datasource.password=root 35 | spring.jpa.hibernate.ddl-auto=update 36 | spring.jpa.show-sql=true 37 | - > create folder in main name it webapp and inside webapp create another name it WEB-INF 38 | - > create packages 39 | - > in controller @RestController and @RequestMapping("/") 40 | - > Finish Motherfucker now do it on your own way.a 41 | -------------------------------------------------------------------------------- /11palindom.py: -------------------------------------------------------------------------------- 1 | 2 | n=int(input("Enter number:")) 3 | temp=n 4 | rev=0 5 | while(n>0): 6 | dig=n%10 7 | rev=rev*10+dig 8 | n=n//10 9 | if(temp==rev): 10 | print("The number is a palindrome!") 11 | else: 12 | print("The number isn't a palindrome!") 13 | -------------------------------------------------------------------------------- /12histogram.py: -------------------------------------------------------------------------------- 1 | def histogram( items ): 2 | for n in items: 3 | output = '' 4 | times = n 5 | while( times > 0 ): 6 | output += '*' 7 | times = times - 1 8 | print(output) 9 | 10 | histogram([2, 3, 6, 5]) 11 | -------------------------------------------------------------------------------- /13fiborecursion.py: -------------------------------------------------------------------------------- 1 | def recur_fibo(n): 2 | """Recursive function to 3 | print Fibonacci sequence""" 4 | if n <= 1: 5 | return n 6 | else: 7 | return(recur_fibo(n-1) + recur_fibo(n-2)) 8 | 9 | # Change this value for a different result 10 | nterms = 10 11 | 12 | # uncomment to take input from the user 13 | #nterms = int(input("How many terms? ")) 14 | 15 | # check if the number of terms is valid 16 | if nterms <= 0: 17 | print("Plese enter a positive integer") 18 | else: 19 | print("Fibonacci sequence:") 20 | for i in range(nterms): 21 | print(recur_fibo(i)) 22 | -------------------------------------------------------------------------------- /14factrecursion.py: -------------------------------------------------------------------------------- 1 | 2 | def recur_factorial(n): 3 | """Function to return the factorial 4 | of a number using recursion""" 5 | if n == 1: 6 | return n 7 | else: 8 | return n*recur_factorial(n-1) 9 | 10 | # Change this value for a different result 11 | num = 7 12 | 13 | # uncomment to take input from the user 14 | #num = int(input("Enter a number: ")) 15 | 16 | # check is the number is negative 17 | if num < 0: 18 | print("Sorry, factorial does not exist for negative numbers") 19 | elif num == 0: 20 | print("The factorial of 0 is 1") 21 | else: 22 | print("The factorial of",num,"is",recur_factorial(num)) 23 | -------------------------------------------------------------------------------- /1stack.py: -------------------------------------------------------------------------------- 1 | class Stack: 2 | 3 | def __init__(self): 4 | self.stack = list() 5 | self.maxSize = 8 6 | self.top = 0 7 | 8 | def push(self,data): 9 | if self.top>=self.maxSize: 10 | return ("Stack Full!") 11 | self.stack.append(data) 12 | self.top += 1 13 | return True 14 | 15 | def pop(self): 16 | if self.top<=0: 17 | return ("Stack Empty!") 18 | item = self.stack.pop() 19 | self.top -= 1 20 | return item 21 | 22 | def size(self): 23 | return self.top 24 | 25 | def merge(a,b): 26 | ans = [] 27 | while(len(a)>0): 28 | ans.append(a.pop()) 29 | while(len(b)>0): 30 | ans.append(b.pop()) 31 | return(ans) 32 | a = [3,4] 33 | b = [1,2] 34 | m = merge(a,b) 35 | for k in m: 36 | print(k) 37 | 38 | s = Stack() 39 | print(s.push(1)) 40 | print(s.push(2)) 41 | print(s.push(3)) 42 | print(s.push(4)) 43 | print(s.push(5)) 44 | print(s.push(6)) 45 | print(s.push(7)) 46 | print(s.push(8)) 47 | print(s.push(9)) 48 | print(s.size()) 49 | print(s.pop()) 50 | print(s.pop()) 51 | print(s.pop()) 52 | print(s.pop()) 53 | print(s.pop()) 54 | print(s.pop()) 55 | print(s.pop()) 56 | print(s.pop()) 57 | print(s.pop()) 58 | -------------------------------------------------------------------------------- /2queue.py: -------------------------------------------------------------------------------- 1 | class queue: 2 | def __init__(self): 3 | self.itmes = [] 4 | 5 | def add(self,item): 6 | self.items.append(item) 7 | 8 | def delete(self): 9 | itemtodelete = self.items[0] 10 | del self.items[0] 11 | return itmetodelete 12 | 13 | def size(self): 14 | return len(self.items) 15 | 16 | 17 | 18 | myqueue = queue() 19 | myqueue.add("jaimin") 20 | myqueue.add("ajay") 21 | myqueue.add("yo") 22 | myqueue.add("jalfjj") 23 | print(myqueue.size()) 24 | print(myqueue.report()) 25 | print(myqueue.delete()) 26 | print(myqueue.report()) 27 | -------------------------------------------------------------------------------- /3merge.py: -------------------------------------------------------------------------------- 1 | # Merges two subarrays of arr[]. 2 | # First subarray is arr[l..m] 3 | # Second subarray is arr[m+1..r] 4 | def merge(arr, l, m, r): 5 | n1 = m - l + 1 6 | n2 = r- m 7 | 8 | # create temp arrays 9 | L = [0] * (n1) 10 | R = [0] * (n2) 11 | 12 | # Copy data to temp arrays L[] and R[] 13 | for i in range(0 , n1): 14 | L[i] = arr[l + i] 15 | 16 | for j in range(0 , n2): 17 | R[j] = arr[m + 1 + j] 18 | 19 | # Merge the temp arrays back into arr[l..r] 20 | i = 0 # Initial index of first subarray 21 | j = 0 # Initial index of second subarray 22 | k = l # Initial index of merged subarray 23 | 24 | while i < n1 and j < n2 : 25 | if L[i] <= R[j]: 26 | arr[k] = L[i] 27 | i += 1 28 | else: 29 | arr[k] = R[j] 30 | j += 1 31 | k += 1 32 | 33 | # Copy the remaining elements of L[], if there 34 | # are any 35 | while i < n1: 36 | arr[k] = L[i] 37 | i += 1 38 | k += 1 39 | 40 | # Copy the remaining elements of R[], if there 41 | # are any 42 | while j < n2: 43 | arr[k] = R[j] 44 | j += 1 45 | k += 1 46 | 47 | # l is for left index and r is right index of the 48 | # sub-array of arr to be sorted 49 | def mergeSort(arr,l,r): 50 | if l < r: 51 | 52 | # Same as (l+r)/2, but avoids overflow for 53 | # large l and h 54 | m = (l+(r-1))/2 55 | 56 | # Sort first and second halves 57 | mergeSort(arr, l, m) 58 | mergeSort(arr, m+1, r) 59 | merge(arr, l, m, r) 60 | 61 | 62 | # Driver code to test above 63 | arr = [12, 11, 13, 5, 6, 7] 64 | n = len(arr) 65 | print ("Given array is") 66 | for i in range(n): 67 | print ("%d" %arr[i]), 68 | 69 | mergeSort(arr,0,n-1) 70 | print ("\n\nSorted array is") 71 | for i in range(n): 72 | print ("%d" %arr[i]), 73 | -------------------------------------------------------------------------------- /4bubbol.py: -------------------------------------------------------------------------------- 1 | def bubbleSort(arr): 2 | n = len(arr) 3 | 4 | # Traverse through all array elements 5 | for i in range(n): 6 | 7 | # Last i elements are already in place 8 | for j in range(0, n-i-1): 9 | 10 | # traverse the array from 0 to n-i-1 11 | # Swap if the element found is greater 12 | # than the next element 13 | if arr[j] > arr[j+1] : 14 | arr[j], arr[j+1] = arr[j+1], arr[j] 15 | 16 | # Driver code to test above 17 | arr = [64, 34, 25, 12, 22, 11, 90] 18 | 19 | bubbleSort(arr) 20 | 21 | print ("Sorted array is:") 22 | for i in range(len(arr)): 23 | print ("%d" %arr[i]), 24 | -------------------------------------------------------------------------------- /5knapsack.py: -------------------------------------------------------------------------------- 1 | #A naive recursive implementation of 0-1 Knapsack Problem 2 | 3 | # Returns the maximum value that can be put in a knapsack of 4 | # capacity W 5 | def knapSack(W , wt , val , n): 6 | 7 | # Base Case 8 | if n == 0 or W == 0 : 9 | return 0 10 | 11 | # If weight of the nth item is more than Knapsack of capacity 12 | # W, then this item cannot be included in the optimal solution 13 | if (wt[n-1] > W): 14 | return knapSack(W , wt , val , n-1) 15 | 16 | # return the maximum of two cases: 17 | # (1) nth item included 18 | # (2) not included 19 | else: 20 | return max(val[n-1] + knapSack(W-wt[n-1] , wt , val , n-1), 21 | knapSack(W , wt , val , n-1)) 22 | 23 | # end of function knapSack 24 | 25 | # To test above function 26 | val = [60, 100, 120] 27 | wt = [10, 20, 30] 28 | W = 50 29 | n = len(val) 30 | print knapSack(W , wt , val , n) 31 | -------------------------------------------------------------------------------- /6fib.py: -------------------------------------------------------------------------------- 1 | ## Example 1: Using looping technique 2 | def fib(n): 3 | a,b = 1,1 4 | for i in range(n-1): 5 | a,b = b,a+b 6 | return a 7 | print (fib(5)) 8 | 9 | ## Example 2: Using recursion 10 | def fibR(n): 11 | if n==1 or n==2: 12 | return 1 13 | return fibR(n-1)+fibR(n-2) 14 | print (fibR(5)) 15 | 16 | ## Example 3: Using generators 17 | a,b = 0,1 18 | def fibI(): 19 | global a,b 20 | while True: 21 | a,b = b, a+b 22 | yield a 23 | f=fibI() 24 | f.next() 25 | f.next() 26 | f.next() 27 | f.next() 28 | print (f.next()) 29 | 30 | ## Example 4: Using memoization 31 | def memoize(fn, arg): 32 | memo = {} 33 | if arg not in memo: 34 | memo[arg] = fn(arg) 35 | return memo[arg] 36 | 37 | ## fib() as written in example 1. 38 | fibm = memoize(fib,5) 39 | print (fibm) 40 | 41 | ## Example 5: Using memoization as decorator 42 | class Memoize: 43 | def __init__(self, fn): 44 | self.fn = fn 45 | self.memo = {} 46 | def __call__(self, arg): 47 | if arg not in self.memo: 48 | self.memo[arg] = self.fn(arg) 49 | return self.memo[arg] 50 | 51 | @Memoize 52 | def fib(n): 53 | a,b = 1,1 54 | for i in range(n-1): 55 | a,b = b,a+b 56 | return a 57 | print (fib(5)) 58 | 59 | 60 | 61 | def memoize(f): 62 | memo = {} 63 | def helper(x): 64 | if x not in memo: 65 | memo[x] = f(x) 66 | return memo[x] 67 | return helper 68 | 69 | 70 | def fib(n): 71 | if n == 0: 72 | return 0 73 | elif n == 1: 74 | return 1 75 | else: 76 | return fib(n-1) + fib(n-2) 77 | 78 | fib = memoize(fib) 79 | 80 | print(fib(40)) 81 | -------------------------------------------------------------------------------- /7cal.py: -------------------------------------------------------------------------------- 1 | def add(x, y): 2 | return x + y 3 | 4 | # This function subtracts two numbers 5 | def subtract(x, y): 6 | return x - y 7 | 8 | # This function multiplies two numbers 9 | def multiply(x, y): 10 | return x * y 11 | 12 | # This function divides two numbers 13 | def divide(x, y): 14 | return x / y 15 | 16 | print("Select operation.") 17 | print("1.Add") 18 | print("2.Subtract") 19 | print("3.Multiply") 20 | print("4.Divide") 21 | 22 | # Take input from the user 23 | choice = input("Enter choice(1/2/3/4):") 24 | 25 | num1 = int(input("Enter first number: ")) 26 | num2 = int(input("Enter second number: ")) 27 | 28 | if choice == '1': 29 | print(num1,"+",num2,"=", add(num1,num2)) 30 | 31 | elif choice == '2': 32 | print(num1,"-",num2,"=", subtract(num1,num2)) 33 | 34 | elif choice == '3': 35 | print(num1,"*",num2,"=", multiply(num1,num2)) 36 | 37 | elif choice == '4': 38 | print(num1,"/",num2,"=", divide(num1,num2)) 39 | else: 40 | print("Invalid input") 41 | -------------------------------------------------------------------------------- /7fact.py: -------------------------------------------------------------------------------- 1 | memo ={} 2 | 3 | def fact(n): 4 | if n in memo: 5 | return memo[n] 6 | elif n == 0: 7 | return 1 8 | else: 9 | x = fact(n-1) * n 10 | memo[n] = x 11 | return x 12 | 13 | a = fact(10) 14 | b = fact(20) 15 | 16 | print a,b 17 | -------------------------------------------------------------------------------- /8maxodd.py: -------------------------------------------------------------------------------- 1 | def my_solution(): 2 | numbers = [input('Enter a value: ') for i in range(10)] 3 | odds = [y for y in numbers if y % 2 != 0] 4 | if odds: 5 | return max(odds) 6 | else: 7 | return 'All declared variables have even values.' 8 | my_solution() 9 | -------------------------------------------------------------------------------- /9armstrong.py: -------------------------------------------------------------------------------- 1 | # Python program to check if the number provided by the user is an Armstrong number or not 2 | 3 | # take input from the user 4 | num = int(input("Enter a number: ")) 5 | 6 | # initialize sum 7 | sum = 0 8 | 9 | # find the sum of the cube of each digit 10 | temp = num 11 | while temp > 0: 12 | digit = temp % 10 13 | sum += digit ** 3 14 | temp //= 10 15 | 16 | # display the result 17 | if num == sum: 18 | print(num,"is an Armstrong number") 19 | else: 20 | print(num,"is not an Armstrong number") 21 | -------------------------------------------------------------------------------- /DBOperation.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import java.util.List; 4 | 5 | import org.hibernate.Query; 6 | import org.hibernate.Session; 7 | import org.hibernate.SessionFactory; 8 | import org.hibernate.Transaction; 9 | import org.hibernate.cfg.AnnotationConfiguration; 10 | 11 | public class DBOperation { 12 | 13 | static AnnotationConfiguration annotationConfiguration; 14 | static SessionFactory sessionFactory; 15 | Session session; 16 | Transaction transaction; 17 | Query query; 18 | List list; 19 | 20 | static { 21 | annotationConfiguration = new AnnotationConfiguration(); 22 | annotationConfiguration.configure("hibernate.cfg.xml"); 23 | sessionFactory = annotationConfiguration.buildSessionFactory(); 24 | } 25 | 26 | public List getListByParams(String hqlQuery, String[] paramNames, String[] paramValues) { 27 | query = session.createQuery(hqlQuery); 28 | if(paramNames.length == paramValues.length) 29 | { 30 | for(int i=0;iMy Python Examples 2 |
Here is more detailed information about scripts I have written. I create these little programs as experiments to play with the language, 3 | or to solve problems for myself. I would gladly accept pointers from others to improve the code and make it more efficient, 4 | or simplify the code. If you would like to make any comments then please feel free to email me at jaimin.jp99@gmail.com 5 | These scripts are very important functions which help reduce the workload on people. In the scripts the comments and other documents are lined up correctly 6 | 7 |

Enjoy!!

8 | -------------------------------------------------------------------------------- /appending_to_files.py: -------------------------------------------------------------------------------- 1 | appendMe = '\nNew bit of information' 2 | 3 | appendFile = open('example.txt','a') 4 | appendFile.write(appendMe) 5 | appendFile.close() 6 | -------------------------------------------------------------------------------- /built_in_functions.py: -------------------------------------------------------------------------------- 1 | import math #this is just becouse i used math down below 2 | exNum1 = -5 3 | exNum2 = 5 4 | 5 | print(abs(exNum1)) #absolute function 6 | 7 | if abs(exNum1) == exNum2: 8 | print('these are the same') 9 | 10 | exList = [1,2,3,4,5,6,7,8,9,10,11] 11 | 12 | print(max(exList)) 13 | print(min(exList)) 14 | 15 | intMe = '55' #take it as a string 16 | print(intMe) 17 | print(int(intMe)) 18 | print(float(intMe)) 19 | 20 | strMe = 77 21 | print(str(strMe)) 22 | x = 5.622 23 | print(round(x)) 24 | 25 | print(math.floor(x)) 26 | print(math.ceil(x)) 27 | -------------------------------------------------------------------------------- /cal.py: -------------------------------------------------------------------------------- 1 | class calculator: 2 | def add(x,y): 3 | ans = x + y 4 | print(ans) 5 | 6 | def sub(x,y): 7 | ans = x - y 8 | print(ans) 9 | 10 | def mul(x,y): 11 | ans = x * y 12 | print(ans) 13 | 14 | def div(x,y): 15 | ans = x / y 16 | print(ans) 17 | 18 | calculator.mul(5,9) 19 | -------------------------------------------------------------------------------- /class_py.py: -------------------------------------------------------------------------------- 1 | class calculator: 2 | def addition(x,y): 3 | added = x + y 4 | print(added) 5 | def substraction(x,y): 6 | sub = x - y 7 | print(sub) 8 | def multiplication(x,y): 9 | mult = x * y 10 | print(mult) 11 | def division(x,y): 12 | div = x / y 13 | print(div) 14 | 15 | calculator.addition(4,6) 16 | calculator.substraction(4,6) 17 | calculator.multiplication(4,6) 18 | calculator.division(4,6) 19 | -------------------------------------------------------------------------------- /cx_freeze_python_to_exe.py: -------------------------------------------------------------------------------- 1 | import urllib.request 2 | import urllib.parse 3 | import re 4 | import time 5 | 6 | 7 | url = 'http://pythonprogramming.net' 8 | values = {'s' : 'basics', 9 | 'submit' : 'search'} 10 | 11 | data = urllib.parse.urlencode(values) 12 | data = data.encode('utf-8') # data should be bytes 13 | req = urllib.request.Request(url, data) 14 | resp = urllib.request.urlopen(req) 15 | respData = resp.read() 16 | 17 | paragraphs = re.findall(r'

(.*?)

',str(respData)) 18 | 19 | for eachParagraph in paragraphs: 20 | print(eachParagraph) 21 | 22 | time.sleep(15) 23 | -------------------------------------------------------------------------------- /cx_setup.py: -------------------------------------------------------------------------------- 1 | from cx_Freeze import setup, Executable 2 | 3 | setup(name='UrlParse', 4 | version='0.1', 5 | description='Parse stuff', 6 | executables = [Executable("cx_freeze_python_to_exe.py")]) 7 | -------------------------------------------------------------------------------- /dictionaries.py: -------------------------------------------------------------------------------- 1 | exDict = {'Jaimin':[20, 'black'], 'Ajay':[18,'blonde'], 'Jack':[22,'pink']} 2 | print(exDict) 3 | print(exDict['Jaimin']) 4 | print(exDict['Jaimin'][1]) 5 | 6 | exDict['Tim'] = 14 7 | 8 | print(exDict) 9 | 10 | exDict['Tim'] = 15 11 | 12 | print(exDict) 13 | 14 | del exDict['Tim'] 15 | 16 | print(exDict) 17 | -------------------------------------------------------------------------------- /eval_py.py: -------------------------------------------------------------------------------- 1 | list_str = "[5,6,2,1,2]" 2 | list_str = eval(list_str) 3 | print(list_str) 4 | print(list_str[2]) 5 | 6 | x = input("code :") 7 | y = eval(input("code")) 8 | 9 | print(y) 10 | -------------------------------------------------------------------------------- /example.txt: -------------------------------------------------------------------------------- 1 | Sample Text to save 2 | New Line! 3 | New bit of information -------------------------------------------------------------------------------- /example1.txt: -------------------------------------------------------------------------------- 1 | 1,8 2 | 2,9 3 | 3,7 4 | 4,5 5 | 5,6 6 | 6,7 7 | 7,2 8 | 8,1 9 | 9,6 10 | 10,7 11 | -------------------------------------------------------------------------------- /examples.csv: -------------------------------------------------------------------------------- 1 | 1/2/2017,5,8,red 2 | 1/3/2018,6,88,green 3 | 1/3/2008,7,8,black 4 | -------------------------------------------------------------------------------- /exec_py.py: -------------------------------------------------------------------------------- 1 | exec("print('this works like eval')") 2 | list_str = "[5,2,1,5]" 3 | list_str = exec(list_str) 4 | print(list_str) 5 | 6 | exec("list_str2 = [5,6,4,5]") 7 | print(list_str2) 8 | 9 | exec("def test(): print('yo!')") 10 | test() 11 | 12 | exec(""" 13 | def test2(): 14 | print('Yo this works too') 15 | 16 | """) 17 | test2() 18 | -------------------------------------------------------------------------------- /for_loop.py: -------------------------------------------------------------------------------- 1 | exampleList = [1,2,3,4,5,6,7,8,9,10] 2 | 3 | for eachItem in exampleList: 4 | print(eachItem) 5 | print('Continue Program') # By doing tab it will take it as in for loop so the string will be printed after every single number. 6 | 7 | print('Finish Program') # This string is not tabbed so it will take it as out of the for loop so it will be printed last and only for once. 8 | 9 | 10 | for x in range(1,11): 11 | print(x) 12 | -------------------------------------------------------------------------------- /ftplib_py.py: -------------------------------------------------------------------------------- 1 | # this program has no error but you have to place actual domain name and password in order to access all the things. 2 | 3 | from ftplib import FTP 4 | 5 | ftp = FTP('domainname.com') 6 | ftp.login(user='username',passwd='password') 7 | ftp.cwd('/specificdomain-ro-location/') 8 | 9 | def grabFile(): 10 | fileName = 'fileName.txt' 11 | localfile = open(filename, 'wb') 12 | ftp.retrbinary('RETR ' + filename, localfile.write, 1024) 13 | ftp.quit() 14 | localfile.close() 15 | 16 | def placeFile(): 17 | fileName = 'fileName.txt' 18 | ftp.storbinary('STOR '+filename, open(filename, 'rb')) 19 | ftp.quit() 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /function.py: -------------------------------------------------------------------------------- 1 | def example(): # def is a keyword to create any function. 2 | print('Basic funtion') 3 | z = 3+9 4 | print(z) 5 | 6 | example() 7 | -------------------------------------------------------------------------------- /function_with_parameter.py: -------------------------------------------------------------------------------- 1 | def simple_addition(num1,num2): # here num1 and num2 are two different parameters. 2 | print('Number 1 is', num1) 3 | print('Number 2 is', num2) 4 | answer = num1+num2 5 | print('Addition is' , answer) 6 | simple_addition(5,6) 7 | simple_addition(num2=6,num1=5) 8 | -------------------------------------------------------------------------------- /function_with_parameter_default.py: -------------------------------------------------------------------------------- 1 | def basic_window(width,height,font='TNR',bgc='w',scrollbar=True): # the values that are already define here are known as default values. 2 | print(width,height,font,bgc) 3 | 4 | basic_window(500,350) 5 | -------------------------------------------------------------------------------- /getting_user_input.py: -------------------------------------------------------------------------------- 1 | x = input('What is your name? ') 2 | print('Hello', x) 3 | -------------------------------------------------------------------------------- /global_and_local_variables.py: -------------------------------------------------------------------------------- 1 | x = 6 2 | 3 | def example(): 4 | global x 5 | print(x) 6 | x+=5 7 | print(x) 8 | example() 9 | 10 | def example2(): 11 | globx = x 12 | print(globx) 13 | globx += 5 14 | print(globx) 15 | return globx 16 | x = example2() 17 | print(x) 18 | -------------------------------------------------------------------------------- /hibernate.cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | com.mysql.jdbc.Driver 7 | 8 | jdbc:mysql://localhost:3306/aquazen-crm 9 | root 10 | root 11 | 12 | 15 | 16 | 11 17 | org.hibernate.dialect.MySQLDialect 18 | true 19 | true 20 | true 21 | true 22 | update 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /if_elif.py: -------------------------------------------------------------------------------- 1 | x = 6 2 | y = 10 3 | z = 22 4 | 5 | if x > y: 6 | print(x, ' is greter than ' ,y) 7 | elif x > z: 8 | print(x, ' is greter than ' ,z) 9 | elif y == x: 10 | print(y, ' is greter than ' ,x) 11 | elif y > z: 12 | print(y, ' is greter than ' ,z) 13 | else: 14 | print(z, ' is greter than' ,x ,'and' ,y) 15 | -------------------------------------------------------------------------------- /if_else.py: -------------------------------------------------------------------------------- 1 | x = 5 2 | y = 6 3 | z = 5 4 | a = 3 5 | if x > y: 6 | print(x, ' is greater than ', y) 7 | else: 8 | print(y, ' is greater than ', x) 9 | 10 | 11 | if z < y > x > a: 12 | print('y is greater than x,z and also a') 13 | 14 | if z == x: # for equal statement we have to user double = 15 | print('z is equal to x') 16 | -------------------------------------------------------------------------------- /input.py: -------------------------------------------------------------------------------- 1 | x = input('What is your name? ') 2 | print('Hello',x) 3 | 4 | -------------------------------------------------------------------------------- /list_manipulation.py: -------------------------------------------------------------------------------- 1 | x = [3,4,5,6,7,8,9,0,4,8,6,8] # This is the fucking list. 2 | print(x) 3 | x.append(2) # will add 2 at the end of the list. 4 | print(x) 5 | x.insert(2,88) # will insert 88 at the 2nd position. 6 | print(x) 7 | x.remove(88) # will remove 88 from the list. 8 | print(x) 9 | x.remove(x[4]) # will remove the 4th element from the list. 10 | print(x) 11 | print(x[3]) # will print the 3rd element. 12 | print(x[3:7]) # will print from 3rd to 7th element. 13 | print(x[-1]) # will print last element from the list. 14 | print(x.index(0)) # will print the index value of 0. 15 | print(x.count(8)) # it will count that how many time 8 occurs in the list. 16 | x.sort() # this will sort the values from ascending to descending order. 17 | print(x) 18 | 19 | y = ['Zayn','Daniel','Jaimin','Ajay','Emma','Mango'] 20 | y.sort() # This will sort alphabetically. 21 | print(y) 22 | -------------------------------------------------------------------------------- /lists_and_tuples.py: -------------------------------------------------------------------------------- 1 | x = 3,4,5,6 #This is tuple. 2 | # x = (3,4,5,6) This is also fucking tuple. 3 | 4 | y = [3,4,5,6] #But this my friend is a list. 5 | 6 | print(x[1]) 7 | print(y[2],y[3]) 8 | -------------------------------------------------------------------------------- /makemodule.py: -------------------------------------------------------------------------------- 1 | def ex(data): 2 | print(data) 3 | -------------------------------------------------------------------------------- /math_py.py: -------------------------------------------------------------------------------- 1 | # Single Line Comment 2 | ''' 3 | Double line 4 | comments 5 | in 6 | python 7 | 8 | ''' 9 | print('hi') 10 | print(1+6) 11 | print(1-1) 12 | print(64*4) 13 | print(4**4) # Power if 4 means 4*4*4*4 14 | -------------------------------------------------------------------------------- /matplotlib_py.py: -------------------------------------------------------------------------------- 1 | from matplotlib import pyplot as plt 2 | 3 | x = [5,6,7,8] 4 | y = [7,3,8,3] 5 | 6 | print(len(x)) 7 | print(len(y)) 8 | 9 | plt.plot(x,y) 10 | 11 | plt.title('Epic Chart') 12 | plt.ylabel('Y axis') 13 | plt.xlabel('X axis') 14 | 15 | plt.show() 16 | -------------------------------------------------------------------------------- /multi_dimensional_list.py: -------------------------------------------------------------------------------- 1 | x = [[5,7],[3,5],[4,6],[3,7]] 2 | 3 | print(x) 4 | print(x[1]) 5 | print(x[1][0]) 6 | -------------------------------------------------------------------------------- /multiline_print.py: -------------------------------------------------------------------------------- 1 | print(''' 2 | so this is a simple 3 | milti-line 4 | print 5 | ================= 6 | | | 7 | | | 8 | | Box | 9 | | | 10 | | | 11 | ================= 12 | ''') 13 | -------------------------------------------------------------------------------- /os_module.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | curDir = os.getcwd() 4 | print(curDir) 5 | 6 | os.mkdir('newDir') 7 | 8 | import time 9 | 10 | time.sleep(2) 11 | 12 | os.rename('newDir','newDir2') 13 | time.sleep(2) 14 | 15 | os.rmdir('newDir2') 16 | -------------------------------------------------------------------------------- /p1.py: -------------------------------------------------------------------------------- 1 | a=int(input("enter fucking value :")) 2 | b=int(input("enter another fucking value :")) 3 | c=a+b 4 | print(c) 5 | -------------------------------------------------------------------------------- /parsing_website_with_re_and_urllib.py: -------------------------------------------------------------------------------- 1 | import urllib.request 2 | import urllib.parse 3 | import re 4 | 5 | url = 'http://pythonprogramming.net' 6 | values= {'s':'basics', 7 | 'submit':'search'} 8 | data = urllib.parse.urlencode(values) 9 | data = data.encode('utf-8') 10 | req = urllib.request.Request(url, data) 11 | resp = urllib.request.urlopen(req) 12 | respData = resp.read() 13 | 14 | #print(respData) 15 | 16 | paragraphs = re.findall(r'(.*?)', str(respData)) 17 | 18 | for eachP in paragraphs: 19 | print(eachP) 20 | 21 | -------------------------------------------------------------------------------- /pic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spider-yamet/Python/321c9001663235b348dd91cfa8e4e5f6f3985799/pic.jpg -------------------------------------------------------------------------------- /pickle_py.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | ''' 3 | example_dict = {1:"6",2:"2",3:"f"} 4 | 5 | pickle_out = open("dict.pickle","wb") 6 | pickle.dump(example_dict, pickle_out) 7 | pickle_out.close() 8 | ''' 9 | pickle_in = open("dict.pickle","rb") 10 | example_dict = pickle.load(pickle_in) 11 | 12 | print(example_dict) 13 | print(example_dict[2]) 14 | -------------------------------------------------------------------------------- /print_funtion.py: -------------------------------------------------------------------------------- 1 | print('This is an example of print function') 2 | print('We\'re going to the store') 3 | print('Hi','there') 4 | print('Hi',5) 5 | print('Hi'+ str(5)) 6 | print(int('8')+5) 7 | print(float('8.5')+5) 8 | -------------------------------------------------------------------------------- /read_to_files.py: -------------------------------------------------------------------------------- 1 | readMe = open('example.txt','r').readlines() 2 | readsMe = open('example.txt','r').read() 3 | print(readMe) 4 | print(readsMe) 5 | -------------------------------------------------------------------------------- /reading_from_CSV_spreadsheet.py: -------------------------------------------------------------------------------- 1 | import csv #comma saperated variables 2 | 3 | with open('examples.csv') as csvfile: 4 | readCSV = csv.reader(csvfile, delimiter=',') 5 | 6 | dates= [] 7 | colors = [] 8 | 9 | for row in readCSV: 10 | color = row[3] 11 | date = row[0] 12 | 13 | dates.append(date) 14 | colors.append(color) 15 | 16 | print(dates) 17 | print(colors) 18 | 19 | try: 20 | whatColor = input('What color do you wish to know the date of?') 21 | 22 | if whatColor in colors: 23 | coldex = colors.index(whatColor.lower()) 24 | 25 | theDate = dates[coldex] 26 | 27 | print('The date of',whatColor,'is :',theDate) 28 | else: 29 | print('Color not found') 30 | except Exception as e: 31 | print(e) 32 | 33 | print('Continuing') 34 | -------------------------------------------------------------------------------- /regular_expression.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Identifiers: 3 | \d : any number 4 | \D : anything but a number 5 | \s : space 6 | \S : anything but a space 7 | \w : any character 8 | \W : anything but a character 9 | . : any character, except for a newline 10 | \b : the whitespace around words 11 | \. : a period 12 | 13 | Modifiers : 14 | {1,3} : we're expecting 1-3 15 | + : match 1 or more 16 | ? : match 0 or 1 17 | * : match 0 or more 18 | $ : match the end of a string 19 | ^ : match the beginning of a string 20 | | : either or 21 | [] : range or "variance" 22 | {x} : expecting "x" amount 23 | 24 | White Space Character: 25 | \n : new line 26 | \s : space 27 | \t : tab 28 | \e : escape 29 | \f : form feed 30 | \r : return 31 | 32 | DONT FORGET! : 33 | . + * ? [ ] $ ^ ( ) { } | \ 34 | ''' 35 | 36 | 37 | import re 38 | 39 | exampleString = ''' 40 | Ajay is 18 years old, and Jaimin is 20 years old. 41 | Edward is 97, and his grandfather, Oscar, is 102. 42 | ''' 43 | 44 | ages = re.findall(r'\d{1,3}',exampleString) 45 | names = re.findall(r'[A-Z][a-z]*',exampleString) 46 | 47 | print(ages) 48 | print(names) 49 | 50 | ageDict = {} 51 | x=0 52 | for eachName in names: 53 | ageDict[eachName] = ages[x] 54 | x+=1 55 | 56 | print(ageDict) 57 | -------------------------------------------------------------------------------- /socket_binding_listening.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import sys 3 | from _thread import * 4 | host = '' 5 | port = 5555 6 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 7 | 8 | try: 9 | s.bind((host, port)) 10 | except socket.error as e: 11 | print(str(e)) 12 | 13 | s.listen(5) 14 | 15 | def threaded_client(conn): 16 | conn.send(str.encode('Welcome, type your info\n')) 17 | 18 | while True: 19 | data = conn.recv(2048) 20 | reply = 'Server output: ' + data.decode('utf-8') 21 | if not data: 22 | break 23 | conn.sendall(str.encode(reply)) 24 | conn.close() 25 | 26 | while True: 27 | conn, addr = s.accept() 28 | print('Connected to :'+addr[0]+':'+str(addr[1])) 29 | start_new_thread(threaded_client,(conn,)) 30 | -------------------------------------------------------------------------------- /sockets_py.py: -------------------------------------------------------------------------------- 1 | import socket 2 | import threading 3 | from queue import Queue 4 | 5 | print_lock = threading.Lock() 6 | 7 | target = 'pythonprogramming.net' 8 | 9 | def portscan(port): 10 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 11 | try: 12 | con = s.connect((target,port)) 13 | with print_Lock: 14 | print('port',port,'is open') 15 | con.close() 16 | except: 17 | pass 18 | 19 | def threader(): 20 | while True: 21 | worker = q.get() 22 | portscan(worker) 23 | q.task_done() 24 | 25 | q = Queue() 26 | 27 | for x in range(30): 28 | t = threading.Thread(target=threader) 29 | t.daemon = True 30 | t.start() 31 | 32 | for worker in range(1,101): 33 | q.put(worker) 34 | 35 | q.join() 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /sqlite3_py.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import time 3 | import datetime 4 | import random 5 | import matplotlib.pyplot as plt 6 | import matplotlib.dates as mdates 7 | from matplotlib import style 8 | 9 | style.use('fivethirtyeight') 10 | 11 | conn = sqlite3.connect('tutorial.db') 12 | c = conn.cursor() 13 | 14 | def create_table(): 15 | c.execute('CREATE TABLE IF NOT EXISTS stuff(unix REAL, datestamp TEXT, keyword TEXT, value REAL)') 16 | 17 | def data_entry(): 18 | c.execute("INSERT INTO stuff VALUES(1545678, '2018-01-01', 'Python', 5)") 19 | conn.commit() 20 | c.close() 21 | conn.close() 22 | 23 | def dynamic_data_entry(): 24 | unix = time.time() 25 | date = str(datetime.datetime.fromtimestamp(unix).strftime('%Y-%m-%d %H:%M:%S')) 26 | keyword = 'python' 27 | value = random.randrange(0,10) 28 | c.execute("INSERT INTO stuff (unix, datestamp, keyword, value) VALUES (?, ?, ?, ?)", 29 | (unix, date, keyword, value)) 30 | conn.commit() 31 | 32 | def read_from_db(): 33 | c.execute("SELECT * FROM stuff WHERE value>1 AND keyword='python'") 34 | #data = c.fetchall() 35 | #print(data) 36 | for row in c.fetchall(): 37 | print(row) 38 | 39 | def graph_data(): 40 | c.execute("SELECT unix, value FROM stuff") 41 | dates = [] 42 | values = [] 43 | for row in c.fetchall(): 44 | #print(row[0]) 45 | #print(datetime.datetime.fromtimestamp(row[0])) 46 | dates.append(datetime.datetime.fromtimestamp(row[0])) 47 | values.append(row[1]) 48 | plt.plot_date(dates, values, '-') 49 | plt.show() 50 | 51 | def del_and_update(): 52 | c.execute("SELECT * FROM stuff") 53 | [print(row) for row in c.fetchall()] 54 | 55 | ## c.execute("UPDATE stuff SET value = 99 WHERE value = 1") 56 | ## conn.commit() 57 | ## 58 | ## c.execute("SELECT * FROM stuff") 59 | ## [print(row) for row in c.fetchall()] 60 | 61 | ## c.execute("DELETE FROM stuff WHERE value = 99 ") 62 | ## conn.commit() 63 | ## print(50*'#') 64 | c.execute("SELECT * FROM stuff") 65 | [print(row) for row in c.fetchall()] 66 | c.execute("SELECT * FROM stuff WHERE value = 9") 67 | print(len(c.fetchall())) 68 | 69 | ##create_table() 70 | ##data_entry() 71 | ##for i in range(10): 72 | ## dynamic_data_entry() 73 | ## time.sleep(1) 74 | ##read_from_db() 75 | #graph_data() 76 | del_and_update() 77 | c.close() 78 | conn.close() 79 | -------------------------------------------------------------------------------- /statistics_py.py: -------------------------------------------------------------------------------- 1 | import statistics 2 | 3 | example_list = [4,2,3,4,5,6,6,3,3,2,3,5,5,3,3] 4 | 5 | x = statistics.mean(example_list) 6 | y = statistics.median(example_list) 7 | z = statistics.mode(example_list) 8 | a = statistics.stdev(example_list) 9 | b = statistics.variance(example_list) 10 | 11 | print(x) 12 | print(y) 13 | print(z) 14 | print(a) 15 | print(b) 16 | -------------------------------------------------------------------------------- /sys_module.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | sys.stderr.write('This is stderr text\n') 4 | sys.stderr.flush() 5 | sys.stdout.write('This is stdout text\n') 6 | 7 | print(sys.argv) 8 | 9 | if len(sys.argv) > 1: 10 | print(sys.argv[1]) 11 | -------------------------------------------------------------------------------- /threading_module.py: -------------------------------------------------------------------------------- 1 | import threading 2 | from queue import Queue 3 | import time 4 | 5 | print_lock = threading.Lock() 6 | 7 | def exampleJob(worker): 8 | time.sleep(0.5) 9 | 10 | with print_lock: 11 | print(threading.current_thread().name, worker) 12 | 13 | def threader(): 14 | while True: 15 | worker = q.get() 16 | exampleJob(worker) 17 | q.task_done() 18 | 19 | q = Queue() 20 | 21 | for x in range(10): 22 | t = threading.Thread(target = threader) 23 | t.daemon = True 24 | t.start() 25 | 26 | start = time.time() 27 | 28 | for worker in range(20): 29 | q.put(worker) 30 | 31 | q.join() 32 | 33 | print('Entire job took:',time.time()-start) 34 | -------------------------------------------------------------------------------- /tkinter_adding_button.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | class Window(Frame): 4 | 5 | def __init__(self, master = None): 6 | Frame.__init__(self, master) 7 | 8 | self.master = master 9 | 10 | self.init_window() 11 | 12 | def init_window(self): 13 | 14 | self.master.title("GUI") 15 | 16 | self.pack(fill=BOTH, expand=1) 17 | 18 | quitButton = Button(self, text="Quit", command=self.client_exit) 19 | 20 | quitButton.place(x=0, y=0) 21 | 22 | def client_exit(self): 23 | exit() 24 | 25 | root = Tk() 26 | root.geometry("400x300") 27 | 28 | app = Window(root) 29 | 30 | root.mainloop() 31 | -------------------------------------------------------------------------------- /tkinter_adding_images_and_text.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | from PIL import Image, ImageTk 4 | 5 | class Window(Frame): 6 | 7 | def __init__(self, master = None): 8 | Frame.__init__(self, master) 9 | 10 | self.master = master 11 | 12 | self.init_window() 13 | 14 | def init_window(self): 15 | 16 | self.master.title("GUI") 17 | 18 | self.pack(fill=BOTH, expand=1) 19 | 20 | #quitButton = Button(self, text="Quit", command=self.client_exit) 21 | #quitButton.place(x=0, y=0) 22 | 23 | menu = Menu(self.master) 24 | self.master.config(menu=menu) 25 | 26 | file = Menu(menu) 27 | file.add_command(label='New File') 28 | file.add_command(label='Open') 29 | file.add_command(label='Save') 30 | file.add_command(label='Save as') 31 | file.add_command(label='Print Windows') 32 | file.add_command(label='Exit', command=self.client_exit) 33 | menu.add_cascade(label='File', menu=file) 34 | 35 | edit = Menu(menu) 36 | edit.add_command(label='Show Image', command=self.showImg) 37 | edit.add_command(label='Show Text', command=self.showTxt) 38 | edit.add_command(label='Undo') 39 | edit.add_command(label='Redo') 40 | edit.add_command(label='Cut') 41 | edit.add_command(label='Copy') 42 | edit.add_command(label='Paste') 43 | edit.add_command(label='Select All') 44 | edit.add_command(label='Find') 45 | menu.add_cascade(label='Edit', menu=edit) 46 | 47 | formatt = Menu(menu) 48 | formatt.add_command(label='Toggle Tabs') 49 | formatt.add_command(label='Indent Region') 50 | formatt.add_command(label='Dedent Region') 51 | formatt.add_command(label='Format Paragraph') 52 | formatt.add_command(label='New Indent') 53 | menu.add_cascade(label='Format', menu=formatt) 54 | 55 | run = Menu(menu) 56 | run.add_command(label='Python Shell') 57 | run.add_command(label='Rub Module') 58 | run.add_command(label='Check Module') 59 | menu.add_cascade(label='Run', menu=run) 60 | 61 | options = Menu(menu) 62 | options.add_command(label='Configure IDLE') 63 | options.add_command(label='Code Context') 64 | menu.add_cascade(label='Options', menu=options) 65 | 66 | window = Menu(menu) 67 | window.add_command(label='Zoom') 68 | menu.add_cascade(label='Window', menu=window) 69 | 70 | helps = Menu(menu) 71 | helps.add_command(label='About IDLE') 72 | helps.add_command(label='IDLE Help') 73 | helps.add_command(label='Python Docs') 74 | helps.add_command(label='Turtle Demp') 75 | menu.add_cascade(label='Help', menu=helps) 76 | 77 | def showImg(self): 78 | load = Image.open('pic.jpg') 79 | render = ImageTk.PhotoImage(load) 80 | 81 | img = Label(self, image=render) 82 | img.image = render 83 | img.place(x=0,y=0) 84 | 85 | def showTxt(self): 86 | text = Label(self, text='Hey it is awesome!') 87 | text.pack() 88 | def client_exit(self): 89 | exit() 90 | 91 | root = Tk() 92 | root.geometry("400x300") 93 | 94 | app = Window(root) 95 | 96 | root.mainloop() 97 | -------------------------------------------------------------------------------- /tkinter_exe.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | from PIL import Image, ImageTk 4 | 5 | class Window(Frame): 6 | 7 | def __init__(self, master = None): 8 | Frame.__init__(self, master) 9 | 10 | self.master = master 11 | 12 | self.init_window() 13 | 14 | def init_window(self): 15 | 16 | self.master.title("GUI") 17 | 18 | self.pack(fill=BOTH, expand=1) 19 | 20 | #quitButton = Button(self, text="Quit", command=self.client_exit) 21 | #quitButton.place(x=0, y=0) 22 | 23 | menu = Menu(self.master) 24 | self.master.config(menu=menu) 25 | 26 | file = Menu(menu) 27 | file.add_command(label='New File') 28 | file.add_command(label='Open') 29 | file.add_command(label='Save') 30 | file.add_command(label='Save as') 31 | file.add_command(label='Print Windows') 32 | file.add_command(label='Exit', command=self.client_exit) 33 | menu.add_cascade(label='File', menu=file) 34 | 35 | edit = Menu(menu) 36 | edit.add_command(label='Show Image', command=self.showImg) 37 | edit.add_command(label='Show Text', command=self.showTxt) 38 | edit.add_command(label='Undo') 39 | edit.add_command(label='Redo') 40 | edit.add_command(label='Cut') 41 | edit.add_command(label='Copy') 42 | edit.add_command(label='Paste') 43 | edit.add_command(label='Select All') 44 | edit.add_command(label='Find') 45 | menu.add_cascade(label='Edit', menu=edit) 46 | 47 | formatt = Menu(menu) 48 | formatt.add_command(label='Toggle Tabs') 49 | formatt.add_command(label='Indent Region') 50 | formatt.add_command(label='Dedent Region') 51 | formatt.add_command(label='Format Paragraph') 52 | formatt.add_command(label='New Indent') 53 | menu.add_cascade(label='Format', menu=formatt) 54 | 55 | run = Menu(menu) 56 | run.add_command(label='Python Shell') 57 | run.add_command(label='Rub Module') 58 | run.add_command(label='Check Module') 59 | menu.add_cascade(label='Run', menu=run) 60 | 61 | options = Menu(menu) 62 | options.add_command(label='Configure IDLE') 63 | options.add_command(label='Code Context') 64 | menu.add_cascade(label='Options', menu=options) 65 | 66 | window = Menu(menu) 67 | window.add_command(label='Zoom') 68 | menu.add_cascade(label='Window', menu=window) 69 | 70 | helps = Menu(menu) 71 | helps.add_command(label='About IDLE') 72 | helps.add_command(label='IDLE Help') 73 | helps.add_command(label='Python Docs') 74 | helps.add_command(label='Turtle Demp') 75 | menu.add_cascade(label='Help', menu=helps) 76 | 77 | def showImg(self): 78 | load = Image.open('pic.jpg') 79 | render = ImageTk.PhotoImage(load) 80 | 81 | img = Label(self, image=render) 82 | img.image = render 83 | img.place(x=0,y=0) 84 | 85 | def showTxt(self): 86 | text = Label(self, text='Hey it is awesome!') 87 | text.pack() 88 | def client_exit(self): 89 | exit() 90 | 91 | root = Tk() 92 | root.geometry("400x300") 93 | 94 | app = Window(root) 95 | 96 | root.mainloop() 97 | -------------------------------------------------------------------------------- /tkinter_menu_bar.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | class Window(Frame): 4 | 5 | def __init__(self, master = None): 6 | Frame.__init__(self, master) 7 | 8 | self.master = master 9 | 10 | self.init_window() 11 | 12 | def init_window(self): 13 | 14 | self.master.title("GUI") 15 | 16 | self.pack(fill=BOTH, expand=1) 17 | 18 | #quitButton = Button(self, text="Quit", command=self.client_exit) 19 | #quitButton.place(x=0, y=0) 20 | 21 | menu = Menu(self.master) 22 | self.master.config(menu=menu) 23 | 24 | file = Menu(menu) 25 | file.add_command(label='New File') 26 | file.add_command(label='Open') 27 | file.add_command(label='Save') 28 | file.add_command(label='Save as') 29 | file.add_command(label='Print Windows') 30 | file.add_command(label='Exit', command=self.client_exit) 31 | menu.add_cascade(label='File', menu=file) 32 | 33 | edit = Menu(menu) 34 | edit.add_command(label='Undo') 35 | edit.add_command(label='Redo') 36 | edit.add_command(label='Cut') 37 | edit.add_command(label='Copy') 38 | edit.add_command(label='Paste') 39 | edit.add_command(label='Select All') 40 | edit.add_command(label='Find') 41 | menu.add_cascade(label='Edit', menu=edit) 42 | 43 | formatt = Menu(menu) 44 | formatt.add_command(label='Toggle Tabs') 45 | formatt.add_command(label='Indent Region') 46 | formatt.add_command(label='Dedent Region') 47 | formatt.add_command(label='Format Paragraph') 48 | formatt.add_command(label='New Indent') 49 | menu.add_cascade(label='Format', menu=formatt) 50 | 51 | run = Menu(menu) 52 | run.add_command(label='Python Shell') 53 | run.add_command(label='Rub Module') 54 | run.add_command(label='Check Module') 55 | menu.add_cascade(label='Run', menu=run) 56 | 57 | options = Menu(menu) 58 | options.add_command(label='Configure IDLE') 59 | options.add_command(label='Code Context') 60 | menu.add_cascade(label='Options', menu=options) 61 | 62 | window = Menu(menu) 63 | window.add_command(label='Zoom') 64 | menu.add_cascade(label='Window', menu=window) 65 | 66 | helps = Menu(menu) 67 | helps.add_command(label='About IDLE') 68 | helps.add_command(label='IDLE Help') 69 | helps.add_command(label='Python Docs') 70 | helps.add_command(label='Turtle Demp') 71 | menu.add_cascade(label='Help', menu=helps) 72 | 73 | 74 | 75 | def client_exit(self): 76 | exit() 77 | 78 | root = Tk() 79 | root.geometry("400x300") 80 | 81 | app = Window(root) 82 | 83 | root.mainloop() 84 | -------------------------------------------------------------------------------- /tkinter_module_making_windows.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | 3 | class Window(Frame): 4 | 5 | def __init__(self, master = None): 6 | Frame.__init__(self, master) 7 | 8 | self.master = master 9 | 10 | 11 | root = Tk() 12 | 13 | app = Window(root) 14 | 15 | root.mainloop() 16 | -------------------------------------------------------------------------------- /tkinter_setup.py: -------------------------------------------------------------------------------- 1 | from cx_Freeze import setup, Executable 2 | 3 | setup(name='Menu', 4 | version='0.1', 5 | description='Faltu', 6 | executables = [Executable("tkinter_exe.py")]) 7 | -------------------------------------------------------------------------------- /tutorial.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spider-yamet/Python/321c9001663235b348dd91cfa8e4e5f6f3985799/tutorial.db -------------------------------------------------------------------------------- /urllib_module.py: -------------------------------------------------------------------------------- 1 | import urllib.request 2 | import urllib.parse 3 | 4 | #x = urllib.request.urlopen('https://www.google.com') 5 | #print(x.read()) 6 | ''' 7 | url = 'http://pythonprogramming.net' 8 | values = {'s':'basic','submit':'search'} 9 | 10 | data = urllib.parse.urlencode(values) 11 | data = data.encode('utf-8') 12 | req = urllib.request.Request(url,data) 13 | resp = urllib.request.urlopen(req) 14 | respData = resp.read() 15 | 16 | print(respData) 17 | ''' 18 | 19 | try: 20 | x = urllib.request.urlopen('https://www.google.com/search?q=test') 21 | print(x.read()) 22 | 23 | except Exception as e: 24 | print(str(e)) 25 | 26 | try: 27 | url = 'https://www.google.com/search?q=test' 28 | 29 | headers = {} 30 | headers['User-Agent'] = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.27 Safari/537.17" 31 | req = urllib.request.Request(url, headers = headers) 32 | resp = urllib.request.urlopen(req) 33 | respData = resp.read() 34 | 35 | saveFile = open('withHeaders.txt','w') 36 | saveFile.write(str(respData)) 37 | saveFile.close() 38 | except Exception as e: 39 | print(str(e)) 40 | -------------------------------------------------------------------------------- /usemodule.py: -------------------------------------------------------------------------------- 1 | import makemodule 2 | 3 | makemodule.ex('test') 4 | -------------------------------------------------------------------------------- /variables.py: -------------------------------------------------------------------------------- 1 | exampleVar = 55 2 | print(exampleVar) 3 | 4 | exampleVar1 = print('Print function within variable') 5 | 6 | x,y = (10,5) # Here it will take 10 as x and 5 as y. Multiple variables at a time and it must be equal otherwise it will give you and error. 7 | print(x) 8 | print(y) 9 | -------------------------------------------------------------------------------- /vcruntime140.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spider-yamet/Python/321c9001663235b348dd91cfa8e4e5f6f3985799/vcruntime140.dll -------------------------------------------------------------------------------- /while_loop.py: -------------------------------------------------------------------------------- 1 | number = 1 2 | while number < 10: # This ":" sign need to run while and other if else or for loop. 3 | print(number) 4 | number += 1 # it will add + 1 to that number variable so it will print till 9 and stop becouse we did less than 10 5 | -------------------------------------------------------------------------------- /writing_to_file.py: -------------------------------------------------------------------------------- 1 | text = "Sample Text to save\n New Line!" 2 | 3 | saveFile = open("../../example.txt",'w') 4 | saveFile.write(text) 5 | saveFile.close() 6 | --------------------------------------------------------------------------------