|
I've got an interesting problem that I'd like to see if anyone can provide me some guidance on. I want to preface this all by saying that I've been learing Python as my first language and I'm still pretty new at it so please bear with me. We have an AD service account at work that requires it's password to be reset every morning at 8 AM. We have a script that currently does this but it's really finicky and fails more often that not. For this reason I decided to try and rewrite it in Python as a little project. So far I've only gotten as far as creating something that will generate a password that meets the complexity requirements: code:
That all being said has anyone used that particular module before and could give me some guidance with it or alternatively can you think of some other way for me to bind in order to make changes to the account?
|
# ? Jul 29, 2009 16:54 |
|
|
# ? May 9, 2024 05:12 |
|
BROHAMMER posted:[...] AD service [...] or [...] some other way for me to bind in order to make changes to the account? The ActiveState guys that do the ActivePython distribution provide a pretty seemless wrapper library for the native COM objects. You'll want to use that to give yourself access to the native ADS and WSH objects and work from there.
|
# ? Jul 29, 2009 16:57 |
|
outlier posted:*thumps head against desk* StringIO and cStringIO in 2.6 are byte-based -- if you're trying to insert Unicode strings, it's best to encode them to UTF-8 before writing them. Some Unicode strings might work, but that behavior shouldn't be relied upon (as you've discovered). In Python 3, StringIO operates only on Unicode, and BytesIO only on bytes, so this confusion doesn't exist.
|
# ? Jul 29, 2009 17:41 |
|
Short easy question: So I'm trying to learn PyGame, and in the aliens example I come across this: code:
self.image = self.images[0] and not self.image = Player.images[0] because to me it looks like you are assigning an instance member to a class member, so it would make sense you would scope the class member by the class name, and not by self. Looking it up, it seems you can do both, but I don't understand why it is ever done this way. Any explanation?
|
# ? Jul 30, 2009 16:48 |
|
Manner Please posted:Any explanation? Off the top of my head, I suspect you'd want to preserve your ability to reuse that code in a subclass. IE: code:
wins32767 fucked around with this message at 17:54 on Jul 30, 2009 |
# ? Jul 30, 2009 17:41 |
|
here's something I'm dealing with now, that I'm picking up an old project where I went hog wild with separate modules for everything: What's the best way to deal with command option information from something like optparse when your classes are in different files and need to see something? Currently, I'm passing the parsed tuple from optparse into the constructor of classes I know need it. Originally, I did an import from the main file and used them as globals in each function. similar to: from main_file import parsed_cl_options, parsed_cl_arguments where: (parsed_cl_options, parsed_cl_arguments) = OptionParserInstance.parse_args() I had also considered reparsing the command-line in each function, but that seemed bad.
|
# ? Jul 31, 2009 19:52 |
|
Alright I'm kind of getting kicked in the rear end trying to use Python for CGI scripting with my Hostgator account. Even a basic "hello world" script yields a 500 error. Here's what http://revenant1.net/cgi-bin/test.py looks like: code:
The server's running Python 2.4 last time I checked, in case that's relevant here for some reason.
|
# ? Aug 1, 2009 00:29 |
|
Try a couple of things: 1: check the permissions of the file. Make sure the script is executable. 2: change the file to test.cgi to see if apache (assuming) isn't aware of .py files 3: add this code: import sys sys.stderr = sys.stdout so you can see anything sent to stderr on the webpage. If you don't redirect stderr, it goes to the web logs.
|
# ? Aug 1, 2009 01:46 |
|
I already checked the file permissions beforehand, it was already set to 755 so that wasn't the issue. I tried both renaming it to test.cgi, and redirecting sys.stderr; no matter what I still get the 500 error here (.cgi) and here (.py) Both of these have stderr redirected to stdout.
|
# ? Aug 1, 2009 02:35 |
|
Why are you using CGI? I didn't realize anyone still used it.
|
# ? Aug 1, 2009 02:51 |
|
I don't plan on using it a whole lot, I mostly just want to figure out why the hell it's not working in the first place.
|
# ? Aug 1, 2009 02:56 |
|
king_kilr posted:Why are you using CGI? I didn't realize anyone still used it. Are you sure you know what CGI is? It's a standard in, for example, apache, used for simple scripts across the world.
|
# ? Aug 1, 2009 06:18 |
|
quadreb posted:Are you sure you know what CGI is? It's a standard in, for example, apache, used for simple scripts across the world. Umm, it may be a standard, but it's an old crappy one, designed in such a manner to inhibit both good programming practice and speed. You'll notice mod_php, mod_perl, mod_python, mod_wsgi, mod_fcgi, etc. are a good bit more popular.
|
# ? Aug 1, 2009 06:56 |
|
Yeah if memory serves me correctly you're firing up a new python process for every hit to the page with straight cgi.
|
# ? Aug 1, 2009 06:59 |
|
The only reason I'm using CGI for the time being is because I don't have access to mod_python with my current shared hosting plan, although I do have FastCGI available. I know this isn't the CGI megathread, but do any of you have experience using FastCGI? Is it worth using?
|
# ? Aug 1, 2009 08:15 |
|
Lurchington posted:What's the best way to deal with command option information from something like optparse when your classes are in different files and need to see something? Note that there's nothing especially Pythonic about this problem, it's a common design issue. There's a few ways you can go around this: 1. The central command class or function gathers the options and distributes them to more peripheral classes. You parse the options and then call "MyAppModel.set_options", which calls "DisplayController. set_options" and "DataReader. set_options" which may in turn call "DataParser. set_options", etc. Advantages: centralised control of options, no part of the program can see or effect options that don't concern it. Disadvantages: If you change or expand options, you have to walk your changes down the chain. And what if two parts of a program share options? Probably works better with smaller programs. 2. Have some sort of global settings / options object or class. See Django's settings and conf machinery for an example. Advantages: easy. Everything can get at everything. Scales well. Disadvantages: ohmigod, don't you now that globals are bad! Everything can get at everything! I'd tip my hat towards the second for most cases, especially as a program grows in size.
|
# ? Aug 1, 2009 09:09 |
|
acker posted:The only reason I'm using CGI for the time being is because I don't have access to mod_python with my current shared hosting plan, although I do have FastCGI available. (man, everyone thinks mod_python is the right apache module to use. mod_wsgi is The One.) Your best bet is to write the application in WSGI or use a WSGI framework, and then use a WSGI-fastcgi or WSGI-CGI adapter. You'll have more deployment options later if you want/need to change it, as well as be able to test out your application a little easier.
|
# ? Aug 1, 2009 13:00 |
|
acker posted:Alright I'm kind of getting kicked in the rear end trying to use Python for CGI scripting with my Hostgator account. Even a basic "hello world" script yields a 500 error. I think python is just hosed on hostgator. Back when I had an account I looked into getting some python stuff going, but eventually decided to just use another hosting service after reading all about people having troubles getting it working. Check their forum. I don't think a single person has gotten it working.
|
# ? Aug 1, 2009 13:39 |
|
nbv4 posted:I think python is just hosed on hostgator. Back when I had an account I looked into getting some python stuff going, but eventually decided to just use another hosting service after reading all about people having troubles getting it working. Check their forum. I don't think a single person has gotten it working. This is what I was afraid of. I had looked around the support forums a few times but every Python related thread I found pretty much boiled down to "use mod_python" which is only available if you're on a dedicated server. As for WSGI/fastcgi, that looks doable, I'll probably check that out later today and see if I get anywhere. Thanks for the suggestion.
|
# ? Aug 1, 2009 13:51 |
|
You can use Django with fastcgi http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/ Also if you must do cgi, make sure your setting your headers right.\ But yeah, go get yourself an account with something like slicehost so you can get your setup juuuust right. Your time is more valuable than making GBS threads around with crappy $5 hosts. A non crappy $20 vhost pays itself off in the first hour of saved time.
|
# ? Aug 1, 2009 17:45 |
|
duck monster posted:You can use Django with fastcgi Or if you prefer shared hosting/the low cost go with webfaction.
|
# ? Aug 1, 2009 18:54 |
|
Ok, I've decided to just make myself learn wtf classes are good for. I'm designing a script to take entries from my google reader shared items rss feed and do various things with each item like post it to a Twitter feed, Facebook, post it on a forum, etc... The problem is that classes seem kind of weird to me, and I'm having a hard time thinking about them with the right mind-set. This is my current thinking about some classes to use:
The second item I'm a little confused about. On the one hand it seems like I should make it a class because classes are cool, but on the other hand, I don't really see a reason for it to be a class as the things it does should only be done once each time my script is run. Basically, I'm just looking for some ideas and thoughts about how people with experience would design such a project.
|
# ? Aug 3, 2009 17:54 |
|
Why not just have a function that takes the URL and returns a list of instances of the item class?
|
# ? Aug 3, 2009 18:50 |
|
acker posted:Why not just have a function that takes the URL and returns a list of instances of the item class? Basically because I'm a noob to OOP and didn't know if it was bad form to mix functions and classes in such a manner. Of course, now that I think about it, I use regular Python objects all the time...
|
# ? Aug 3, 2009 18:51 |
|
Thermopyle posted:Ok, I've decided to just make myself learn wtf classes are good for. Models of data. However, in other languages they are the only major component. (I.e in java, they do namespacing too, etc...) so you end up using classes everywhere. quote:I'm designing a script to take entries from my google reader shared items rss feed and do various things with each item like post it to a Twitter feed, Facebook, post it on a forum, etc... As the poster above said, use a list of Item classes. In python it's easier to use the built in data types than creating your own. quote:The problem is that classes seem kind of weird to me, and I'm having a hard time thinking about them with the right mind-set. In a language like python, use classes where they are convenient. This frequently means custom data types with a handful of methods. (And It is often easier to use functions in python than methods. The big thing with classes is inheritance - being able to incorporate other classes into a new one. quote:Basically, I'm just looking for some ideas and thoughts about how people with experience would design such a project. If you're wanting a more common oo experience try Java or C#, or if you're feeling more traditional you can use Squeak/Smalltalk. The python oo experience is more of an option when coding python.
|
# ? Aug 3, 2009 19:00 |
|
For example, if you wrote a calculator, you could model the operations like so:code:
This can also be written as: code:
With the classes, you can keep the data specific code with the data itself.
|
# ? Aug 3, 2009 19:13 |
|
tef posted:In a stricter language, we would introduce an interface or an abstract class, and both Add and Num would inherit from it, as to be the same type. But Python already has abstract classes.
|
# ? Aug 3, 2009 20:13 |
|
Avenging Dentist posted:But Python already has abstract classes.
|
# ? Aug 3, 2009 20:21 |
|
tripwire posted:Sorry for being dumb but is this actually an idiom in python? It seems like it does what it advertises... if I did something like: from __builtin__ import pass as abstract at the top of that file, it wouldn't error Here's an actual PEP on the subject edit: and I just noticed there was a Python Module of the Week on abstract base classes: http://blog.doughellmann.com/2009/07/pymotw-abc-abstract-base-classes.html Lurchington fucked around with this message at 03:34 on Aug 4, 2009 |
# ? Aug 3, 2009 20:24 |
|
tripwire posted:Sorry for being dumb but is this actually an idiom in python? It seems like it does what it advertises... http://norvig.com/python-iaq.html
|
# ? Aug 3, 2009 20:25 |
|
tripwire posted:Sorry for being dumb but is this actually an idiom in python? It seems like it does what it advertises... No, it's not. raise NotImplementerError is the correct idiom.
|
# ? Aug 3, 2009 23:47 |
|
king_kilr posted:No, it's not. raise NotImplementerError is the correct idiom. Cool, thanks
|
# ? Aug 4, 2009 00:31 |
|
king_kilr posted:No, it's not. raise NotImplementerError is the correct idiom. code:
|
# ? Aug 4, 2009 15:26 |
|
I've tried to look online for this information but so far I've been unsuccessful. I am attempting to implement a rather large API. The method we're going with is to use standard getters and setters functions. Naturally this places right into the property() built-in. What I have been unsuccessful in coding / finding on google is a decorator or metaclass that allows to me condense the fget(), fset(), fdel() and doc arguments to property () so that I don't have classes completely loaded with dozens of (basically) duplicate functions. I see from the property link that I can use @property as a decorator for the fget(), but I'd really really like to have a way to do it for all 4 arguments to property (). Metaclasses get into python internals that I simply do not understand but the metaclass page says this: quote:The potential uses for metaclasses are boundless. Some ideas that have been explored including logging, interface checking, automatic delegation, automatic property creation, proxies, frameworks, and automatic resource locking/synchronization. Has anybody explored this? I'm tearing my hair out trying to understand metaclasses.
|
# ? Aug 5, 2009 00:21 |
|
If you're going to use set/get methods for all attribute access, that's not what property is for. Property is for special behavior on regular attribute access, so obj.attr = "foo" calls the setter method you've defined for attr instead of simply doing setattr(obj, "attr", "foo"). Unless that's what you meant. In which case you don't have to implement methods for the attributes that aren't going to do anything special on getting/setting. Now if you're talking about changing the default behavior of attribute access, you could override setattr/getattr, I think.
|
# ? Aug 5, 2009 00:48 |
|
spankweasel posted:I've tried to look online for this information but so far I've been unsuccessful. From the page: code:
|
# ? Aug 5, 2009 00:51 |
|
On the other hand, if you wanted to automatically make a bunch of getter/setter methods for your class maybe something like this would work:code:
|
# ? Aug 5, 2009 01:30 |
|
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." I don't care if using IDLE means that I have to repeatedly force-quit every time I use pygame...at least I can edit/run things.
|
# ? Aug 5, 2009 02:42 |
|
Kire posted:Try WingIDE.
|
# ? Aug 5, 2009 06:54 |
|
|
# ? May 9, 2024 05:12 |
|
Before 2.6 I didcode:
code:
|
# ? Aug 5, 2009 09:10 |