Re: Appending to []

2012-04-21 Thread Steven D'Aprano
On Sat, 21 Apr 2012 14:48:44 +0200, Bernd Nawothnig wrote: > On 2012-04-20, Rotwang wrote: >> since a method doesn't assign the value it returns to the instance on >> which it is called; what it does to the instance and what it returns >> are two completely different things. > > Returning a None-

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Chris Angelico
On Sun, Apr 22, 2012 at 1:14 PM, Steven D'Aprano wrote: > The CPython interpreter is especially aggressive in optimizing multiple > literals in the same line. Compare this: > x = 3.1; y = 3.1; x is y > True > > with this: > x = 3.1 y = 3.1 x is y > False > > > Again, this is an

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Steven D'Aprano
On Sat, 21 Apr 2012 15:02:00 +0200, Bernd Nawothnig wrote: > On 2012-04-20, dmitrey wrote: >> I have spent some time searching for a bug in my code, it was due to >> different work of "is" with () and []: > () is () >> True > > You should better not rely on that result. I would consider it to

Re: Newbie, homework help, please.

2012-04-21 Thread Michael Torrie
On 04/21/2012 02:14 PM, someone wrote: > Thanks for your reply Mr. Roy Smith. Also, thanks for the tip. Maybe > I did not make myself as clear or maybe you did not understand my > post. It states homework help, and I am doing this post to get help > before I pay somebody to show me how to do it,

Re: Newbie, homework help, please.

2012-04-21 Thread duncan smith
On 21/04/12 23:48, BartC wrote: "someone" wrote in message news:9533449.630.1335042672358.JavaMail.geo-discussion-forums@ynmf4... On Saturday, April 21, 2012 3:44:49 PM UTC-5, BartC wrote: Hi, Bart: Thank you, your post is working now, maybe, I did something wrong, unfortunately, you are rig

Re: Newbie, homework help, please.

2012-04-21 Thread BartC
"someone" wrote in message news:9533449.630.1335042672358.JavaMail.geo-discussion-forums@ynmf4... On Saturday, April 21, 2012 3:44:49 PM UTC-5, BartC wrote: Hi, Bart: Thank you, your post is working now, maybe, I did something wrong, unfortunately, you are right, my setup for getting the file

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Robert Kern
On 4/21/12 10:15 PM, Bernd Nawothnig wrote: Your argument above was: it would violate first principles. And I still don't see that point. The comparison [] is [] maybe totally useless, of course, but which first principle would be violated by a compiler that lets that expression evaluate to True

Re: Newbie, homework help, please.

2012-04-21 Thread Kiuhnm
On 4/21/2012 22:26, GrayShark wrote: --- #!/usr/bin/python xl = ["First Name and Last","ENGR 109-X","Fall 2999","Format Example"] xl_max = 0 for x in xl: xl_max = max ( len( x ), xl_max ) Or xl_max = max([len(x) for x in xl]) topBorder = '^'*( xl_max + 4 ) pr

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Bernd Nawothnig
On Sat, Apr 21, 2012 at 03:43:03PM -0400, Dave Angel wrote: > On 04/21/2012 09:48 AM, Bernd Nawothnig wrote: > > On Sat, Apr 21, 2012 at 09:21:50AM -0400, Dave Angel wrote: > >>> [] is [] > False > >>> Same for that. > >> > >> Here I have to disagree. If an implementation reused the list

Re: Newbie, homework help, please.

2012-04-21 Thread someone
On Saturday, April 21, 2012 3:44:49 PM UTC-5, BartC wrote: > "someone" wrote in message > news:9071485.2215.1335040139144.JavaMail.geo-discussion-forums@yniw15... > > > Thanks Bart for trying, it helped me out a little more by showing me a > > little more than I knew, but I tried and I am not sur

Re: Newbie, homework help, please.

2012-04-21 Thread BartC
"someone" wrote in message news:9071485.2215.1335040139144.JavaMail.geo-discussion-forums@yniw15... Thanks Bart for trying, it helped me out a little more by showing me a little more than I knew, but I tried and I am not sure if it does fit my example due to it was too many stars in between the

Re: Newbie, homework help, please.

