OT: Python Help!

From: Ryan Macy 
Source = http://pastebin.com/GGjKW9Kp

Im trying to figure out the best way to get a a list of project names from
the user and then compare them to the files I collected with

I also would like to know if there is more error checking I can implement or
if there is something I am doing very very wrong.

thanks !

=============================================================== From: Ryan Bales ------------------------------------------------------ Couple things: 1. You're not using the correct "AND" operator. You're using a bitwise AND. Try using "AND" instead; It's the more pythonic way of constructing the expression. I think also, more relevantly in this case, the bitwise and operator binds tighter than ==, so you're almost certainly not constructing the expression the way you want. 2. Your exceptions should be explicit, since handled exceptions should do something other than just failing silently in most cases. I would try to avoid the catch-all exceptions. If you're invoking functions that raise errors, catch

=============================================================== From: Ryan Macy ------------------------------------------------------ You're completely right, thank you for those suggestions. If you don't mind what would be your advice about taking some type of user inputted list and comparing that list to what glob grabs. I'm trying to give a department at work the ability to specify projects, have my program search in the sub folders for said projects, compare the two, take the matches and copy them to a new location. I thought about having the user create a CSV file and then comparing the list generated from the CSV file to the list that glob makes but I've run into some issues with that method and I think there has to be a better way to implement this. I could do some kind of list widget with wxpython but I'm not sure if that method is too complicated. Thanks in advance!

=============================================================== From: Ryan Bales ------------------------------------------------------ Just to clarify, by compare the two, you mean compare path names? ~Ryan Bales

=============================================================== From: Ryan Macy ------------------------------------------------------ yes, I would like the user to put projectd123 and it will look at glob.glob and match that to C:/some/folder/location/projectd123.csv

=============================================================== From: "Robert A. Kelly III" ------------------------------------------------------ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I have no experience with wxPython, but my first thought would be to use a TextCtrl and let the user input a list of one project per line. I would think it should be fairly easy to go over that line by line and pull matching items out of the list returned by glob(). -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk4M5S0ACgkQQCTX/7MVrjYF1ACeL5vPg7RvbSIaFFqlzctLpZpu AIsAn37AG27LuX1FLxMTAvCmISHQVoXT =42YY -----END PGP SIGNATURE-----

=============================================================== From: Ryan Bales ------------------------------------------------------ I think the easiest way to do what I

=============================================================== From: "Robert A. Kelly III" ------------------------------------------------------ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

=============================================================== From: Ryan Bales ------------------------------------------------------ That's roughly what I was suggesting. I never think it's a good idea to take fat-fingered input from the user, whether in csv or any other input method that originates with a user typing, if it can be avoided. ~Ryan Bales

=============================================================== From: "Robert A. Kelly III" ------------------------------------------------------ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 That is basically what I initially thought you were suggesting, but then I thought perhaps you meant to simply provide a tree view of the filesystem, and it seemed like it should be pretty easy to simply present a list of the project names to the user. But either way it makes sense to just let them select from what is there, rather than taking arbitrary input, unless there is some reason for it I have missed. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk4M73YACgkQQCTX/7MVrjZKPACfSS7qKETr0HZAgVrGPBtJqTlb jP4An201blUoq9PpegEASGaaTvs8El8P =FNos -----END PGP SIGNATURE-----

=============================================================== From: Ryan Bales ------------------------------------------------------ Ah, I see, yes. It would seem we're singin' out of the same hymnal ;) ~Ryan Bales

=============================================================== From: Ryan Macy ------------------------------------------------------ The predicament is that the user needs to select 100s of projects and sometimes projects are used that day and sometimes they aren't. The actual list of working projects only typically changes once a quarter though. I would

=============================================================== From: Sean Brewer ------------------------------------------------------ Are you trying to use CsvBrowse and CsvPath

=============================================================== From: Billy ------------------------------------------------------ So global makes it a static class variable? --b

