|
Ah yeah, glad we got this cleared up. I knew about accessing variables from parent namespaces. They're planning to implement a keyword called nonlocal, which would allow you to alter parent namespaces, which I think is pretty cool but isn't as cool as real closures.
|
# ? Feb 11, 2008 21:30 |
|
|
# ? May 4, 2024 10:59 |
|
ATLbeer posted:This might warrant it's own thread but, I'm having problems with both Python24 and 25 installed on my Mac. No need to remove one or the other - they can co-exist nicely. And some software *cough*Zope*cough* can't use 2.5. It's odd about the install and execution going to different pythons. Type in "which python" at the terminal to see what your default Python is. (I'm guessing 2.5.) Do you have any execution line at the top of your scripts like "#/usr/bin/python24"? Finally, is there an alias or symbolic link to python anywhere that you might have made? nonathlon fucked around with this message at 12:59 on Feb 12, 2008 |
# ? Feb 12, 2008 12:22 |
|
outlier posted:No need to remove one or the other - they can co-exist nicely. And some software *cough*Zope*cough* can't use 2.5. Thanks for the reply. I figured out the problem. I had installed MacPorts and it had put an ugly 2.4.4 version on top of 2.4 and 2.5 and injected itself into my profile. Took MacPorts out and it went back to normal again Thanks though
|
# ? Feb 12, 2008 21:48 |
|
ATLbeer posted:Thanks for the reply. I figured out the problem. I had installed MacPorts and it had put an ugly 2.4.4 version on top of 2.4 and 2.5 and injected itself into my profile. Took MacPorts out and it went back to normal again Same thing happened to me, except with fink. One of the reasons I stopped using fink.
|
# ? Feb 13, 2008 13:31 |
|
outlier posted:Same thing happened to me, except with fink. One of the reasons I stopped using fink. You guys know you can safely run multiple versions of Python on the same machine? You just have to set them up right, and choose which version you want to be your generic system-wide install.
|
# ? Feb 13, 2008 18:54 |
|
porkface posted:You guys know you can safely run multiple versions of Python on the same machine? You just have to set them up right, and choose which version you want to be your generic system-wide install. This man speaks truth: I have several versions installed on my mac. I just twiddle my bash_profile to point to the one I want.
|
# ? Feb 14, 2008 04:17 |
|
porkface posted:You guys know you can safely run multiple versions of Python on the same machine? You just have to set them up right, and choose which version you want to be your generic system-wide install. I'm aware, thanks. It wasn't the Python alone (once I knew about that I could work it out) but dealing with similar problems with other apps and libraries, and making sure that things that relied upon the fink versions could find the fink versions and those that wanted non-fink ... One reason to be grateful for the framework builds under OSX - it keeps everything nice and separated and easy to find. I've got 3 versions of Python installed currently with no problems.
|
# ? Feb 14, 2008 10:26 |
|
On to other topics: web development in Python. I've got a couple of web-applications (or rather, applications and databases that need a web front-end). It makes sense for all the logic to be in Python, rather than mix-and-matching languages and models. So what are people's experiences with Python webwork? My own (limited) experience: * Zope / Plone: I've done a lot of work with these and would advise anyone think strongly before before getting into them. You get a lot with Zope / Plone (default content presentation, ubiquitous and finely grained security, administrative tools, combining multiple applications / tools / products in the one web front). But they're tools that are a way of life - you have to dedicate a lot of time to get the framework to do anything, and I commonly spend more time wondering how to get Zope to do what I want, rather than solving the domain problems. And arguably Zope-Plone gets in the way of the development process, making it difficult be Pythonic and bang out some quick code to see how things work. * Pylons: The Pylons philosophy looks good (use anything you want with our framework), but I've seen argued that this actually means that Pylons provides you with drat-all. Nonetheless, it seemed to work okay and I've been thinking about this for a dedicated web-service (as opposed to a general CMS). * Django is the officially blessed framework. My one (and major) quibble is that it's using it's own database layer and ORM, which defeats the point if you have your own database layer already laid out (as I do). And Django's efforts at integrating SQLALchemy appear to have gone nowhere in 2 years. * Webware has finally tottered out from it's coma and looks cool. * I worked through the Turbogears book and it all seemed simple but (1) can it go beyond simple things, (2) with Turbogears 2 being mooted, this may not be a good time to commit. Opinions?
|
# ? Feb 15, 2008 14:11 |
|
outlier posted:* Django is the officially blessed framework. My one (and major) quibble is that it's using it's own database layer and ORM, which defeats the point if you have your own database layer already laid out (as I do). And Django's efforts at integrating SQLALchemy appear to have gone nowhere in 2 years. I thought part of Django's charm was that it didn't force you to use anything you didn't want to. So if you wanted to use a different db layer/ORM then you could.
|
# ? Feb 15, 2008 14:55 |
|
SmirkingJack posted:I thought part of Django's charm was that it didn't force you to use anything you didn't want to. So if you wanted to use a different db layer/ORM then you could. Yup. This is a major misunderstanding about Django; it is loosely coupled by design. Yes, you lose the contrib apps (admin, auth, etc) and generic views, but it still works perfectly fine in terms of URL dispatch, view functions and template rendering. Now, given that the contrib stuff is a large part of what people like about Django, it's fair to say that you prefer how TG or Pylons does things at that level (when Django is "only" the URL dispatch + views + templates) but it's entirely possible to use Django sans its ORM, and it's designed that way on purpose.
|
# ? Feb 15, 2008 17:13 |
|
outlier posted:* Pylons: The Pylons philosophy looks good (use anything you want with our framework), but I've seen argued that this actually means that Pylons provides you with drat-all. Nonetheless, it seemed to work okay and I've been thinking about this for a dedicated web-service (as opposed to a general CMS). Pylons being a "collection" of separate components is a load of poo poo. It's all tightly coupled together and about the only place you really get any freedom is in OR mapping. It touts being WSGI-based but it abstracts away WSGI to the point of it being irrelevant. You see other projects writing "adapters" just for Pylons compatibility. And not to mention it's poorly documented, and just poorly designed all around. It's like they went out of their way to make their framework as complicated as possible.
|
# ? Feb 15, 2008 17:57 |
|
Hey I was wondering, what way do you guys use of getting a class from a string? I've been doing it in a fairly convoluted way and really think there's an easier way.
|
# ? Feb 15, 2008 20:50 |
|
deimos posted:Hey I was wondering, what way do you guys use of getting a class from a string? I've been doing it in a fairly convoluted way and really think there's an easier way. You mean serialization? There are a couple of ways: the shelve and pickle modules that are built in will do it for you fairly easy and there are a number of other ways as well.
|
# ? Feb 15, 2008 22:35 |
|
No Safe Word posted:You mean serialization? There are a couple of ways: the shelve and pickle modules that are built in will do it for you fairly easy and there are a number of other ways as well. Nah, I am more thinking for settings and class loading. Like storing the name of the class you're supposed to use for a certain task on a settings file as a string then loading the correct class. Right now I use an eval and I really don't like it.
|
# ? Feb 15, 2008 22:49 |
|
deimos posted:Nah, I am more thinking for settings and class loading. Like storing the name of the class you're supposed to use for a certain task on a settings file as a string then loading the correct class. Right now I use an eval and I really don't like it.
|
# ? Feb 15, 2008 23:00 |
|
lilbean posted:I've been trying to find this too (basically the equivalent of a lot of the Java reflection API). Can you guys elaborate more on the background of wanting to do things this way / what problem needs solving? On the face of it it sounds sort of icky / un-Pythonic, to me, but I don't want to be judgemental until I know more. I can say that generally when I hear someone wanting to make code-loading decisions based on a string, the answer is either getattr()/dict key access, or __import__(). Edit: vvv That works too - globals() and locals() exist for a reason. Just try not to alter them, I think that's generally a big no-no bitprophet fucked around with this message at 00:00 on Feb 16, 2008 |
# ? Feb 15, 2008 23:08 |
|
I would use a metaclass (or a decorator, although I don't think class decorators are done yet) to add all class names to a dictionary as they're created, then just look up the class in the dictionary.code:
code:
code:
JoeNotCharles fucked around with this message at 23:51 on Feb 15, 2008 |
# ? Feb 15, 2008 23:48 |
|
Does anyone know of any 64-bit python database back-ends for windows? I've just installed Vista x64 and this has put a stop to my django tomfoolery. I prefer postgres but any database will do at this stage. Looks like I'll have to run it in vmware again edit: even if someone can explain what I'll need to do to compile a 64-bit version of win-psycopg I'd be grateful. http://www.stickpeople.com/projects/python/win-psycopg/index.html
|
# ? Feb 17, 2008 14:07 |
|
I really loving wish the Python people would use an open source compiler (ie gcc) for its windows distros. It pisses me off into near nerd-rage when I need to compile poo poo for windows but woops don't own Visual studio, and I can't get it to work with the express one worth poo poo. This has been a show stopper for me numerous times now, and makes me want to summon robot-stallman to shoot motherfuckers dead.
|
# ? Feb 17, 2008 15:50 |
|
Any idea how I can get python to read and show umlaut characters from a file properly? My file is called data and contains only: ö My python program: import string, msvcrt, sys myfile=open("data") print myfile.readlines() When I run it, I get (in the XP command prompt) C:\Python\test>test.py ['\xf6'] Replacing the umlaut with a plain x in the "data" file works OK: C:\Python\test>test.py ['x'] I suspect it's not really python but XP because of this: C:\Python\test>type data ÷ But I can type in umlauts on the prompt: C:\Python\test>ööööääääää 'ööööääääää' is not recognized as an internal or external command, operable program or batch file. Any ideas? Thanks.
|
# ? Feb 17, 2008 16:46 |
|
dwayne_dibbley posted:Any idea how I can get python to read and show umlaut characters from a file properly? Not Vista's fault, not Python's fault. You're got a non-ascii file. Open the file with `codecs.open()`, while specifying the encoding you want and then treat it like a normal file. You'll get unicode strings back. Arguably, the issue is that unicode and normal string interoperate in Python so much that the fact you have to use a different call here is anomalous. See http://www.jorendorff.com/articles/unicode/python.html
|
# ? Feb 17, 2008 17:26 |
|
duck monster posted:I really loving wish the Python people would use an open source compiler (ie gcc) for its windows distros. It pisses me off into near nerd-rage when I need to compile poo poo for windows but woops don't own Visual studio, and I can't get it to work with the express one worth poo poo. This has been a show stopper for me numerous times now, and makes me want to summon robot-stallman to shoot motherfuckers dead. If you're gonna be compiling your own extensions anyway, why not compile Python yourself? (EDIT: how can this be a show stopper when you know what the solution is?) EDIT: oh, so the problem is that you have third-party, closed source Python extensions that you want to use at the same time as your own extensions? Asking people writing closed-source stuff on Windows to switch to mingw just to get Python compatibility seems like too much to ask - isn't paying for VC++ the standard for Windows development? JoeNotCharles fucked around with this message at 19:31 on Feb 17, 2008 |
# ? Feb 17, 2008 17:39 |
|
Because it then breaks compatibility with all the other stuff people have compiled in MS C++ And if you don't have the sources, your boned.
|
# ? Feb 17, 2008 18:38 |
|
outlier posted:Not Vista's fault, not Python's fault. You're got a non-ascii file. Aha! Thanks very much. After living in Switzerland all this time I've become so used to umlauts that I forgot they are non-ASCII.
|
# ? Feb 17, 2008 21:15 |
Why is that once I run a script in IDLE the text highlighting disappears? Is there any way I can turn it on again?
|
|
# ? Feb 18, 2008 20:13 |
|
Zcientista posted:Why is that once I run a script in IDLE the text highlighting disappears? Is there any way I can turn it on again? Really? I havent seen that before. I wonder what causes it. Hey, if you get a chance, play with iPython. Its loving wonderful. If you run it on windows, be sure to set up Readline libs, but if you do its amazing, and if there was a way of making it work inside of idle, it'd make idle into gods own python environ. (Well, if I could get idle running as the shell in eclipse python, I'd probably consider that it).
|
# ? Feb 19, 2008 00:23 |
duck monster posted:
Wow, I'm just starting out here and iPython is so over my head. It sure looks pretty though. Yeah, I've realized that I don't even need to run the script in IDLE, it goes black and white even if I save. I have no idea what is going but I'm sure I'll figure it out at some point. Edit: figured it out... I assumed that IDLE was saving every file as *.py without me having to type in the file extension. I most definitely do have to add the file extension, at least in windows. Ishmael fucked around with this message at 19:03 on Feb 19, 2008 |
|
# ? Feb 19, 2008 05:10 |
|
I wrote this short program as a cheap excuse to mess around with Python a bit more (only started learning about a week ago) and to screw around with VIM. Just wondering if there's any stupid newbie mistakes I've made or things I should watch out for. Considering it's pretty short I think I'm safe but just to be sure...code:
|
# ? Feb 23, 2008 15:17 |
|
FrontLine posted:I wrote this short program as a cheap excuse to mess around with Python a bit more (only started learning about a week ago) and to screw around with VIM. Just wondering if there's any stupid newbie mistakes I've made or things I should watch out for. Considering it's pretty short I think I'm safe but just to be sure... After a quick once over (I've not tested the program) the first thing I noticed was the lack of input validation. For example, when asked how many images I want to download I type 'five.' what happens?
|
# ? Feb 23, 2008 17:34 |
|
Milde posted:Pylons being a "collection" of separate components is a load of poo poo. It's all tightly coupled together and about the only place you really get any freedom is in OR mapping. It touts being WSGI-based but it abstracts away WSGI to the point of it being irrelevant. You see other projects writing "adapters" just for Pylons compatibility. Okaayyyy ... Actually that's just the sort of information I was looking for. A lot of things look good from the outside, or have a good image due to the relentless promotion by the inner circle, but when you get to actually do something non-trivial, you run into problems. (Cue, my grousing about Plone's form handling which was abysmal until recently. For every form you had to write the HTML by hand, supply two scripts for handling the form that had a very restricted range of python you could use in them, and another two files of metadata. As a consequence, changing a form was like turning an oil-tanker ... yet no one in the Plone community complained about this.) bitprophet posted:Yup. This is a major misunderstanding about Django; it is loosely coupled by design. Yes, you lose the contrib apps (admin, auth, etc) and generic views, but it still works perfectly fine in terms of URL dispatch, view functions and template rendering. Also good to hear. I'd avoided Django because I didn't want to deal with its ORM (SQLAlchemy for ever!)- but the contrib stuff looks nice, as does encapsulating a site as a Python package. On other matters, has anyone coded a plugin / extension using setuptools entry point schema? It seems to be simple (especially compared to zope.interface) but like a lot fo thinsg with setuptools, it's under explained and I can't find many examples.
|
# ? Feb 23, 2008 19:42 |
|
Wedge of Lime posted:After a quick once over (I've not tested the program) the first thing I noticed was the lack of input validation. I've thrown this bit in. Effective? code:
|
# ? Feb 24, 2008 01:29 |
|
FrontLine posted:I've thrown this bit in. Effective? Don't do "except:", that swallows all exceptions. And I'm not sure why you need to turn it back into a string. And the convention for naming non-class variables in Python is lowercase_with_underscores: code:
|
# ? Feb 24, 2008 03:09 |
|
Milde posted:Don't do "except:", that swallows all exceptions. And I'm not sure why you need to turn it back into a string. And the convention for naming non-class variables in Python is lowercase_with_underscores: Thanks for the info The example I found for checking for the int turned it into a string so I didn't think much of it. I also didn't know about python naming conventions, much appreciated
|
# ? Feb 24, 2008 03:20 |
|
Milde posted:And the convention for naming non-class variables in Python is lowercase_with_underscores Kind of. It's more of a convention than camelCaps but the whole style issue isn't as fixed as it is in (say) Java. l lowercase_with_underscores is what they use in the Python style sheet, but several communities have quite different styles (e.g. Zope). The major styles points would be to be consistent, use lowercase (no underscores) for module Names, CapsStyle for classes and *never* mix spaces and tabs for indentation.
|
# ? Feb 24, 2008 08:59 |
|
outlier posted:Kind of. It's more of a convention than camelCaps but the whole style issue isn't as fixed as it is in (say) Java. l lowercase_with_underscores is what they use in the Python style sheet, but several communities have quite different styles (e.g. Zope). The major styles points would be to be consistent, use lowercase (no underscores) for module Names, CapsStyle for classes and *never* mix spaces and tabs for indentation. It's as fixed as in you always follow PEP 8, so everyone else follows it, so style conventions can be consistent and meaningful. Things like Zope are essentially legacy applications (though in this case it's the APIs that are legacy) and obviously have their own rules. That doesn't mean you should make up your own rules too for no good reason.
|
# ? Feb 24, 2008 09:32 |
|
I have a python application that is just about finished up, you can check out the code here: http://github.com/alex/pyelection/tree/master any thoughts on it would be great, there are some areas where the code is a little messy and any thoughts would be great.
|
# ? Feb 24, 2008 21:55 |
|
I've started messing with django recently, and I won't deny it is pretty sweet... Now, I want to try to create an import script. My model is really simple, but all I really want to do is take some stuff from a text file, parse it, then send the data to the database. Anyone ever put something like this together in django? What's the best way to go about this?
|
# ? Feb 25, 2008 02:31 |
|
This is something I threw together last time I needed importing from CSV:code:
code:
deimos fucked around with this message at 14:52 on Feb 25, 2008 |
# ? Feb 25, 2008 03:01 |
|
Another python newbie assignment question time! (Yay, me) I'm programming a hangman game, and I've got a working version that has 1 flaw I cannot fix. code:
My prof's objective was to familiarize us with the top level programming using functions. However, I cannot use the functions to syntactically add 1 to the variable 'guesses', using the continue statement. Also, when the user makes 6 wrong guesses, I want the program to print "You've guessed wrong too many times.", but it just skips that part and heads back to greetings(). (Not to mention the fact that the wrong guess indicator only goes to (5/6)) I've made a nightmarish hack job that has very little top level programming, and it's going to be a bitch to draw the flow chart for, but I'm drat proud of it. If you guys could give me some advice as to accomplish the task I wish to do, I'd be really grateful.
|
# ? Feb 25, 2008 09:35 |
|
|
# ? May 4, 2024 10:59 |
|
Kresher posted:Another python newbie assignment question time! (Yay, me) Start analyzing the program from the beginning of the inner while loop. Write out a few possible inputs you could give the program at ask_user_guess(). For each one of those, go very carefully line by line and see what the program will do. You have five possibilities, in general: nothing, a single letter not in the word, a single letter that is in the word, multiple letters that do not equal the word, multiple letters that equal the word. For example, if you give it multiple letters that do not equal the word, 'guess not in word' will evaluate true, so you will enter that if-block. It will print "You've made a wrong guess", and hit the continue statement and reset the while loop. Not what you were intending. If you patch that up, you may find that the program is appending all the letters in the guess to 'letters' even if the guess is wrong, with entertaining results. Also, due to the way the last if-else block is written, it will print "You've guessed wrong too many times" every time the set of letters is not equal to the set of words, even if your guess was correct! What's with that? Basically, the core logic is all wrong. Rethink it, flowchart it, then rewrite it, and you'll be off and running. quote:However, I cannot use the functions to syntactically add 1 to the variable 'guesses', using the continue statement.
|
# ? Feb 25, 2008 12:03 |