|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:20 on Mar 13, 2017 |
# ? Dec 17, 2009 20:04 |
|
|
# ? May 11, 2024 07:15 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:20 on Mar 13, 2017 |
# ? Dec 17, 2009 20:15 |
|
In Python 3+, print is a function not statement so its arguments need to be wrapped in ()
|
# ? Dec 17, 2009 20:20 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:20 on Mar 13, 2017 |
# ? Dec 17, 2009 20:22 |
|
Python posted:If you don't know which version to use, start with Python 2.6.4; more existing third party software is compatible with Python 2 than Python 3 right now.
|
# ? Dec 17, 2009 20:26 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:20 on Mar 13, 2017 |
# ? Dec 17, 2009 20:41 |
|
GregNorc posted:poo poo, too late for that now. Unless there's a way to revert? Mark's wrote a python 3 version of the book: http://diveintopython3.org/ so you can use that, or switch to python 2.6, they're really very similar.
|
# ? Dec 17, 2009 20:42 |
|
GregNorc posted:poo poo, too late for that now. Unless there's a way to revert? If all you did was use print as a function like print() then the code should run perfectly fine in 2. Unless you used any of the special things print can do in 3.0(like file= rather than >> in python 2). python 2 should handle string formatting and concatenation inside of the tuple and print fine if it results in a tuple filled with a single item. So you are not too deep. tehk fucked around with this message at 21:07 on Dec 17, 2009 |
# ? Dec 17, 2009 20:51 |
|
GregNorc posted:
|
# ? Dec 17, 2009 21:04 |
|
If someone has the time to give me a critique, I've got a 70 line module here on pastebin. This module scrapes a movies sex, violence, and profanity ratings off of kids-in-mind.com. (I've got a kid and I'd like my movie organizing script to take advantage of this stuff.) I'm particularly looking for style and code organization critiques. It's hard when you're not a pro programmer and learning programming on your own in isolation to know if you're doing things the "right" way.
|
# ? Dec 17, 2009 22:16 |
|
I only have a minute but just glancing at it there are exactly zero reasons that should be a class and uncountably infinitely many why it shouldn't be. Other than that it looks fine, but like I said I just did it a cursory once over.
|
# ? Dec 17, 2009 22:22 |
|
Thermopyle posted:If someone has the time to give me a critique, I've got a 70 line module here on pastebin. This module scrapes a movies sex, violence, and profanity ratings off of kids-in-mind.com. (I've got a kid and I'd like my movie organizing script to take advantage of this stuff.) Here goes, you asked for fully anal PEP8 mode, you got it Put imports on seperate lines, alphabetized: code:
class names should be CamelCase, no underscores, use new style classes (subclass object): code:
One space after colons inside of dictionaries: code:
You've also got some indentation weirdness with docstrings. They should be indented all the way. I'd simplify _move_the to be this: code:
|
# ? Dec 17, 2009 22:27 |
|
Thermopyle posted:If someone has the time to give me a critique, I've got a 70 line module here on pastebin. This module scrapes a movies sex, violence, and profanity ratings off of kids-in-mind.com. (I've got a kid and I'd like my movie organizing script to take advantage of this stuff.) Your class kim_getter is not much of a object and the methods could just be functions or a single function. I would not use a class unless you are defining a video object that has attributes like title, sex_rating, violence_rating, profanity_rating. Perhaps this stuff should be in that Video object you posted about earlier.
|
# ? Dec 17, 2009 22:32 |
|
Thanks guys. The reason it's a class is that I'm imitating several other third-party modules I'm using for querying stuff like IMDB and the like. Of course, now that you made me think of it, just because they use a class doesn't mean I have to... Also, that kind of stuff was much appreciated, king_kilr.
|
# ? Dec 17, 2009 23:04 |
|
GregNorc posted:poo poo, too late for that now. Unless there's a way to revert? You don't need to revert, python installs with different major versions can live beside each other just fine. Just edit your path to put the one you want first. I think I was telling someone else about this a few pages back if you need more detail. Just grab the 2.6.4 dmg installer and it should set you up right good.
|
# ? Dec 18, 2009 04:33 |
|
Out of curiosity more than anything... Say I wanted to make the module I just posted a web service. You submit the movie title and year (a POST request a guess) and get back a JSON feed with the ratings. What's the simplest way to do that? Is the simplest way somewhat scalable?
|
# ? Dec 18, 2009 21:06 |
|
Thermopyle posted:Out of curiosity more than anything... I'd personally use a Django install. You could do it by editing one line of the urls file and a view which would just take the variables, do whatever you want to do with them, and use the (simple)json module to serialise and output them. Django's pretty scalable as far as I know. If you want help, there's the Django thread here (or feel free to PM me if it's one of those 'yes it's in the docs but I can't be bothered reading them' type questions). You could probably do it with a simpler mod_python or whatever type script I guess, but I'm not familiar with them.
|
# ? Dec 19, 2009 14:54 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:20 on Mar 13, 2017 |
# ? Dec 19, 2009 23:10 |
|
code:
|
# ? Dec 19, 2009 23:19 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:20 on Mar 13, 2017 |
# ? Dec 19, 2009 23:20 |
|
Here's a pretty basic question. How well suited is Python for sysadmin-y type tasks? Basically, I'm trying to decide if I should learn Perl or Python. Obviously I'm leaning towards Python as a better general-purpose language, but I have no desire to write games or web apps, mostly looking for a replacement for writing shell scripts.
|
# ? Dec 22, 2009 02:47 |
|
ZippySLC posted:Here's a pretty basic question. How well suited is Python for sysadmin-y type tasks? Basically, I'm trying to decide if I should learn Perl or Python. Obviously I'm leaning towards Python as a better general-purpose language, but I have no desire to write games or web apps, mostly looking for a replacement for writing shell scripts. It's excellent for sysadmin stuff; I use it all the time. The builtin standard library alone has just about everything you could need for integration with the OS, and there are oodles upon oodles of third party libraries for anything imaginable. The only thing Perl has going for it over Python in this area is the marginally quicker-to-write integration with regex and the shell, so whereas Perl can do stuff like (paraphrasing here, my Perl is weak) code:
code:
|
# ? Dec 22, 2009 03:00 |
|
bitprophet posted:To be honest, though, the #1 reason to prefer Python over Perl for shell-script-like stuff (or anything) is simply that you can figure out what the hell it's doing 6 months later -- something that is often poo-pooed but is far more important than inexperienced folks think. And I don't mean this as a rag on "lol Perl is line noise", but hard-to-read code is inevitable in a language with such a large syntax and loose constraints on formatting, no matter what one's intentions are. Right, that's sort of the problem I have now with some of my larger, oft-ignored shell scripts. I write something, it runs fine for a long time, and then I need to make a change and I have to spend 30 minutes trying to decipher what the heck I was thinking.
|
# ? Dec 22, 2009 03:17 |
|
I've been messing with this all day...I have a class derived from BaseHTTPRequestHandler which I want to handle AJAX POST requests. Here's the AJAX POST I'm doing via jQuery;code:
Note: I intentionally am not pasting my Python code. I don't care what I wrote, I want to see how you all do it this since my method is obviously not working.
|
# ? Dec 22, 2009 04:21 |
|
ZippySLC posted:Right, that's sort of the problem I have now with some of my larger, oft-ignored shell scripts. I write something, it runs fine for a long time, and then I need to make a change and I have to spend 30 minutes trying to decipher what the heck I was thinking. The set type can be really useful for sysadmin tasks.
|
# ? Dec 23, 2009 01:38 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:20 on Mar 13, 2017 |
# ? Dec 23, 2009 03:31 |
|
GregNorc posted:I've read stuff like this: http://docs.python.org/library/index.html If you want to understand the syntax on a deep level, that's what you want to read. Otherwise, the tutorial covers pretty much all the syntax. e: I'd rewrite your code to be code:
Scaevolus fucked around with this message at 03:40 on Dec 23, 2009 |
# ? Dec 23, 2009 03:36 |
|
Edit: Double Post
maskenfreiheit fucked around with this message at 20:34 on Mar 13, 2017 |
# ? Dec 23, 2009 05:29 |
|
Write a .bat file?
|
# ? Dec 23, 2009 06:38 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:21 on Mar 13, 2017 |
# ? Dec 23, 2009 17:49 |
|
I have a decorator that I want to pass the class of the method it is decorating, but I can not do "@typecheck(Window) because as expected I get a name error. I know I can just modify my typecheck decorator with some 'ismethod' switch to avoid checking self, but I am wondering if there is some other way I could do this.code:
|
# ? Dec 23, 2009 19:09 |
|
griliard posted:
You could do it like that, but to be forward compatible then I would use input(). The cool thing about input() is it wraps the input to a type, so if you type "1" into the prompt it will see that it is an integer and return an integer, as opposed to a string. That way you can change the code to this: code:
|
# ? Dec 23, 2009 22:25 |
|
tehk posted:I have a decorator that I want to pass the class of the method it is decorating, but I can not do "@typecheck(Window) because as expected I get a name error. I know I can just modify my typecheck decorator with some 'ismethod' switch to avoid checking self, but I am wondering if there is some other way I could do this. Not totally certain I correctly understand what you're trying to accomplish, but here goes. There's no need to pass the class name because it's already available in the decorator anyway. Your typecheck decorator should, fundamentally, look something like this: code:
code:
edit: hurr, now I realize what you're trying to do. Instead of passing Window (as in the class), pass 'Window' (string) and test against args[0].__class__.__name__ . MaberMK fucked around with this message at 22:48 on Dec 23, 2009 |
# ? Dec 23, 2009 22:41 |
|
Lobe posted:You could do it like that, but to be forward compatible then I would use input(). I'm going to object to this. I would not recommend using input() for almost any reason. Here's a fun little tidbit - try entering this as a value for any of those variables. code:
The input() function is equivalent to eval(raw_input()), which is dumb on a number of levels and really shouldn't have been included in the language at all. Using int(raw_input()) is safer, clearer, and more idiomatic. Randel Candygram fucked around with this message at 23:11 on Dec 23, 2009 |
# ? Dec 23, 2009 22:46 |
|
MaberMK posted:edit: hurr, now I realize what you're trying to do. Instead of passing Window (as in the class), pass 'Window' (string) and test against args[0].__class__.__name__ . Yeah that is a bit closer to what I am trying to do. I am just trying to check the types of some arguments and I want to factor it out into a decorator for ease of use. But the problem is I have no syntactically easy way of dealing with methods. My typecheck decorator looks like this: code:
tehk fucked around with this message at 23:04 on Dec 23, 2009 |
# ? Dec 23, 2009 23:01 |
|
GregNorc posted:Oops, I should have said - this would be for an OSX system. So the short answer is, no, not really.
|
# ? Dec 23, 2009 23:23 |
|
Yay posted:To the best of my recollection, OSX doesn't have anything that autoruns, hence CDs & DVDs mount onto the desktop, as do external or network drives. Windows also eschewed the ability to autorun things in XP until SP2, I think. A quick google search turns up launchd. http://discussions.apple.com/thread.jspa?threadID=1676188 Sounds like a bit of a hack but you can use it to launch a script when any volume is inserted.
|
# ? Dec 23, 2009 23:52 |
|
Edit: Double Post
maskenfreiheit fucked around with this message at 20:34 on Mar 13, 2017 |
# ? Dec 24, 2009 01:13 |
|
GregNorc posted:If anyone knows what I'm doing wrong, I'd appreciate a hint. Probably that you aren't reading the documentation for list.sort. (Also it helps to call the function in your interactive example.)
|
# ? Dec 24, 2009 01:19 |
|
|
# ? May 11, 2024 07:15 |
|
GregNorc posted:Horrible mess of a post x.sort is a reference to the sort method. You want x.sort(), which actually calls sort.
|
# ? Dec 24, 2009 01:25 |