In Python, functions like str(), int(), float(), etc. are generally used to perform type conversions. However, these require you to know at development time what type you want to convert to. A subproblem of some Python code I'm trying to write is as follows:
Given two variables, foo and bar, find the type of foo. (It is not known at ...
Apropos of This question, there is a bit of scaffolding within the interpreter to inspect frame objects, which can be retrieved by sys._getframe(). The frame objects appear to be read only, but I can't find anything obvious in the docs that explicitly states this. Can someone confirm whether these objects are writeable (in some way) or...
Suppose you have a python method that gets a type as parameter; is it possible to determine if the given type is a nested class?
E.g. in this example:
def show_type_info(t):
print t.__name__
# print outer class name (if any) ...
class SomeClass:
pass
class OuterClass:
class InnerClass:
pass
show_type_info(Some...
The following code
import types
class A:
class D:
pass
class C:
pass
for d in dir(A):
if type(eval('A.'+d)) is types.ClassType:
print d
outputs
C
D
How do I get it to output in the order in which these classes were defined in the code? I.e.
D
C
Is there any way other than using inspect.getsour...
Say you have a javascript object like this:
var data = { Name: 'Property Name', Value: '0' };
You can access the properties by the property name:
var name = data.Name;
var value = data["Value"];
But is it possible to get these values if you don't know the name of the properties? Does the unordered nature of these properties make it...
Why does creating/modifying a member of locals() not work within a function?
Python 2.5 (release25-maint, Jul 20 2008, 20:47:25)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> # Here's an example of what I expect to be possible in a function:
>>> ...
Given a class C in Python, how can I determine which file the class was defined in? I need something that can work from either the class C, or from an instance off C.
The reason I am doing this, is because I am generally a fan off putting files that belong together in the same folder. I want to create a class that uses a Django template...
When generating cache-keys for rendered content in web applications, you have to take into account all variables that might change the result.
In dynamic environments like rails these can be defined in different places: the controller, a model, the session or the server environment. And they can be referenced in the template, in a templa...
Java's java.lang.Class class has a getDeclaredFields method which will return all the fields in a given class. Is there something similar for Common Lisp? I came across some helpful functions such as describe, inspect and symbol-plist after reading trying out the instructions in Successful Lisp, Chapter 10 (http://www.psg.com/~dlamkins/s...
In Java is there a way to retrieve the format string from a Format object (or any derived classes)
In code:
Format f = new DecimalFormat("$0.00");
System.out.println(???);
Is there something I can use to get System.out.println(???); to print "$0.00".
I looked at toPattern(); but that function doesn't appear in the abstract Format c...
I'm looking for a tool that can provide code quality metrics.
For instance it could report
very long functions (spaghetti code)
very complex classes (which could contain do-it-all code)
...
While we're on the (subjective:-) subject of code quality, what other code metrics would you suggest?
I'm targetting C#/.NET code, but I'm sure...
Hello,
Is there a method that returns all the keys for an object conforming to the NSKeyValueCoding protocol?
Something along the lines of [object getPropertyKeys] that would return an NSArray of NSString objects. It would work for any KVC-compliant object. Does such a method exist? I haven't found anything in searching the Apple docs ...
How do I list available methods on a given object or package in Perl?
...
What is the proper way to loop over a Python object's methods and call them?
Given the object:
class SomeTest():
def something1(self):
print "something 1"
def something2(self):
print "something 2"
...
How do you dynamically find out which functions have been defined from an instance of a class?
For example:
class A(object):
def methodA(self, intA=1):
pass
def methodB(self, strB):
pass
a = A()
Ideally I want to find out that the instance 'a' has methodA and methodB, and which arguments they take?
...
How do I find out which class I am initialising a decorator in? It makes sense that I wouldn't be able to find this out as the decorator is not yet bound to the class, but is there a way of getting round this?
class A(object):
def dec(f):
# I am in class 'A'
def func(cls):
f(cls)
return func
@dec...
Say you have a flexunit test that looks like this:
package foo {
import flexunit.framework.TestCase;
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedSuperclassName;
class DescribeTypeTest {
public function testDescribeInnerType():void {
var currentInstance:ChildBar = new ChildBar();
...
In the spirit of the c# question..
What is the equivalent statements to compare class types in VB.NET?
...
I'm starting to code in various projects using Python (including Django web development and Panda3D game development). To help me understand whats going on, I would like to basically 'look' inside the Python objects to see how they tick - like their methods and properties. So say I have a Python object, what could would I need to print o...
Hi,
I'm trying to write a tool which lets me inspect the state of a PowerBuilder-based application. What I'm thinking of is something like Spy++ (or, even nicer, 'Snoop' as it exists for .NET applications) which lets me inspect the object tree (and properties of objects) of some PowerBuilder-based GUI.
I did the same for ordinary (MFC-...