相关疑难解决方法(0)

python print end =''

我有这个python脚本,我需要运行 gdal_retile.py

但我在这一行得到一个例外:

if Verbose:
   print("Building internam Index for %d tile(s) ..." % len(inputTiles), end=' ')
Run Code Online (Sandbox Code Playgroud)

end=''是无效的语法.我很好奇为什么,以及作者可能打算做什么.

如果你还没有猜到,我是python的新手.


我认为问题的根本原因是这些导入失败,因此必须包含此导入 from __future__ import print_function

try: 
   from osgeo import gdal
   from osgeo import ogr
   from osgeo import osr
   from osgeo.gdalconst import *
except:
   import gdal
   import ogr
   import osr
   from gdalconst import *
Run Code Online (Sandbox Code Playgroud)

python

106
推荐指数
4
解决办法
40万
查看次数

Python print语句"语法错误:语法无效"

为什么Python print在第9行的简单语句中给出了语法错误?

import hashlib, sys
m = hashlib.md5()
hash = ""
hash_file = raw_input("What is the file name in which the hash resides?  ")
wordlist = raw_input("What is your wordlist?  (Enter the file name)  ")
try:
    hashdocument = open(hash_file,"r")
except IOError:
    print "Invalid file."    # Syntax error: invalid syntax
    raw_input()
    sys.exit()
else:
    hash = hashdocument.readline()
    hash = hash.replace("\n","")
Run Code Online (Sandbox Code Playgroud)

Python的版本是:

Python 3.2.2 (default, Sep  4 2011, 09:07:29) [MSC v.1500 64 bit (AMD64)] on win
32
Run Code Online (Sandbox Code Playgroud)

python syntax syntax-error python-3.x

50
推荐指数
2
解决办法
19万
查看次数

标签 统计

python ×2

python-3.x ×1

syntax ×1

syntax-error ×1