Skip to content

Instantly share code, notes, and snippets.

BLOCK_COLOURS = "purple", "lightgreen", "lightblue", "orange"
for n_block in range(8):
# stuff
colour = BLOCK_COLOURS[n_block % len(BLOCK_COLOURS)]
print(colour)
import itertools
BLOCK_COLOURS = "purple", "lightgreen", "lightblue", "orange"
colours = itertools.cycle(BLOCK_COLOURS)
for n_block in range(8):
colour = next(colours)
print(colour)
from __future__ import with_statement
import os, sys
import htmlentitydefs
import itertools
import operator
import posixpath
import re
import sgmllib
import tempfile
fizz = 5
buzz = 7
counter = 1
while counter <= 60:
fizz_num = counter % fizz
buzz_num = counter % buzz
if fizz_num == 0:
print("Fizz")
elif buzz_num == 0:
@tjguk
tjguk / first.py
Created November 18, 2018 17:23
first.py
name = input("Hi, what's your name?")
year = input("Hi " + name + " what year were you born in?")
month = input("What month were you born in?")
day = input("What day were you born in?")
age = 0
counter = 1
check = input("just making sure, you were born on " + day +"/"+ month +"/"+ year + " ,correct?")
if check == "yes":
print("Great!!")
@tjguk
tjguk / pr726.py
Created December 23, 2018 12:14
Explore https://github.com/mu-editor/mu/pull/726 in different environments
import os, sys
import site
def munged(text):
user_profile = os.environ['USERPROFILE'].lower()
return text.lower().replace(user_profile, "[user]")
with open("pr726.log", "w") as f:
f.write("CWD: %s\n" % munged(os.getcwd()))
f.write("File location: %s\n" % munged(__file__))
@tjguk
tjguk / testing.py
Created January 26, 2019 14:16
Kelston Test
import os, sys
print(sys.executable)
@tjguk
tjguk / desaturate.py
Created September 14, 2019 15:24
Changing the saturation of an image
#
# You nearly always just need to import Image
# from PIL(low) to do what you need
#
from PIL import Image
#
# It's convenient to import everything from colorzero
# so you don't have to put "colorzero." before everything
#
from colorzero import *
book_file = open("""bleak-house.txt""")
book_text = book_file.read()
print(book_text[:200])
words = book_text.lower().split()
print(words[:200])
input_word=input("Please enter a word: ").lower()
print(input_word)
print(len(words), "words")
if input_word in words:
print("Found it")
@tjguk
tjguk / venv-pythonpath.py
Created November 7, 2019 14:47
Removing PYTHONPATH from environment
import os, sys
import subprocess
## env = {}
## env['SystemRoot'] = os.environ['SystemRoot']
env = dict(os.environ)
del env['PYTHONPATH']
print(subprocess.run(["c:/temp/mu/yyy/scripts/python.exe", "-c", 'import sys; print(sys.path)'], stdout=subprocess.PIPE, env=env).stdout)
print(subprocess.run(["c:/temp/mu/yyy/scripts/python.exe", "-m", "pip", "freeze"], stdout=subprocess.PIPE, env=env).stdout)