r/inventwithpython • • Jun 08 '15

Application specific passwords with Gmail?

3 Upvotes

I am using Automate the Boring Stuff with Python. I am working on sending email from Chapter 16. It's asking for an application specific password when I try to login. The book says to check the resources at nostarch.com/automatestuff but I can't find any references that refer to that . How do I set up an application-specific passwords for my script so I can use gmail as my outgoing mail server.

Thanks for any help


r/inventwithpython • • May 25 '15

Confused on “TRUTHY” AND “FALSEY” Values, Chap 2

3 Upvotes

Tried Googling this, nothing comes up. The part I don't get is "while not name", specifically why the 'not' boolean operator is there and what it's telling the computer to do?

name = ''
while not name:
	print('Enter your name:')
	name = input()
print('How many guests will you have?')
numOfGuests = int(input())
if numOfGuests != 0:
	print('Be sure to have enough room for all your guests')
print('Done')	

r/inventwithpython • • Mar 12 '15

Link in 3rd edition does not work.

3 Upvotes

r/inventwithpython • • Jan 27 '15

Newbie questions in re chapter 3

3 Upvotes

I am trying to run guess.py and I keep getting a "syntax error" with the word "am" in the sentence "I am thinking" highlighted in red. Also the word "and" in "between 1 and 20" is in orange.

I have checked my code against "Diff" and it does not seem to be pointing out any errors although I am not sure what the different colored blocks represent.

Any guidance would be greatly appreciated, thanks.


r/inventwithpython • • Jan 18 '15

Small question about Chapter 6? Regarding functions! :)

3 Upvotes

Hi all! Can someone help me understand what "chosenCave" is referring to in Chapter 6 (the dragon realm game). Its used as an argument here: "def checkCave(chosenCave):" but I have no idea where "chosenCave" is defined in the code before. I am used to seeing a variable defined before using it as an argument in a function... but I can't see where this is done before. I have tried reading the summary but I really don't get it still D:. Link to the chapter is here: http://inventwithpython.com/chapter6.html

I'm new to reddit and python, so sorry if I've done anything nooby without realising!


r/inventwithpython • • Dec 20 '14

Just finished chapter 3. Made a few changes with what I learned. Is there a better way to do this?

3 Upvotes

So once I finished up chapter 3 I wanted to experiment a little to see how well I understood the material. I added an option for the user to say how many guesses they wanted and a count down of those guesses.

#guess numbers
import random

guessesTaken = 0

print ('Hey what is your name?')
myName = input()

number = random.randint(1, 200)
print ('Well, ' + myName + ', I am thinking of a number between 1 and 200. How many guesses do you need?')
guessesWantedInt = int(input())
while guessesTaken < guessesWantedInt:
    guessesWanted = guessesWantedInt - guessesTaken
    guessesLeft = str(guessesWanted)
    if guessesWanted > 1:
        print ('Take a guess. You have ' + guessesLeft + ' guesses left.' )
    else:
        print ('Take a guess. You have ' + guessesLeft + ' guess left.' )
        
    
    guess = input()
    guess = int(guess)

    guessesTaken = guessesTaken + 1

    if guess < number:
        print ('Your guess is too low.')
    if guess > number:
        print ('Your guess is too high.')
    if guess == number:
        break

if guess == number:
    guessesTaken = str(guessesTaken)
    print ('Good job ' + myName + '! You did guessed it in only '+ guessesTaken + ' guesses!')

if guess != number:
    number = str(number)
    print ('You are out of guesses. The number I was thinking of was ' + number)

I would really like pointers on how to make this cleaner if possible. I guess I will learn more as i go through the book too. Just thought I'd share a little bit as I go along.


r/inventwithpython • • Nov 29 '14

NotImplementedError(MissingPygameModule)

3 Upvotes

Very new to python here and using your books as entry point. I was trying to run Squirrel Eat Squirrel but the following warning is keeping it from running:

Warning (from warnings module): File "C:\Python34\squirrel\squirrel.py", line 71 BASICFONT = pygame.font.Font('freesansbold.ttf', 32) RuntimeWarning: use font: DLL load failed: The specified module could not be found. (ImportError: DLL load failed: The specified module could not be found.) Traceback (most recent call last): File "C:\Python34\squirrel\squirrel.py", line 396, in <module> main() File "C:\Python34\squirrel\squirrel.py", line 71, in main BASICFONT = pygame.font.Font('freesansbold.ttf', 32) File "C:\Python34\lib\site-packages\pygame_init_.py", line 102, in getattr raise NotImplementedError(MissingPygameModule) NotImplementedError: font module not available (ImportError: DLL load failed: The specified module could not be found.)

Similar warnings are preventing other programs like memorypuzzle.py, slidepuzzle.py, wormy.py and others from running as well. What's the fix for this?

Currently running Python 3.4.2 and Pygame 1.9.2a0 win32


r/inventwithpython • • Mar 02 '14

Chapter 9 - Hangman

3 Upvotes

I'm going through and adding comments to the code so that I can make sure I understand every part of it before I move on.

this is the function that I'm having problems with specifically the for loop that replaces blanks with correctly guessed letters.

what does the i stand for in the line "for i in range(len(secretWord)):

I looked at the chapter multiple times and it eludes me.

Any help would be appreciated.

def displayBoard(HANGMANPICS, missedLetters, correctLetters, secretWord): #this function displays the game board to the player. len(missedLetters) will look at the length of the #missedLetters variable and add it as an element so the interpreter knows which picture to display to the player #from HANGMANPICS. HANGMANPICS is all caps because it is a constant variable, which does not change. #the for loop prints a _ for every letter in the secret word chosen in the function getRandomWord (line 66) with a #space between them. #the blanks variable makes _ the length of the word chosen for the variable secretWord #the next for loop will go through each letter in secretWord and replace the _ with the actual guessed letter. print (HANGMANPICS[len(missedLetters)]) print ()

print('Missed letters:', end=' ')
for letter in missedLetters:
    print(letter, end=' ')
print ()

blanks = '_' * len(secretWord)

for i in range(len(secretWord)):  #replaces blanks with correctly guessed letters

    if secretWord[i] in correctLetters:
        blanks = blanks[:i] + secretWord[i] + blanks[i+1:]

for letter in blanks: #show the secret word with spaces in between each letter.
    print(letter, end=' ')
print()

r/inventwithpython • • Oct 08 '13

Caesar Hacker for lazy folks...

3 Upvotes

My students have been working on the various Caesar Cipher programs in the 'Hacking' book. Today one student decided they didn't want to show Key #0 when showing the results of the Caesar Hacker program, since he knew that was the same as the original ciphertext. We accomplished this easily by modifying the range. He wanted to take it to the next level by using a dictionary lookup so the program reports only the correct plaintext. We realize that one only needs to look at the 25 or 26 lines of output, but I wanted to use this as a teachable moment fi we could make it work. The problem is that we couldn't figure out how to do it!

We imported detectEnglish and added

if detectEnglish.isEnglish(translated): #and len(translated) == len(message) print('Key #%s: %s' % (key, translated))

but the program prints to screen as soon as it gets a word/partial result: Key #9: THIS

As you can see above (it is commented out and needs to be moved to the 'if' line), we added a line to also ensure that the length of the message and translated arethe same, but then nothing is returned.

Any hints or tips to push us in the right direction? Thanks!


Caesar Cipher Hacker

http://inventwithpython.com/hacking (BSD Licensed)

import detectEnglish

message = "cqrbfjbqjamnaknljdbncqnanfnanwxbyjlnbkncfnnwfxamb" LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' message = message.upper()

loop through every possible key

for key in range(1, len(LETTERS)):

# It is important to set translated to the blank string so that the
# previous iteration's value for translated is cleared.
translated = ''

# The rest of the program is the same as the original Caesar program:

# run the encryption/decryption code on each symbol in the message
for symbol in message:
    if symbol in LETTERS:
        num = LETTERS.find(symbol) # get the number of the symbol
        num = num - key

        # handle the wrap-around if num is 26 or larger or less than 0
        if num < 0:
            num = num + len(LETTERS)

        # add number's symbol at the end of translated
        translated = translated + LETTERS[num]

    else:
        # just add the symbol without encrypting/decrypting
        translated = translated + symbol

# display translated when words are found in dictionary
    if detectEnglish.isEnglish(translated):
        #and len(translated) == len(message)
        print('Key #%s: %s' % (key, translated))

r/inventwithpython • • Aug 24 '13

Is there a way to get pygame to work with python 3 on a Mac?

3 Upvotes

I've been doing just fine using python 2.7 but I'm curious if there's a way to use python 3. All solutions seem to be Windows only, from what I can find.


r/inventwithpython • • May 10 '13

Programs that got cut from "Hacking Ciphers": The Null Cipher and Null Hacker.

Thumbnail inventwithpython.com
3 Upvotes

r/inventwithpython • • May 09 '13

When importing Pygame, I get "ImportError: DLL load failed: The specified module could not be found."

3 Upvotes

This is caused by using Pygame with a 64-bit version of Python. Currently Pygame only works on 32-bit versions of Python.


r/inventwithpython • • Apr 29 '25

Program Robots in Minecraft links dead

2 Upvotes

On this page: https://inventwithpython.com/#minecraft The links to the book are dead: https://turtleappstore.com/book/

Bummer, I was going to send information about it to some kids


r/inventwithpython • • Jun 10 '24

How is everyone? I just started reading Invent Your Own Computer Games with Python, 4th Edition.

2 Upvotes

(This photo is not me irl btw, found it when i googled "waving picture")
Anyways, just me saying hello to the community, i doubt anyone is gonna care anyways. :D


r/inventwithpython • • Feb 03 '23

Having Issues with selenium

Post image
2 Upvotes

r/inventwithpython • • Oct 29 '22

problem with indentation, python 3

Thumbnail self.learnpython
2 Upvotes

r/inventwithpython • • Oct 07 '22

Invent with python book hw, unexpected character error

Thumbnail self.learnprogramming
2 Upvotes

r/inventwithpython • • Jun 04 '22

How do I install the Debugger on Python 3.10.4?

2 Upvotes

I'm on Chapter 7 of Using the Debugger on Invent with Python but I don't have the debug option on my Idle Shell 3.10.4. How do I fix this? Newbie here.


r/inventwithpython • • Apr 16 '22

Pyzmail

2 Upvotes

Hi all,

It seems Pyzmail won't install beyond python 3.6? Any suggestions around this. It would be nice to be able to do the book on the latest version of python


r/inventwithpython • • Apr 12 '22

Eagl and Tails (task experiments in monet, page in book 161, name book Automating routine tasks with Python: A practical guide for beginners)

2 Upvotes

Здравствуйте, у меня есть вопрос, конкретно в этом: правильно я понял задачу и выполнил её?
I have a question about the task (task name in the table of contents of the post), specifically in this one: did I understand and complete it correctly?

import random, numpy, re
chetone = 0
chetzero = 0
numberOfStreaks = 0
for experimentNumber in range(10000):
    # create lists range of 100 values 0 and 1
    spisok = numpy.random.randint(0, 2, 100)    
    # Code verify availability 6 series Eagle and Tails
    sc = " ".join(map(str, spisok))
    regexone = re.search("1 1 1 1 1 1", sc)
    regexzero = re.search("0 0 0 0 0 0", sc)
    if regexone:
        chetone = chetone + 1
    elif regexzero:
        chetzero = chetzero + 1
    else:
        numberOfStreaks = numberOfStreaks + 1
print('Procent serries: %s%%' % (100 - (numberOfStreaks // 100)))
print(chetone, '\n' + str(chetzero))

r/inventwithpython • • Aug 08 '21

Need help with loop

2 Upvotes

r/inventwithpython • • Sep 15 '20

HELP The noob is here AGAIN

2 Upvotes

Hi people today I'm trying to do a program where you can add names to a list or something like this, so I'm starting and I have a problem with the if idk why so if someone can explain me and help I would be happy.

Yes I'm trying to do a calendar

Agenda = ['Juan', 'Alvaro', 'Lucia']
elem = Agenda
print ('Los contactos actuales que hay son: ')
for elem in Agenda:
print ('- ' + elem)
res = input('¿Deseas añadir algun contacto a la lista?')
if res == ('si') or ('Si'):
print('¿Que contacto desea añadir?')
else:

print('¿Esta seguro de que no quiere añadir ningun contacto?')

The problem is the if idk why else is not doing anything and always if is printed I mean if I write asdas in the input of the 9th line then the if of the 11th line is executed as well and the else doesn't do anything.

See you thanks ma boooys.


r/inventwithpython • • Aug 08 '20

Feedback please -- auto-generate new python file, new batch file, and open in editor, ready to go...

Thumbnail self.learnprogramming
2 Upvotes

r/inventwithpython • • Jul 15 '20

Need Help with Selenium and Stale Elements - No Longer Attached to DOM

2 Upvotes

Just finished Section 13 of the Udemy Course (Thank you Al!). I've noticed that when assigning a CSS Selector to a variable and making using of that variable, e.g:

browser.click()

..It is then no longer usable. I get the following error message:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: The element reference of <img src="images/automate_2e_cover.png"> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed

Why does this happen and how do i work around it so that it's usable more than once? What does 'no longer attached to DOM' mean?

I have googled and seen some work arounds but not explanation (at least one that I understand) as to why it works like this. I'd like to be able to understand it. Thanks.

-------------------------------------

Edit: I've added the code and steps as requested.

from selenium.webdriver import Chrome

browser = Chrome()
browser.get('http://automatetheboringstuff.com/')
elem = browser.find_element_by_css_selector('body > div.main > div:nth-child(1) > div:nth-child(3) > center > a:nth-child(1) > img')

elem.click()     # This works
browser.back()
elem.click()  # This doesn't work due to stale element

From what I gather, navigating away from the page once loaded will render the element 'stale' if you try to use it again but why is this? The CSS selector is still the same, as is the webpage etc. Everything is the same as before. Even the same session ID.