Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Alan Gauld
Jojo Mwebaze jojo.mweb...@gmail.com wrote i would like to implement the following in lists assuming x = 3 y = 4 z = None i want to create a dynamic list such that mylist = [ x , y, z ] , if z in not None if z is None then mylist = [x,y] Assuming you actually mean that you don;t want

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Christian Witts
Jojo Mwebaze wrote: Hi There, i would like to implement the following in lists assuming x = 3 y = 4 z = None i want to create a dynamic list such that mylist = [ x , y, z ] , if z in not None if z is None then mylist = [x,y] Anyhelp! cheers Jojo

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Dave Angel
Jojo Mwebaze wrote: Hi There, i would like to implement the following in lists assuming x = 3 y = 4 z = None i want to create a dynamic list such that mylist = [ x , y, z ] , if z in not None if z is None then mylist = [x,y] Anyhelp! cheers Jojo Are there any constraints on x

Re: [Tutor] Encoding

2010-03-03 Thread Stefan Behnel
Giorgio, 03.03.2010 09:36: i am looking for more informations about encoding in python: i've read that Amazon SimpleDB accepts every string encoded in UTF-8. How can I encode a string? byte_string = unicode_string.encode('utf-8') If you use unicode strings throughout your application, you

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Jojo Mwebaze
Thanks to everyone, nice ideas! cheers On Wed, Mar 3, 2010 at 10:02 AM, Christian Witts cwi...@compuscan.co.zawrote: Jojo Mwebaze wrote: Hi There, i would like to implement the following in lists assuming x = 3 y = 4 z = None i want to create a dynamic list such that mylist = [ x

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread C.T. Matsumoto
Dave Angel wrote: Jojo Mwebaze wrote: Hi There, i would like to implement the following in lists assuming x = 3 y = 4 z = None i want to create a dynamic list such that mylist = [ x , y, z ] , if z in not None if z is None then mylist = [x,y] Anyhelp! cheers Jojo Are there any

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Steven D'Aprano
On Wed, 3 Mar 2010 07:46:39 pm Alan Gauld wrote: mylist = [irtem for item in aList where item != None] Comparisons with None almost always should be one of: item is None item is not None The reason is that item is None is ONLY ever true if the item actually is the singleton object None

[Tutor] sorting algorithm

2010-03-03 Thread C.T. Matsumoto
Hello, This is follow up on a question I had about algorithms. In the thread it was suggested I make my own sorting algorithm. Here are my results. #!/usr/bin/python def sort_(list_): for item1 in list_: pos1 = list_.index(item1) pos2 = pos1 + 1 try: item2

Re: [Tutor] Why is the max size so low in this mail list?

2010-03-03 Thread spir
On Wed, 03 Mar 2010 02:38:57 +1100 Lie Ryan lie.1...@gmail.com wrote: On 03/02/2010 04:13 AM, Wayne Watson wrote: See Subject. 40K here, but other Python lists allow for larger (total) sizes. I don't know, I've never realized it; that's an indication that the 40K limit is reasonable, at

Re: [Tutor] Encoding

2010-03-03 Thread Patrick Sabin
Giorgio wrote: i am looking for more informations about encoding in python: i've read that Amazon SimpleDB accepts every string encoded in UTF-8. How can I encode a string? And, what's the default string encoding in python? I think the safest way is to use unicode strings in your

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
byte_string = unicode_string.encode('utf-8') If you use unicode strings throughout your application, you will be happy with the above. Note that this is an advice, not a condition. Mmm ok. So all strings in the app are unicode by default? Do you know if there is a function/method i can

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
Oh, sorry, let me update my last post: if i have a string, let's say: s = hi giorgio; and want to store it in a latin1 db, i need to convert it to latin1 before storing, right? 2010/3/3 Giorgio anothernetfel...@gmail.com byte_string = unicode_string.encode('utf-8') If you use unicode

[Tutor] Bowing out

2010-03-03 Thread Kent Johnson
Hi all, After six years of tutor posts my interest and energy have waned and I'm ready to move on to something new. I'm planning to stop reading and contributing to the list. I have handed over list moderation duties to Alan Gauld and Wesley Chun. Thanks to everyone who contributes questions and

Re: [Tutor] Encoding

2010-03-03 Thread Patrick Sabin
Mmm ok. So all strings in the app are unicode by default? Depends on your python version. If you use python 2.x, you have to use a u before the string: s = u'Hallo World' Do you know if there is a function/method i can use to check encoding of a string? AFAIK such a function doesn't

Re: [Tutor] Bowing out

2010-03-03 Thread Wayne Werner
I can only add my personal thanks, and echo the sentiments of others. I'm certainly glad the archives exist, and that those inheriting responsibility are certainly well qualified. So long and thanks for all the fish! -Wayne 2010/3/3 Emad Nawfal (عمـ نوفل ـاد) emadnaw...@gmail.com On Wed,

Re: [Tutor] Bowing out

2010-03-03 Thread Modulok
After six years of tutor posts my interest and energy have waned and I'm ready to move on to something new. I'm planning to stop reading and contributing to the list. I have handed over list moderation duties to Alan Gauld and Wesley Chun. Thanks to everyone who contributes questions and

Re: [Tutor] Bowing out

2010-03-03 Thread Philip Kilner
Hi Kent, Thank you! -- Regards, PhilK 'work as if you lived in the early days of a better nation' - alasdair gray smime.p7s Description: S/MIME Cryptographic Signature ___ Tutor maillist - Tutor@python.org To unsubscribe or change

Re: [Tutor] Encoding

2010-03-03 Thread Stefan Behnel
Giorgio, 03.03.2010 15:50: Depends on your python version. If you use python 2.x, you have to use a u before the string: s = u'Hallo World' Ok. So, let's go back to my first question: s = u'Hallo World' is unicode in python 2.x - ok Correct. s = 'Hallo World' how is encoded?

Re: [Tutor] Encoding

2010-03-03 Thread Patrick Sabin
Giorgio wrote: Depends on your python version. If you use python 2.x, you have to use a u before the string: s = u'Hallo World' Ok. So, let's go back to my first question: s = u'Hallo World' is unicode in python 2.x - ok s = 'Hallo World' how is encoded? I am not 100% sure,

Re: [Tutor] Bowing out

2010-03-03 Thread Dave Angel
Kent Johnson wrote: Hi all, After six years of tutor posts my interest and energy have waned and I'm ready to move on to something new. I'm planning to stop reading and contributing to the list. I have handed over list moderation duties to Alan Gauld and Wesley Chun. Thanks to everyone who

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
Uff, encoding is a very painful thing in programming. Ok so now comes last layer of the encoding: the webserver. I now know how to handle encoding in a python app and in interactions with the db, but the last step is sending the content to the webserver. How should i encode pages? The encoding

Re: [Tutor] sorting algorithm

2010-03-03 Thread Dave Angel
C.T. Matsumoto wrote: Hello, This is follow up on a question I had about algorithms. In the thread it was suggested I make my own sorting algorithm. Here are my results. #!/usr/bin/python def sort_(list_): for item1 in list_: pos1 = list_.index(item1) pos2 = pos1 + 1

Re: [Tutor] Encoding

2010-03-03 Thread Dave Angel
Giorgio wrote: Depends on your python version. If you use python 2.x, you have to use a u before the string: s = u'Hallo World' Ok. So, let's go back to my first question: s = u'Hallo World' is unicode in python 2.x - ok s = 'Hallo World' how is encoded? Since it's a

Re: [Tutor] Bowing out

2010-03-03 Thread Sander Sweers
On 3 March 2010 14:17, Kent Johnson ken...@tds.net wrote: After six years of tutor posts my interest and energy have waned and I'm ready to move on to something new. Let me join the other people and thank you for your contribution to this list. Good luck with something new :-) Greets Sander

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
Ok. So, how do you encode .py files? UTF-8? 2010/3/3 Dave Angel da...@ieee.org Giorgio wrote: Depends on your python version. If you use python 2.x, you have to use a u before the string: s = u'Hallo World' Ok. So, let's go back to my first question: s = u'Hallo World' is

Re: [Tutor] Bowing out

2010-03-03 Thread Albert-Jan Roskam
Hi Kent, Thank you very much for sharing your knowledge. Much appreciated! Cheers!! Albert-Jan ~~ In the face of ambiguity, refuse the temptation to guess.

[Tutor] no bowing out for you

2010-03-03 Thread Gman
Nope ya can't do it Kent, we wont have it ! Looks like a good time to start a patitiion to get you a salary or something to keep you on :) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] getting diagonals from a matrix

2010-03-03 Thread Emile van Sebille
On 3/2/2010 2:54 PM David Eccles (gringer) said... I've managed to drum up some code to obtain a list containing joined diagonal elements of a matrix (I'm making a word finder generator), but am wondering if there's any better way to do this: This works. Lots of other ways would work too.

Re: [Tutor] Bowing out

2010-03-03 Thread David Hutto
--- On Wed, 3/3/10, Sander Sweers sander.swe...@gmail.com wrote: From: Sander Sweers sander.swe...@gmail.com Subject: Re: [Tutor] Bowing out To: Kent Johnson ken...@tds.net Cc: Tutor@python.org Date: Wednesday, March 3, 2010, 11:06 AM On 3 March 2010 14:17, Kent Johnson ken...@tds.net wrote:

Re: [Tutor] Bowing out

2010-03-03 Thread Glen Zangirolami
Thank you for all your hard work! I learned a ton from your tutorials. Good luck on your future endeavors. On Wed, Mar 3, 2010 at 10:18 AM, Albert-Jan Roskam fo...@yahoo.com wrote: Hi Kent, Thank you very much for sharing your knowledge. Much appreciated! Cheers!! Albert-Jan

Re: [Tutor] getting diagonals from a matrix

2010-03-03 Thread Glen Zangirolami
I am not really sure of a better way but if your looking for a way to make your code cleaner or more efficient you can try Numpy - http://numpy.scipy.org/ On Tue, Mar 2, 2010 at 4:54 PM, David Eccles (gringer) gm...@gringer.orgwrote: I've managed to drum up some code to obtain a list

