[Tutor] SQLite database creation bafflement

2007-08-20 Thread Che M
Hi, I am trying to simply create an SQLite database with Python. I find that when I try to create a new database file, *sometimes* it lets me do it, and sometimes it doesn't, and the only thing I am changing is the name of the database. I am baffled as to why some names appear to work and

[Tutor] iterate list items as lvalue

2007-08-20 Thread János Juhász
Dear Tutors! I know a python list is a mutable object. array = [1,2,3,4,5] So I can modify any item in it. for index in range(len(array)): array[index] *= 2 ... array [2, 4, 6, 8, 10] So I typed this: for item in array: item *= 2 ... array [1, 2, 3, 4, 5] It confused me a little, so

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Alan Gauld
János Juhász [EMAIL PROTECTED] wrote So I can modify any item in it. for index in range(len(array)): array[index] *= 2 ... array [2, 4, 6, 8, 10] So I typed this: for item in array: item *= 2 This is equivalent to index = 0 while index len(array): item = array[index] #

Re: [Tutor] SQLite database creation bafflement

2007-08-20 Thread Alan Gauld
Che M [EMAIL PROTECTED] wrote don't. For example, this will create a brand new database on the desktop: conn = sqlite3.connect('C:\Documents and Settings\user\Desktop\mydatabase.db') But running *this*--only thing different is the database's name--gives the error, as shown: conn =

Re: [Tutor] SQLite database creation bafflement

2007-08-20 Thread Roel Schroeven
Che M schreef: Hi, I am trying to simply create an SQLite database with Python. I find that when I try to create a new database file, *sometimes* it lets me do it, and sometimes it doesn't, and the only thing I am changing is the name of the database. I am baffled as to why some names

[Tutor] Loop optimization

2007-08-20 Thread wormwood_3
Hello tutors, I am trying to understand the best cases in which to use for loops, list comprehensions, generators, and iterators. I have a rather simple process that I made initially as a for loop: self.potdomains = [] for word in self.dictcontents:

Re: [Tutor] Loop optimization

2007-08-20 Thread Kent Johnson
wormwood_3 wrote: Hello tutors, I am trying to understand the best cases in which to use for loops, list comprehensions, generators, and iterators. I have a rather simple process that I made initially as a for loop: self.potdomains = [] for word in self.dictcontents:

Re: [Tutor] Loop optimization

2007-08-20 Thread wormwood_3
I think what you have is pretty clear. I can't think of a way to do this with a single list comprehension because you add two items to the list each time through the loop. You could use a list comp and a generator expression, but the order of entries in the result will be different:

Re: [Tutor] Python Book Recommendations [Was:[Re: Security]]

2007-08-20 Thread Chris Calloway
Tim Michelsen wrote: How nice that the SWC gets updated and improved! I heard from Chris Lasher at the SWC Sprint on Saturday. Turns out there is a bug collector for SWC and this bug has been documented for some time: http://projects.scipy.org/swc/ticket/88 Chris reported, Will have this

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Noufal Ibrahim
János Juhász wrote: Dear Tutors! I know a python list is a mutable object. array = [1,2,3,4,5] So I can modify any item in it. for index in range(len(array)): array[index] *= 2 ... array [2, 4, 6, 8, 10] So I typed this: for item in array: item *= 2 ... array [1, 2, 3, 4, 5]

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Trilok Khairnar
It also seems fair to do the following (if the modified list is to be used more than once - to avoid building the modified list more than once)? array = [item*2 for item in array] # instead of for item in array: item *= 2 Regards, Trilok -Original Message- From: [EMAIL PROTECTED]

Re: [Tutor] xls file

2007-08-20 Thread Kirk Bailey
ok, I installed XLRD and can load a xls file; it works quite well BTW. Now it is returning Unicode objects. I need to strip that to a simple string value. Is there a recommended way or module for handling Unicode objects? Kirk Bailey wrote: Ii want to read a xls file and use the data in part

Re: [Tutor] SQLite database creation bafflement

2007-08-20 Thread Che M
Thank you Alan and Roel for the insight, and Roel thank you for all the suggested ways to get around it. It's always nice when something goes from making no sense to making complete sense in a snap. Che _ Booking a flight? Know

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Ricardo Aráoz
Noufal Ibrahim wrote: János Juhász wrote: Dear Tutors! I know a python list is a mutable object. array = [1,2,3,4,5] So I can modify any item in it. for index in range(len(array)): array[index] *= 2 ... array [2, 4, 6, 8, 10] So I typed this: for item in array: item *= 2 ... array

Re: [Tutor] xls file

2007-08-20 Thread Kent Johnson
Kirk Bailey wrote: ok, I installed XLRD and can load a xls file; it works quite well BTW. Now it is returning Unicode objects. I need to strip that to a simple string value. Is there a recommended way or module for handling Unicode objects? What kind of characters are in the Excel file? What

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Dave Kuhlman
On Mon, Aug 20, 2007 at 03:14:24PM -0300, Ricardo Ar?oz wrote: [snip] You just work on a generated modified list. foo = range(1,6) for i in [x*2 for x in foo]: do_whatever_you_want_with(i) What about : array = [1,2,3,4,5] array = [i * 2 for i in array] Good solution.

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Kent Johnson
Dave Kuhlman wrote: Consider the following: array = [1,2,3,4,5] array2 = array array = [i * 2 for i in array] array [2, 4, 6, 8, 10] array2 [1, 2, 3, 4, 5] So, did you want array2 to change, or not? Here is a solution that changes the object that

Re: [Tutor] iterate list items as lvalue

2007-08-20 Thread Ricardo Aráoz
Kent Johnson wrote: Dave Kuhlman wrote: Consider the following: array = [1,2,3,4,5] array2 = array array = [i * 2 for i in array] array [2, 4, 6, 8, 10] array2 [1, 2, 3, 4, 5] So, did you want array2 to change, or not? Here is a solution that changes

Re: [Tutor] Loop optimization

2007-08-20 Thread wormwood_3
I ran a few tests, with the following results: 1. Timing using the time module: * Using for loop, src code: import time start = time.time() for word in self.dictcontents: self.potdomains.append(word +

Re: [Tutor] Loop optimization

2007-08-20 Thread Kent Johnson
wormwood_3 wrote: I ran a few tests, with the following results: 1. Timing using the time module: * Using for loop, src code: import time start = time.time() for word in self.dictcontents:

[Tutor] Accesing column of a 2D list

2007-08-20 Thread Orest Kozyar
I've got a 2D list (essentially a list of lists where all sublists are of the same length). The sublists are polymorphic. One 2D list I commonly work with is: [ [datetime object, float, int, float], [datetime object, float, int, float], [datetime object, float, int, float] ] I'd like to be

Re: [Tutor] Accesing column of a 2D list

2007-08-20 Thread Ian Witham
This looks like a job for List Comprehensions! list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] new_list = [item[1] for item in list] new_list [2, 5, 8] looks good? Ian On 8/21/07, Orest Kozyar [EMAIL PROTECTED] wrote: I've got a 2D list (essentially a list of lists where all sublists are of

[Tutor] operating system key-bindings that call Python scripts

2007-08-20 Thread tpc247
I have a particular date time format I use for making entries in various logs I maintain, and ideally what I'd like is for my operating system (Windows or Linux) to recognize that every time I type, say, Ctrl-'C' '1', a Python script I wrote will execute and out will pop the current date time in