Re: How to run self-contained Python scripts who don't need Python installation?

2017-06-09 Thread Akira Li
"Juan C."  writes:

> I need to run some Python 3.6.0 scripts on the users' machines (W7 and
> W10) in an enterprise environment, but I can't install Python on those
> machines. I tried looking for those "py to exe", but sadly they don't
> support Python 3.6.0.

I've tried PyInstaller (development version) and it works with Python 3.6:

  $ py -3.6 -m pip install 
https://github.com/pyinstaller/pyinstaller/archive/develop.zip

From
https://www.reddit.com/r/Python/comments/6fpr70/how_do_i_distribute_a_py_file_and_its/


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


Re: Bug or intended behavior? (Posting On Python-List Prohibited)

2017-06-09 Thread Steve D'Aprano
On Fri, 9 Jun 2017 02:23 pm, Lawrence D’Oliveiro wrote:

> The indentation itself doesn’t provide enough grouping, cf
> .


Your argument is:

"Now, what happens if these pieces of code get posted online 
somewhere, say in a discussion forum which makes it hard, or 
even impossible to keep the correct formatting?"


"Doctor, it hurts when I stab myself in the eye with this pointy stick."

"Then stop doing that."

If your forum strips leading whitespace, the forum software is broken and should
be avoided if possible. If not, don't blame Python for your decision to use
broken tools.



You might as well argue that C's "greatest mistake" is to use braces for
grouping code blocks instead of BEGIN/END like Pascal, because there exists
broken software that strips { and } characters from your text.

Why would they do that? Simple: { and } don't exist in the original 1963 version
of the ASCII standard. For many years, very few computers supported braces.
That's why Pascal had *two* delimiters for comments:

{ comment }

(* comment *)

It wasn't until 1967, four years after the initial ASCII standard was published,
that braces were added to the language. So any program which stripped
out "unassigned" characters from your source code would remove braces.

If we came across such a program, would we:

- argue that C and other brace languages are to blame?

- or that the *program*, not the language, is broken?




-- 
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: Bug or intended behavior? (Posting On Python-List Prohibited)

2017-06-09 Thread Steve D'Aprano
On Fri, 9 Jun 2017 02:13 pm, Lawrence D’Oliveiro wrote:

> On Sunday, June 4, 2017 at 9:59:11 AM UTC+12, Sean DiZazzo wrote:
>> Looking at operator precedence, I only see the % operator in regards to
>> modulus.  Nothing in regards to string formatting.
> 
> Operators in Python have no intrinsic meaning. They are just syntactic sugar
> for invoking methods with special names on the operand objects. 

That's wrong. The dunder methods are implementation, and are not intended to be
called directly. It is a myth that, for example:


> For example, 
> 
> a % b
> 
> is just a cleaner way of writing
> 
> a.__mod__(b)
>
> or, if object “a” does not support “__mod__”, but object “b” has “__rmod__”,
> then it means
> 
> b.__rmod__(a)

That's wrong.

First error: in CPython 3, and in CPython 2 for new style classes, the
interpreter does not call a.__mod__ or b.__rmod__.

Instead, it calls type(a).__mod__ or type(b).__rmod__, which is not necessarily
the same thing.

Second error: it is not correct that b.__rmod__ is only called if a does not
support __mod__. That is a woefully incomplete description of what actually
occurs. Here is an approximate pseudo-code of what actually happens:


A = type(a)
B = type(b)
if issubclass(B, A) and hasattr(B, '__rmod__'):
x = B.__rmod__(b, a)
if x is NotImplemented:
if hasattr(A, '__mod__'):
x = A.__mod__(a, b)
if x is NotImplemented:
raise TypeError
else:
return x
else:
return x
elif hasattr(A, '__mod__'):
x = A.__mod__(a, b)
if x is NotImplemented:
if hasattr(B, '__rmod__'):
x = B.__mod__(b, a)
if x is NotImplemented:
raise TypeError
else:
return x
else:
return x
elif hasattr(B, '__rmod__'):
x = B.__rmod__(b, a)
if x is NotImplemented:
assert not hasattr(A, '__mod__')
raise TypeError
else:
return x
else:
raise TypeError


The bottom line is, if you are calling dunder methods directly instead of
operators, you're probably doing it wrong.




-- 
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: Is An Element of a Sequence an Object?

2017-06-09 Thread Steve D'Aprano
On Fri, 9 Jun 2017 02:04 pm, Lawrence D’Oliveiro wrote:

> I generally have very little use for “is” in my code. I do try it out for
> testing sometimes, to ensure consistency of semantic behaviour in library
> bindings for example, but I don’t think I have ever written an “is”-construct
> in production code.

If you are using None as a sentinel value, and testing for None with ==
(equality) instead of identity (is), then you have a bug waiting to strike.

if obj == None:
# do special behaviour that is intended to ONLY occur if obj is None


Using equality there is wrong (as well as needlessly slow). The problem is that
Python will call obj.__eq__ which has a chance to claim to be equal to None. If
it does, then you will run the "only run for None" code for something that
isn't None.




-- 
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


In which order many functions are executed in a python code

2017-06-09 Thread sondes kalboussi

Am a bit confused I was thinking that the order of execution of functions in a 
code is from the first to the last function but sometimes it is the opposite, 
for instance, some parameters or outputs from the second function are called in 
the first one even thou they are not global, any hints ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: In which order many functions are executed in a python code

2017-06-09 Thread Thomas Nyberg
On 06/09/2017 11:39 AM, sondes kalboussi wrote:
> 
> Am a bit confused I was thinking that the order of execution of functions in 
> a code is from the first to the last function but sometimes it is the 
> opposite, for instance, some parameters or outputs from the second function 
> are called in the first one even thou they are not global, any hints ?
> 
Maybe if you post some specific code it will be easier to see what
you're confused about?

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


Re: In which order many functions are executed in a python code

2017-06-09 Thread Joel Goldstick
On Fri, Jun 9, 2017 at 2:46 PM, Thomas Nyberg  wrote:
> On 06/09/2017 11:39 AM, sondes kalboussi wrote:
>>
>> Am a bit confused I was thinking that the order of execution of functions in 
>> a code is from the first to the last function but sometimes it is the 
>> opposite, for instance, some parameters or outputs from the second function 
>> are called in the first one even thou they are not global, any hints ?
>>
> Maybe if you post some specific code it will be easier to see what

Functions are run in the order in which they are called from the main code
-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Time Calculation to Tag a Sentence/File (Posting On Python-List Prohibited)

2017-06-09 Thread subhabangalore
On Friday, June 9, 2017 at 1:18:35 PM UTC+5:30, Lawrence D’Oliveiro wrote:
> On Thursday, June 8, 2017 at 9:57:40 AM UTC+12, subhaba...@gmail.com wrote:
> > ... (with Python2.7 on MS-Windows 7) ...
> 
> Why?

Are you asking why not Python3? My Java based colleagues say it clashes with 
Java, so we try to work around Python2.x.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Time Calculation to Tag a Sentence/File (Posting On Python-List Prohibited)

2017-06-09 Thread Paul Barry
This is a strange statement.  Python 3 doesn't even clash with Python 2, so
I can't think of how it might cause problems with Java.  I've run 2 and 3
on Windows 7, Vista, and 10 without any issues.

Paul.

On 9 June 2017 at 20:14,  wrote:

> On Friday, June 9, 2017 at 1:18:35 PM UTC+5:30, Lawrence D’Oliveiro wrote:
> > On Thursday, June 8, 2017 at 9:57:40 AM UTC+12, subhaba...@gmail.com
> wrote:
> > > ... (with Python2.7 on MS-Windows 7) ...
> >
> > Why?
>
> Are you asking why not Python3? My Java based colleagues say it clashes
> with Java, so we try to work around Python2.x.
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Paul Barry, t: @barrypj  - w:
http://paulbarry.itcarlow.ie - e: paul.ba...@itcarlow.ie
Lecturer, Computer Networking: Institute of Technology, Carlow, Ireland.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Time Calculation to Tag a Sentence/File (Posting On Python-List Prohibited)

2017-06-09 Thread subhabangalore
On Saturday, June 10, 2017 at 1:53:07 AM UTC+5:30, Paul Barry wrote:
> This is a strange statement.  Python 3 doesn't even clash with Python 2, so
> I can't think of how it might cause problems with Java.  I've run 2 and 3
> on Windows 7, Vista, and 10 without any issues.
> 
> Paul.
> 
> On 9 June 2017 at 20:14,  wrote:
> 
> > On Friday, June 9, 2017 at 1:18:35 PM UTC+5:30, Lawrence D’Oliveiro wrote:
> > > 
> > > > ... (with Python2.7 on MS-Windows 7) ...
> > >
> > > Why?
> >
> > Are you asking why not Python3? My Java based colleagues say it clashes
> > with Java, so we try to work around Python2.x.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> 
> 
> 
> -- 
> 
> Lecturer, Computer Networking: Institute of Technology, Carlow, Ireland.

Dear Sir,
I believe I can take your word. I'd take your word and send to my project 
manager, let me check his view now. 
Regards,
RP
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: In which order many functions are executed in a python code

2017-06-09 Thread Erik

On 09/06/17 19:39, sondes kalboussi wrote:

Am a bit confused I was thinking that the order of execution of
functions in a code is from the first to the last function but
sometimes it is the opposite, for instance, some parameters or
outputs from the second function are called in the first one even
thou they are not global, any hints ?


As a complete and utter guess, I assume you are talking about something 
like:


result = func1(1, 2, func2(x, y))

In this case, func2() will be called before func1(). This is because 
func1() needs three parameters and one of those parameters is the return 
value of func2().


Python can not know the return value of func2() without calling it. 
Therefore, to be able to call func1() and give it its three parameters, 
it must first call func2() to find out what that third parameter value is.


It's equivalent to:

func2result = func2(x, y)
result = func1(1, 2, func2result)

If that is _not_ what you are talking about, then like Thomas says - you 
need to paste some code and explain what you are confused by.


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


Re: In which order many functions are executed in a python code

2017-06-09 Thread Terry Reedy

On 6/9/2017 6:00 PM, Erik wrote:

On 09/06/17 19:39, sondes kalboussi wrote:

Am a bit confused I was thinking that the order of execution of
functions in a code is from the first to the last function but
sometimes it is the opposite, for instance, some parameters or
outputs from the second function are called in the first one even
thou they are not global, any hints ?


As a complete and utter guess, I assume you are talking about something 
like:


result = func1(1, 2, func2(x, y))


On the right side of '=', Python evaluates expressions, to the extent 
possible, left to right.  The result of each evaluation is an object. 
In the above, the order is func1, 1, 2, func2, x, y, _tem = func2(x, y), 
func1(1, 2, _tem).  Note that function expressions can be more 
complicated than just a name, as in func_array[selector].


In this case, func2() will be called before func1(). This is because 
func1() needs three parameters and one of those parameters is the return 
value of func2().


Given r = f[a](1, g[b](c)), your rule above does not determine whether 
f[a] or g[b] is determined first.  In at least some C implementations, 
g[b] would be.  Since the call g[b](c) could affect the bindings of f, 
a, and the result of f[a], the rule that f[a] is calculated before g, b, 
c, g[b], and g[b](c) may make a real difference.


Python can not know the return value of func2() without calling it. 
Therefore, to be able to call func1() and give it its three parameters, 
it must first call func2() to find out what that third parameter value is.


It's equivalent to:

func2result = func2(x, y)
result = func1(1, 2, func2result)


Since the func2 call could have the side effect of rebinding 'func1', 
this is not exactly equivalent.


If that is _not_ what you are talking about, then like Thomas says - you 
need to paste some code and explain what you are confused by.


Indeed.

--
Terry Jan Reedy

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


Re: In which order many functions are executed in a python code

2017-06-09 Thread Erik

On 10/06/17 00:18, Terry Reedy wrote:

On 6/9/2017 6:00 PM, Erik wrote:

On 09/06/17 19:39, sondes kalboussi wrote:

Am a bit confused I was thinking that the order of execution of
functions in a code is from the first to the last function but
sometimes it is the opposite, for instance, some parameters or
outputs from the second function are called in the first one even
thou they are not global, any hints ?


As a complete and utter guess, I assume you are talking about 
something like:


result = func1(1, 2, func2(x, y))


On the right side of '=', Python evaluates expressions, to the extent 
possible, left to right.  The result of each evaluation is an object. In 
the above, the order is func1, 1, 2, func2, x, y, _tem = func2(x, y), 
func1(1, 2, _tem).  Note that function expressions can be more 
complicated than just a name, as in func_array[selector].


Terry, how does this help the OP who is obviously a learner, understand 
their problem?


In this case, func2() will be called before func1(). This is because 
func1() needs three parameters and one of those parameters is the 
return value of func2().


Given r = f[a](1, g[b](c)), your rule above does not determine whether 
f[a] or g[b] is determined first.  In at least some C implementations, 
g[b] would be.  Since the call g[b](c) could affect the bindings of f, 
a, and the result of f[a], the rule that f[a] is calculated before g, b, 
c, g[b], and g[b](c) may make a real difference.


Terry, how does this help the OP who is obviously a learner, understand 
their problem?


Python can not know the return value of func2() without calling it. 
Therefore, to be able to call func1() and give it its three 
parameters, it must first call func2() to find out what that third 
parameter value is.


It's equivalent to:

func2result = func2(x, y)
result = func1(1, 2, func2result)


Since the func2 call could have the side effect of rebinding 'func1', 
this is not exactly equivalent.


Whilst this is strictly correct, Terry, how does this help the OP who is 
obviously a learner, understand their problem?


I was trying to help someone by writing in terms I thought would help 
them to understand the question they posed (if I was correct in my 
assumption of what that question actually meant).


Why have you just jumped on everything I've said with responses that are 
really not what someone posting to -list for the first time might even 
understand?


If you want to prove something to me, then send something to me. I 
really don't understand why you would respond in this way.


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


Re: Access flles on a Android device from Windows PC

2017-06-09 Thread Fred Fishbin
Um, no.  I *now* understand that USB Mass drive is no longer supported, but it 
was a legit question.

I'd still love if someone could post a code sample, or point me in the 
direction to a code snippet that would show me how to access the phone.  I know 
it can be done, its just not simple anymore.

Freddie

wxjmfa...@gmail.com wrote:
Le mardi 6 juin 2017 21:37:24 UTC+2, Fred Fishbin a écrit :
>> Hi
>> 
>> I want to write little program that my friend can run - he'll plug a USB 
>>drive 
>> into his Windows 7 PC, plug his phone in a USB port on same PC, then run my 
>> program and it'll xfer some audiobook files over for him.
>> 
>> I plugged the USB drive in and it became "G:\", but the phone plugged in and 
>> became just "SAMSUNG-SM-G930V", no drive designation, just a Portable Media 
>> Device.  Windows Explore can go there so the files are accessible, the phone 
>> isn't looking him out, but what do I use for a path?  I tried several 
>>different 
>> listdir()'s nothing worked.
>> 
>> Thoughts?
>> 
>> thanks, Freddie
>
>I hope your mounted external device is full of file names
>with plenty of Emojis...
>It will be very funny.

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


Re: Passing arguments to & executing, a python script on a remote machine from a python script on local machine (using ssh ?)

2017-06-09 Thread niteesh . k80
hey did you find the answer for this
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Access flles on a Android device from Windows PC (Posting On Python-List Prohibited)

2017-06-09 Thread Fred Fishbin
Lawrence_D?Oliveiro  wrote:
>On Thursday, June 8, 2017 at 3:41:35 PM UTC+12, Fred Fishbin wrote:
>> Yup, that seems to be the deal, and there doesn't seem tpo be a really 
>>simple 
>> way to deal with this.
>
>The preferred way to do file transfers to/from Android devices over USB seems 
>to be via MTP nowadays .

Excellent!  Exactly what I was looking for!

thank you, Freddie
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: In which order many functions are executed in a python code

2017-06-09 Thread Terry Reedy

On 6/9/2017 8:14 PM, Erik wrote:

On 10/06/17 00:18, Terry Reedy wrote:

On 6/9/2017 6:00 PM, Erik wrote:

On 09/06/17 19:39, sondes kalboussi wrote:

Am a bit confused I was thinking that the order of execution of
functions in a code is from the first to the last function but
sometimes it is the opposite, for instance, some parameters or
outputs from the second function are called in the first one even
thou they are not global, any hints ?


As a complete and utter guess, I assume you are talking about 
something like:


result = func1(1, 2, func2(x, y))


On the right side of '=', Python evaluates expressions, to the extent 
possible, left to right.  The result of each evaluation is an object. 
In the above, the order is func1, 1, 2, func2, x, y, _tem = func2(x, 
y), func1(1, 2, _tem).  Note that function expressions can be more 
complicated than just a name, as in func_array[selector].


Terry, how does this help the OP who is obviously a learner, understand 
their problem?


Which is unclear in the absence of any example.

Erik, calm down.  I did not jump on what you said, I added detail. 
python-list is a public forum and answers are for any one who reads the 
thread, either now or in the future.  That is why answers are posted 
publicly, not privately.  (I happen to more often answer questions on 
StackOverflow, where questions and answers are more explicitly intended 
to constitute a growing database of programming knowledge, and where 
they are much more easily searched.)


That said, Python's uniform left-to-right rule is a simplifying rule 
which I found very helpful when *I* was a beginner.  It was a relief 
after my previous experience with a language (C) where so many behaviors 
are 'implementation defined' or worse, 'undefined'.  So I thought it 
might be helpful to this beginner and I expect it will be to someone. 
Knowing order of evaluation is crucial to understanding code where most 
anything might have a side-effect.


For example, what should be the order of output of this code?

def echo(x):
print(x)
return x

d = {echo(1): echo(2), echo(3): echo(4)}

In 3.5+, it is 1,2,3,4, as the rule says.  In early 3.x, 2.7, and some 
undetermined earlier versions, it was 2,1,4,3*.  When the bug was 
discovered, there was a thought that we should just document the 
exception, because fixing the bug could break code.  The decision was to 
leave maintenance versions, including 2.x, alone and fix the bug in the 
next py 3 version.


* If one views dict displays as abbreviating a series of assignments, 
such as d[echo(1)] = echo(2); d[echo(3)] = echo(4), the reversal makes 
some sense.


--
Terry Jan Reedy

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


Re: Access flles on a Android device from Windows PC (Posting On Python-List Prohibited)

2017-06-09 Thread Fred Fishbin
Lawrence_D?Oliveiro  wrote:
>On Thursday, June 8, 2017 at 3:41:35 PM UTC+12, Fred Fishbin wrote:
>> Yup, that seems to be the deal, and there doesn't seem tpo be a really 
>>simple 
>> way to deal with this.
>
>The preferred way to do file transfers to/from Android devices over USB seems 
>to be via MTP nowadays .

Excellent!  Exactly what I was looking for!

thank you, Freddie
-- 
https://mail.python.org/mailman/listinfo/python-list