[Tutor] problem with simple sqlite script

2008-11-07 Thread aivars
Hello,
I am getting frustrated.

I have been successfully inserting, deleting, etc records with python
and sqlite no problem.

Suddenly the following very simple scrip does not work:

import sqlite3

sPath=r'e:\pythonexamples\aivars2.db'

con=sqlite3.connect(sPath)
cur=con.cursor()
cur.execute(insert into test (name) values (?),sPath)
con.commit()

here is an error message

Traceback (most recent call last):
  File C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py,
line 307, in RunScript
debugger.run(codeObject, __main__.__dict__, start_stepping=0)
  File C:\Python25\Lib\site-packages\pythonwin\pywin\debugger\__init__.py,
line 60, in run
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
  File C:\Python25\Lib\site-packages\pythonwin\pywin\debugger\debugger.py,
line 631, in run
exec cmd in globals, locals
  File E:\PythonExamples\test.py, line 7, in module
cur.execute(insert into test (name) values (?),sPath)
ProgrammingError: Incorrect number of bindings supplied. The current
statement uses 1, and there are 28 supplied.

What the hell is going on? I have used the syntax with (?) successfully before!

I tested and found out that above script allows me to insert only
single character into database. Then it works.

Using ActiveState python 2.5, WinXP

Thanks for any hint.

Aivars
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Intermediate/advanced concepts

2008-11-07 Thread Alan Gauld


[EMAIL PROTECTED] wrote

on more intermediate/advanced topics like linked lists, nodes, 
trees, etc. However, it's kind of like reading a math textbook


Thats because these are abstract theoretical concepts
at the root of programming but not used much in practice in
high level languages like Python. If you were using a language
like C or Fortran or Pascal they would be highly relevant
because the language would not provide much support for
collections of data. But Python offers such a wealth of data
collections that these advanced topics are largely redundant;
just use a list or a dictionary or a set...

any suggestions for learning about real world application of more 
advanced concepts?


There are general rules about when different types apply but
the edges are blurred in Python. For example a linked list is
pretty much a Python list. A double linked list too can often be
faked in Python by using negative indexing. Trees are a bit
more valid and do have uses in applications like heirarchical
data storage such as found in file browsers, family trees,
organisational charts etc. They are also very powerful tools
for constructing searches of large data sets.

Things like bags and sets are just heterogenous collections
which Pythons native types mimic well. (Many of these
concepts grew out of early languages which only allowed
a single type of data in a collection)

OTOH there are cases for most of these data types where
there are arguments for constructing a dedicated implementation
in Python is valid, but they are rare.

If you have specific questions about specific types let us
know and we can offer more speciofic advice.

Also, are there other concepts that I should focus on? Frankly, I'm 
a bit bored because I've hit this ceiling, and I'm not really sure 
where to go to next.


If you are interested in investigating the more advanced
aspects of programming I'd suggest digging into concepts like
closures, locking, semaphores, predicate and lambda calculus,
boolean algebra, relational data theory, functional programming,
aspect oriented programming, literate programming, provable
correctness (use of assertions for pre/post conditions and
invariance etc), meta data. These are all of more direct relevance
in higher level languages like Python.

HTH,

Alan G. 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] please help with sqlite replace function

2008-11-07 Thread Alan Gauld


aivars [EMAIL PROTECTED] wrote


Yes it seems you are right. The ActiveState python version I have
installed have sqlite 2.3.2 only. I find it strange.


Why? SQLite is a separate product. Python bundled the then
current version in its standard distribution, but time has moved on.
You have apparently installed a more recent version of SQLite.


I see that on a python website there is is a new version Python26


2.6 may or may not have the same version as you but regardless
you should be able to get the older version of Python to work
with the newer SQLite instal;l, provided the newer version has
a Python library available - which it usually has.


Mark Hammonds PythonWin to get other things for windows? Or maybe I
will reinstall ActiveState Python25 and install Python25 from the
official website


