直接访问py文件方式

以下黑体字为正确的代码,未加粗的为错误的尝试。(注意空格"."之类的不同)

appledeMacBook:~ JEZAU$ /Users/apple/Desktop/python/test.py

-bash: /Users/apple/Desktop/python/test.py: Permission denied (无权限

appledeMacBook:~ JEZAU$ chmod a+x ./test.py

chmod: ./test.py: No such file or directory

要先cd进入其上一级目录才可以用 ./进入 

cd .. 进入上一级文件夹

appledeMacBook:~ JEZAU$ chmod a+x ./test

chmod: ./test: No such file or directory

appledeMacBook:~ JEZAU$ chmod a+x ./Users/apple/Desktop/python/test.py

chmod: ./Users/apple/Desktop/python/test.py: No such file or directory

appledeMacBook:~ JEZAU$ chmod a+x/Users/apple/Desktop/python/test.py (可执行程序

可以 chmod a+x ./文件夹路径 这样整个文件夹里的py文件就可以直接./hh.py打开了

(苹果里用777不行,得a+x)

appledeMacBook:~ JEZAU$ /Users/apple/Desktop/python/test.py

/Users/apple/Desktop/python/test.py: line 1: syntax error near unexpected token `"hello"'

/Users/apple/Desktop/python/test.py: line 1: `print("hello")'

appledeMacBook:~ JEZAU$ /Users/apple/Desktop/python/test.py

/Users/apple/Desktop/python/test.py: line 1: 100+200: command not found

在py文件前加入#!/usr/local/Cellar/python3/3.6.1/bin/python3

appledeMacBook:~ JEZAU$ /Users/apple/Desktop/python/test.py

其中的内容需要print才可以显示

appledeMacBook:~ JEZAU$ /Users/apple/Desktop/python/test.py

hello,world

你可能感兴趣的:(直接访问py文件方式)