PHP » PYTHON |
login |
register |
about
|
PYTHON Magic constants
is this article helpful?
|
Python replacement for PHP's Magic constants
[
edit
| history
]
This is not exact replacements but here are some ways to achieve the same.
Some of the examples below make use of the 'inspect' module. This module can be very useful for debugging purpose and you can get with it much more that what described here. If you want to use it, don't forget to put the following line in the start of your script: import inspect The 'logging' module is also very useful and many times even better, since it's designed to be used for logging and debugging. For example: import logging logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s %(filename)s:%(lineno)-4d: %(message)s', datefmt='%m-%d %H:%M', ) logging.debug('A debug message') logging.info('Some information') logging.warning('A shot across the bow') # Should print the following (with current date/time of course) #10-19 19:57 INFO test.py:9 : Some information #10-19 19:57 WARNING test.py:10 : A shot across the bow Also see http://www.oreillynet.com/pub/a/python/2005/06/02/logging.html So here are the proposed replacements: (The ones listed below is the popular ones, if you need something else, see the included links and write your solution here)
Magic constantsPHP provides a large number of predefined constants to any script which it runs. Many of these constants, however, are created by various extensions, and will only be present when those extensions are available, either via dynamic loading or because they have been compiled in. There are seven magical constants that change depending on where they are used. For example, the value of __LINE__ depends on the line that it's used on in your script. These special constants are case-insensitive and are as follows:
See also get_class(), get_object_vars(), file_exists() and function_exists(). |
more
Recently updated
more
Most requested
|