【发布时间】:2017-06-13 13:13:04
【问题描述】:
我是在终端中运行 python 脚本的新手。我已经运行了脚本 ./filename.py 并确保它可以使用 chmod +x 文件名执行。我还将#!/usr/bin/env python 放在我的程序顶部。我没有收到任何错误,但我的终端中没有显示任何打印语句。附件是我的代码。有什么想法吗?
#!/usr/bin/env python
import ctypes
import os
def is_hidden(filepath):
name = os.path.basename(os.path.abspath(filepath))
return ('.' + name) or (has_hidden_attribute(filepath))
def has_hidden_attribute(filepath):
try:
attrs = ctypes.windll.kernel32.GetFileAttributesW(unicode(filepath))
assert attrs != -1
result = bool(attrs & 2)
except (AttributeError, AssertionError):
result = False
return result
def main():
print ('whatup')
print(is_hidden('~/.jupyter'))
print('hey')
然后从终端
$ ./makepass_jup.py
$
【问题讨论】:
-
您的背景是
Java还是C? Python 中的main函数没有什么特别之处。您必须实际调用它。