[Tutor] unittest

2010-03-03 Thread C.T. Matsumoto
Hello, Can someone tell me the difference between unittests assertEqual and assertEquals? Cheers, T ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
Ops, i have another update: string = ublabla This is unicode, ok. Unicode UTF-8? Thankyou 2010/3/3 Giorgio anothernetfel...@gmail.com Ok. So, how do you encode .py files? UTF-8? 2010/3/3 Dave Angel da...@ieee.org Giorgio wrote: Depends on your python version. If you use python

[Tutor] lazy? vs not lazy? and yielding

2010-03-03 Thread John
Hi, I just read a few pages of tutorial on list comprehenion and generator expression. From what I gather the difference is [ ] and ( ) at the ends, better memory usage and the something the tutorial labeled as lazy evaluation. So a generator 'yields'. But what is it yielding too? John

Re: [Tutor] sorting algorithm

2010-03-03 Thread Glen Zangirolami
http://www.sorting-algorithms.com/ It is a fantastic website that explains each kind of sort and how it works. They also show you visuals how the sorts work and how fast they go based on the amount of data. Depending on the amount/kind of data I would choose a sorting algorithm that fits your

Re: [Tutor] sorting algorithm

2010-03-03 Thread C.T. Matsumoto
Dave Angel wrote: C.T. Matsumoto wrote: Hello, This is follow up on a question I had about algorithms. In the thread it was suggested I make my own sorting algorithm. Here are my results. #!/usr/bin/python def sort_(list_): for item1 in list_: pos1 = list_.index(item1)

Re: [Tutor] Bowing out

2010-03-03 Thread David
After six years of tutor posts my interest and energy have waned and I'm ready to move on to something new. Another new Python student that received understanding from your style and knowledge, great teacher. I hope you will post some more tutorials on Kents Korner when you find the time and

Re: [Tutor] sorting algorithm

2010-03-03 Thread Dave Angel
(You forgot to do a Reply-All, so your message went to just me, rather than to me and the list ) C.T. Matsumoto wrote: Dave Angel wrote: C.T. Matsumoto wrote: Hello, This is follow up on a question I had about algorithms. In the thread it was suggested I make my own sorting algorithm.

