|
Quick stupid question for a beginner: If I made some project (lets say... some roguelike game) in python, would I need to have python installed on every machine to play it? Is there a way to avoid that?
|
# ? Jul 30, 2008 01:42 |
|
|
# ? May 10, 2024 12:04 |
|
agscala posted:Quick stupid question for a beginner:
|
# ? Jul 30, 2008 01:49 |
|
I'm in the middle of my personal coding project of the moment (http://code.google.com/p/keasby/ *) and I'm looking into a good way of doing data persistence. Currently I'm using shelve to cache away what are essentially pickled XML blocks that have been parsed through xml.dom.minidom. I'm also using anydbm to keep a dict of past search results. What are the best tools out there to do the job? * the version that's currently there is basically avoiding Object Oriented / Best Practices because I was copying the logic of a perl script. The svn code I'm more proud of, although it needs to be tightened, a lot.
|
# ? Jul 30, 2008 05:54 |
|
lilbean posted:You can use py2exe (http://www.py2exe.org/) to make a self-contained executable for Windows platforms. ...and Python is standard on Linux/BSD and OSX. So you'd be good to go.
|
# ? Jul 30, 2008 17:09 |
|
lilbean posted:You can use py2exe (http://www.py2exe.org/) to make a self-contained executable for Windows platforms. If pygame or pyglet was used, would they need to be installed as well, or would the exe contain everything needed?
|
# ? Jul 30, 2008 17:47 |
|
SlightlyMadman posted:If pygame or pyglet was used, would they need to be installed as well, or would the exe contain everything needed?
|
# ? Jul 30, 2008 23:41 |
|
So I'm having an interesting time with python so far (the only time I'd used it before was map scripts for CIV, which are pretty simple), but I've run into an interesting issue. I have a game that runs perfectly on my WinXP laptop, but absolutely abysmally on my Ubuntu laptop. The thing is, they're both almost the same model (WinXP is Thinkpad R60, Ubuntu is Thinkpad T60, which is actually better). If I comment out all the main loop of blit code, it runs fine. Here's the code in question: code:
|
# ? Jul 31, 2008 03:06 |
|
Has anyone had a good experience with a messaging package? I have used the XMLRPC library and I LOVE it.. I really want to use the library but, I would like some sort of central logging of all messages that have gone through the system for debugging and error checking since it's going to be transactional system. I guess I could funnel all the XMLRPC requests through a handler which would log the message and pass it along to the appropriate system but, that seems like a cheap hack and a bottle neck. A Jabber server seems like the only solution but, I can't seem to bring my self to be a fan of the libraries out there. They all seem to be a bit too "un-pythonic" and obtuse. Anyone have any experience in a client-server-client messaging system for Python that you've liked to work with or do you believe I'm just stuck hacking up a Pythonic wrapper for an existing Jabber wrapper?
|
# ? Jul 31, 2008 04:29 |
|
ATLbeer posted:I would like some sort of central logging of all messages that have gone through the system for debugging and error checking since it's going to be transactional system. Does the logging module not do what you want? http://docs.python.org/lib/module-logging.html Specifically the syslog module, or the httplog module: http://docs.python.org/lib/node416.html http://docs.python.org/lib/node420.html
|
# ? Jul 31, 2008 11:06 |
|
ATLbeer posted:Has anyone had a good experience with a messaging package? The XML-RPC library is astonishingly effective and simple to use. poo poo. Its a shame you didn't ask this 6-7 months ago, I wrote an awesome system that did precisely this. Central logging system with a web interface, switchable logging levels, all sorts of statistics, and a big bag of interfaces to talk to it in various languages. (PHP, Python, Perl, C). The boss let me LGPL it all, but when I quit the job I never took a copy of the code, and I did my usual and burnt the bridge with a flamethrower, so I probably can't get it for you. But heres how it basically worked;- Make a simple daemon (just descend from Simple xml server class) that takes messages, and poo poo them into a database. Get out Django, or poo poo even PHP if you wish, an punk out a little web interface to it. An then just make a little includable library to catch errors and fwd them across to the daemon.
|
# ? Jul 31, 2008 12:43 |
|
If anyone else is having trouble with pyglet, a word of warning. Apparently it's just not optimized for 2d sprite games at this point. Apparently it's coming though. There's some good information about my exact problem above, here: http://groups.google.com/group/pyglet-users/browse_thread/thread/607b94cdcc8254ec Thankfully I only put a few hours into the game so far (pyglet is definitely easy to get started), so I don't mind starting over again with pygame instead.
|
# ? Jul 31, 2008 16:15 |
|
SlightlyMadman posted:So I'm having an interesting time with python so far (the only time I'd used it before was map scripts for CIV, which are pretty simple), but I've run into an interesting issue. I have a game that runs perfectly on my WinXP laptop, but absolutely abysmally on my Ubuntu laptop. The thing is, they're both almost the same model (WinXP is Thinkpad R60, Ubuntu is Thinkpad T60, which is actually better). code:
Consider iterating over the 480x480 viewport instead of over every pixel and seeing it should be drawn-- that should improve performance as well. Scaevolus fucked around with this message at 03:34 on Aug 1, 2008 |
# ? Aug 1, 2008 03:27 |
|
Scaevolus posted:0 <= draw_x < self.view_width Holy poo poo!
|
# ? Aug 1, 2008 04:31 |
|
Scaevolus posted:In particular, your use of range(), which returns a list, instead of xrange(), which returns an iterator, could drastically reduce performance. Also, you can do "0 <= foo < 100", which is handy for stuff like this. Thanks! I definitely appreciate the optimizations, and I'll try it out. I didn't even really consider it though, because there's only 24 elements in each direction, so that's just 576 iterations. There's no excuse for that to take the 5-10 seconds it's taking now, so it's definitely the blit code. edit: yeah, just tried it. No noticeable difference. Good to know about xrange, though. SlightlyMadman fucked around with this message at 16:08 on Aug 1, 2008 |
# ? Aug 1, 2008 16:01 |
|
I've run into some strange behavior from some class members in my Python program.code:
This baffles me because if I wanted it to be static, then I would have had to use Square.conflicts in the __init__ and addConflict functions and not use self parameters in those functions. Google is giving me nothing but instructions on how to make things static rather than explanations of why this is behaving statically out of nowhere. Anyone have a hint on what's going on here?
|
# ? Aug 1, 2008 21:45 |
|
Default arguments are initialized only once. Every time you call Square.__init__() it adds to the list in the _conflicts parameter. Set its default value to None and instantiate it inside the function:code:
|
# ? Aug 1, 2008 21:58 |
|
Milde posted:Default arguments are initialized only once. Every time you call Square.__init__() it adds to the list in the _conflicts parameter. Set its default value to None and instantiate it inside the function: Ah, that makes a lot of sense. Thanks a lot!
|
# ? Aug 1, 2008 22:31 |
|
SlightlyMadman posted:Thanks! I definitely appreciate the optimizations, and I'll try it out. I didn't even really consider it though, because there's only 24 elements in each direction, so that's just 576 iterations. There's no excuse for that to take the 5-10 seconds it's taking now, so it's definitely the blit code. Just in case anyone's curious, I just rewrote my game in straight pygame, and it performs beautifully. I even tried running it on my N800 tablet, and it runs with only a slight lag, which I'm sure further optimization could take care of.
|
# ? Aug 4, 2008 22:19 |
|
I want to start making a roguelike game in python, and I was going to use the curses module to do all of my console interaction. I ran into a snag right off the bat. First off, curses isn't available on windows, so I'm using wcurses. Whenever I try to import curses, I get:code:
|
# ? Aug 5, 2008 04:40 |
|
agscala posted:I want to start making a roguelike game in python, and I was going to use the curses module to do all of my console interaction. I'm really liking pygame for simple 2D graphics, and there's many great roguelike tile sets available. Or if you prefer text, you can just use images of text for your tiles. Not much harder to code up front, and gives you a lot more flexibility in the end.
|
# ? Aug 5, 2008 15:36 |
|
SlightlyMadman posted:I'm really liking pygame for simple 2D graphics, and there's many great roguelike tile sets available. Or if you prefer text, you can just use images of text for your tiles. Not much harder to code up front, and gives you a lot more flexibility in the end. then you can make a game where you manage a bunch of goblins that live in a cave...
|
# ? Aug 5, 2008 15:51 |
|
agscala posted:I looked all over the web and I couldn't find a solution. I emailed the creator of wcurses and haven't received a response... Any help is much appreciated for this beginner! Extract the curses files into c:\python25\lib not c:\python25\lib\site-packages
|
# ? Aug 5, 2008 16:18 |
|
tef posted:Extract the curses files into c:\python25\lib not c:\python25\lib\site-packages I want to give pygame a shot, I'm not happy about how it won't run on v2.5, though.
|
# ? Aug 5, 2008 20:13 |
|
I am current in complete and total awe of python and pygame. Rather than deal with getting all my classes and data structures perfect, I decided I just wanted to make a game that I could interact with by the end of the day. It's not exactly fun yet, but I've got most of the game implemented to some degree: pathfinding, mini-map, combat routines, line of site with fog of war. All told, I've probably put 5-6 hours of actual coding time into this: I've gotten projects further than this in the past, but never this quickly. Hopefully it doesn't fall apart at the seams later on because of it.
|
# ? Aug 6, 2008 00:25 |
|
agscala posted:Thanks, that was the correct solution. According the pygame site, 1.8.1 runs on python 2.4, 2.5, and 2.6, but they suggest not running 2.6 if you want compatibility with older versions of Windows. Do these not work? I've never used pygame before, but I've been thinking about maybe starting a project in it, and it would be good to know if something's up with compatibility.
|
# ? Aug 6, 2008 10:00 |
|
SlightlyMadman posted:If anyone else is having trouble with pyglet, a word of warning. Apparently it's just not optimized for 2d sprite games at this point. Apparently it's coming though. There's some good information about my exact problem above, here: Version 1.1 of Pyglet was just released yesterday. Here is a quote from the announcement... pyglet.org posted:pyglet 1.1 is backward compatible with pyglet 1.0 and introduces many new features such as formatted text rendering, animated GIF support, fast sprite rendering, resource loading and a managed event loop. I haven't had much time to play around with it myself yet, but it looks really spiffy. I'm interested in hearing if anyone else has used pyglet.
|
# ? Aug 6, 2008 17:22 |
|
Can anyone help me with using pickle to serialize and deserialize complex objects? I want to be able to do something like this:code:
I think I have to do something with the __dict__ member, but I can't quite figure it out. Google keeps coming up with seemingly helpful examples, but they end up being far too simplistic and don't solve the inherited class issue. I can post the full code if anyone thinks they can help. Update: If anyone is curious, this is the code I ended up needing: code:
SlightlyMadman fucked around with this message at 16:57 on Aug 13, 2008 |
# ? Aug 13, 2008 04:30 |
|
I want to learn Python by making a simple address/phone book application. In terms of the data structure, is it possible to define an entry in the phone book as a class, and then simply store those entries (Of class Entry, for example) in a list? Would that allow me to add/delete the entries and whatnot?
|
# ? Aug 13, 2008 23:20 |
|
Centipeed posted:I want to learn Python by making a simple address/phone book application. Depends on what sort of persistence you want. If you're talking about a trying-stuff-out demo app where you don't actually care about the data sticking around, then sure -- lists can hold any object, and class instances are of course objects like anything else. However, once your program stops running, your list will obviously disappear. If you wanted to keep the data on disk somewhere, the typical method is to use a SQL database, the simplest such being SQLite (which stores stuff in simple files, as opposed to the heavyweights which are full blown servers) -- Python 2.5 has a built-in SQLite library so all you'd need is to install the SQLite binaries and you're all set. Edit: Fix retarded typo. bitprophet fucked around with this message at 00:27 on Aug 14, 2008 |
# ? Aug 14, 2008 00:20 |
|
For this exercise, can't I just store the list in a text file with simple markup? A database seems like overkill, even it is is only SQLite.
|
# ? Aug 14, 2008 00:41 |
|
Centipeed posted:For this exercise, can't I just store the list in a text file with simple markup? A database seems like overkill, even it is is only SQLite. What do you mean by "simple markup"? I suppose you could use "<whatever> separate values" (comma, tab, pipe, whatever) but then you need to translate back and forth every time you save. And, yea, SQL is a bit of overkill; I did say "the typical method", not "the only method" I think the best middle-of-the-road approach would be to use the pickle module, which lets you store Python objects in strings (and thus in files). I probably should have mentioned that first, honestly, but I'm too used to thinking of "real" applications, for which stuff like pickle is almost never a good idea (unless your data sets are very small AND you really want to work with Python objects instead of SQL or an ORM).
|
# ? Aug 14, 2008 01:11 |
|
Centipeed posted:For this exercise, can't I just store the list in a text file with simple markup? A database seems like overkill, even it is is only SQLite. Go here: http://docs.python.org/tut/node9.html and scroll down to section 7.2; it should have everything you need.
|
# ? Aug 14, 2008 01:14 |
|
A question about PDF libraries for Python: ReportLab allows you to *make* PDFs, PyPDF allows you to *edit* them (to the extent of adding and deleting pages), but is there any library that will allow you to interrogate or add to them? I'm doing some work with PDF ebooks and I'd like to peek at the PDF metadata to rename the files accordingly, and then to merge some annotations (from an iLiad reader) into the main document. However current Python PDF libraries seem to neatly skirt this functionality. I guess what I'm looking for is the Python equivalent of iText. Options?
|
# ? Aug 14, 2008 09:05 |
|
aeiou posted:Version 1.1 of Pyglet was just released yesterday. Here is a quote from the announcement... Pyglet has had the fast sprite rendering available through the 1.1 betas for awhile. I've been using it a lot to prototype some things and I've been very happy with performance. If you know what you're doing and use batches in 1.1 it's much faster than Pygame. Even without the 1.1 improvements there was a fast sprite library available called Rabbyt which worked with Pyglet and again would be much faster than Pygame. I think the problems come from people trying to do things with it exactly like they would in Pygame or other libraries. Pyglet certainly lets you do things that will result in very bad performance (individually blitting each sprite for instance), but I've seen a few demos posted to the Pyglet mailinglist that were very impressive. One generated a few thousand sprites (with transparency) in the form of a particle fountain and ran flawlessly on my old Powerbook G4, and this was done before version 1.1. You simply cannot get anywhere close to that in Pygame. Pyglet still has a few deficiencies, like no joystick or gamepad support yet, but it seems to be developing much more quickly than Pygame these days. I do however find a lot of things that Pyglet has, like it's event handling, to be much better than what's available for Pygame. Overall I don't think I could ever recommend Pygame over Pyglet to anyone for anything. By the way, nice name. Oae Ui fucked around with this message at 19:15 on Aug 14, 2008 |
# ? Aug 14, 2008 19:13 |
|
Oae Ui posted:Pyglet has had the fast sprite rendering available through the 1.1 betas for awhile. I've been using it a lot to prototype some things and I've been very happy with performance. If you know what you're doing and use batches in 1.1 it's much faster than Pygame. Even without the 1.1 improvements there was a fast sprite library available called Rabbyt which worked with Pyglet and again would be much faster than Pygame. I'm actually having two problems with pygame right now. The first is that there's no way to order a sprite batch, so if I have multiple overlapping sprites in the same batch, I get an annoying flicker where they intersect. The second is that drawing lines directly to the screen seems to be incredibly slow. I've noticed that my game slows down dramatically (drops from about 60fps to 5-10) once I've explored the whole map, because the fog-of-war has been lifted so there's more mini-map to draw. Would pyglet resolve these issues for me? If so, I might swap back out pygame for it and give it a shot. Thankfully, when I replaced pyglet with pygame initially, I ended up fairly well compartmentalizing the rendering code as a result.
|
# ? Aug 14, 2008 19:56 |
|
SlightlyMadman posted:I'm actually having two problems with pygame right now. The first is that there's no way to order a sprite batch, so if I have multiple overlapping sprites in the same batch, I get an annoying flicker where they intersect. The second is that drawing lines directly to the screen seems to be incredibly slow. I've noticed that my game slows down dramatically (drops from about 60fps to 5-10) once I've explored the whole map, because the fog-of-war has been lifted so there's more mini-map to draw. The way that you do drawing with Pyglet 1.1 is you add sprites to a batch and then call batch.draw(). This renders the whole batch in a single call. To handle ordering sprites can be assigned to ordered groups (you can also do other things here like have setup and teardown code for each group). This sounds like what you're doing but sprites inside of a group will maintain their order so you shouldn't get any flickering. As for drawing lines, Pyglet still does not have a primitives module, which is one area where it's lacking. However, the new pyglet.graphics API makes drawing shapes in OpenGL a bit easier than it used to be. It's pretty easy to draw a line with it and it will be very fast, especially if added into your main batch. It's pretty easy to wrap into a function. Adding a line to the batch can be done like this (taking this partly from the pyglet docs): code:
code:
|
# ? Aug 14, 2008 21:50 |
|
I finished my phone book application. I have no idea if it was coded well, but it was a decent learning exercise for my first Python program. What I'd like to know, though, is the following:code:
|
# ? Aug 14, 2008 23:19 |
|
Centipeed posted:I finished my phone book application. I have no idea if it was coded well, but it was a decent learning exercise for my first Python program. What I'd like to know, though, is the following: Are you familiar with the "static" keyword in C++ and Java? It makes a member variable part of the *class* instead of the *object*. Like this: code:
Python's the same, except you can actually reuse a name as both a static variable and an instance variable: code:
|
# ? Aug 14, 2008 23:34 |
|
So the foo = "" isn't necessary at all, because I never set Name.foo to anything in my program. And am I right in saying that passing "self" as an argument (Or are they called parameters?) is basically passing the object (Instance of a class) that you're calling at that moment? So if I had two instances of Name: n1 and n2, then calling n1.set_variable("name") would be passing (n1, "name") to the set_variable function? Or put more simply, is "self" essentially a variable that gets set to the name of whichever object you happen to be using at that point?
|
# ? Aug 15, 2008 01:04 |
|
|
# ? May 10, 2024 12:04 |
|
Centipeed posted:Or put more simply, is "self" essentially a variable that gets set to the name of whichever object you happen to be using at that point? Yes. This also means that if n1 is an instance of a class n, you can do n.some_function(n1, ...)
|
# ? Aug 15, 2008 01:09 |