[issue32730] Allow py launcher to launch other registered Pythons

2019-12-12 Thread Tzu-ping Chung


Change by Tzu-ping Chung :


--
nosy: +uranusjr

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: The perils of multiple Pythons

2018-04-30 Thread Youta TAKAOKA
I am using pipenv...

http://docs.pipenv.org/en/latest/

It has bootstrap probrem.
pyenv solves it, but windows is NOT a first-class citizen for pyenv.

2018年5月1日(火) 14:00 Percival John Hackworth :

> On 30-Apr-2018, Chris Angelico wrote
> (in article):
>
> > https://xkcd.com/1987/
> >
> > So take-away is: On a Mac, just use Homebrew.
> >
> > (Cue the angry hordes telling me how wrong I am.)
> >
> > ChrisA
>
> This comic is talking about python on his Mac installed via home brew.
>
> I chose to keep the 2.[67] versions installed with the base install and
> install the V3 versions from the Python web site. They install in
> /Library/Frameworks/Python.
>
> https://www.python.org/downloads/
>
> I could have also used the 2.7.15 version on that site, but I'll keep with
> the 2.7.10 that's part of the base install of 10.10. I deleted the
> versions
> installed by port and homebrew so all the cruft is gone.
>
> Then I upgraded pip from the ancient version to 10.0.1 using easy_install.
> python3 and and python3.6 are soft links to the /Library/Frameworks
> version.
> My /etc/paths.d/python3 config file adds /Library/Frameworks to the global
> path, but I think that's MacOS specific.
>
> There's more than one way to do this, but it's for a personal machine, not
> a
> global environment that multiple developers will use, so YMMV.
>
> --
> DeeDee, don't press that button! DeeDee! NO! Dee...
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The perils of multiple Pythons

2018-04-30 Thread Terry Reedy

On 4/30/2018 5:03 PM, Chris Angelico wrote:


Yep. Munroe (the author of XKCD) is clearly using a Mac, though, and
Macs don't ship with Python 3.5+. So there's a bootstrapping problem:
how do you install a newer Python? There are about half a dozen
options.


I think the situation is improved with 3.7 Mac installer, which includes 
and installs an up-to-date tcl/tk, instead of telling people, on a 
separate page that many do not go to, to separately install a less 
ancient tcl/tk from ActiveState, which some have trouble doing, or 
switch to another distribution, which has its own issues.



--
Terry Jan Reedy

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


Re: The perils of multiple Pythons

2018-04-30 Thread Terry Reedy

On 4/30/2018 5:03 PM, Chris Angelico wrote:

On Tue, May 1, 2018 at 6:59 AM, justin walters
 wrote:

With Python 3.5+, venv is a built in module. If using a venv, default to
using the binary in the venv.

That's what I do anyways.


Yep. Munroe (the author of XKCD) is clearly using a Mac, though, and
Macs don't ship with Python 3.5+. So there's a bootstrapping problem:
how do you install a newer Python? There are about half a dozen
options.

ChrisA




--
Terry Jan Reedy

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


Re: The perils of multiple Pythons

2018-04-30 Thread Rich Shepard

On Mon, 30 Apr 2018, justin walters wrote:


Yes, you can create a virtual env with all of the global packages. Though,
you would probably want to run: `python3 -m venv
~/development/project/venv` to put the virtualenv files in their own
directory.


Justin,

  That's what I thought to be the case after reading the python docs about
the venv module.

Thanks!

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


Re: The perils of multiple Pythons

2018-04-30 Thread justin walters
On Mon, Apr 30, 2018 at 3:24 PM, Rich Shepard 
wrote:

> On Mon, 30 Apr 2018, justin walters wrote:
>
> With Python 3.5+, venv is a built in module. If using a venv, default to
>> using the binary in the venv. That's what I do anyways.
>>
>
>   I'm running Python3-3.6.5 and have a developing application in
> ~/development/project/. Can I run 'python3 -m venv ~/development/project/'
> to install it in a directory with existing modules?
>
> Rich
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Yes, you can create a virtual env with all of the global packages. Though,
you would probably want to run:
`python3 -m venv ~/development/project/venv` to put the virtualenv files in
their own directory. Then you
just need to activate it with: `source venv/bin/activate`. As long as the
virtualenv is activated, you can interact
with it in the same way you would with the system/global environment. i.e.
running the interpreter will use the binary
from the virtualenv, pip install will install in the virtualenv only, etc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The perils of multiple Pythons

2018-04-30 Thread Rich Shepard

On Mon, 30 Apr 2018, justin walters wrote:


With Python 3.5+, venv is a built in module. If using a venv, default to
using the binary in the venv. That's what I do anyways.


  I'm running Python3-3.6.5 and have a developing application in
~/development/project/. Can I run 'python3 -m venv ~/development/project/'
to install it in a directory with existing modules?

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


Re: The perils of multiple Pythons

2018-04-30 Thread Chris Angelico
On Tue, May 1, 2018 at 7:16 AM, Tim Chase  wrote:
> On 2018-05-01 06:40, Chris Angelico wrote:
 >> https://xkcd.com/1987/
>>>
>>> I feel like this problem is pretty handily solved by virtual
>>> environments. Also, if a single project requires all of this,
>>> perhaps Python isn't the best choice for the project.
>>
>> Some of it is definitely solved by venvs. But which Python binary do
>> you use?
>
> Pretty sure that all venvs I've used know their corresponding binary.
> But...

Right. It's locked in when you create it. But you still have to pick.

>> And is venv installed? Do you need to install virtualenv
>> first? How do you...
>
> Is it virtualenv?  Or are you using virtualenvwrapper which, last I
> checked doesn't work in ksh (OpenBSD's default shell) without jumping
> through hoops and getting external ksh-specific files?  Or are you
> using pipenv?  Or `python -m venv`?  So many different flavors. :-(
>

Exactly! Personally, I don't use any of them except "python3 -m venv",
but I also have some custom bash scripting to make the activation and
deactivation happen automatically.

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


Re: The perils of multiple Pythons

2018-04-30 Thread Tim Chase
On 2018-05-01 06:40, Chris Angelico wrote:
>>> >> https://xkcd.com/1987/
>>
>> I feel like this problem is pretty handily solved by virtual
>> environments. Also, if a single project requires all of this,
>> perhaps Python isn't the best choice for the project.  
> 
> Some of it is definitely solved by venvs. But which Python binary do
> you use? 

Pretty sure that all venvs I've used know their corresponding binary.
But...

> And is venv installed? Do you need to install virtualenv
> first? How do you... 

Is it virtualenv?  Or are you using virtualenvwrapper which, last I
checked doesn't work in ksh (OpenBSD's default shell) without jumping
through hoops and getting external ksh-specific files?  Or are you
using pipenv?  Or `python -m venv`?  So many different flavors. :-(

-tkc




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


Re: The perils of multiple Pythons

2018-04-30 Thread Chris Angelico
On Tue, May 1, 2018 at 6:59 AM, justin walters
 wrote:
> With Python 3.5+, venv is a built in module. If using a venv, default to
> using the binary in the venv.
>
> That's what I do anyways.

Yep. Munroe (the author of XKCD) is clearly using a Mac, though, and
Macs don't ship with Python 3.5+. So there's a bootstrapping problem:
how do you install a newer Python? There are about half a dozen
options.

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


Re: The perils of multiple Pythons

2018-04-30 Thread justin walters
On Mon, Apr 30, 2018 at 1:40 PM, Chris Angelico  wrote:

> On Tue, May 1, 2018 at 6:22 AM, justin walters
>  wrote:
> > On Mon, Apr 30, 2018 at 10:32 AM, Chris Angelico 
> wrote:
> >
> >> On Tue, May 1, 2018 at 3:30 AM, Ned Batchelder 
> >> wrote:
> >> > On 4/30/18 1:15 PM, Chris Angelico wrote:
> >> >>
> >> >> https://xkcd.com/1987/
> >> >>
> >> >> So take-away is: On a Mac, just use Homebrew.
> >> >>
> >> >> (Cue the angry hordes telling me how wrong I am.)
> >> >>
> >> >
> >> > My take-away (though not really, since I held this view before this
> >> > morning): pick a way and stick to it.
> >>
> >> Well, yes. Until that way stops working, in which case you have to try
> >> another way. And that's when the problems start...
> >>
> >> ChrisA
> >> --
> >> https://mail.python.org/mailman/listinfo/python-list
> >>
> >
> > I feel like this problem is pretty handily solved by virtual
> environments.
> > Also, if a single project requires all of this,
> > perhaps Python isn't the best choice for the project.
>
> Some of it is definitely solved by venvs. But which Python binary do
> you use? And is venv installed? Do you need to install virtualenv
> first? How do you... etc, etc, etc, etc, etc. Endless fun!
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>

With Python 3.5+, venv is a built in module. If using a venv, default to
using the binary in the venv.

That's what I do anyways.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The perils of multiple Pythons

2018-04-30 Thread Chris Angelico
On Tue, May 1, 2018 at 6:22 AM, justin walters
 wrote:
> On Mon, Apr 30, 2018 at 10:32 AM, Chris Angelico  wrote:
>
>> On Tue, May 1, 2018 at 3:30 AM, Ned Batchelder 
>> wrote:
>> > On 4/30/18 1:15 PM, Chris Angelico wrote:
>> >>
>> >> https://xkcd.com/1987/
>> >>
>> >> So take-away is: On a Mac, just use Homebrew.
>> >>
>> >> (Cue the angry hordes telling me how wrong I am.)
>> >>
>> >
>> > My take-away (though not really, since I held this view before this
>> > morning): pick a way and stick to it.
>>
>> Well, yes. Until that way stops working, in which case you have to try
>> another way. And that's when the problems start...
>>
>> ChrisA
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
> I feel like this problem is pretty handily solved by virtual environments.
> Also, if a single project requires all of this,
> perhaps Python isn't the best choice for the project.

Some of it is definitely solved by venvs. But which Python binary do
you use? And is venv installed? Do you need to install virtualenv
first? How do you... etc, etc, etc, etc, etc. Endless fun!

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


Re: The perils of multiple Pythons

2018-04-30 Thread justin walters
On Mon, Apr 30, 2018 at 10:32 AM, Chris Angelico  wrote:

> On Tue, May 1, 2018 at 3:30 AM, Ned Batchelder 
> wrote:
> > On 4/30/18 1:15 PM, Chris Angelico wrote:
> >>
> >> https://xkcd.com/1987/
> >>
> >> So take-away is: On a Mac, just use Homebrew.
> >>
> >> (Cue the angry hordes telling me how wrong I am.)
> >>
> >
> > My take-away (though not really, since I held this view before this
> > morning): pick a way and stick to it.
>
> Well, yes. Until that way stops working, in which case you have to try
> another way. And that's when the problems start...
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>

I feel like this problem is pretty handily solved by virtual environments.
Also, if a single project requires all of this,
perhaps Python isn't the best choice for the project.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The perils of multiple Pythons

2018-04-30 Thread Chris Angelico
On Tue, May 1, 2018 at 3:30 AM, Ned Batchelder  wrote:
> On 4/30/18 1:15 PM, Chris Angelico wrote:
>>
>> https://xkcd.com/1987/
>>
>> So take-away is: On a Mac, just use Homebrew.
>>
>> (Cue the angry hordes telling me how wrong I am.)
>>
>
> My take-away (though not really, since I held this view before this
> morning): pick a way and stick to it.

Well, yes. Until that way stops working, in which case you have to try
another way. And that's when the problems start...

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


Re: The perils of multiple Pythons

2018-04-30 Thread Ned Batchelder

On 4/30/18 1:15 PM, Chris Angelico wrote:

https://xkcd.com/1987/

So take-away is: On a Mac, just use Homebrew.

(Cue the angry hordes telling me how wrong I am.)



My take-away (though not really, since I held this view before this 
morning): pick a way and stick to it.


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


The perils of multiple Pythons

2018-04-30 Thread Chris Angelico
https://xkcd.com/1987/

So take-away is: On a Mac, just use Homebrew.

(Cue the angry hordes telling me how wrong I am.)

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


[issue32730] Allow py launcher to launch other registered Pythons

2018-03-03 Thread Steve Dower

Steve Dower  added the comment:

Since I took the time to do a brain dump of my thinking here, feel free to 
review/contribute to https://github.com/zooba/PyLauncher/wiki

Note that the code in that repo doesn't match the wiki page, and while I think 
it's good code I do now think it's the wrong approach. So ignore that and just 
read the "spec"

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32730] Allow py launcher to launch other registered Pythons

2018-02-02 Thread Terry J. Reedy

Change by Terry J. Reedy :


--
versions:  -Python 3.4, Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32730] Allow py launcher to launch other registered Pythons

2018-01-31 Thread Steve Dower

Steve Dower  added the comment:

Yep, this was part of the plan. Just hasn't happened yet (it probably requires 
a significant rewrite of the launcher which nobody has volunteered to do or 
found the time for).

I thought I had another open bug on this too... if someone finds it, feel free 
to dup this one.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32730] Allow py launcher to launch other registered Pythons

2018-01-31 Thread Peter Suter

New submission from Peter Suter <petsu...@gmail.com>:

For example Anaconda Python is registered under 
HKEY_LOCAL_MACHINE\Software\Python\ContinuumAnalytics\Anaconda36-64\ as 
described in PEP 514 "Python registration in the Windows registry" .

The py launcher from PEP 397 however ignores that and only considers 
HKEY_LOCAL_MACHINE\Software\Python\PythonCore\ registrations.

There seems to be no mechanism to register Anaconda Python with the py 
launcher. Anaconda considers this a bug in the Python launcher. 
https://github.com/ContinuumIO/anaconda-issues/issues/149#issuecomment-361922640

Shouldn't this be possible? Maybe via py.ini [defaults]?

--
components: Windows
messages: 311338
nosy: paul.moore, petsu...@gmail.com, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Allow py launcher to launch other registered Pythons
type: enhancement
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32730>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Check Python version from inside script? Run Pythons script in v2 compatibility mode?

2017-07-07 Thread Ian Kelly
On Fri, Jul 7, 2017 at 3:49 PM,   wrote:
> Is there any particular reason the Windows python does it that way?  
> Certainly it wouldn't be too difficult to include a "python2.exe" and 
> "python3.exe", even as symbolic links.

Windows associates file types with applications by extension. When you
double click on "holygrail.py" should it open with python2.exe or
python3.exe? In Unix this is solved with a shebang, so the main
purpose of py.exe is to do the same: it's the standard open handler
for .py files and it delegates out the actual execution to the
appropriate Python version by examining the file for version hints.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check Python version from inside script? Run Pythons script in v2 compatibility mode?

2017-07-07 Thread Rick Johnson
On Friday, July 7, 2017 at 2:54:04 AM UTC-5, Steve D'Aprano wrote:
> [...] That's now not only backwards compatible, but it is
> forward compatible: if Python changes in the future to
> bring reduce back into the built-in functions, your code
> will automatically keep working.

If python starts going all paranoid schizoid on us, the few
remaining holdovers from the good old days will be choosing
another language. But don't worry Steven, even if i find a
new favorite language, i will always drop in preiodically to
say hi. ;-)

> > Additional question: Is there a way to execute a python
> > script with v3 python engine in v2 compatibility mode? 

Nope. Even the though the most hated software developer in
history offers a compatibility mode for their users, Python
does not. Python's philosophy is that you will accept
Python3, or you will suffer...

As for myself, i'm waiting for Python4. I will skip right
over Python3. I say, let the other saps to suffer the
migration headaches, because i don't need them. I'm too busy
getting stuff done.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check Python version from inside script? Run Pythons script in v2 compatibility mode?

2017-07-07 Thread sohcahtoa82
On Friday, July 7, 2017 at 11:58:33 AM UTC-7, eryk sun wrote:
> On Fri, Jul 7, 2017 at 7:53 AM, Steve D'Aprano
>  wrote:
> > On Fri, 7 Jul 2017 04:30 pm, Ben S. wrote:
> >
> >> Is there a way to execute a python script with v3 python engine in v2
> >> compatibility mode? I am thinking about a command parameter like 
> >> (python.exe
> >> is v3.*):
> >>
> >>   python.exe -execute_as_v2 myscript.py
> >
> > No. Python 3 is always Python 3, and Python 2 is always Python 2. But what 
> > you
> > can do is install both, and then call
> >
> > python2.exe myscript.py
> >
> > python3.exe anotherscript.py
> 
> Windows Python installs two loaders for each version of Python:
> python.exe and pythonw.exe. No links or copies are created for
> pythonX[w].exe, pythonX.Y[w].exe, or pythonX.Y-32[w].exe. Instead,
> there are separate py.exe and pyw.exe launchers that use the registry
> to find and execute a loader for a given version, e.g.
> 
> py -2 myscript.py
> py -3.6-32 anotherscript.py
> 
> As of 3.6, the py launcher defaults to the highest version of Python 3
> that's installed. 64-bit Python is preferred on 64-bit Windows. The
> default version can be overridden by setting the PY_PYTHON environment
> variable.
> 
> That said, you don't have to manually run a script as an argument of
> py.exe or python.exe. For a default Python 3 installation, if the
> PATHEXT environment variable contains ".PY", then you can run
> "script.py" as
> 
> script arg1 ... argN
> 
> in CMD or PowerShell. If a script has a Unix shebang, the launcher
> will read it to run the required version of Python, if that version is
> installed.

Is there any particular reason the Windows python does it that way?  Certainly 
it wouldn't be too difficult to include a "python2.exe" and "python3.exe", even 
as symbolic links.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check Python version from inside script? Run Pythons script in v2 compatibility mode?

2017-07-07 Thread eryk sun
On Fri, Jul 7, 2017 at 7:53 AM, Steve D'Aprano
 wrote:
> On Fri, 7 Jul 2017 04:30 pm, Ben S. wrote:
>
>> Is there a way to execute a python script with v3 python engine in v2
>> compatibility mode? I am thinking about a command parameter like (python.exe
>> is v3.*):
>>
>>   python.exe -execute_as_v2 myscript.py
>
> No. Python 3 is always Python 3, and Python 2 is always Python 2. But what you
> can do is install both, and then call
>
> python2.exe myscript.py
>
> python3.exe anotherscript.py

Windows Python installs two loaders for each version of Python:
python.exe and pythonw.exe. No links or copies are created for
pythonX[w].exe, pythonX.Y[w].exe, or pythonX.Y-32[w].exe. Instead,
there are separate py.exe and pyw.exe launchers that use the registry
to find and execute a loader for a given version, e.g.

py -2 myscript.py
py -3.6-32 anotherscript.py

As of 3.6, the py launcher defaults to the highest version of Python 3
that's installed. 64-bit Python is preferred on 64-bit Windows. The
default version can be overridden by setting the PY_PYTHON environment
variable.

That said, you don't have to manually run a script as an argument of
py.exe or python.exe. For a default Python 3 installation, if the
PATHEXT environment variable contains ".PY", then you can run
"script.py" as

script arg1 ... argN

in CMD or PowerShell. If a script has a Unix shebang, the launcher
will read it to run the required version of Python, if that version is
installed.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check Python version from inside script? Run Pythons script in v2 compatibility mode?

2017-07-07 Thread Marko Rauhamaa
Pavol Lisy :

> On 7/7/17, Steve D'Aprano  wrote:
>
>> import sys
>> if sys.version_info >= (3,):  # the comma is important
>> print("version 3")
>
> But be careful inside script! It could live long enough to see python4
> :)

That's a serious concern. An application doesn't know about Python's
future. What would be needed is:

   import sys
   try:
   sys.require_version((3, 4, 2))
   except NotSupportedException:
   sys.stderr.write("Sorry :(\n")
   sys.exit(1)


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


Re: Check Python version from inside script? Run Pythons script in v2 compatibility mode?

2017-07-07 Thread Pavol Lisy
On 7/7/17, Steve D'Aprano  wrote:

> import sys
> if sys.version_info >= (3,):  # the comma is important
> print("version 3")

But be careful inside script! It could live long enough to see python4 :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check Python version from inside script? Run Pythons script in v2 compatibility mode?

2017-07-07 Thread Steve D'Aprano
On Fri, 7 Jul 2017 04:30 pm, Ben S. wrote:

> Can I somehow check from inside a Python script if the executing Python engine
> is major version v2 or v3?

Yes you can, but generally speaking you shouldn't.

