在终端上运行python代码的正确语法是什么?

2024-09-29 22:22:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我的文件名是Step1.py,用于在google地图上打开一个页面。我在macbook air上运行El Capitan。它保存在我的主文件中,我给了它所需的权限(我想)。 下面是Step1.py:

#! 

import pprint
import webbrowser
def launchweb(location):
   web = 'https://www.google.com/maps/place/'
   location = input('Gimmi Yo Adress: ')
   rlocation = (location.replace(',', ''))
   rlocation = rlocation.split()
   for i in range(len(rlocation)):
      if i != len(rlocation) - 1:
          rlocation[i] = rlocation[i] + '+'
   for i in rlocation:
      web = web + i
   return web
webbrowser.open(launchweb(12))

我在终端中输入chmod +x Step1.py,然后尝试运行python ./Step1.py

它提示了一个地址,我输入了一个Gimmi Yo Adress: 1234 fake st, san fransisco, ca

然后它给了我这个:

 Traceback (most recent call last):
   File "./Step1.py", line 16, in <module>
     webbrowser.open(launchweb(12))
   File "./Step1.py", line 7, in launchweb
     location = input('Gimmi Yo Adress: ')
   File "<string>", line 1
     1234 fake st, san fransisco, ca
             ^
 SyntaxError: invalid syntax

正确的语法是什么


Tags: inpyimportwebgooglelinelocationfile

热门问题