Re: [Tutor] Finding error from os.system(cmd)

2011-05-31 Thread Kann Vearasilp
Hi All, I apologize for now being specific enough. The testing environment was actually "django ver. 1.2" which is a CMS based on python codes; so, I figured it's python related and want to post my question here as well. Anyway, Here is a more detail about what I have facing now. The java script

Re: [Tutor] Finding error from os.system(cmd)

2011-05-31 Thread Alan Gauld
"Kann Vearasilp" wrote I tested the complete java command via terminal and it worked fine. The PNG image was created correctly. So as your user account with your local environment set up, it worked. I tested the python package using python shell ... and the PNG image was created And in y

[Tutor] Nicer error message

2011-05-31 Thread Válas Péter
Hi, my code is (Python 2.5): class SomeError(Error): """Uff!""" raise SomeError, "blahblah" Screen result: __main__.SomeError: "blahblah" How can I make "__main__" disappear from output? Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe

Re: [Tutor] Nicer error message

2011-05-31 Thread Válas Péter
2011. május 31. 16:39 Japhy Bartlett írta, : > You could write directly to sys.stderr instead of raising an error. > > If other programmers have to work with your code, they'll probably > find this _incredibly_ annoying. > You mean there is no way to write it nicely? Or are error messages not int

Re: [Tutor] Nicer error message

2011-05-31 Thread Steven D'Aprano
Válas Péter wrote: Hi, my code is (Python 2.5): class SomeError(Error): """Uff!""" raise SomeError, "blahblah" Screen result: __main__.SomeError: "blahblah" I get Traceback (most recent call last): File "", line 1, in NameError: name 'Error' is not defined How can I make "__main__

Re: [Tutor] Nicer error message

2011-05-31 Thread Steven D'Aprano
Válas Péter wrote: 2011. május 31. 16:39 Japhy Bartlett írta, : You could write directly to sys.stderr instead of raising an error. If other programmers have to work with your code, they'll probably find this _incredibly_ annoying. You mean there is no way to write it nicely? Or are error m

Re: [Tutor] Nicer error message

2011-05-31 Thread Válas Péter
2011/5/31 Steven D'Aprano > You should inherit exceptions from the Exception class: > OK, as a matter of fact, it was not Error, it was the own error class of a bigger program, I just wanted to substitute it with the root object by heart, and I was wrong, sorry. > Only built-in exceptions don't

Re: [Tutor] Nicer error message

2011-05-31 Thread Válas Péter
2011/5/31 Steven D'Aprano > > Tracebacks are intended to be *useful*, not "nice". Nobody ever said, "Oh > look, what a pretty error message! OK, I just saw how nice builtin exceptions were, and went envying them. :-) ___ Tutor maillist - Tutor@pytho

Re: [Tutor] Nicer error message

2011-05-31 Thread Alan Gauld
"Válas Péter" wrote You could write directly to sys.stderr instead of raising an error. Or better still do both. But only at the top level of your program. > If other programmers have to work with your code, they'll probably > find this _incredibly_ annoying. You mean there is no way to wr

[Tutor] checking if a variable is an integer?

