Python With As

In Python you can do the typical way of opening/writing to a file by calling it with: my_var = open(“my file.txt”,”r”) or “w” for write… In such cases you need to close the file when you’re done with a my_var.close() Instead you could also use: with open(“my_file.txt”, “w”) as my_var: Continue Reading

Python Classes

In Python you create a class with: class Like: class MyCalculator(object): Member variables are variables defined within a class.  For example: class MyCalculator(object): statement = “Welcome to the calculator” You can access member variables with dot notation like so: Frist lets create an instance of the class: my_calc = MyCalculator() Continue Reading

404 Checker

After getting a ping from a friend of mine, I updated my web scrapper and modified it a bit to fit his needs.  He wanted to catch 404’s… so I sent him my old web scrapper.  The problem was though, his test machine had limited memory.  Due to that it Continue Reading

What is Selenium

There is a serious misunderstanding with a lot of people who are not doing web automation day to day.  Every now and then I run into someone looking at my code and he/she says, “hmm. have you heard of selenium?” Such comments deserve a *bonk* on the head. Selenium So Continue Reading

Python & Selenium

Step 1: Install Selenium libraries with Python.  If you are using Python3, then you would use: pip3 install selenium If using Pre-Python3: pip install selenium Step 2: In your Python script, import the libraries you need… like: from selenium import webdriver from selenium.webdriver.common.keys import Keys Step 3: Write the selenium Continue Reading

Python Palindrome Test

Code Exercise Years ago I used to say if I was given a palindrome test for Ruby, I’d just write: some logic that if the variable = variable.reverse() then it’s a palindrome. HA! Such a solution doesn’t exercise thinking, and wouldn’t really ace an interview. While learning Python, I wrote Continue Reading

Python: While

Over at the codecademy.com, this was my python solution for their exercise on a random number game: from random import randint # Generates a number from 1 through 10 inclusive random_number = randint(1, 10) guesses_left = 3 # Start your game! while guesses_left >0: guess = int(input(“What is your guess?”)) Continue Reading