I don't thing the vanilla Python will make any difference. SQLite is
bundled with Python not with ActiveState.


Copying dll to c:\python25\DLLs directory did not help - it still
shows version sqlite version 2.3.2. which I also do not understand 
why


I think you might need to install more than the DLL. Check
the SQLite web site for a new Ptython interface and install
that version.

Alan G. 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with simple sqlite script

2008-11-07 Thread Alan Gauld


aivars [EMAIL PROTECTED] wrote


sPath=r'e:\pythonexamples\aivars2.db'

con=sqlite3.connect(sPath)
cur=con.cursor()
cur.execute(insert into test (name) values (?),sPath)
con.commit()



 File E:\PythonExamples\test.py, line 7, in module
   cur.execute(insert into test (name) values (?),sPath)
ProgrammingError: Incorrect number of bindings supplied. The current
statement uses 1, and there are 28 supplied.


It looks like name expects a char and you are giving it a string.
How did you define the name field of test?
Can you send us the create statement?

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] please help with sqlite replace function

2008-11-07 Thread aivars
Hello, Denis,

Please try what sqlite3.version shows on your machine?

Thanks

aivars


2008/11/7 spir [EMAIL PROTECTED]:
 aivars a écrit :

 Thanks, John,
 Yes it seems you are right. The ActiveState python version I have
 installed have sqlite 2.3.2 only. I find it strange.

 I also have ActiveState's python (mainly for its very good doc) and I get:
  import sqlite3
 sqlite3.sqlite_version
 '3.3.4'

 Denis


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] pattern expressions

2008-11-07 Thread spir

Hello,

I'm learning to use parsers: trying pyParsing, construct and simpleparse to 
have a better overview. I know a bit regular expressions and rather used to 
BNF-like formats such as used for specification of languages. But I have never 
really employed them personly, so the following may be trivial. Below is used a 
BNF dialect that I think is clear and non-ambiguous.


format_code := '+' | '-' | '*' | '#'
I need to specify that a single, identical, format_code code may be repeated. 
Not that a there may be several one on a sequence.

format  := (format_code)+
would catch '+-', which is wrong. I want only patterns such as '--', '+++',...

style_code  := '/' | '!' | '_'
Similar case, but different. I want patterns like:
styled_text := style plain_text style
where both style instances are identical. As the number of styles may grow (and 
even be impredictable: the style_code line will actually be written at runtime 
according to a config file) I don't want, and anyway can't, specify all 
possible kinds of styled_text. Even if possible, it would be ugly!


I would like to specify a side-condition for a pattern, meaning that it 
should only when a specific token lies aside. For instance:

A   := A_pattern {X}
X is not part of the pattern, thus should not be extracted. If X is just 
garbage, I can write an enlarged pattern, then let it down later:

A   := A_pattern
A_X := A X
If X itself is a token, I can write a super pattern, then extract both items 
from the combination, and let down As that come alone:

X   := X_pattern
A   := A_pattern
A_X := A X
But what if X is part of another production? For example:
B   := X B_end_pattern
A_X := A X
I tried it, but I can't get X in both productions. So that I catch either B or 
A_X -- according to mysterious priority rules I don't fully understand (it 
seems to be neither the longest string, nor the first written pattern, by 
pyParsing).


Now, precisely, what about priority? I mean ambiguous cases, when an actual 
production can match several patterns. Parsers have tricks, rules, or explicit 
features to cope with such cases, but, as I understand it, these apply during 
or after the parsing process, as additional treatment. Is there a way to 
specify priority in the grammar itself?


Denis

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with simple sqlite script

2008-11-07 Thread Kent Johnson
On Fri, Nov 7, 2008 at 3:49 AM, aivars [EMAIL PROTECTED] wrote:

 import sqlite3

 sPath=r'e:\pythonexamples\aivars2.db'

 con=sqlite3.connect(sPath)
 cur=con.cursor()
 cur.execute(insert into test (name) values (?),sPath)