import sys
if sys.version_info >= (3,):  # the comma is important
print("version 3")

else:
print("version 2")


But keep in mind that your code must be syntactically valid for the running
version regardless of the result of the test. This will **NOT** work:

import sys
if sys.version_info >= (3,):  # the comma is important
print("version 3")

else:
print "version 2"  # Python 2 syntax


Earlier I said that in general you shouldn't test for the version. Normally you
should test for a specific feature, not for the version number. For example,
suppose I want to use the "reduce()" function. In Python 2 it is a built-in
function, but in Python 3 it is moved into the functools module.

Don't do this:

if sys.version_info >= (3,):
from functools import reduce


This is better:

try:
reduce
except NameError:
# reduce no longer defined as a built-in
from functools import reduce


That's now not only backwards compatible, but it is forward compatible: if
Python changes in the future to bring reduce back into the built-in functions,
your code will automatically keep working.

Dealing with syntax changes in hybrid version 2 + 3 code is quite tricky. It can
be done, but it is painful, even for experts.

> Additional question:
> Is there a way to execute a python script with v3 python engine in v2
> compatibility mode? I am thinking about a command parameter like (python.exe
> is v3.*):
> 
>   python.exe -execute_as_v2 myscript.py

No. Python 3 is always Python 3, and Python 2 is always Python 2. But what you
can do is install both, and then call 

python2.exe myscript.py

python3.exe anotherscript.py



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Check Python version from inside script? Run Pythons script in v2 compatibility mode?

2017-07-07 Thread Jeremiah Dodds
"Ben S. via Python-list"  writes:

> Can I somehow check from inside a Python script if the executing Python 
> engine is major version v2 or v3?

import sys
sys.version_info[0]

(If you just need to print() consistently, you should follow Terry's advice)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Check Python version from inside script? Run Pythons script in v2 compatibility mode?

2017-07-07 Thread Terry Reedy

On 7/7/2017 2:30 AM, Ben S. via Python-list wrote:

Can I somehow check from inside a Python script if the executing Python engine 
is major version v2 or v3?

I am thinking about a code similar to

if (os.python-majorversion<3)
   print hello
else
   print (hello)


For this, just use print('hello').
Checkout 'from __future__ import print_function'
check __future__ module for spelling.
Checkout sys.version, sys.hexversion, platform module,

Some import will tell you.

try:
import tkinter as tk
pyversion = 3
except ImportError:
import Tkinter as tk
pyversion = 2



Additional question:
Is there a way to execute a python script with v3 python engine in v2 
compatibility mode?
I am thinking about a command parameter like (python.exe is v3.*):

   python.exe -execute_as_v2 myscript.py


No.


--
Terry Jan Reedy

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


Check Python version from inside script? Run Pythons script in v2 compatibility mode?

2017-07-07 Thread Ben S. via Python-list
Can I somehow check from inside a Python script if the executing Python engine 
is major version v2 or v3?

I am thinking about a code similar to

if (os.python-majorversion<3)
  print hello
else
  print (hello)


Additional question:
Is there a way to execute a python script with v3 python engine in v2 
compatibility mode?
I am thinking about a command parameter like (python.exe is v3.*):

  python.exe -execute_as_v2 myscript.py 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basics of pythons 

2017-04-21 Thread tommy yama
Hi there,

For what, you want to learn?





On Sat, Apr 22, 2017 at 1:10 AM, Thomas Nyberg  wrote:

> On 04/21/2017 08:06 AM, harounelyaako...@gmail.com wrote:
> > Hey everyone, I'm willing to learn python , ant advices ?
> > Thanks in advance
> >
> Here is a tutorial:
>
> https://docs.python.org/3/tutorial/
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Basics of pythons 

2017-04-21 Thread Thomas Nyberg
On 04/21/2017 08:06 AM, harounelyaako...@gmail.com wrote:
> Hey everyone, I'm willing to learn python , ant advices ? 
> Thanks in advance 
> 
Here is a tutorial:

https://docs.python.org/3/tutorial/
-- 
https://mail.python.org/mailman/listinfo/python-list


Basics of pythons 

2017-04-21 Thread harounelyaakoubi
Hey everyone, I'm willing to learn python , ant advices ? 
Thanks in advance 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Compiling new Pythons on old Windows compilers

2017-03-12 Thread Michael Torrie
On 03/12/2017 09:26 PM, Michael Torrie wrote:
> On 03/12/2017 02:45 PM, eryk sun wrote:
>> On Sun, Mar 12, 2017 at 5:02 PM, Eric Frederich
>>  wrote:
>>> Any idea why compatibility was dropped recently?  There used to be a PC
>>> directory with different VS directories in the source tree, now it isn't
>>> there any more.
>>
>> CPython 3.5+ uses the Universal CRT on Windows, which is a system
>> component in Vista and later (a recommended update for Windows
>> versions prior to 10). See this blog post:
>>
>> http://stevedower.id.au/blog/building-for-python-3-5

Did I read that right that you can link python statically so you can use
the new universal runtime-based python to extend an app with another
runtime (but requiring administrator access somehow?)?

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


Re: Compiling new Pythons on old Windows compilers

2017-03-12 Thread Michael Torrie
On 03/12/2017 02:45 PM, eryk sun wrote:
> On Sun, Mar 12, 2017 at 5:02 PM, Eric Frederich
>  wrote:
>> Any idea why compatibility was dropped recently?  There used to be a PC
>> directory with different VS directories in the source tree, now it isn't
>> there any more.
> 
> CPython 3.5+ uses the Universal CRT on Windows, which is a system
> component in Vista and later (a recommended update for Windows
> versions prior to 10). See this blog post:
> 
> http://stevedower.id.au/blog/building-for-python-3-5

Hmm, this is going to be a huge problem for Python users that work with
proprietary software that is fixed to specific versions of MSCVRT.  The
idea that everyone should just update their builds to the latest
universal runtime is a good one, but it's just not going to happen
across the entire software industry anytime soon.  Especially for
existing releases.  Looks like Python 3 is a no go for Eric.

The runtime mixing issue has always been a problem for Windows
developers.  Not sure the universal runtime really solves it!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Compiling new Pythons on old Windows compilers

2017-03-12 Thread eryk sun
On Sun, Mar 12, 2017 at 5:02 PM, Eric Frederich
 wrote:
> Any idea why compatibility was dropped recently?  There used to be a PC
> directory with different VS directories in the source tree, now it isn't
> there any more.

CPython 3.5+ uses the Universal CRT on Windows, which is a system
component in Vista and later (a recommended update for Windows
versions prior to 10). See this blog post:

http://stevedower.id.au/blog/building-for-python-3-5
-- 
https://mail.python.org/mailman/listinfo/python-list


Compiling new Pythons on old Windows compilers

2017-03-12 Thread Eric Frederich
There is a commercial application which allows customizations through a C
API.
There are 3 different releases of this application each compiled with
different versions of Visual Studio, 2008, 2010, and 2012.

I'd like to release a customization which embeds a Python interpreter, but
I'd like to use the same Python release across all 3 application versions.
There may be versions of Python like 2.7 or something which compile on all
3 of those Visual Studio releases, but I'd really prefer to use Python 3.

Any idea why compatibility was dropped recently?  There used to be a PC
directory with different VS directories in the source tree, now it isn't
there any more.

Thanks,
~Eric
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-12-13 Thread Steve Dower

Steve Dower added the comment:

Fixed for 3.5.3, 3.6.1 and default.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-12-13 Thread Roundup Robot

Roundup Robot added the comment:

New changeset c3da1ee47e6b by Steve Dower in branch '3.5':
Issue #26071: Fixes preprocessor definition and rebuilds 
wininst-14.0[-amd64].exe
https://hg.python.org/cpython/rev/c3da1ee47e6b

New changeset 0528a6743018 by Steve Dower in branch '3.6':
Issue #26071: Fixes preprocessor definition and rebuilds 
wininst-14.0[-amd64].exe
https://hg.python.org/cpython/rev/0528a6743018

New changeset 4e9d899fcb65 by Steve Dower in branch 'default':
Issue #26071: Fixes preprocessor definition and rebuilds 
wininst-14.0[-amd64].exe
https://hg.python.org/cpython/rev/4e9d899fcb65

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-12-13 Thread Ned Deily

Ned Deily added the comment:

Since we are two days from the final release, the fix requires rebuilding and 
replacing a binary file in the source repo, and you state (in related 
Issue28680): "Considering we've gone through all of 3.5 and 3.6 with very few 
people noticing (and as far as I'm aware, completely able to fix it 
themselves), it may not make the initial 3.6 release.", I would prefer to hold 
this for 3.6.1.

--
priority: release blocker -> deferred blocker
stage: resolved -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-12-13 Thread Steve Dower

Steve Dower added the comment:

Looks like I acknowledged the error in the patch and then didn't fix it when I 
applied it.

The change needed here is what Mark describes above, plus recompiling the 
executable stubs. Or alternatively, I can probably just edit out the bytes in 
the existing stub for 3.6.0 and fix it properly for 3.6.1.

Ned - thoughts? This regressed from 3.4 and has not worked properly for both 
architectures (simultaneously) since 3.5.

--
keywords: +3.4regression
nosy: +larry, ned.deily
priority: normal -> release blocker
resolution: fixed -> 
status: closed -> open
versions: +Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-12-13 Thread Christoph Gohlke

Christoph Gohlke added the comment:

The applied patch breaks bdist_wininst installers for 64-bit Python. See 
.

--
nosy: +cgohlke

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Pythons for .Net

2016-09-05 Thread Denis Akhiyarov
On Saturday, September 3, 2016 at 8:53:18 PM UTC-5, Steve D'Aprano wrote:
> On Sat, 3 Sep 2016 12:34 pm, Denis Akhiyarov wrote:
> 
> > Finally if anyone can contact Christian Heimes (Python Core Developer),
> > then please ask him to reply on request to update the license to MIT:
> > 
> > https://github.com/pythonnet/pythonnet/issues/234
> > 
> > He is the only contributor that prevents updating to MIT license.
> 
> 
> I have emailed him off-list.
> 
> Thanks for the information on PythonNet, Denis.
> 
> 
> 
> -- 
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.

Emailing and twitter did not help either.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pythons for .Net

2016-09-03 Thread Steve D'Aprano
On Sat, 3 Sep 2016 12:34 pm, Denis Akhiyarov wrote:

> Finally if anyone can contact Christian Heimes (Python Core Developer),
> then please ask him to reply on request to update the license to MIT:
> 
> https://github.com/pythonnet/pythonnet/issues/234
> 
> He is the only contributor that prevents updating to MIT license.


I have emailed him off-list.

Thanks for the information on PythonNet, Denis.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Pythons for .Net

2016-09-02 Thread Denis Akhiyarov
On Sunday, July 24, 2016 at 11:30:09 PM UTC-5, Steven D'Aprano wrote:
> Yes, I said Pythons plural :-)
> 
> For those wanting to use Python on .Net or Mono, there is some good news.
> 
> Firstly, the venerable old "Python for .Net" project is still alive, and now
> supports up to Python 3.5 on .Net or Mono. PythonNet, as this is known,
> integrates the regular CPython interpreter with .Net or Mono.
> 
> Secondly, we can also expect that IronPython will have a new lease of life.
> Continuing on the work of their predecessor, Jeff Hardy, the IronPython
> project now has two tech leads who will carry it forward: Alex Earl and
> Benedikt Eggers.
> 
> https://thelasttechie.com/2016/07/24/its-back-python-for-net/
> 
> 
> IronPython is a reimplementation of Python, written in C# as managed code
> for .Net. It doesn't use a GIL, and is sometimes considered a little faster
> than CPython, so this is good news for the Python ecosystem.
> 
> IronPython:
> http://ironpython.net/
>  
> Python for .Net:
> https://github.com/pythonnet/pythonnet
> http://pythonnet.github.io/
> https://pypi.python.org/pypi/pythonnet
> 
> 
> 
> 
> -- 
> Steven
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.

