Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRyan Carson
23,287 PointsFeedback on my simple Python script?
I'm working on creating a basic Python app that helps you remember people's names. I'd love to get some feedback on the code.
- Anything I could do more efficiently?
- Am I not following any 'standard' coding conventions?
- etc
Next, I'll be
- Hooking it up to a database to persistently store the data
- Using OOP
- Creating a web interface
- Creating an API so I can write an iOS app
3 Answers
Kenneth Love
Treehouse Guest Teacher- You should be using four spaces and not use two to comply with PEP 8. Also, holy line length, Batman! Try to stick to 79 characters per line. You can break up strings inside of parentheses like:
print("this is a really "
"long string on"
" multiple lines.")
Good job using
namedtuple
. Convention is that the object created bynamedtuple
is CamelCased, though, so it should beMemory
instead ofmemory
.You're going to get some fun effects when you import this somewhere else. I'd suggest putting the whole thing into a function and then preventing import side effects by putting the following at the bottom:
if __name__ == '__main__':
memory_palace()
This assumes the function name is memory_palace
and it takes no arguments. This will make it so the function is only called automatically if the script is run directly (python memory_palace.py
) and won't run when it's imported (which you'll be doing when you tie it into other scripts).
It's a great start (especially with just what you got from docs and the course)! I can't wait to see more.
Ricky Catron
13,023 PointsAdditonally why should he use a named tuple instead of a dictionary?
Kenneth Love
Treehouse Guest TeacherReally it should probably be a class or information pulled out of a database, but to answer the question, any sort of tuple is going to be more memory efficient than a dictionary. Dictionaries are not cheap objects, even though they look and act like it. Named tuples are a pretty good in-between, though.
Ricky Catron
13,023 PointsThanks! I will be sure to look into them! Plus a kind of related question. If he was going to use a database how would he go about protecting the database from a malicious user. The database password would be in his code and they could go in a mess with any users data? This is a problem I have run into in my own work.
Kenneth Love
Treehouse Guest TeacherRicky Catron that's way more than we should probably get into in this thread. There are lots of ways to approach it, though. I generally prefer a twelve-factor app approach, though.
Ricky Catron
13,023 PointsThanks for the link at least it looks great!
Ryan Carson
23,287 PointsThanks Kenneth, Ricky and Andrew. I've made some changes and pushed them up to GitHub! :)
Kenneth Love
Treehouse Guest TeacherRyan Carson only one problem now, your import
should be at the top of the file.
Ricky Catron
13,023 PointsSeems good to me! The only code i didn't like was
for s in rooms:
s is not a very descriptive variable name. I know it doesn't really matter but personally I would change it. Plus you could turn it into an app for IOS, Android, Mac, Linux, or Windows using the Kivy library!
Kenneth Love
Treehouse Guest TeacherYes! It's pretty much always worth the extra keystrokes to use more descriptive names.
The only exception I can think of is holding onto throwaway index variables like when using enumerate
.
Ryan Carson
23,287 PointsKenneth Love
Treehouse Guest TeacherOOP is in the third course that's well underway.
Django and DBs will come after...2?...more Python courses.
Ryan Carson
23,287 PointsGracias sir
Andrew Molloy
37,259 PointsAndrew Molloy
37,259 PointsLove the project, I like the principle of a memory palace but always felt like I need a tool to aid me with it.