Re: GvR Europython keynote described on lwn.net

2015-07-31 Thread Rustom Mody
On Friday, July 31, 2015 at 12:03:36 PM UTC+5:30, Paul Rubin wrote:
> The final question was about what he hates in Python. "Anything to do
> with package distribution", he answered immediately. There are problems
> with version skew and dependencies that just make for an "endless
> mess". He dreads it when a colleague comes to him with a "simple Python
> question". Half the time it is some kind of import path problem and
> there is no easy solution to offer.

Heh! I'm in good company!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New module (written in C) for using the high-precision QD library

2015-07-31 Thread Stefan Behnel
baruc...@gmail.com schrieb am 30.07.2015 um 22:09:
> It is written in pure C with the CPython C-API in order to get the highest 
> possible speed.

This is a common fallacy. Cython should still be able to squeeze another
bit of performance out of your wrapper for you. It tends to know the C-API
better than you would think, and it does things for you that you would
never do in C. It also helps in keeping your code safer and easier to maintain.

Your C code seems to be only about 1500 lines, not too late to translate
it. That should save you a couple of hundred lines and at the same time
make it work with Python 3 (which it currently doesn't, from what I see).

Stefan


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New module (written in C) for using the high-precision QD library

2015-07-31 Thread Chris Angelico
On Fri, Jul 31, 2015 at 5:26 PM, Stefan Behnel  wrote:
> Your C code seems to be only about 1500 lines, not too late to translate
> it. That should save you a couple of hundred lines and at the same time
> make it work with Python 3 (which it currently doesn't, from what I see).

I was just looking over the README (literally two minutes ago, your
message came in as I was wording up a reply), and Python 3 support
does seem to be a bit of a hole in the support.

To what extent does Cython make this easier? The biggest barrier I
would expect to see is the bytes/text distinction, where a default
quoted string has different meaning in the two versions - but like
with performance guessing, this is much more likely to be wrong than
right.

Another, but much smaller, hole in the support would be installation
via pip. I'd recommend getting the package listed on PyPI and then
testing some pip installations on different platforms - chances are
that's going to be the best way to do the builds.

All the best!

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to re-write this bash script in Python?

2015-07-31 Thread Chris Angelico
On Fri, Jul 31, 2015 at 4:31 AM,   wrote:
> #!/bin/bash
>
> _maillist='pa...@email.com'
> _hname=`hostname`
> _logdir=/hadoop/logs
> _dirlog=${_logdir}/directory_check.log
>
> _year=$(date -d "-5 hour" +%Y)
> _month=$(date -d "-5 hour" +%m)
> _day=$(date -d "-5 hour" +%d)
> _hour=$(date -d "-5 hour" +%H)
>
> _hdfsdir=`hdfs dfs -ls -d /hadoop/flume_ingest_*/$_year/$_month | awk '{print 
> $8}'`
>
> echo "Checking for HDFS directories:" > ${_dirlog}
> echo >> ${_dirlog}
>
> for _currdir in $_hdfsdir
> do
> hdfs dfs -ls -d $_currdir/$_day/$_hour &>> ${_dirlog}
> done
>
> if [[ `grep -i "No such file or directory" ${_dirlog}` ]];
> then
> echo "Verify Flume is working for all  servers" | mailx -s "HDFS Hadoop 
> Failure on Flume: ${_hname}" -a ${_dirlog} ${_maillist}
> fi
> --
> https://mail.python.org/mailman/listinfo/python-list

There are two basic approaches to this kind of job.

1) Go through every line of bash code and translate it into equivalent
Python code. You should then have a Python script which blindly and
naively accomplishes the same goal by the same method.

2) Start by describing what you want to accomplish, and then implement
that in Python, using algorithmic notes from the bash code.

The second option seems like a lot more work, but long-term it often
isn't, because you end up with better code. For example, bash lacks
decent timezone support, so I can well believe random832's guess that
your five-hour offset is a simulation of that; but Python can do much
better work with timezones, so you can get that actually correct.
Also, file handling, searching, and text manipulation and so on can
usually be done more efficiently and readably in Python directly than
by piping things through grep and awk.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to re-write this bash script in Python?

2015-07-31 Thread Cameron Simpson

On 31Jul2015 17:47, Chris Angelico  wrote:

On Fri, Jul 31, 2015 at 4:31 AM,   wrote:

#!/bin/bash

[...]

_year=$(date -d "-5 hour" +%Y)
_month=$(date -d "-5 hour" +%m)

[...]

For example, bash lacks
decent timezone support, so I can well believe random832's guess that
your five-hour offset is a simulation of that; but Python can do much
better work with timezones, so you can get that actually correct.