=============================================================== From: Ryan Bales ------------------------------------------------------ No, global makes it a global. Static class variables are defined as such: class MyClass(Object): foo = 'bar' // static class variable def

=============================================================== From: Troy Melhase ------------------------------------------------------ No, global means "get this name from the global scope". At any point in execution, python has 3 scopes (or namespaces) available: function (or method), module, and global. The global keyword means that the name is already defined outside of the function and the code should use that value instead. Also, there is one very, very good reason to use the global keyword, and that's when you run into unbound names in closures. This only applies to python 2.x, and is probably not something you need to worry about until you get into functional programming.

=============================================================== From: Ryan Bales ------------------------------------------------------ Ah, I guess I didn't understand that clearly, sorry. Thanks for clearing that up! ~Ryan Bales

=============================================================== From: Sean Brewer ------------------------------------------------------ The thing about that is, foo isn't *really* static. You can modify foo by doing: foo.

=============================================================== From: Sean Brewer ------------------------------------------------------ Oops, I meant self.

=============================================================== From: Ryan Bales ------------------------------------------------------ Yeah, and you would be accessing a centrally managed object, a static class method. Are you confusing static with constant? class myClass(object): foo = 'foo' 'foo'

=============================================================== From: Ryan Bales ------------------------------------------------------ Erm, not method, variable, sorry.

=============================================================== From: Troy Melhase ------------------------------------------------------ It's not a variable and as you showed, it's not a constant, either: it's a name and it has a value. It's very helpful to think in these two terms when discussing Python code. Names have values.

=============================================================== From: Ryan Bales ------------------------------------------------------ lol, variable, name, symbol, whatever; Let's not be pedantic. They actually

=============================================================== From: Sean Brewer ------------------------------------------------------ I can't believe I did that. I need to go to bed.

=============================================================== From: Sean Brewer ------------------------------------------------------ It's a little dated, but this is a good, still relevant tutorial on OOP in Python for those that need it: http://diveintopython.org/object

=============================================================== From: Billy ------------------------------------------------------ Well, if you ever look at groovy, it's like python - but with java. It has duck typing (or whatever python calls it), closures, anonymous functions, can treat maps as proxy objects to other objects and is so damn reflective that it can break encapsulation by allowing you access to the private fields and methods of instantiated objects. As someone that actually LIKES type safety and compiler type checking, python and groovy really annoy me. Ok, so I can write a one line piece of code that can twirl a hash array into a hyper cube, and save about 15 lines of code... But in two months, it'll take me 15 minutes of staring at said one line of code to actually figure out what the hell it's doing. Also, Bob the new programmer can update a method signature in another object, and because closures don't have type checking, we won't know about it until runtime during the unit tests (at best), or during QA testing (probably), or when it's pushed into production (some people test code in production). So, what was it trying to fix again? Job Security? --b

=============================================================== From: Billy ------------------------------------------------------

=============================================================== From: Dave Brockman ------------------------------------------------------ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

=============================================================== From: Sean Brewer ------------------------------------------------------ This reminds me of this article: https://docs.google.com/View?id=dcsvntt2

=============================================================== From: Billy ------------------------------------------------------ Oh, java is compiled. It's byte code, sure, but that's akin to CLI. It's funny, when you get to the high level languages, you'd think that they'd all be slow, but the reality is when you apply optimizations at the compiler level, and then at the byte code level, you can optimize things in a way that would be more difficult from a lower level language. Think: gcc with -mtune=i386 vs -mtune=core2. Once you've compiled it to object code, it's more difficult for the processor to optimize it down further. Granted, processors these days perform voodoo in order to optimize it anyway - out of order execution, pre-fetching, lazy prediction - but the compiler could do so much more to help the processor along. In much the same way, while the jvm or CLI (or python) compiler can optimize the higher level language constructs, the byte code optimizer can do it's thing at runtime and optimize it even further in ways that the compiler and programmer are unaware. In fact, the sun hotspot virtual machine could even compile portions of the java byte code stream into native object code once it figured out that there was enough of an optimization trade-off for it to do so. Speed is rarely a reason these days to pick a language... jobs and maintainability should be big factors, too. Rapid Development is great, but at the end of the day, I need to be able to read what you did and if it's being maintained or shared by lots of developers, then the language should also play well with others. --b

=============================================================== From: Ryan Bales ------------------------------------------------------ Be careful where you suggest that source. Python enthusiasts hate Dive Into Python, so you might get a tongue lashing in mixed company ;) I actually found it to be hugely helpful. ~Ryan Bales

=============================================================== From: Sean Brewer ------------------------------------------------------ LOL, I think by Python enthusiasts you mean Zed Shaw who wrote douchey rant a year ago about Dive Into Python: http://oppugn.us/posts/1272050135.html The funniest thing about his rant about how "too many potential programmers find this book and get tripped up by its horrible design decisions" when Dive Into Python clearly states that it's geared toward experienced programmers.

=============================================================== From: Ryan Bales ------------------------------------------------------ Lol, well, yes, Zed Shaw. Also, #python on freenode ~Ryan Bales

=============================================================== From: Ryan Bales ------------------------------------------------------ If you're not unit testing, you're either really lazy or really stupid. Personally, I care more about the behaviors of an object (or the messages to which the object responds, depending on your preferred idiom) than the actual, specific type, so I don't care about type checking at compile time. Also, most people find the syntax of python to be more readable than the verbose, noisy syntax of other languages. ~Ryan Bales

=============================================================== From: Sean Brewer ------------------------------------------------------ What's the specific complaint? I'd guess they're just circlejerking around Zed's rant. The old Dive Into Python and Dive Into Python 3 are OK. There are better books, but I don't see a good reason to absolutely hate them. I wouldn't recommend it to anyone that's new to programming, and the author even says that it's not for that audience.

=============================================================== From: Ryan Bales ------------------------------------------------------ I don't really recall, sorry. It's been a while since I've heard someone flamed over it, but I don't spend a lot of time in #python anymore anyway. I don't think it was a matter of information being wrong; I just remember people groaning over the suggested implementations. ~Ryan Bales

=============================================================== From: Rod-Lists ------------------------------------------------------ What would you suggest? I used program in fortran77 a long time ago before objects. ----- Original Message ----- From: "Ryan Bales" To: "CHUGALUG" Sent: Friday, July 1, 2011 11:52:13 AM GMT -05:00 US/Canada Eastern Subject: Re: [Chugalug] OT: Python Help! I don't really recall, sorry. It's been a while since I've heard someone flamed over it, but I don't spend a lot of time in #python anymore anyway. I don't think it was a matter of information being wrong; I just remember people groaning over the suggested implementations. ~Ryan Bales

=============================================================== From: Stephen Haywood ------------------------------------------------------ Here are six free e-book suggestions: http://www.readwriteweb.com/hack/2011/03/python-is-an-increasingly-popu.php e ne .

=============================================================== From: Ryan Macy ------------------------------------------------------ That list is great thank you! http://www.readwriteweb.com/hack/2011/03/python-is-an-increasingly-popu.php before anyway.

=============================================================== From: Sean Brewer ------------------------------------------------------ I think you would like Ruby or Python. Just try it.

=============================================================== From: Ryan Macy ------------------------------------------------------ At the moment im working on compiling and porting python onto my XOOM before anyway.

=============================================================== From: Cameron Kilgore ------------------------------------------------------ Is this with SL4A? --Cameron

=============================================================== From: Sean Brewer ------------------------------------------------------ I was about to say, you already have a port of python (and ruby, lua and some others) with SL4A: http://code.google.com/p/android-scripting/ someone

=============================================================== From: Billy ------------------------------------------------------ In a company of any specific size, there are inevitable proportions of both.= .. So, you can spend your time fixing stupid (can't fix stupid), or take whatev= er help you can get to get your job done. --b

=============================================================== From: "Robert A. Kelly III" ------------------------------------------------------ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1