Re: Strange behavior in string interpolation of constants

2017-10-16 Thread Ned Batchelder
On 10/16/17 7:39 PM, מיקי מונין wrote: Hello, I am working on an article on python string formatting. As a part of the article I am researching the different forms of python string formatting. While researching string interpolation(i.e. the % operator) I noticed something weird with string lengt

Strange behavior in string interpolation of constants

2017-10-16 Thread מיקי מונין
Hello, I am working on an article on python string formatting. As a part of the article I am researching the different forms of python string formatting. While researching string interpolation(i.e. the % operator) I noticed something weird with string lengths. Given two following two functions:

Re: Strange behavior

2016-01-14 Thread Chris Angelico
On Thu, Jan 14, 2016 at 3:03 PM, Michal Nalevanko wrote: > I've just installed Python 3.5.1 on my computer and came across somewhat > strange behavior. > > This is a snapshot of a short code that I wrote: https://goo.gl/izYbD0 > > Quite simple, you might say. Obviously, th

Strange behavior

2016-01-14 Thread Michal Nalevanko
Hello, I've just installed Python 3.5.1 on my computer and came across somewhat strange behavior. This is a snapshot of a short code that I wrote: https://goo.gl/izYbD0 Quite simple, you might say. Obviously, the program should create a new text file, nothing else. But do you see the numbe

Re: Strange Behavior

2014-06-03 Thread Steven D'Aprano
On Tue, 03 Jun 2014 10:01:26 +0200, Peter Otten wrote: > Steven D'Aprano wrote: > >> On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: >> >>> I invoked the wrong bug.py :/ , works fine now (this happens to me >>> when im a bit tired sometimes...). >> >> Clarity in naming is an excellent thin

Re: Strange Behavior

2014-06-03 Thread Peter Otten
Steven D'Aprano wrote: > On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: > >> I invoked the wrong bug.py :/ , works fine now (this happens to me when >> im a bit tired sometimes...). > > Clarity in naming is an excellent thing. If you have two files called > "bug.py", that's two too many.

Re: Choosing good names for things is difficult (was: Strange Behavior)

2014-06-02 Thread Chris Angelico
On Tue, Jun 3, 2014 at 12:06 PM, Rustom Mody wrote: > Add to that the restriction to limited character sets such as ASCII > – a restriction that has only historical relevance Wrong. The name has to fit inside the human's brain; if it's not ASCII, that's not a problem. ChrisA -- https://mail.pyt

Re: Choosing good names for things is difficult (was: Strange Behavior)

2014-06-02 Thread Rustom Mody
On Tuesday, June 3, 2014 6:27:25 AM UTC+5:30, Ben Finney wrote: > Steven D'Aprano writes: > > On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: > > > I invoked the wrong bug.py :/ , works fine now (this happens to me > > > when im a bit tired sometimes...). > > Clarity in naming is an excellen

Choosing good names for things is difficult (was: Strange Behavior)

2014-06-02 Thread Ben Finney
Steven D'Aprano writes: > On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: > > > I invoked the wrong bug.py :/ , works fine now (this happens to me > > when im a bit tired sometimes...). > > Clarity in naming is an excellent thing […] Programs should be named > by what they do […] or when tha

Re: Strange Behavior

2014-06-02 Thread Igor Korot
On Mon, Jun 2, 2014 at 5:30 PM, Chris Angelico wrote: > On Tue, Jun 3, 2014 at 10:22 AM, Steven D'Aprano > wrote: >> On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: >> >>> I invoked the wrong bug.py :/ , works fine now (this happens to me when >>> im a bit tired sometimes...). >> >> Clarity

Re: Strange Behavior

2014-06-02 Thread Chris Angelico
On Tue, Jun 3, 2014 at 10:22 AM, Steven D'Aprano wrote: > On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: > >> I invoked the wrong bug.py :/ , works fine now (this happens to me when >> im a bit tired sometimes...). > > Clarity in naming is an excellent thing. If you have two files called > "

Re: Strange Behavior

2014-06-02 Thread Steven D'Aprano
On Mon, 02 Jun 2014 20:05:29 +0200, robertw89 wrote: > I invoked the wrong bug.py :/ , works fine now (this happens to me when > im a bit tired sometimes...). Clarity in naming is an excellent thing. If you have two files called "bug.py", that's two too many. Imagine having fifty files called "

Re: Strange Behavior

2014-06-02 Thread robertw89
I invoked the wrong bug.py :/ , works fine now (this happens to me when im a bit tired sometimes...). Im unsure about the "real" bugreport, will investigate if I find some time and motivation. -- https://mail.python.org/mailman/listinfo/python-list