2012-04-21 Thread BartC
"someone" wrote in message news:4068590.2196.1335038608255.JavaMail.geo-discussion-forums@ynjn4... textTuple = border(SHI) for lines in textTuple: print (lines) Thanks your Bart for trying, I don't understand how it works or if you tried to place my script in python to see if it would wo

Re: Newbie, homework help, please.

2012-04-21 Thread someone
On Saturday, April 21, 2012 12:28:33 PM UTC-5, someone wrote: > Ok, this is my dillema, not only am I new to this programming buisness, > before the last few days, I did not even know what python was, and besides > opening up the internet or word documents, that is most of what I know. Yet, > I

Re: Newbie, homework help, please.

2012-04-21 Thread GrayShark
A lot of to do about this. --- #!/usr/bin/python xl = ["First Name and Last","ENGR 109-X","Fall 2999","Format Example"] xl_max = 0 for x in xl: xl_max = max ( len( x ), xl_max ) topBorder = '^'*( xl_max + 4 ) print topBorder for x in xl: print "* %s%s *

Re: Newbie, homework help, please.

2012-04-21 Thread Roy Smith
On 04/21/12 14:44, Roy Smith wrote: > print "* %-*s *" % (max_length, data) On Apr 21, 2012, at 4:12 PM, Tim Chase wrote: > Sounds like a lot more work and less flexible than using the (underemployed) > .ljust() or .center() methods of a string. :-) > > print "* %s *" % data.ljust(42) Six o

Re: Newbie, homework help, please.

2012-04-21 Thread someone
On Saturday, April 21, 2012 12:28:33 PM UTC-5, someone wrote: > Ok, this is my dillema, not only am I new to this programming buisness, > before the last few days, I did not even know what python was, and besides > opening up the internet or word documents, that is most of what I know. Yet, > I

Re: Newbie, homework help, please.

2012-04-21 Thread someone
On Saturday, April 21, 2012 12:28:33 PM UTC-5, someone wrote: > Ok, this is my dillema, not only am I new to this programming buisness, > before the last few days, I did not even know what python was, and besides > opening up the internet or word documents, that is most of what I know. Yet, > I

Re: Newbie, homework help, please.

2012-04-21 Thread Tim Chase
On 04/21/12 14:44, Roy Smith wrote: *** * * * First Name and Last * * ENGR 109-X * * Fall 2999 * * Format Example * * * *** You

Re: Newbie, homework help, please.

2012-04-21 Thread Roy Smith
In article <32945367.2045.1335029313436.JavaMail.geo-discussion-forums@ynjn4>, someone wrote: I'm not going to do your homework for you (nor do I expect anybody else will), but I'll give you a hint about one sticky part. > 6) Display the SHI data read from the file in the interpreter with a b

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Dave Angel
On 04/21/2012 09:48 AM, Bernd Nawothnig wrote: > On Sat, Apr 21, 2012 at 09:21:50AM -0400, Dave Angel wrote: >>> [] is [] False >>> Same for that. >> >> Here I have to disagree. If an implementation reused the list object >> for two simultaneously-existing instances, it would violate firs

Re: Newbie, homework help, please.

2012-04-21 Thread BartC
"someone" wrote in message news:32945367.2045.1335029313436.JavaMail.geo-discussion-forums@ynjn4... 6) Display the SHI data read from the file in the interpreter with a border around the SHI data (include a buffer of 1 line/space between the border and SHI data). An example might look like:

Re: Newbie, homework help, please.

2012-04-21 Thread MRAB
On 21/04/2012 18:28, someone wrote: Ok, this is my dillema, not only am I new to this programming buisness, before the last few days, I did not even know what python was, and besides opening up the internet or word documents, that is most of what I know. Yet, I have a professor who should be o

Re: Newbie, homework help, please.

2012-04-21 Thread Jon Clements
On Saturday, 21 April 2012 18:35:26 UTC+1, someone wrote: > On Saturday, April 21, 2012 12:28:33 PM UTC-5, someone wrote: > > Ok, this is my dillema, not only am I new to this programming buisness, > > before the last few days, I did not even know what python was, and besides > > opening up the

Re: Newbie, homework help, please.

2012-04-21 Thread Ian Kelly
On Sat, Apr 21, 2012 at 11:28 AM, someone wrote: > for item in userinput: >    openfile=open(textfile,'w');openfile.writelines("%s\n" % item for item in > userinput);openfile.close() The for loop here means that the file will be written and rewritten four times. The end result is the same, but

