|
Oddhair posted:I keep getting: This indicates that it found a line somewhere that begins with "File Created", but doesn't have any other spaces in it. I can only guess that this means somewhere in your file there's a line that just says "File Created" or "File Created\par" or something but doesn't have a date. You can get more information about any of the variables that are being used by printing them out; this will also help show if things are working at all or if my crazy assumptions based on your sample file are off-base. code:
|
# ? May 10, 2011 04:21 |
|
|
# ? Jun 2, 2024 15:14 |
|
Yep, there are apparently some files without dates, but I'm reasonably sure they all have hashes. I'm looking at this now, but I'm too green to modify it to allow for either the date or the hash or both being empty. No biggie, I've gotten a PM from someone interested in doing it, thanks everyone for all your help. Oddhair fucked around with this message at 14:58 on May 10, 2011 |
# ? May 10, 2011 14:12 |
|
Hmm, I'm using Python to generate a 65x75 array file in a dumb game I'm working on in my spare time. I'm still pretty new to Python and desktop programming in general so I may be doing something completely wrong here. I'm using code like this to save a file filled with Tile objects: code:
code:
|
# ? May 10, 2011 14:35 |
|
karma_coma posted:Hmm, I'm using Python to generate a 65x75 array file in a dumb game I'm working on in my spare time. I'm still pretty new to Python and desktop programming in general so I may be doing something completely wrong here. Avoid calling your variable 'map', map is a keyword in python. To put your filename together use os.path.join(). You incur overhead associated with the objects when you pickle your data which makes your files larger than they need be. Consider writing your planet data to disc in a binary format rather than by using pickle. The struct module will help you read and write binary.
|
# ? May 10, 2011 18:07 |
|
Dren posted:Avoid calling your variable 'map', map is a keyword in python. Ahh thanks for all the info. That was exactly what I was looking for. Thanks!
|
# ? May 10, 2011 18:34 |
|
So I've written a life like cellular automaton thing using pygame and numpy. Everything works fine except my function for updating the grid runs like rear end. Does anyone have any suggestions to get it to run faster? I've already cut the run time of this function by like 40% over my first version, but it was so bad to begin with that it's still holding everything else up.code:
code:
fart simpson fucked around with this message at 19:28 on May 10, 2011 |
# ? May 10, 2011 19:22 |
|
You could store two grids: the grid you have now and a grid of neighbor values. That value you compute could be generated as you update the grid for each iteration of your game. This will save you from doing the check on all 8 neighbors and reduce your runtime from R * C * 8 to R * C. (Where R and C are the sizes of the ranges) e.g. code:
|
# ? May 10, 2011 21:28 |
|
Thanks, that made it run almost 7 times faster in practice.
|
# ? May 10, 2011 22:48 |
|
Use PyPy.
|
# ? May 11, 2011 04:42 |
|
MeramJert posted:Thanks, that made it run almost 7 times faster in practice. Sweet! Just to be computer sciency about it, the tradeoff there is memory/runtime and you can often make that trade in order to optimize one or the other.
|
# ? May 11, 2011 14:03 |
|
king_kilr posted:Use PyPy. Can you get numpy to work with pypy? e: yeah, this isn't really applicable to me at all since I'm basing everything on pygame and numpy, both of which are incompatible with pypy. fart simpson fucked around with this message at 19:20 on May 11, 2011 |
# ? May 11, 2011 18:55 |
|
MeramJert posted:Can you get numpy to work with pypy? Totally working on it: http://morepypy.blogspot.com/2011/05/numpy-in-pypy-status-and-roadmap.html http://morepypy.blogspot.com/2011/05/numpy-follow-up.html . Someone is playing with getting enough of cpyext working to use pygame as well. We totally understand people want NumPy, we want NumPy too. Ninja edit: if people have questions about pypy feel free to ask me
|
# ? May 11, 2011 23:07 |
|
king_kilr posted:Totally working on it: http://morepypy.blogspot.com/2011/05/numpy-in-pypy-status-and-roadmap.html http://morepypy.blogspot.com/2011/05/numpy-follow-up.html . Someone is playing with getting enough of cpyext working to use pygame as well. We totally understand people want NumPy, we want NumPy too. Is PyPy in/going to be in pydev to replace psyco? (Particularly for eclipse under windows.)
|
# ? May 11, 2011 23:48 |
|
Hughlander posted:Is PyPy in/going to be in pydev to replace psyco? (Particularly for eclipse under windows.) Does PyDev ship psyco or something? At this point psyco is no longer actively maintained, it's primary author, Armin Rigo has been working on PyPy from the very beginning.
|
# ? May 11, 2011 23:52 |
|
king_kilr posted:Does PyDev ship psyco or something? At this point psyco is no longer actively maintained, it's primary author, Armin Rigo has been working on PyPy from the very beginning. It complains when psyco isn't found about not being able to use it, when I looked into it/asked about it a year or so back the answer was 'we're waiting for pypy to be stable/release and won't be supporting psyco anymore' (Particularly on 2.7 obviously.)
|
# ? May 12, 2011 00:41 |
|
I have a question that's more a general algorithm question than a Python question. So if I had a very large grid, and randomly moving particles were spread out all across it, what would be a good way to select 1 particle and tell which other particles are within a certain distance of the selected one? The only way I can think of involves checking the position of every particle in the whole system to see if they are in range, but there has to be a better way to do it.
|
# ? May 13, 2011 02:54 |
|
MeramJert posted:I have a question that's more a general algorithm question than a Python question. So if I had a very large grid, and randomly moving particles were spread out all across it, what would be a good way to select 1 particle and tell which other particles are within a certain distance of the selected one? The only way I can think of involves checking the position of every particle in the whole system to see if they are in range, but there has to be a better way to do it. One idea might be to keep track of a mapping from chunks of your grid to individual particles. So say your grid went from (0,0) to (100,100) - you might keep a mapping from 10x10 squares to a set of the particles contained within the squares. Keeping track of this would only require a constant-time addition to your physics tick process, but if your particles are generally not clustered together would significantly reduce the amount of particles you need to check (just check those from the 10x10 squares near the target). You can be cleverer than this by allowing for variable-sized partitions (ie, not all of your squares are 10x10), using smaller ones where particles are more densely gathered. This is much harder, especially if the "dense areas" move over time, but might be more effective if you have particles clustered together all the time.
|
# ? May 13, 2011 03:17 |
|
Hmm, I was sort of tossing a similar idea around in my head. It reminds me of loading zones in an open world RPG. This seems like it must be some sort of solved problem already, though?
|
# ? May 13, 2011 03:28 |
|
MeramJert posted:I have a question that's more a general algorithm question than a Python question. So if I had a very large grid, and randomly moving particles were spread out all across it, what would be a good way to select 1 particle and tell which other particles are within a certain distance of the selected one? The only way I can think of involves checking the position of every particle in the whole system to see if they are in range, but there has to be a better way to do it. There are various way to do this using clustering. I used a method called k-means clustering in a scientific computing course using Euclidean distance for clustering star data. So you could Google k-means and see how it works for you. It worked pretty good for me for a data set on the order of 100,000 stars in a large 3d space and clustered the data in 3 to 10 groups in about a minute using Python and numpy. VirtuaSpy fucked around with this message at 18:25 on May 15, 2011 |
# ? May 13, 2011 04:36 |
|
MeramJert posted:I have a question that's more a general algorithm question than a Python question. So if I had a very large grid, and randomly moving particles were spread out all across it, what would be a good way to select 1 particle and tell which other particles are within a certain distance of the selected one? The only way I can think of involves checking the position of every particle in the whole system to see if they are in range, but there has to be a better way to do it. You might benefit from looking into K-D trees.
|
# ? May 13, 2011 06:18 |
|
Possibly dumb question: How do I correctly do a format string that also contains a literal %? Example:code:
|
# ? May 13, 2011 19:00 |
|
crazyfish posted:Possibly dumb question: How do I correctly do a format string that also contains a literal %? Example: %%
|
# ? May 13, 2011 19:07 |
|
A A 2 3 5 8 K posted:%% Thanks!
|
# ? May 13, 2011 20:22 |
|
I'm using urllib2 to monitor a web socket I have the following class which handles connecting to the site and receiving a response:code:
code:
I'm sure I'm missing something obvious, but why is it I can't shut down my original stream thread?
|
# ? May 14, 2011 18:13 |
|
I had a crazy idea today. I have a well-defined API that is machine readable and very detailed. I'm wondering if it's possible to translate it into a class dynamically...i.e. to have code that parses the spec and produces a class (not an object) that can be instantiated against it. Leaving aside the OO aspect for the moment, I'm wondering if there's a programmatic way to construct a function. For example, if I have an array of input variable names (strings) and an array of booleans that indicates if a given input is optional (i.e., defaults to None), could I programmatically build the function? Assume that the body of the function is always the same (it just walks the args and does something). Could it be done? Example: code:
EDIT: I should add that part of the goal is parameter name checking, so push_widget=generic_handler isn't going to cut it unless we can layer parameter name checking on top somehow. Stabby McDamage fucked around with this message at 22:26 on May 16, 2011 |
# ? May 16, 2011 22:18 |
|
So, to clarify, you want to REQUIRE callers to use keyword arguments for every parameter, regardless of whether it's optional? That is, something like:code:
code:
Edit: This doesn't add your function to the global namespace on its own, of course - it's probably cleaner to add it to a dict from function names to these generated functions than to just shove them in the global namespace, unless there's some reason you absolutely can't do that. brosmike fucked around with this message at 23:27 on May 16, 2011 |
# ? May 16, 2011 23:18 |
|
Stabby McDamage posted:I had a crazy idea today. I have a well-defined API that is machine readable and very detailed. I'm wondering if it's possible to translate it into a class dynamically...i.e. to have code that parses the spec and produces a class (not an object) that can be instantiated against it.
|
# ? May 17, 2011 03:07 |
|
Janin posted:Use eval() -- it's ugly, not not as ugly as mucking around in internal Python implementation details. I wouldn't really call using **kwargs "mucking around in internal Python implementation details". It's possible that an eval call could open up a pretty serious security hole, depending on where the data is coming from. Also, Stabby McDamage posted:Obviously I could use string processing to write the python itself, but I think it's more interesting to build the objects dynamically, that way the machine-readable spec can live right in the code.
|
# ? May 17, 2011 03:24 |
|
brosmike posted:I wouldn't really call using **kwargs "mucking around in internal Python implementation details". It's possible that an eval call could open up a pretty serious security hole, depending on where the data is coming from. Also, Given how simple the requirements are, it's trivial to verify the input (parameters, function name, and function body match ^[a-zA-Z_]$) before compiling the generated string. e: Here's a simple implementation. I assumed [[ funtion_body = generic_handler ]] was not a typo, and the attribute is an actual function; if it was a typo, you'll have to tweak this code slightly. code:
TOO SCSI FOR MY CAT fucked around with this message at 04:15 on May 17, 2011 |
# ? May 17, 2011 03:41 |
|
http://docs.python.org/library/ast.html
|
# ? May 17, 2011 11:40 |
|
Where can one find documentation on the C API for writing extensions? I'm trying to do something that I'd think would be pretty easily but I'm having a hard time finding one place that will tell me how to do it. I want to create a new object, I want to add attributes to it, I want those attributes to be ASCII strings, numbers, lists, and dictionaries. I want to make sure the ref counts are all correct, and return it back to Python. It seems like this should all be Baby's First Extension, but my google-fu is failing horribly.
|
# ? May 17, 2011 17:07 |
|
you may enjoy using ctypes or cython instead of the c api
|
# ? May 17, 2011 17:20 |
|
Hughlander posted:Where can one find documentation on the C API for writing extensions? I'm trying to do something that I'd think would be pretty easily but I'm having a hard time finding one place that will tell me how to do it. I learned all of my extension writing from this tutorial. It's only relevant for the 2.* series, I believe. The Python docs cover creating extensions here.
|
# ? May 17, 2011 17:21 |
|
So I have a bunch of filenames in the wrong character encoding. It shows up like garbage in Windows, etc. Basically they're encoded as big5 but everything thinks they're encoded as utf-8, and I'd like to write a script to go through and re encode them as utf-8 in actuality. I can do what I want manually in the python shell by getting the filename and doing this:code:
So basically, I need what's actually written on my screen, u'\xa6\xd0\xa4\xf2\xaae', without the u at the front. Any help? I fukken hate character encodings
|
# ? May 18, 2011 01:45 |
|
MeramJert posted:So I have a bunch of filenames in the wrong character encoding. It shows up like garbage in Windows, etc. Basically they're encoded as big5 but everything thinks they're encoded as utf-8, and I'd like to write a script to go through and re encode them as utf-8 in actuality. I can do what I want manually in the python shell by getting the filename and doing this: code:
|
# ? May 18, 2011 03:01 |
|
MeramJert, you might try thiscode:
http://docs.python.org/howto/unicode.html I had a very similar problem this weekend.
|
# ? May 18, 2011 14:45 |
|
Okay, posting this code, I know it's completely wrong somehow, but I'm having a complete blank on how to get poo poo to work properly. I'm almost embarrassed to post this, but I'm not going to learn. I gotta be stupid sometime. pre:# Guess my number, GUI edition from tkinter import * class Application(Frame): """ Set up the GUI """ def __init__(self, master): import random super(Application, self).__init__(master) self.grid() self.counter = 0 #Counter for tries self.guess = "" #Current Guess self.number = random.randint(1, 100) #Random number self.create_widgets() def create_widgets(self): """ Create the input box """ self.inst_lbl = Label(self, text = "Guess the number between 1 and 100!" ).grid(row = 0, column = 0, columnspan = 2, sticky = W) self.count_lbl = Label(self, text = str(self.counter), ).grid(row = 1, column = 3, sticky = W) self.current_guess = Label(self, text = "Guess: " ).grid(row = 2, column = 0, sticky = W) self.guess = Entry(self) self.guess.grid(row = 2, column = 1, sticky = W) Button(self, text = "Guess!" command = self.check() ).grid(row = 2, column = 3, sticky = W) def check(self, guess): #Stuff here to check if it's right or not def reset(self): import random self.counter = 0 self.guess = "" self.number = random.randint(1, 100) root = Tk() root.title("Guess my number!") app = Application(root) root.mainloop()
|
# ? May 19, 2011 15:59 |
|
Gothmog1065 posted:I know my biggest problem here is how the buttons work, I'm just not able to get my mind around how it works. I'm using Tkinter because it what the book I'm using uses. I might go ahead and do the next chapter, but it really doesn't have much in the way of buttons (pictures and sounds yay!). I can't actually get this to run, but from the looks of it you are defining the Button callbacks (command) incorrectly. You want to specify a method for the button to call. As a result, you don't want to call the method in the assignment. command=self.check instead of command=self.check() Also, it looks like you are trying to pass arguments to the callback. For that you need to use lambda functions. See documentation here command=lambda: self.check(guess) Modern Pragmatist fucked around with this message at 16:39 on May 19, 2011 |
# ? May 19, 2011 16:37 |
|
Modern Pragmatist posted:I can't actually get this to run, but from the looks of it you are defining the Button callbacks (command) incorrectly. You want to specify a method for the button to call. As a result, you don't want to call the method in the assignment. edit: changed that button to: pre:Button(self, text = "Guess!" command = lambda: self.check(guess) ).grid(row = 2, column = 3, sticky = W)
|
# ? May 19, 2011 19:07 |
|
|
# ? Jun 2, 2024 15:14 |
|
Gothmog1065 posted:Yeah, I'm doing something wrong, all of those are throwing syntax errors. Commas between arguments? code:
|
# ? May 19, 2011 20:49 |