How do I convert a number to a string in Python?
Answer:
To convert a number to a string in Python, try the str() function.
foo = str( 999 );
print foo + ' is a string';
Result is :
999 is a string
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
How do I convert a number to a string in Python?
Answer:
To convert a number to a string in Python, try the str() function.
foo = str( 999 );
print foo + ' is a string';
Result is :
999 is a string
How do I find the current module name in Python?
Answer:
The easiest way is to look at the look at the predefined global variable __main__. If it has the value "__main__", it means the program is run as a script (not as imported module).
E.g.
def main():
print 'Running test...'
if __name__ == '__main__':
main()
What is the PHP's short_open_tag
Answer:
PHP's short_open_tag is a way to use PHP in a PHP script without the normal PHP tag, e.g.
Instead of
# <?php echo "hello world"; ?>
You can use a simplified version.
# <? echo "hello world"; ?>
Although it is not recommended, if you want to set it, you can enable it by editing the php.ini
vi /etc/php.ini
Locate and set
short_open_tag = On
Also, remember to restart web server such as Apache if needed.
Validate the syntax of PHP files in a directory
Answer:
To validate the syntax of PHP files in a directory, to check if any syntax error so we can fix them before they really happen at runtime.
You would need to have the GNU parallel installed in order to use the command below.
# find -type f -name '*.php' | parallel php -l
How to find a Perl Module's Path
Answer:
For example, we want to know where the module JSON and related modules exist in the local file system, we can try:
# perl -MJSON -e'print $_ . " => " . $INC{$_} . "\n" for keys %INC'
attributes.pm => /usr/share/perl/5.10/attributes.pm
XSLoader.pm => /usr/local/lib/perl/5.10.0/XSLoader.pm
warnings/register.pm => /usr/share/perl/5.10/warnings/register.pm
Carp.pm => /usr/share/perl/5.10/Carp.pm
Exporter/Heavy.pm => /usr/share/perl/5.10/Exporter/Heavy.pm
common/sense.pm => /usr/local/share/perl/5.10.0/common/sense.pm
vars.pm => /usr/share/perl/5.10/vars.pm
Exporter.pm => /usr/share/perl/5.10/Exporter.pm
strict.pm => /usr/share/perl/5.10/strict.pm
constant.pm => /usr/local/share/perl/5.10.0/constant.pm
warnings.pm => /usr/share/perl/5.10/warnings.pm
JSON/XS.pm => /usr/local/lib/perl/5.10.0/JSON/XS.pm
overload.pm => /usr/share/perl/5.10/overload.pm
base.pm => /usr/share/perl/5.10/base.pm
JSON.pm => /usr/local/share/perl/5.10.0/JSON.pm