sqlite tuples
I am fairly new to Python and am trying to get to grips with pysqlite2. >From what I have read data is returned as a list of tuples when using SELECT via connection.cursor. But I have not, despite frantic googling, found how to INSERT a list of tuples into a sqlite table. If I convert the tuple to a string and concatenate it to the 'INSERT INTO table etc.' string then it works, but only if all the tuple values are strings and then only if all the table fields are of type TEXT. Is it possible to, and if so how can one, insert a list of tuples into a sqlite table? Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlite tuples
On 17:30 Tue 17 Jul , Carsten Haese wrote: > On Tue, 2007-07-17 at 21:49 +0100, John K Masters wrote: > > I am fairly new to Python and am trying to get to grips with pysqlite2. > > >From what I have read data is returned as a list of tuples when using > > SELECT via connection.cursor. But I have not, despite frantic googling, > > found how to INSERT a list of tuples into a sqlite table. If I convert > > the tuple to a string and concatenate it to the 'INSERT INTO table etc.' > > string then it works, but only if all the tuple values are strings and > > then only if all the table fields are of type TEXT. > > > > Is it possible to, and if so how can one, insert a list of tuples into a > > sqlite table? > > Assuming that each tuple is the same length and goes into the same table > and columns, something like this will do the trick: > > sql = "insert into tablename(column1,column2,column3) values(?,?,?)" > cursor.executemany(sql, list_of_tuples) > > If you don't know the number of columns at design time, you'll need to > fill the values(...) clause on the fly with the correct number of > question marks, and you'll have to build the list of column names > somehow, too, but the basic idea is the same. > > HTH, > Thanks, I'll try that tomorrow. Number of columns are known and static; I'm extracting the data from a report generated by an old DOS program. I had been converting it to CSV and plugging it into Open Office Calc but it is now getting beyond that and I need to do a bit more with the data. Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
GUI tutorial
Can someone point me in the direction of a good tutorial on programming python with a GUI? I'm just starting out with python and have written a few scripts successfully but would like to add a graphical front end to them to make it easier for my work colleagues, most of whom have never used a command line, to use. Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Re: GUI tutorial
On 15:03 Mon 14 May , Jarek Zgoda wrote: > John K Masters napisał(a): > > > Can someone point me in the direction of a good tutorial on programming > > python with a GUI? I'm just starting out with python and have written a > > few scripts successfully but would like to add a graphical front end to > > them to make it easier for my work colleagues, most of whom have never > > used a command line, to use. > > Each of GUI frameworks/libraries has its own tutorial and some even more > than one... The choice is directly related to what library you would use. Thanks to all for the advice. I shall start with Py-GTK and see how it goes. Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Re: ten small Python programs
On 11:43 Sat 26 May , Steve Howell wrote: > I've always thought that the best way to introduce new > programmers to Python is to show them small code > examples. > > When you go to the tutorial, though, you have to wade > through quite a bit of English before seeing any > Python examples. > > Below is my attempt at generating ten fairly simple, > representative Python programs that expose new users > to most basic concepts, as well as the overall syntax. > > It was an interesting exercise. I constrained myself > to ten lines or less, and it was pretty easy to > incorporate loops, conditionals, print, open(), lists, > tuples, dictionaries, and imported modules. > > It was harder to show classes, and my ShoppingCart > class is nothing more than an encapsulation of a list, > which has dubious value (although it's the start of > something more useful). > > Anyway, here goes: > Many thanks for that. This is exactly what is missing in most introductory books. Simple, relevant and concise examples. Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Re: I am giving up perl because of assholes on clpm -- switching to Python
On 16:33 Thu 26 Jul , brad wrote: > [EMAIL PROTECTED] wrote: > > Python is a better language, with php support, anyway, but I am fed up > > with attitudes of comp.lang.perl.misc. Assholes in this newsgroup ruin > > Perl experience for everyone. Instead of being helpful, snide remarks, > > back-biting, scare tactings, and so on proliferate and self > > reinforce. All honest people have left this sad newsgroup. Buy bye, > > assholes, I am not going to miss you!!! > > > > Martha > > Out of the pan and into the fire. :) Welcome to the world of Ph.D's in > Computer Science. You think the Perl guys have attitude, just wait and > see what you're in for over here. I think you'll find attitudes in any > programming language... just different types. May God have mercy on your > soul! You'll be making a similar announcement in a few weeks when you > switch to Ruby :) The cold, cruel theoretical, lofty Python will > mercilessly crush you :) > > I'm just joking, OK. As a complete amateur in the world of programming (barring 25 years programming machine tools in the aerospace industry) I would like to point out that the more arcane the ['language', 'operating system', 'application'] the more unfriendly the community. Python is a revelation to me as a language that grows with the ability of the programmer, which creates a multi-level community not too centered on one-upmanship to nurture new talent. Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Re: Wing IDE for Python v. 3.0 beta1 released
On 15:34 Tue 31 Jul , Wingware wrote: > Hi, > > I'm happy to announce the first beta release of Wing IDE 3.0. It is > available from http://wingware.com/wingide/beta > If their support for paid customers is anything like their support for prospective customers then I would leave well alone. I have been trying wing for a few days but have noticed that auto-completion does not work on all modules. I submitted this to wing and was told that probably my PYTHONPATH was wrong. I subsequently submitted a question about the licensing, i.e. whether I could use wing on a home setup using Debian Etch, where I develop my apps, and a work setup, using Debian Etch, with no net access. So far I have had no response Regards, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Wing IDE for Python v. 3.0 beta1 released
On 13:45 Wed 01 Aug , Joshua J. Kugler wrote: > On Wednesday 01 August 2007 13:28, John K Masters wrote: > > > On 15:34 Tue 31 Jul , Wingware wrote: > >> Hi, > >> > >> I'm happy to announce the first beta release of Wing IDE 3.0. It is > > I've had excellent support from them. I'm sorry to hear your experiences > have not been stellar. Questions submitted to the bug or comment list > usually get a response in one day or less. And there are frequently > respones by WingWare people to just about every question asked on the > WingWare mailing list. > > > I have been trying wing for a few days but have noticed that > > auto-completion does not work on all modules. I submitted this to wing > > and was told that probably my PYTHONPATH was wrong. > > It may also not work if the IDE isn't sure what kind of object you are > dealing with. You can "clarify" this as documented with an > assert(isinstance()) statement. But as I pointed out to the wingware people the autocompletion was recognising some methods but not others from the same module, > > > I subsequently submitted a question about the licensing, i.e. whether I > > could use wing on a home setup using Debian Etch, where I develop my > > apps, and a work setup, using Debian Etch, with no net access. > > From http://www.wingware.com/wingide/license: > > "Each Wing IDE user may run Wing on as many machines as needed for their own > work, for all the operating systems which they have licensed. In order to > reduce casual license sharing, which is a unfortunately a problem for small > businesses like Wingware, licenses must be activated after installation on > each machine." > > "We've worked hard to make this flexible and forgiving for valid customers. > For example, reinstalling an OS and/or altering hardware usually should not > break your activation. Also, activation can be done directly from Wing IDE > and off-line activation is available if your machine does not have TCP port > 80 (http) access to wingware.com. Each license is allowed three activations > by default and more can be obtained on request from identifiable > customers." > But this requires activation via a web connection. > > So far I have had no response > > I tend to let questions slide when they are answered in the documentation or > on the web site. Maybe the Wing developers/support personnel are the same > way. > > j > > -- > Joshua Kugler > Lead System Admin -- Senior Programmer > http://www.eeinternet.com > PGP Key: http://pgp.mit.edu/ ID 0xDB26D7CE > > -- > http://mail.python.org/mailman/listinfo/python-list -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Re: Wing IDE for Python v. 3.0 beta1 released
On 18:23 Wed 01 Aug , Steve Holden wrote: > Joshua J. Kugler wrote: > > On Wednesday 01 August 2007 13:53, Robert Dailey wrote: > >> He's secretly an employee of Wing IDE in disguise!!! > > > > Sorry to destroy your conspiracy theories, but no, I've never been employed > > by Wing IDE in any fashion, nor have I ever received any monetary > > compensation from them in any form. Just a satisfied user. That's all. > > > > j > > > Me too, and I have to say the response I have had to all my technical > support requests has been first-class. Maybe they are busy because > they're in beta? I know they aren't the largest company, but they can > stand comparison with most when it comes to support. > > I can't think of any other products I use where you can contact the > support team from right inside the software. And get answers without > paying per-incident support fees! > > regards > Steve > -- I am happy to hear that you have had a good experience with wingide and I wish I could say the same as I have found the product to be excellent as far as the concept goes but lacking in the implementation. To suggest that, because the autocompletion worked on one method of a module and not on another was because I had not configured the PYTHONPATH properly is at least insulting. Regards, John -- War is God's way of teaching Americans geography uggest that mbrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Re: Wing IDE for Python v. 3.0 beta1 released
On 08:00 Thu 02 Aug , [EMAIL PROTECTED] wrote: > On Aug 1, 6:42 pm, John K Masters <[EMAIL PROTECTED]> wrote: > > To suggest that, because the autocompletion worked on one method of a > > module and not on another was because I had not configured the > > PYTHONPATH properly is at least insulting. > > We certainly didn't intend to be insulting. This it the most common > cause of > auto-completion problems but you are right that it's a mis-diagnosis > on our > part if it was just one method. We respond to sometimes hundreds of > emails > a day ,so we do make mistakes. > > It may be solved by using Reanalyze File from the right-click context > menu > on the editor but there's no gaurantee. This is incredibly complex > code with > many layers of highly optimized tokenizing, analysis, inference, > caching, > and then display in the various tools in Wing so it often takes a bit > more time > to find where the bug is. > > By the way, Wing 3.0 beta1 fixes a number of bugs that would lead to > bad analysis, including missing methods as a result of failure to > track edits in a file properly. It also improves reading completion > info > out of extension modules and properly handles several forms of > import where it fell on its face previously. > > Hope that's useful... please let me know if not. > > - Stephan > > -- > http://mail.python.org/mailman/listinfo/python-list This is the point at which I eat cartloads of humble pie and crawl backwards out of the room muttering my apologies. Not only had I sent my email to Wingware, I had mis-spelled it. The good people at Wingware kindly emailed me following my post here. My only (feeble) excuse is that I have just lost the backspace key in my vim config and it's causing me loads of problems when I write emails. Once again I apologise profusely. I shall certainly purchase wingware and will not hesitate to recommend it. Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Re: Puzzled by "is"
On 15:53 Thu 09 Aug , Steve Holden wrote: > Dick Moores wrote: > > At 10:46 AM 8/9/2007, Bill Scherer wrote: > >> Dick Moores wrote: > [...] > >> There is only one empty tuple. > >> Does that clear it up for you? > > > > But isn't that the same as saying, "That's just the reality of > > Python; it is what it is."? I want to know why there is only one > > empty tuple, but more than one (1,). > > > Why? Because. > > Seriously, it's just an optimization by the implementers. There is no > need for more than one empty tuple, since tuples can never be modified > once created. > > But they decided not to create (1, ) in advance. They probably knew that > hardly anybody would want to create that tuple ;-) [Seriously: if you > started trying to predict which tuples would be used you would go > insane, but the empty tuple is the most likely candidate]. > > > Also, > > >>> [] is [] > > False > > > In that case it would definitely NOT make sense to have them the same > list. Python always ensures that the [] constructor creates a new list, > since that list may be bound to one or more variables and mutated. You > wouldn't want > >a = [] >b = [] >a.append("boo!") > > to change b so it was no longer an empty list. If you wanted a and b to > reference the same list you would change the second statement to > >b = a > > regards > Steve OK fiddling around with this and reading the docs I tried:- a = 'qq' #10 q's b = 'qq' #10 q's a is b true c = 'q' * 10 c 'qq' #10 q's d = 'q' * 10 d 'qq' #10 q's c is d false So from what I've read "==" tests for equivalence, "is" tests for identity but that does not explain the behaviour above. Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Re: negative polar axis
On 10:58 Mon 13 Aug , Erik Max Francis wrote: > Steve Holden wrote: > > > About the best interpretation I can think of is to add 180 degrees to > > the angle and reverse the sign of the magnitude, but this would be a > > hack. Where are those coordinates coming from? > > Well, sometimes in polar coordinates (r, theta), r is allowed to be > negative. The usual translation from polar to Cartesian coordinates > makes this meaningful, albeit weird, so in effect the resulting > positions are just reflections around the origin. > > Which I suppose is what the original poster was asking about, but it's > still not clear. > Many years ago when I started programming machine tools (on punched paper tape) if you wished to specify a cutter path around a radius as being more than 180 degrees you programmed it as a negative r value. There are 2 possible paths from x1y1 to x2y2 along a radius r and going in the same direction; that less than 180 deg and that more than 180 deg, unless the radius is exactly 180. But this was rarely used, the other method of specifying the end point as an incremental value in relation to the radius centre is less error prone when the arcs are close to 180. Sorry about the slight diversion but I'm getting nostalgic. Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
replacement for string.printable
>From what I have read the string module is obsolete and should not be used but I am working on a project that parses printable files created in a DOS program and creates a web page for each file. I am using the string.printable constant to determine which characters should be kept; the files contain many print control codes. There seems to be nothing like this in the string methods. isalnum() seems the nearest but gives false for '+' '!' etc. I realise I could define a global string to cover this but wondered if there was another, better, way Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Re: replacement for string.printable
On 19:03 Wed 15 Aug , Marc 'BlackJack' Rintsch wrote: > On Wed, 15 Aug 2007 19:56:01 +0100, John K Masters wrote: > > > From what I have read the string module is obsolete and [???] > > The `string` module isn't obsolete. It even contains a more or less > recent new addition: `Template`. Only the functions that are also > available as methods on `str` are deprecated. > > Ciao, > Marc 'BlackJack' Rintsch > -- > http://mail.python.org/mailman/listinfo/python-list help('string') DESCRIPTION Warning: most of the code you see here isn't normally used nowadays. Beginning with Python 1.6, many of these functions are implemented as methods on the standard string object. They used to be implemented by a built-in module called strop, but strop is now obsolete itself. Beginning with Python 1.6 We are now way past 1.6. Are you sure the string module is still being added to? Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Python equivalent of Perl's $/
I am currently working my way through Jeffrey Friedl's book Mastering Regular Expressions. Great book apart from the fact it uses Perl for the examples. One particular expression that interests me is '$/ = ".\n"' which, rather than splitting a file into lines, splits on a period-newline boundary. Combined with Perl's 'while (<>)' construct this seems a great way to process the files I am interested in. Without wishing to start a flame war, is there a way to do this in Python? Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python equivalent of Perl's $/
On 10:30 Mon 20 Aug , Nick Craig-Wood wrote: > Something like this maybe? > > import re > > input_data = """I am currently working my way through Jeffrey Friedl's book > Mastering > Regular Expressions. Great book apart from the fact it uses Perl for the > examples. > > One particular expression that interests me is '$/ = ".\\n"' which, > rather than splitting a file into lines, splits on a period-newline > boundary. Combined with Perl's 'while (<>)' construct this seems a great > way to process the files I am interested in. > > Without wishing to start a flame war, is there a way to do this in Python? > """ > > for para in re.split(r"\.\n", input_data): > print "para = %r" % para > Thanks, that looks promising. The Perl examples are really confusing sometimes and throw me off the track of the obvious Python way. That said, the Python documentation does not always make it clear, at least not to me, how to get the result one wants. Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python equivalent of Perl's $/
On 19:19 Mon 20 Aug , [EMAIL PROTECTED] wrote: > > import StringIO > > text = """\ > To mimic Perl's input record separator in > Python, you can use a generator. > And a substring test. > Perhaps something like the following > is what you wanted. > """ > > mockfile = StringIO.StringIO(text) > > def genrecords(mockfile, sep=".\n"): > buffer = "" > while True: > while sep in buffer: > idx = buffer.find(sep) + len(sep) > yield buffer[:idx] > buffer = buffer[idx:] > rl = mockfile.readline() > if rl == "": > break > else: > buffer = '%s%s' % (buffer, rl) > yield buffer > raise StopIteration > > for record in genrecords(mockfile): > print "READ:", record > > > -- > Hope this helps, > Steven Thanks, this also looks like a good way to go but ATM beyond my level of Python knowledge. I've not reached the generator chapter yet but I'll flag the message and return later. Regards, John -- War is God's way of teaching Americans geography Ambrose Bierce (1842 - 1914) -- http://mail.python.org/mailman/listinfo/python-list