![]() |
|
Re: ** Python Support Thread **
Here's the mit version of Fibonacci.
Code:
def fastFib(n, memo):Code:
def fastFib(n, memo): |
Re: ** Python Support Thread **
For amusement value, here was my first python generator function.
Code:
def fibonacci():Code:
for i, seq in enumerate(fibonacci(), start=1): |
Re: ** Python Support Thread **
Quote:
This is especially true if he's talking about doing assignment questions and other toy/small problems. |
Re: ** Python Support Thread **
The biggest reason I can think of to use a debugger more often is that you get better at using it and don't have to learn it the first time AND find a problem in your code.
|
Re: ** Python Support Thread **
Does anybody develop python on windows? I was just hired at a startup that mostly uses python and they currently don't have a single developer out of about 25 that uses a windows machine. I've pretty much only used windows in the past, but looks like it might be time to switch. From reading through the talk regarding IDEs on the previous page, I'm guessing the easy access to a unix shell is pretty important?
|
Re: ** Python Support Thread **
Learning unix is always a good idea, doubly so if you work in a unix shop. However, there are plenty of legit python interpreters and ides for win. One of the points of python is to be a cross-platform scripting language, so unless you go crazy, scripts will run equivalently on nix and win.
|
Re: ** Python Support Thread **
About 3-4 years ago I did a small amount of python development in cygwin on a Windows machine. It was kind of painful since cygwin had a few incompatibilities with libraries.
|
Re: ** Python Support Thread **
Yeah, don't use cygwin. Use the native windows tools.
|
Re: ** Python Support Thread **
I have a question about objects and inheritance, or rather the style of using inheritance.
So a very generic and dysfunctional Python code: Code:
|
Re: ** Python Support Thread **
i haven't done much oop with python, but i think the general answer is: do whatever makes the code easiest to understand. oop is all about modeling something in the world. thinking about your model will help you figure out where methods belong and how to call them.
btw are you deliberately using iClass to signify that it is an interface? or are you not there yet? |
Re: ** Python Support Thread **
I know what I'd do in Ruby, so I looked up the Python equivalent. Perhaps try this:
Try, from the Python docs, Code:
class C(B): |
Re: ** Python Support Thread **
Quote:
He suggests using a bisection/ divide in half style of debugging. Obviously there was no need to create so many print statements. I only use the numbers to demonstrate the order he checked, not what he actually wrote. Perhaps 3 and 4 are mixed up; regardless, you can see what he did. Code:
Quote:
Quote:
But according to this post linked from the pyDocs: http://rhettinger.wordpress.com/2011...sidered-super/ super() isn't so good to use in Python 2.x, which is what I am learning to use atm. I'll definitely keep this one in mind for the day I decide to download Python 3.x. (*shiver*) ------------ The course went to lullaby easy to monster hard in a matter of a few lectures. The assignments jump from recursion to knapsack algorithms and OOP. |
Re: ** Python Support Thread **
Code:
class MyNewStyleClass(object):Using super is better because it doesn't require you to explicitly know the super class that defined the method. This is important when you have multiple inheritance. |
Re: ** Python Support Thread **
I was so confused about OOP in Python-land that I decided to type out the entire lecture notes plus some other stuff. During the lecture, Python apparently wasn't working the way it was supposed to. I figured out the problem: lots of bugs.
I think now is time to start learning how to use a debugger. I felt really stupid using print all over the place. I put more thought into the .sort, .reverse idea. I don't understand why these functions should return new values. What benefit is it to have extra variables when your function returns a mutated output? It seems like it is a cleaner solution to simply have one variable. If you really need to return the non-mutated variable, then having an explicit copied variable seems to make the code easier to read. I guess having .copy set so that it either returns or not returns a new variable would be a nifty addition, though I'm not sure how hard that would be to implement. I guess if it really upsets you, you can create your own object and over-ride .sort. Maybe at the end of this class, I could try to create a new .sort function that could return a new variable or not. Shouldn't be too hard, really. |
Re: ** Python Support Thread **
Quote:
Code:
>>> a = [1,2,3,9,7,8] |
Re: ** Python Support Thread **
yes, of course. if i want to modify the list in place i use listObject.sort() but if i want to return a copy of the sorted list i use sorted(listObject). how consistent and easy to understand! hooray for python!
(again, i know why it's set up this way. i'm just trying to elaborate on why i think it's bad language design.) |
Re: ** Python Support Thread **
yeah the Ruby (Scheme, I guess) notation is pretty cool for that. I'm not sure that sorted and reversed should be builtins at all in Python.
|
Re: ** Python Support Thread **
Quote:
Looking at the keys() vs sort() distinction, it still seems pretty clear to me. keys() is obviously a property of the object (and so returns that property) while sort() is obviously an operation (and so just mutates the object and returns nothing). Are there other examples that are inconsistent? |
Re: ** Python Support Thread **
shabby,
i already trucked out the str(object) vs object.toString() example. i'll try to post another if i think of it. to me, the keys() vs sort() distinction to be obvious. i'm not sure what else to say about it. for me, it forces me to think about something which i believe should be natural, it creates friction, it slows down my coding, etc. maybe this is because i learned ruby before python, maybe it's because i'm a dullard, maybe it's because i have the heart of a pure programming champion while you are a nasty, brutish hacker. i guess we'll all have to decide for ourselves :). |
Re: ** Python Support Thread **
I have my first official beef with Python. Well, maybe not Python, but probably the packaged IDLE and Shell.
This only happens with larger codes (probably 100+ lines because that's 'large' in my world, lol). I f5 and the Shell crashes. Okay, fine, close down the Shell and run the file again. Yes, this sucks but I can sort of get over it. The thing I can't get over is that Shell/IDLE can't handle Classes and OOP worth a ****. Run a file and the code executes. Does this mean I have a good piece of code? I always assume like 80% yes even if I 'know' I have it right. But not now: I can only flip a coin and hope it is correct. f5 again and find out that the code that just ran great for the past 3 runs is now throwing an error! Fine, whatever, I fix the bug and the code runs fine again (I think). This would only be a minor irritation if that only happened when the code is bad, but no, it also happens when the code is plenty fine. Run the good code, get an error (or maybe Shell crashes). Screw that. Close Shell, re-run and all is good again. Wow, I really hope it isn't Python doing this. I most certainly would not understand it's popularity if this is a constant thing. I can only conclude, at this time, that IDLE is only good for learning the real basics: loop, add, subtract. Add in functions and you get some problems. Add in classes and all hell breaks loose. I think there was talk of IDEs earlier, but since I only have 1 3/4 assignments left, I really don't feel like going through the trouble. These issues also happened on the OCW videos, so I know it isn't just me. |
Re: ** Python Support Thread **
The command line is your friend. Edit in one window, run from another. I only use IDLE to work out syntax stuff I should know but didn't remember...
|
Re: ** Python Support Thread **
IDLE works fine for me unless I write infinite loops, which I do too often. As usual, it's probably you.
|
Re: ** Python Support Thread **
idle sucks. there's a better one that a couple of my colleagues use but i can't remember the name right now :\.
edit: and honestly, learning how to use vim as a poor man's ide (or emacs as a crazy man's ide) is probably better than learning any language-specific ide. |
Re: ** Python Support Thread **
Quote:
I run the same exact code, with the same exact test case, multiple times and I get error or completion. I can't blame myself for this, unless I am missing something egregious. I simply can't understand why pressing f5 at :37 vs :21 is my fault. en re: Emacs. I agree it's nuts (and ugly to look at). The Scheme class uses Emacs. C-x C-e? That's crazy. I am pretty happy to say that after running infinite loops a billion times when I first started Python, I haven't done that one in a long while. Lesson (hopefully) learned. For... var is your best friend. Speaking of for..., I just learned about xrange. Further research suggests that Python 3 deprecated xrange, and it has its own variant on range and xrange. http://stackoverflow.com/questions/1...nge-over-range |
Re: ** Python Support Thread **
In light of all the requests about poker evaluator/hand this hand that stuff in this forum, I decided that may be a semi-fun project to attempt.
I just started this last night. It is already 111 lines long. I obviously need to abstract a ton of this, but I'm okay with the extra visuals right now. I guess it'll be done in about a month. Taking the next series of classes, which is on Scheme, so I won't be able to commit tons of time to this. Code:
#Hold'em poker eval that is extensible to other variants: |
| All times are GMT -4. The time now is 03:50 PM. |
|
Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Copyright © 2008-2020, Two Plus Two Interactive