Re: [Tutor] Size of Python Console
Title: Signature.html Well, while I'm waiting for the moderator approval* on a message I sent 3 hours ago concerning my inability to create a shortcut with properties, I'll mention I later did find away to set the size. One just brings up the program and sets the width-height using the properties option in the upper-left corner. Next one saves them when exiting. That does it. No shortcut needed. * I had included an image to show the shortcut properties dialog. Alan Gauld wrote: "Wayne Watson" <[EMAIL PROTECTED]> wrote is there a way I can begin with something other than the default? It's an inconvenience to the user to do this every time. Create a shortcut that specifies the window parameters. (use properties and adjust the font and layout tab settings) Distribute the shortcut with the program. HTH, -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) "Dreaming permits each and every one of us to be quietly insane every night of our lives." -- William Dement Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Size of Python Console
"Wayne Watson" <[EMAIL PROTECTED]> wrote find away to set the size. One just brings up the program and sets the width-height using the properties option in the upper-left corner. Next one saves them when exiting. That only works on your PC, any other user needs to do the same thing. Creating a shortcut means you can redistribute it and the recipient gets whatever settings you set. The shortcut needs to be to python.exe not the program file. Thus if your script is C:\MYSCRIPT\FOO.PY and Python is in C:\Python25\python25.exe you need a shortcut to C:\Python25\python25.exe C:\MYSCRIPT\FOO.PY That should then have all the usual console properties. If you build an installer to install the program at some other location then you can write a WSH script to create a shortcut programmatically at install time, but thats more tricky. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] faulty code (maths)
On Sun, Nov 23, 2008 at 6:37 AM, David <[EMAIL PROTECTED]> wrote: > I am trying to solve exercise 1.18 ("Why does the following program not work > correctly?"), but I don't find the mistake: why does the line > > q = sqrt(b*b - 4*a*c) > > cause an error? I was playing around with the code, but got nowhere. Did you get an error? What was it? Please show the entire error message, including the stack trace, when you have a question about an error. What is the value of (b*b - 4*a*c) ? Does that give you a hint? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] faulty code (maths)
Hello everybody, I recently came across a book by Prof. Langtangen: Indroduction to Computer Programming: http://folk.uio.no/hpl/INF1100/INF1100-ebook-Aug08.pdf I am trying to solve exercise 1.18 ("Why does the following program not work correctly?"), but I don't find the mistake: why does the line q = sqrt(b*b - 4*a*c) cause an error? I was playing around with the code, but got nowhere. Here the entire code: a = 2; b = 1; c = 2 from math import sqrt q = sqrt(b*b - 4*a*c) x1 = (-b + q)/2*a x2 = (-b - q)/2*a print x1, x2 Many thanks for a pointer! David ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Regular expression oddity
bob gailer a écrit : Emmanuel Ruellan wrote: Hi tutors! While trying to write a regular expression that would split a string the way I want, I noticed a behaviour I didn't expect. re.findall('.?', 'some text') ['s', 'o', 'm', 'e', ' ', 't', 'e', 'x', 't', ''] Where does the last string, the empty one, come from? I find this behaviour rather annoying: I'm getting one group too many. The ? means 0 or 1 occurrence. I think re is matching the null string at the end. Drop the ? and you'll get what you want. Of course you can get the same thing using list('some text') at lower cost. I find this fully consistent, for your regex means matching * either any char * or no char at all Logically, you first get n chars, then one 'nothing'. Only after that will parsing be stopped because of end of string. Maybe clearer: print re.findall('.?', '') ==> [''] print re.findall('.', '') ==> [] denis ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] faulty code (maths)
Hello Kent, yes, the error message - sorry: When I just run line 3, I get: In [7]: q = sqrt(b*b - 4*a*c) ...: --- Traceback (most recent call last) /home/david/Documents/Python/myCode/Langtangen/py1st/ in () : math domain error In [8]: Ah! It's a not a Python, but a math error - I am trying to take a root of a negative number! Thanks for the help! David Kent Johnson wrote: On Sun, Nov 23, 2008 at 6:37 AM, David <[EMAIL PROTECTED]> wrote: I am trying to solve exercise 1.18 ("Why does the following program not work correctly?"), but I don't find the mistake: why does the line q = sqrt(b*b - 4*a*c) cause an error? I was playing around with the code, but got nowhere. Did you get an error? What was it? Please show the entire error message, including the stack trace, when you have a question about an error. What is the value of (b*b - 4*a*c) ? Does that give you a hint? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] faulty code (maths)
hi! On Sun, Nov 23, 2008 at 5:07 PM, David <[EMAIL PROTECTED]> wrote: > Hello everybody, > > I recently came across a book by Prof. Langtangen: Indroduction to Computer > Programming: http://folk.uio.no/hpl/INF1100/INF1100-ebook-Aug08.pdf > > I am trying to solve exercise 1.18 ("Why does the following program not work > correctly?"), but I don't find the mistake: why does the line > > q = sqrt(b*b - 4*a*c) problem here is that the method sqrt doesn't accepts -negative numbers which in this case is the outcome of the expression above. to rectify that u can use the following q = sqrt(math.fabs(b*b - 4*a*c)) basically convert the negative number to absolute number, rest of the stuff will work. > > cause an error? I was playing around with the code, but got nowhere. > > Here the entire code: > > a = 2; b = 1; c = 2 > from math import sqrt > q = sqrt(b*b - 4*a*c) > x1 = (-b + q)/2*a > x2 = (-b - q)/2*a > print x1, x2 > > > Many thanks for a pointer! > > David > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- Regards, Arun Tomar blog: http://linuxguy.in ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Size of Python Console
Title: Signature.html This then would seem to what I need in my case for the shortcut: c:\python25\python25.exe C:\Sandia_Meteors\New_Sentinel_Development\Development\Utility_Dev\SU_DateTimeAdjust.py (It's really a single line, but wrapped here and there is a space between to two path items.) but Win says something is wrong with my path for c:\python25\python25.exe. Even if that works, I don't think a user is likely to install it in a folder like the one I have above. I'm probably better off specifying that the user should set up his size as I've done. Alan Gauld wrote: "Wayne Watson" <[EMAIL PROTECTED]> wrote find away to set the size. One just brings up the program and sets the width-height using the properties option in the upper-left corner. Next one saves them when exiting. That only works on your PC, any other user needs to do the same thing. Creating a shortcut means you can redistribute it and the recipient gets whatever settings you set. The shortcut needs to be to python.exe not the program file. Thus if your script is C:\MYSCRIPT\FOO.PY and Python is in C:\Python25\python25.exe you need a shortcut to C:\Python25\python25.exe C:\MYSCRIPT\FOO.PY That should then have all the usual console properties. If you build an installer to install the program at some other location then you can write a WSH script to create a shortcut programmatically at install time, but thats more tricky. HTH, -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) "Dreaming permits each and every one of us to be quietly insane every night of our lives." -- William Dement Web Page:___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] faulty code (maths)
Hello, yes, that did the trick, though I had to change the "from math import ~" line to "import math". I also changed in line three the sqrt() function to math.sqrt(). Otherwise there would be complaints: : name 'sqrt' is not defined WARNING: Failure executing file: The working code: a = 2; b = 1; c = 2 import math q = math.sqrt(math.fabs(b*b - 4*a*c)) x1 = (-b + q)/2*a x2 = (-b - q)/2*a print x1, x2 Thanks a lot! David Arun Tomar wrote: hi! On Sun, Nov 23, 2008 at 5:07 PM, David <[EMAIL PROTECTED]> wrote: Hello everybody, I recently came across a book by Prof. Langtangen: Indroduction to Computer Programming: http://folk.uio.no/hpl/INF1100/INF1100-ebook-Aug08.pdf I am trying to solve exercise 1.18 ("Why does the following program not work correctly?"), but I don't find the mistake: why does the line q = sqrt(b*b - 4*a*c) problem here is that the method sqrt doesn't accepts -negative numbers which in this case is the outcome of the expression above. to rectify that u can use the following q = sqrt(math.fabs(b*b - 4*a*c)) basically convert the negative number to absolute number, rest of the stuff will work. cause an error? I was playing around with the code, but got nowhere. Here the entire code: a = 2; b = 1; c = 2 from math import sqrt q = sqrt(b*b - 4*a*c) x1 = (-b + q)/2*a x2 = (-b - q)/2*a print x1, x2 Many thanks for a pointer! David ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] faulty code (maths)
On Sun, Nov 23, 2008 at 9:44 AM, David <[EMAIL PROTECTED]> wrote: > The working code: > > a = 2; b = 1; c = 2 > import math > q = math.sqrt(math.fabs(b*b - 4*a*c)) > x1 = (-b + q)/2*a > x2 = (-b - q)/2*a > print x1, x2 Working in the sense of "completes without an error message and prints a result", anyway. Not working in the sense of "gives the correct answer". Using your code above gives In [17]: print x1, x2 2.87298334621 -4.87298334621 In [18]: a*x1*x1 + b*x1 + c Out[18]: 21.381049961377752 which should be 0. Some quadratic equations do not have a solution in the real numbers, only in complex numbers. You might want to look at cmath.sqrt() which will take the square root of a negative number, giving a complex result. Using the above values for a, b, c: In [19]: import cmath In [20]: cmath.sqrt(b*b - 4*a*c) Out[20]: 3.872983346207417j Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Re: class/type methods/functions]
Hey Spir! Maybe you should read the book "Design Patterns" from Erich Gamma and the rest of "the gang of four". (A.T.Hofkamp, mentioning its terminology, got me thinking.) You ask complicated questions that normal newbies don't ask, so you should maybe read an advanced book. The book's idea is: There are certain problems in programming that appear frequently (called "design patterns" in the book). These problems can be categorized, and there exist well working solutions for these probelms. Additionally, when programmers adopt a common terminology for those problems, it will be more easy to talk about computer programs. One of those patterns is "factory" which A.T mentioned. Kind regards, Eike. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] faulty code (maths)
On Sun, 23 Nov 2008 19:39:54 +0530, Arun Tomar wrote: > hi! > > > On Sun, Nov 23, 2008 at 5:07 PM, David <[EMAIL PROTECTED]> wrote: >> Hello everybody, >> >> I recently came across a book by Prof. Langtangen: Indroduction to >> Computer Programming: >> http://folk.uio.no/hpl/INF1100/INF1100-ebook-Aug08.pdf >> >> I am trying to solve exercise 1.18 ("Why does the following program not >> work correctly?"), but I don't find the mistake: why does the line >> >> q = sqrt(b*b - 4*a*c) > > problem here is that the method sqrt doesn't accepts -negative numbers > which in this case is the outcome of the expression above. to rectify > that u can use the following > > q = sqrt(math.fabs(b*b - 4*a*c)) > > basically convert the negative number to absolute number, rest of the > stuff will work. > An alternative solution would be to use the sqrt from cmath module, which does handle negative root by outputting complex number: a = 2; b = 1; c = 2 from cmath import sqrt q = sqrt(b*b - 4*a*c) x1 = (-b + q)/2*a x2 = (-b - q)/2*a print x1, x2 output: (-1+3.87298334621j) (-1-3.87298334621j) This would be the most mathematically correct solution without changing what the program _seems_ to meant. However, what the program _actually_ meant, I don't know. Python's math module does not handle complex numbers because many day-to- day scripters doesn't have strong mathematical background to handle complex number, or they simply doesn't need to use complex number, or sometimes complex number solution is -- for their particular problem -- an indication that something is not right. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor