Posts

Showing posts from November, 2017

double linked list Nodes python

Image
Ok, the only way I can really learn this stuff is to see how it works.  So next in my class is making a double linked list....   So I need to know how the nodes work in order to manipulate them.  I spent A LOT of the day making diagrams until one made sense.  Then I spent hours playing with creating nodes until I figured out how I needed to set them up.  Here's my pretty.   Not as creative as the other ones,  but I'll do something better next time. The thing I figured out is this....  If I say x = "yellow"....   an address is created in my python compiler to store that variable x.   I can change x as many times as I want,  to --almost--  anything I want, and the address remains the same. So when your modifing the nodes,  their address stays the same,  so link is still just the address to them.   You can change the actual contents of that address --almost-- to anything you want to. ...

a Stack in python

I have went through my original code and updated and fixed it.  It is now tested and a StackNode class   and    a Stack List class.   Originally I had all of this as my Single Linked List, and I honestly thought this is how they worked.  I didn't understand why Zed kept saying it was backwards... Like no... all my tests pass... HUH???? I finally got the nerve up to discuss it with him, and he explained it.  There's a reason he's so good at this!   Holy cow.  A simple misunderstanding led to all of this.  But now when we get to doing the stacks in my class, I'm done. Here's the code: class StackNode(object):     # Value is like the item in the list     def __init__(self, value, prev):         self.value = value         # next is a reference to the previous node in the list         self.next = prev     def __repr__(self): ...

insert into a Stack

Image
UPDATE:   This is a Stack, NOT a single linked list.  I thought it was a single linked list,  but that is why I'm in zeds class, to figure this stuff out. Hope it helps someone.  I'll try and do one for remove too.   I'm done with the computer for the night after this though.   Happy trails !

trying to understand single linked lists

Image
Update:  This is a STACK,  Not a single linked list. I spent much of yesterday looking at this stuff going... WTH is this?  I have no programming background so it was just dumbfounding me. I took Zed's advice and just tried to play with the Node to try and see what it does, and today I found a video of someone explaining them in C language....  And it kinda clicked. Link to video: https://www.youtube.com/watch?v=o1QaGUEi6ew And here's my little toy to test it out.   Still a ways to go, but maybe this will help someone else out. Also an example I drew out, (Zed was right. Helped to draw out how it works) Update:  I have the logic completely wrong for this example.... I'll fix a new one tomorrow.  New diagram attached below.   egg() is the instance,  egg is the address.  The node does not store the instance, but the address of it.  ((although I think it would be useful if there was such a thing as storing the in...

highlight change color of words in a file to std.out.

I wanted a way for the color of the similar words I find to be highlighted when you print the file.  print() in python is basically std.out() so here's the bit I added to the previous post to make the similar words green when it prints out to command shell. I also added a line count, cause thats handy too. update:  I realized there was a bug in the original.  Lists did not properly highlight the original word correctly, or the whole word like I wanted it to.  11-25-2017 The whole parser is in the newer posts.  CTRL F with parser python args.file is the file it reads args.similate is the word searched for args.ignore is to tell the parser to ignore Case of letters def highlight(args):     with open(args.file) as f:         linecount = 0         count = 0         # green         stop_color = '\x1b[0m'         color = '\x1b[1;32;40m' ...

CTRL F with parser and python

Image
Update: 10-10-19 1) Added a codeblock for easier reading and copying. 2) This code will now work on windows also, with the install of python colorama. THANK YOU COLORAMA. docs:  https://pypi.org/project/colorama/ 3) As always take it, break it, bend it, whatever, I made this blog to share the code for those of us learning. Just like any skill, practicing will help improve the language in your brain.  4) Cheers, and happy practicing friends! Also big shout out to the Learn More Python The Hard Way by Zed Shaw.  Without knowing which direction to travel , having a road map was invaluable. Image:  A screenshot of my useless octopus dictionary with the word 'node's color changed to green so that every instance of the word stands out on command prompt. Making a command line CTRL F: I wrote this, thinking it would be handy.  Then I realized this is what CTRL F does.  And yes. Handy. So here's a more complete version.  Moving on tomorrow to...

search for similar words. contains.

This isn't fully tested, but it looks promising. This is a parser that will search through a file for words containing a sequence of stuff you search for,  like if I want to know how many times I use a variable 'carrots'  or anything containing that word in a file.  Maybe you want to know how many times you repeat yourself, or just search for similarities...  I'm sure it can be better, and it's probably highly unpythonic, but work in progress! Distraction for the day! update: fixed the copy paste. Blogger doesn't like to paste visual studio code correctly. import argparse import re parser = argparse.ArgumentParser() parser.add_argument('file', help="file to search through") parser.add_argument('similate', type=str, help='character similate to find in fuzz.') args = parser.parse_args() def main(args):     words = []     if args.file:         similar_stuff= []         with open(arg...

something new

Been away on vacation with my kiddo. I am going to dabble with some things tomorrow, and try and get something new to post on here. Just have to come up with an idea.  We're doing a lot with python's argparser at the moment, and going to try and do something silly with it and put it in here.  Happy turkey week everyone!

LMPTHW

I've moved on to the Learning More Python the hard way book, and one of the first assignments is to kinda dissect the way you program. I am spastic.  I can be meticulous, and detail oriented.  But when I'm really just plugging away at something, I just write code and make it go.   When I hit a barrier, or when I find myself wondering what the 'F' just happened... That's when I stop and look at what's really going on.  It's a really bad habit to have, in my opinion.  I've had errors that I fixed by just spazzing my screen until it worked.  Problem is, the process goes so fast like that, that I forget what I did that didn't work and how I got to the solution.  Sometimes (not often), I don't know what was actually causing the error, just that I fixed it.  So moving forward I will try and stop doing that.  I can't imagine it's a good thing for a beginner like me to do.  I need to learn what was causing the error's, why, and how to...

python file that saves passwords to txt

Ok, so this is in no way a secure way to do registration, or passwords.  Have had a lot of family time so not much time to work on putting an explanation to this.  Basically the functions will test the file of users, to see if one exists already.  Can't have users with the same name. Then if they are not on the list they can register, and add a name and password to a file.  another function can test if that name and password are on the lines of the password txt.  It also saves the name and password to a temporary list and dictionary for the session of the web app or whatever they are in.  I took the list and dict. out, but they would be there for an implementation. I imagine with a database, you would add the name and password to it, similarly. Here's the code, I'll try and share more later.  def search_users ( name ): found = False try : with open ( 'userNames.txt' ) as search: for line in search: ...

omg this took forever

Image
I'm going to try and make a post tomorrow to explain what I did to make this happen. But just know, the way I have passwords and usernames set up is totally insecure, and doesn't use one of those SQL, or json, or any imported databases. It saves them to txt files and reads lines to see if there is a match.  I know. Totally not safe, but I'll learn about all that in the next part of class.  Just wanted to say I did it. I'll try and get the code up explaining it tomorrow.  But only the Gothons game works at the moment. Going to add another tomorrow.  This took a lot of studing Flask and trial and error.

a test for if an instance was created

Ok,  I tried to put comments in to explain it.  ********* first the file that holds the class's and methods *********** example.py class Example ( object ): # this is just for testing. I want to show how you can test it. def print_something ( self ): # def a string to return for test... some_string = "I am going to make this work" #return that string, could be anything return some_string class MakeSomething ( object ): # we are going to give the instance of MakeSomething two # attributes when it's initiated. A name and a dictionary # which will hold the call for our Example class when we # create it. def __init__ ( self , name ): # the has has an attribute, name which you pass # in with the paramaters makesomething = MakeSomething('name') # it also has a dictionary named routes, that belongs to only # the class MakeSomething...