Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79125 > unrolled thread
| Started by | ryguy7272 <ryanshuell@gmail.com> |
|---|---|
| First post | 2014-10-14 19:13 -0700 |
| Last post | 2014-10-21 06:51 -0700 |
| Articles | 6 on this page of 26 — 15 participants |
Back to article view | Back to comp.lang.python
Is there an easy way to control indents in Python ryguy7272 <ryanshuell@gmail.com> - 2014-10-14 19:13 -0700
Re: Is there an easy way to control indents in Python Juan Christian <juan0christian@gmail.com> - 2014-10-14 23:23 -0300
Re: Is there an easy way to control indents in Python alex23 <wuwei23@gmail.com> - 2014-10-15 17:27 +1000
Re: Is there an easy way to control indents in Python Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2014-10-15 16:32 +0200
Re: Is there an easy way to control indents in Python alex23 <wuwei23@gmail.com> - 2014-10-16 09:51 +1000
Re: Is there an easy way to control indents in Python Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-10-17 18:22 +1300
Re: Is there an easy way to control indents in Python Terry Reedy <tjreedy@udel.edu> - 2014-10-15 13:12 -0400
Re: Is there an easy way to control indents in Python Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-15 13:30 -0600
Re: Is there an easy way to control indents in Python Simon Kennedy <sffjunkie@gmail.com> - 2014-10-16 07:08 -0700
Re: Is there an easy way to control indents in Python Chris Angelico <rosuav@gmail.com> - 2014-10-17 02:02 +1100
Re: Is there an easy way to control indents in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-18 21:53 +1100
Re: Is there an easy way to control indents in Python Simon Kennedy <sffjunkie@gmail.com> - 2014-10-20 08:54 -0700
Re: Is there an easy way to control indents in Python Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-20 11:54 -0600
Re: Is there an easy way to control indents in Python Simon Kennedy <sffjunkie@gmail.com> - 2014-10-21 01:45 -0700
Re: Is there an easy way to control indents in Python Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-21 11:09 -0600
Re: Is there an easy way to control indents in Python Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-20 11:57 -0600
Re: Is there an easy way to control indents in Python Juan Christian <juan0christian@gmail.com> - 2014-10-20 17:04 -0200
Re: Is there an easy way to control indents in Python Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-20 13:40 -0600
Re: Is there an easy way to control indents in Python MRAB <python@mrabarnett.plus.com> - 2014-10-20 20:43 +0100
Re: Is there an easy way to control indents in Python Juan Christian <juan0christian@gmail.com> - 2014-10-20 20:30 -0200
Re: Is there an easy way to control indents in Python Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-20 21:13 -0400
Re: Is there an easy way to control indents in Python Chris Angelico <rosuav@gmail.com> - 2014-10-15 13:18 +1100
Re: Is there an easy way to control indents in Python Dan Stromberg <drsalists@gmail.com> - 2014-10-14 19:38 -0700
Re: Is there an easy way to control indents in Python Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-10-14 21:35 -0500
Re: Is there an easy way to control indents in Python Chris Angelico <rosuav@gmail.com> - 2014-10-15 13:47 +1100
Re: Is there an easy way to control indents in Python jumppanen.jussi@gmail.com - 2014-10-21 06:51 -0700
Page 2 of 2 — ← Prev page 1 [2]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2014-10-20 21:13 -0400 |
| Message-ID | <mailman.15020.1413853991.18130.python-list@python.org> |
| In reply to | #79317 |
On Mon, 20 Oct 2014 17:04:09 -0200, Juan Christian
<juan0christian@gmail.com> declaimed the following:
>Ok, new code using ?:
>
>import sqlite3
>
>db = sqlite3.connect('db.sqlite')
>
>
>def create_db():
Misnamed function... the "database" was created (if it didn't exist)
when you did the .connect() call. Here you are defining the schema of a
table.
> db.execute('''
> CREATE TABLE TOPICS(
> ID INT PRIMARY KEY NOT NULL,
> URL VARCHAR NOT NULL,
> AUTHOR VARCHAR NOT NULL,
> MESSAGE VARCHAR NOT NULL
> );
> ''')
>
Stylistic point -- I never use the connection.execute() form; as
documented:
execute(sql[, parameters])
This is a nonstandard shortcut that creates an intermediate cursor
object by calling the cursor method, then calls the cursor’s execute method
with the parameters given.
More portable to create an actual cursor
cur = db.cursor()
and then
cur.execute(...)
>
>def insert_db(_id, url, author, message):
> db.execute("INSERT INTO TOPICS (ID, URL, AUTHOR, MESSAGE) VALUES (?, ?,
>?, ?)", (_id, url, author, message))
> db.commit()
>
>
>def get_db(_id):
>cursor = db.execute("SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHERE ID =
>?", (_id))
Presuming the adapter is expecting a tuple of parameters, you haven't
provided one. Try with
..., (_id,) )
It is the comma, not the () that make a tuple.
> cursor = db.execute("SELECT ID, URL, AUTHOR, MESSAGE FROM TOPICS WHERE
>ID = ?", (_id))
>ValueError: parameters are of unsupported type
>
{see prior comment}
>-------------
>
>And the second time, again, I get
>
>Traceback (most recent call last):
> File ".\sql.py", line 28, in <module>
> create_db()
> File ".\sql.py", line 14, in create_db
> ''')
>sqlite3.OperationalError: table TOPICS already exists
Well, sure... If it failed on the "select" statement you had already
executed (and commited) the table create and the insert of one row.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-10-15 13:18 +1100 |
| Message-ID | <mailman.14870.1413340023.18130.python-list@python.org> |
| In reply to | #79125 |
On Wed, Oct 15, 2014 at 1:13 PM, ryguy7272 <ryanshuell@gmail.com> wrote: > I'm just learning Python. It seems like indents are EXTREMELY important. I guess, since there are no brackets, everything is controlled by indents. Well, I'm reading a couple books on Python now, and in almost all of the examples they don't have proper indents, so when I copy/paste the code (from the PDF to the IDE) the indents are totally screwed up. I'm thinking that there should be some control, or setting, for this. I hope. :) > That probably depends on the person who made the PDF. You may simply have to copy and paste one line at a time; if you're using an editor that understands Python syntax, it'll do some of your indenting for you, and you'll just have to manually mark the unindents. Alternatively, just paste it all in without indentation, then go through and select blocks of code and hit Tab; in many editors, that'll indent the selected code by one level. But ultimately, the fault is almost certainly with the PDF. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Dan Stromberg <drsalists@gmail.com> |
|---|---|
| Date | 2014-10-14 19:38 -0700 |
| Message-ID | <mailman.14871.1413340702.18130.python-list@python.org> |
| In reply to | #79125 |
On Tue, Oct 14, 2014 at 7:13 PM, ryguy7272 <ryanshuell@gmail.com> wrote: > I'm just learning Python. It seems like indents are EXTREMELY important. I guess, since there are no brackets, everything is controlled by indents. Well, I'm reading a couple books on Python now, and in almost all of the examples they don't have proper indents, so when I copy/paste the code (from the PDF to the IDE) the indents are totally screwed up. I'm thinking that there should be some control, or setting, for this. I hope. :) Perhaps if you share a screenshot of your PDF and the name of your PDF viewer, we can help you more. Here's a URL about Python and Whitespace: http://stromberg.dnsalias.org/~strombrg/significant-whitespace.html
[toc] | [prev] | [next] | [standalone]
| From | Zachary Ware <zachary.ware+pylist@gmail.com> |
|---|---|
| Date | 2014-10-14 21:35 -0500 |
| Message-ID | <mailman.14872.1413340909.18130.python-list@python.org> |
| In reply to | #79125 |
On Tue, Oct 14, 2014 at 9:18 PM, Chris Angelico <rosuav@gmail.com> wrote: > On Wed, Oct 15, 2014 at 1:13 PM, ryguy7272 <ryanshuell@gmail.com> wrote: >> I'm just learning Python. It seems like indents are EXTREMELY important. I guess, since there are no brackets, everything is controlled by indents. Well, I'm reading a couple books on Python now, and in almost all of the examples they don't have proper indents, so when I copy/paste the code (from the PDF to the IDE) the indents are totally screwed up. I'm thinking that there should be some control, or setting, for this. I hope. :) >> > > That probably depends on the person who made the PDF. You may simply > have to copy and paste one line at a time; if you're using an editor > that understands Python syntax, it'll do some of your indenting for > you, and you'll just have to manually mark the unindents. > Alternatively, just paste it all in without indentation, then go > through and select blocks of code and hit Tab; in many editors, > that'll indent the selected code by one level. But ultimately, the > fault is almost certainly with the PDF. Agreed, although I'd say the PDF viewer could also be at fault. Earlier today I tried to copy just a paragraph of mostly plain text from the Firefox built-in PDF viewer, but when pasting it elsewhere, it was pasted one character per line. Opening it in the Windows 8.1 default PDF viewer (of all things...), copying and pasting worked like a charm. -- Zach
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-10-15 13:47 +1100 |
| Message-ID | <mailman.14873.1413341243.18130.python-list@python.org> |
| In reply to | #79125 |
On Wed, Oct 15, 2014 at 1:35 PM, Zachary Ware <zachary.ware+pylist@gmail.com> wrote: >> But ultimately, the >> fault is almost certainly with the PDF. > > Agreed, although I'd say the PDF viewer could also be at fault. Good point, there are some really terrible PDF viewers around. Either way, the workaround of grabbing one line at a time will be effective - albeit tedious for anything more than a dozen lines or so. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | jumppanen.jussi@gmail.com |
|---|---|
| Date | 2014-10-21 06:51 -0700 |
| Message-ID | <18da7dec-432d-46be-9a77-25b0f7ad7584@googlegroups.com> |
| In reply to | #79125 |
On Wednesday, October 15, 2014 12:13:51 PM UTC+10, ryguy7272 wrote: > I'm just learning Python. One of the best ways to learn any language is to type in the example code by hand. As you type in the code you will make mistakes, you will learn from your mistakes and that will help you learn the language and in the process make you a better programmer. So if you really want to learn the language just type in the code by hand and the problem goes away.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.python
csiph-web