|
Lonely Wolf posted:But if you have Python 2.6, do what Tef said. In fact, all of you do what Tef says or my crew will jump you. If you need to sanitize settings or validate them, then getters & setters are ok (for example a phone number property that checks for valid area codes, etc). Properties are excellent for this. The problem is that for some classes, getters and setters are examples of things that break encapsulation, as logic often ends up in the classes calling them, rather than the classes themselves. The idea is that it is better to tell, don't ask. Pass the information to the class needed to do the work, rather than pull the information out. I don't know which applies for the classes the guy above is writings, so I'll avoid trying to apply dogma here, but I don't want to encourage some pitfalls in OO design.
|
# ? Aug 5, 2009 12:58 |
|
|
# ? May 9, 2024 15:23 |
|
Kire posted:Gosh, I've heard people say to use Netbeans or Eclipse, but I'm trying to load some simple scripts that refuse to work in IDLE (pygame's event.QUIT has never worked when I create and run things in IDLE, and I've been told it might be a Tkinter issue) and holy cow is this impossible. Both Netbeans and Eclipse adamantly refuse to let me run a script. In Netbeans, it just says "Hello" in a sub-window (not part of the program I'm trying to run) and eclipse just tells me it can't do it: "The selection cannot be launched, and there are no recent launches." netbeans defaults to having something like this line in new projects, maybe that's your problem? code:
|
# ? Aug 5, 2009 18:29 |
|
spankweasel posted:(Metaclasses and "automatic property creation" Has anybody explored this? I'm tearing my hair out trying to understand metaclasses. Some nifty, clever stuff has been done with metaclasses. However, I've begun to avoid using them because (a) they can be tricky to understand, (b) your code starts to be shaped by 'clever tricks' and odd metaclass idioms and (c) they're going away in Python 3000. I think "automatic property creation" is probably referring to stuff like Django uses in its models.
|
# ? Aug 6, 2009 08:48 |
|
After teaching myself some Python, I finally finished my A* algorithm program. Yes, it's basic, but I only have a few CS classes under by belt, so I'm proud. Added mobility to the start/stop nodes, but I broke it so no pictures of that. The app scales to any grid size, but after about 50x50 it begins to noticeably slow down. Haven't done any optimization yet, but thus far I'm proud with how much I've learned. I really do love Python so much. (in case it needs saying, black = open space, dark blue = walls, red = goal, green = start, light blue = best path) ((Yes, it looks like a swastika, no I'm not racist)) (((In my implementation I chose to disallow cutting corners of walls, which is why the path doesn't cut them to save distance))) My eventual goal is to take this module and implement it in a 2-d top-scroller of some sort.
|
# ? Aug 7, 2009 05:17 |
|
outlier posted:[metaclasses are] going away in Python 3000.
|
# ? Aug 7, 2009 05:28 |
|
Janin posted:What? No they're not. Metaclasses, especially abstract base classes, are a fundamental and useful feature of Python 3. Mea culpa - I mispoke. The metaclass _syntax_ and machinery is changing in P3000. Thus any fancy metaclass you do now will have to change. (There is a metaclass solution that works in Python 2/3 here, but it looks a bit clumsy to my eye.) nonathlon fucked around with this message at 09:00 on Aug 7, 2009 |
# ? Aug 7, 2009 08:54 |
|
I'm still trying to figure out the barebones of python web programming. I've only ever coded PHP for the web (although I have written a number of apps in python), and I am still having trouble breaking my brain from how easy PHP is. My latest frustration: How the gently caress do I access the query string? The closest I can find online is os.environ['QUERY_STRING'] - but that doesn't exist? What I've got: Lighttpd with mod_fcgi and flup. My little app looks like this: code:
code:
Please help, I've frustrated myself into a corner yet again... [EDIT] - I'm happy to learn on my own, but the documentation that I've found thus far doesn't actually explain anything. The actual python docs are great, but they don't seem to have anything to do with this. If you know where I can find documentation that has examples, I would be indebted to you. Also, please don't link me to this: http://www.wsgi.org/wsgi/ - I can't find anything of use in there (I don't even know if it's the right place). ShizCakes fucked around with this message at 14:31 on Aug 7, 2009 |
# ? Aug 7, 2009 14:24 |
|
ShizCakes posted:My little app looks like this: Take a look at myapp()'s argument list. You should notice that it takes an environ parameter. Instead of printing out os.environ.keys(), try printing environ.keys().
|
# ? Aug 7, 2009 14:32 |
|
Use a web framework rather than a collection of wsgi utilities? For example: http://webpy.org/
|
# ? Aug 7, 2009 14:35 |
|
Xenos posted:Take a look at myapp()'s argument list. You should notice that it takes an environ parameter. Instead of printing out os.environ.keys(), try printing environ.keys(). Thank you! I don't quite understand why that works, but it does. (Specifically, I am not passing an environ or start_response variable to myapp when I call it, so where is it getting them?) tef posted:Use a web framework rather than a collection of wsgi utilities? I'm trying this now. I don't get the concept of how this works. (the hello world example just puts out "not found"?). God, I swear I am not this retarded usually - I just wish there was something that explained the underlying concepts simply, or a guide to switching from php, or something.
|
# ? Aug 7, 2009 15:22 |
|
ShizCakes posted:I'm trying this now. I don't get the concept of how this works. (the hello world example just puts out "not found"?). God, I swear I am not this retarded usually - I just wish there was something that explained the underlying concepts simply, or a guide to switching from php, or something. Anyway, the idea is, with a traditional CGI script, and also with PHP, you call the script directly from the url - http://url/hello.py or http://url/showthread.php The way web.py and django and similar frameworks are supposed to be used, your script gets called with every url requested from the server - http://url/hello or http://forums.somethingawful.com/thread/2675400-python-information-and-short-questions-megathread. If you need static files served from the server, you make those exceptions (like /static/ in the lighttpd config on the web.py site) After that you're free to use Python concepts to decide how to deal with the URL - for example web.py uses its url rules to decide what class to will render the page. In the Hello World example on the web.py front page, http://url/hello is a valid url and everything else is a 404. This is a good excuse to link this. Threep fucked around with this message at 15:47 on Aug 7, 2009 |
# ? Aug 7, 2009 15:44 |
|
Django is another webframework that is pretty popular and has an amazing tutorial
|
# ? Aug 7, 2009 16:32 |
|
Threep posted:Explain what you've done/not done and what the actual error is, it's hard to help you when we don't know what isn't found. First, thanks for your quick explanation. I am on board with that concept (mostly - I wish I had a choice, because sometimes I don't need things to be that complicated, or I want to run multiple apps easily, or a million other things) Anyways, the problem that I am having now seems to be the way that web.py does it's URL matching or whatever. With this simple code: code:
If I change '/test.py' to '.*', it works - but I can't figure out what actual string it wants to match against. "test.py", "/", "./test.py" all output "not found". Going to a different path like https://www.example.com/BONK returns the proper server 404. Note that I am not routing all requests to test.py at the moment - I just want to test some stuff and play around.
|
# ? Aug 7, 2009 16:58 |
|
code:
Also, if it actually was /test.py you should do this: code:
|
# ? Aug 7, 2009 17:16 |
|
Threep posted:
The answer, after much loving around, is an empty string. My theory was that it's not matching any URL - it's just itself. I really wish there was good documentation on this stuff. I prefer not to use django, yet, because - as painful as it is for me right now, I want to learn some of the 'lower level' of this before it's all abstracted away.
|
# ? Aug 7, 2009 17:27 |
|
ShizCakes posted:Thank you! I don't quite understand why that works, but it does. (Specifically, I am not passing an environ or start_response variable to myapp when I call it, so where is it getting them?) I see you've already moved on from this, but I feel compelled to respond: You never called myapp, you passed it to WSGIServer(). It sets up the environ and calls your function for each request. If you're just coming to Python, I suggest you do yourself a favor and stay away from the low level machinations of WSGI and use a framework. Not that WSGI is bad - it's a great way to host applications - but developing on it directly can be tedious. Once you get to the point of deploying your app, regardless of the framework, I recommend taking a look at mod_wsgi. Also, I personally recommend using Django.
|
# ? Aug 7, 2009 17:27 |
|
Milde posted:I see you've already moved on from this, but I feel compelled to respond: I'm glad you did, and I appreciate it. The idea of what's going is much clearer - right now, I am really just interested in understanding even more than being productive. Unfortunately, I am in a place where I can't trace out what's going on so little things are throwing me for a loop. I'm not a professional coder or anything, but I do like it anyways.
|
# ? Aug 7, 2009 17:36 |
|
king_kilr posted:No, it's not. raise NotImplementerError is the correct idiom. A little late, but no, that's not the correct idiom. Raising NotImplementedError breaks correct use of super(). This is what abc.abstractmethod is for, if you're using python 2.6+. Otherwise, just make your method do nothing.
|
# ? Aug 9, 2009 08:43 |
|
I feel really stupid but I'm not really used to this language... how do you change parts of a string? What I want to do is basically like: mystring[40] = 'i' at a few select places. what's the best way to go about it? the whole string can get up to a few megabytes so ideally i wouldn't want to copy it around too much. Do i have to split it up then merge it again?
|
# ? Aug 9, 2009 12:26 |
|
Mata posted:I feel really stupid but I'm not really used to this language... how do you change parts of a string? Strings in python are immutable. The best you can do is create a new string that is a variation on the original. Maybe something like this: code:
|
# ? Aug 9, 2009 15:15 |
|
Thermopyle posted:Strings in python are immutable. The best you can do is create a new string that is a variation on the original. Yeah that's what I ended up doing, trying not to think too much about the efficiency
|
# ? Aug 9, 2009 15:22 |
|
Mata posted:Yeah that's what I ended up doing, trying not to think too much about the efficiency code:
|
# ? Aug 9, 2009 18:11 |
|
I'm working on something that involves downloading a queue from a small number of different connections (say, 5 or so) to different files What's the best way to go about this? I've looked at:
And for the sake of learning - if I was downloading from 50/100 connections and/or to one file, what would the answer be?
|
# ? Aug 10, 2009 15:38 |
|
Threep posted:I'm working on something that involves downloading a queue from a small number of different connections (say, 5 or so) to different files Use threading - you're I/O/Socket bound.
|
# ? Aug 10, 2009 16:21 |
|
This is probably a really stupid question, but I'm in the middle of learning Python as my first programming language with A Byte of Python and I'm stuck on this lesson According to the lesson when I import the using_sys.py script I should get a result that looks like this: code:
The command line arguments are: The PYTHONPATH is ['', 'C:\\Windows\\system32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26\\Lib\\site-packages\\pythonwin', 'C:\\Python26', 'C:\\Python26\\lib\\site-packages', 'C:\\Python26\\lib\\site-packages\\win32', 'C:\\Python26\\lib\\site-packages\\win32\\lib', 'C:\\Users\\Jordan\\Desktop\\diveintopython-5.4\\py'] and when I run it I get this: The command line arguments are: C:\Users\Jordan\Desktop\diveintopython-5.4\py\using_sys.py The PYTHONPATH is ['C:\\Users\\Jordan\\Desktop\\diveintopython-5.4\\py', 'C:\\Windows\\system32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26\\Lib\\site-packages\\pythonwin', 'C:\\Python26', 'C:\\Python26\\lib\\site-packages', 'C:\\Python26\\lib\\site-packages\\win32', 'C:\\Python26\\lib\\site-packages\\win32\\lib', 'C:\\Users\\Jordan\\Desktop\\diveintopython-5.4\\py'] I'm using PythonWin to code and run everything, if it matters.
|
# ? Aug 10, 2009 23:58 |
|
It looks like it's running fine except you didn't pass it any command line arguments and you're running it on windows instead of a *nix. There does not appear to be a problem. What do you think is wrong? Try running it from the command line like code:
|
# ? Aug 11, 2009 00:12 |
|
I want to develop a small ad network system, I've worked out the logic behind how it will work and have mapped out functions, checks, etc. Problem is I am not really a programmer. I'm the opposite of an average programmer: I don't know poo poo about syntax but I know how to keep good practices (writing up specs, keeping view, model, and data seperate, making sure user input is cleansed, etc. I have heard some pretty great things about python and specifically Django. What would be a good book to read regarding this? People keep telling me to read the Python Docs, but I can't really learn by reading docs on my monitor, I need printed word. Any recommendations for good, hands on, learn-by-doing books on Python and Django for someone who knows how to code well but doesn't know how to code?
|
# ? Aug 11, 2009 05:30 |
|
Sparta posted:I want to develop a small ad network system, I've worked out the logic behind how it will work and have mapped out functions, checks, etc. Problem is I am not really a programmer. I'm the opposite of an average programmer: I don't know poo poo about syntax but I know how to keep good practices (writing up specs, keeping view, model, and data seperate, making sure user input is cleansed, etc. I've never used django but it might make sense to pick up a basic python book before diving into a framework. I started with "Learning Python" but have heard good things about "Dive into Python." http://www.pythonchallenge.com is worth a look to get some hands on experience. Once you have the basic understanding you should pick up one of the many django books. Someone can call me out on this if they feel it's bad advice.
|
# ? Aug 11, 2009 16:35 |
|
Sparta posted:Any recommendations for good, hands on, learn-by-doing books on Python and Django for someone who knows how to code well but doesn't know how to code? I and two other gentlemen wrote a Django book which includes a large early chapter on Python, so that you can learn enough Python to get off the ground and handle the rest of the book: Python Web Development with Django Not entirely sure if your situation is the exact target audience (which is to say, people who know how to code but not necessarily well *cough*average PHP coder*cough*) but as long as you know enough about programming to know what a loop is and what a variable is, you should be fine. Otherwise, aforementioned Dive into Python is good stuff for learning Python, and the Django team has an official book out in print for that topic (and online for free, but if you want a book-book, obviously get the hard copy.)
|
# ? Aug 11, 2009 21:55 |
|
I'm new to python, but I've written a long program and it has an issue. Basically it copies a template web page, and makes 10 copies of it with different first paragraphs. Because I'm new, this has ended up being a fairly long program. When I run it, it gets through each copy fine until it get to the last one. It only manages to copy the last page half way. If I swap the programming for the 9th and 10th copies, then the 9th only gets halfway, so I know its not the actual code that's the problem. Is there a maximum length for a python program? That seems highly unlikely. (The code's a couple of hundred lines long max) Any ideas? E: This was written in IDLE 2.6, by the by. Also, I've got a punctuation checker that only actually works if I open it and hit f5 in the IDLE editor, but not if I just double click on it, running it through command prompt. It's only 4 seconds of effort, but it still seems like that shouldn't be right? TheMaskedUgly fucked around with this message at 23:58 on Aug 11, 2009 |
# ? Aug 11, 2009 23:54 |
|
TheMaskedUgly posted:I'm new to python, but I've written a long program and it has an issue. Post the code.
|
# ? Aug 11, 2009 23:55 |
|
TheMaskedUgly posted:I'm new to python, but I've written a long program and it has an issue. Not enough info. Post the code. Also, a couple of hundred lines isn't long at all, so don't worry about that.
|
# ? Aug 12, 2009 00:04 |
|
This is my first non 'hello world' program so go easy. There are 10 copies of this, with the A replaced with B etc, preceeded by a chunk that copies the template to the temp file. If you need anything else say. Didn't make this clear, but it reads the template from a text file, as well as the different first paragraph, title, and reference numbers, each from seperate text files. Temp01 = the files locations etc. code:
TheMaskedUgly fucked around with this message at 00:07 on Aug 12, 2009 |
# ? Aug 12, 2009 00:05 |
|
Just throw the whole thing on pastebin or something and link us. Also if you catch yourself getting ready to copy and paste code slam your hand in a door until you learn not to do it. If only a couple things vary between all those different blocks opening a file and closing it, make a list and go through them with a loop.
|
# ? Aug 12, 2009 00:25 |
|
http://pastebin.com/m7eea8442 There's the first program. The original program was identical except it went all the way to the 10th copy and finished. To make the two programs, I copied the beginning section and initialising crap, and then cut out the last 5. It works now in two sections.
|
# ? Aug 12, 2009 00:31 |
|
bitprophet posted:Otherwise, aforementioned Dive into Python is good stuff for learning Python, and the Django team has an official book out in print for that topic (and online for free, but if you want a book-book, obviously get the hard copy.) Small correction. The Django Book is not by the Django team, it is by Adrian Holovaty and Jacob Kaplan-Moss, it is a private enterprise and is unaffiliated with either the Django Project or the Django Software Foundation.
|
# ? Aug 12, 2009 00:38 |
|
TheMaskedUgly posted:http://pastebin.com/m7eea8442
|
# ? Aug 12, 2009 14:38 |
|
TheMaskedUgly posted:http://pastebin.com/m7eea8442 I'm pretty sure this replaces that entire monstrosity: code:
deedee megadoodoo fucked around with this message at 19:47 on Aug 12, 2009 |
# ? Aug 12, 2009 15:17 |
|
If I write code:
code:
0 1 2 3 4 if my list has 5 elements.
|
# ? Aug 12, 2009 17:43 |
|
|
# ? May 9, 2024 15:23 |
|
code:
0: . . . 1: . . . 2: . . . and so on
|
# ? Aug 12, 2009 17:51 |