This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import glob | |
| #list of csv files | |
| csv_files = glob.glob('*.csv') | |
| #read csv files into a list of dataframes | |
| df_list = [pd.read_csv(file) for file in csv_files] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pickle | |
| def save_dict(dict_to_save, file_path): | |
| with open(file_path, 'wb') as file: #write bytes | |
| pickle.dump(dict_to_save, file) | |
| def load_dict(file_path): | |
| with open(file_path, 'rb') as file: #read the binary data | |
| return pickle.load(file) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python3 | |
| #Find all files in a directory with required extension .py/.sh/.log/.txt | |
| import os | |
| req_path=input("Enter your directory path: ") | |
| #req_ex=input("Enter the required files extention .py/.sh/.log/.txt: ") | |
| if os.path.isfile(req_path): | |
| print(f"The given path {req_path} is a file. Please pass only directory path") | |
| else: | |
| all_f_ds=os.listdir(req_path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pywhatkit | |
| import datetime | |
| print(datetime.datetime.now()) | |
| # Send message to a contact | |
| phone_number = '+1784xxxxx' | |
| pywhatkit.sendwhatmsg(phone_number, message='Just ignore this message', | |
| time_hour=17, time_min=19, | |
| wait_time=10, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from bs4 import BeautifulSoup | |
| import requests | |
| rf = requests.get(url='https://subslikescript.com/movie/Titanic-120338') | |
| rf_text = rf.text | |
| my_soup = BeautifulSoup(rf_text, 'lxml') | |
| print(my_soup.prettify()) | |
| #find main article |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try: | |
| num = int(input('Enter Number: ')) | |
| print(num) | |
| except ValueError: | |
| print('Invalid Input') | |
| try: | |
| Value = 10/0 | |
| except: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Ask for a file then open file in read only mode anbd prints contents in console | |
| file1 = input('Enter file:') | |
| with open(file1) as f: | |
| print(f.read()) | |
| #Open file in read format then close file | |
| file2 = open("Myfile.txt", 'r') | |
| content = file2.read | |
| #check if readable | |
| print(file2.readable()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests as r | |
| url = 'https://jsonplaceholder.typicode.com/photos' | |
| response = r.get(url) | |
| #read data into a variable | |
| content = response.json() |