Re: There may be a much better way to manage artillery.
Tobiah wrote: > I'm writing a video game with armed space ships. > I decided to make a class to manage all of the bullets > that may be on the screen at a given time: > > class Bullets(): > > def __init__(self): > self.bullets = [] > > def update(self): > temp = [] > for bullet in self.bullets: > bullet.update() > bullet.time_to_live -= 1 > if bullet.time_to_live: > temp.append(bullet) > self.bullets = temp > > def add(self, new_bullet): > self.bullets.append(new_bullet) > > When the main loop calls .update() on the bullets > object, I want it to decrement a counter on each > bullet, and destroy the bullets who's time has come. > > I wanted the bullets to be responsible for destroying > themselves, but a little Googling brought me to points > about dangling references and how an object is not allowed > (nor does it seem to have the means) to destroy itself. > That's why I made this wrapper class for all of the bullets. > > The idea is to copy bullets with time left into a temp list > and then overwrite the man bullets array with the good bullets. > I believe that the other bullets will be garbage collected. > I could not delete the items in place within the loop, of course. > Was there a better container than a list for my purposes? > > Above is what I settled on, but I wonder > whether my approach is a good one. > > Thanks very much, > > Toby This also gives you the means to destroy the oldest bullet when creating a new one, once some arbitrary limit was reached. Think back to how old games like Raptor worked. If you had the bullets take care of their lifetime themselves, you would have to have more code touching all the bullets to do this. Now, you can add a little bit while you are already working through them all, saving yourself some cycles I would wager. -- http://mail.python.org/mailman/listinfo/python-list
Re: tarfile doesn't work with tgz files?
On 2009-05-16, Robert Dailey wrote: > On May 16, 11:49 am, Gary Herron wrote: >> Robert Dailey wrote: >> > Hi, >> >> > I'm not a big expert on the tarfile component, but I assumed that .tgz >> > files were short for .tar.gz and the format was the same. >> >> That's correct. >> >> > When I try >> > to extract a .tgz file using tarfile in Python 3.0 on Windows, I get >> > the following error: >> >> > File "C:\Python30\lib\tarfile.py", line 1630, in open >> > raise ReadError("file could not be opened successfully") >> > tarfile.ReadError: file could not be opened successfully >> >> > I'm assuming this is because the .tgz format is not what I think it is >> > and is not supported. >> >> Not true. It's supported. >> >> > How can I extract .tgz files using Python 3.0? >> > Note that I probably can't depend on third party python modules, since >> > I have yet to find many that support Python 3.0. >> >> > Thanks. >> >> It's hard to debug your code when you don't show us your code, so I >> won't try. >> >> I can however supply a bit of working code: >> >> >>> import tarfile >> >>> f=tarfile.open('f.tgz') >> >>> f.list() >> -rw-r--r-- gherron/gherron 703 2009-03-14 15:59:46 t.py >> -rw-r--r-- gherron/gherron 566 2009-05-15 09:13:08 note-bzr-hg >> -rw-r--r-- gherron/gherron 11563 2009-04-24 09:33:12 .emacs >> >> So the module correctly reads the tar-gzip file, and finds its contents. >> >> Now, what is it you were trying to do? >> >> Gary Herron > > Okay so I managed to figure out the problem. > > Initially, I manually downloaded the TGZ above through Chrome and then > opened it in WinRAR and extracted the files. Everything worked fine. > > Then, I ran my Python script which uses urlretrieve() to download the > file and then tarfile is used to extract it. However, urlretrieve() > was not downloading the full file because of a bug that was corrupting > my URL. > > Sorry for the confusion, and thanks to everyone for the very prompt > help! Just to clarify: A tar.gz is a gzipped tar archive. It's a normal tar file, processed into a normal gzip file. tar.bz2 is the same, but bzip2 instead of gzip. So, if for some reason you want to do it yourself, just decompress the data first, then handle it like a tar file. -- http://mail.python.org/mailman/listinfo/python-list
Re: Your message to CMake awaits moderator approval
On Thu, 24 Jul 2008 18:43:34 -0400, cmake-bounces wrote: > Your mail to 'CMake' with the subject > > Status > > Is being held until the list moderator can review it for approval. > > The reason it is being held: > > Post by non-member to a members-only list > > Either the message will get posted to the list, or you will receive > notification of the moderator's decision. If you would like to cancel > this posting, please visit the following URL: > > Should this be showing up in a usenet group? -- http://mail.python.org/mailman/listinfo/python-list
three column dataset - additions and deletions
I'm going to be writing a utility that will be pulling three fields from a MySQL table. I've already got a sample dataset - there's a long int (which is a db key), a short string, and a looong string. Many rows. As it is, receive this data from the DB interface as a rather large tuple of tuples. I plan on hashing the long string field (both for convenience and security) and storing the set in a pickle. The idea is that this script will run periodically, pulling the table, and comparing the data gathered at that run to that stored by the previous, acting on changes made, and storing the current data back (to be referenced against in the next invocation) I figure it will be easy enough to determine changed hashes for a given key. What I'm unclear on is what the best type of structure to keep this data in, given that I need to modify the data after it comes in (replacing that long string with, say, an MD5 from hashlib) and both need to act on "new" rows (rows that don't exist in the 'old' data) and deleted rows (rows that only exist in the 'old' data). Keeping in mind that I'm a newbie here, and I'm probably not aware of most of the different ways to store such things. I shouldn't have any problems with the logic itself - I just know enough to know I don't know the best ways of doing things :) Any suggestions? I'm not asking for code or handholding, but some objects or datatypes to look into would be very helpful at this early stage. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: three column dataset - additions and deletions
On Thu, 02 Dec 2010 22:55:53 +, Tim Harig wrote: Thanks for taking the time to check in on this, Tim! > So, basically, you want to store a local copy of the data and sync it to > the original. In a way. I only need to store one copy of the data, and make note of changes between it and the current data. > You need to differentiate between the in memory data model and the > storage model. Since this data comes from a database in the first > place, I would dump it to an sqlite3 database from the beginning. You > can use this to store, modify, and change the values as you receive them > from the database. I thought of doing that, but given that I only need to store a single instance of the data, a simple pickle will do the job nicely (am I correct in reading that it can save/load any python object?) > If you are looking for in-memory structures, then you haven't really > provided us with enough information on the significance and organization > of the data. The data columns: Long Int, String (under 30 chars), String (over 100 chars) The rows can scale up to hundreds, perhaps thousands. The integer is the database key, the shorter string is a user name, and the longer string is an access control definition. The whole idea of this script is to check, daily, for any added or removed users - or any altered access control definition. I realize this could likely all be done from inside the database itself - but altering the DB itself is not an option (as the product vendor is very touchy about that, and altering it can null our support agreement) -- http://mail.python.org/mailman/listinfo/python-list
Re: three column dataset - additions and deletions
On Fri, 03 Dec 2010 02:19:54 +, Tim Harig wrote: > a whole bunch of useful stuff Certainly some good points for me to chew on... thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: three column dataset - additions and deletions
The only reason I want the hash is that I don't want a copy of this string laying around. I also don't need to know what it is, I just need to know if it's different. Think of this as a tripwire - if someone's user access level is changed, we find out. I still think using a separate database (sqlite or not) is entirely unnecessary. The task simply isn't large enough of a scale to justify going to that extreme. That's like cutting a string with a chainsaw. Granted, the next time I'm at my workstation I'll just give it a go and just stick with whatever turns out "best" The alternatives are what I was looking for, and you all did provide them :) So here's the goal, since it seems it's still unclear: Cron will call my script on an interval (probably once a day... so yea). The script will determine if users were added, removed, or changed. If so, an email will be constructed with generic details "users bjoe, jdoe created; user mwallace deleted; user psouter access level changed" and sent to the MUA/MTA/whatever for delivery to myself and the other admins. -- http://mail.python.org/mailman/listinfo/python-list