|
Bonus posted:Haha! Yes, clown coding is the best coding. Is there a reason you can't make 'clowns' a global? Unless I'm misunderstanding some implementation-specific need, a global variable should probably do the trick.
|
# ¿ Jan 9, 2008 03:32 |
|
|
# ¿ May 5, 2024 16:07 |
|
karuna posted:Hey, how do you pass a variable within a URL? Check out the official documentation on urllib and urllib2 (http://docs.python.org/lib/module-urllib2.html) specifically the part about urllib2.urlopen() and urllib.urlencode(). That should answer most of your questions. I've worked with these libraries extensively and have encountered pretty much every conceivable problem that could come up with them. deedee megadoodoo fucked around with this message at 18:53 on May 10, 2008 |
# ¿ May 10, 2008 18:35 |
|
Spazmo posted:Ah, that's great. Thanks very much! Also try http://docs.python.org/lib/lib.html and http://docs.python.org/modindex.html
|
# ¿ Jun 11, 2008 12:55 |
|
Is there any way to call a function that expects a number arguments with a list of those arguments without resorting to this:code:
And yes, I am aware of the many alternate methods to get a timestamp from the DBAPI, this just came up in something I was working on and I wanted to know if there was a pretty way to call the oracle.Timestamp() function without doing "date[0],date[1],..." deedee megadoodoo fucked around with this message at 13:23 on Jun 24, 2008 |
# ¿ Jun 24, 2008 13:20 |
|
I know when I first started working with python I had read something about how to call a function with a list of arguments but I couldn't for the life of me remember what it was. Thanks to both of you.
|
# ¿ Jun 24, 2008 13:45 |
|
I own Python in a Nutshell and Learning Python. I use Python in a Nutshell on an almost daily basis even though it only covers version 2.2. I just supplement with the online docs. After finishing Learning Python I never looked at it again (even though I could probably stand to brush up on some of the basics again). It sounds like you want a combination of both of these. I don't think that exists. Or if it does, I haven't found it. The only book for any language that I can think of that really covers both of those bases is Thinking in Java/C++. If only Bruce Eckel wrote Thinking in Python (and not the electronic version available at his website, that was last updated in 2001 and isn't as comprehensive as his other works).
|
# ¿ Jun 26, 2008 21:17 |
|
Recommending Django for writing simple cgi scripts is a bit overkill don't you think? I've used a variety of methods for writing web applications and I like mod_python the most. web.py and other cgi modules feel clunky to me. I guess it's personal preference, but mod_python makes writing cgi in python feel more like python.
|
# ¿ Jul 1, 2008 12:33 |
|
Milde posted:I would personally never ever ever use mod_python if I could avoid it. Its poorly documented code caching (which can be inconsistent across the processes it loads) is probably the most frustrating thing I've ever had to deal with when testing code. And to make matters worse you can't really test applications developed for mod_python outside of mod_python. It's a loving framework too. I've run into the caching problem a few times, but it's really only been an issue if I'm developing on a live environment and constantly changing the code. Usually I develop on another box, deploy the app and hup apache. As for not being able to test applications outside of mod_python, you can't really test PHP apps outside of mod_php either or JSP's outside of a java application server so I don't really understand where you're going with that one.
|
# ¿ Jul 2, 2008 11:22 |
|
I ran into an issue when attempting to retrieve a slice from a container class I had created. The docs seem to imply that __getslice__() has been deprecated since 2.0 so I didn't bother to declare it in my class definition. However, once I added it my code magically worked. What gives? I can see why it would be deprecated as __getitem__ should be enough to pull a slice. But why is that bit about deprecation in the docs if I still have to declare it? Is that just wishful thinking?
|
# ¿ Jul 8, 2008 17:22 |
|
bitprophet posted:In a semi related note, I'm embarrassed to admit that I only really "got" PEP8 about a month or two ago (despite being primarily a Python coder for the past 4 years), and until then would sort of haphazardly mix things up. Still not a PEP8 saint but I've got the basics (e.g. foo, bar instead of foo,bar) down pat and it actually does make a difference in terms of the overall feel of the code. I've been using Python for about 2 years and I've been using nearly everything in PEP8 since the beginning, probably due to the book I was learning from (Learning Python). The only thing I had been doing differently was using lowerCamelCase for variable names. I just switched to underscored variables and it *feels* more Pythonic. Which probably sounds weird. But it does. I don't know.
|
# ¿ Jul 15, 2008 11:48 |
|
I wanted to contribute to this thread because I use python a ton. I was reading a few pages back and saw there was some confusion about how to implement decorators so I figured I'd post two that I've used fairly recently: The first example wraps a function in some log messages that will tell you when a function starts and when it ends and what values it took as arguments. I've used this quite a bit in a threaded application to track down some bugs I encountered and changed the "print" statements to logging calls when it went into production. Just add "@log" above your function declaration to make it work. code:
code:
|
# ¿ May 27, 2009 14:05 |
|
Can anyone explain in small words how the gently caress to use ZSI to access a SOAP service with WSDL? Using the SOAPpy module this is simple as all hell... code:
send ha;lp
|
# ¿ Jun 3, 2009 14:45 |
|
tef posted:I have never had any success with python soap implementations I would much rather use xmlrpc but that option isn't available. It makes me a sad panda.
|
# ¿ Jun 3, 2009 16:32 |
|
HatfulOfHollow posted:Can anyone explain in small words how the gently caress to use ZSI to access a SOAP service with WSDL? I figured out that the actual issue I was having is that ZSI makes assumptions about the format of the wsdl document. ZSI tries to read ahead on certain node types because it assumes that those nodes have children, which causes all kinds of errors. It's some hosed up xml parsing that makes no sense. Just walk the doman tree you loving loonies. In any case I switched to suds. It does everything I need (correctly) and seems to be recent and/or at least maintained a bit better. It even supports http proxies and wsdl that doesn't live at the same address as the service.
|
# ¿ Jun 4, 2009 20:00 |
|
I've done something stupid but for the life of me I can't figure out what. code:
deedee megadoodoo fucked around with this message at 17:12 on Jun 14, 2009 |
# ¿ Jun 14, 2009 17:10 |
|
tef posted:I don't think self = {} does what you think it does poo poo. You're right. I was trying to empty the ProcessList dict and hosed myself.
|
# ¿ Jun 14, 2009 17:39 |
|
CentOS has a server distribution that fits on a single CD. It doesn't include x windows so you should probably be comfortable with the command line before you download it.
|
# ¿ Jun 18, 2009 11:49 |
|
LuckySevens posted:Is there an alternative to mod_python, since I'm running 2.6? I found some vague info from google on how to alter the install, but I can't get it to work. It depends on what you're trying to do with it. If you're looking to find something like the python publisher handler you can probably use zope but I've never used it personally so I can't say what the real differences are. If you wanted to use mod_python to access apache via handlers for each step I don't think there is an alternative to mod_python. But if all you're trying to do is write CGI scripts, you can just stick a "#!/bin/env python" at the top of your script and drop them in a directory with +ExecCGI.
|
# ¿ Jun 22, 2009 15:54 |
|
PrinceofLowLight posted:Newbie with python. I'm trying to automate a repetitive task, analyzing some data that's too big to put in Excel. The text files range from 6-30 megs. It usually crashes notepad too, but opens with wordpad. Will Python be able to handle this? Python isn't a front end like notepad. You'll be able to open any file as long as your machine has the memory for it and you've coded the operations correctly. PS - notepad can't open the file because it has a limit on file size. Wordpad has a much higher limitation, if it has one at all. edit: also, for what you're describing you really only need to read one row at a time, which is fairly trivial. deedee megadoodoo fucked around with this message at 21:59 on Jul 5, 2009 |
# ¿ Jul 5, 2009 21:48 |
|
ATLbeer posted:
Since a tuple is immutable you can wrap your time in parens and use a normal dictionary. x = {} x[(12345678910,)] = "hello thar"
|
# ¿ Jul 17, 2009 09:53 |
|
checkeredshawn posted:It turns out that even though I figured out the pygtk problem I had asked about above, I can't figure out one of the other problems that goes like this: Instead of using a list, if you use a dictionary you can do this pretty simply. code:
|
# ¿ Jul 22, 2009 11:11 |
|
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 |
|
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 |
|
TheMaskedUgly posted:You people and your making me look bad. I'll have a look over those, and if they work, I love you. Even if they don't I appreciate the effort. Thanks, really. That's actually surprising. I didn't even test mine. I wrote it in notepad after tracing the original script in my head. I'm a badass.
|
# ¿ Aug 13, 2009 01:15 |
|
NadaTooma posted:Yeah but mine calls strip() so it doesn't embed extra newlines. creating a working script without testing > using strip()
|
# ¿ Aug 13, 2009 15:26 |
|
Habnabit posted:Twisted! Anything else is just dumb. (Short of reimplementing twisted yourself, which is dumb for other reasons.) Threading would just add a lot of overhead: code complexity overhead and CPU overhead both. I can write a multi-threaded application with no problem but for some reason twisted just confuses the hell out of me. I think it's the layer of abstraction. Not seeing exactly what's going on behind the scenes makes it harder for me to understand.
|
# ¿ Aug 13, 2009 19:46 |
|
TheMaskedUgly posted:Say I've got a list of values, in this form: If every value starts with the word "reference," has a string of numbers and then a single letter at the end you can extract the number and letter with this... code:
|
# ¿ Aug 24, 2009 13:39 |
|
nbv4 posted:Anyone have any experience with the csv module? I have a csv file that, after so many lines, switches headers. Like this: How about reading through the whole file first and marking the header sections since you know how to identify them. Then seek(0) and start reading until you reach your next header. At that point recreate your DictReader and it might pick up the next header. Not sure if this works, but its worth a shot. Alternatively subclass "reader" and alter the next() method to inspect the new line to see if it's a header.
|
# ¿ Aug 24, 2009 22:11 |
|
duck monster posted:Yay debian! I love it when people quote things without context.
|
# ¿ Aug 26, 2009 11:28 |
|
duck monster posted:Whats there to say? 2.6 won't be in the next debian. And? [root@ashprdmon04 nagios]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.3 (Tikanga) [root@ashprdmon04 nagios]# rpm -q python python-2.4.3-24.el5
|
# ¿ Aug 27, 2009 12:24 |
|
duck monster posted:Well thats poo poo too. Its a problem, because it slows adoption of 2.6/3.0 and that means python devs have to keep supporting legacy code bases, and provides disincentives for people to modernise their code for the superior 2.6/3.0 branches. I completely agree. But I've just started accepting that Redhat is going to be slow to adopt new versions of anything, even if it offers vast improvement. Hell, we're still building some boxes with RHEL4 and those REALLY suck... -bash-3.00$ cat /etc/redhat-release Red Hat Enterprise Linux AS release 4 (Nahant Update 4) -bash-3.00$ rpm -q python python-2.3.4-14.2
|
# ¿ Aug 28, 2009 13:55 |
|
I just want to add the one of the main problems I encountered with twisted is that in every release they are drastically changing the API. Because of this, the twisted book and a lot of the examples you find online are hilariously/frustratingly dated.
|
# ¿ Sep 14, 2009 22:23 |
|
I'm trying to write a handler using mod_python that will process all requests on a specific directory and perform some action before serving the originally requested file. Is this possible? I'm really only familiar with the mod_python publisher which is a completely different animal.
|
# ¿ Nov 12, 2009 19:55 |
|
aSSbAG. posted:Hey guys, just decided to learn python. I used to consider myself a pretty good VB6 programmer, and was waiting for microsoft to realize what a huge mistake they made with VB.net, yeah I got tired of burning that torch. Python 3.0 is a huge departure from 2.x and as such many libraries need to be updated to do things the new way. You need to either get the latest 2.x release or wait until Pyglet supports 3.x. I'm not sure why that information isn;t front and center on the Pyglet website. But yeah, that's a pretty terrible message that doesn't describe the actual problem.
|
# ¿ Nov 14, 2009 00:14 |
|
Avenging Dentist posted:Also I really question the notion that Py3k is a "huge departure" from Python 2.x. There are some important differences, but it's still more-or-less the same syntax, and the number of stuff that changed (as opposed to being added) could probably be summed up in a page. Probably. I'm still developing for 2.3 so for me it feels much bigger than for everyone else.
|
# ¿ Nov 14, 2009 00:59 |
|
Thermopyle posted:Shelf is a shelve. I'm storing my object on disk. I'm confused why you would want to store the object in the shelf. It really doesn't make much sense to me.
|
# ¿ Nov 28, 2009 22:48 |
|
Thermopyle posted:That's how the shelve module works. No I mean, why do you need a save method? Why can't you just do code:
|
# ¿ Nov 29, 2009 11:08 |
|
xmlrpclib is built in and standard and easy as gently caress to use. You can even use it inside apache if you don't want to write your own daemon.
deedee megadoodoo fucked around with this message at 21:34 on Aug 10, 2013 |
# ¿ Aug 10, 2013 21:30 |
|
You need to read up on scope. The simplest explanation is that the variables within a certain scope (in this case the function) only exist within that scope. However, the function has access to outside variables in the greater scope. So for example: code:
however code:
There is a lot more to it, but hopefully that makes sense.
|
# ¿ Aug 14, 2013 04:18 |
|
|
# ¿ May 5, 2024 16:07 |
|
Couldn't you encapsulate your code within a class then pickle it and send it across via rpc? I'm pretty sure I did something similar for a custom nagios NCSA replacement a while back.
|
# ¿ Aug 15, 2013 14:10 |