Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54785 > unrolled thread

Handling 3 operands in an expression without raising an exception

Started byΝίκος <nikos.gr33k@gmail.com>
First post2013-09-26 10:26 +0300
Last post2013-09-29 13:32 -0400
Articles 20 on this page of 107 — 25 participants

Back to article view | Back to comp.lang.python


Contents

  Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 10:26 +0300
    Re: Handling 3 operands in an expression without raising an exception Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-09-26 10:48 +0300
      Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 10:51 +0300
        Re: Handling 3 operands in an expression without raising an exception Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-09-26 11:12 +0300
          Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 11:39 +0300
            Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 11:46 +0300
              Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 11:50 +0300
                Re: Handling 3 operands in an expression without raising an exception Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-09-26 12:20 +0300
            Re: Handling 3 operands in an expression without raising an exception Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-09-26 12:04 +0300
              Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 12:45 +0300
            Re: Handling 3 operands in an expression without raising an exception Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-26 11:07 +0200
              Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 12:31 +0300
                Re: Handling 3 operands in an expression without raising an exception Maarten <maarten.sneep@knmi.nl> - 2013-09-26 02:52 -0700
                Re: Handling 3 operands in an expression without raising an exception Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-26 12:01 +0200
                Re: Handling 3 operands in an expression without raising an exception "James Harris" <james.harris.1@gmail.com> - 2013-09-26 11:53 +0100
            Re: Handling 3 operands in an expression without raising an exception alex23 <wuwei23@gmail.com> - 2013-09-27 10:05 +1000
          Re: Handling 3 operands in an expression without raising an exception Chris Angelico <rosuav@gmail.com> - 2013-09-26 18:41 +1000
          Re: Handling 3 operands in an expression without raising an exception Tim Golden <mail@timgolden.me.uk> - 2013-09-26 09:47 +0100
    Re: Handling 3 operands in an expression without raising an exception Nobody <nobody@nowhere.com> - 2013-09-26 09:55 +0100
      Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 12:56 +0300
        Re: Handling 3 operands in an expression without raising an exception Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-26 12:12 +0200
          Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 13:18 +0300
            Re: Handling 3 operands in an expression without raising an exception Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-26 12:41 +0200
              Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 13:51 +0300
                Re: Handling 3 operands in an expression without raising an exception Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-26 13:07 +0200
                  Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 14:25 +0300
                    Re: Handling 3 operands in an expression without raising an exception Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-26 13:47 +0200
                    Re: Handling 3 operands in an expression without raising an exception Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-26 14:42 +0000
                Re: Handling 3 operands in an expression without raising an exception Dave Angel <davea@davea.name> - 2013-09-26 11:24 +0000
                  Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 15:39 +0300
                    Re: Handling 3 operands in an expression without raising an exception Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-26 14:53 +0200
                      Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 16:34 +0300
                        Re: Handling 3 operands in an expression without raising an exception Dave Angel <davea@davea.name> - 2013-09-26 14:22 +0000
                          Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-26 19:58 +0300
                            Re: Handling 3 operands in an expression without raising an exception Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-26 20:16 +0000
                              Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-27 01:14 +0300
                                Re: Handling 3 operands in an expression without raising an exception Dave Angel <davea@davea.name> - 2013-09-26 22:55 +0000
                                  Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-27 12:19 +0300
                                    Re: Handling 3 operands in an expression without raising an exception Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-27 09:26 +0000
                                      Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-27 13:04 +0300
                                    Re: Handling 3 operands in an expression without raising an exception Dave Angel <davea@davea.name> - 2013-09-27 10:43 +0000
                                      Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-27 14:15 +0300
                                        Re: Handling 3 operands in an expression without raising an exception Dave Angel <davea@davea.name> - 2013-09-27 12:17 +0000
                                          Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-27 15:51 +0300
                                      Re: Handling 3 operands in an expression without raising an exception rusi <rustompmody@gmail.com> - 2013-09-28 10:29 -0700
                                    Re: Handling 3 operands in an expression without raising an exception Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-27 15:16 +0000
                                      Re: Handling 3 operands in an expression without raising an exception Grant Edwards <invalid@invalid.invalid> - 2013-09-27 16:04 +0000
                                      Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-27 19:47 +0300
                                        Re: Handling 3 operands in an expression without raising an exception Neil Cerutti <neilc@norwich.edu> - 2013-09-27 16:56 +0000
                                        Re: Handling 3 operands in an expression without raising an exception Grant Edwards <invalid@invalid.invalid> - 2013-09-27 17:00 +0000
                                          Re: Handling 3 operands in an expression without raising an exception Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-27 13:19 -0400
                                          Re: Handling 3 operands in an expression without raising an exception Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-09-27 18:32 +0100
                                            Re: Handling 3 operands in an expression without raising an exception Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-27 18:49 +0000
                                              Re: Handling 3 operands in an expression without raising an exception Grant Edwards <invalid@invalid.invalid> - 2013-09-27 18:54 +0000
                                                Re: Handling 3 operands in an expression without raising an exception Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-27 15:21 -0400
                                          Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-28 01:06 +0300
                                            Re: Handling 3 operands in an expression without raising an exception Dave Angel <davea@davea.name> - 2013-09-27 22:26 +0000
                                              Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-28 12:33 +0300
                                                Re: Handling 3 operands in an expression without raising an exception Chris Angelico <rosuav@gmail.com> - 2013-09-28 20:19 +1000
                                                  Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-28 16:23 +0300
                                                    Re: Handling 3 operands in an expression without raising an exception Andreas Perstinger <andipersti@gmail.com> - 2013-09-28 17:02 +0200
                                                      Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-28 19:14 +0300
                                                        Re: Handling 3 operands in an expression without raising an exception Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-09-28 18:53 +0100
                                                        Re: Handling 3 operands in an expression without raising an exception Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-28 14:21 -0400
                                                        Re: Handling 3 operands in an expression without raising an exception Zero Piraeus <z@etiol.net> - 2013-09-28 15:38 -0300
                                                          Re: Handling 3 operands in an expression without raising an exception Neil Cerutti <neilc@norwich.edu> - 2013-09-30 11:32 +0000
                                                            Re: Handling 3 operands in an expression without raising an exception Chris Angelico <rosuav@gmail.com> - 2013-09-30 21:53 +1000
                                                              Re: Handling 3 operands in an expression without raising an exception Neil Cerutti <neilc@norwich.edu> - 2013-09-30 12:56 +0000
                                                        Re: Handling 3 operands in an expression without raising an exception Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-09-28 19:45 +0100
                                                          Re: Handling 3 operands in an expression without raising an exception Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-28 19:20 +0000
                                                        Re: Handling 3 operands in an expression without raising an exception Chris Angelico <rosuav@gmail.com> - 2013-09-29 09:04 +1000
                                                          Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-29 10:35 +0300
                                                            Re: Handling 3 operands in an expression without raising an exception Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-09-29 12:35 +0300
                                                              Re: Handling 3 operands in an expression without raising an exception Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-29 09:48 +0000
                                                                Re: Handling 3 operands in an expression without raising an exception Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-09-29 14:04 +0300
                                                                  Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-29 14:14 +0300
                                                                    Re: Handling 3 operands in an expression without raising an exception Dave Angel <davea@davea.name> - 2013-09-29 11:27 +0000
                                                                      Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-29 14:34 +0300
                                                                        Re: Handling 3 operands in an expression without raising an exception Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-29 21:15 +0000
                                                                          Re: Handling 3 operands in an expression without raising an exception Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-09-30 16:07 +0100
                                                                    Re: Handling 3 operands in an expression without raising an exception Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-09-29 15:24 +0300
                                                            Re: Handling 3 operands in an expression without raising an exception Dave Angel <davea@davea.name> - 2013-09-29 09:50 +0000
                                                              Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-29 13:17 +0300
                                                                Re: Handling 3 operands in an expression without raising an exception Dave Angel <davea@davea.name> - 2013-09-29 10:57 +0000
                                                                Re: Handling 3 operands in an expression without raising an exception Chris Angelico <rosuav@gmail.com> - 2013-09-29 23:58 +1000
                                                                Re: Handling 3 operands in an expression without raising an exception Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-29 21:01 +0000
                                                              Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-29 14:06 +0300
                                                            Re: Handling 3 operands in an expression without raising an exception Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-29 12:48 +0200
                                                              Re: Handling 3 operands in an expression without raising an exception Piet van Oostrum <piet@vanoostrum.org> - 2013-09-29 13:24 -0400
                                                                Re: Handling 3 operands in an expression without raising an exception MRAB <python@mrabarnett.plus.com> - 2013-09-29 18:44 +0100
                                                                Re: Handling 3 operands in an expression without raising an exception Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-29 14:45 -0400
                                                                Re: Handling 3 operands in an expression without raising an exception Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-09-30 16:05 +0100
                                                        Re: Handling 3 operands in an expression without raising an exception Ben Finney <ben+python@benfinney.id.au> - 2013-09-29 11:35 +1000
                                            Re: Handling 3 operands in an expression without raising an exception Chris Angelico <rosuav@gmail.com> - 2013-09-28 11:59 +1000
                                              Re: Handling 3 operands in an expression without raising an exception Νίκος <nikos.gr33k@gmail.com> - 2013-09-28 12:14 +0300
                                            Re: Handling 3 operands in an expression without raising an exception Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-09-28 15:53 +0200
                                            Re: Handling 3 operands in an expression without raising an exception Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-28 12:15 -0400
                                    Re: Handling 3 operands in an expression without raising an exception Robert Kern <robert.kern@gmail.com> - 2013-09-28 12:18 +0100
                                    Re: Handling 3 operands in an expression without raising an exception giacomo boffi <pecore@pascolo.net> - 2013-09-29 17:28 +0200
                                      Re: Handling 3 operands in an expression without raising an exception Joel Goldstick <joel.goldstick@gmail.com> - 2013-09-29 12:07 -0400
                                        Re: Handling 3 operands in an expression without raising an exception giacomo boffi <pecore@pascolo.net> - 2013-09-29 23:39 +0200
                                          Re: Handling 3 operands in an expression without raising an exception giacomo boffi <pecore@pascolo.net> - 2013-09-29 23:49 +0200
                                      Re: Handling 3 operands in an expression without raising an exception Chris Angelico <rosuav@gmail.com> - 2013-09-30 02:18 +1000
                            Re: Handling 3 operands in an expression without raising an exception Dave Angel <davea@davea.name> - 2013-09-26 20:37 +0000
        Re: Handling 3 operands in an expression without raising an exception Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-26 14:38 +0000
        Re: Handling 3 operands in an expression without raising an exception Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-26 14:38 +0000
    Re: Handling 3 operands in an expression without raising an exception Gene Heskett <gheskett@wdtv.com> - 2013-09-29 13:32 -0400