Hello Steven,

I'm one of the contributors to pythonnet. We strive for compatibility with 
IronPython, but also have a simplified embedding interface and support Python 3 
+ C-Extensions such as numpy, scipy, sklearn.

If anyone is interested in learning pythonnet, then try it out from PYPI or 
github and use this tutorial:

https://pythonnet.github.io/readme.html

There is also a mailing list and a tag on stackoverflow:

https://mail.python.org/mailman/listinfo/pythondotnet
http://stackoverflow.com/questions/tagged/python.net

Finally if anyone can contact Christian Heimes (Python Core Developer), then 
please ask him to reply on request to update the license to MIT:

https://github.com/pythonnet/pythonnet/issues/234

He is the only contributor that prevents updating to MIT license.

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


Pythons for .Net

2016-07-24 Thread Steven D'Aprano
Yes, I said Pythons plural :-)

For those wanting to use Python on .Net or Mono, there is some good news.

Firstly, the venerable old "Python for .Net" project is still alive, and now
supports up to Python 3.5 on .Net or Mono. PythonNet, as this is known,
integrates the regular CPython interpreter with .Net or Mono.

Secondly, we can also expect that IronPython will have a new lease of life.
Continuing on the work of their predecessor, Jeff Hardy, the IronPython
project now has two tech leads who will carry it forward: Alex Earl and
Benedikt Eggers.

https://thelasttechie.com/2016/07/24/its-back-python-for-net/


IronPython is a reimplementation of Python, written in C# as managed code
for .Net. It doesn't use a GIL, and is sometimes considered a little faster
than CPython, so this is good news for the Python ecosystem.

IronPython:
http://ironpython.net/
 
Python for .Net:
https://github.com/pythonnet/pythonnet
http://pythonnet.github.io/
https://pypi.python.org/pypi/pythonnet




-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-16 Thread Roundup Robot

Roundup Robot added the comment:

New changeset daa6fdaf9835 by Steve Dower in branch '3.5':
Issue #26071: bdist_wininst created binaries fail to start and find 32bit Python
https://hg.python.org/cpython/rev/daa6fdaf9835

New changeset db74f3a4cbeb by Steve Dower in branch 'default':
Issue #26071: bdist_wininst created binaries fail to start and find 32bit Python
https://hg.python.org/cpython/rev/db74f3a4cbeb

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-16 Thread Steve Dower

Steve Dower added the comment:

Applied the patch and rebuilt the stubs, so this will show up in 3.5.2 and 3.6.

--
assignee:  -> steve.dower
resolution:  -> fixed
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-11 Thread Steve Dower

Steve Dower added the comment:

The downside of the preprocessor - no errors when you spell an ifdef wrong ;)

It looks good to me.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-10 Thread Mark Hammond

Mark Hammond added the comment:

> Mark said the "built binary links against the DLL version of the CRT
> but I just checked in 3.5.1 that you actually didn't switch that
> one to link against vcruntime140.dll like you did with everything else

Yeah, I didn't dig too much further here, but I'm fairly sure that "static crt" 
has been a thing for quite a while now for that stub (there are comments about 
that around the SetStdHandle calls in that file). I suspect it was accidentally 
lost in one of the build system fixups that happened (which seem great and a 
vast improvement!)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-10 Thread Eryk Sun

Eryk Sun added the comment:

> why isn't the directory containing the loaded DLL searched 
> for dependencies?

That's possible. The loader provides several ways to go about solving this 
problem. The directory of the DLL can be added to the search path if you use 
LoadLibraryEx with the flag LOAD_WITH_ALTERED_SEARCH_PATH and use an absolute 
path. Python already does this for loading extension modules. 

If we didn't have to worry about older systems, in Windows 8/10 (and Vista/7 
with KB2533623), the loader supports a set of flags that give detailed control 
of the DLL path, including LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR. Individual 
directories can be added via AddDllDirectory and enabled via the flag 
LOAD_LIBRARY_SEARCH_USER_DIRS. Default flags can be set via 
SetDefaultDllDirectories, which affects LoadLibrary as well as LoadLibraryEx. 

On a related note, it would be nice to modify ctypes to call LoadLibraryEx 
instead of LoadLibrary. If the flags value is 0 the two calls are identical, so 
it wouldn't be a disruptive change. The existing dlopen "mode" parameter can be 
used for the flags, since it isn't used on Windows currently.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-10 Thread Steve Dower

Steve Dower added the comment:

Ultimately, launching python.exe is better than loading python##.dll here 
because it avoids DLL planting vulnerabilities, but I'm honestly a little 
surprised still that LoadLibrary won't resolve vcruntime in this case. Been a 
while since I looked, and I haven't had a chance to check for this yet, but why 
isn't the directory containing the loaded DLL searched for dependencies?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-10 Thread Steve Dower

Steve Dower added the comment:

> The directory of the DLL can be added to the search path if you use 
> LoadLibraryEx with the flag LOAD_WITH_ALTERED_SEARCH_PATH and use an absolute 
> path. 

That sounds like the better fix then. I thought there was something along those 
lines available.

We already use the full path to load it - can someone test this change? If not 
I'll give it a go later today.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-09 Thread Mark Hammond

New submission from Mark Hammond:

Binaries created by bdist_wininst fail on 3.5+ for 2 reasons:

* The built binary links against the DLL version of the CRT. This means the 
binary will typically fail to start as the CRT DLL isn't found.

* When looking for 32bit Python versions, it fails to take the recent "-32" 
change for the registry key, so it tells you no Python is installed.

This patch:
* Uses the static CRT, which IIRC, was the case in previous Python versions.
* Changes directory to the directory with pythonxx.dll before attempting to 
loadlibrary it - this allows the loadlibrary to succeed as the CRT DLL in that 
directory is found.
* Appends "-32" to registry keys on 32bit builds.

With these patches I can successfully get a pywin32 build working and 
installing.

Steve (or anyone), what do you think?

(Note that the attached patch does *not* include a newly built wininst-14.exe, 
but that would obviously need to be updated before checking in.)

--
components: Windows
files: bdist.patch
keywords: patch
messages: 257879
nosy: mhammond, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: bdist_wininst created binaries fail to start and find 32bit Pythons
type: behavior
versions: Python 3.5, Python 3.6
Added file: http://bugs.python.org/file41561/bdist.patch

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26071>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-09 Thread Steve Dower

Steve Dower added the comment:

Looks good to me. Feel free to check it in, Mark, or one of us will get to it 
if you're not set up for committing right now.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-09 Thread Eryk Sun

Eryk Sun added the comment:

I would call SetDllDirectory instead of changing the current directory. This 
replaces the current directory in the DLL search. Then call 
SetDllDirectory(NULL) to restore the default before returning. 

When you say "the CRT assembly", you're talking about vcruntime140.dll, right? 
This module implements exceptions, setjmp/longjmp, and other functions that are 
closely coupled with the VC++ version, but most of the universal CRT is 
implemented in the system DLL ucrtbase.dll. 

vcruntime was initially linked statically everywhere, but that was a problem 
for extension modules, since each instance was taking a fiber locale storage 
slot. 

However, it really should be static for the bdist_wininst installer. I believe 
Steve had the link configuration customized as a partially static build that 
linked dynamically with ucrtbase.dll. This benefits from continuous CRT bug 
fixes and security updates. To configure this he added ucrt[d].lib as a 
dependency and ignored the default library libucrt[d].lib. See the following 
diff for the changes that were made to revert this:

https://hg.python.org/cpython/diff/8374472c6a6e/PCbuild/pyproject.props

--
nosy: +eryksun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-09 Thread Steve Dower

Steve Dower added the comment:

In this case, it needs to load vcruntime for the python##.dll, so linking isn't 
going to make any difference. We need to statically link the loader, since it 
will be run independently and can't have any dependencies, but when it finds a 
Python install and loads the DLL directly it's not finding the vcruntime 
adjacent to the DLL. We'd have to statically link python##.dll.

SetDllDirectory would also work, though it's a little more complicated to get 
right. It's probably worth it here though to set the search path around the 
load in this case, as we know that nobody else is expecting the value to not 
change. However, it may break other loads if python##.dll calls it or makes 
assumptions about the search path (which it almost certainly does). Setting the 
working directory is likely to lead to a more reliable initial state.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-09 Thread Eryk Sun

Eryk Sun added the comment:

> We'd have to statically link python##.dll.

I was talking about the partially static build that you used for 
wininst-14.0-amd64.exe in rc3, in which vcruntime is linked statically but ucrt 
is linked dynamically (actually to the api-ms-win-crt-* API sets). But is there 
a bad assumption there? I was only thinking about installing to systems with 
Python 3.5+, on which ucrtbase.dll is guaranteed to be in System32, but this 
installer should work for older systems that don't have the universal CRT 
update, right?

> However, it may break other loads if python##.dll calls it or 
> makes assumptions about the search path

I don't understand. It would be pretty broken if python##.dll depends on the 
current directory. All SetDllDirectory does is swap in the target directory in 
place of the current directory in the DLL search path. I made the suggestion 
because it's cleaner to surgically change only what the system loader sees, 
rather than changing the current directory, which affects everything. The 
LoadLibrary docs recommend using SetDllDirectory instead of changing the 
current directory. Using AddDllDirectory would be better, but that's only 
available on updated Vista/7 systems (KB2533623).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26071] bdist_wininst created binaries fail to start and find 32bit Pythons

2016-01-09 Thread Eryk Sun

Eryk Sun added the comment:

Steve, I think I understand the linking problem now -- in terms of the bad 
assumption I mentioned in the previous message. Mark said the "built binary 
links against the DLL version of the CRT", but I just checked in 3.5.1 that you 
actually didn't switch that one to link against vcruntime140.dll like you did 
with everything else, so he's only referring to the api-set-ms-win-crt 
dependencies. This would only fail on systems that don't have the universal CRT 
update. I thought he meant the executable was typically failing on all systems 
that don't have Visual Studio, which installs vcruntime140.dll in System32.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25843] unexpected output using pythons ternary operator in combination with lambda

2015-12-11 Thread Tijs Van Oevelen

Tijs Van Oevelen added the comment:

Apologies for not posting a summary of the bug. I really had no idea how to 
describe the problem, as it is over my head. I could only refer to my question 
on Stack Overflow that triggered the discovery of the bug.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25843] unexpected output using pythons ternary operator in combination with lambda

2015-12-11 Thread Tijs Van Oevelen

Tijs Van Oevelen added the comment:

It's definitely also in 3.4 by the way.

--
versions: +Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25843] unexpected-output-using-pythons-ternary-operator-in-combination-with-lambda

2015-12-11 Thread Tijs Van Oevelen

Changes by Tijs Van Oevelen :


--
nosy:  -Tijs Van Oevelen

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25843] unexpected-output-using-pythons-ternary-operator-in-combination-with-lambda

2015-12-11 Thread Tijs Van Oevelen

New submission from Tijs Van Oevelen:

The bug is described on Stack Overflow in length:

http://stackoverflow.com/questions/34100732/unexpected-output-using-pythons-ternary-operator-in-combination-with-lambda

--
messages: 256229
nosy: Tijs Van Oevelen
priority: normal
severity: normal
status: open
title: 
unexpected-output-using-pythons-ternary-operator-in-combination-with-lambda
type: behavior
versions: Python 3.4

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25843>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25843] unexpected-output-using-pythons-ternary-operator-in-combination-with-lambda

2015-12-11 Thread R. David Murray

R. David Murray added the comment:

For reference, the minimal reproducer is:

>>> f1, f2 = lambda: 1, lambda: 1.0
>>> f2()
1

The cause (according to the answer in the link) is that the two lambda's 
incorrectly compare as equal and end up sharing the same code object...one of 
the inequality checks is line number, so this only happens when the lambdas are 
on the same line.

Aside: it would be helpful if people would post bug summaries instead of just 
linking to an outside article.  The link is of course very valuable 
information, but it saves us time if the poster summarizes the bug so the right 
people know to look at it.

--
nosy: +Tijs Van Oevelen, r.david.murray
versions: +Python 2.7, Python 3.5, Python 3.6 -Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25843] unexpected output using pythons ternary operator in combination with lambda

2015-12-11 Thread Ethan Furman

Changes by Ethan Furman <et...@stoneleaf.us>:


--
title: 
unexpected-output-using-pythons-ternary-operator-in-combination-with-lambda -> 
unexpected output using pythons ternary operator in combination with lambda

___
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25843>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: What the Pythons docs means by container ?

2015-02-20 Thread Rustom Mody
On Wednesday, February 18, 2015 at 2:51:34 AM UTC+5:30, candide wrote:
 Official Python documentation very frequently invokes a mysterious 
 *container* data structure. The PLR manual explains :
 
 --
 Some objects contain references to other objects; these are called containers.
 --
 
 So containers contain : what a great definition!
 
 To be more precise, the container wording suggests a data structure 
 _storing_ items somewhere and that the number of items in the container has a 
 memory footprint. This is exacly the container definition given by the ISO 
 C++ standard (cf.  
 http://www.open-std.org/jtc1/sc22/open/n2356/lib-containers.html) :
 
 --
 Containers are objects that store other objects.
 --
 
 So I was considering a Python range object NOT being a container: indeed, 
 range(10**6) does NOT store 10**6 integers and range(10**6) has a small 
 memory footprint in the contrary to the associated list :
 
 --
  from sys import getsizeof
  r = range(10**6)
  L = list(r)
  getsizeof(r)
 24
  getsizeof(L)
 4500056
  
 --
 
 Then, mining the official docs, I realized that the collections module 
 provides an ABC Container class allowing you to know if a given object is a 
 container or not. And what a surprise, a range object IS a container !
 
 --
  from collections import Container
  r = range(10**6)
  isinstance(r, Container)  

 True  
   
 
 --
 
 So, what documentation means by the generic term of container? 
 
 I agree with the existence of built-in containers (list, dict and the like) 
 and the existence of special containers provided by the collections module 
 (most of them inheriting from a built-in container) but I can't find a 
 precise definition explaining what is a container object or a container 
 type. 
 
 The docs at :
 
 https://docs.python.org/3.2/reference/datamodel.html#object.__contains__
 
 explains that a container is an object compatible with the membership test 
 (in and not in operators). So a file is a container ? recall a file supports 
 the in operator :
 
 --
 $ touch my_test.txt
 $ python3.2
 Python 3.2.3 (default, Feb 28 2014, 00:22:33) 
 [GCC 4.7.2] on linux2
 Type help, copyright, credits or license for more information.
  42 in open(my_test.txt)
 False
  from collections import Container
  isinstance(open(my_test.txt), Container)
 False
  
 --

+1

See https://www.python.org/dev/peps/pep-0246/

There Guido says something much better is about to happen

Best as I know its not happened yet...

[Personal note: I am currently trying to teach python
and the lack of a standardized place for all protocols (in python's duck typing 
sense)
is quite a slow-down-er for me and my class
]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What the Pythons docs means by container ?

2015-02-20 Thread Ian Kelly
On Fri, Feb 20, 2015 at 4:37 AM, Rustom Mody rustompm...@gmail.com wrote:
 See https://www.python.org/dev/peps/pep-0246/

 There Guido says something much better is about to happen

 Best as I know its not happened yet...

Well, since that PEP was rejected we now have ABCs. Although PEP 3119
wasn't written until a couple of years later, so who knows if that's
what he had in mind.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What the Pythons docs means by container ?

2015-02-19 Thread perfectican
in duck-typing, any objects can acts as Container. but only difference is type 
that we need to consider as a Container or not.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What the Pythons docs means by container ?

2015-02-19 Thread Mark Lawrence

On 19/02/2015 10:59, perfectican wrote:

in duck-typing, any objects can acts as Container. but only difference is type 
that we need to consider as a Container or not.



This comment makes no sense to me at all.  Could you please rephrase it, 
preferably supplying some context at the same time.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: What the Pythons docs means by container ?

2015-02-18 Thread MRAB

On 2015-02-18 02:14, candide wrote:

Le mercredi 18 février 2015 01:50:16 UTC+1, Chris Angelico a écrit :


So, what's a container? It's a thing that you put other objects
into.


I agree with this approach. The important point to consider here is
the last word in your definition : into. There is the container and
there is the content (the objects into). The so-called built-in
containers (list, string, etc) are in conformance with this view.
Now, regarding a range object as a container disagrees completely
with the definition given in the PLR : there is no contents and hence
there is no container. For instance, range(10**6) doesn't hold any
kind of object, there are no reference to the int objects 0, 1, 2,
... As the range's docstring explains, range returns a VIRTUAL
sequence.


It's a virtual, read-only container that contains integers.

Try comparing range(10) with tuple(range(10)). Both contain integers.
Both have a length. Both can be indexed.
--
https://mail.python.org/mailman/listinfo/python-list


Re: What the Pythons docs means by container ?

2015-02-18 Thread Ethan Furman
On 02/17/2015 06:14 PM, candide wrote:
 Le mercredi 18 février 2015 01:50:16 UTC+1, Chris Angelico a écrit :
 

 So, what's a container? It's a thing that you put other objects into.
 
 I agree with this approach. The important point to consider here is the last 
 word in your definition : into.

You are getting bogged down with implementation details; not even dict, list, 
nor tuple actually have the contained
objects inside their memory space.  What they have is a record of what objects 
they contain, and methods to work with
those objects.

Whether a contained object exists before it is accessed is irrelevant, is an 
implementation detail, and is a level of
optimization.

--
~Ethan~



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What the Pythons docs means by container ?

2015-02-18 Thread Ian Kelly
On Wed, Feb 18, 2015 at 11:04 AM, MRAB pyt...@mrabarnett.plus.com wrote:
 On 2015-02-18 02:14, candide wrote:

 Le mercredi 18 février 2015 01:50:16 UTC+1, Chris Angelico a écrit :

 So, what's a container? It's a thing that you put other objects
 into.


 I agree with this approach. The important point to consider here is
 the last word in your definition : into. There is the container and
 there is the content (the objects into). The so-called built-in
 containers (list, string, etc) are in conformance with this view.
 Now, regarding a range object as a container disagrees completely
 with the definition given in the PLR : there is no contents and hence
 there is no container. For instance, range(10**6) doesn't hold any
 kind of object, there are no reference to the int objects 0, 1, 2,
 ... As the range's docstring explains, range returns a VIRTUAL
 sequence.

 It's a virtual, read-only container that contains integers.

 Try comparing range(10) with tuple(range(10)). Both contain integers.
 Both have a length. Both can be indexed.

Another way to look at range is as an optimization of the range from
Python 2, which returned an actual list of integers. Most callers are
only interested in iterating over the container and don't have to be
concerned whether the result is actually a list or just something that
looks enough like one for their purposes. From that point of view, a
range object is still a container.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What the Pythons docs means by container ?

2015-02-18 Thread Terry Reedy

On 2/18/2015 2:43 PM, Ethan Furman wrote:


Whether a contained object exists before it is accessed is irrelevant, is an 
implementation detail, and is a level of
optimization.


Is in not irrelevant in that virtual collections can be infinite.

--
Terry Jan Reedy

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


Re: What the Pythons docs means by container ?

2015-02-18 Thread Steven D'Aprano
Terry Reedy wrote:

 On 2/18/2015 2:43 PM, Ethan Furman wrote:
 
 Whether a contained object exists before it is accessed is irrelevant,
 is an implementation detail, and is a level of optimization.
 
 Is in not irrelevant in that virtual collections can be infinite.

Hmmm. I'm not sure I believe that. Can you enumerate all of the items and
see if there actually is an infinite number of them? I'll wait... 

*wink*

But seriously... Ethan's comment shouldn't be interpreted as meaning that
virtual containers are exactly the same as concrete ones. Ethan's comment
should be understand in terms that whether something is a container or not
is *not* connected to whether it is a concrete data structure like a list
or an array, or a virtual/lazy/on-demand data structure like (x)range.

In Python ABC terms, I believe that the, or at least a, defining
characteristic of containers is that they implement the in operator. If
there is some value X for which `X in OBJ` succeeds, then OBJ may be a
container.




-- 
Steven

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


Re: What the Pythons docs means by container ?

2015-02-18 Thread Chris Angelico
On Thu, Feb 19, 2015 at 11:05 AM, Ben Finney ben+pyt...@benfinney.id.au wrote:
 Hmmm. I'm not sure I believe that. Can you enumerate all of the items
 and see if there actually is an infinite number of them? I'll wait...

 A mathematician should know better: you don't need to enumerate to
 demonstrate a collection is infinite.

But you may have to demonstrate a 1:1 correspondence with counting
numbers, to prove that it's countably infinite. And that's pretty much
what the enumerate() function does, so that's enumeration right?

Bizarre pseudo-logic for the win.

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


Re: What the Pythons docs means by container ?

2015-02-18 Thread Ben Finney
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info writes:

 Terry Reedy wrote:

  […] virtual collections can be infinite.

 Hmmm. I'm not sure I believe that. Can you enumerate all of the items
 and see if there actually is an infinite number of them? I'll wait...

A mathematician should know better: you don't need to enumerate to
demonstrate a collection is infinite.

Provided, of course, that the collection is *virtual* — so virtual that
it's not actually implemented on hardware :-)

-- 
 \“If you have the facts on your side, pound the facts. If you |
  `\ have the law on your side, pound the law. If you have neither |
_o__)   on your side, pound the table.” —anonymous |
Ben Finney

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


Re: What the Pythons docs means by container ?

2015-02-17 Thread Chris Angelico
On Wed, Feb 18, 2015 at 11:30 AM, candide c.cand...@laposte.net wrote:
 Python Language Referenceb (PLR) is expected to give formal and acurate 
 definition, not descriptive term to talk about things.

In a lot of ways, technically accurate definitions can be useless,
where sloppy but descriptive terms are useful. For instance, we can
distinguish between an integer (doesn't contain things) and a list
(does contain things), and then categorize sets, tuples, and
SimpleNamespace()s with the latter, and exceptions, strings, and
functions with the former. But technically, an exception has a
reference to something else (a traceback), and could thus be said to
contain it, and a function always has a reference to its global
namespace (which itself contains that function), etc, so any specific
and formal definition is likely to be quite useless. Also, a string
can be said to contain a whole lot of substrings - bcd in abcde
is True - even though those substrings don't actually have to exist as
objects, so it's impossible for the string to retain references to
those substrings. Even worse, a string always contains *itself*, which
makes a definition based on the 'in' operator conflict entirely with a
definition based on a real-world analogy involving a box with stuff in
it.

So, what's a container? It's a thing that you put other objects into.
That's all the definition you really need, most of the time. If you
want a better definition, you first need to ask yourself: What aspect
of containerness matters here? Why do you need to distinguish
container from non-container? If you want to know whether the 'in'
operator can be used, then ask whether the 'in' operator can be used.
If you want to know whether it's possible for this object to be part
of a reference cycle, ask whether it's possible for this object to be
part of a reference cycle. If you want to know whether this is a
useful way to return multiple results from a function, then ... you
get the idea. They're all very different aspects of containers, and
not all containers have all those aspects. (For instance, a tuple
can't [1] have a reference to itself. You can't get a reference cycle
without having some other type of object, such as a list, involved.)
Is this a container? isn't often a useful question to ask.

ChrisA

[1] You can use C code to create a tuple containing itself, but in C,
you're most welcome to shoot yourself in the foot in other ways, too.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What the Pythons docs means by container ?

2015-02-17 Thread candide
Le mercredi 18 février 2015 01:50:16 UTC+1, Chris Angelico a écrit :

 
 So, what's a container? It's a thing that you put other objects into.

I agree with this approach. The important point to consider here is the last 
word in your definition : into. There is the container and there is the 
content (the objects into). The so-called built-in containers (list, string, 
etc) are in conformance with this view. Now, regarding a range object as a 
container disagrees completely with the definition given in the PLR : there is 
no contents and hence there is no container. For instance, range(10**6) doesn't 
hold any kind of object, there are no reference to the int objects 0, 1, 2, ... 
As the range's docstring explains, range returns a VIRTUAL sequence.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What the Pythons docs means by container ?

2015-02-17 Thread Terry Reedy

On 2/17/2015 4:21 PM, candide wrote:

Official Python documentation very frequently invokes a mysterious *container* 
data structure. The PLR manual explains :


I use 'collection' rather than 'container'.


--
Some objects contain references to other objects; these are called containers.
--


A mathematical set has 'members', like a club.  Objects, like people, 
can be members of 0 to many clubs.  Containing 'references',  and the 
nature of said references is a computer implementation issue.  There are 
no 'references' in math.


--
Terry Jan Reedy

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


Re: What the Pythons docs means by container ?

2015-02-17 Thread candide
 
 Shrug. It is a useful descriptive term when you want to talk about things. You

Python Language Referenceb (PLR) is expected to give formal and acurate 
definition, not descriptive term to talk about things.

 might keep in mind that a container's _primary_ purpose is usually its 
 containing function. So a list. But not so some arbitrary object, even though 

containing function ? Does PLR document this containing function?


 most objects have references to other objects.

have or contain ;)  ? 


 
 Duck typing again: this bases the term on behaviour, not memory use.

Again this is undocumented. Compare with the definition of duck-typed 
iterators, cf. https://docs.python.org/3.2/library/stdtypes.html#iterator-types

On the other hand, recall that the new behavior of range since Python 3 is 
motivated by memory considerations, quoted from the doc : 




The advantage of the range type over a regular list or tuple is that a range 
object will always take the same (small) amount of memory, no matter the size 
of the range it represents (as it only stores the start, stop and step values, 
calculating individual items and subranges as needed).



 Neither of these things has a .__contains__ method; the in operator falls 
 back to iteration if there is no .__contains__.


The documentation is fuzzy and inconsistant here: containers are supposed to 
implement the membership test, dixit the doc. 


 
 A container usually lets you test in in a nondestructive/nonconsuming

usually ? I need something more acurate ;)


 fashion. An iterable can be ined, but it will be consumed. So iterables are 
 not, of themselves, containers.

First this is undocumented. Second, range objects are considered as iterable by 
the doc. And you are telling us that an iterable is not a container. And range 
has a __contains__ method.

 
 So, range? A range object knows its bounds and state; it can answer in 
 without consuming the range iteration, so it is effectively a container.

Again, this no-consuming feature is completely undocumented. And unconvincing: 
do you regard a linked list as not being a container ?

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


Re: What the Pythons docs means by container ?

2015-02-17 Thread Cameron Simpson

On 17Feb2015 13:21, candide c.cand...@laposte.net wrote:

Official Python documentation very frequently invokes a mysterious *container* 
data structure. The PLR manual explains :
--
Some objects contain references to other objects; these are called containers.
--


And this is the basic thing, as you understand.


So containers contain : what a great definition!


Shrug. It is a useful descriptive term when you want to talk about things. You 
might keep in mind that a container's _primary_ purpose is usually its 
containing function. So a list. But not so some arbitrary object, even though 
most objects have references to other objects.


[...]

So I was considering a Python range object NOT being a container: indeed, 
range(10**6) does NOT store 10**6 integers and range(10**6) has a small memory 
footprint

[...]

Then, mining the official docs, I realized that the collections module provides 
an ABC Container class allowing you to know if a given object is a container or 
not. And what a surprise, a range object IS a container !


You might find it duck types like other containers.

[...]

The docs at :
https://docs.python.org/3.2/reference/datamodel.html#object.__contains__
explains that a container is an object compatible with the membership test (in 
and not in operators).


Duck typing again: this bases the term on behaviour, not memory use.


So a file is a container ? recall a file supports the in operator :


Yes and no. A file can be iterated. in on a file reads the file as a side 
effect of iterating over it. A generator also supports in, again by 
iteration.


Neither of these things has a .__contains__ method; the in operator falls 
back to iteration if there is no .__contains__.


A container usually lets you test in in a nondestructive/nonconsuming 
fashion. An iterable can be ined, but it will be consumed. So iterables are 
not, of themselves, containers.


So, range? A range object knows its bounds and state; it can answer in 
without consuming the range iteration, so it is effectively a container.


Hoping this helps.

Cheers,
Cameron Simpson c...@zip.com.au

[Alain] had been looking at his dashboard, and had not seen me, so I
ran into him. - Jean Alesi on his qualifying prang at Imola '93
--
https://mail.python.org/mailman/listinfo/python-list


What the Pythons docs means by container ?

2015-02-17 Thread candide
Official Python documentation very frequently invokes a mysterious *container* 
data structure. The PLR manual explains :

--
Some objects contain references to other objects; these are called containers.
--

So containers contain : what a great definition!

To be more precise, the container wording suggests a data structure _storing_ 
items somewhere and that the number of items in the container has a memory 
footprint. This is exacly the container definition given by the ISO C++ 
standard (cf.  
http://www.open-std.org/jtc1/sc22/open/n2356/lib-containers.html) :

--
Containers are objects that store other objects.
--

So I was considering a Python range object NOT being a container: indeed, 
range(10**6) does NOT store 10**6 integers and range(10**6) has a small memory 
footprint in the contrary to the associated list :

--
 from sys import getsizeof
 r = range(10**6)
 L = list(r)
 getsizeof(r)
24
 getsizeof(L)
4500056
 
--

Then, mining the official docs, I realized that the collections module provides 
an ABC Container class allowing you to know if a given object is a container or 
not. And what a surprise, a range object IS a container !

--
 from collections import Container
 r = range(10**6)
 isinstance(r, Container)
 
True


--

So, what documentation means by the generic term of container? 

I agree with the existence of built-in containers (list, dict and the like) and 
the existence of special containers provided by the collections module (most of 
them inheriting from a built-in container) but I can't find a precise 
definition explaining what is a container object or a container type. 

The docs at :

https://docs.python.org/3.2/reference/datamodel.html#object.__contains__

explains that a container is an object compatible with the membership test (in 
and not in operators). So a file is a container ? recall a file supports the in 
operator :

--
$ touch my_test.txt
$ python3.2
Python 3.2.3 (default, Feb 28 2014, 00:22:33) 
[GCC 4.7.2] on linux2
Type help, copyright, credits or license for more information.
 42 in open(my_test.txt)
False
 from collections import Container
 isinstance(open(my_test.txt), Container)
False
 
--




Reference of interest :

http://blog.wachowicz.eu/?p=132
http://stackoverflow.com/questions/11575925/what-exactly-are-containers-in-python-and-what-are-all-the-python-container

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


Re: Using pythons smtp server

2013-12-14 Thread Irmen de Jong
On 14-12-2013 1:46, Dennis Lee Bieber wrote:

   About then, I discovered the first two significant books on Python at
 Computer Literacy, and that an Amiga binary was available (Python 1.4, I
 think -- thanks, Irmin).

You're welcome, but my name is spelled Irmen, with an 'e' ;-)

Cheers
Irmen


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


Re: Using pythons smtp server

2013-12-13 Thread Grant Edwards
On 2013-12-13, Vincent Davis vinc...@vincentdavis.net wrote:

 I have an app that generates a file one a day and would like to email it
 using pythons SMTP server.

You don't send mail using an SMTP server.  You receive mail using an
SMTP server.

 http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
 The documentation is kinda sparse and I cant seem to find any good examples.

 Basically what I want to do; when my app runs it would initiate a SMTP
 server, send the attachment and shutdown the SMTP after.

Newsgroups: comp.lang.python
From: Grant Edwards invalid@invalid.invalid
Subject: Re: Using pythons smtp server
References: mailman.4046.1386908855.18130.python-l...@python.org
Followup-To:

On 2013-12-13, Vincent Davis vinc...@vincentdavis.net wrote:

 I have an app that generates a file one a day and would like to email
 it using pythons SMTP server.

You don't send mail using an SMTP server.  You receive mail using an 
SMTP server.  You send mail using an SMTP client.

 http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
 The documentation is kinda sparse and I cant seem to find any good examples.

 Basically what I want to do; when my app runs it would initiate a SMTP
 server, send the attachment and shutdown the SMTP after.

https://www.google.com/search?q=python+send+email+smtp

-- 
Grant Edwards   grant.b.edwardsYow! The PINK SOCKS were
  at   ORIGINALLY from 1952!!
  gmail.comBut they went to MARS
   around 1953!!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using pythons smtp server

2013-12-13 Thread Vincent Davis

 You don't send mail using an SMTP server.  You receive mail using an
 SMTP server.
 ​​


Um maybe, I guess it is a matter of perspective.

Let me rephrase my question. ​​I want to send an email using python but do
not want to use an external service. Does python have the ability to send
emails without installing additional software or using an external
server/service?
Maybe I am wrong, I thought examples like s = smtplib.SMTP('localhost')
​​ are using a local(outside of python) smtp server, like postfix.




Vincent Davis
720-301-3003


On Fri, Dec 13, 2013 at 9:40 AM, Grant Edwards invalid@invalid.invalidwrote:

 On 2013-12-13, Vincent Davis vinc...@vincentdavis.net wrote:

  I have an app that generates a file one a day and would like to email it
  using pythons SMTP server.

 You don't send mail using an SMTP server.  You receive mail using an
 SMTP server.

  http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
  The documentation is kinda sparse and I cant seem to find any good
 examples.
 
  Basically what I want to do; when my app runs it would initiate a SMTP
  server, send the attachment and shutdown the SMTP after.

 Newsgroups: comp.lang.python
 From: Grant Edwards invalid@invalid.invalid
 Subject: Re: Using pythons smtp server
 References: mailman.4046.1386908855.18130.python-l...@python.org
 Followup-To:

 On 2013-12-13, Vincent Davis vinc...@vincentdavis.net wrote:

  I have an app that generates a file one a day and would like to email
  it using pythons SMTP server.

 You don't send mail using an SMTP server.  You receive mail using an
 SMTP server.  You send mail using an SMTP client.

  http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
  The documentation is kinda sparse and I cant seem to find any good
 examples.
 
  Basically what I want to do; when my app runs it would initiate a SMTP
  server, send the attachment and shutdown the SMTP after.

 https://www.google.com/search?q=python+send+email+smtp

 --
 Grant Edwards   grant.b.edwardsYow! The PINK SOCKS were
   at   ORIGINALLY from 1952!!
   gmail.comBut they went to MARS
around 1953!!
 --
 https://mail.python.org/mailman/listinfo/python-list

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


Re: Using pythons smtp server

2013-12-13 Thread Vincent Davis
Obviously I don't really know how this works. I have used python to send
email using my smtp server (whatever that may be gmail, postfix..)
But I don't want to do that. After a little more research I think what I
need to do is lookup the MX address of the address I want to send the email
too.
Then submit the email to that address using smtplib.SMTP
​Do I have that right?
​


Vincent Davis
720-301-3003


On Fri, Dec 13, 2013 at 10:24 AM, Dennis Lee Bieber
wlfr...@ix.netcom.comwrote:

 On Thu, 12 Dec 2013 18:01:58 -0700, Vincent Davis
 vinc...@vincentdavis.net declaimed the following:

 I have an app that generates a file one a day and would like to email it
 using pythons SMTP server.
 http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
 The documentation is kinda sparse and I cant seem to find any good
 examples.
 
 Basically what I want to do; when my app runs it would initiate a SMTP
 server, send the attachment and shutdown the SMTP after.
 

 I suspect you don't want the server per se -- that's more a unit
 for
 receiving SMTP mail (sure, you can start it, but then you have to send the
 email to IT so it can relay it to the next server in the line).

 Look into the smtplib module (section 20.12 in the v2.7.2
 documentation) in order to send email TO a mail server
 --
 Wulfraed Dennis Lee Bieber AF6VN
 wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/

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

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


Re: Using pythons smtp server

2013-12-13 Thread Grant Edwards
On 2013-12-13, Vincent Davis vinc...@vincentdavis.net wrote:

 Obviously I don't really know how this works. I have used python to
 send email using my smtp server (whatever that may be gmail,
 postfix..) But I don't want to do that. After a little more research
 I think what I need to do is lookup the MX address of the address I
 want to send the email too.

 Then submit the email to that address using smtplib.SMTP

Maybe.  In theory, that will work -- and it did in the good old days
before SPAM (the electric kind) was invented.

But, many SMTP servers (the ones pointed to by the MX record) will not
accept mail from you unless you meet various requirements (which vary
considerably and the SMTP servers administrators try to keep secret).

For example you may have to be sending from an IP address who's
reverse-DNS lookup matches up with the from headers and with the MX
record for the domain you claim to be sending from.

Your mail might also get blocked/discarded if you're sending from
what's been identified as a dynamically allocated IP block (even if it
does have proper DNS and MX records).

-- 
Grant Edwards   grant.b.edwardsYow! Look into my eyes and
  at   try to forget that you have
  gmail.coma Macy's charge card!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using pythons smtp server

2013-12-13 Thread Chris Angelico
On Sat, Dec 14, 2013 at 4:13 AM, Vincent Davis vinc...@vincentdavis.net wrote:
 Let me rephrase my question. I want to send an email using python but do not
 want to use an external service. Does python have the ability to send emails
 without installing additional software or using an external server/service?

Any SMTP server you install has to do one of three things with the
mail you give it:

1) Accept it locally. Presumably the wrong thing to do here.
2) Deliver it to the authoritative SMTP server for the domain.
3) Deliver it to an intermediate server.

(Edit: Your next mail shows that you understand that, as looking up
the MX record is what I was going to say here.)

So if you want to avoid using an external intermediate server, you
need to find and talk to the authoritative server. Now, this is where
another big consideration comes in. What envelope From address are you
going to use? Is your own IP address allowed to send mail for that
domain? If not, you may be forced to use the legitimate server for
that domain. There are other concerns, too; if you don't have a nice
name to announce in the HELO, you might find your mail treated as
spam. But if you deal with all that, then yes, the only thing you need
to do is look up the MX record and pick the best server. (And then
deal with other concerns like coping with that one being down, which
is the advantage of having a local mail queue. But sometimes that
doesn't matter, like if you're sending to yourself for notifications.)

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


Re: Using pythons smtp server

2013-12-13 Thread Vincent Davis
Grant, Chris
Thanks !!!
I guess in the end this is a bad idea, (for my purposes) I should just use
my gmail account smtp server.

Vincent Davis
720-301-3003


On Fri, Dec 13, 2013 at 11:15 AM, Chris Angelico ros...@gmail.com wrote:

 On Sat, Dec 14, 2013 at 4:13 AM, Vincent Davis vinc...@vincentdavis.net
 wrote:
  Let me rephrase my question. I want to send an email using python but do
 not
  want to use an external service. Does python have the ability to send
 emails
  without installing additional software or using an external
 server/service?

 Any SMTP server you install has to do one of three things with the
 mail you give it:

 1) Accept it locally. Presumably the wrong thing to do here.
 2) Deliver it to the authoritative SMTP server for the domain.
 3) Deliver it to an intermediate server.

 (Edit: Your next mail shows that you understand that, as looking up
 the MX record is what I was going to say here.)

 So if you want to avoid using an external intermediate server, you
 need to find and talk to the authoritative server. Now, this is where
 another big consideration comes in. What envelope From address are you
 going to use? Is your own IP address allowed to send mail for that
 domain? If not, you may be forced to use the legitimate server for
 that domain. There are other concerns, too; if you don't have a nice
 name to announce in the HELO, you might find your mail treated as
 spam. But if you deal with all that, then yes, the only thing you need
 to do is look up the MX record and pick the best server. (And then
 deal with other concerns like coping with that one being down, which
 is the advantage of having a local mail queue. But sometimes that
 doesn't matter, like if you're sending to yourself for notifications.)

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

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


Re: Using pythons smtp server

2013-12-13 Thread Chris Angelico
On Sat, Dec 14, 2013 at 5:27 AM, Vincent Davis vinc...@vincentdavis.net wrote:
 Grant, Chris
 Thanks !!!
 I guess in the end this is a bad idea, (for my purposes) I should just use
 my gmail account smtp server.

If you're sending from gmail, use whatever gmail specifies for
sending. Otherwise your mail will be seen as spoofed.

The converse of this is that, in my opinion, *every* domain should
have an SPF record and *every* mail server should check them. That
would eliminate a huge slab of forged mail, and it'd prevent some
stupid web email forms from doing the wrong thing and only finding out
that it's wrong years later.

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


Re: Using pythons smtp server

2013-12-13 Thread Grant Edwards
On 2013-12-13, Vincent Davis vinc...@vincentdavis.net wrote:
 Grant, Chris
 Thanks !!!

 I guess in the end this is a bad idea, (for my purposes) I should just use
 my gmail account smtp server.

If you're going to claim the mail is from somebody@gmail.com, then
yes you should definitly send it via Gmail's SMTP server.  Doing
anything else is going to be a long, losing battle involving you
learning more about SMTP and e-mail headers than you probably want to.

If you've got your own domain (which you're using as the from
address), a static IP, and your own MX record and corresponding SMTP
server, you should be able to set things up to send mail directly.

Many years ago (like 20), I used to configure my home Linux boxes to
send mail directly to the destination SMTP server while claiming to be
from grante@my-isp's-name.com.  At first it worked fine that way.
Then about about 12-15 years ago, I started having problems with some
servers refusing my mail.  I had a static IP address with a real,
official hostname, so I set up an MX record for that hostname, and
made sure my handshaking configuration was using a hostname that
mapped back to my static IP address.  That helped for a while, but
SMTP servers continued to get more and more paranoid.  Some SMTP
servers won't accept mail from an IP if they've determined is a
residential IP address even if you do have a domain that matches the
from address, an MX record, and everything else.

Eventually, I just gave up and started routing everything through the
official SMTP server associated with the e-mail address from which I
wanted to send the mail.

-- 
Grant Edwards   grant.b.edwardsYow! I'm having a MID-WEEK
  at   CRISIS!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Using pythons smtp server

2013-12-12 Thread Vincent Davis
I have an app that generates a file one a day and would like to email it
using pythons SMTP server.
http://docs.python.org/2/library/smtpd.html#smtpd.SMTPServer
The documentation is kinda sparse and I cant seem to find any good examples.

Basically what I want to do; when my app runs it would initiate a SMTP
server, send the attachment and shutdown the SMTP after.

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


Re: Python's and and Pythons or

2013-10-10 Thread Peter Cacioppi
On Wednesday, October 9, 2013 4:54:03 PM UTC-7, Peter Cacioppi wrote:
 I really like the logic that Pythons or is not only short-circuit but 
 non-typed.
 
 
 
 So I can say
 
 
 
 y = override or default
 
 
 
 and y won't necc be True or False. If override boolean evaluates to True 
 (which, for most classes, means not None) than y will be equal to override. 
 Otherwise it will be equal to default.
 
 
 
 I have two questions
 
 -- Is there a handy name for this type of conditional (something as catchy 
 as short circuit or)
 
 
 
 and 
 
 
 
 -- Is there a common idiom for taking advantage of the similar behavior of 
 and. The override or default just makes me grin every time I use it.
 
 
 
 Thanks

ok, since someone asked, I suggest we call the return it's arguments behavior 
echo-argument.

That is to say, the reason we can write 

y = override or default 

is because Python implements echo-argument or. That is to say, or doesn't 
necc return True or False, or returns the first truthy argument it 
encounters. 

and behaves similarly, in that it returns the first falsey argument it 
encounters.

I'm trying to think of a good example usage of echo-argument and. Maybe 
something like

possible = foo and foo.allowsit()
if (possible is None) :
   print foo not provided
if (possible is False) :
   print foo doesn't allow it

A bit awkward, echo-argument or is more naturally useful to me then 
echo-argument and.



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


Re: Python's and and Pythons or

2013-10-10 Thread Chris Angelico
On Thu, Oct 10, 2013 at 5:12 PM, Peter Cacioppi
peter.cacio...@gmail.com wrote:
 I'm trying to think of a good example usage of echo-argument and. Maybe 
 something like

 possible = foo and foo.allowsit()
 if (possible is None) :
print foo not provided
 if (possible is False) :
print foo doesn't allow it

 A bit awkward, echo-argument or is more naturally useful to me then 
 echo-argument and.

first_element = some_list[0]# Oops, may crash

try:
first_element = some_list[0]
except IndexError:
firstelement = None   # A bit verbose

first_element = some_list and some_list[0]

# or if you want a zero instead of an empty list:
first_element = len(some_list) and some_list[0]


Also, consider the case where you have a function, or None:

result = func(*args,**kwargs)   # NoneType is not callable

result = func and func(*args,**kwargs)

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


Re: Python's and and Pythons or

2013-10-10 Thread Peter Cacioppi
On Wednesday, October 9, 2013 4:54:03 PM UTC-7, Peter Cacioppi wrote:
 I really like the logic that Pythons or is not only short-circuit but 
 non-typed.
 
 
 
 So I can say
 
 
 
 y = override or default
 
 
 
 and y won't necc be True or False. If override boolean evaluates to True 
 (which, for most classes, means not None) than y will be equal to override. 
 Otherwise it will be equal to default.
 
 
 
 I have two questions
 
 -- Is there a handy name for this type of conditional (something as catchy 
 as short circuit or)
 
 
 
 and 
 
 
 
 -- Is there a common idiom for taking advantage of the similar behavior of 
 and. The override or default just makes me grin every time I use it.
 
 
 
 Thanks

So you can wrap it all up in one big example

y = (overrideprovider and overrideprovdider() ) or default

echo-argument and/or is a beautiful thing

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


Re: Python's and and Pythons or

2013-10-10 Thread Ethan Furman

On 10/09/2013 11:12 PM, Peter Cacioppi wrote:


I'm trying to think of a good example usage of echo-argument and. Maybe 
something like

possible = foo and foo.allowsit()
if (possible is None) :
print foo not provided
if (possible is False) :
print foo doesn't allow it

A bit awkward, echo-argument or is more naturally useful to me then 
echo-argument and.


It's used as a guard:

if some_list and some_list[0] == something_or_other:
 do some_work()

Without the 'some_list and' portion when some_list was either empty or, say, None, the some_list[0] would fail with an 
error (IndexError, TypeError, etc.).


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


Re: Python's and and Pythons or

2013-10-10 Thread Terry Reedy

On 10/10/2013 2:45 AM, Chris Angelico wrote:

On Thu, Oct 10, 2013 at 5:12 PM, Peter Cacioppi
peter.cacio...@gmail.com wrote:

I'm trying to think of a good example usage of echo-argument and. Maybe 
something like



A bit awkward, echo-argument or is more naturally useful to me then 
echo-argument and.


first_element = some_list[0]# Oops, may crash


some_list[0:1] always works, and sometimes is usable, but you still 
cannot index the slice.



try:
 first_element = some_list[0]
except IndexError:
 firstelement = None   # A bit verbose

first_element = some_list and some_list[0]

# or if you want a zero instead of an empty list:
first_element = len(some_list) and some_list[0]


Also, consider the case where you have a function, or None:

result = func(*args,**kwargs)   # NoneType is not callable

result = func and func(*args,**kwargs)


y = x and 1/x
One just has to remember that y==0 effectively means y==+-infinity ;-).

--
Terry Jan Reedy

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


Re: Python's and and Pythons or

2013-10-10 Thread Chris Angelico
On Thu, Oct 10, 2013 at 6:43 PM, Terry Reedy tjre...@udel.edu wrote:
 y = x and 1/x
 One just has to remember that y==0 effectively means y==+-infinity ;-).

Good example. Extremely appropriate to situations where you're showing
a set of figures and their average:

Foo   1
Bar   3
Quux  7
Asdf  9
= 5

Let the average show as zero if there are none, it won't hurt:

print(=,count and total/count)

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


Re: Python's and and Pythons or

2013-10-10 Thread Ethan Furman

On 10/10/2013 12:43 AM, Terry Reedy wrote:

On 10/10/2013 2:45 AM, Chris Angelico wrote:

On Thu, Oct 10, 2013 at 5:12 PM, Peter Cacioppi
peter.cacio...@gmail.com wrote:

I'm trying to think of a good example usage of echo-argument and. Maybe 
something like



A bit awkward, echo-argument or is more naturally useful to me then 
echo-argument and.


first_element = some_list[0]# Oops, may crash


some_list[0:1] always works, and sometimes is usable, but you still cannot 
index the slice.


Not if some_list is None, False, or another non-indexable type.

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


Re: Python's and and Pythons or

2013-10-10 Thread Terry Reedy

On 10/10/2013 9:33 AM, Ethan Furman wrote:


On 10/10/2013 12:43 AM, Terry Reedy wrote:



On 10/10/2013 2:45 AM, Chris Angelico wrote:

first_element = some_list[0]# Oops, may crash



some_list[0:1] always works, and sometimes is usable, but you still
cannot index the slice.



Not if some_list is None, False, or another non-indexable type.


Did you really not understand that some_list is intended to be a list? 
Just like my_string, for instance, would be a string? Chris's statement 
further specifies some_list as a list that is expected to not be empty, 
but might be -- so one has to guard against the possibility.


The trick of slicing instead of indexing in this context is not obvious 
to everyone learning Python. Most other languages only have indexing. I 
learned the trick years ago when someone posted it on this list.


--
Terry Jan Reedy

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


  1   2   3   >