Re: Appending to []

2012-04-21 Thread Bernd Nawothnig
On 2012-04-21, Kiuhnm wrote: > Sorry if I wasn't clear. I meant that one should either relies on > side-effects and write something like >a.append('x').append('t').append('z') > or use a more functional style and write >a = a + [x] + [z] > Mixing the two doesn't seem very elegant to me. >

Re: Newbie, homework help, please.

2012-04-21 Thread someone
On Saturday, April 21, 2012 12:28:33 PM UTC-5, someone wrote: > Ok, this is my dillema, not only am I new to this programming buisness, > before the last few days, I did not even know what python was, and besides > opening up the internet or word documents, that is most of what I know. Yet, > I

Newbie, homework help, please.

2012-04-21 Thread someone
Ok, this is my dillema, not only am I new to this programming buisness, before the last few days, I did not even know what python was, and besides opening up the internet or word documents, that is most of what I know. Yet, I have a professor who should be on Psych medication for giving us 3 pro

Re: Appending to []

2012-04-21 Thread Kiuhnm
On 4/21/2012 18:14, Kiuhnm wrote: On 4/21/2012 17:41, Bernd Nawothnig wrote: On 2012-04-21, Kiuhnm wrote: Returning a None-value is pretty useless. Why not returning self, which would be the resulting list in this case? Returning self would make the language a little bit more functional, withou

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Terry Reedy
On 4/21/2012 9:02 AM, Bernd Nawothnig wrote: You should better not rely on that result. I would consider it to be an implementation detail. I may be wrong, but would an implementation that results in () is () ==> False be correct or is the result True really demanded by the language specifica

Re: Appending to []

2012-04-21 Thread Kiuhnm
On 4/21/2012 17:41, Bernd Nawothnig wrote: On 2012-04-21, Kiuhnm wrote: Returning a None-value is pretty useless. Why not returning self, which would be the resulting list in this case? Returning self would make the language a little bit more functional, without any drawback. ^

Re: Appending to []

2012-04-21 Thread Terry Reedy
On 4/21/2012 9:08 AM, Dave Angel wrote: On 04/21/2012 08:48 AM, Bernd Nawothnig wrote: On 2012-04-20, Rotwang wrote: since a method doesn't assign the value it returns to the instance on which it is called; what it does to the instance and what it returns are two completely different things. R

Re: Appending to []

2012-04-21 Thread Bernd Nawothnig
On 2012-04-21, Kiuhnm wrote: >> Returning a None-value is pretty useless. Why not returning self, which >> would be >> the resulting list in this case? Returning self would make the >> language a little bit more functional, without any drawback. >> >> Then

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Chris Angelico
On Sat, Apr 21, 2012 at 10:51 PM, gst wrote: > case 2) also ok to me: > x = id([]) ; y = id([]) x == y > True > > > case 3) NOT ok to me : > x = id([]) y = id([]) x == y > False The fact that ids get reused at all is an implementation detail ONLY. In CPython, id

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread gst
Le samedi 21 avril 2012 10:46:39 UTC+2, Alexander Blinne a écrit : > Am 21.04.2012 05:25, schrieb Rotwang: > > This happens only because the first [] gets destroyed after evaluation > of id([]). The second [] then by accident gets the same id as the first > one had. > > >>> a = [] > >>> b = [] >

Re: Appending to []

2012-04-21 Thread Kiuhnm
On 4/21/2012 14:48, Bernd Nawothnig wrote: On 2012-04-20, Rotwang wrote: since a method doesn't assign the value it returns to the instance on which it is called; what it does to the instance and what it returns are two completely different things. Returning a None-value is pretty useless. Why

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Dave Angel
On 04/21/2012 09:02 AM, Bernd Nawothnig wrote: > On 2012-04-20, dmitrey wrote: >> I have spent some time searching for a bug in my code, it was due to >> different work of "is" with () and []: > () is () >> True > You should better not rely on that result. I would consider it to be > an impleme

Re: Appending to []

