Skip to content

Instantly share code, notes, and snippets.

View SahbiOuali13's full-sized avatar
🎯
Focusing

SahbiOuali SahbiOuali13

🎯
Focusing
  • Toulouse
View GitHub Profile
@SahbiOuali13
SahbiOuali13 / Custom configs for django.md
Last active September 25, 2022 09:07
# Necessary Modules: - AutoDocstring: Python Docstring Genearator ![](https://cdn.cacher.io/attachments/u/3d66b3pypor7b/9XS2q6pWmavgYBO4FSe-_h5PDfUggYK4/8r4krhuur.png) # Parameters: - Nice fonts: 'Cascadia code' ![](https://cdn.cacher.io/attachme

Lanch configuration to run a django server

  • Go to Run and Debug
  • Go to Add Configuration

  • Django

  • Add the way to your manage.py relatively to where your launched VS Code.
a = b = c = 5
@SahbiOuali13
SahbiOuali13 / is.py
Last active September 3, 2020 18:09
is function verifies is the variables here occupies the same memory placement and therefore the False == verifies is the twho variables have the same value and therefore the True.
a = [1, 2, 3]
b = [1, 2, 3]
print(a == b)
# True
print(a is b)
# False
@SahbiOuali13
SahbiOuali13 / Common_errors
Last active September 6, 2020 10:23
Most common error types in Python.
SyntaxErrors: Maj / Min errors, usage of reserved words
NameErrors : usage of undefined variable, etc.
TypeErrors : When you try to perform a function that doesn't take the right type of variable
SemanticErrors: The script doesn't return the wished result. Usage of debugger is adviced in order to comprehend programmer logic.
from random import randint, uniform, randrange
# Randint make inclusiv calls, 5 is here included. It calls integers in the intervall 1-5
a = randint(1,5)
# Uniforms is basically the same as Randint but call floats in the specified intervall
b = uniform(1,5)
# randrange makes exclusiv calls like range function, returns integers between 0 and 999 here, step can be specified
c = randrange (999)
d = randrange(5,999,2)
@SahbiOuali13
SahbiOuali13 / os_module.py
Last active September 6, 2020 16:15
- Add path to a specified folder in project. - Create new folder with argument exist_ok. - Remove a folder after checking if it exists.
# add path to a specified folder in project
import os
chemin = r"C:\Users\ouali\OneDrive\Bureau\Formations\Formation Python\la-formation-complete-python-master\test"
folder = os.path.join(chemin, "dossier")
print(folder)
# Create new folder, works fine if the folder already exists.
os.makedirs(folder, exist_ok=True)
import random
import os
# list all functions in a module
print(dir(os))
# get a description of the function, don't add the parenthesis!
help(random.randint)
fruit = "banana"
# length of a string
l = len(fruit)
# iterating through a string
for letter in fruit:
print(letter)
# checking if a string or a substring exists in another
print("anana" in fruit)
# comaparing maj and min
fruit_upper = 'BANANA'
@SahbiOuali13
SahbiOuali13 / strip.py
Last active September 20, 2020 09:12
Cleans a string from spaces and other characters.
greet = ' Hello Python '
>>greet.lstrip()
'Hello Python '
>>greet.rstrip()
' Hello Python'
>>greet.strip()
'Hello Python'
nom = ";,: olom',;:"
>>>print(nom.strip(";,: '"))
xfile = open('course.txt')
for line in xfile:
print(line)
# clean from spaces at end
xfile = open('course.txt')
for line in xfile:
line = line.rstrip()
print(line)