Re: [Tutor] Bowing out

2010-03-03 Thread Alan Gauld
kevin parks k...@mac.com wrote Wish Danny Yoo was still here too. Technically he is, but just keeps very, very quiet! :-) Alan G. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] Encoding

2010-03-03 Thread Stefan Behnel
Giorgio, 03.03.2010 18:28: string = ublabla This is unicode, ok. Unicode UTF-8? No, not UTF-8. Unicode. You may want to read this: http://www.amk.ca/python/howto/unicode Stefan ___ Tutor maillist - Tutor@python.org To unsubscribe or change

Re: [Tutor] Bowing out

2010-03-03 Thread Ken G.
Thanks for helping out. I enjoyed readying your posts. Good luck on your future endeavors. Ken Kent Johnson wrote: Hi all, After six years of tutor posts my interest and energy have waned and I'm ready to move on to something new. I'm planning to stop reading and contributing to the list. I

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
Please let me post the third update O_o. You can forgot other 2, i'll put them into this email. --- s = ciao è ciao print s ciao è ciao s.encode('utf-8') Traceback (most recent call last): File pyshell#2, line 1, in module s.encode('utf-8') UnicodeDecodeError: 'ascii' codec can't decode

Re: [Tutor] Encoding

2010-03-03 Thread Giorgio
I'm sorry, it's utf8_unicode_ci that's confusing me. So, UTF-8 is one of the most commonly used encodings. UTF stands for Unicode Transformation Format UTF8 is, we can say, a type of unicode, right? And what about utf8_unicode_ci in mysql? Giorgio 2010/3/3 Stefan Behnel stefan...@behnel.de

Re: [Tutor] lazy? vs not lazy? and yielding

2010-03-03 Thread Dave Angel
John wrote: Hi, I just read a few pages of tutorial on list comprehenion and generator expression. From what I gather the difference is [ ] and ( ) at the ends, better memory usage and the something the tutorial labeled as lazy evaluation. So a generator 'yields'. But what is it yielding

Re: [Tutor] Encoding

2010-03-03 Thread Dave Angel
(Don't top-post. Put your response below whatever you're responding to, or at the bottom.) Giorgio wrote: Ok. So, how do you encode .py files? UTF-8? 2010/3/3 Dave Angel da...@ieee.org I personally use Komodo to edit my python source files, and tell it to use UTF8 encoding. Then I add

Re: [Tutor] Encoding

2010-03-03 Thread Sander Sweers
On 3 March 2010 20:44, Giorgio anothernetfel...@gmail.com wrote: s = ciao è ciao print s ciao è ciao s.encode('utf-8') Traceback (most recent call last):   File pyshell#2, line 1, in module     s.encode('utf-8') UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 5:

Re: [Tutor] How to wrap ctype functions

2010-03-03 Thread Hugo Arts
On Wed, Mar 3, 2010 at 6:43 PM, Jan Jansen knack...@googlemail.com wrote: Hi there, I wonder what's the best way to wrap given function calls (in this case ctype function calls but more generally built-in functions and those kinds). I have a huge c library and almost all functions return an

Re: [Tutor] Bowing out

2010-03-03 Thread Kent Johnson
On Wed, Mar 3, 2010 at 11:51 AM, Robert webtour...@gmail.com wrote: so you're done with Python ? :) No, I hope not! I still love Python, but my enthusiasm for beginners questions has pretty much gone away. I'm looking for a place where I can contribute code rather than answers, possibly with the

Re: [Tutor] unittest

2010-03-03 Thread Steven D'Aprano
On Thu, 4 Mar 2010 04:27:23 am C.T. Matsumoto wrote: Hello, Can someone tell me the difference between unittests assertEqual and assertEquals? assertEqual, assertEquals and failUnless are three spellings for the same thing. There is no difference. -- Steven D'Aprano

Re: [Tutor] Encoding

2010-03-03 Thread Sander Sweers
On 3 March 2010 22:41, Sander Sweers sander.swe...@gmail.com wrote: It is confusing but once understand how it works it makes sense. I remembered Kent explained it very clear in [1]. Greets Sander [1] http://mail.python.org/pipermail/tutor/2009-May/068920.html