Page 2 of 6 — ← Prev page 1 [2] 3 4 5 6  Next page →


#54804

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-09-26 12:12 +0200
Message-ID<mailman.345.1380190345.18130.python-list@python.org>
In reply to#54802
Op 26-09-13 11:56, Νίκος schreef:
> Στις 26/9/2013 11:55 πμ, ο/η Nobody έγραψε:
>> On Thu, 26 Sep 2013 10:26:48 +0300, Νίκος wrote:
>>
>>> How can i wrote the two following lines so for NOT to throw out
>>> KeyErrors when a key is missing?
>>>
>>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or
>>> gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or
>>> "Άγνωστη Πόλη"
>>
>> tz = None
>> ip = os.environ.get('HTTP_CF_CONNECTING_IP')
>> if ip:
>>    tz = gi.time_zone_by_addr(ip)
>> if not tz:
>>    ip = os.environ.get('REMOTE_ADDR')
>>    if ip:
>>      tz = gi.time_zone_by_addr(ip)
>> if not tz:
>>    tz = "ÎγνÏÏÏη Î Ïλη"
>>
>> Likewise for the hostname.
>>
> 
> Its logic is simple and straightforward but too many lines:
> 
> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )
> 
> this is much better in my opinion and straighforward also and more clear
> to read:

No it is not and you prove that in the very next line.

> it doens't work though:

If it doesn't do what you think it should do then it is not straight
forward or clear, at least not to you.

-- 
Antoon Pardon

[toc] | [prev] | [next] | [standalone]


#54806

FromΝίκος <nikos.gr33k@gmail.com>
Date2013-09-26 13:18 +0300
Message-ID<l211m1$f3b$1@dont-email.me>
In reply to#54804
Στις 26/9/2013 1:12 μμ, ο/η Antoon Pardon έγραψε:
> Op 26-09-13 11:56, Νίκος schreef:
>> Στις 26/9/2013 11:55 πμ, ο/η Nobody έγραψε:
>>> On Thu, 26 Sep 2013 10:26:48 +0300, Νίκος wrote:
>>>
>>>> How can i wrote the two following lines so for NOT to throw out
>>>> KeyErrors when a key is missing?
>>>>
>>>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or
>>>> gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or
>>>> "Άγνωστη Πόλη"
>>>
>>> tz = None
>>> ip = os.environ.get('HTTP_CF_CONNECTING_IP')
>>> if ip:
>>>     tz = gi.time_zone_by_addr(ip)
>>> if not tz:
>>>     ip = os.environ.get('REMOTE_ADDR')
>>>     if ip:
>>>       tz = gi.time_zone_by_addr(ip)
>>> if not tz:
>>>     tz = "ÎγνÏÏÏη Î Ïλη"
>>>
>>> Likewise for the hostname.
>>>
>>
>> Its logic is simple and straightforward but too many lines:
>>
>> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
>> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )
>>
>> this is much better in my opinion and straighforward also and more clear
>> to read:
>
> No it is not and you prove that in the very next line.
>
>> it doens't work though:
>
> If it doesn't do what you think it should do then it is not straight
> forward or clear, at least not to you.

It is far better than the ifs, even easier to read, i was just missing a 
[0] at the end.

host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or 
os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]

[toc] | [prev] | [next] | [standalone]


#54808

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-09-26 12:41 +0200
Message-ID<mailman.348.1380192089.18130.python-list@python.org>
In reply to#54806
Op 26-09-13 12:18, Νίκος schreef:
> Στις 26/9/2013 1:12 μμ, ο/η Antoon Pardon έγραψε:
>> Op 26-09-13 11:56, Νίκος schreef:
>>> Στις 26/9/2013 11:55 πμ, ο/η Nobody έγραψε:
>>>> On Thu, 26 Sep 2013 10:26:48 +0300, Νίκος wrote:
>>>>
>>>>> How can i wrote the two following lines so for NOT to throw out
>>>>> KeyErrors when a key is missing?
>>>>>
>>>>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or
>>>>> gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or
>>>>> "Άγνωστη Πόλη"
>>>>
>>>> tz = None
>>>> ip = os.environ.get('HTTP_CF_CONNECTING_IP')
>>>> if ip:
>>>>     tz = gi.time_zone_by_addr(ip)
>>>> if not tz:
>>>>     ip = os.environ.get('REMOTE_ADDR')
>>>>     if ip:
>>>>       tz = gi.time_zone_by_addr(ip)
>>>> if not tz:
>>>>     tz = "ÎγνÏÏÏη Î Ïλη"
>>>>
>>>> Likewise for the hostname.
>>>>
>>>
>>> Its logic is simple and straightforward but too many lines:
>>>
>>> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
>>> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )
>>>
>>> this is much better in my opinion and straighforward also and more clear
>>> to read:
>>
>> No it is not and you prove that in the very next line.
>>
>>> it doens't work though:
>>
>> If it doesn't do what you think it should do then it is not straight
>> forward or clear, at least not to you.
> 
> It is far better than the ifs, even easier to read, i was just missing a
> [0] at the end.
> 
> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]