The second argument to execute() is a *sequence* of parameter values.
A string is a sequence of characters, so by passing a plain string you
are saying that each character of the string is a parameter to the
SQL.

Try adding braces around the parameter to make  list:
cur.execute(insert into test (name) values (?), [sPath])

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Intermediate/advanced concepts

2008-11-07 Thread Kent Johnson
On Thu, Nov 6, 2008 at 11:14 PM,  [EMAIL PROTECTED] wrote:
 Hi everyone,

 I've been teaching myself python for a few months and I'm becoming
 frustrated because I've kind of hit a wall in terms of learning new
 information.

You might like to read the (printed) Python Cookbook. It has many good
examples of idiomatic Python in the context of solving a real problem.
Also I suggest you start working on a project that interests you and
learn what you need to know to complete it.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with simple sqlite script

2008-11-07 Thread aivars
Thanks, Alan,
here is a create statement:

CREATE TABLE test (name TEXT)

And also I would like to thank you for you web page. Classes and OOP
seems to start to make sense to me now slowly after I am reading your
material.


Aivars


2008/11/7 Alan Gauld [EMAIL PROTECTED]:

 aivars [EMAIL PROTECTED] wrote

 sPath=r'e:\pythonexamples\aivars2.db'

 con=sqlite3.connect(sPath)
 cur=con.cursor()
 cur.execute(insert into test (name) values (?),sPath)
 con.commit()

  File E:\PythonExamples\test.py, line 7, in module
   cur.execute(insert into test (name) values (?),sPath)
 ProgrammingError: Incorrect number of bindings supplied. The current
 statement uses 1, and there are 28 supplied.

 It looks like name expects a char and you are giving it a string.
 How did you define the name field of test?
 Can you send us the create statement?

 --
 Alan Gauld
 Author of the Learn to Program web site
 http://www.freenetpages.co.uk/hp/alan.gauld

 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Intermediate/advanced concepts

2008-11-07 Thread W W
On Fri, Nov 7, 2008 at 4:12 AM, Eric Abrahamsen [EMAIL PROTECTED]wrote:


 snip

 Also, are there other concepts that I should focus on? Frankly, I'm a bit
 bored because I've hit this ceiling, and I'm not really sure where to go to
 next.


If you want to learn all sorts of new and exciting things, I'd suggest
learning about cryptography, and writing attacks (on your own data) as a
method of learning more. It's fun, challenging, and there's a real world
application for it, if you happen to enjoy any type of security.

my 2¢
-Wayne
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with simple sqlite script

2008-11-07 Thread aivars
Kent, Yesss!!

That did the trick! It's worth to remeber.

Thank you very much!

Aivars



2008/11/7 Kent Johnson [EMAIL PROTECTED]:
 On Fri, Nov 7, 2008 at 3:49 AM, aivars [EMAIL PROTECTED] wrote:

 import sqlite3

 sPath=r'e:\pythonexamples\aivars2.db'

 con=sqlite3.connect(sPath)
 cur=con.cursor()
 cur.execute(insert into test (name) values (?),sPath)

 The second argument to execute() is a *sequence* of parameter values.
 A string is a sequence of characters, so by passing a plain string you
 are saying that each character of the string is a parameter to the
 SQL.

 Try adding braces around the parameter to make  list:
 cur.execute(insert into test (name) values (?), [sPath])

 Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Intermediate/advanced concepts

2008-11-07 Thread Eric Abrahamsen


On Nov 7, 2008, at 12:14 PM, [EMAIL PROTECTED] wrote:


Hi everyone,

I've been teaching myself python for a few months and I'm becoming  
frustrated because I've kind of hit a wall in terms of learning new  
information. In an effort to continue to learn I've found some  
material on more intermediate/advanced topics like linked lists,  
nodes, trees, etc. However, it's kind of like reading a math  
textbook - the tutorials do a decent job of explaining the material  
but it's all kind of theoretical, and I'm not sure how I'd apply  
these concepts in real world applications, or incorporate them into  
my code. Does anyone have any suggestions for learning about real  
world application of more advanced concepts?