Re: [Tutor] sorting algorithm

2010-03-03 Thread Steven D'Aprano
On Thu, 4 Mar 2010 04:34:09 am Glen Zangirolami wrote: http://www.sorting-algorithms.com/ It is a fantastic website that explains each kind of sort and how it works. They also show you visuals how the sorts work and how fast they go based on the amount of data. For actual practical work, you

Re: [Tutor] How to wrap ctype functions

2010-03-03 Thread Steven D'Aprano
On Thu, 4 Mar 2010 04:43:28 am Jan Jansen wrote: Hi there, I wonder what's the best way to wrap given function calls (in this case ctype function calls but more generally built-in functions and those kinds). I have a huge c library and almost all functions return an error code. The library

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Steven D'Aprano
On Thu, 4 Mar 2010 05:18:40 am Alan Gauld wrote: Steven D'Aprano st...@pearwood.info wrote Comparisons with None almost always should be one of: item is None item is not None Yes, but the reason I changed it (I originally had is not) is that != is a more general test for illustrating

Re: [Tutor] Any Tutor there ? Removing redundant parameters in a models file having include files.

2010-03-03 Thread Karim Liateni
Hello Alan, Steven, I was narrow minded about this topic and did not see the benefits of these multiple Python implementations. You opened my eyes. Regards Karim Steven D'Aprano wrote: On Tue, 2 Mar 2010 11:25:44 am Andreas Kostyrka wrote: Furthermore I do not think that most of the

Re: [Tutor] parsing a chunked text file

2010-03-03 Thread Karim Liateni
Hello Steven, Is there a big difference to write your first functions as below because I am not familiar with yield keyword? def skip_blanks(lines): Remove leading and trailing whitespace, ignore blank lines. return [line.strip() in lines if line.strip()] I tried to write as well the

Re: [Tutor] List comprehension possible with condition statements?

2010-03-03 Thread Alan Gauld
Steven D'Aprano st...@pearwood.info wrote List comps can include *any* comparison: [x+1 for x in data if (3*x+2)**2 100*x or x -5] Sure, but the wording suggested (maybe wrongly) that the OP was a real beginner and so the concept of an expression was likely to be foreign. Sticking with

[Tutor] Understanding (Complex) Modules

2010-03-03 Thread Wayne Watson
First a little preamble before my questions. Most of my work in Python has required modifying a program that uses modules that were imported by the original program. I've made some use of modules on a command line like math, and have used the idea of a qualifier. On occasion, I've used

Re: [Tutor] Understanding (Complex) Modules

2010-03-03 Thread David Hutto
--- On Wed, 3/3/10, Wayne Watson sierra_mtnv...@sbcglobal.net wrote: From: Wayne Watson sierra_mtnv...@sbcglobal.net Subject: [Tutor] Understanding (Complex) Modules To: tutor@python.org Date: Wednesday, March 3, 2010, 8:24 PM First a little preamble before my questions. Most of my work in

Re: [Tutor] Encoding

2010-03-03 Thread spir
On Wed, 3 Mar 2010 16:32:01 +0100 Giorgio anothernetfel...@gmail.com wrote: Uff, encoding is a very painful thing in programming. For sure, but it's true for any kind of data, not only text :-) Think at music or images *formats*. The issue is a bit obscured for text but the use of the

Re: [Tutor] Bowing out

2010-03-03 Thread python
Hi Kent, Your posts and web pages really helped me during my early days with python. Wishing you great success in your new endeavors!!! Cheers, Malcolm ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] Encoding

2010-03-03 Thread spir
On Wed, 3 Mar 2010 20:44:51 +0100 Giorgio anothernetfel...@gmail.com wrote: Please let me post the third update O_o. You can forgot other 2, i'll put them into this email. --- s = ciao è ciao print s ciao è ciao s.encode('utf-8') Traceback (most recent call last): File

[Tutor] object representation

2010-03-03 Thread spir
Hello, In python like in most languages, I guess, objects (at least composite ones -- I don't know about ints, for instance -- someone knows?) are internally represented as associative arrays. Python associative arrays are dicts, which in turn are implemented as hash tables. Correct? Does this