No it is not. Your purpose was to have a line that wouldn't throw an
exception even if some environ variables were not available. That
means it shouldn't throw an exception when I execute the code. Guess
what happens:

>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known

You are just illustrating your lack of basic understaning.

-- 
Antoon Pardon

[toc] | [prev] | [next] | [standalone]


#54809

FromΝίκος <nikos.gr33k@gmail.com>
Date2013-09-26 13:51 +0300
Message-ID<l213jr$p9j$1@dont-email.me>
In reply to#54808
Στις 26/9/2013 1:41 μμ, ο/η Antoon Pardon έγραψε:
> Op 26-09-13 12:18, Νίκος schreef:
>> Στις 26/9/2013 1:12 μμ, ο/η Antoon Pardon έγραψε:
>>> Op 26-09-13 11:56, Νίκος schreef:
>>>> Στις 26/9/2013 11:55 πμ, ο/η Nobody έγραψε:
>>>>> On Thu, 26 Sep 2013 10:26:48 +0300, Νίκος wrote:
>>>>>
>>>>>> How can i wrote the two following lines so for NOT to throw out
>>>>>> KeyErrors when a key is missing?
>>>>>>
>>>>>> city = gi.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] ) or
>>>>>> gi.time_zone_by_addr( os.environ['REMOTE_ADDR'] ) or
>>>>>> "Άγνωστη Πόλη"
>>>>>
>>>>> tz = None
>>>>> ip = os.environ.get('HTTP_CF_CONNECTING_IP')
>>>>> if ip:
>>>>>      tz = gi.time_zone_by_addr(ip)
>>>>> if not tz:
>>>>>      ip = os.environ.get('REMOTE_ADDR')
>>>>>      if ip:
>>>>>        tz = gi.time_zone_by_addr(ip)
>>>>> if not tz:
>>>>>      tz = "ÎγνÏÏÏη Î Ïλη"
>>>>>
>>>>> Likewise for the hostname.
>>>>>
>>>>
>>>> Its logic is simple and straightforward but too many lines:
>>>>
>>>> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
>>>> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )
>>>>
>>>> this is much better in my opinion and straighforward also and more clear
>>>> to read:
>>>
>>> No it is not and you prove that in the very next line.
>>>
>>>> it doens't work though:
>>>
>>> If it doesn't do what you think it should do then it is not straight
>>> forward or clear, at least not to you.
>>
>> It is far better than the ifs, even easier to read, i was just missing a
>> [0] at the end.
>>
>> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
>> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]
>
> No it is not. Your purpose was to have a line that wouldn't throw an
> exception even if some environ variables were not available. That
> means it shouldn't throw an exception when I execute the code. Guess
> what happens:
>
>>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> socket.gaierror: [Errno -2] Name or service not known
>
> You are just illustrating your lack of basic understaning.

I'm surepirsed, becaus eon my domain [superhost.gr] the same lien of 
code works withnout an error and it display the 'host' fileds properly.

Perhaps its failing via shell or you do not have a web server installed 
to prepare the enviromental variables or i dont know what else to hink.

But in my website this code runs at the probelm with no problem.

[toc] | [prev] | [next] | [standalone]


#54811

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-09-26 13:07 +0200
Message-ID<mailman.349.1380193672.18130.python-list@python.org>
In reply to#54809
Op 26-09-13 12:51, Νίκος schreef:
> Στις 26/9/2013 1:41 μμ, ο/η Antoon Pardon έγραψε:
>> Op 26-09-13 12:18, Νίκος schreef:
>>> Στις 26/9/2013 1:12 μμ, ο/η Antoon Pardon έγραψε:
>>>> Op 26-09-13 11:56, Νίκος schreef:
>>>
>>> It is far better than the ifs, even easier to read, i was just missing a
>>> [0] at the end.
>>>
>>> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
>>> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]
>>
>> No it is not. Your purpose was to have a line that wouldn't throw an
>> exception even if some environ variables were not available. That
>> means it shouldn't throw an exception when I execute the code. Guess
>> what happens:
>>
>>>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
>> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>> socket.gaierror: [Errno -2] Name or service not known
>>
>> You are just illustrating your lack of basic understaning.
> 
> I'm surepirsed, becaus eon my domain [superhost.gr] the same lien of
> code works withnout an error and it display the 'host' fileds properly.

You shoudn't be. This illustrates beautifully the difference between
understanding what one is doing and dabbling around until one stumbles
on something that currently works but that will stop working in other
circumstances.

> Perhaps its failing via shell or you do not have a web server installed
> to prepare the enviromental variables or i dont know what else to hink.

Yes it is failing via shell, but that doesn't matter. If your purpose
was to have that line working even if the environ variables were not
available, then the line should work from a shell too.

> But in my website this code runs at the probelm with no problem.

So? That just means that your website is not a good test environment
for checking whether the code works under all circumstances you want
it to work.

-- 
Antoon Pardon

[toc] | [prev] | [next] | [standalone]


#54813

FromΝίκος <nikos.gr33k@gmail.com>
Date2013-09-26 14:25 +0300
Message-ID<l215k3$42c$1@dont-email.me>
In reply to#54811
Στις 26/9/2013 2:07 μμ, ο/η Antoon Pardon έγραψε:
> Op 26-09-13 12:51, Νίκος schreef:
>> Στις 26/9/2013 1:41 μμ, ο/η Antoon Pardon έγραψε:
>>> Op 26-09-13 12:18, Νίκος schreef:
>>>> Στις 26/9/2013 1:12 μμ, ο/η Antoon Pardon έγραψε:
>>>>> Op 26-09-13 11:56, Νίκος schreef:
>>>>
>>>> It is far better than the ifs, even easier to read, i was just missing a
>>>> [0] at the end.
>>>>
>>>> host = socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
>>>> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]
>>>
>>> No it is not. Your purpose was to have a line that wouldn't throw an
>>> exception even if some environ variables were not available. That
>>> means it shouldn't throw an exception when I execute the code. Guess
>>> what happens:
>>>
>>>>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
>>> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]
>>> Traceback (most recent call last):
>>>     File "<stdin>", line 1, in <module>
>>> socket.gaierror: [Errno -2] Name or service not known
>>>
>>> You are just illustrating your lack of basic understaning.
>>
>> I'm surepirsed, becaus eon my domain [superhost.gr] the same lien of
>> code works withnout an error and it display the 'host' fileds properly.
>
> You shoudn't be. This illustrates beautifully the difference between
> understanding what one is doing and dabbling around until one stumbles
> on something that currently works but that will stop working in other
> circumstances.
>
>> Perhaps its failing via shell or you do not have a web server installed
>> to prepare the enviromental variables or i dont know what else to hink.
>
> Yes it is failing via shell, but that doesn't matter. If your purpose
> was to have that line working even if the environ variables were not
> available, then the line should work from a shell too.
>
>> But in my website this code runs at the probelm with no problem.
>
> So? That just means that your website is not a good test environment
> for checking whether the code works under all circumstances you want
> it to work.
>
Okey then please tell me, what do you see wrong in it:

socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]

the [0] at then end in case the statemnt default to the string?
please tell me in details what might go wrong with it so i cna 
understand it.

[toc] | [prev] | [next] | [standalone]


#54814

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-09-26 13:47 +0200
Message-ID<mailman.351.1380196045.18130.python-list@python.org>
In reply to#54813
Op 26-09-13 13:25, Νίκος schreef:
>>
> Okey then please tell me, what do you see wrong in it:
> 
> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]
> 
> the [0] at then end in case the statemnt default to the string?
> please tell me in details what might go wrong with it so i cna
> understand it.

Startup python and try to figure it out yourself. Show us you can
really learn something.

-- 
Antoon Pardon

[toc] | [prev] | [next] | [standalone]


#54830

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-09-26 14:42 +0000
Message-ID<l21h5e$q8$3@dont-email.me>
In reply to#54813
On Thu, 26 Sep 2013 14:25:55 +0300, Νίκος wrote:

> Okey then please tell me, what do you see wrong in it:
> 
> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP')

If os.environ.get('HTTP_CF_CONNECTING_IP') is false

> or os.environ.get('REMOTE_ADDR') 

and os.environ.get('REMOTE_ADDR') is false

> or  "Άγνωστη Προέλευση" )[0]

The you try and get the host name from the ip address "Άγνωστη 
Προέλευση", but "Άγνωστη Προέλευση" is not an ip address, so you get an 
error.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#54812

FromDave Angel <davea@davea.name>
Date2013-09-26 11:24 +0000
Message-ID<mailman.350.1380194717.18130.python-list@python.org>
In reply to#54809
On 26/9/2013 06:51, Νίκος wrote:

   <SNIP>
>>>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
>> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>> socket.gaierror: [Errno -2] Name or service not known
>>
>> You are just illustrating your lack of basic understaning.
>
> I'm surepirsed, becaus eon my domain [superhost.gr] the same lien of 
> code works withnout an error and it display the 'host' fileds properly.
>
> Perhaps its failing via shell or you do not have a web server installed 
> to prepare the enviromental variables or i dont know what else to hink.
>
> But in my website this code runs at the probelm with no problem.
>
In Python 3.3, but not on a web server, I get:


>>> import socket
>>> socket.gethostbyaddr("unknown")[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
>>> 

Question, do you get the same result on your server?  (You can put the
Greek string in place of "unknown" of course)

If so, then the default value makes no sense;  it'll cause an exception
if it's ever used.  If you insist on sticking to expressions (no
try/catch, no if statements), then perhaps you should default to a
string representing a domain which will always exist.

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#54817

FromΝίκος <nikos.gr33k@gmail.com>
Date2013-09-26 15:39 +0300
Message-ID<l219tq$o2c$1@dont-email.me>
In reply to#54812
Στις 26/9/2013 2:24 μμ, ο/η Dave Angel έγραψε:
> On 26/9/2013 06:51, Νίκος wrote:
>
>     <SNIP>
>>>>>> socket.gethostbyaddr( os.environ.get('HTTP_CF_CONNECTING_IP') or
>>> os.environ.get('REMOTE_ADDR') or  "Άγνωστη Προέλευση" )[0]
>>> Traceback (most recent call last):
>>>     File "<stdin>", line 1, in <module>
>>> socket.gaierror: [Errno -2] Name or service not known
>>>
>>> You are just illustrating your lack of basic understaning.
>>
>> I'm surepirsed, becaus eon my domain [superhost.gr] the same lien of
>> code works withnout an error and it display the 'host' fileds properly.
>>
>> Perhaps its failing via shell or you do not have a web server installed
>> to prepare the enviromental variables or i dont know what else to hink.
>>
>> But in my website this code runs at the probelm with no problem.
>>
> In Python 3.3, but not on a web server, I get:
>
>
>>>> import socket
>>>> socket.gethostbyaddr("unknown")[0]
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> socket.gaierror: [Errno -2] Name or service not known
>>>>
>
> Question, do you get the same result on your server?  (You can put the
> Greek string in place of "unknown" of course)
>
> If so, then the default value makes no sense;  it'll cause an exception
> if it's ever used.  If you insist on sticking to expressions (no
> try/catch, no if statements), then perhaps you should default to a
> string representing a domain which will always exist.

Yes, you are right, in my shell it fails too givign the same error 
message as yours, while on the other had in the websste is working.

Can you explain this please?
why doesnt it fail to both enviroments?

[toc] | [prev] | [next] | [standalone]


#54819

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2013-09-26 14:53 +0200
Message-ID<mailman.354.1380200021.18130.python-list@python.org>
In reply to#54817
Op 26-09-13 14:39, Νίκος schreef:
> Yes, you are right, in my shell it fails too givign the same error
> message as yours, while on the other had in the websste is working.
> 
> Can you explain this please?
> why doesnt it fail to both enviroments?

Your site and your shell are two different environments. The state
of the website environment lets your code succeed while the state
of the shell environment, doesn't.

-- 
Antoon Pardon

[toc] | [prev] | [next] | [standalone]


#54820

FromΝίκος <nikos.gr33k@gmail.com>
Date2013-09-26 16:34 +0300
Message-ID<l21d5u$cit$1@dont-email.me>
In reply to#54819
Στις 26/9/2013 3:53 μμ, ο/η Antoon Pardon έγραψε:
> Op 26-09-13 14:39, Νίκος schreef:
>> Yes, you are right, in my shell it fails too givign the same error
>> message as yours, while on the other had in the websste is working.
>>
>> Can you explain this please?
>> why doesnt it fail to both enviroments?
>
> Your site and your shell are two different environments. The state
> of the website environment lets your code succeed while the state
> of the shell environment, doesn't.
>
What modification does it need to also work in the shell environmentthe 
[0] at the end is what complicates things.

[toc] | [prev] | [next] | [standalone]


#54825

FromDave Angel <davea@davea.name>
Date2013-09-26 14:22 +0000
Message-ID<mailman.355.1380205373.18130.python-list@python.org>
In reply to#54820
On 26/9/2013 09:34, Νίκος wrote:

> Στις 26/9/2013 3:53 μμ, ο/η Antoon Pardon έγραψε:
>> Op 26-09-13 14:39, Νίκος schreef:
>>> Yes, you are right, in my shell it fails too givign the same error
>>> message as yours, while on the other had in the websste is working.
>>>
>>> Can you explain this please?
>>> why doesnt it fail to both enviroments?
>>
>> Your site and your shell are two different environments. The state
>> of the website environment lets your code succeed while the state
>> of the shell environment, doesn't.
>>
> What modification does it need to also work in the shell environmentthe 
> [0] at the end is what complicates things.

Not at all.  What complicates/confuses things is trying to do too much
in one line.

The line is trying to solve two separate things.  You might now
understand the first of them; the fetching of multiple environment
variables that may or may not exist.

The second thing is the function call to gethostbyname().  If fed
invalid data, this call will throw an exception.  So you need to either
put it in a try/catch or somehow pretend that you can know what
constitutes invalid data.  One example of invalid data is your default
string.  Another might be if one of those environment variables exists,
but isn't reasonable.  And a third might be if the domain server
temporarily refuses to recognize a valid hostname.

I'd say you need to put the gethostbyname() in a try/catch, and then
supply some reasonable bogus string for host.  Only you will know what
to use there;  depending on what you're going to use it for.


ipval = (os.environ.get('HTTP_CF_CONNECTING_IP') or 
os.environ.get('REMOTE_ADDR', "Please throw a gaierror exception")
try:
     host = socket.gethostbyaddr(ipval) [0]
except socket.gaierror as exc;
     host = "Unknown host"

I don't know the gethostbyaddr(), so i don't know if there are other
exceptions you should also try to catch.

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#54840

FromΝίκος <nikos.gr33k@gmail.com>
Date2013-09-26 19:58 +0300
Message-ID<l21p2r$ilf$1@dont-email.me>
In reply to#54825
Στις 26/9/2013 5:22 μμ, ο/η Dave Angel έγραψε:
> On 26/9/2013 09:34, Νίκος wrote:
>
>> Στις 26/9/2013 3:53 μμ, ο/η Antoon Pardon έγραψε:
>>> Op 26-09-13 14:39, Νίκος schreef:
>>>> Yes, you are right, in my shell it fails too givign the same error
>>>> message as yours, while on the other had in the websste is working.
>>>>
>>>> Can you explain this please?
>>>> why doesnt it fail to both enviroments?
>>>
>>> Your site and your shell are two different environments. The state
>>> of the website environment lets your code succeed while the state
>>> of the shell environment, doesn't.
>>>
>> What modification does it need to also work in the shell environmentthe
>> [0] at the end is what complicates things.
>
> Not at all.  What complicates/confuses things is trying to do too much
> in one line.
>
> The line is trying to solve two separate things.  You might now
> understand the first of them; the fetching of multiple environment
> variables that may or may not exist.
>
> The second thing is the function call to gethostbyname().  If fed
> invalid data, this call will throw an exception.  So you need to either
> put it in a try/catch or somehow pretend that you can know what
> constitutes invalid data.  One example of invalid data is your default
> string.  Another might be if one of those environment variables exists,
> but isn't reasonable.  And a third might be if the domain server
> temporarily refuses to recognize a valid hostname.
>
> I'd say you need to put the gethostbyname() in a try/catch, and then
> supply some reasonable bogus string for host.  Only you will know what
> to use there;  depending on what you're going to use it for.
>
>
> ipval = (os.environ.get('HTTP_CF_CONNECTING_IP') or
> os.environ.get('REMOTE_ADDR', "Please throw a gaierror exception")
> try:
>       host = socket.gethostbyaddr(ipval) [0]
> except socket.gaierror as exc;
>       host = "Unknown host"
>
> I don't know the gethostbyaddr(), so i don't know if there are other
> exceptions you should also try to catch.
>

Indeed this logic you follow is hethe best i have seen so far.
But actually i have 2 variables that relay on a proper ip address.

ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or 
os.environ.get('REMOTE_ADDR', "UnKnown Origin") )
try:
	gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
	city = gi.time_zone_by_addr( ipval )
	host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
	city = host = "UnKnown Origin"

But then what if in case of an error i needed different string set to be 
assigned on city and host respectively?

As i ahve it know in case of n address related error i get the smae 
sting for both of them.

[toc] | [prev] | [next] | [standalone]


#54852

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2013-09-26 20:16 +0000
Message-ID<l224n6$oak$1@dont-email.me>
In reply to#54840
On Thu, 26 Sep 2013 19:58:02 +0300, Νίκος wrote:

> except socket.gaierror as e:
> 	city = host = "UnKnown Origin"
> 
> But then what if in case of an error i needed different string set to be
> assigned on city and host respectively?

Oh FFS

Are you serious when you ask this?

Simply change:

except socket.gaierror as e:
    city = host = "UnKnown Origin"

To:

except socket.gaierror as e:
    city = "Unknown City"
    host = "Unknown Host"

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#54854

FromΝίκος <nikos.gr33k@gmail.com>
Date2013-09-27 01:14 +0300
Message-ID<l22bkl$9ds$1@dont-email.me>
In reply to#54852
Στις 26/9/2013 11:16 μμ, ο/η Denis McMahon έγραψε:
> On Thu, 26 Sep 2013 19:58:02 +0300, Νίκος wrote:
>
>> except socket.gaierror as e:
>> 	city = host = "UnKnown Origin"
>>
>> But then what if in case of an error i needed different string set to be
>> assigned on city and host respectively?
>
> Oh FFS
>
> Are you serious when you ask this?
>
> Simply change:
>
> except socket.gaierror as e:
>      city = host = "UnKnown Origin"
>
> To:
>
> except socket.gaierror as e:
>      city = "Unknown City"
>      host = "Unknown Host"

Yes indeed that was an idiotic question made by me, but i was somehow 
feeling again that i should handle it in one-liner, avoid wanting to use 
2 statements.

I wonder if there is a way to assign the string "Unknown Origin" to the 
variable that failed in the try block to get a value.

Can i describe that somehow inside the except block?

I mean like:

except socket.gaierror as e:
	what_ever_var_failed = "Unknown Origin"

[toc] | [prev] | [next] | [standalone]


#54855

FromDave Angel <davea@davea.name>
Date2013-09-26 22:55 +0000
Message-ID<mailman.372.1380236161.18130.python-list@python.org>
In reply to#54854
On 26/9/2013 18:14, Νίκος wrote:

> Στις 26/9/2013 11:16 μμ, ο/η Denis McMahon έγραψε:
>> On Thu, 26 Sep 2013 19:58:02 +0300, Νίκος wrote:
>>
>>> except socket.gaierror as e:
>>> 	city = host = "UnKnown Origin"
>>>
>>> But then what if in case of an error i needed different string set to be
>>> assigned on city and host respectively?
>>
>> Oh FFS
>>
>> Are you serious when you ask this?
>>
>> Simply change:
>>
>> except socket.gaierror as e:
>>      city = host = "UnKnown Origin"
>>
>> To:
>>
>> except socket.gaierror as e:
>>      city = "Unknown City"
>>      host = "Unknown Host"
>
> Yes indeed that was an idiotic question made by me, but i was somehow 
> feeling again that i should handle it in one-liner, avoid wanting to use 
> 2 statements.

newlines are still cheap.  And they can really help readability.

> I wonder if there is a way to assign the string "Unknown Origin" to the 
> variable that failed in the try block to get a value.
>
> Can i describe that somehow inside the except block?
>
> I mean like:
>
> except socket.gaierror as e:
> 	what_ever_var_failed = "Unknown Origin"

Simply assign the default values BEFORE the try block, and use pass as
the except block.

That still doesn't get around the inadvisability of putting those 3
lines in the try block.

You still haven't dealt with the gt assignment and its possible
exception.

-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#54867

FromΝίκος <nikos.gr33k@gmail.com>
Date2013-09-27 12:19 +0300
Message-ID<l23ijp$jka$1@dont-email.me>
In reply to#54855
Στις 27/9/2013 1:55 πμ, ο/η Dave Angel έγραψε:
> On 26/9/2013 18:14, Νίκος wrote:
>
>> Στις 26/9/2013 11:16 μμ, ο/η Denis McMahon έγραψε:
>>> On Thu, 26 Sep 2013 19:58:02 +0300, Νίκος wrote:
>>>
>>>> except socket.gaierror as e:
>>>> 	city = host = "UnKnown Origin"
>>>>
>>>> But then what if in case of an error i needed different string set to be
>>>> assigned on city and host respectively?
>>>
>>> Oh FFS
>>>
>>> Are you serious when you ask this?
>>>
>>> Simply change:
>>>
>>> except socket.gaierror as e:
>>>       city = host = "UnKnown Origin"
>>>
>>> To:
>>>
>>> except socket.gaierror as e:
>>>       city = "Unknown City"
>>>       host = "Unknown Host"
>>
>> Yes indeed that was an idiotic question made by me, but i was somehow
>> feeling again that i should handle it in one-liner, avoid wanting to use
>> 2 statements.
>
> newlines are still cheap.  And they can really help readability.
>
>> I wonder if there is a way to assign the string "Unknown Origin" to the
>> variable that failed in the try block to get a value.
>>
>> Can i describe that somehow inside the except block?
>>
>> I mean like:
>>
>> except socket.gaierror as e:
>> 	what_ever_var_failed = "Unknown Origin"
>
> Simply assign the default values BEFORE the try block, and use pass as
> the except block.
>
> That still doesn't get around the inadvisability of putting those 3
> lines in the try block.
>
> You still haven't dealt with the gt assignment and its possible
> exception.
>
Yes gi must be removed form within the try block because iam tesign it 
for failure.

I'am not sure what you mean though when you say:

> Simply assign the default values BEFORE the try block, and use pass as
> the except block.

Can you please make it more clear for me?

This is my code as i have it at the moment:

ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or 
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
try:
	gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
	city = gi.time_zone_by_addr( ipval )
	host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
	city = "Άγνωστη Πόλη"
	host = "Άγνωστη Προέλευση"

Or even better since i actually use 3 vars inside the try block it would 
be really neat to be able to detect which far failed and assign a 
specific value variable failed depended.

IF it can also be written in one-line afteer the excpect would be even 
better. Call me persistent but when i can write somethign in 1-line i 
wou;d prefer it over 3-lines.

[toc] | [prev] | [next] | [standalone]


#54868

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-09-27 09:26 +0000
Message-ID<52454f46$0$30000$c3e8da3$5496439d@news.astraweb.com>
In reply to#54867
On Fri, 27 Sep 2013 12:19:53 +0300, Νίκος wrote:

> I'am not sure what you mean though when you say:
> 
>> Simply assign the default values BEFORE the try block, and use pass as
>> the except block.
> 
> Can you please make it more clear for me?


variable = "default value"
try:
    variable = something_that_might_fail()
except SomeException:
    pass




-- 
Steven

[toc] | [prev] | [next] | [standalone]


#54870

FromΝίκος <nikos.gr33k@gmail.com>
Date2013-09-27 13:04 +0300
Message-ID<l23l6i$vks$1@dont-email.me>
In reply to#54868
Στις 27/9/2013 12:26 μμ, ο/η Steven D'Aprano έγραψε:
> On Fri, 27 Sep 2013 12:19:53 +0300, Νίκος wrote:
>
>> I'am not sure what you mean though when you say:
>>
>>> Simply assign the default values BEFORE the try block, and use pass as
>>> the except block.
>>
>> Can you please make it more clear for me?
>
>
> variable = "default value"
> try:
>      variable = something_that_might_fail()
> except SomeException:
>      pass

Thanks Steven but this way i still have to declare the default string 
sfor the variables:

Its no different than:

except socket.gaierror as e:
	city = "Άγνωστη Πόλη"
	host = "Άγνωστη Προέλευση"

Your way set the vars on top, the other way set the vars inside the 
except block.

[toc] | [prev] | [next] | [standalone]


Page 2 of 6 — ← Prev page 1 [2] 3 4 5 6  Next page →

Back to top | Article view | comp.lang.python


csiph-web