Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54785 > unrolled thread
| Started by | Νίκος <nikos.gr33k@gmail.com> |
|---|---|
| First post | 2013-09-26 10:26 +0300 |
| Last post | 2013-09-29 13:32 -0400 |
| Articles | 20 on this page of 107 — 25 participants |
Back to article view | Back to comp.lang.python
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 5 of 6 — ← Prev page 1 2 3 4 [5] 6 Next page →
| From | Jussi Piitulainen <jpiitula@ling.helsinki.fi> |
|---|---|
| Date | 2013-09-29 15:24 +0300 |
| Message-ID | <qotpprrak84.fsf@ruuvi.it.helsinki.fi> |
| In reply to | #55008 |
Νίκος writes:
> Σ�ις 29/9/2013 2:04 μμ, ο/η Jussi Piitulainen
> έγ�α�ε:
>
> > Let's see. The task is to assign a default value to city and host,
> > if they haven't a value yet; on one line (which I take to mean one
> > statement); in an "except" block where we may not know which
> > assignment failed in the "try" block; without "if"; but "or" is
> > allowed.
> >
> > But the logic I was trying to implement is
> >
> > city, host = ( (city if 'city' in locals() else "default city"),
> > (host if 'host' in locals() else "default host") )
> >
> > which uses an "if". The old tricks of using "or" and stuff for
> > this would surely go too far.
> >
> > I know!
> >
> > city, host = ( locals().get('city', "default city"),
> > locals().get('host', "default host") )
>
> I tend to like this: I might use it because it is a clear way to
> tell what var failed in the try clause and default it to soemthing.
Well, I think it's as close to what you asked as I can get. Seeing it
in a real program would make me nervous, though. I shouldn't have
brought it up at all.
[...]
> Dave's way though seems better.
> Assign the vars default string and if they get re-assinged correctly
> that would be ideal, otherwise we have already given them the defaults.
>
> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
> os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
> city = "�γν���η Π�λη"
> host = "�γν���η Π�οέλε���η"
> try:
> gi = pygeoip.GeoIP('/usr/local/share/GeoIPCity.dat')
> city = gi.time_zone_by_addr( ipval )
> host = socket.gethostbyaddr( ipval ) [0]
> except Exception as e:
> print( "metrites.py => (%s): " % lastvisit, repr(
> sys.exc_info() ), file=open('/tmp/err.out', 'w') )
>
> I'll think i'll stick to this solution.
Yes, that's a serious way to do it. (Except the destination of the
error message probably isn't.)
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-09-29 09:50 +0000 |
| Message-ID | <mailman.442.1380448230.18130.python-list@python.org> |
| In reply to | #54984 |
On 29/9/2013 03:35, Νίκος wrote:
>
> 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 = "Άγνωστη Προέλευση"
ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
gi = city=host=None
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:
gi,city,host=gi if gi is not None else "who knows", city if city is not
None else"Άγνωστη Πόλη", host if host is not None else "Άγνωστη
Προέλευση"
That's one line. And if you now want to eliminate the gi=city=host=None
line, let me attempt that. But this probably will have some serious
typo in it, as I'm not testing any of these. And it assumes that the
code is at top-level, and that none of these variables already exists.
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:
gi,city,host=globals().get("gi", "who knows"), globals().get("city",
"Άγνωστη Πόλη"), globals().get("host", "Άγνωστη
Προέλευση")
Or perhaps even, assuming this is the main script, and not a loaded
module:
import __main__ as qq
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:
gi,city,host=getattr(qq,"gi", "who knows"), getattr(qq,"city","Άγνωστη
Πόλη"),getattr(qq, "host", "Άγνωστη
Προέλευση")
--
DaveA
[toc] | [prev] | [next] | [standalone]
| From | Νίκος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-09-29 13:17 +0300 |
| Message-ID | <l28unv$en4$1@dont-email.me> |
| In reply to | #54999 |
Στις 29/9/2013 12:50 μμ, ο/η Dave Angel έγραψε:
> 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:
> gi,city,host=globals().get("gi", "who knows"), globals().get("city",
> "Άγνωστη Πόλη"), globals().get("host", "Άγνωστη
> Προέλευση")
Hello Dave,
By looking at your code i think that you are tellign the progrma to try
to gri don't know what the function globals() is supposed to do
but i was thinking more of:
ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
try:
city = gi.time_zone_by_addr( ipval )
host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
# We need something here to identify which one of the 2 above variables
or even both of them went wrong, and then assign the appropriate value
to each one of them but i don't know how to write it.
Is there a function that can tell us which variable failed to be
assigned a value that we can use in order to decide to which variable we
will
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-09-29 10:57 +0000 |
| Message-ID | <mailman.444.1380452278.18130.python-list@python.org> |
| In reply to | #55000 |
On 29/9/2013 06:17, Νίκος wrote:
> Στις 29/9/2013 12:50 μμ, ο/η Dave Angel έγραψε:
>> 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:
>> gi,city,host=globals().get("gi", "who knows"), globals().get("city",
>> "Άγνωστη Πόλη"), globals().get("host", "Άγνωστη
>> Προέλευση")
>
> Hello Dave,
>
> By looking at your code i think that you are tellign the progrma to try
> to gri don't know what the function globals() is supposed to do
Try help(globals()) at the interpreter prompt.
Help on built-in function globals in module builtins:
globals(...)
globals() -> dictionary
Return the dictionary containing the current scope's global variables.
So once you have a dictionary, you can use get() to fetch values which
might or not be present, and supply the default in case they aren't.
>
> but i was thinking more of:
>
> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
> os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
> try:
> city = gi.time_zone_by_addr( ipval )
> host = socket.gethostbyaddr( ipval ) [0]
> except socket.gaierror as e:
> # We need something here to identify which one of the 2 above variables
> or even both of them went wrong, and then assign the appropriate value
> to each one of them but i don't know how to write it.
>
> Is there a function that can tell us which variable failed to be
> assigned a value that we can use in order to decide to which variable we
> will
>
I showed you the only 3 ways I know of, and none of them is as readable
as just setting the defaults in the standard way.
I only showed you those in order to show you how unreadable it would be.
--
DaveA
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-09-29 23:58 +1000 |
| Message-ID | <mailman.450.1380463084.18130.python-list@python.org> |
| In reply to | #55000 |
On Sun, Sep 29, 2013 at 8:57 PM, Dave Angel <davea@davea.name> wrote: > Try help(globals()) at the interpreter prompt. > > Help on built-in function globals in module builtins: > > globals(...) > globals() -> dictionary > > Return the dictionary containing the current scope's global variables. Insignificant quibble: help(globals()) will give you help on the dict type. What you actually want here is help(globals). Otherwise agreed. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2013-09-29 21:01 +0000 |
| Message-ID | <l2a4f8$suv$1@dont-email.me> |
| In reply to | #55000 |
On Sun, 29 Sep 2013 13:17:36 +0300, Νίκος wrote:
> Στις 29/9/2013 12:50 μμ, ο/η Dave Angel έγραψε:
>> 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:
>> gi,city,host=globals().get("gi", "who knows"), globals().get
("city",
>> "Άγνωστη Πόλη"), globals().get("host", "Άγνωστη Προέλευση")
>
> Hello Dave,
>
> By looking at your code i think that you are tellign the progrma to try
> to gri don't know what the function globals() is supposed to do
>
> but i was thinking more of:
>
> ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
> os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
> try:
> city = gi.time_zone_by_addr( ipval )
> host = socket.gethostbyaddr( ipval ) [0]
> except socket.gaierror as e:
> # We need something here to identify which one of the 2 above
variables
> or even both of them went wrong, and then assign the appropriate value
> to each one of them but i don't know how to write it.
>
> Is there a function that can tell us which variable failed to be
> assigned a value that we can use in order to decide to which variable we
> will
Yes, set the default values first, and overwrite them with the successful
values when the values are successfully calculated.
This is a very common method used in many programming languages.
--
Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Νίκος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-09-29 14:06 +0300 |
| Message-ID | <l291ju$rvl$1@dont-email.me> |
| In reply to | #54999 |
Στις 29/9/2013 12:50 μμ, ο/η Dave Angel έγραψε:
> 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:
> gi,city,host=globals().get("gi", "who knows"), globals().get("city",
> "Άγνωστη Πόλη"), globals().get("host", "Άγνωστη
> Προέλευση")
Hello Dave,
By looking at your code i think that you are tellign the progrma to try
to gri don't know what the function globals() is supposed to do
but i was thinking more of:
ipval = ( os.environ.get('HTTP_CF_CONNECTING_IP') or
os.environ.get('REMOTE_ADDR', "Cannot Resolve") )
try:
city = gi.time_zone_by_addr( ipval )
host = socket.gethostbyaddr( ipval ) [0]
except socket.gaierror as e:
# We need something here to identify which one of the 2 above variables
or even both of them went wrong, and then assign the appropriate value
to each one of them but i don't know how to write it.
Is there a function that can tell us which variable failed to be
assigned a value that we can use in order to decide to which string we
weill be defaulting to?
[toc] | [prev] | [next] | [standalone]
| From | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
|---|---|
| Date | 2013-09-29 12:48 +0200 |
| Message-ID | <mailman.445.1380452304.18130.python-list@python.org> |
| In reply to | #54984 |
Op 29-09-13 09:35, Νίκος schreef: > Στις 29/9/2013 2:04 πμ, ο/η Chris Angelico έγραψε: >> On Sun, Sep 29, 2013 at 4:45 AM, Mark Lawrence >> <breamoreboy@yahoo.co.uk> wrote: >>> Not tortured, simply murdered so we don't have to put up with his >>> completely >>> unacceptable behaviour, which sadly is thriving owing to so many people >>> ignoring the "do not feed this moron" signs. >> >> You miss one important factor in these discussions: the silent >> majority of readers. We have a few people here who are not "worth" >> responding to, as they're highly unlikely to listen (the most >> noteworthy other example being jmf on Unicode), but that doesn't mean >> the threads can't be useful to someone else. And sometimes there can >> be some extremely entertaining conversation, too. >> >> That's also why I don't plonk anyone :) > > Its not that i don't listen, its that i want something to be implemented > in a specific way. Why? What is so important about this particular way, that you are willing to spend/waste so much time on it? You act like someone who want to get from Brussels to London and when asked how to do that gets advise on how to take the boat or plane at which point you react that you want to get to Londen without boat or plane but just by bicycle. And in further exchange make it clear that using a bike is more important than arriving in London. So please why do you make it your priority to implement it in a specific way, over it working correctly? -- Antoon Pardon
[toc] | [prev] | [next] | [standalone]
| From | Piet van Oostrum <piet@vanoostrum.org> |
|---|---|
| Date | 2013-09-29 13:24 -0400 |
| Message-ID | <m2pprr5ymw.fsf@cochabamba.vanoostrum.org> |
| In reply to | #55004 |
Antoon Pardon <antoon.pardon@rece.vub.ac.be> writes: > Why? What is so important about this particular way, that you are > willing to spend/waste so much time on it? You act like someone > who want to get from Brussels to London and when asked how to > do that gets advise on how to take the boat or plane at which > point you react that you want to get to Londen without boat > or plane but just by bicycle. And in further exchange make it > clear that using a bike is more important than arriving in London. And then the easiests would be to put your bicycle in the train. -- Piet van Oostrum <piet@vanoostrum.org> WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4]
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2013-09-29 18:44 +0100 |
| Message-ID | <mailman.458.1380476831.18130.python-list@python.org> |
| In reply to | #55028 |
On 29/09/2013 18:24, Piet van Oostrum wrote: > Antoon Pardon <antoon.pardon@rece.vub.ac.be> writes: > >> Why? What is so important about this particular way, that you are >> willing to spend/waste so much time on it? You act like someone >> who want to get from Brussels to London and when asked how to >> do that gets advise on how to take the boat or plane at which >> point you react that you want to get to Londen without boat >> or plane but just by bicycle. And in further exchange make it >> clear that using a bike is more important than arriving in London. > > And then the easiests would be to put your bicycle in the train. > But what if you don't want to use the train, but cycle all the way? There _must_ be a way of cycling through the tunnel...
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2013-09-29 14:45 -0400 |
| Message-ID | <mailman.460.1380480324.18130.python-list@python.org> |
| In reply to | #55028 |
[Multipart message — attachments visible in raw view] — view raw
On Sun, Sep 29, 2013 at 1:44 PM, MRAB <python@mrabarnett.plus.com> wrote: > On 29/09/2013 18:24, Piet van Oostrum wrote: > >> Antoon Pardon <antoon.pardon@rece.vub.ac.be> writes: >> >> Why? What is so important about this particular way, that you are >>> willing to spend/waste so much time on it? You act like someone >>> who want to get from Brussels to London and when asked how to >>> do that gets advise on how to take the boat or plane at which >>> point you react that you want to get to Londen without boat >>> or plane but just by bicycle. And in further exchange make it >>> clear that using a bike is more important than arriving in London. >>> >> >> And then the easiests would be to put your bicycle in the train. >> >> But what if you don't want to use the train, but cycle all the way? > There _must_ be a way of cycling through the tunnel... > wlle thats fien bit i doont wnt to go thru the tunnel. Perhaps you can suggest my sloulution > -- > https://mail.python.org/**mailman/listinfo/python-list<https://mail.python.org/mailman/listinfo/python-list> > -- Joel Goldstick http://joelgoldstick.com
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-09-30 16:05 +0100 |
| Message-ID | <mailman.491.1380553547.18130.python-list@python.org> |
| In reply to | #55028 |
On 29/09/2013 18:44, MRAB wrote: > On 29/09/2013 18:24, Piet van Oostrum wrote: >> Antoon Pardon <antoon.pardon@rece.vub.ac.be> writes: >> >>> Why? What is so important about this particular way, that you are >>> willing to spend/waste so much time on it? You act like someone >>> who want to get from Brussels to London and when asked how to >>> do that gets advise on how to take the boat or plane at which >>> point you react that you want to get to Londen without boat >>> or plane but just by bicycle. And in further exchange make it >>> clear that using a bike is more important than arriving in London. >> >> And then the easiests would be to put your bicycle in the train. >> > But what if you don't want to use the train, but cycle all the way? > There _must_ be a way of cycling through the tunnel... There is but all the illegal immigrants who use it won't tell us about it :) -- Cheers. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2013-09-29 11:35 +1000 |
| Message-ID | <mailman.437.1380418551.18130.python-list@python.org> |
| In reply to | #54949 |
Mark Lawrence <breamoreboy@yahoo.co.uk> writes: > On 28/09/2013 19:38, Zero Piraeus wrote: > > To be clear, Mark, you are calling for Νίκος to be tortured to death > > with a red hot poker, yes? > > Not tortured, simply murdered so we don't have to put up with his > completely unacceptable behaviour Regardless of the behaviour of anyone else, threatening them (with calls for their murder) is completely unacceptable in this forum. Please don't do it, ever. -- \ “Religious faith is the one species of human ignorance that | `\ will not admit of even the *possibility* of correction.” —Sam | _o__) Harris, _The End of Faith_, 2004 | Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-09-28 11:59 +1000 |
| Message-ID | <mailman.400.1380333591.18130.python-list@python.org> |
| In reply to | #54914 |
On Sat, Sep 28, 2013 at 8:06 AM, Νίκος <nikos.gr33k@gmail.com> wrote: > Well to tell the truth no matter what you say to me if something can be > written in less lines than another implementation but still retain its > simplicity and straightforward logic behind it i would prefer it! > I don't know why you think otherwise, especially people who are used to > write Perl code(me being one of them) would agree with me! It's high time you stopped trying to write Perl code that runs under the Python interpreter, and started writing Python code that runs under the Python interpreter. There are rules. You first learn the rules and learn to code within them; then later, once you actually achieve some measure of competence, you begin learning when to break the rules. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Νίκος <nikos.gr33k@gmail.com> |
|---|---|
| Date | 2013-09-28 12:14 +0300 |
| Message-ID | <l266l1$h0c$1@dont-email.me> |
| In reply to | #54921 |
Στις 28/9/2013 4:59 πμ, ο/η Chris Angelico έγραψε:
> On Sat, Sep 28, 2013 at 8:06 AM, Νίκος <nikos.gr33k@gmail.com> wrote:
>> Well to tell the truth no matter what you say to me if something can be
>> written in less lines than another implementation but still retain its
>> simplicity and straightforward logic behind it i would prefer it!
>> I don't know why you think otherwise, especially people who are used to
>> write Perl code(me being one of them) would agree with me!
>
> It's high time you stopped trying to write Perl code that runs under
> the Python interpreter, and started writing Python code that runs
> under the Python interpreter.
>
> There are rules. You first learn the rules and learn to code within
> them; then later, once you actually achieve some measure of
> competence, you begin learning when to break the rules.
>
> ChrisA
> χεχεf
I agree with everything you say, but i also have to say that even
writing compact code which still retain its simplicity and understanding
its preferred to me and to other coders too.
For example i wouldn't change this line for anything in my code no
matter how simple you can get it look..
#check if date entered as intented, format it properly for MySQL
lastvisit = datetime.strptime(lastvisit, '%d %m %Y').strftime('%Y-%m-%d')
why write it in 2-3 lines when you cna have it written in 1-liner?
Isn't it clear as it is now?
[toc] | [prev] | [next] | [standalone]
| From | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
|---|---|
| Date | 2013-09-28 15:53 +0200 |
| Message-ID | <mailman.414.1380384238.18130.python-list@python.org> |
| In reply to | #54914 |
Op 28-09-13 00:06, Νίκος schreef: > Στις 27/9/2013 8:00 μμ, ο/η Grant Edwards έγραψε: >> On 2013-09-27, ?????????? <nikos.gr33k@gmail.com> wrote: >> >>> Sure your method follows the the logic in a straighforward way >>> step-by-step but i just dont want to spent almost 20 lines of code just >>> to calculate 2 variables(city and host). >> >> Does your provider charge you per line of code? >> >> If all that matters is the number of lines of code then use this: >> >> city,host = 0,0 >> >> Only _1_ nice short line of code. >> >> Happy? >> > > Well to tell the truth no matter what you say to me if something can be > written in less lines than another implementation but still retain its > simplicity and straightforward logic behind it i would prefer it! > I don't know why you think otherwise, especially people who are used to > write Perl code(me being one of them) would agree with me! The problem is, as it stands you seem to make it a priority to write compact code over correct code, wasting everybody's time. If you hadn't been insisting on trying to reduce the number of lines of the various given proposals, you might already have a working solution and be working on something else. As it is all your attempts to reduce the number of lines while retaining its simplicity and straightforward logic behind it have only resulted in you producing code that didn't work. People like you who judge code in one language by how much it resembles code in an other language are like people who used to work with glue but need to work with hammer and nails for some reason and are surprised they just can't subtituted nails for glue and fail to see they may have to rethink the design. So they just keep trying glue solutions with nails and every nail solution that is offered by people who have experience with nails, they will adapt until it looks like it could be a glue solution. In the mean time all these glue solutions fail and much time is wasted. -- Antoon Pardon
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2013-09-28 12:15 -0400 |
| Message-ID | <mailman.417.1380384961.18130.python-list@python.org> |
| In reply to | #54914 |
[Multipart message — attachments visible in raw view] — view raw
On Sat, Sep 28, 2013 at 9:53 AM, Antoon Pardon <antoon.pardon@rece.vub.ac.be > wrote: > Op 28-09-13 00:06, Νίκος schreef: > > Στις 27/9/2013 8:00 μμ, ο/η Grant Edwards έγραψε: >> >>> On 2013-09-27, ?????????? <nikos.gr33k@gmail.com> wrote: >>> >>> Sure your method follows the the logic in a straighforward way >>>> step-by-step but i just dont want to spent almost 20 lines of code just >>>> to calculate 2 variables(city and host). >>>> >>> >>> Does your provider charge you per line of code? >>> >>> If all that matters is the number of lines of code then use this: >>> >>> city,host = 0,0 >>> >>> Only _1_ nice short line of code. >>> >>> Happy? >>> >>> >> Well to tell the truth no matter what you say to me if something can be >> written in less lines than another implementation but still retain its >> simplicity and straightforward logic behind it i would prefer it! >> I don't know why you think otherwise, especially people who are used to >> write Perl code(me being one of them) would agree with me! >> > > The problem is, as it stands you seem to make it a priority to write > compact code over correct code, wasting everybody's time. > > If you hadn't been insisting on trying to reduce the number of lines > of the various given proposals, you might already have a working > solution and be working on something else. > > As it is all your attempts to reduce the number of lines while retaining > its simplicity and straightforward logic behind it have only resulted in > you producing code that didn't work. > > People like you who judge code in one language by how much it resembles > code in an other language are like people who used to work with glue but > need to work with hammer and nails for some reason and are surprised > they just can't subtituted nails for glue and fail to see they may have > to rethink the design. So they just keep trying glue solutions with > nails and every nail solution that is offered by people who have > experience with nails, they will adapt until it looks like it could be > a glue solution. In the mean time all these glue solutions fail and > much time is wasted. > > > -- > Antoon Pardon > > -- > https://mail.python.org/**mailman/listinfo/python-list<https://mail.python.org/mailman/listinfo/python-list> > Its funny how the guy who wants the one line of code has the longest threads that meander endlessly in the mailing list. He's a write only machine -- don't think he reads or understands or has any interest in understanding what people here explain to him. This whole goofy exercise is to try to figure out where the visitor to the website come from -- the geo ip stuff, etc. Now back last month there was another endless thread where is was pointed out that you can't really be sure where someone is reading from. Next we'll get more questions about how to screw up unicode, and how to write code that deals with apache and linux shell with the caveat that the OP has no interesting in learning how those things work. He just wants the one line. Troll is maybe too respectable a label to put on this guy. -- Joel Goldstick http://joelgoldstick.com
[toc] | [prev] | [next] | [standalone]
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Date | 2013-09-28 12:18 +0100 |
| Message-ID | <mailman.409.1380367109.18130.python-list@python.org> |
| In reply to | #54867 |
On 2013-09-27 11:43, Dave Angel wrote: > You should study APL. Many functions were written in one line, with > twenty lines of explanation. The function itself was considered > unreadable nonsense. And if a function stopped working, general wisdom > was to throw it out, and re-implement the explanation. I studied it > briefly in class in 1970, and have no idea if there are current > implementations. You are in luck! GNU APL 1.0 was just released! http://www.gnu.org/software/apl/ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
[toc] | [prev] | [next] | [standalone]
| From | giacomo boffi <pecore@pascolo.net> |
|---|---|
| Date | 2013-09-29 17:28 +0200 |
| Message-ID | <87eh87ir51.fsf@pascolo.net> |
| In reply to | #54867 |
Νίκος <nikos.gr33k@gmail.com> writes: > IF it can also be written in one-line def f(x,n,w):return(lambda y=f(x[::2],n/2,w[::2]),z=f(x[1::2],n/2,w[::2]):reduce(lambda x,y:x+y,zip(*[(y[k]+w[k]*z[k],y[k]-w[k]*z[k]) for k in range(n/2)])))()if n>1 else x -- anch'io la penso come me, ma -- SteO153, in IHC
[toc] | [prev] | [next] | [standalone]
| From | Joel Goldstick <joel.goldstick@gmail.com> |
|---|---|
| Date | 2013-09-29 12:07 -0400 |
| Message-ID | <mailman.453.1380470867.18130.python-list@python.org> |
| In reply to | #55021 |
[Multipart message — attachments visible in raw view] — view raw
On Sun, Sep 29, 2013 at 11:28 AM, giacomo boffi <pecore@pascolo.net> wrote: > Νίκος <nikos.gr33k@gmail.com> writes: > > > IF it can also be written in one-line > > def f(x,n,w):return(lambda > y=f(x[::2],n/2,w[::2]),z=f(x[1::2],n/2,w[::2]):reduce(lambda > x,y:x+y,zip(*[(y[k]+w[k]*z[k],y[k]-w[k]*z[k]) for k in range(n/2)])))()if > n>1 else x > > -- > anch'io la penso come me, ma -- SteO153, in IHC > -- > https://mail.python.org/mailman/listinfo/python-list > I've been reading along and learning some really obscure coding patterns. The missing part is the why. Antoon asks: Why? What is so important about this particular way, that you are willing to spend/waste so much time on it? This question goes completely unnoticed. In the big picture this seems to be the pattern. Nikos asks a question that shows fundamental flaws in his understanding of a problem. People probe to understand what he really wants. He ignores everything except little coding snippets, and requests different choices on and on. Its like a fussy shopper wanting to see endless dresses, and in the end choosing none. I don't think any of Nikos questions have anything to do with finding an answer, because if you dig deeper into the questions they end up being only red herrings. As I pointed out yesterday he still hasn't fixed the fact that his python files on his server are set with permissions to read the code which contains passwords in plain text. That was the big drama from June So, Antoon, I think the question is why are 'we' wasting so much time. Nikos is just the orchestrator. He isn't wasting any time. He isn't doing anything. Here's my question: I wonder if Nikos has ever been employed to write software. If so, I wonder how long he lasted before he was let go. And I feel bad for the guy who had to support his code! -- Joel Goldstick http://joelgoldstick.com
[toc] | [prev] | [next] | [standalone]
Page 5 of 6 — ← Prev page 1 2 3 4 [5] 6 Next page →
Back to top | Article view | comp.lang.python
csiph-web