Python找不到“主”模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42681801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python can't find 'main' module
提问by sheetal_158
When I run the code using the command python filename.py
, I am getting the following error,
当我使用命令运行代码python filename.py
时,出现以下错误,
/Library/anaconda/bin/python: can't find '__main__' module in filename.py
/Library/anaconda/bin/python: can't find '__main__' module in filename.py
I am not sure what exactly is going wrong here. I need help correcting this. How can I correct this?
我不确定这里到底出了什么问题。我需要帮助纠正这一点。我该如何纠正?
SUFFIXES = {1000: ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
1024: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']}
def approximate_size(size, a_kilobyte_is_1024_bytes=True):
'''Convert a file size to human-readable form.
Keyword arguments:
size -- file size in bytes
a_kilobyte_is_1024_bytes -- if True (default), use multiples of 1024
if False, use multiples of 1000
Returns: string
'''
if size < 0:
raise ValueError('number must be non-negative')
multiple = 1024 if a_kilobyte_is_1024_bytes else 1000
for suffix in SUFFIXES[multiple]:
size /= multiple
if size < multiple:
return '{0:.1f} {1}'.format(size, suffix)
raise ValueError('number too large')
if __name__ == “__main__”:
print(“Hello World”)
print(approximate_size(1000000000000, False))
print(approximate_size(1000000000000))
回答by crookedleaf
It's because of the quote marks you are using. Change the “
s to "
s
这是因为您使用的引号。将“
s更改为"
s