Re: Strange Behavior

2014-06-02 Thread Peter Otten
robert...@googlemail.com wrote: > Hello folks, > > I am not sure if it is only on my system the case that the code in > http://pastebin.com/WETvqMJN misbehaves in the stated way. > Can anybody reproduce it? > > I thought it could be that the tabs/spaces do influence it, but it doesn't > care. >

Re: Strange Behavior

2014-06-02 Thread Mark Lawrence
On 02/06/2014 17:35, robert...@googlemail.com wrote: Hello folks, I am not sure if it is only on my system the case that the code in http://pastebin.com/WETvqMJN misbehaves in the stated way. Can anybody reproduce it? I thought it could be that the tabs/spaces do influence it, but it doesn't ca

Strange Behavior

2014-06-02 Thread robertw89
Hello folks, I am not sure if it is only on my system the case that the code in http://pastebin.com/WETvqMJN misbehaves in the stated way. Can anybody reproduce it? I thought it could be that the tabs/spaces do influence it, but it doesn't care. Thank you very much for your time. Robert -- htt

Re: Strange behavior with sort()

2014-02-26 Thread Larry Hudson
On 02/26/2014 10:24 PM, ast wrote: Hello box is a list of 3 integer items If I write: box.sort() if box == [1, 2, 3]: the program works as expected. But if I write: if box.sort() == [1, 2, 3]: it doesn't work, the test always fails. Why ? Thx sort() sorts the sequence in pla

Re: Strange behavior with sort()

2014-02-26 Thread Gary Herron
On 02/26/2014 10:24 PM, ast wrote: Hello box is a list of 3 integer items If I write: box.sort() if box == [1, 2, 3]: the program works as expected. But if I write: if box.sort() == [1, 2, 3]: Most such questions can be answered by printing out the values in question and observi

Re: Strange behavior with sort()

2014-02-26 Thread ast
Thanks for the very clear explanation -- https://mail.python.org/mailman/listinfo/python-list

Re: Strange behavior with sort()

2014-02-26 Thread Marko Rauhamaa
"ast" : > if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test always fails. Why ? The list.sort() method returns None. The builtin sorted() function returns a list: if sorted(box) == [1, 2, 3]: would work. Note that the list.sort() method is often preferred because

Re: Strange behavior with sort()

2014-02-26 Thread Lele Gaifax
"ast" writes: > If I write: > >box.sort() >if box == [1, 2, 3]: > > the program works as expected. But if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test always fails. Why ? Because very often methods **dont't** return the object they are applied (self that is).

Re: Strange behavior with sort()

2014-02-26 Thread Eduardo A . Bustamante López
On Thu, Feb 27, 2014 at 07:24:24AM +0100, ast wrote: > Hello > > box is a list of 3 integer items > > If I write: > >box.sort() >if box == [1, 2, 3]: > > > the program works as expected. But if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test always fails. Wh

Re: Strange behavior with sort()

2014-02-26 Thread Frank Millman
"ast" wrote in message news:530eda1d$0$2061$426a7...@news.free.fr... > Hello > > box is a list of 3 integer items > > If I write: > >box.sort() >if box == [1, 2, 3]: > > > the program works as expected. But if I write: > >if box.sort() == [1, 2, 3]: > > it doesn't work, the test alwa

Strange behavior with sort()

2014-02-26 Thread ast
Hello box is a list of 3 integer items If I write: box.sort() if box == [1, 2, 3]: the program works as expected. But if I write: if box.sort() == [1, 2, 3]: it doesn't work, the test always fails. Why ? Thx -- https://mail.python.org/mailman/listinfo/python-list

Re: lambda - strange behavior

2013-09-20 Thread Jussi Piitulainen
Kasper Guldmann writes: > I was playing around with lambda functions, but I cannot seem to > fully grasp them. I was running the script below in Python 2.7.5, > and it doesn't do what I want it to. Are lambda functions really > supposed to work that way. How do I make it work as I intend? > > f =

Re: lambda - strange behavior

2013-09-20 Thread rusi
On Friday, September 20, 2013 8:51:20 PM UTC+5:30, Kasper Guldmann wrote: > I was playing around with lambda functions, but I cannot seem to fully grasp > them. I was running the script below in Python 2.7.5, and it doesn't do what > I want it to. Are lambda functions really supposed to work that w

Re: lambda - strange behavior

2013-09-20 Thread Rotwang
On 20/09/2013 16:21, Kasper Guldmann wrote: I was playing around with lambda functions, but I cannot seem to fully grasp them. I was running the script below in Python 2.7.5, and it doesn't do what I want it to. Are lambda functions really supposed to work that way. How do I make it work as I int

Re: lambda - strange behavior

2013-09-20 Thread Chris Angelico
On Sat, Sep 21, 2013 at 1:21 AM, Kasper Guldmann wrote: > f = [] > for n in range(5): > f.append( lambda x: x*n ) You're leaving n as a free variable here. The lambda function will happily look to an enclosing scope, so this doesn't work. But there is a neat trick you can do: f = [] for n in

lambda - strange behavior

2013-09-20 Thread Kasper Guldmann
I was playing around with lambda functions, but I cannot seem to fully grasp them. I was running the script below in Python 2.7.5, and it doesn't do what I want it to. Are lambda functions really supposed to work that way. How do I make it work as I intend? f = [] for n in range(5): f.append(

weave in 64 bit strange behavior

2013-05-14 Thread Jadhav, Alok
Hi everyone, I realize my previous post was quite unreadable, thanks to my email client. I am going to report my question here, with slight enhancements. Apologies for inconvenience caused and spamming your mailboxes. I am facing a strange problem using weave on 64 bit machine. Specifically

Re: Strange behavior for a 2D list

2013-04-18 Thread Wim R. Cardoen
Thank you all for your replies. I had the matrix concept in mind such as explained in the numpy example. Rob On Thu, Apr 18, 2013 at 3:19 PM, Wolfgang Maier < wolfgang.ma...@biologie.uni-freiburg.de> wrote: > Robrecht W. Uyttenhove gmail.com> writes: > > > > > Hello, > > I tried out the follo

Re: Strange behavior for a 2D list

2013-04-18 Thread Wolfgang Maier
Robrecht W. Uyttenhove gmail.com> writes: > > Hello, > I tried out the following code:y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)] > >>> y[[0, 1, 2, 3, 4, 5, 6],  [7, 8, 9, 10, 11, 12, 13], > [14, 15, 16, 17, 18, 19, 20],  [21, 22, 23, 24, 25, 26, 27],  [28, >

Re: Strange behavior for a 2D list

2013-04-18 Thread John Gordon
In "Robrecht W. Uyttenhove" writes: > I tried out the following code: > y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)] > >>> y > [[0, 1, 2, 3, 4, 5, 6], > [7, 8, 9, 10, 11, 12, 13], > [14, 15, 16, 17, 18, 19, 20], > [21, 22, 23, 24, 25, 26, 27], > [28, 29, 30, 31, 32, 33,

Re: Strange behavior for a 2D list

2013-04-18 Thread Peter Otten
Robrecht W. Uyttenhove wrote: > Hello, > > I tried out the following code: > y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)] y > [[0, 1, 2, 3, 4, 5, 6], > [7, 8, 9, 10, 11, 12, 13], > [14, 15, 16, 17, 18, 19, 20], > [21, 22, 23, 24, 25, 26, 27], > [28, 29, 30, 31, 32, 3

Strange behavior for a 2D list

2013-04-18 Thread Robrecht W. Uyttenhove
Hello, I tried out the following code: y=[range(0,7),range(7,14),range(14,21),range(21,28),range(28,35)] >>> y [[0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20], [21, 22, 23, 24, 25, 26, 27], [28, 29, 30, 31, 32, 33, 34]] >>> y[1:5:2][::3] [[7, 8, 9, 10, 11, 12,

Re: Strange behavior

2012-08-16 Thread Virgil Stokes
On 16-Aug-2012 19:40, Steven D'Aprano wrote: On Thu, 16 Aug 2012 13:18:59 +0200, Virgil Stokes wrote: On 15-Aug-2012 02:19, Steven D'Aprano wrote: On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote: You might find the following useful: def testFunc(startingList): xOnlyList = [];

Re: Strange behavior

2012-08-16 Thread Steven D'Aprano
On Thu, 16 Aug 2012 13:18:59 +0200, Virgil Stokes wrote: > On 15-Aug-2012 02:19, Steven D'Aprano wrote: >> On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote: >> >>> You might find the following useful: >>> >>> def testFunc(startingList): >>> xOnlyList = []; j = -1 >>> for xl in s

Re: Strange behavior

2012-08-16 Thread Virgil Stokes
x27;'' Purpose: Time four different algorithms for the same task Author: V. Stokes (v...@it.uu.se, 2012-08-16 (15:46), 2012-08-16) Refs: python-list@python.org list * Strange behavior, 14-Aug-2012 17:38, light1qu...@gmail.com * Re: Strange behavior, 14-Aug-2012 21:40, Stok

Re: Strange behavior

2012-08-16 Thread Peter Otten
Virgil Stokes wrote: >>> def testFunc(startingList): >>>xOnlyList = []; j = -1 >>>for xl in startingList: >>>if (xl[0] == 'x'): >> That's going to fail in the starting list contains an empty string. Use >> xl.startswith('x') instead. > Yes, but this was by design (tacitly assumed that startingList

Re: Strange behavior

2012-08-16 Thread Virgil Stokes
algorithm-2A slower than algorithm-2? I would be interested in seeing code that is faster than algorithm-1 --- any suggestions are welcomed. And of course, if there are any errors in my attached code please inform me of them and I will try to correct them as soon as possible. Note, some of the

Re: Strange behavior

2012-08-15 Thread Alain Ketterlin
light1qu...@gmail.com writes: > I got my answer by reading your posts and referring to: > http://docs.python.org/reference/compound_stmts.html#the-for-statement > (particularly the shaded grey box) Not that the problem is not specific to python (if you erase the current element when traversing a

Re: Strange behavior

2012-08-15 Thread Alain Ketterlin
Chris Angelico writes: > Other people have explained the problem with your code. I'll take this > example as a way of introducing you to one of Python's handy features > - it's an idea borrowed from functional languages, and is extremely > handy. It's called the "list comprehension", and can be l

Re: Strange behavior

2012-08-14 Thread Steven D'Aprano
On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote: > You might find the following useful: > > def testFunc(startingList): > xOnlyList = []; j = -1 > for xl in startingList: > if (xl[0] == 'x'): That's going to fail in the starting list contains an empty string. Use xl.s

Re: Strange behavior

2012-08-14 Thread Chris Angelico
On Wed, Aug 15, 2012 at 1:38 AM, wrote: > def testFunc(startingList): > xOnlyList = []; > for str in startingList: > if (str[0] == 'x'): > print str; > xOnlyList.append(str) > startingList.remo

Fwd: Re: Strange behavior

2012-08-14 Thread Virgil Stokes
Original Message Subject:Re: Strange behavior Date: Tue, 14 Aug 2012 21:32:16 +0200 From: Virgil Stokes To: light1qu...@gmail.com On 2012-08-14 17:38, light1qu...@gmail.com wrote: Hi, I am migrating from PHP to Python and I am slightly confused. I am

Re: Strange behavior

2012-08-14 Thread Virgil Stokes
On 2012-08-14 17:38, light1qu...@gmail.com wrote: Hi, I am migrating from PHP to Python and I am slightly confused. I am making a function that takes a startingList, finds all the strings in the list that begin with 'x', removes those strings and puts them into a xOnlyList. However if you run

Re: Strange behavior

2012-08-14 Thread Terry Reedy
On 8/14/2012 11:59 AM, Alain Ketterlin wrote: light1qu...@gmail.com writes: However if you run the code you will notice only one of the strings beginning with 'x' is removed from the startingList. def testFunc(startingList): xOnlyList = []; for str in startingList:

Re: Strange behavior

2012-08-14 Thread Alain Ketterlin
light1qu...@gmail.com writes: > However if you run the code you will notice only one of the strings > beginning with 'x' is removed from the startingList. > > def testFunc(startingList): > xOnlyList = []; > for str in startingList: > if (str[0] == 'x'): >

Strange behavior

2012-08-14 Thread light1quark
Hi, I am migrating from PHP to Python and I am slightly confused. I am making a function that takes a startingList, finds all the strings in the list that begin with 'x', removes those strings and puts them into a xOnlyList. However if you run the code you will notice only one of the strings beg

Re: Strange Behavior on Python 3 Windows Command Line

2012-02-13 Thread Waylan Limberg
On Mon, Feb 13, 2012 at 3:16 PM, Arnaud Delobelle wrote: >> Strangely it was working fine the other day. Then while debugging a >> script it suddenly started do this and now does this for every script > > How were you debugging? I think I may have been attempting to use pipes to redirect stdin an

Re: Strange Behavior on Python 3 Windows Command Line

2012-02-13 Thread Arnaud Delobelle
On 13 February 2012 19:50, waylan wrote: > When I try running any Python Script on the command line with Python > 3.2 I get this weird behavior. The cursor dances around the command > line window and nothing ever happens. Pressing Ctr+C does nothing. > When I close the window (mouse click on X in

Strange Behavior on Python 3 Windows Command Line

2012-02-13 Thread waylan
_": print("Hello, World!") In an attempt to check the exact version of Python, even this causes the strange behavior: c:\Python32\python.exe -V I'm on Windows XP if that matters. IDLE (which works fine) tells me I'm on Python 3.2.2 Any suggestions? -- http://mail.python.org/mailman/listinfo/python-list

Re: strange behavior from recursive generator

2011-09-23 Thread Phillip Feldman
I don't know how many times I stared at that code without seeing the error. Thanks so much! Phillip On Fri, Sep 23, 2011 at 1:26 PM, Arnaud Delobelle wrote: > On 23 September 2011 21:09, Dr. Phillip M. Feldman > wrote: > > > > A few weeks ago, I wrote a class that creates an iterator for solv

Re: strange behavior from recursive generator

2011-09-23 Thread Arnaud Delobelle
On 23 September 2011 21:09, Dr. Phillip M. Feldman wrote: > > A few weeks ago, I wrote a class that creates an iterator for solving the > general unlabeled-balls-in-labeled boxes occupancy problem. Chris Rebert > converted my code to a generator, which made the code cleaner, and I > subsequently s

strange behavior from recursive generator

2011-09-23 Thread Dr. Phillip M. Feldman
above, but one of them is now missing. If someone can shed light on why this is happening, I'd be grateful. Phillip http://old.nabble.com/file/p32503886/balls_in_labeled_boxes.py balls_in_labeled_boxes.py -- View this message in context: http://old.nabble.com/strange-behavior-from-recursive

Re: Multiprocessing Queue strange behavior

2010-09-16 Thread Bruno Oliveira
e code work all time. That is the main reason I believe there is a problem in the Queue code somewhere. Cheers, On Wed, Sep 15, 2010 at 5:47 PM, MRAB wrote: > On 15/09/2010 21:10, Bruno Oliveira wrote: > >> Hi list, >> >> I recently found a bug in my company&#

Re: Multiprocessing Queue strange behavior

2010-09-15 Thread MRAB
On 15/09/2010 21:10, Bruno Oliveira wrote: Hi list, I recently found a bug in my company's code because of a strange behavior using multiprocessing.Queue. The following code snippet: from multiprocessing import Queue queue = Queue() queue.put('x') print queue.get_nowa

Multiprocessing Queue strange behavior

2010-09-15 Thread Bruno Oliveira
Hi list, I recently found a bug in my company's code because of a strange behavior using multiprocessing.Queue. The following code snippet: from multiprocessing import Queue queue = Queue() queue.put('x') print queue.get_nowait() Fails with: ... File "E:\Shared\

Re: dict.fromkeys strange behavior

2009-12-07 Thread Terry Reedy
Tsviki Hirsh wrote: >>>dict.fromkeys('at',50) {'a': 50, 't': 50} This is obviously not what I wanted. Not obvious at all. It is precisely what you asked for ;-) Please read the doc: 5.8. Mapping Types — dict "classmethod fromkeys(seq[, value]) Create a new dictionary with keys from seq and

Re: dict.fromkeys strange behavior

2009-12-07 Thread Chris Rebert
On Mon, Dec 7, 2009 at 12:42 AM, Tsviki Hirsh wrote: > Dear list, > I'm trying to create a dictionary from set of keys and values using > dict.fromkeys > When I type: dict.fromkeys('a',50) > the output is: > {'a': 50} > This is fine, but when I try to set the same value to a different name key

dict.fromkeys strange behavior

2009-12-07 Thread Tsviki Hirsh
Dear list, I'm trying to create a dictionary from set of keys and values using dict.fromkeys When I type: >>>dict.fromkeys('a',50) the output is: {'a': 50} This is fine, but when I try to set the same value to a different name key: >>>dict.fromkeys('at',50) the output now is: {'a': 50, 't':

Re: Strange behavior related to value / reference

2009-10-30 Thread Aahz
In article <626f24e5-4d8e-416c-b3ed-dc56a88dc...@s21g2000prm.googlegroups.com>, Lambda wrote: > >def matrix_power(m, n): > result = m[:] > print result is m Use copy.deepcopy() -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "You could make Eskimos emigrate t

Re: Strange behavior related to value / reference

2009-10-28 Thread Dave Angel
Mark Dickinson wrote: On Oct 28, 8:24 am, Lambda wrote: Thank you! Following is my final code: Looks good, but are you sure about that word 'final'? ;-) def matrix_power(m, n): """ Raise 2x2 matrix m to nth power. """ if n =0: return [[1, 0], [0, 1]] x =atrix_power(m,

Re: Strange behavior related to value / reference

2009-10-28 Thread Peter Otten
Lambda wrote: > I defined a function to raise a 2x2 matrix to nth power: > BTW, numpy has such a function, but it doesn't support really large > number. > Does numpy has some functions that support arbitrarily large number? You can tell it to use Python instead of C integers: >>> import numpy >

Re: Strange behavior related to value / reference

2009-10-28 Thread Mark Dickinson
On Oct 28, 8:24 am, Lambda wrote: > Thank you! > Following is my final code: Looks good, but are you sure about that word 'final'? ;-) > > def matrix_power(m, n): >   """ >   Raise 2x2 matrix m to nth power. >   """ >   if n == 0: return [[1, 0], [0, 1]] > >   x = matrix_power(m, n / 2) I sugg

Re: Strange behavior related to value / reference

2009-10-28 Thread Lambda
On Oct 28, 10:40 am, Chris Rebert wrote: > On Tue, Oct 27, 2009 at 7:15 PM, Lambda wrote: > > I defined a function to raise a 2x2 matrix to nth power: > > > def matrix_power(m, n): > >  result = m[:] > > Note that this only copies the *outer* list. It does NOT copy any of > the inner, nested list

Re: Strange behavior related to value / reference

2009-10-27 Thread Terry Reedy
Lambda wrote: I defined a function to raise a 2x2 matrix to nth power: There is a much faster way to raise x to a count power n than the definitional but naive method of multipling 1 by x n times. It is based on the binary representation of n. Example: x**29 = x**(16+8+4+1) = x**16 * x**8 *

Re: Strange behavior related to value / reference

2009-10-27 Thread Chris Rebert
On Tue, Oct 27, 2009 at 7:15 PM, Lambda wrote: > I defined a function to raise a 2x2 matrix to nth power: > > def matrix_power(m, n): >  result = m[:] Note that this only copies the *outer* list. It does NOT copy any of the inner, nested lists, it just makes fresh *references* to them, which is w

Strange behavior related to value / reference

2009-10-27 Thread Lambda
I defined a function to raise a 2x2 matrix to nth power: def matrix_power(m, n): result = m[:] print result is m for i in range(n - 1): result[0][0] = result[0][0] * m[0][0] + result[0][1] * m[1][0] result[0][1] = result[0][0] * m[0][1] + result[0][1] * m[1][1] result[1][0] = re

Re: strange behavior with os.system

2009-06-17 Thread kmw
That's it. I am calling my own program and not coreutils' sort, what explains the unrequested output. Many thanks. Cheers, Kay On 16 Jun., 22:16, Piet van Oostrum wrote: > > kmw (k) wrote: > >k> Hi, > >k> I wanted to write a simple script (in 5 minutes or so) which replaces > >k> the option

Re: strange behavior with os.system

2009-06-16 Thread Piet van Oostrum
> kmw (k) wrote: >k> Hi, >k> I wanted to write a simple script (in 5 minutes or so) which replaces >k> the option '+1' given to the command 'sort' by '-k 2' and than runs >k> 'sort' with the modified argument list. After two hours I am giving up >k> and ask you for help. This is what I tried

Re: strange behavior with os.system

2009-06-16 Thread MRAB
kmw wrote: Hi, I wanted to write a simple script (in 5 minutes or so) which replaces the option '+1' given to the command 'sort' by '-k 2' and than runs 'sort' with the modified argument list. After two hours I am giving up and ask you for help. This is what I tried (please excuse the verbose co

strange behavior with os.system

2009-06-16 Thread kmw
Hi, I wanted to write a simple script (in 5 minutes or so) which replaces the option '+1' given to the command 'sort' by '-k 2' and than runs 'sort' with the modified argument list. After two hours I am giving up and ask you for help. This is what I tried (please excuse the verbose code, it is due

Re: strange behavior of math.sqrt() in new 3.0 version

2009-01-03 Thread Eric Kemp
Tim Roberts wrote: Scott David Daniels wrote: I avoid using single-letter variables except where I know the types from the name (so I use i, j, k, l, m, n as integers, s as string, and w, x, y, and z I am a little looser with (but usually float or complex). It's amazing to me that Fortran con

Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-28 Thread Steve Holden
Tim Roberts wrote: > Scott David Daniels wrote: >> I avoid using single-letter variables except where I know the types >>from the name (so I use i, j, k, l, m, n as integers, s as string, >> and w, x, y, and z I am a little looser with (but usually float or >> complex). > > It's amazing to me tha

Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-27 Thread Tim Roberts
Scott David Daniels wrote: > >I avoid using single-letter variables except where I know the types >from the name (so I use i, j, k, l, m, n as integers, s as string, >and w, x, y, and z I am a little looser with (but usually float or >complex). It's amazing to me that Fortran continues to live on

Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread John Machin
On Dec 27, 8:52 am, David Lemper wrote: > I'm a newbee trying 3.0   Please help with  math.sqrt() math.sqrt() is not the problem. > At the command line this function works correctly >       >>> import math >               n = input("enter a number > ") >               s = math.sqrt(n) >      An e

Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread Gabriel Genellina
En Fri, 26 Dec 2008 19:52:24 -0200, escribió: I'm a newbee trying 3.0 Please help with math.sqrt() At the command line this function works correctly >>> import math n = input("enter a number > ") s = math.sqrt(n) An entry of 9 or 9.0 will yield 3.0 Y

Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread Chris Rebert
On Fri, Dec 26, 2008 at 1:52 PM, wrote: > I'm a newbee trying 3.0 Please help with math.sqrt() > > At the command line this function works correctly > >>> import math > n = input("enter a number > ") raw_input() was renamed input() in Python 3.0, and it returns a *string*, n

Re: strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread Scott David Daniels
David Lemper wrote: I'm a newbee trying 3.0 Please help with math.sqrt() At the command line this function works correctly >>> import math n = input("enter a number > ") s = math.sqrt(n) An entry of 9 or 9.0 will yield 3.0 Yet the same code in a sc

strange behavior of math.sqrt() in new 3.0 version

2008-12-26 Thread David
I'm a newbee trying 3.0 Please help with math.sqrt() At the command line this function works correctly >>> import math n = input("enter a number > ") s = math.sqrt(n) An entry of 9 or 9.0 will yield 3.0 Yet the same code in a script gives an error mess

Re: pretty strange behavior of "strip"

2008-12-08 Thread Tim Roberts
Guy Doune <[EMAIL PROTECTED]> wrote: >Ok, didn't show the whole problem... > >I will read the doc anyway, but why "questions.html" keep it "t"?? > > >>> test=['03.html', '06.html', 'questions.html', '04.html', >'toc.html', '01.html', '05.html', '07.html', '02.html', '08.html'] > >>> test[4] >'toc

Re: pretty strange behavior of "strip" FORGET THE LAST ONE

2008-12-05 Thread Scott David Daniels
Guy Doune wrote: Guy Doune a écrit : Ok, didn't show the whole problem... I will read the doc anyway, but why "questions.html" keep it "t"?? >>> test=['03.html', '06.html', 'questions.html', '04.html', 'toc.html', '01.html', '05.html', '07.html', '02.html', '08.html'] >>> test[4] 'toc.html

Re: pretty strange behavior of "strip"

2008-12-05 Thread rdmurray
On Fri, 5 Dec 2008 at 07:54, Mark Tolonen wrote: > > import re > > re.split('[,.]','blah,blah.blah') ['blah', 'blah', 'blah'] Thank you. Somehow it never occurred to me that I could use that kind of pattern that way. I guess my brain just doesn't think in regexes very well :) --RDM -- htt

Re: pretty strange behavior of "strip"

2008-12-05 Thread MRAB
[EMAIL PROTECTED] wrote: On Thu, 4 Dec 2008 at 20:54, Terry Reedy wrote: 'toc.html' > > > test[4].strip('.html') 'oc' Can't figure out what is going on, really. What I can't figure out is why, when people cannot figure out what is going on with a function (or methods in this case), they

Re: pretty strange behavior of "strip"

2008-12-05 Thread Mark Tolonen
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On Thu, 4 Dec 2008 at 20:54, Terry Reedy wrote: [snip] I have often wished that in 'split' I could specify a _set_ of characters on which the string would be split, in the same way the default list of whitespace characters causes a s

Re: pretty strange behavior of "strip"

2008-12-05 Thread rdmurray
On Thu, 4 Dec 2008 at 20:54, Terry Reedy wrote: 'toc.html' > > > test[4].strip('.html') 'oc' Can't figure out what is going on, really. What I can't figure out is why, when people cannot figure out what is going on with a function (or methods in this case), they do not look it up the doc.

Re: pretty strange behavior of "strip"

2008-12-05 Thread Mark Tolonen
"Guy Doune" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Ok, didn't show the whole problem... I will read the doc anyway, but why "questions.html" keep it "t"?? >>> test=['03.html', '06.html', 'questions.html', '04.html', 'toc.html', '01.html', '05.html', '07.html', '02.html'

Re: pretty strange behavior of "strip" FORGET THE LAST ONE

2008-12-05 Thread Guy Doune
Guy Doune a écrit : Ok, didn't show the whole problem... I will read the doc anyway, but why "questions.html" keep it "t"?? >>> test=['03.html', '06.html', 'questions.html', '04.html', 'toc.html', '01.html', '05.html', '07.html', '02.html', '08.html'] >>> test[4] 'toc.html' >>> test[4].stri

Re: pretty strange behavior of "strip"

2008-12-05 Thread Guy Doune
Ok, didn't show the whole problem... I will read the doc anyway, but why "questions.html" keep it "t"?? >>> test=['03.html', '06.html', 'questions.html', '04.html', 'toc.html', '01.html', '05.html', '07.html', '02.html', '08.html'] >>> test[4] 'toc.html' >>> test[4].strip('.html') 'oc' >>> tes

Re: pretty strange behavior of "strip"

2008-12-04 Thread Terry Reedy
Guy Doune wrote: Hi everybody, Could it be a bug? Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> test=['03.html', '06.html', 'questions.html', '04.html', 'toc.html',

Re: pretty strange behavior of "strip"

2008-12-04 Thread MRAB
Guy Doune wrote: Hi everybody, Could it be a bug? Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> test=['03.html', '06.html', 'questions.html', '04.html', 'toc.html',

Re: pretty strange behavior of "strip"

2008-12-04 Thread James Mills
On Fri, Dec 5, 2008 at 9:35 AM, Guy Doune <[EMAIL PROTECTED]> wrote: test=['03.html', '06.html', 'questions.html', '04.html', 'toc.html', '01.html', '05.html', '07.html', '02.html', '08.html'] test > ['03.html', '06.html', 'questions.html', '04.html', 'toc.html', '01.html', > '05.htm

Re: pretty strange behavior of "strip"

2008-12-04 Thread Ned Deily
In article <[EMAIL PROTECTED]>, Guy Doune <[EMAIL PROTECTED]> wrote: > Could it be a bug? > > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> test=['03.html', '06.h

Re: pretty strange behavior of "strip"

2008-12-04 Thread Robert Kern
Guy Doune wrote: Hi everybody, Could it be a bug? Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> test=['03.html', '06.html', 'questions.html', '04.html', 'toc.html',

pretty strange behavior of "strip"

2008-12-04 Thread Guy Doune
Hi everybody, Could it be a bug? Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> test=['03.html', '06.html', 'questions.html', '04.html', 'toc.html', '01.html', '05.html

Re: initialized list: strange behavior

2008-11-25 Thread Arnaud Delobelle
Steve Holden <[EMAIL PROTECTED]> writes: > Arnaud Delobelle wrote: >> Jason Scheirer <[EMAIL PROTECTED]> writes: >>> Python is pass-by-reference, not pass-by-value. >> >> It's certainly not pass-by-reference, nor is it pass-by-value IMHO. >> > Since no lists are being passed as arguments in thes

Re: initialized list: strange behavior

2008-11-25 Thread alexander . genkin
The issue is exhausted in Python Library Reference, Chapter 3.6, so I should apologize for initial posting. All comments were helpful, though Arnaud and Steve are right that pass-by-anything is off the point. Thanks All! -- http://mail.python.org/mailman/listinfo/python-list

Re: initialized list: strange behavior

2008-11-25 Thread Steve Holden
Arnaud Delobelle wrote: > Jason Scheirer <[EMAIL PROTECTED]> writes: > >> On Nov 24, 10:34 pm, [EMAIL PROTECTED] wrote: >>> Hi Python experts! Please explain this behavior: >>> >> nn=3*[[]] >> nn >>> [[], [], []] >> mm=[[],[],[]] >> mm >>> [[], [], []] >>> >>> Up till now, 'mm' and

Re: initialized list: strange behavior

2008-11-25 Thread Benjamin Kaplan
On Tue, Nov 25, 2008 at 9:23 AM, Arnaud Delobelle <[EMAIL PROTECTED]>wrote: > Jason Scheirer <[EMAIL PROTECTED]> writes: > > > On Nov 24, 10:34 pm, [EMAIL PROTECTED] wrote: > >> Hi Python experts! Please explain this behavior: > >> > >> >>> nn=3*[[]] > >> >>> nn > >> [[], [], []] > >> >>> mm=[[],[

  1   2   >