Actually, bash has no timezone support but the date command _does_, and 
probably neither better nor worse than Python. All one has to do is set the TZ 
environment variable, eg (untested):


 _year_gmt=$( TZ=GMT date +%Y )


Also, file handling, searching, and text manipulation and so on can
usually be done more efficiently and readably in Python directly than
by piping things through grep and awk.


Again, depends a bit on the data. But in the general case probably true.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to re-write this bash script in Python?

2015-07-31 Thread Chris Angelico
On Fri, Jul 31, 2015 at 6:15 PM, Cameron Simpson  wrote:
>> For example, bash lacks
>> decent timezone support, so I can well believe random832's guess that
>> your five-hour offset is a simulation of that; but Python can do much
>> better work with timezones, so you can get that actually correct.
>
>
> Actually, bash has no timezone support but the date command _does_, and
> probably neither better nor worse than Python. All one has to do is set the
> TZ environment variable, eg (untested):
>
>  _year_gmt=$( TZ=GMT date +%Y )

That's assuming that it's converting against the current system
timezone. I don't know how you'd use `date` to convert between two
arbitrary timezones. But anyway, still justification to rewrite from
original spec rather than reimplementing the five-hour hack.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: New module (written in C) for using the high-precision QD library

2015-07-31 Thread Stefan Behnel
Chris Angelico schrieb am 31.07.2015 um 09:37:
> On Fri, Jul 31, 2015 at 5:26 PM, Stefan Behnel wrote:
>> Your C code seems to be only about 1500 lines, not too late to translate
>> it. That should save you a couple of hundred lines and at the same time
>> make it work with Python 3 (which it currently doesn't, from what I see).
> 
> To what extent does Cython make this easier? The biggest barrier I
> would expect to see is the bytes/text distinction

Yes, that tends to be a barrier. Cython is mostly just Python, so you can write

if isinstance(s, unicode):
s = ( s).encode('utf8')

and be happy with it ("" is a cast in Cython). Such simple code looks
uglier when spelled out using the C-API and wouldn't be any CPU cycle faster.

But there's also the PyInt/PyLong unification, which can easily get in the
way for a number processing library. In Cython, you can write

if isinstance(x, (int, long)):
try:
c_long =  x
except OverflowError:
...  # do slow conversion of large integer here
else:
...  # do fast conversion from c_long here

or something like that and it'll work in Py2.6 through Py3.5 because Cython
does the necessary adaptations internally for you. This code snippet
already has a substantially faster fast-path than what the OP's code does
and it will still be much easier to tune later, in case you notice that the
slow path is too slow after all.

And then there are various helpful little features in the language like,
say, C arrays assigning by value, or freelists for extension types using a
decorator. The OP's code would clearly benefit from those, if only for
readability.

Python is much easier to write and maintain than C. Cython inherits that
property and expands it across C data types. And it generates C code for
you that automatically adapts to the different Python versions in various
ways, both in terms of compatibility and performance.

Stefan


-- 
https://mail.python.org/mailman/listinfo/python-list


Interactive entered code, inserts spurious numbers.

2015-07-31 Thread Antoon Pardon
I'm using python 3.4.2 on debian 8.

This is the code:

 8< =

import sys
write = sys.stdout.write

from math import pi

frac = 3
for a in range(2 * frac):
write("%2d: %6.4f\n" % (a, a * pi / frac))

= 8< 

Now when this code is written in a file and executed
I get the expected result:

 0: 0.
 1: 1.0472
 2: 2.0944
 3: 3.1416
 4: 4.1888
 5: 5.2360

But when I enter this code interactively in the interpreter
I get the following result:

 0: 0.
11
 1: 1.0472
11
 2: 2.0944
11
 3: 3.1416
11
 4: 4.1888
11
 5: 5.2360
11

That is different behaviour from python2, which gives me
the expected result. My guess is that the write returns
11, being the number of characters written en that the
interpreter, shows that each time through the loop.

But is this the expected behaviour in python3? I find
it annoying.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Interactive entered code, inserts spurious numbers.

2015-07-31 Thread Chris Angelico
On Fri, Jul 31, 2015 at 6:47 PM, Antoon Pardon
 wrote:
> That is different behaviour from python2, which gives me
> the expected result. My guess is that the write returns
> 11, being the number of characters written en that the
> interpreter, shows that each time through the loop.
>
> But is this the expected behaviour in python3? I find
> it annoying.

It is; it's the behaviour of the interactive interpreter. If you want
to disable that, change sys.displayhook to not print stuff out, or
assign to a dummy variable.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Interactive entered code, inserts spurious numbers.

2015-07-31 Thread Steven D'Aprano
On Fri, 31 Jul 2015 06:47 pm, Antoon Pardon wrote:

> That is different behaviour from python2, which gives me
> the expected result. My guess is that the write returns
> 11, being the number of characters written en that the
> interpreter, shows that each time through the loop.

In Python 3, write returns the number of characters written (or bytes
written, when in binary mode).

At the interactive interpreter, results returned but not assigned to
anything are printed.

> But is this the expected behaviour in python3? I find
> it annoying.

Yes, expected.

dontcare = write("%2d: %6.4f\n" % (a, a * pi / frac))



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Convert between timezones (was: How to re-write this bash script in Python?)

2015-07-31 Thread Thomas 'PointedEars' Lahn
[X-Post & F'up2 comp.unix.shell]

Chris Angelico wrote:

> On Fri, Jul 31, 2015 at 6:15 PM, Cameron Simpson  wrote:
>> Actually, bash has no timezone support but the date command _does_, and
>> probably neither better nor worse than Python. All one has to do is set
>> the TZ environment variable, eg (untested):
>>
>>  _year_gmt=$( TZ=GMT date +%Y )
> 
> That's assuming that it's converting against the current system
> timezone. I don't know how you'd use `date` to convert between two
> arbitrary timezones. […]

With POSIX date(1), ISTM all you could do is set the system time and for an 
additional invocation the TZ variable accordingly for output.



With GNU date(1):

$ (tz_source="Asia/Dubai"; time_source="$(LC_TIME=C TZ=$tz_source date -d 
"today 00:00 UTC+4" -Im)"; tz_target="America/Chicago"; echo "When it was 
$time_source in $tz_source, it was $(LC_TIME=C TZ=$tz_target date -d 
"$time_source") in $tz_target.")
When it was 2015-07-31T00:00+0400 in Asia/Dubai, it was Thu Jul 30 15:00:00 
CDT 2015 in America/Chicago.

$ date --version
date (GNU coreutils) 8.23
[…]

:)

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Logical Query JSON

2015-07-31 Thread Denis McMahon
On Fri, 31 Jul 2015 08:07:23 +0200, dieter wrote:

> Keep in mind that Python is a (more or less) "general purpose" language
> which does not know about "jsonquery". It has "and", "or" and "not"
> operators (defined in the language reference) *BUT* these are not the
> operators you are looking for.
> You will need a special "jsonquery" extension (search
> "http://pypi.python.org"; to find out whether there is something like
> this)
> which would provide appropriate support.

Actually it's not too hard. You can construct the json query syntax 
fairly easily from python once you understand it:

>>> import json

>>> query = json.dumps( { "$and":[ { "$gt": {"age": 5} }, { "$not": 
{"name": "curly"} } ] } )

>>> query

'{"$and": [{"$gt": {"age": 5}}, {"$not": {"name": "curly"}}]}'

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to re-write this bash script in Python?

2015-07-31 Thread Grant Edwards
On 2015-07-31, Chris Angelico  wrote:

> There are two basic approaches to this kind of job.
>
> 1) Go through every line of bash code and translate it into
>equivalent Python code. You should then have a Python script which
>blindly and naively accomplishes the same goal by the same method.

