[Tutor] short circuiting
Hi I've read that the builtin all() function stops evaluating as soon as it hits a false item, meaning that items after the first false one are not evaluated. I was wondering if someone could give an example of where all()'s short circuiting is of consequence, akin to: False and produces_side_effect() Many thanks ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] why PyObject_VAR_HEAD?
Hi, I'm studying the CPython source code. I don't quite understand why they're using PyObject_VAR_HEAD to define struct like PyListObject. To define such kind of struct, could I use _PyObject_HEAD_EXTRA as a header and add "items" pointer and "allocated" count explicity? Is there any difference? Thanks. Eric ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Program Slicing / Trace
On Thu, Jun 18, 2009 at 10:37 AM, Jojo Mwebaze wrote: > Hi Tutor > > The problem i have is to see which statements modify my data at execution > time without referring to the code. Referring to the code is difficult esp > because of branching. You can never tell before hand which branch execution > will follow. Stepping through the code in a debugger can be very helpful, either pdb or winpdb. You also might look at CodeInvestigator: http://codeinvestigator.googlepages.com/main Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] re module / separator
Thanks Kent! Once more you go straight to the point! Kent Johnson writes: > On Wed, Jun 24, 2009 at 2:24 PM, Tiago Saboga wrote: >> In [33]: re.search("(a[^.]*?b\.\s?){2}", text).group(0) >> Out[33]: 'a45453b. a325643b. ' > > group(0) is the entire match so this returns what you expect. But what > is group(1)? > > In [6]: re.search("(a[^.]*?b\.\s?){2}", text).group(1) > Out[6]: 'a325643b. ' > > Repeated groups are tricky; the returned value contains only the first > match for the group, not the repeats. The problem was exactly that. I had seen that findall got the first group of the match, but not that this would not span repeats. But it makes sense, as the repeat count is after the parens. > If you change the inner parentheses to be non-grouping then you get > pretty much what you want: > > In [8]: re.findall("((?:a[^.]*?b\.\s?)+)", text) > Out[8]: ['a2345b. ', 'a45453b. a325643b. a435643b. '] And the trick of the non-grouping parens is great too. Thanks again! Tiago. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string pickling and sqlite blob'ing
2009/6/25 Lie Ryan : > > Although pickle output only ascii string, it is not meant to be human > readable at all. Basically there is no difference how it is stored as > long as what goes in is equal with what goes out. I can't think of a > need to sort or compare raw pickle data. > > ___ > Tutor maillist - tu...@python.org > http://mail.python.org/mailman/listinfo/tutor > But you never know, do you. I mean, it wouldn't be the first time SQL has been abused for something much easier to do in code... see http://thedailywtf.com/Articles/The-Int-Divide.aspx for one, and I'm sure there's many more out there. A couple of rough ideas for usage are already forming, but not to a sharable degree. -- Richard "Roadie Rich" Lovely, part of the JNP|UK Famile www.theJNP.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string pickling and sqlite blob'ing
Alan On a machine with 6gb of ram, storing very long strings in sqlite caused a "sqlite3.OperationalError: Could not decode to UTF-8 column 'j' with text" which has been resolved. This fix then caused a memory error when reading some of the strings back from the db. Hence, I'm trying to work out what the problem is and looking for alternative solutions. It is strange that I can insert a long string into sqlite but a memory error is caused when selecting it. Splitting the strings into smaller chunks is the obvious solution but I need to sort out the above first since the post-processing after the select is on the entire string. Dinesh Message: 3 Date: Thu, 25 Jun 2009 00:44:22 +0100 From: "Alan Gauld" To: tutor@python.org Subject: Re: [Tutor] string pickling and sqlite blob'ing Message-ID: Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original "Dinesh B Vadhia" wrote > I want to pickle (very long) strings and save them in a sqlite db. Why? Why not just store the string in the database? If that turns out to be a problem then think about other options - like splitting it into chunks say? But until you know you have a problem don't try to solve it! > - Is this a good approach for storing very long strings? Probably not. > - Are the pickle'd strings stored in the sqlite db as a STRING or BLOB? They could be stored either way, thats up to how you define your tables and write your SQL. In general I expect databases to handle very large quantities of data either as blobs or as references to a file. Is this a valid approach? Write the long string (assuming its many MB in size) into a text file and store that with a unique name. Then store the filename in the database. But first check that you can't store it in the database directly or in chunks. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] syntax error
loaded python 3 and 3.1 several times on vista. tried first command: print "hello world' but keep getting syntax error. what am I doing wrong? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] syntax error
Christopher Altieri wrote: loaded python 3 and 3.1 several times on vista. tried first command: print "hello world' but keep getting syntax error. what am I doing wrong? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Python 3.0+ print has been changed to a function so you need to do print("Hello World!") -- Kind Regards, Christian Witts ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] short circuiting
On Wed, Jun 24, 2009 at 11:32 PM, Dave C wrote: > Hi > I've read that the builtin all() function stops evaluating as soon as > it hits a false item, meaning that items after the first false one are > not evaluated. > > I was wondering if someone could give an example of where all()'s > short circuiting is of consequence It can have a performance impact if the sequence under test is long or the comparison is expensive. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] string pickling and sqlite blob'ing
Dinesh In theory you can store in either type(i have done it), however you should store in the binary column, blob Vince On Wed, Jun 24, 2009 at 2:42 PM, Dinesh B Vadhia wrote: > Hi Vince > > That's terrific! Once a string is compressed with gzip.zlib does it make a > difference whether it is stored it in a TEXT or BLOB column? > > Dinesh > > > > *From:* vince spicer > *Sent:* Wednesday, June 24, 2009 10:49 AM > *To:* Dinesh B Vadhia > *Cc:* tutor@python.org > *Subject:* Re: [Tutor] string pickling and sqlite blob'ing > > Pickle is more for storing complex objects (arrays, dict, etc). pickling a > string makes it bigger. > > I have stored large text chunks in text and/or blob columns compressed with > gzip.zlib.compress and extracted with gzip.zlib.decompress > > Comparison: > > import cPickle as Pickle > import gzip > > x = "asdfasdfasdfasdfasdfasdfasdfasdfasdf" > > print len(x) > >> 36 > > print len(Pickle.dumps(x)) > >> 44 > > print len(gzip.zlib.compress(x)) > >> 14 > > > Vince > > On Wed, Jun 24, 2009 at 11:17 AM, Dinesh B Vadhia < > dineshbvad...@hotmail.com> wrote: > I want to pickle (very long) strings and save them in a sqlite db. The > plan is to use pickle dumps() to turn a string into a pickle object and > store it in sqlite. After reading the string back from the sqlite db, use > pickle loads() to turn back into original string. > > - Is this a good approach for storing very long strings? > > - Are the pickle'd strings stored in the sqlite db as a STRING or BLOB? > > Cheers. > > Dinesh > > > >> >> ___ >> 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] Fwd: Problems with parameter queries
On Wed, Jun 24, 2009 at 6:16 PM, Richard Lovely wrote: > (oops... forgot to reply-all) > > > -- Forwarded message -- > From: Richard Lovely > Date: 2009/6/25 > Subject: Re: [Tutor] Problems with parameter queries > To: Eduardo Vieira > > > 2009/6/24 Eduardo Vieira : >> Hello, I am accessing a Pervasive SQL data source using odbc and I'm >> having this trouble: >> >> import dbi >> import odbc >> # the first execute works >> pnumber = '09F153' >> wh = '00' >> qty = 3 >> myconn = odbc.odbc('DSN=MKPT01') >> mycursor = myconn.cursor() >> mycursor.execute(""" >> SELECT "INVENTORY"."CODE", "INVENTORY"."INV_DESCRIPTION" FROM "INVENTORY" >> WHERE "INVENTORY"."CODE" = ? AND WHSE = ? >> >> """, [pnumber, wh]) >> results = mycursor.fetchall() >> >> print results >> >> # this one below doesn't >> >> mycursor.execute("""UPDATE INVENTORY SET ONHAND = ? >> WHERE CODE = ? AND WHSE = '00' >> >> """, [pnumber, qty]) >> #mycursor.commit() >> mycursor.close() >> >> If I don't use parameter in the update code, it updates fine. Am I >> missing something? Is this a problem specific to the Pervasive SQL? >> For example, this works: >> mycursor.execute("""UPDATE INVENTORY SET ONHAND='0' >> WHERE CODE = '09F153' AND WHSE = '00' >> >> """) >> >> Thanks >> >> Eduardo >> ___ >> Tutor maillist - tu...@python.org >> http://mail.python.org/mailman/listinfo/tutor >> > > Isn't the arguement list to the non-working query back-to-front? > > -- > Richard "Roadie Rich" Lovely, part of the JNP|UK Famile > www.theJNP.com > > > Oops! My bad, I guess that was the problem. I'm going to test it soon. Thanks for spotting that! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] short circuiting
Kent Johnson wrote: On Wed, Jun 24, 2009 at 11:32 PM, Dave C wrote: Hi I've read that the builtin all() function stops evaluating as soon as it hits a false item, meaning that items after the first false one are not evaluated. I was wondering if someone could give an example of where all()'s short circuiting is of consequence It can have a performance impact if the sequence under test is long or the comparison is expensive. Also an item could be a call to a callable object (function, method, ...?). That can have side effects. -- Bob Gailer Chapel Hill NC 919-636-4239 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor