2012-04-17 110 views
1

我使用python 2.7.2运行Ubuntu。python宽度语法错误

脚本

python \ 
/home/blainer/Desktop/convert/converter.py \ 
/home/blainer/Desktop/convert/urban.shp \ 
/home/blainer/Desktop/convert/result.js \ 
--width 900 \ 
--country_name_index 4 \ 
--where "ISO = 'USA'" \ 
--codes_file /home/blainer/Desktop/convert/codes-en.tsv \ 
--insets '[{"codes": ["US-AK"], "width": 200, "left": 10, "top": 370}, {"codes": ["US-HI"], "width": 100, "left": 220, "top": 400}]' \ 
--minimal_area 4000000 \ 
--buffer_distance -3000 \ 
--simplify_tolerance 1000 \ 
--longtitude0 10w \ 
--name us 

错误

[email protected]:~/Desktop/convert$ python script.py 
File "script.py", line 5 
--width 900 \ 
     ^
SyntaxError: invalid syntax 
+0

您没有任何尾随空格后您的任何\吧?如果将所有内容放在一行中并包含width参数,会发生什么情况,您是否也会收到此错误? – Levon 2012-04-17 20:19:19

+0

@Levon这不是一个Python脚本,他试图用Python来运行它。 – agf 2012-04-17 20:19:57

+0

Ooops .. right you .. – Levon 2012-04-17 20:20:45

回答

6

这不是一个Python脚本,它是运行的Python的shell脚本。

  1. 将它命名为script.sh而不是.py
  2. 添加“认领”行到顶端:#!/bin/bash
  3. 使其可执行:chmod +x ./script.sh
  4. 运行:[email protected]:~/Desktop/convert$ ./script.sh
+0

哇,一个白痴。谢谢!将标记为完整 – Blainer 2012-04-17 20:20:34

+1

我必须开始输入它作为“sh-bang”,否则每次我想到William Hung在唱“She Bangs” – jdi 2012-04-17 20:20:41