|
Lonely Wolf posted:No, that's not possible. Yes, it sounds like you are not using objects right. It sounds like you want is a function that returns a Film object iff it is constructible. Actually it technically is possible, it just involves a metaclass.
|
# ? Dec 6, 2009 20:09 |
|
|
# ? May 24, 2024 21:02 |
|
Hmm, I suppose so but it's also technically possible to shoot yourself in the face. I wouldn't recommend either, except in special circumstances.
|
# ? Dec 6, 2009 20:30 |
|
Milde posted:Sounds like either his distribution of Python is built incorrectly, or the app he's trying to build is adding those flags itself. afaik its just bog standard apple python on a pretty standard snow leopard install mindyou theres been many iiterations of Xcode on there, so gently caress knows what impact that has.
|
# ? Dec 6, 2009 21:57 |
|
duck monster posted:afaik its just bog standard apple python on a pretty standard snow leopard install well --cflags gives me this on the default Snow Leopard python install: code:
|
# ? Dec 7, 2009 02:00 |
|
Sailor_Spoon posted:well --cflags gives me this on the default Snow Leopard python install: code:
How would I give it a kick in the teeth and tell it to use the proper version?
|
# ? Dec 7, 2009 03:38 |
|
duck monster posted:
Are you using python.org's distribution? If so, uninstall it and use Apple Python (it lives in /System). Alternatively, install python2.6 from MacPorts.
|
# ? Dec 7, 2009 03:49 |
|
duck monster posted:Should I be on v2.6 by now? Seems to have hung onto an old build or something whacko like that. If you're on Snow Leopard, than you have 2.6.2 installed, only it's in /System as Milde mentioned. It should just be a matter of changing your PATH to point to it first. I recommend ensuring that /System/Library/Frameworks/Python.framework/Versions/2.6/bin is first, or at least before any of the usual bin/ dirs in $PATH. If you want to stick with 2.5, or at least use it by default, there is also a 2.5.4 framework in /System. From the sound of the problems you're having, I'd probably just nuke your existing python install. If none of the /System frameworks will do for whatever reason, just grab one of the .dmg installers from python.org. I don't have any good, concrete reasoning, but I strongly advise against installing from macports. That way lies madness and sorrow.
|
# ? Dec 7, 2009 06:49 |
|
Found it. There was some poo poo stuck in my .profile (or whatever it is again) that was locking it down to the apple 2.5 instead of 2.6. Removed that and victory ensured. Still a little puzzling why apples 2.5 python has GCC options that are not compatible with its prefered GCC. Maybe it didn't upgrade it from leopard when I upgraded, maybe due to some dumb poo poo.
|
# ? Dec 8, 2009 06:59 |
|
Ok, so the different pieces of software I'm writing are getting close to 5k lines total, and managing all this is getting irritating. Maintaining different versions while trying out different methods to solve problems, keeping old versions around, etc is not fun. Given that I know nothing about the subject, I'm guessing I need some sort of version control system/code repository/magic. I guess this maybe isn't Python specific...but maybe it is, I don't know: What's a good solution for a developer on a Windows machine? Is this completely language agnostic, meaning I should make a new thread about it?
|
# ? Dec 9, 2009 01:03 |
|
Thermopyle posted:What's a good solution for a developer on a Windows machine? Is this completely language agnostic, meaning I should make a new thread about it? Pretty much this. But the common open source revision control systems are: Subversion(Centralized RCS) Mercurial(Distributed RCS) Git(Distributed RCS - Used by most Linux kernel developers) See wikipedia for the difference between centralized and distributed revision control. Edit: And here is the megathread. griliard fucked around with this message at 01:19 on Dec 9, 2009 |
# ? Dec 9, 2009 01:11 |
|
I don't recommend using Git if you're only developing on Windows, it's a pain to use.
|
# ? Dec 9, 2009 02:27 |
|
Captain Lou posted:I don't recommend using Git if you're only developing on Windows, it's a pain to use. Listen to this man. I use TortoiseHg.
|
# ? Dec 9, 2009 03:44 |
|
I'm having trouble with the immutable strings.. I'm writing something small and gimmicky, and it relies on changing individual characters in a string.. (many many times over) I'm struggling to work out how to get around it
|
# ? Dec 10, 2009 22:10 |
|
echinopsis posted:I'm having trouble with the immutable strings.. I'm writing something small and gimmicky, and it relies on changing individual characters in a string.. (many many times over) code:
|
# ? Dec 10, 2009 22:13 |
|
echinopsis posted:I'm having trouble with the immutable strings.. I'm writing something small and gimmicky, and it relies on changing individual characters in a string.. (many many times over) use lists? You're going to have to be a little more specific.
|
# ? Dec 10, 2009 22:19 |
|
Sailor_Spoon posted:use lists? You're going to have to be a little more specific. I think you mean "NumPy arrays". The overhead from a list of characters in Python would be hilarious.
|
# ? Dec 10, 2009 22:21 |
|
Avenging Dentist posted:I think you mean "NumPy arrays". The overhead from a list of characters in Python would be hilarious. he said it was "small and gimmicky"
|
# ? Dec 10, 2009 22:26 |
|
Sailor_Spoon posted:he said it was "small and gimmicky" I would assume he's worried about performance to some degree, or he'd have just written a function that did s[0:i]+char+s[i+1:]
|
# ? Dec 10, 2009 22:43 |
|
Sailor_Spoon posted:use lists? You're going to have to be a little more specific. i'm attempting to make that program dawkins used to "prove" evolution it takes a random string of characters "tyikjc" and a target "target" and then every cycle it randomly changes each character unless it ends up as one of the target letters output might look like this: (but will take many more iterations) tyikjc trruyt tarewt targut target so I'd cycle through each character in the string replacing each one with a random character unless it matched the target letter, then print the string, then repeat, until eventually all the letters were the same as the target edit: this is the first thing I've ever coded in python and I'm a noob when it comes to coding eitherway echinopsis fucked around with this message at 23:13 on Dec 10, 2009 |
# ? Dec 10, 2009 23:11 |
|
echinopsis posted:i'm attempting to make that program dawkins used to "prove" evolution (I remember writing a program just like that to learn Python.) The simplest solution speedwise is probably - as Sailor_Spoon said - to model the "chromosome" or sentence as a list of characters (single letter strings) rather than a string. Actually I seem to remember someone using this exact problem to compare the various ways of mutating strings in Python. If you just don't want to bothered about the immutability of strings (for the purposes of the exercise), you could use MutableString. It's not fast, but I think it's still hanging around in the standard library.
|
# ? Dec 11, 2009 01:00 |
|
echinopsis posted:i'm attempting to make that program dawkins used to "prove" evolution code:
|
# ? Dec 11, 2009 01:11 |
|
tripwire posted:Here's a version which uses lists of letters in place of strings. Its slow but for your purposes I think it will work. I think I need to go back to the documentation because I can't follow that code at all what I wanted to do would look like this code:
|
# ? Dec 11, 2009 02:45 |
|
code:
|
# ? Dec 11, 2009 03:05 |
|
echinopsis posted:so that's my attempt using lists but I must fundamentally misunderstand something as it complains that I am indexing out of range whenever I got toy[i] something (and i=>1).. what is wrong with me code:
|
# ? Dec 11, 2009 03:23 |
|
echinopsis posted:
I actually took your earlier example and made it work with not very many changes at all. It manages it in about 50-100 iterations. Here is is, with comments about why I changed things. code:
Jonnty fucked around with this message at 03:26 on Dec 11, 2009 |
# ? Dec 11, 2009 03:24 |
|
Jonnty posted:If you don't understand anything, please do ask. I'm sure AD would have you using numpy and JIT compilers and poo poo, but for your purposes, that's fine. It's worth noting, though, that this isn't really an accurate simulation of evolution (whereas tripwire's is) because once you've got something you know to be right, you stick to it. Real evolution doesn't have that luxury - it just knows how good something is as a whole - so it just tries to better that by randomising everything. Work through tripwire's code, and you'll hopefully get what I'm aiming at. thanks for the help man, I'll work through it I'm not trying to make an evolution simulator though, just this specific program..
|
# ? Dec 11, 2009 03:38 |
|
Just had a work through it.. thanks for the help it's really, um, helpful I appreciate it. I'm glad my theory was there, just not my understanding of the implementations of lists etc.. One day I will get there edit:http://forums.somethingawful.com/showthread.php?threadid=3239608 echinopsis fucked around with this message at 03:54 on Dec 11, 2009 |
# ? Dec 11, 2009 03:43 |
|
I'm having difficulty with some basic python and wondered if anyone could give me a quick hand, or at least tell me if the solution to this is a simple or a difficult one. I have two dictionaries of the format {groupID:{IDswithingroup:numberofoccurences}} I want to merge them together. Can anyone help? Thanks!
|
# ? Dec 16, 2009 04:45 |
|
itsasnake posted:I have two dictionaries of the format {groupID:{IDswithingroup:numberofoccurences}} code:
When in doubt, just go to that stdtypes page and look at the available methods for the data type you're working with
|
# ? Dec 16, 2009 05:16 |
|
nice! Thanks very much. I did look at that method but misunderstood it, i assumed it would not work for dict within dict.
|
# ? Dec 16, 2009 05:21 |
|
Actually, after testing it, it doesn't work how i want it to. I have 2 dictionaries, both of these have a dictionary within them. So 2 separate dictionaries which are both of the format. {IDno{IDgroup:numberofoccurences}} If i simply update one with the other then in cases where both dictionaries have an ID number, the contents of one dictionary gets overwritten. I need the two dictionary contents added together. Such as below {1:{[A:1],[B:2]}} {1:{[C:1],[E.4]}} = {1:{[A:1],[B:2],[C:1],[E,4]} Group IDs will always be different so i do not need to worry about them being the same. edited for more clarity. edit: nevermind, solved it. Using that update function and for loops. thanks. edit: again, no still not working. Sorry for indecisiveness! Would appreciate some help on this if possible! itsasnake fucked around with this message at 06:23 on Dec 16, 2009 |
# ? Dec 16, 2009 05:54 |
|
Something like this?code:
|
# ? Dec 16, 2009 07:23 |
|
Sort of, though i don't think that accounts for circumstances where only one of the 2 dictionaries has a specific persons ID.
|
# ? Dec 16, 2009 07:34 |
|
Well how about this then:code:
|
# ? Dec 16, 2009 07:44 |
|
Or you could roughly halve the performance cost and:code:
Avenging Dentist fucked around with this message at 08:26 on Dec 16, 2009 |
# ? Dec 16, 2009 07:49 |
|
Yeah, thats it, thanks guys.
|
# ? Dec 16, 2009 08:08 |
|
I'm not sure what problem you're trying to solve, but have you considered flattening your dictionary and using tuples as keys instead? That would simplify your merges since keys wouldn't overlap. Seeing one dictionary stored in another makes me a bit, since whenever I've used that pattern in my own code, I've always refactored it out later. So, you might want to try changing this: code:
code:
Once again, not sure what you're trying to do, just some food for thought.
|
# ? Dec 16, 2009 18:27 |
|
What's a good heuristic for figuring out whether something would be better as a method or a function? I'm always torn about this. For example, I have this class: code:
code:
|
# ? Dec 16, 2009 18:49 |
|
Thermopyle posted:What's a good heuristic for figuring out whether something would be better as a method or a function? If you are setting attributes on just a specific type of object, that should be a method of that object not a function. Let the class's __init__ method do all the initializing by passing it the path. It would also be nice to store the file path in the class as well. You could also make stuff like codec, vres and hres properties(using either the builtin or the decorator) with their own setters and getters if you were so inclined so that exec_n_return is only called once when you actually first try and get the attribute not on initialization. tehk fucked around with this message at 19:07 on Dec 16, 2009 |
# ? Dec 16, 2009 18:59 |
|
|
# ? May 24, 2024 21:02 |
|
Thermopyle posted:What's a good heuristic for figuring out whether something would be better as a method or a function? Is it an intrinsic action on the abstraction itself or is it an action that uses the abstraction? That's what I use. In your specific case, it seems that you want that function to be __init__ unless there are several ways to create the object in which case several such factory functions is the way to go.
|
# ? Dec 16, 2009 19:14 |