简体   繁体   English

Python SQLITE出现意外缩进错误

[英]Unexpected Indent Error on Python SQLITE

I'm working on a Thinkful challenge. 我正在努力思考。 Here are the instructions: 以下是说明:

Write a script called "database.py" to print out the cities with the July being the warmest month. 编写一个名为“ database.py”的脚本以打印出城市,其中七月是最温暖的月份。 Your script must: 您的脚本必须:

Connect to the database Create the cities and weather tables (HINT: first pass the statement DROP TABLE IF EXISTS ; to remove the table before you execute the CREATE TABLE ... statement) Insert data into the two tables Join the data together Load into a pandas DataFrame 连接到数据库创建城市和天气表(提示:首先传递语句DROP TABLE IF EXISTS;在执行CREATE TABLE ...语句之前删除该表)将数据插入两个表将数据连接在一起将数据加载到一个表中熊猫DataFrame

Here is the error 这是错误

Aschs-MacBook-Air:dbs aschharwood$ python database.py
  File "database.py", line 20
    cols = [desc[0] for desc in cur.description]
    ^
IndentationError: unexpected indent

Here is the code: 这是代码:

import sqlite3 as lite

# Here you connect to the database. The `connect()` method returns a connection object.
con = lite.connect('get_started.db')

with con:

    cur = con.cursor()
    cur.execute("DROP TABLE IF EXISTS cities")
    cur.execute("DROP TABLE IF EXISTS weather")
    cur.execute("CREATE TABLE cities (name text, state text)")
    cur.execute("CREATE TABLE weather (city text, year integer, warm_month text, cold_month text)")
    cur.execute("INSERT INTO cities VALUES('Washington', 'DC')")
    cur.execute("INSERT INTO cities VALUES('Houston', 'TX')")
    cur.execute("INSERT INTO weather VALUES('Washington', 2013, 'July', 'January',)")
    cur.execute("INSERT INTO weather VALUES('Houston', 2013, 'July', 'January',)")
    cur.execute("SELECT * FROM cities LEFT OUTER JOIN weather ON name = city")

    rows = cur.fetchall() #grabbing all the rows
    cols = [desc[0] for desc in cur.description]
    df = pd.DataFrame(rows, columns=cols)


    print(df)

What am I doing wrong? 我究竟做错了什么?

Your help is much appreciated!!! 非常感谢您的帮助!!!

So it turns out that this was a copy paste issue in my text editor, Sublime Text. 因此,事实证明这是我的文本编辑器Sublime Text中的复制粘贴问题。 I copied some code from one file to another. 我将一些代码从一个文件复制到了另一个文件。 And while it did not look like there was an indent issue, the text editor seemed to be reading it as so. 尽管看起来没有缩进问题,但文本编辑器似乎正在阅读它。

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

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