Typing Casting in Python Question [closed]
Im a AS3 developer, currently learning Python
In AS3 Id quite often do this:
for ( var foo in fooArray ) {
trace(FooObject(foo).name);
}
Typing casting the objects in the array, so that I get code hinting in my IDE
How would I do this in Python?
There is no type casting in Python, as types are dynamic, so casting is completely pointless. Your IDE will give hints if it can figure out what type it is, which it often can't.
Types are determined at runtime in Python. Thus, there is typically less "code hinting" (I assume you mean completion, navigation, and so forth) in IDEs. There is still some.
Related: a commonly used IDE for Python development with some hinting is Eclipse (or Aptana) with pydev. Some installation instructions.
Your best bet is to use logging. Python has a default logging module (with five strict levels: debug, info, error, etc), but I prefer my own tagalog (which supports n arbitrary tags on log messages).
With python logging module:
import logging
for foo in foo_list:
logging.log(type(foo))
With tagalog:
import tagalog
for foo in foo_list:
tagalog.log(type(foo))
Either of these approaches will write entries to a log. The output location for tagalog is always a file, which is specified in the 'log_file_path' variable here. The output location for Python's logging module (docs here) depends on your configuration.
To watch a file in realtime, do this in the linux/unix/mac terminal:
tail -f /path/to/file
Figured this out, Python deal with classes a little more intelligently
In Actionscript
for ( var f in itemArray ) {
// call function in f
FooObject(f).doSomething()
}
In Python
for FooObject in itemArray:
# call function
FooObject.foo()
精彩评论