In my experience, that works OK for C (with a little post-translation
tweaking and re-factoring).  But, it's a pretty lousy method for bash
scripts.  There are a lot of things that are trivial in Python and
complex/hard in bash (and a few vice versa), so a direct translation
usually turns out to be a mess.  You end up with a lot of Python code
where only a couple lines are really needed. You also end up doing
things in a bizarre manner in Python because the simple, easy, right
way wasn't supported by bash.

> 2) Start by describing what you want to accomplish, and then
>implement that in Python, using algorithmic notes from the bash code.
>
> The second option seems like a lot more work, but long-term it often
> isn't, because you end up with better code.

And the code works. :)

For bash, I really recommend 2)

-- 
Grant Edwards   grant.b.edwardsYow! GOOD-NIGHT, everybody
  at   ... Now I have to go
  gmail.comadminister FIRST-AID to my
   pet LEISURE SUIT!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to re-write this bash script in Python?

2015-07-31 Thread Chris Angelico
On Sat, Aug 1, 2015 at 12:26 AM, Grant Edwards  wrote:
> On 2015-07-31, Chris Angelico  wrote:
>
>> There are two basic approaches to this kind of job.
>>
>> 1) Go through every line of bash code and translate it into
>>equivalent Python code. You should then have a Python script which
>>blindly and naively accomplishes the same goal by the same method.
>
> In my experience, that works OK for C (with a little post-translation
> tweaking and re-factoring).  But, it's a pretty lousy method for bash
> scripts.  There are a lot of things that are trivial in Python and
> complex/hard in bash (and a few vice versa), so a direct translation
> usually turns out to be a mess.  You end up with a lot of Python code
> where only a couple lines are really needed. You also end up doing
> things in a bizarre manner in Python because the simple, easy, right
> way wasn't supported by bash.

Right. The two techniques I suggested can be generalized to any
language pair, but some work better this way than others do. Shell
scripts are something of a special case, because they're massively
optimized toward running other programs and piping output into input,
which applications languages like Python are not as good at; so the
naive transformation leads to code that goes to ridiculous lengths to
invoke five subprocesses and move data between them, where a more
intelligent approach might invoke one process, and then do the rest in
Python code. The trouble is, you really need to know what your code is
doing, because the non-naive transformation generally has a different
set of assumptions. For instance, the OP's shell script calls on the
'mailx' command. What's it do? Presumably it sends an email... well,
Python can do that. But what if the mailx command on this host has
been carefully configured to pass mail along via a specific relay
host, and that direct access on port 25 has been blocked? How would
you know? So it's not just a matter of translating the script, you
have to know its execution environment as well.

>> 2) Start by describing what you want to accomplish, and then
>>implement that in Python, using algorithmic notes from the bash code.
>>
>> The second option seems like a lot more work, but long-term it often
>> isn't, because you end up with better code.
>
> And the code works. :)
>
> For bash, I really recommend 2)

Yeah. You remove the ability for environmental changes to unexpectedly
affect the script, which is often a feature and not a bug.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python launcher problem

2015-07-31 Thread ElChino

Zachary Ware wrote:


On Jul 30, 2015 2:05 AM, "ElChino" mailto:elch...@cnn.cn>> 
wrote:
 >
 > If I in a cmd-shell (actually it is 4NT), do:
 >   c:>py -3 -V & python3 -V
 >
 > I get:
 >   Requested Python version (3) not installed  << ! from py -3 -V
 >   Python 3.5.0b2   << ! from the 2nd cmd.
 >
 > What nonsense is this? I DO HAVE Python3 in my %PATH.
 > A Registry setting gone haywire?

Did you perchance rename the installed 'python.exe' to 'python3.exe'?
That would be enough to break the launcher.  If you want a 'python3'
command, you can copy 'python.exe' to 'python3.exe', but 'python.exe'
needs to remain where it was.


That's what I did:

  ls -l f:/ProgramFiler/Python35/python*.exe
  -rwxr-xr-x 1 XX Administratorer 37664 May 31 04:18 
f:/ProgramFiler/Python35/python.exe
  -rwxr-xr-x 1 XX Administratorer 37664 May 31 04:18 
f:/ProgramFiler/Python35/python3.exe
  -rwxr-xr-x 1 XX Administratorer 37664 May 31 04:18 
f:/ProgramFiler/Python35/pythonw.exe

They all depends on:
 f:\ProgramFiler\Python35\python35.dll

The one and only python35.dll on this box. And also on PATH.

I took Ben Finney's advice to heart. From:
  http://code.activestate.com/lists/python-list/684547/


  Calling ‘python’ is now ambiguous, and with Python 2 slipping inexorably
  into the past, increasingly the ‘python’ command is the wrong choice for
  code that we want to survive in the future.

  I am seeing a growing call, with which I agree, to recommend explicitly
  calling ‘python2’ or ‘python3’ as commands.


That's why I made that copy; even if some of you find that strange on Windows.
I'll investigate is there's an issue with the Registry later.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Authenticate users using command line tool against AD in python

2015-07-31 Thread Prasad Katti
On Tuesday, July 28, 2015 at 12:56:29 AM UTC-7, Michael Ströder wrote:
> Prasad Katti wrote:
> > I am writing a command line tool in python to generate one time
> > passwords/tokens. The command line tool will have certain sub-commands like
> > --generate-token and --list-all-tokens for example. I want to restrict
> > access to certain sub-commands. In this case, when user tries to generate a
> > new token, I want him/her to authenticate against AD server first.
> 
> This does not sound secure:
> The user can easily use a modified copy of your script.
> 
> > I have looked at python-ldap and I am even able to bind to the AD server.
> > In my application I have a function
> > 
> > def authenticate_user(username, password): pass
> > 
> > which gets username and plain-text password. How do I use the LDAPObject 
> > instance to validate these credentials?
> 
> You probably want to use
> 
> http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject.simple_bind_s
> 
> Check whether password is non-zero before because most LDAP servers consider
> an empty password as anon simple bind even if the bind-DN is set.
> 
> Ciao, Michael.

Hi Michael,

Thank you for the reply. I ended up using simple_bind_s to authenticate users. 
But apparently it transmits plain-text password over the wire which can be 
easily sniffed using a packed sniffer. So I am looking at the start_tls_s 
method right now.

About your other comment; How could I make it more secure? I looked for ways to 
obfuscate the file, but I read that it is easy to reverse engineer. How is 
python code usually distributed? This seems like a fairly common requirement. 
Am I using the wrong tool (Python)? This is my first attempt at doing such a 
thing.

Appreciate your help!

-
Prasad
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Authenticate users using command line tool against AD in python

2015-07-31 Thread Michael Ströder
Prasad Katti wrote:
> On Tuesday, July 28, 2015 at 12:56:29 AM UTC-7, Michael Ströder wrote:
>> Prasad Katti wrote:
>>> I am writing a command line tool in python to generate one time
>>> passwords/tokens. The command line tool will have certain sub-commands like
>>> --generate-token and --list-all-tokens for example. I want to restrict
>>> access to certain sub-commands. In this case, when user tries to generate a
>>> new token, I want him/her to authenticate against AD server first.
>>
>> This does not sound secure:
>> The user can easily use a modified copy of your script.
>>
>>> I have looked at python-ldap and I am even able to bind to the AD server.
>>> In my application I have a function
>>>
>>> def authenticate_user(username, password): pass
>>>
>>> which gets username and plain-text password. How do I use the LDAPObject 
>>> instance to validate these credentials?
>>
>> You probably want to use
>>
>> http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject.simple_bind_s
>>
>> Check whether password is non-zero before because most LDAP servers consider
>> an empty password as anon simple bind even if the bind-DN is set.
> 
> Thank you for the reply. I ended up using simple_bind_s to authenticate
> users. But apparently it transmits plain-text password over the wire which
> can be easily sniffed using a packed sniffer. So I am looking at the
> start_tls_s method right now.

Yes, use TLS if the server supports it. Make sure to the option for CA
certificate. See Demo/initialize.py in the source distribution tar.gz.

> About your other comment; How could I make it more secure?

If you want something to be inaccessible for a user you have to spread the
functionality across separate components which communicate with each other. In
this communication you can implement authorization based on sufficiently
secure authentication.

Ciao, Michael.


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to rearrange array using Python?

2015-07-31 Thread Martin Schöön
Den 2015-07-31 skrev Thomas 'PointedEars' Lahn :
> Mark Lawrence wrote:
>> 
>> I'm not absolutely certain but I think you're into what's known as a
>> constraint satisfaction problem, in which case this
>> https://pypi.python.org/pypi/python-constraint/1.2 is as good a starting
>> point as any.  If I'm wrong we'll soon get told :)
>
> It is a CSP indeed, and as I was reading the OP I was thinking of SWI-
>
Thanks guys, I will follow up on the CSP lead. It is not something I
have prior experience of so it will be interesting.

> Please trim your quotes to the relevant minimum.
>
Indeed.

/Martin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to rearrange array using Python?

2015-07-31 Thread Martin Schöön
Den 2015-07-31 skrev Robin Koch :
> Am 30.07.2015 um 22:31 schrieb Martin Schöön:
>
>> Scores to the right show how many wishes are fulfilled in each room
>
> Is it possible the is a mistake in the sum column on the third row?
> Should the be a 1?

Indeed.
>
>> The goal is to re-shuffle the array to maximize this score.
>>
>> How do I go about doing that?
>
> Depending on how you store those wishes I'd think you can use
> random.shuffle()!?

When cruising the net yesterday I came across this and it looked to me
it does re-shuffle arrays but not in a way that helps me. Maybe I
am wrong.
>
> But do you think simply maximising the score is the optimal solution to 
> the problem?

It is a start. The result will no doubt need some human post-processing.
I am merely hoping to eliminate the grunt-work.

(There will be pre-processing too, correcting misspelled names etc...)

> That way some kids will get their both wishes fulfilled (s, e and p in 

> kids picking each other. Another thing one might want to takeinto 
> account. :-))
>
I did hint at differences between my example and the real problem...

/Martin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Convert between timezones

2015-07-31 Thread Akira Li
Thomas 'PointedEars' Lahn  writes:

> [X-Post & F'up2 comp.unix.shell]
>
> Chris Angelico wrote:
>
>> On Fri, Jul 31, 2015 at 6:15 PM, Cameron Simpson  wrote:
>>> Actually, bash has no timezone support but the date command _does_, and
>>> probably neither better nor worse than Python. All one has to do is set
>>> the TZ environment variable, eg (untested):
>>>
>>>  _year_gmt=$( TZ=GMT date +%Y )
>> 
>> That's assuming that it's converting against the current system
>> timezone. I don't know how you'd use `date` to convert between two
>> arbitrary timezones. […]
>
> With POSIX date(1), ISTM all you could do is set the system time and for an 
> additional invocation the TZ variable accordingly for output.
>
> 
>
> With GNU date(1):
>
> $ (tz_source="Asia/Dubai"; time_source="$(LC_TIME=C TZ=$tz_source date -d 
> "today 00:00 UTC+4" -Im)"; tz_target="America/Chicago"; echo "When it was 
> $time_source in $tz_source, it was $(LC_TIME=C TZ=$tz_target date -d 
> "$time_source") in $tz_target.")
> When it was 2015-07-31T00:00+0400 in Asia/Dubai, it was Thu Jul 30 15:00:00 
> CDT 2015 in America/Chicago.
>
> $ date --version
> date (GNU coreutils) 8.23
> […]
>

Here's a corresponding Python code. I haven't seen the beginning of the
discussion. I apologize if it has been already posted:

  #!/usr/bin/env python
  from datetime import datetime
  import pytz # $ pip install pytz
  
  source_tz, target_tz = map(pytz.timezone, ['Asia/Dubai', 'America/Chicago'])
  d = datetime.now(source_tz) # the current time in source_tz timezone
  midnight = source_tz.localize(datetime(d.year, d.month, d.day), is_dst=None)  
  
  fmt = "%Y-%m-%dT%H:%M:%S%z"
  print("When it was {:{fmt}} in {}, it was {:{fmt}} in {}".format(
  midnight, source_tz.zone, target_tz.normalize(midnight),
  target_tz.zone, fmt=fmt))

Output:

  When it was 2015-08-01T00:00:00+0400 in Asia/Dubai, it was
  2015-07-31T15:00:00-0500 in America/Chicago





-- 
https://mail.python.org/mailman/listinfo/python-list


How Do I ............?

2015-07-31 Thread Steve Burrus
How Do I access tkinter in Python 3.4 anyway? I've tried and  tried but cannot 
do it. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How Do I ............?

2015-07-31 Thread Jason Swails
On Fri, Jul 31, 2015 at 9:21 PM, Steve Burrus 
wrote:

> How Do I access tkinter in Python 3.4 anyway? I've tried and  tried but
> cannot do it.
>

​You import it.

If I play mind-reader for a second, I suspect you're trying to do in Python
3 what you did in Python 2.  That won't work -- the Tkinter module layout
has completely changed between Python 2 and Python 3.  For starters,
instead of doing:

import Tkinter

like you did in Python 2, you need to do

import tkinter

in Python 3.  There are several other changes, like standalone modules that
are not subpackages in tkinter (e.g., tkMessageBox is now
tkinter.messagebox).  To get a more complete list of name changes, you can
Google something like "tkinter python 2 to python 3", which will give you a
page like this:
http://docs.pythonsprints.com/python3_porting/py-porting.html.

Personally, I don't bother with that.  I have my working Tkinter code from
Python 2 and simply look at what the "2to3" module spits out during its
conversion.  That's often a good way to figure out "how the heck do I do
something in Python 3" when you have a script written for Python 2 that
works.

If that doesn't answer your question, then chances are your Python wasn't
built with Tkinter support (like the system Pythons in many Linux
distributions).  In that case you need to install the appropriate package
(depends on your distro).

​Or if that *still* doesn't answer your question, then provide enough
information so that someone can actually figure out what went wrong ;).​

HTH,
Jason
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Improper Django Project error (solved)

2015-07-31 Thread Gary Roach

On 07/30/2015 11:15 PM, dieter wrote:

Gary Roach  writes:

Being new to Django and Python, I have two projects setup side by
side, each in it's own virtualenv wrapper.
The twr_project is running Django 1.7, python 2.7 and is set up to
duplicate the 'Tango With Rango' tutorial.
The archivedb project is running Django 1.8, python 2.7 and is my
actual project.

As this is more a "Django" (than a general "Python") question,
you might get better help in a "Django" mailing list/support forum.

Actually you are dead correct on that.



Your "subject" indicates that you likely see (somewhere)
the "Django" error message "Improper Django Project error".
Likely, you have corrupted you "Django" project setup.
Read about how "Django" projects must look like and fix your setup.
The real problem was that the settings.py files for Django 1.7 and 1.8 
have some very significant differences with the format of the TEMPLATES 
= [] tuple. So the  problem's solved --- sort of .

I am using Ninja-IDE as my IDE. I like it a lot.

At this point both projects are essentially identical with the
exception of name changes. The twr project work down to the first
template inclusion ( index.html ). The archivedb project refuses to
find the home.html template file. The system layout is exactly the
same.

I wiped the home.html file and attempted to re-install it but my IDE
gave the following error window:


Sorry, either settings file or virtualenv are missingthese are
required for Django Plugin to work in thepresent version, we are
working on fixing this.


I have virtualenv installed and active and the settings file is
present.

You should ask this question on a "Ninja-IDE" mailing list/support forum.
Ninja_IDE is just reporting an apparent problem. The real problem is 
that the browser can't find the file. A Django problem.




--
https://mail.python.org/mailman/listinfo/python-list


Re: GvR Europython keynote described on lwn.net

2015-07-31 Thread Rick Johnson
On Friday, July 31, 2015 at 1:33:36 AM UTC-5, Paul Rubin wrote:
> The Dropbox cluster runs a modified Python 2.7, he said, which 
> elicited audience laughter. "I said it, it is no secret", he said.

Yep, even the BDFL is actively developing in 2.7! He's no fool.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to re-write this bash script in Python?

2015-07-31 Thread Cameron Simpson

On 31Jul2015 18:26, Chris Angelico  wrote:

On Fri, Jul 31, 2015 at 6:15 PM, Cameron Simpson  wrote:

For example, bash lacks
decent timezone support, so I can well believe random832's guess that
your five-hour offset is a simulation of that; but Python can do much
better work with timezones, so you can get that actually correct.



Actually, bash has no timezone support but the date command _does_, and
probably neither better nor worse than Python. All one has to do is set the
TZ environment variable, eg (untested):

 _year_gmt=$( TZ=GMT date +%Y )


That's assuming that it's converting against the current system
timezone. I don't know how you'd use `date` to convert between two
arbitrary timezones.


If date supports it I'd think one could use its -d option:

 utc=$( TZ=src_zone date -d source-time-spec -u +%Y%m%dT%H%M%SZ )

then:

 tz2=$( TZ=dst_zone date -d "$utc" )

Untested, but seems tractable.


But anyway, still justification to rewrite from
original spec rather than reimplementing the five-hour hack.


Yes indeed.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


debugging during package development

2015-07-31 Thread Seb
Hello,

It seems too cumbersome to have to update `sys.path` to include the
development tree of a package (and sub-packages) that's still very
young.  With lots of debugging to do, the last thing I'd want is to
worry about the search path.  So I've been searching for better ways to
work, but I can't seem hit the right keywords and come with all sorts of
tangentially related stuff.  I'm sure there must be some tool that sets
up the development environment when the package source is not on
`sys.path`.  Any advice on this topic would be appreciated.

Cheers,

-- 
Seb

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: debugging during package development

2015-07-31 Thread Ben Finney
Seb  writes:

> With lots of debugging to do, the last thing I'd want is to worry
> about the search path.

Short answer: you need ‘python3 ./setup.py develop’.

Medium-length answer: you need to add some infrastructure to get your
project to the point where you can run ‘python3 ./setup.py develop’.

Longer answer below.

> So I've been searching for better ways to work,
> but I can't seem hit the right keywords and come with all sorts of
> tangentially related stuff.

The Python module search path is an abstraction, with only a partial
relationship to the location of modules files in the filesystem.

The expectation is that a module (or a package of modules) will be
*installed* to a location already in the module search path (with
‘python ./setup.py .

This allows for cross-platform package management, especially on systems
that don't have a working OS package manager. The trouble is that it
does cause a significant learning curve for Python programmers, and is
an ongoing sore point of Python.

> I'm sure there must be some tool that sets up the development
> environment when the package source is not on `sys.path`. Any advice
> on this topic would be appreciated.

What you need is to tell Distutils which Python modules form your
project https://docs.python.org/3/library/distutils.html>.

Once you've got a working ‘setup.py’ for your project, run ‘python3
./setup.py develop’ to allow your packages to be run in-place while you
develop them.

-- 
 \“I think it would be a good idea.” —Mohandas K. Gandhi (when |
  `\asked what he thought of Western civilization) |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GvR Europython keynote described on lwn.net

2015-07-31 Thread Steven D'Aprano
On Sat, 1 Aug 2015 01:08 pm, Rick Johnson wrote:

> On Friday, July 31, 2015 at 1:33:36 AM UTC-5, Paul Rubin wrote:
>> The Dropbox cluster runs a modified Python 2.7, he said, which
>> elicited audience laughter. "I said it, it is no secret", he said.
> 
> Yep, even the BDFL is actively developing in 2.7! He's no fool.

Of course not. Dropbox pay him to work on their systems, and he wants to
keep his job.

Are you aware that Dropbox are heavily pushing for static type hints in
Python 3 as a prerequisite for them porting their masses of Python 2 code
to Python 3? That's one of the motives for the masses of effort put into
PEP 484, and its support PEPs, 482 and 483:

https://www.python.org/dev/peps/pep-0484/
https://www.python.org/dev/peps/pep-0483/
https://www.python.org/dev/peps/pep-0482/

As I understand it, Dropbox are paying Guido to work on static type hinting
for Python, with the emphasis on proving program correctness, not speed,
specifically because they want a big positive gain for moving to Python 3.



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 'open' is not defined

2015-07-31 Thread dieter
 writes:
> What about using the append function to remove duplicate outputs entered on 
> or thereafter line no. 9, i.e., 

As far as I know, "append" does not have intelligence in this respect.
Thus, if you need intelligence, your program must implement it.

In cases like yours, I use

  a) added = set(); l = list()
 for x ...
   if x not in added: added.insert(x); l.append(x)

or

  b) l = list()
 for x ...
   if x not in l: l.append(x)

Note that b) looks more natural - but I prefer a) (if the "x"s are
hashable) as it is slightly more efficient.


> LIST_APPEND(i) Calls list.append(TOS[-i], TOS). Used to implement list 
> comprehensions. While the appended value is popped off, the list object 
> remains on the stack so that it is available for further iterations of the 
> loop. URL link available at 
> https://docs.python.org/2.7/library/dis.html?highlight=append%20list#opcode-LIST_APPEND

Nore that the "dis" module shows you low level Python implementation details
(in fact the byte code of CPython's virtual maschine).
You are not supposed to make direct use of those in your own programs.
>
> What is the command line for such an append function?

As far as I know, there is none (interpreting "command line" as
"in my program").

The documentation above indicates that the virtual maschine's command
"LIST_APPEND" is used internally to implement Python's "list comprehension"
("[...x... for x in ... if ...]"). Maybe, it is used also for other
purposes, maybe not.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: debugging during package development

2015-07-31 Thread dieter
Seb  writes:

> It seems too cumbersome to have to update `sys.path` to include the
> development tree of a package (and sub-packages) that's still very
> young.  With lots of debugging to do, the last thing I'd want is to
> worry about the search path.  So I've been searching for better ways to
> work, but I can't seem hit the right keywords and come with all sorts of
> tangentially related stuff.  I'm sure there must be some tool that sets
> up the development environment when the package source is not on
> `sys.path`.  Any advice on this topic would be appreciated.

On "*nix" like systems, you can set "sys.path" via the envvar
"PYTHONPATH".

Note that "sys.path" needs only contain the top level packages - subpackages
are found automatically.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: debugging during package development

2015-07-31 Thread Terry Reedy

On 8/1/2015 12:21 AM, Seb wrote:


It seems too cumbersome to have to update `sys.path` to include the
development tree of a package (and sub-packages) that's still very
young.  With lots of debugging to do, the last thing I'd want is to
worry about the search path.  So I've been searching for better ways to
work, but I can't seem hit the right keywords and come with all sorts of
tangentially related stuff.  I'm sure there must be some tool that sets
up the development environment when the package source is not on
`sys.path`.  Any advice on this topic would be appreciated.


I am not sure what you are asking, but do you know about .pth files in 
site-packages?  For each python installed, I put in site-packages a 
python.pth containing one line "F:/python".  That file contains my 
project directory, call it x/  Running any version of python, 'from x 
import y' or 'from x.y import z' just works, the same as if x/ *were* in 
site-packages, and will be if I ever distribute the x package. No fuss 
with search paths; python plugs x into site-packages for me.


I do not know where this is documented.

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: Trouble getting to windows My Documents directory

2015-07-31 Thread random832
On Sat, Jul 11, 2015, at 03:28, Chris Warrick wrote:
> That’s not necessarily “older”.
> 
> Windows XP/7/8: My Documents
> Windows Vista/8.1: Documents

Mine's called Documents on 7 and 8. Is the system you got this
information from a new install or an upgrade? (It may also depend on
whether it's a new *user profile* or one from before the upgrade)

> As for localized versions, Vista and up do the translation in Windows
> Explorer but use English names on disk.
> 
> …but even with all that, users (or their administrators) can move the
> My Documents folder away from the home directory (to a file server,
> for example).

Yeah, the real point is that it can be an arbitrary location, but I was
just illustrating that even in *default* circumstances it won't always
be Documents
-- 
https://mail.python.org/mailman/listinfo/python-list