|
Scaevolus posted:I thought the Global Interpreter Lock made this form of threading pointless? Or are you doing multiple processes? You can use parallel python (http://www.parallelpython.com/) or pyprocessing (http://pyprocessing.berlios.de/) to easily side-step the GIL. My particular favorite is the latter (pyprocessing). In fact I am working on a pep and with python-dev to see if I can get pyprocessing into the stdlib for 2.6. The pyprocessing module is a drop-in replacement for the threading module (it's API compliant)
|
# ? May 23, 2008 11:50 |
|
|
# ? May 11, 2024 11:05 |
|
m0nk3yz posted:You can use parallel python (http://www.parallelpython.com/) or pyprocessing (http://pyprocessing.berlios.de/) to easily side-step the GIL. My particular favorite is the latter (pyprocessing). In fact I am working on a pep and with python-dev to see if I can get pyprocessing into the stdlib for 2.6. The pyprocessing module is a drop-in replacement for the threading module (it's API compliant) quote:Internally ppsmp uses processes and IPC (Inter Process Communications) to organize parallel computations. All the details and complexity of the latter are completely taken care of, and your application just submits jobs and retrieves their results (the easiest way to write parallel applications). Thanks, I didn't know about this.
|
# ? May 23, 2008 11:55 |
|
tripwire posted:This isn't strictly a python question, but its related so I figured I'd ask here. I've been tweaking and fiddling with a genetic algorithm in python for a while, and Ive had some success using parallel python to break up the population that needs to be evaluated so it each required evaluation can be farmed out to an available processor. I'm not exactly a python expert, but it seems to me you should just save all of the individuals scores and then filter them afterwards. The filtering is not easily parallizable from what I can think of.
|
# ? May 23, 2008 15:47 |
|
Bozart posted:I'm not exactly a python expert, but it seems to me you should just save all of the individuals scores and then filter them afterwards. The filtering is not easily parallizable from what I can think of. It's a little bit more tricky than that because of the change from a generational dynamic to a steady-state one (I was in essence doing what you are suggesting already, it works fine when you have large populations which are cleanly divisible by the number of processors you have). The search dynamic is apparently damaged if you don't use a population which changes only one individual at a time, probabilistically, versus the old system where the population is replaced by a new one every generation. That's why I've changed my software to replace one individual per step, and hence evaluation, which is how a steady state genetic algorithm should work I think. Since its done serially like this, I'm really puzzled how you would share work between different computers.
|
# ? May 23, 2008 16:04 |
|
I'm trying to decide between Django and TurboGears for a web app. One thing that I definitely don't like about Django is that updating my model requires manually generating and running SQL queries. I've looked at evolution, but I'm scared to use something that's not yet stable in my application. However, I don't know if the ORM that TurboGears uses suffers from the same problem. I don't find any warnings about it in the TurboGears or SQLObject documentation, but I wanted to ask to be sure. Can I update a model in TurboGears and expect to see those changes in the database?
|
# ? May 24, 2008 02:13 |
|
Can someone point me to a guide or something somewhere on organising a small project into modules? This is the first thing I've written in Python, and I just have no idea how to organise my classes and functions into separate modules. Whatever I try I just end up getting errors because each module doesn't have access to what it needs. Maybe I'm just organising everything wrong. Either way, is there a decent guide somewhere on general project organisation in Python?
|
# ? May 24, 2008 02:28 |
|
Nickopops posted:Can someone point me to a guide or something somewhere on organising a small project into modules? This is the first thing I've written in Python, and I just have no idea how to organise my classes and functions into separate modules. Whatever I try I just end up getting errors because each module doesn't have access to what it needs. Maybe I'm just organising everything wrong. Either way, is there a decent guide somewhere on general project organisation in Python? http://docs.python.org/tut/node8.html
|
# ? May 24, 2008 02:42 |
|
Sock on a Fish posted:I'm trying to decide between Django and TurboGears for a web app. One thing that I definitely don't like about Django is that updating my model requires manually generating and running SQL queries. I've looked at evolution, but I'm scared to use something that's not yet stable in my application. There's a whole Django thread actually, and I answered a similar question in it, which basically boils down to having django generate a sql dump script with your data in it, recreating the model (drop/recreate), and then re-inserting the data after you've modified the dump appropriately. If you use SQLite (which is awesome), it unfortunately doesn't support removal of columns from schema anyway, so you'd have to drop the table
|
# ? May 24, 2008 03:57 |
|
tripwire posted:It's a little bit more tricky than that because of the change from a generational dynamic to a steady-state one (I was in essence doing what you are suggesting already, it works fine when you have large populations which are cleanly divisible by the number of processors you have). The search dynamic is apparently damaged if you don't use a population which changes only one individual at a time, probabilistically, versus the old system where the population is replaced by a new one every generation. That's why I've changed my software to replace one individual per step, and hence evaluation, which is how a steady state genetic algorithm should work I think. Since its done serially like this, I'm really puzzled how you would share work between different computers. This sort of stuff is really interesting to me and is why I am in the process of learning python - could you tell me what resources you use to implement this, and what information is out there as well?
|
# ? May 24, 2008 05:06 |
|
No Safe Word posted:There's a whole Django thread actually, and I answered a similar question in it, which basically boils down to having django generate a sql dump script with your data in it, recreating the model (drop/recreate), and then re-inserting the data after you've modified the dump appropriately. Or you can use a 3rd party project such as django-evolution(which works pretty drat well IMO).
|
# ? May 24, 2008 05:45 |
|
I am using sqlalchemy(with sqlite) in a project and I have having issues my objects/database becoming useless eventually after multiple shut downs and restarts. The application I am developing this for does not emit any type of shutdown signal so I can not save on that event so I am looking for suggestion on how I can reduce the chances that corruption or an incomplete write might occur? Ideally I would like the application to emit a signal so I can cleanly deal with the database but that is out of my hands for various reasons. For some background it is a rss reader database/backend that uses feedparser to handle feeds. It is being used by another project which is where this particular issue is occurring.
|
# ? May 24, 2008 18:42 |
|
Check out http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html where it says "Transactions". I think that might be what you're looking for.
|
# ? May 24, 2008 19:01 |
|
I remember that when this one came out I was beginning to visit Python and it inspired a little project. I did not have the time to follow through on it but things have been getting a little monotonous for me lately and I needed to take a break and do something different. So I finally got around to writing this. It grabs xkcd's RSS feed and looks for an update. If it finds one then it will download the new strip to a pictures directory and set it as the wallpaper. I was going to make it cross platform but I ended up not feeling like it and hey, it was only supposed to be a small break. So sorry, OS X only. Download the script to wherever you want and save this plist to ~/Library/LaunchAgents and change the path appropriately. The plist has the script running every three hours so if you want it to be different then change TimeInterval to however many seconds. Perhaps in 2011, when I hope to have some more free time, I will update it to work with other operating systems (not hard) and other comics. A couple caveats - Prior to running this the background preferences must be set to a centered non-rotating picture. And it might freak out if ~/Pictures/xkcd doesn't already exist, I can't remember. Somebody fucked around with this message at 05:10 on May 28, 2008 |
# ? May 27, 2008 19:35 |
|
I'm working on a metaclass that builds a lot of repetitious code from a class attribute. No problems there. But I also want it to generate some automatic documentation for the class and the class's __init__. It seems wasteful and error prone to do this repetious documentation by hand. Unfortunately __doc__ is immutable. There seem to be a number of messy ways around this. This is for a hobby library and I'm trying to simplify it for people who want to extend the library as well as people who just want to use code by them or me. What I want to know is if there's a 'proper' way to deal with this, or at least a clean way. I'd rather stick to the standard library. I can post the code if necessary, but it's a dirty sketch as I play around with possible designs, filled with numerous stanzas irrelevant to the discussion, and I basically just want to know how to use a metaclsass to alter docstrings.
|
# ? May 28, 2008 02:53 |
|
Lord Uffenham posted:Unfortunately __doc__ is immutable. There seem to be a number of messy ways around this. Have you tried using __new__? code:
|
# ? May 28, 2008 03:45 |
|
I'm sorry. I was unclear. I am using __new__, the problems is updating the docstring of the __init__ method of the class being created. Note that I'm using attrs where Milde used dct and that the gross assumptions my code makes about how the class's __init__ method operated are valid in context, and that I've tried to cutaway code and comments that don't apply to the questions at hand.code:
|
# ? May 28, 2008 04:01 |
|
Set cls.__init__.im_func.__doc__. You're trying to assign a doc string to the instance method, which is just a wrapper around the function.
|
# ? May 28, 2008 04:38 |
|
Awesome! Thanks for the help. Where in the documentation would I find more about these abstrusely named properties?
|
# ? May 28, 2008 04:58 |
|
It's not a pretty doc, but this page lists most of this kind of info: http://docs.python.org/ref/types.html. That same manual also has information on special methods.
|
# ? May 28, 2008 05:07 |
|
The processing PEP is now live (draft form): http://www.python.org/dev/peps/pep-0371/
|
# ? May 28, 2008 19:34 |
|
Python GUI's? Any opinions? Tkinter, Wx, GTK, QT? Which one has better IDE support currently? Are there any good IDE's? Anyone in particular I should avoid if I'm using OS X?
|
# ? May 28, 2008 19:52 |
|
Choose Wx or Qt: Tkinter is completely obsolete and ugly. Wx is a wrapper around Gtk on Linux, and around the native UI on other platforms, so I'd choose it over Gtk for portability. I like Qt myself, but I don't have any killer arguments for why it's better than Wx.
|
# ? May 28, 2008 20:06 |
|
Has anyone ever compiled the sqlite3 library (new in 2.5) for Mac OS9 python (the latest version of which I can find is 2.3)? I have seen a few posts after googling which seem to suggest some kind of implementation is possible but not found any how tos or help as to how to do it. So any help would be much appreciated or even a no not possible if anyone knows the answer. Thanks.
|
# ? May 28, 2008 21:04 |
|
I'm writing some image manipulation stuff in Python using PIL and was wondering if anyone would review a few basic functions I wrote(I'm a Python n00b).code:
Anyone have comments on my style or where I'm not being "Pythonish"? edit: I just realized it makes NO SENSE AT ALL to return a 3-tuple for HSL from a function that expects a dict for RGB. Ergh. editx2: changed that ashgromnies fucked around with this message at 22:02 on May 28, 2008 |
# ? May 28, 2008 21:49 |
|
ATLbeer posted:Python GUI's? I can't give an opinion on the others, but I recently started using PyQt and so far I'm loving it. I find it to be very flexible and powerful while still being incredible easy to use. It comes with a good GUI designer, though personally I prefer to do the GUI layout in code. Documentation is pretty good as it's mostly based on Trolltech's excellent Qt docs. I would however also recommend the book Rapid GUI Programming with Python and Qt if you've never used Qt before. As for IDEs, I like Eclipse/PyDev, and Trolltech also ships a Qt integration module so you can do the GUI design from within Eclipse. There's also the Eric4 IDE, which is actually made using PyQt. I haven't used it much myself, though.
|
# ? May 28, 2008 22:08 |
|
ashgromnies posted:I'm writing some image manipulation stuff in Python using PIL and was wondering if anyone would review a few basic functions I wrote(I'm a Python n00b). And I think using lambdas on the last bit is a little too "clever", just write the small function that actually does it: code:
code:
|
# ? May 28, 2008 22:53 |
|
ATLbeer posted:Python GUI's? QT4.4 for OS X, Windows, and Linux. It has a decent API and works great as a cross platform toolkit, but it is GPL rather than LGPL so keep that in mind. I have not used WX much yet but it was nice when I did. I prefer pyGTK when developing for X11 systems because I know the API and it works well with Glade3svn+WingIDE. Avoid GTK+ on OSX unless you do not mind having an X server running or using the experimental native GTK+. Hopefully someone adds better python support to Monodevelop because I am really enjoying their code completion tool and deeply integrated Stetic UI designer that does WinForms and GTK(C# grr). tehk fucked around with this message at 23:13 on May 28, 2008 |
# ? May 28, 2008 23:09 |
|
Hey m0nk3yz, congratz on the PEP, I read it and it looks real good, I hope it gets accepted!
|
# ? May 29, 2008 01:18 |
|
I just realized I've been reading m0nk3yz's blog for a while if that's his PEP.
|
# ? May 29, 2008 02:21 |
|
Have any python programmers (new or old) have used Ulipad ? Some one just posted a link to a screen cast on the Tutor mailing list, which shows off several of the features on it. It just used it and I think it will be a really good replacement for Notepad++, and a really handy tool for Python development because of how lightweight it is, the code completion, "notes feature", debugger and the built in python shell.
|
# ? May 29, 2008 02:43 |
|
Bozart posted:This sort of stuff is really interesting to me and is why I am in the process of learning python - could you tell me what resources you use to implement this, and what information is out there as well? I'm modifying the source of neat-python, which is a pretty decent implementation of NEAT to use. One of the benefits of python that I'm really enjoying is how understandable the code is; if you want to learn about how neuroevolution works I'd recommend studying neat-python code over any of the c++ or even java implementations, which had a lot more code devoted to just making things work, or work fast. A lot of people will bitch and moan that python isn't suitable for number crunching but really that is misleading I think. All of the CPU intensive parts of this code can be sped up by using psyco and special optimized c++ libraries for manipulating neural nets, but because I'm using this 32-bit simulation environment and my native python is incompatible (64-bit), I have to use the python packaged with the simulator, version 2.3. Because this interpreter is incompatible with my installed modules, I've simply been throwing my modified neat-python folder into the simulation directory and waiting for the simulator developer to hurry up and throw python 2.5 in there. Right now I've pretty much mangled the code in my attempts to implement a steady state algorithm novelty search (first time using python, it's been a real learning experience), but once I'm satisfied thats its cleaned up enough to be legible and understandable (and once it works properly) I'll ask the dev to throw it on the SVN. Which is here by the way: http://code.google.com/p/neat-python/source/browse
|
# ? May 29, 2008 06:12 |
|
deimos posted:I just realized I've been reading m0nk3yz's blog for a while if that's his PEP. It is, and I hope it's been a decent read, although I've been heads down with the new job/PEP/python magazine work lately.
|
# ? May 29, 2008 13:51 |
|
here's an easy one hopefully. let's say I have a bunch of different strings stored in class "Shop" so that Shop.a = "string", Shop.b = "strang", Shop.c = "streng", ect... now I want to remove a number of characters from those strings and replace them. First I try writing a function: code:
Am I doing this wrong? Should I define this function within the "Shop" class? The next thing that's bothering me, I don't want to have to write code:
|
# ? May 29, 2008 17:31 |
|
politicorific posted:here's an easy one hopefully. politicorific posted:The next thing that's bothering me, I don't want to have to write Not easily, and not cleanly. The best way would be to store the strings in a different data structure, like a dictionary.
|
# ? May 29, 2008 18:17 |
|
politicorific posted:here's an easy one hopefully. I'm just typing this out and not double checking my code so there maybe a syntax error or two in here so YMMV code:
|
# ? May 30, 2008 02:29 |
|
What's the specific reason that arrays are faster than tuples? When should you use an array versus a tuple? From what I understand, you should use a tuple when you want to form it and pass it off without manipulating its internals any further - that is, "I have calculated three pieces of data and want to return them from a function. I should use a tuple." But why use a tuple over an array in that case? For example: code:
code:
code:
code:
ashgromnies fucked around with this message at 05:05 on May 30, 2008 |
# ? May 30, 2008 05:01 |
|
Those are lists, not arrays (an array is a specialized data type in Python). You use tuples when you want to return or hold on to multiple values. They're like structs in C, but without named elements. Lists on the other hand are mutable, unlike tuples. They're meant for being grown and shrunk, filtered, sorted, etc. When you append to a list, it doesn't create a new list. You can't append to tuples, only make new tuples.
|
# ? May 30, 2008 05:20 |
|
Tuples are immutable, use them as such.
|
# ? May 30, 2008 05:49 |
|
Tuples are for collections of heterogeneous types, lists are for collections of homogeneous types. edit: Quote from GvR No Safe Word fucked around with this message at 06:49 on May 30, 2008 |
# ? May 30, 2008 06:44 |
|
|
# ? May 11, 2024 11:05 |
|
And because tuples are immutable, they can be used as dictionary keys!
|
# ? May 30, 2008 12:31 |