请参考下面的执行 -
import sys
_list = [2,55,87]
print(f'1 - Memory used by Python List - {sys.getsizeof(_list)}')
narray = np.array([2,55,87])
size = narray.size * narray.itemsize
print(f'2 - Memory usage of np array using itemsize - {size}')
print(f'3 - Memory usage of np array using getsizeof - {sys.getsizeof(narray)}')
Run Code Online (Sandbox Code Playgroud)
这是我得到的结果
1 - Memory used by Python List - 80
2 - Memory usage of np array using itemsize - 12
3 - Memory usage of np array using getsizeof - 116
Run Code Online (Sandbox Code Playgroud)
一种计算方法表明 numpy …
我是编码新手。我正在使用 anaconda 环境开发 jupyter 笔记本。我有这个示例代码,我在其中使用 sys.exit() 命令。当它执行时,它会退出脚本并显示几条错误消息。这是我的示例代码。
import sys
name = 'joh'
if name == 'john':
print('Name matches')
else:
print('Incorrect name')
sys.exit(0)
... some more code
Run Code Online (Sandbox Code Playgroud)
执行后返回
Incorrect name
An exception has occurred, use %tb to see the full traceback.
SystemExit: 0
C:\Users\ankur.kulshrestha\AppData\Local\Continuum\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py:2889: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
Run Code Online (Sandbox Code Playgroud)
如何在不收到所有这些错误消息的情况下优雅地退出脚本(除了我实际放入代码中的第一行)。
我是 Ipython 的新手。目前我已经使用 Anaconda 安装了 Ipython 并编写了使用 jupyter Notebook UI 绘制图表的代码。我想在 argparse 模块的帮助下将一些参数传递给我的工作脚本。下面是代码..
import argparse
parser = argparse.ArgumentParser(description = 'Process display arguments')
parser.add_argument('-t', "--test_name", help="Mandatory test name directory path", type=str)
parser.add_argument('-s', "--symbolSet", nargs = '?', help="Optional symbolset", const = 'baz', default = 'deafultOne')
args = parser.parse_args()
if args.test_name is None:
print("test_name argument is mandatory.. Use option -h for help.. Exiting..")
sys.exit(1)
Run Code Online (Sandbox Code Playgroud)
现在,如何在通过 UI 执行脚本时传递这些参数,或者如何通过命令提示符运行脚本并仍然能够绘制图表?我正在 Windows 机器上工作。如果您需要更多信息,请告诉我。关于这一点。
我是perl的新手.我有这个示例代码.
#! /usr/bin/perl
# Calcu.pm
package Calc;
sub add {
( $one , $two ) = @_;
$total = $one + $two;
return $total;
}
1;
Run Code Online (Sandbox Code Playgroud)
&
#! /usr/bin/perl
# add.pl
use Calcu;
print Calcu::add(50, 60);
Run Code Online (Sandbox Code Playgroud)
脚本add.pl运行正常.但我想调用该add方法而不提及其模块名称.我用Google搜索并在我的Calcu.pm中添加了以下行
use Exporter;
@ISA = (Exporter);
@EXPORT = qw (add);
Run Code Online (Sandbox Code Playgroud)
print Calcu::add(50, 60);并print add(50, 60);在add.pl中替换,但它仍然给我以下错误.
Undefined subroutine &main::add called at add.pl
Run Code Online (Sandbox Code Playgroud)
有没有办法可以直接在我的ad.pl中调用add子例程?
我创建了一个磁盘清理脚本,在清理后发送状态电子邮件.现在,当我通过命令行运行它时,它执行完美,但通过cronjob它无法发送staus邮件休息,脚本工作正常.我在谷歌阅读了很多解决方案,但没有什么对我有用.我在我的Ubuntu机器上使用Bash.这是sendmail的一部分我的脚本.
export CONTENT="/root/cleanup/cleanup.htm"
export SUBJECT="Disk Space Clean Up Process : Completed @ $date_time"
(echo "Subject: $SUBJECT"
echo "`cat sendmail_list.txt`"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat $CONTENT
)|/usr/sbin/sendmail -t
Run Code Online (Sandbox Code Playgroud)
请帮我知道解决方案......谢谢