|
Janin posted:If the plugin metadata is stored in a documented format, it can be used to load a class that implements the documented interface, which is then used as a plugin. No dependence on an external registration library is needed. Okay, I thought you meant sharing plugins between different applications, not different versions or instances of the same application, which would be troublesome with the metaclass approach.
|
# ¿ Jun 6, 2009 23:50 |
|
|
# ¿ May 14, 2024 03:22 |
|
Janin posted:There's not much difference, technically speaking, between different applications and very different versions of the same application. True enough, but you could also add a class variable requires_version="1.0.1" to check in the metaclass. Of course add enough of those and at some point you do have a config file, just in a class instead of a file. . . . Boblonius, I'd go with the code that Janin just provided. Metaclasses are fun and all but if you don't feel comfortable with them you shouldn't be using them yet. It would be easier to add error-checking to Janin's code than the metaclass code for you. You should look into metaclasses though just because they're so much fun and will give you a better idea of how Python works.
|
# ¿ Jun 7, 2009 00:10 |
|
Short answer: no. Long answer: yes, but only if the methods in the chain return self, which in the case of list is a (see Short Answer).
|
# ¿ Jun 7, 2009 08:34 |
|
Regular expressions? Seriously? http://docs.python.org/library/csv.html#module-csv is probably the easiest.
|
# ¿ Jul 6, 2009 00:20 |
|
Before 2.6 I didcode:
code:
|
# ¿ Aug 5, 2009 09:10 |
|
It looks like it's running fine except you didn't pass it any command line arguments and you're running it on windows instead of a *nix. There does not appear to be a problem. What do you think is wrong? Try running it from the command line like code:
|
# ¿ Aug 11, 2009 00:12 |
|
code:
0: . . . 1: . . . 2: . . . and so on
|
# ¿ Aug 12, 2009 17:51 |
|
With any luck Nokia's PySide, a recreation of PyQT, will ameliorate those horrors, as QT itself is fantastic and it would be nice to use in Python without dumb poo poo like that, but PySide is new and it's going to be a while before they even start to make the interface pythonic.
|
# ¿ Sep 10, 2009 02:28 |
|
Thermopyle posted:It's entirely possible that I'm not using objects right, but... 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.
|
# ¿ Dec 6, 2009 19:39 |
|
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 |
|
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 |
|
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 |
|
In Python 3+, print is a function not statement so its arguments need to be wrapped in ()
|
# ¿ Dec 17, 2009 20:20 |
|
I only have a minute but just glancing at it there are exactly zero reasons that should be a class and uncountably infinitely many why it shouldn't be. Other than that it looks fine, but like I said I just did it a cursory once over.
|
# ¿ Dec 17, 2009 22:22 |
|
if you replace sum(i, total) with i + total it will work. As it is sum(args) will work as you intend. Further, there is no reason for a while loop here. Tuples are iterable. Edit: if you're not trying this stuff out in the python shell, you're doing it wrong.
|
# ¿ Dec 27, 2009 23:44 |
|
quote:Traceback (most recent call last): You need to learn to read these. It says your sum_all function was called and inside it an error happened on line 6 where you call sum. So you open up the interactive interpreter and try a few things until you get to sum(1, 2) and see that that is the error.
|
# ¿ Dec 28, 2009 00:27 |
|
import atexit
|
# ¿ Jan 9, 2010 23:36 |
|
Assuming that that is your complete file, the first global isn't doing anything. You just need it in function bodies. But try to eschew global state.
|
# ¿ Feb 20, 2010 19:31 |
|
Stabby McDamage posted:I'd say namespace pollution is a big reason. The class is a namespace too a.norm() is as nonsensical as a.dotproduct(b)
|
# ¿ Mar 12, 2010 04:10 |
|
nbv4 posted:All though, I think that syntax is 2.6/3.x only. 2.5+, I believe
|
# ¿ Apr 11, 2010 18:10 |
|
Read about the global keyword
|
# ¿ Jun 19, 2010 06:30 |
|
Teaching OO anything to someone at that level is useless at best and destructive at worst. Let him get to the point where he has a program that could benefit from OO, not just scream BEST PRACTICE! and make him throw a bunch of stuff that makes no sense in his program.
|
# ¿ Jun 19, 2010 19:49 |
|
global not globals() Having a few global variables in an incredibly small program that runs once and then dies is hardly a hack. Better ways to structure code can be explored after he has the satisfaction of getting something working, but baby steps. Systran, get something to work. Let it be ugly. When you're sure it works, figure out ways to clean it up and keep asking questions.
|
# ¿ Jun 19, 2010 21:41 |
|
Modern Pragmatist posted:Although a singleton is a safer and more OO approach to a global variable, I still feel that there are very few situations that would warrant the use of either of these. While a singleton is certainly more OO it is not inherently more or less safe. It's the same thing with a different name. I gave a use for globals: short programs that run one and then quit, which I had thought systran's code was. You can certainly refactor globals away. The question is, is it worth the added complexity? On the other hand, globals are like gotos. Generally to be avoided but if it's simpler to use it, use it. Furthermore, in the context of someone new to programming, refactoring code and data flows to avoid global state is hardly justifiable. If you show them how to do it without showing them why or letting them learn why, then you get a coder who codes by dogma not experience and reason. The reason code with gotos and globals get a bad rap is because most of it is written by people who leap to them unreflexively without weighing the consequences or alternatives first. But bad code is bad code. That doesn't mean that the ingridients of bad code are themselves inherently bad. Bad code has plenty of if statements as well, after all.
|
# ¿ Jun 20, 2010 21:46 |
|
isa = isinstance
|
# ¿ Jul 4, 2010 03:12 |
|
Dictionaries are unordered. If you want to preserve order you can do a list of tuples but you'll have to search every element in the list and compare to the first element of the tuple which is significantly more work.
|
# ¿ Jul 15, 2010 06:10 |
|
That's a valid use of a file object, just not what he intended. If you use a file object as an iterator it defaults to readlines so your code could be expressed more simply as:code:
|
# ¿ Jul 18, 2010 20:33 |
|
sund posted:You'll need to use enumerate() if you want to do it that way, because "line" isn't the index of the line, it refers to the line itself. Here you are with slicing: You need to use islice or read the whole file into memory with readlines and then slice it: code:
code:
|
# ¿ Jul 26, 2010 04:09 |
|
It is still evaluated left to right:code:
|
# ¿ Nov 2, 2010 00:12 |
|
code:
|
# ¿ Nov 5, 2010 00:08 |
|
You are passing it two and it only accepts one. The first parameter of a method is the object so a.b() is the same as b(a) so a.b(c) is b(a, c). So you need to change your method to take (self, genome). also it's __init__ not init so it should be __init__(self, genome)
|
# ¿ Nov 9, 2010 09:17 |
|
use `enumerate`
|
# ¿ Nov 16, 2010 23:53 |
|
== : any X any -> bool. You don't need == True. Also If and if are different things as far as Python knows. Are you trying to find out if the type of a variable's value is int or are you trying to determine if a value is integral? Those are two very different things and everyone is answering the former question.
|
# ¿ Dec 19, 2010 05:43 |
|
Stabby McDamage posted:It's just that this is one of the most common file operations ever Really? I have never once had any reason to do that. What do you do where this is so incredibly common? Also since we're giving smartass answers open is the most common file operation ever.
|
# ¿ Jan 6, 2011 23:44 |
|
Why would you jump through all those hoops instead of just having a dict of functions
|
# ¿ Feb 21, 2011 21:45 |
|
|
# ¿ May 14, 2024 03:22 |
|
Yes, threads are not completely free. You'd get a better improvement by splitting the files up into n batches each processed by n threads where each thread processes each of the files in its batch serially.
|
# ¿ Apr 14, 2011 22:40 |