2012-04-21 Thread Dave Angel
On 04/21/2012 08:48 AM, Bernd Nawothnig wrote: > On 2012-04-20, Rotwang wrote: >> since a method doesn't assign the value it returns to the instance on >> which it is called; what it does to the instance and what it returns are >> two completely different things. > Returning a None-value is prett

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Bernd Nawothnig
On 2012-04-20, dmitrey wrote: > I have spent some time searching for a bug in my code, it was due to > different work of "is" with () and []: () is () > True You should better not rely on that result. I would consider it to be an implementation detail. I may be wrong, but would an implementat

Re: Using arguments in a decorator

2012-04-21 Thread Rotwang
On 21/04/2012 09:36, Steven D'Aprano wrote: [...] Here is how I would write the above. import functools def memoise(func): """Decorator to memoise a function.""" cache = {} @functools.wraps(func) def inner(*args, **kwargs): # Make sure keyword args are always look

Re: Appending to []

2012-04-21 Thread Bernd Nawothnig
On 2012-04-20, Rotwang wrote: > since a method doesn't assign the value it returns to the instance on > which it is called; what it does to the instance and what it returns are > two completely different things. Returning a None-value is pretty useless. Why not returning self, which would be the

Re: Using arguments in a decorator

2012-04-21 Thread Jon Clements
On Saturday, 21 April 2012 09:25:40 UTC+1, Steven D'Aprano wrote: > On Fri, 20 Apr 2012 09:10:15 -0700, Jon Clements wrote: > > >> But I don't know how. I know that I can see the default arguments of > >> the original function using func.__defaults__, but without knowing the > >> number and names

Re: some beginners questions about programming

2012-04-21 Thread Dave Angel
On 04/21/2012 06:03 AM, Santosh Kumar wrote: > Hello Python Developers, > > I have a very less experience with programming. I have digged a little bit > of all (I mean *C, **Java, JavaScript, PHP*) at introductory level and now > I have two question about it. > >1. Are *Arrays* and *Lists* same

Re: *.sdf database access

2012-04-21 Thread Alex Willmer
On Apr 19, 9:18 pm, Page3D wrote: > Hi, I am trying to connect and access data in a *.sdf file on Win7 > system using Python 2.7. I have three questions: > > 1. What python module should I use? I have looked at sqlite3 and > pyodbc. However, I can seem to get the connection to the database file >

some beginners questions about programming

2012-04-21 Thread Santosh Kumar
Hello Python Developers, I have a very less experience with programming. I have digged a little bit of all (I mean *C, **Java, JavaScript, PHP*) at introductory level and now I have two question about it. 1. Are *Arrays* and *Lists* same things? 2. Are *Modules* and *Libraries* same things?

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Serhiy Storchaka
[] is [] False id([]) == id([]) True >>> id([1]) == id([2]) True ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: why () is () and [] is [] work in other way?

2012-04-21 Thread Alexander Blinne
Am 21.04.2012 05:25, schrieb Rotwang: > On 21/04/2012 01:01, Roy Smith wrote: >> In article<877gxajit0@dpt-info.u-strasbg.fr>, >> Alain Ketterlin wrote: >> >>> Tuples are immutable, while lists are not. >> >> If you really want to have fun, consider this classic paradox: >> > [] is [] >>

Re: Using arguments in a decorator

2012-04-21 Thread Steven D'Aprano
On Fri, 20 Apr 2012 16:57:06 +0100, Rotwang wrote: > def memo(func): > def memofunc(*args, **kwargs): > twargs = tuple(kwargs.items()) > if (args, twargs) in memofunc.d: > return copy(memofunc.d[(args, twargs)]) > memofunc.d[(args, twargs)] = func(*args

Re: Using arguments in a decorator

2012-04-21 Thread Steven D'Aprano
On Fri, 20 Apr 2012 09:10:15 -0700, Jon Clements wrote: >> But I don't know how. I know that I can see the default arguments of >> the original function using func.__defaults__, but without knowing the >> number and names of func's positional arguments (which I don't know how >> to find out) this

Re: How do you refer to an iterator in docs?

2012-04-21 Thread Steven D'Aprano
On Fri, 20 Apr 2012 23:01:08 -0400, Roy Smith wrote: > A basket of apples is a basket which contains apples, in the same way a > list contains foos. But an iterator doesn't contain anything. You > wouldn't say, "a spigot of water", because the spigot isn't a container > holding the water. It is