Are you writing real-world applications and using them? My (admittedly  
limited) experience has taught me that the real complexities of  
programming don't lie in obscure data structures or rarely-used  
functions, but in the practical, real-world issues that arise from  
creating actual applications: OOP best practices, application  
architecture, programming paradigms, recurring patterns, even just  
plain-old programming gotchas (though there are fewer of these in  
Python than other languages, thankfully). In other words, stuff that  
isn't necessarily described in the manuals, but that becomes evident  
once you've made the same mistakes two or three times, and start  
thinking about modifying your approach to programming. I've never used  
a tree, and a heap only once, but I feel like I've dipped into some  
pretty mind-bending stuff in terms of how I've arranged programs. Take  
metaclasses, for instance: no description of metaclasses I've read  
ever made sense to me; it only started to come clear after I'd looked  
at a module I was writing, realized that there was something really  
fundamentally wrong with it, and then slowly realized that the answer  
was metaclasses. About eleven lines of metaclass programming, as it  
turned out, but those seven lines turned my brain inside out for a  
bit. Not boring in the least!


Yrs,
Eric


Also, are there other concepts that I should focus on? Frankly, I'm  
a bit bored because I've hit this ceiling, and I'm not really sure  
where to go to next.


Thanks,
Ben
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Intermediate/advanced concepts

2008-11-07 Thread Kent Johnson
On Fri, Nov 7, 2008 at 4:12 AM, Alan Gauld [EMAIL PROTECTED] wrote:
 For example a linked list is
 pretty much a Python list.

Other than the very different timing characteristics! Python lists are
O(1) for reading or writing a value at an index, O(n) for inserting
and deleting. Linked lists are O(n) for reading and writing and O(1)
for insertion and deletion (at a known location).

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to use function from specific module and then switch to other module

2008-11-07 Thread Ertl, John C CIV 63134
Classification: UNCLASSIFIED 
Caveat (s): FOUO

Kent,

Thanks for the lead.  I eventually did something like the Strategy Pattern you 
sent.  It was so much simpler when I just inherited the functions.  I think I 
need to redesign the code but for now it works and my boss will be happy.

Thanks again.

John Ertl
Meteorologist

FNMOC
7 Grace Hopper Ave.
Monterey, CA 93943
(831) 656-5704
[EMAIL PROTECTED]

Classification: UNCLASSIFIED 
Caveat (s): FOUO



From: Kent Johnson
Sent: Thu 11/6/2008 7:36 PM
To: Ertl, John C CIV 63134
Cc: tutor@python.org
Subject: Re: [Tutor] How to use function from specific module and then switch 
to other module


On Thu, Nov 6, 2008 at 5:54 PM, Ertl, John C CIV 63134
[EMAIL PROTECTED] wrote:
 Classification: UNCLASSIFIED
 Caveat (s): FOUO

 I have a program that collects weather data from weather models.  I
 originally had a module that contained a bunch of function that I used.  So
 I just added it to the init of the class I was using and inherited the
 functions.  That worked great but now I have two different models that I can
 get weather from.   Each Module A and B have the exact same function names
 in them but they both do slightly different things.

It might help to see a working example of what you did for one model.

 The idea is as I step through a list I want to use a different function
 (same name but from a different module) for each element in the list.  How
 do I have a generic way to do this.

 for example for point 1 I want to use the rain function from Module A and
 then for point 2 I want to use the rain function from Module B.   At first
 though I would just init the class from either A or B for each point but I
 need the function from A or B to be able to use function from my main
 program...that is why the inheritance thing worked great for just one
 module.

Don't try to make the model A and B into base classes of the forecast.
Just pass the forecast object to the model. So your rain() method will
look more like this:
 def rain(self, fc):
   fc.calTime() # this function is in the main forecast class
   fc.rain = do stuff for model A

