Showing posts from October, 2017

linking a css file in your flask python app

It took me a while sifting through stack overflow to find an answer that explained what you needed to make the css code work.

so,  the static file, put the css code in there....

then this bit goes in your html <link> in your top header  ::

<linkrel="stylesheet"type="text/css"href="{{url_for('static', filename = 'styles/style.css')}}">
I guess I wasn't getting what the code did or what was code and what was instructions. the href that is up there is the one I have typed in to make my code work. It's not instructional, it's the raw code. url_for is a method. It needs 'static' as an arg, and the filename = 'mystyles/style.css' as a variable declaration to run.
So if your trying this out, the html code needs that link in it's beginning header, I put mine after the title. You have your app file, with the bin, templates,…

a scanner for python3.6

Ok so this took a while, and I did find a really neat tool to strip punctuation from stackOverflow.

So far, I think I got everything covered.  It will take any dictionary, and any sentence and return a list of tuples of the words and numbers and things not found in either of those will be listed as 'error' in the returned tuple.

# a scan method: from lexicon import game_lexicon import re

# scan a dictionary and return tuples from it in a list defscan(some_dict, some_sentence): # empty tuple list tuple_list = [] # try it, so if it fails, the scan function doesn't throw error try: #user_input = input(" give me a sentence...>") # make the sentence Lower Case sentance = some_sentence.lower() # strip out the punctuations with re module and sub cleansentance = re.sub(r'[?|$|.|!]',r'',sentance) # split up the clean sentance some…

better python 'hangman' style game

There's a for loop in there that I used, but I'm not sure exactly what it does.  I need to research that and see.  But it works.  I also need to get this to a point where it can use any words, and select them randomly from a list, but for now I got to do more class stuff and move on.

defword_game(): # Explain the game print("\tWord game start.....Type 'quit' to exit game.") print("\tYou will be told when you get a correct letter.") print("\tTo guess the whole word, type in the whole word.") print("\tGuess my 7 letter word!") # create a counter to keep track of guesses player makes count = 0 # create a list of each character in the word so you can tell the player if they got one correct word = ['c','a','r','r','o','t','s']
# add players used guesses to a list that will display used_letters = [] # create a bool set to True so the while will loop play_game = True
# add a …

I ran into something really strange, a loop without while

This is my function, and the game_lexicon is a dict from a different file,  Not sure why it is looping.  It will make the tuple list, run all the stuff, and then start over asking for a user input. It runs a second time, overwrites previous info and then shuts down.

I'll update when I figure out what the hell happened.  I didn't think a loop was possible without a 'while'

The error was in my game_lexicon import.  I had the same scan function running in that file, so it was running twice.  There was no loop.

from lexicon import game_lexicon

defscan(some_dict): tuple_list = [] try: user_input = input(" give me a sentence...>") user_words = user_input.split() print(user_words) except: print("input not tested.")

for word in user_words: key = word print(key) success =False try: int(word) == word #print(f"the integer {word} is accepted.") tuple_list.append(('number', word)) succ…

jdcp is changed, nosetests are hard.

We found out the other day that because of some (I'm assuming silly and over regulated) legal things zed can't offer us a certificate for the course,  But I would have done it regardless.  I want to learn, and in this course I'm learning. 

I had a hell of a time getting nosetests to run.  Had to do it different then zed has us do. Now I can use it, still don't care for it, but I can use it.  I still think I like unittest better, but there's another one he said to check out.  Might try that one out later.

Here's how I got my nosetests to run my test file.

I can make it work this way with other tests,  not sure why I can't do it zeds way.  But like I said, I have no love for nosetests anyways.  And I like to run the program and see for myself what it's doing.  Even if I did run the nosetest, I would still want to see the results, not just if it passed a test.

Doing a unittest on a simple player mod Class

OK, this took me forever to get right....  But if you want an example of a unit test for a class that has
attributes,  here it is.

Update:  At the bottom, an example of the test with a 'log' that will print the results of what the function modattack returned as a value

The Class code:

classPlayer(object): def__init__ (self, STR, ATK): self.STR = STR self.ATK = ATK
defmodattack(self): # define the damage an attack will do based on a formula: # use floor division to return a whole number attack = (self.STR * self.ATK) // 2 return attack

and a unit test to make sure there is not a NONE for the return attack:

import unittest from Player import Player

player1 = Player(60, 10)

with import logging:  (the Stackoverflow I got the logger info from:)

import unittest from Player impo…

re-doing a unittest to learn

We're on testing in the LPTHW course, and I remembered a video I had on here that shows you how to run some and make some, so I decided to watch that again, and play with it to understand.  I would totally do Zed's videos, but this computer says its from 3 - 13 hours to download....  It's not his file, it's the computer. 

Here's the video again, and I'll post some tests I try to make with it.  And if I get around to playing with 'nosetest' I'll see what I can share there too.

my first color ascii

Ok,  I spent way to much time on this.  But I had to see it through. GRAPH paper.  I am going to get more, cause it is so crazy without it.

here is a picture,   The code will be below:

and the code:

import sys
text_red = '\x1b[1;31;40m' stop_color = '\x1b[0m' text_blue = '\x1b[1;34;40m' text_green = '\x1b[1;32;40m' text_purple = '\x1b[1;35;40m' text_lightblue = '\x1b[1;36;40m' text_white = '\x1b[1;37;40m' text_lightGreen = '\x1b[2;32;40m'

#----------- Color pallete for my leaf ----------------------- fill = '\x1b[3;37;44m' stop_color = '\x1b[0m' outline = '\x1b[3;30;42m' edgebright = '\x1b[5;31;42m' edgedark = '\x1b[3;32;42m' orange = '\x1b[1;37;42m' innerred = '\x1b[2;33;41m' # make them one char === a = f"{fill}~{stop_color}" b = f"{outline}+{stop_color}" c = f&…

playing with color in powershell python

Here's a bit I'm working on.  I've discovered I love doing Ascii. 
Examples of how to use the color changing escape. 
I got a table from StackOverflow:

the charts are way at the bottom. So far accurate for me. 

defprettyjunk(self): # 1 is bold, 0 is plain, 2 is dull text_red = '\x1b[1;31;40m' stop_color = '\x1b[0m' text_blue = '\x1b[1;34;40m' text_green = '\x1b[1;32;40m' text_purple = '\x1b[1;35;40m' text_lightblue = '\x1b[1;36;40m' text_white = '\x1b[1;37;40m' a_green_at = (f"{text_green}@{stop_color}") a_red_at = (f"{text_red}@{stop_color}") print(f"{text_red} This should be Red. {stop_color} ") print(f"{text_blue} This should be Blue. {stop_color} ") print(f" {text_green} This should be Green. {stop_c…

simple word guessing game python

This is a tidbit of my RabbitHole I'm making for class.

It is a flawed game, but it works.  I don't want to make it too complicated at the moment, but here is a simple word guessing game:

defword_game(self): borders.horizon() print("\tWord game start.....Type 'quit' to exit game.") print("\tYou will be told when you get a correct letter.") print("\tTo guess the whole word, type in the whole word.") print("\tGuess my 7 letter word!") count = 0 word = ['c','a','r','r','o','t','s'] correct = 'carrots' correct_letters = [] play_game = True while play_game:
guess = input("\t Your Guess = : ") if guess == 'quit': print("............ ok, another time ........") exit(0) elif guess == correct: print("\t>>>>>> You got my Carrots! <<<<<<") p…