2011-05-31 Thread Hans Barkei
I want to make a program that finds all the prime numbers up to a number inputed by the user. I want to know if it is an integer because that will tell me if it is divisible by that number or not. * -Hans-* ___ Tutor

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Joel Goldstick
On Tue, May 31, 2011 at 5:23 PM, Hans Barkei wrote: > I want to make a program that finds all the prime numbers up to a number > inputed by the user. > I want to know if it is an integer because that will tell me if it is > divisible by that number or not. > * -

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Hugo Arts
On Tue, May 31, 2011 at 11:30 PM, Joel Goldstick wrote: > > > http://stackoverflow.com/questions/1265665/python-check-if-a-string-represents-an-int-without-using-try-except > > def RepresentsInt(s): > >     try: >         int(s) > >         return True >     except ValueError: > >         return F

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Rachel-Mikel ArceJaeger
Isn't one of the unsolved millenium prize problems one that includes the ability to find all of the prime numbers? I'm not sure if your program is possible if the input number is large. But to check if a number x is an int, just do this: x == int(x) Rachel On May 31, 2011, at 2:23 PM, Hans

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Rachel-Mikel ArceJaeger
Isn't one of the unsolved millenium prize problems one that includes the ability to find all of the prime numbers? I'm not sure if your program is possible if the input number is large. But to check if a number x is an int, just do this: x == int(x) Rachel On Tue, May 31, 2011 at 2:38 PM, Hug

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Rachel-Mikel ArceJaeger
Isn't one of the unsolved millenium prize problems one that includes the ability to find all of the prime numbers? I'm not sure if your program is possible if the input number is large. But to check if a number x is an int, just do this: x == int(x) Rachel On May 31, 2011, at 2:23 PM, Hans

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Peter Lavelle
I think you could also use the type() function. See example below: if type(yourvar) == int: #Do stuff here if it is an integer else: #Do something here if it is not an integer Regards Peter On 31/05/11 22:23, Hans Barkei wrote: I want to make a program that finds all the prime numb

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Hugo Arts
On Tue, May 31, 2011 at 11:36 PM, Rachel-Mikel ArceJaeger wrote: > Isn't one of the unsolved millenium prize problems one that includes the > ability to find all of the prime numbers? I'm not sure if your program is > possible if the input number is large. > But to check if a number x is an int, j

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread James Reynolds
If prime numbers were finite (an ability to find *all *prime numbers) that would cause havoc with the fundamental theorem of arithmetic ;) On Tue, May 31, 2011 at 5:40 PM, Rachel-Mikel ArceJaeger < arcejae...@gmail.com> wrote: > Isn't one of the unsolved millenium prize problems one that includes

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Noah Hall
On Tue, May 31, 2011 at 10:36 PM, Rachel-Mikel ArceJaeger wrote: > Isn't one of the unsolved millenium prize problems one that includes the > ability to find all of the prime numbers? I'm not sure if your program is > possible if the input number is large. > But to check if a number x is an int, j

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Marilyn Davis
You'll like: >>> isinstance(1, int) True >>> isinstance(1.5, int) False There are infinite primes. Proofs abound on the Internet. But, that's not the problem. Yes, the problem is possible for any finite number. And it's a nice little practice problem. Remember that you can skip the testing f

[Tutor] checking if a variable is an integer?

2011-05-31 Thread Hugo Arts
-- Forwarded message -- From: Hugo Arts Date: Wed, Jun 1, 2011 at 12:01 AM Subject: Re: [Tutor] checking if a variable is an integer? To: Peter Lavelle On Tue, May 31, 2011 at 11:46 PM, Peter Lavelle wrote: > I think you could also use the type() function. See example below: >

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Steven D'Aprano
Peter Lavelle wrote: I think you could also use the type() function. See example below: if type(yourvar) == int: #Do stuff here if it is an integer You can do that, but that will miss out on subclasses of int. It is better to use isinstance(yourvar, int) which will accept an int, or a s

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Steven D'Aprano
Rachel-Mikel ArceJaeger wrote: Isn't one of the unsolved millenium prize problems one that includes the ability to find all of the prime numbers? I'm not sure if your program is possible if the input number is large. Finding all the prime numbers isn't hard. Well, it's not hard if you have a

Re: [Tutor] checking if a variable is an integer?

2011-05-31 Thread Alan Gauld
"Hans Barkei" wrote I want to make a program that finds all the prime numbers up to a number inputed by the user. I want to know if it is an integer because that will tell me if it is divisible by that number or not. I assume you meant the result of the division? If so it is better to us

[Tutor] Strategy to read a redirecting html page

2011-05-31 Thread Karim
Hello, I am having issue in reading a html page which is redirected to a new page. I get the first warning/error message page and not the redirection one. Should I request a second time the same url page or Should I loop forever until the page content is the correct (by parsing it) one? Do you

Re: [Tutor] Strategy to read a redirecting html page

2011-05-31 Thread Hugo Arts
On Wed, Jun 1, 2011 at 1:00 AM, Karim wrote: > > Hello, > > I am having issue in reading a html page which is redirected to a new page. > I get the first warning/error message page and not the redirection one. > Should I request a second time the same url page or Should I loop forever > until the

Re: [Tutor] Strategy to read a redirecting html page

2011-05-31 Thread ian douglas
On 05/31/2011 04:34 PM, Hugo Arts wrote: On Wed, Jun 1, 2011 at 1:00 AM, Karim wrote: Hello, I am having issue in reading a html page which is redirected to a new page. I get the first warning/error message page and not the redirection one. Should I request a second time the same url page or

Re: [Tutor] Strategy to read a redirecting html page

2011-05-31 Thread Alexandre Conrad
Hi Karim, When you hit the page and you get an HTTP redirect code back (say, 302), you will need to make another call to the URL specified in the "Location" parameter in the response headers. Then you retrieve that new page and you can check you got an acceptable HTTP response code (such as 200) a

[Tutor] __init__.py question

2011-05-31 Thread Marilyn Davis
I don't really understand why __init__.py is necessary -- except that it makes the packaging scheme work. The Python Manual by Guido van Rossum and Fred L. Drake says: ... this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur