27966

Typing Casting in Python Question [closed]

Question:

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?

Answer1:

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 <a href="http://www.eclipse.org/" rel="nofollow">Eclipse</a> (or <a href="http://aptana.com/products/studio2" rel="nofollow">Aptana</a>) with <a href="http://pydev.org/" rel="nofollow">pydev</a>. Some <a href="http://pydev.org/download.html" rel="nofollow">installation instructions</a>.

Answer2:

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.

Answer3:

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 <a href="http://github.com/dorkitude/tagalog" rel="nofollow">tagalog</a> (which supports <em>n</em> 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 <a href="https://github.com/dorkitude/tagalog/blob/master/tagalog.py" rel="nofollow">here</a>. The output location for Python's logging module (<a href="http://docs.python.org/library/logging.html" rel="nofollow">docs here</a>) depends on your configuration.

To watch a file in realtime, do this in the linux/unix/mac terminal:

tail -f /path/to/file

Answer4:

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()

Recommend

  • Android: Getting source code from an APK file with R.java
  • Typing Casting in Python Question [closed]
  • What is the red X on my CSS file icon in Aptana Studio 3?
  • Eclipse Android Motodev and PHP integration
  • Why we need a coarse quantizer?
  • What's the rationale behind “Assignment in condition” warnings in Zend Studio IDE?
  • Naming functions, methods, pointers, variables, arrays etc in C++
  • C++11 source code generation
  • Aptana3 rename variable in a file
  • PyDev displays undefined variable from import for 1 out of 2 vars
  • How to add to Aptana helpful panel with snippets?
  • PHP: Using array keys to identify function arguments [closed]
  • Set locale encoding in python
  • Eclipse Configuration Error: Invalid Google App Engine directory
  • How to print colorful text in Python terminal? [closed]
  • Where and How To Define An Application Property? - JHIpster
  • How to attach php documentation in eclipse
  • Eclipse code fomatting
  • Thread Synchronization with IntentService
  • Spring Integration debounce/deduplicate
  • How to set the navigation bar to the top in Table View?
  • Base Internationalization and “Could not find a storyboard named […]”
  • CUDA NSight is not installed with CUDA 5.0 installation file on Windows 8? [closed]
  • jQueryMobile, Ajax Navigation, and MVC
  • “A GKScore must specify a leaderboard.”
  • pygame.init() shows as undefined variable after installing Pygame
  • Add Windows Feature from C#
  • Wrapping text in spinner android
  • Any nice way to generate a timeline view of commits from subversion?
  • Local Development, Apache vs Developer - file permissions
  • Can I programmatically choose the Android layout folder?
  • Debugging VB6 Code From Visual Studio 2010
  • Graphics.CopyFromScreen [Web application] + The handle is invalid
  • Does Mobilefirst provide a provision to access web services directly?
  • ADO and msqli connections very slow
  • zope_i18n_compile_mo_files doesn't work on a Zeo configuration
  • How to suppress a dialog
  • Change multiple background-images with jQuery
  • How to get icons for entities from eclipse?
  • How can I remove ASP.NET Designer.cs files?