简体   繁体   English

Python 2.7 打印语句“SyntaxError: invalid syntax”

[英]Python 2.7 print statement “SyntaxError: invalid syntax”

My python version is: Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32我的 Python 版本是:Python 2.7 (r27:82525, Jul 4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32

I'm getting a message called "Syntax Error| There's an error in your program: invalid syntax"我收到一条消息,名为“语法错误|您的程序中存在错误:语法无效”

The 7 in Python 2.7 is highlighted red. Python 2.7 中的 7 以红色突出显示。

My code is:我的代码是:

Python 2.7 (r27:82525, Jul  4 2010, 07:43:08) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
import numpy as np

def graphRawFX () :
date,bid,ask = np.loadtxt('GPBUSD1d.txt'), unpack=True,
                          delimiter=',',
                          converters={0:mdates.strpdate2num('%Y%m%d%H%M%S') }
fig = plt.figure(figsize=(10,7))
ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)

ax1.plot(date,bid)
ax1.plot(date,ask)

ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))

The first two lines are not Python code;前两行不是 Python 代码; they are just introductory text when you start the interpreter.当您启动解释器时,它们只是介绍性文本。 Remove them from the script, as it appears you copy-and-pasted too much from an example.从脚本中删除它们,因为您似乎从示例中复制粘贴了太多内容。 Once you've done that, you'll also need to fix your indentation, as at least one of the lines following the def graphRawFX() line needs to be indented.完成此操作后,您还需要修复缩进,因为def graphRawFX()行之后的至少一行需要缩进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM