Env files allow you to put your environment variables inside a file. You just create a new file called. env in your project and slap your variables in there on different lines. This env is used for storing your all id, password, keys all important credential so no on directly can get your data. Code Step 1: Create a virtual environment and make it active Step 2: pip install python-dotenv Step 3: Create a .env file Step 4: Create test.py in the same dir where you created .env file Now Check Code test.py from dotenv import load_dotenv load_dotenv() import os my_site = os.getenv("DOMAIN") print("Visit My website : {} ".format(my_site)) .env # a comment that will be ignored. DOMAIN= https://thepyuniverse.blogspot.com Now Run test.py Output: Visit My website : https://thepyuniverse.blogspot.com Screenshot : Quiz Level 1 Quiz Level 2 Request Me
Code Example # Create a Large file for Test Data Processing This below code will create 1.1GB .txt file import string from random import choice with open("large_data.txt", "w") as fp: i = 1 while i <= 1000000: word = (''.join( choice(string.ascii_uppercase + string.digits) for _ in range(10)) + "|" ) * 100 fp.write(word[:] + "\n") i += 1
Code Example # How to solve the Liner Equation using Python Example 1: [with Multiple variable] import numpy as np ''' 8x+3y−2z=9 −4x+7y+5z=15 3x+4y−12z=35 ''' A = np.array([[8, 3, -2], [-4, 7, 5], [3, 4, -12]]) b = np.array([9, 15, 35]) answer = np.linalg.solve(A, b) print(answer)
Comments
Post a Comment