|
I haven't done much Python before, so I was playing around with reimplementing some PHP experiment code I'd made. What the PHP code did was use reflection to take a method of a class, discover its arguments, and then allow a http GET to call that method, using the GET arguments as arguments for the function. I worked out how to discover the number of arguments of a method/function in Python, but it doesn't seem to have a way to discover the names of the arguments - anyone know if there would be a way to do this? I realize that in many languages, this probably doesn't make sense, since the names of arguments are just labels local to the definition of the function. If anyone has a nice guide on reflection in Python, it'd be appreciated - I could only find some rather obtuse references that led me to find im_func and so on, which I have to admit is slightly easier than PHP5's reflection methods.
|
# ¿ Jun 3, 2008 16:03 |
|
|
# ¿ May 20, 2024 16:25 |
|
That's great, thanks a lot.
|
# ¿ Jun 3, 2008 17:20 |
|
GregNorc posted:So I'm trying to create a function that returns True if the list is already orted, and false if it isn't. Wouldn't it be faster to check if the list is sorted in O(n) time (i.e. a single loop pass), rather than sorting it and comparing, taking O(n log n) time? Also, calling a function requires (), otherwise you're just expressing the function object. i.e. if you have a function def f(): return 1 a = f b = f() a contains the "value" of the function f, b contains the value 1.
|
# ¿ Dec 24, 2009 01:25 |
|
That question does indicate that you should probably not be using the .sort() or sorted() functions, but rather loop through and check that each element is in order. It is more efficient to do it that way, though it would work with the given conditions to do your method. Also since your code will be in python and sort() is presumably in C, it might be slower for any reasonable number of elements anyway.
|
# ¿ Dec 24, 2009 02:05 |
|
code:
|
# ¿ Dec 25, 2009 13:23 |
|
How else would you express many-to-one? Having a "linked" mechanism doesn't add anything over references as you still need to be able to remap one of a currently linked set to an unrelated item. Any many-to-one collection must ultimately be a dictionary of references as I described, since you still have to explicitly specify each item. Linking 'b' to 'a' is just code:
code:
code:
|
# ¿ Dec 26, 2009 02:53 |
|
I think the point of the 2to3 tool is that you rework your 2.x code into forward compatible 2.6 code that can then be translated automatically to give valid 3.x code. So for example, as Scaevolus said, you'd need to make sure all your division operators are appropriate and that you aren't using any features that will be removed. http://docs.python.org/dev/3.0/whatsnew/3.0.html#porting-to-python-3-0 explains the process pretty simply. chips fucked around with this message at 18:18 on Jan 1, 2010 |
# ¿ Jan 1, 2010 18:16 |
|
|
# ¿ May 20, 2024 16:25 |
|
Maybe you need to wrap the javascript code in HTML comment tags, if that's allowed. Otherwise find a better parser.
|
# ¿ Feb 28, 2010 17:27 |