Re: [Tutor] character counter

2009-06-27 Thread Richard Lovely
2009/6/27 julie : > Hello, > > I need help with the following problem: > > Write a loop that reads each line of a file and counts the number of lines > that are read until the total length of the lines is 1,000 characters. Use a > break statement to make sure that you don't continue reading the fil

Re: [Tutor] string pickling and sqlite blob'ing

2009-06-25 Thread Richard Lovely
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] Fwd: Problems with parameter queries

2009-06-24 Thread Richard Lovely
(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 >

Re: [Tutor] string pickling and sqlite blob'ing

2009-06-24 Thread Richard Lovely
2009/6/24 Dinesh B Vadhia : > 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 the MySQL language reference: """A BLOB is a binary large object that can hold a variable amount

Re: [Tutor] converting xls to csv

2009-05-31 Thread Richard Lovely
2009/5/31 Nick Burgess : > Got it. > > the row is not a string or buffer but the cell is.. > > for row in spamReader: >    for cell in row: >        if pattern.search(cell): >            print ', '.join(row) > > Alternatively, if you know that the string you want to search for only appears in a sin

Re: [Tutor] How to control the not existent keys in a dict

2009-05-10 Thread Richard Lovely
2009/5/10 Emilio Casbas : > > Hello, > > I have some problems testing keys not existent in a dictionary. > The code works testing existent keys with his corresponding value, but > If I enter a not existent key, an exception is raised. > How can I control the not existent key and assign him a defaul

Re: [Tutor] Suggestions for while loop

2009-05-10 Thread Richard Lovely
2009/5/11 David : > Hi, I am going through Wesley Chun's book and this is Exercise 8-11; > Write a program to ask the user to input a list of names, format "Last Name" > "comma" "First Name". Write a function that manages the input so that > when/if the user types in the names in the wrong format t

[Tutor] Fwd: range() fractional increment

2009-04-01 Thread Richard Lovely
forgot to reply-all... -- Forwarded message -- From: Richard Lovely Date: 1 Apr 2009 18:13 Subject: Re: [Tutor] range() fractional increment To: Alan Gauld There's always the itertools solution: import itertools def rangeInThirds(start,end): for whole, fr

Re: [Tutor] incrementing one minute

2009-03-30 Thread Richard Lovely
2009/3/30 pa yo : > I need to add one minute to a string that has a date and a time in > MMDDHHMM format. > e.g:  200903281346 should become 200903281347 > > the following script converts the string into time and adds one > minute; but somehow I also add an hour and I don't understand why. > >

Re: [Tutor] adding dictionary values

2009-03-20 Thread Richard Lovely
2009/3/20 Chris Fuller : > You should iterate over the keys of the dictionary: > for k in a.keys(): > because if you iterate over the full dictionary, your items are the values, > not the keys.  Otherwise your code looks correct, and I don't think its > terribly bad form.  You could do something in

Re: [Tutor] Passing perimeters in dictionary values?

2009-03-01 Thread Richard Lovely
2009/2/28 Alan Gauld : > > "Richard Lovely" wrote > >> > Sorry, I should have pointed out that you will need to redefine >> > all your functions to accept a parameter. >> >> Always makes me smile when (experienced) people redesign the wheel... &

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-27 Thread Richard Lovely
On 25/02/2009, Alan Gauld wrote: > > "nathan virgil" wrote > > > Whenever I try to use the talk method (which reports the mood, and doesn't > > take parameters), it says I gave it too many parameters. > > > > Sorry, I should have pointed out that you will need to redefine > all your functions to

Re: [Tutor] Active State Python with IDLE Python 2.5

2009-01-14 Thread Richard Lovely
The Activestate package IS vanilla python. It just comes packaged with a few addon modules for things such as ActiveX and with windows GUI libraries. If it works with Vanilla Python, there's virtually no reason it won't work with the activestate distribution, and vice versa, as long as you don't

Re: [Tutor] Suggestions for more efficient and optimized coding technique,

2009-01-08 Thread Richard Lovely
2009/1/8 Kent Johnson : > > This is a strange requirement. If you want to try all combinations of > lowercase letters, the simplest way to do that is with nested loops. > The loops will generate all combinations without repeating, so there > is no need to save the used combinations. > or itertool

Re: [Tutor] Fwd: Class Extend Help

2008-12-23 Thread Richard Lovely
OK, going on Kent's post: from urllib import urlopen class fetch(object): def __init__(self, *args): self.response = urlopen(*args) self.content = self.response.read() I forgot urlopen was a function. It made sense in my head for it to be a class, instead of _returning_ a c

Re: [Tutor] Class Extend Help

2008-12-20 Thread Richard Lovely
There are three ways as I see it: using __getattr__, using a new init, or using a property decorator. The last two are probably the most pythonic, but I'm not familiar with decorators, so here's how I'd do the second of the three: try: from google.appengine.api.urlfetch import fetch except:

Re: [Tutor] Working with lists

2008-12-13 Thread Richard Lovely
When you need indexes for a list you're iterating over, you want to look at the function enumerate(), which returns an iterator yielding (key, value) tuples. If you're working with multiple lists, itertools.imap and itertools.imap_longest are handy if you want to keep the lists in lockstep: >>> l

Re: [Tutor] noise function

2008-12-02 Thread Richard Lovely
There's probably something like what you want within the "random" module. at the interactive prompt, try: import random help(random) --- Richard "Roadie Rich" Lovely, part of the JNP|UK Famile www.theJNP.com 2008/12/2 Alan Gauld <[EMAIL PROTECTED]>: > > "Christopher Spears" <[EMAIL PROTECTED]

[Tutor] Help Optimise Code

2008-11-19 Thread Richard Lovely
I'm pretty new to code optimisation, so I thought I'd ask you all for advice. I'm making an iterative prime number generator. This is what I've got so far: Code: Select all import math, array def count2(start_at=0): 'Yield every third integer, beginning with start_at' # this has been tes

[Tutor] Problems with Calculator Program

2008-10-30 Thread Richard Lovely
Hi, I'm trying to teach myself Tkinter by making a desktop calculator. I've got the Tkinter bit working, but getting the output to work how I want it to is causing serious brainfreeze... The buttons 0 through 9 and '.' all append to a queue, which makeNumber(queue) returns as an actual python nu

Re: [Tutor] Need help w/ a for loop

2008-10-23 Thread Richard Lovely
Why not throw in itertools.cycle while you're at it? ;-) pi = sum(4. / (1+x) * itertools.cycle((1,-1)).next() for x in range(0, 4 * n, 2)) I'd also be so tempted just to call the file 'approximate' (read it with extension...) Let's also not forget about integer division... 2008/10/23 bob gailer

Re: [Tutor] finding numbers in range of of numbers

2008-10-21 Thread Richard Lovely
I felt I need to appolgise for my first post in this thread... I don't have internet access, and I've yet to find a public computer with Python, so I'm unable to test any code I write. I'm going have to discpline myself not to post to here unless its: a) a problem of my own, or b) an answer that

Re: [Tutor] finding numbers in range of of numbers

2008-10-21 Thread Richard Lovely
Guessing you mean [5,100] as the inclusive interval notation, so all but the last element of the example pass? if any(True for x, y in listoflists if 5 <= x and y <= 100): #do stuff does this do it for you? Or if you want to know if any elements of the lists within the larger list are within

Re: [Tutor] More Pythonesque or a more efficient method

2008-10-07 Thread Richard Lovely
In a slightly related matter, Is is possible to use all() with a list comprehension to check if a word contains all of the letters of another? -- Richard "Roadie Rich" Lovely, part of the JNP|UK Famile www.theJNP.com ___ Tutor maillist - Tutor@python.

Re: [Tutor] pysqlite and SQLite

2008-09-29 Thread Richard Lovely
If you're compiling from source you do: http://oss.itsystementwicklung.de/trac/pysqlite/browser/doc/install-source.txt If you've got an installer, it shouldn't let you install if you don't have the right things installed. Even if you can install pysqlite, you wouldn't be able to run any pysqlite

Re: [Tutor] How to replace instances

2008-09-26 Thread Richard Lovely
Hi, I'm not going to guess at why this doesn't work, but I've got a potential solution for you: class Z(object): def __init__(self,y): self.y = y def replaceZ (self,withWhat): self.__dict__ = withWhat.__dict__ Is there a reason you can't use a simple assignment (x=y) outsi

Re: [Tutor] recursive using the os.walk(path) from the os module

2008-09-18 Thread Richard Lovely
The way I'd do it is create a dict mapping extensions to folders (something like {'doc': 'word', 'pdf': 'acrobat'} ), then use os.renames(old, new), which works the same as moving when you give it a different path for new, and also magically handles creating new directories for you. The documentat

[Tutor] Creating a chat system Server

2008-09-16 Thread Richard Lovely
Does anyone have any links and or know of any good libraries for writing chat servers similar to IRC? I'm looking to add chat facilities to a game I'm working on. Thanks. -- Richard "Roadie Rich" Lovely, part of the JNP|UK Famile www.theJNP.com ___ Tut

Re: [Tutor] absolute beginner

2008-09-11 Thread Richard Lovely
I'd absolutely recommend "Python for Dummies" published by Wileys. I've not used that actual book, but I've found other books in the series extremely helpful. http://www.amazon.com/Python-Dummies-Computer-Tech/dp/0471778648/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1221146720&sr=8-1 On Thu, Sep 11, 20

[Tutor] Concatenation vs formatting

2008-09-01 Thread Richard Lovely
Just a couple of quick questions: What differences are there in efficency (i.e. time and memory) between string concatenation ("foo" + "bar") and printf style formatting ("%s%s" % ("foo","bar")). Is there any place where one is better than the other, and any places where either should be avoided?