where fc will be the forecast instance.

You might also be able to use simple functions rather than classes:
 def rain(fc):
   fc.calTime() # this function is in the main forecast class
   fc.rain = do stuff for model A

then just call moduleA.rain(self) or moduleB.rain(self).

You might want to read about the Strategy pattern, that is what you
are doing. Here is a Python example of a class-based Strategy.
http://mail.python.org/pipermail/python-list/2006-April/379188.html

This example passes the strategy to the constructor but you can set it
in your pointInfo() method if you like. I would just make one function
to handle each point though:
for each in x.pointList:
   x.handlePoint(each)

where
def handlePoint(self, point):
   pointStrategy = ...
   pointStrategy.rain(self, point)

Kent

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Torrent

2008-11-07 Thread Ahmet Yasin HAZER

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Intermediate/advanced concepts

2008-11-07 Thread Lie Ryan
On Thu, 06 Nov 2008 23:14:38 -0500, btkuhn wrote:

 Hi everyone,
 
 I've been teaching myself python for a few months and I'm becoming
 frustrated because I've kind of hit a wall in terms of learning new
 information. In an effort to continue to learn I've found some material
 on more intermediate/advanced topics like linked lists, nodes, trees,
 etc. However, it's kind of like reading a math textbook - the tutorials
 do a decent job of explaining the material but it's all kind of
 theoretical, and I'm not sure how I'd apply these concepts in real world
 applications, or incorporate them into my code. Does anyone have any
 suggestions for learning about real world application of more advanced
 concepts?
 
 Also, are there other concepts that I should focus on? Frankly, I'm a
 bit bored because I've hit this ceiling, and I'm not really sure where
 to go to next.
 

There is really no ceiling in learning programming. The problem is to 
find a problem. If you're bored, you can do the practically-for-bored-
programmers challenges like Python Challenge (http://
www.pythonchallenge.com/) or Project Euler (http://projecteuler.net/
index.php?section=view)

If you're up to the challenge and responsibility, you could join an open 
source program teams or start one yourself. Alternatively, you could also 
start learning some embedded python flavors, like the one used by 
OpenOffice.org or Inkscape, these provides different challenge to vanilla 
python as you've got to learn their libraries.

If you think you're bored of python, perhaps it is time to start learning 
another language. Having many programming language in your toolbox is 
certainly a life-saver, since some problems are easier to solve in 
certain languages than other. For example, many mathematical problems are 
(much) easier to express in functional language, like Haskell, compared 
to imperative language. Other languages might have features/paradigm that 
are foreign in python, like Eiffel's Programming by Contract.

You might also start seeing domain-specific languages, like SQL 
(database), XSLT (XML), (E)BNF (syntax parsing), etc.

Alternative languages you might consider: Haskell, Prolog, Eiffel, C-
family, Perl, Lisp-family, APL-family, some assembly, shell scripting 
(bash, bat, etc)

If you're EXTREMELY bored though, you might learn some of the more 
esoteric languages, e.g. Shakespeare, Piet, Whitespace, etc (be ready to 
abandon all sanity)

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pattern expressions

2008-11-07 Thread spir

Paul McGuire a écrit :
 Question 1:
 format_code:= '+' | '-' | '*' | '#'
 I need to specify that a single, identical, format_code code may be
 repeated.
 Not that a there may be several one on a sequence.
 format := (format_code)+
 would catch '+-', which is wrong. I want only patterns such as '--',
 '+++',...


 This interpretation of '+' in your BNF is a bit out of the norm.  Usually
 this notation 'format_code+' would accept 1 or more of any of your
 format_code symbols, so '+-+--++' would match.
That's what I intended to write above. (format_code)+ would catch '+-', which 
is wrong. I need a pattern that matches a repetition of the same token, this 
token beeing an item of a set. Of course, I could write a pattern for each 
token... but it is supposed to be programming, not cooking ;-)

What I'm looking for is a format that may not exist:
format  := (format_code)++
where '++' means 'repetition of an identical token'

 In pyparsing, you could match things like '' using the Word class and
 specifying a string containing the single character '-':  Word('-').  That
 is, parse a word made up of '-' characters.  There is no pyparsing construct
 that exactly matches your (format_code)+ repetition, but you could use Word
 and MatchFirst as in:

 format = MatchFirst(Word(c) for c in +-*#)

That's it! I had not realized that, as pyparsing is real puthon, one can also 
use python idioms /inside/ the grammar... good! thank you. So that it is also 
possible to have variables, no? Then, my question #2 should be solved, too.


 A corresponding regular expression might be:
 formatRE = '|'.join(re.escape(c)+'+' for c in +-*#)

 which you could then parse using the re module, or wrap in a pyparsing Regex
 object:

 format = Regex(formatRE)


 Question 2:
 style_code := '/' | '!' | '_'
 Similar case, but different. I want patterns like:
 styled_text:= style plain_text style
 where both style instances are identical. As the number of styles may grow
 (and even be impredictable: the style_code line will actually be written at
 runtime according to a config file) I don't want, and anyway can't, specify
 all possible kinds of styled_text. Even if possible, it would be ugly!

 pyparsing includes to methods to help you match the same text that was
 matched before - matchPreviousLiteral and matchPreviousExpr.  Here is how
 your example would look:

 plain_text = Word(alphanums +  )
 styled_text = style + plain_text + matchPreviousLiteral(style)

 (There is similar capability in regular expressions, too.)

Good, thank you again. Do you know if there is any way to express such things 
in ordinary E/BNF, or in any dialect coming from BNF? It's like a variable 
inside a pattern, and I personly have never seen that.
Pattern variables would also be very helpful as (said before) I need to write 
or at least reconfigurate the grammar at runtime.


 Question 3:
 I would like to specify a side-condition for a pattern, meaning that it
 should only match when a specific token lies aside. For instance:
 A  := A_pattern {X}
 X is not part of the pattern, thus should not be extracted. If X is just
 garbage, I can write an enlarged pattern, then let it down later:
 A  := A_pattern
 A_X:= A X

 I think you might be looking for some kind of lookahead.  In pyparsing, this
 is supported using the FollowedBy class.

 A_pattern = Word(alphas)
 X = Literal(.)
 A = A_pattern + FollowedBy(X).leaveWhitespace()

 print A.searchString(alskd sldjf sldfj. slfdj . slfjd slfkj.)

 prints

 [['sldfj'], ['slfkj']]

I guess there is the same for left-side conditions. I'm going to search myself. 
This guy who develops pyParsing thinks at everything. There are so many helper 
functions and processing methods -- how can you know all of that by heart, Paul ?


Denis


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pattern expressions

2008-11-07 Thread Kent Johnson
On Fri, Nov 7, 2008 at 4:22 PM, spir [EMAIL PROTECTED] wrote:
 This guy who develops pyParsing thinks at everything. There are so
 many helper functions and processing methods -- how can you know all of that
 by heart, Paul ?

Maybe because he *is* the guy who develops pyparsing? ;-)

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] please help with sqlite replace function

2008-11-07 Thread Alan Gauld


aivars [EMAIL PROTECTED] wrote


Please try what sqlite3.version shows on your machine?


I also have ActiveState's python (mainly for its very good doc) and 
I get:

 import sqlite3
sqlite3.sqlite_version

'3.3.4'


Me too with Python 2.5.1 from Activestate.

Alan G 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Intermediate/advanced concepts

2008-11-07 Thread Alan Gauld


Kent Johnson [EMAIL PROTECTED] wrote


For example a linked list is pretty much a Python list.


Other than the very different timing characteristics! 


True, but its pretty rare that timing issues are a reason 
for me to choose a data structure - especially if I need

to hand code it! :-)

Python lists are O(1) for reading or writing a value at an index, 
O(n) for inserting and deleting. Linked lists are O(n) for reading 
and writing and O(1) for insertion and deletion (at a known 
location).


I would say O(1) only if you already have a reference to 
that location (ie its known in that sense) but if you know that 
it's at position 23 but you only have a reference to the head 
you still need to navigate sequentially to the 23rd element
so its still an O(n). O(1) only applies when inserting at 
the next position to where you currently are. That's not too 
common a scenario in my experience.


But the geneal point is a good specific example (and I 
was struggling to think of one!) where you might choose a 
non standard list over the vanilla version. The array module 
is another case where performance is improved over the 
standard lists.


Alan G.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with simple sqlite script

2008-11-07 Thread ALAN GAULD


 CREATE TABLE test (name TEXT)


OK, That looks fine.

 con=sqlite3.connect(sPath)
 cur=con.cursor()
 cur.execute(insert into test (name) values (?),sPath)


Try putting the string variable in a tuple:

cur.execute(insert into test (name) values (?), (sPath,) )


That seems to work for me...

HTH,

Alan G.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] gnuplot from a python gui

2008-11-07 Thread dwbarne
Hello tutors,

I'm trying to generate a plot using gnuplot from within a python gui. In 
Windows, if after the plot is drawn I use a raw_input string demanding a 
'RETURN' be hit, the plot will persist on the screen until the 'RETURN' is 
pressed. In  *nix, one can use the 'persist' switch to easily and much more 
elegantly accomplish the same.

My question is, is there a better way IN WINDOWS to keep the plot on the screen 
rather than having to leave the gui and find the console window in which a 
'RETURN' must be pressed to continue? My gui will not 'quit' until I enter the 
'RETURN' in the console window. Kind of a chintzy way to end the gui, really.

There must be a better way than using raw_input???

Daniel B.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Intermediate/advanced concepts

2008-11-07 Thread Kent Johnson
On Fri, Nov 7, 2008 at 6:16 PM, Alan Gauld [EMAIL PROTECTED] wrote:

 True, but its pretty rare that timing issues are a reason for me to choose a
 data structure

I would guess you commonly choose a dict or set over a list when you
need fast tests for membership. Failure to choose dict when
appropriate is certainly a common cause of performance problems.

 But the geneal point is a good specific example (and I was struggling to
 think of one!) where you might choose a non standard list over the vanilla
 version. The array module is another case where performance is improved over
 the standard lists.

The standard lib also includes collections.deque (O(1) insertion and
deletion at both ends) and heapq (binary priority queue). Third party
implementations of b-tree, avltree and trie are available which have
better performance than list and dict for some usage.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] cgi scripts

2008-11-07 Thread Jim Morcombe
I want to print a list of the keys and their values passed to a cgi 
script by an HTML form.

I have tried this, but just seems to crash.

Any ideas?

Jim Morcombe


#!C:\python25\python.exe

import cgi, sys
# import cgitb; cgitb.enable()

#Send errors to browser
sys.stderr = sys.stdout

#Parse data from form
data = cgi.FieldStorage()

#Send response to browser
print Content-type: text/html\n
print titleCGI Form Response/title\n
print h2This is the data passed to the cgi script/h2P

print These are the keys\n
print br
print for k in data.keys():
   print key: , k,   value: ,  data[k]
  



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] cgi scripts

2008-11-07 Thread Steve Willoughby

Jim Morcombe wrote:
I want to print a list of the keys and their values passed to a cgi 
script by an HTML form.

I have tried this, but just seems to crash.


When you say crash, what do you mean, exactly?


Any ideas?



print Content-type: text/html\n
print titleCGI Form Response/title\n
print h2This is the data passed to the cgi script/h2P


It wouldn't hurt to output fully-formed HTML here.


print for k in data.keys():


I think you'll find the source of your problem right about here.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor