Re: Python Learning

2017-12-21 Thread Rustom Mody
On Friday, December 22, 2017 at 12:12:58 AM UTC+5:30, Python wrote:
> On Fri, Dec 15, 2017 at 04:51:09PM -0500, Bill wrote:
> > >I'm new to programming, can anyone guide me, how to start learning python 
> > >programming language,...plz suggest some books also.
> > >
> > >Thanks all
> > 
> > Are you sure you want to learn Python first?
> > Python does enough things "behind the scene"
> > that it makes me question the wisdom of that.
> > Other points of view are welcome, of course.
> > Learning the primitives of C++ first, may make for an easier transition.
> 
> This suggestion seems completely backwards to me.

In the locution "computer programming" there are two words
One can choose which one emphasizes I guess??

My own teacher of programming used to relate that when his teacher taught him
assembly language was "programming" and Fortran as "advanced"
Obviously the world today is different from the 1960s

But Gödel's theorem remains true as ever: No formal system (aka language)
is complete (suitable) for expressing everything
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: property decorator?

2017-12-21 Thread Irv Kalb
Thanks to Rob, Cameron, Ian, Chris and Kirill for the detailed explanations.

Very helpful,

Irv

> On Dec 20, 2017, at 3:56 PM, Irv Kalb  wrote:
> 
> I am trying  to work through the concept of the @property decorator with 
> respect to object oriented programming.
> 
> I believe that I understand how the @property and @.setter work 
> - and that they are used to turn what looks like direct access to instance 
> variables into method calls in an object.It seems like these two 
> decorators are essentially fancy substitutes for traditional getter and 
> setter methods.  But, I'm having a hard time understanding why these names 
> were chosen. 
> 
> I have the following example code:
> 
> 
> class Employee():
> 
>def __init__(self, name, salary):
>self.__name = name
>self.__salary = salary
> 
>@property
>def salary(self):
>print('Getting salary of', self.__name, 'which is:', self.__salary)
>return self.__salary
> 
>@salary.setter
>def salary(self, newSalary):
>print('Setting salary of', self.__name, 'to:', newSalary)
>self.__salary = newSalary
> 
> 
> # Test code:
> employee1 = Employee('Joe Schmoe', 9)
> employee2 = Employee('Jane Smith', 123456)
> 
> print(employee1.salary)
> print(employee2.salary)
> 
> employee1.salary = 10
> employee2.salary = 22
> 
> print(employee1.salary)
> print(employee2.salary)
> 
> 
> When it runs, I get the results I expect:
> 
> Getting salary of Joe Schmoe which is: 9
> 9
> Getting salary of Jane Smith which is: 123456
> 123456
> Setting salary of Joe Schmoe to: 10
> Setting salary of Jane Smith to: 22
> Getting salary of Joe Schmoe which is: 10
> 10
> Getting salary of Jane Smith which is: 22
> 22
> 
> 
> My questions about this are really historical.  From my reading, it looks 
> like using an @property decorator is a reference to an older approach using a 
> built in "property" function.  But here goes:
> 
> 1) Why were these decorator names chosen?  These two names @property and 
> @.setter don't seem to be very clear to me.  At a minimum, they don't 
> match.  Wouldn't decorator names like @.getter and @.setter have 
> been better - more explicit?
> 
> 2)  Alternatively, if the getter was going to use the @property decorator, 
> then it would seem complimentary  to have the decorator name for the 
> associated setter function to have the word "property" in its also, something 
> like @propertySetter.  
> 
> 3)  If I create a method with the @property decorator, is there anything else 
> that is implied about the name of the method other than you can now refer to 
> the . - which calls the appropriate method?  My 
> guess/understanding is that in my example above, "salary" is considered the 
> property name, which is how you would refer to it outside of the object. 
> Inside the class, you use the property name as the name of both the setter 
> and the getter methods.  Is that the right way to think about it?
> 
> 
> Finally, it seems very odd to me that when you use the @property decorator 
> and the @.setter, that both of the methods that are decorated 
> need to have the same name (but of course different set of parameters.)  As a 
> teacher, this seems like it would be an extremely difficult concept to get 
> across to students, as this does not work the same way as other Python 
> functions (and methods).  Without a decorator, the second function of the 
> same name overrides an earlier function of the same name, as in this simple 
> example:
> 
> def myFunction( ):
>print('In first version of myFunction')
> 
> def myFunction( ):
>print('In second version of myFunction')
> 
> myFunction()
> 
> Which prints:  In second version of myFunction
> 
> 
> 
> 
> My most recent language before Python was ActionScript 3 (the language of 
> Flash).  It implemented a similar concept of being able to use what appeared 
> to be an explicit data reference which turns into a method call, like this 
> example (from StackOverflow):
> 
> private var _loggy:String;
> 
> public function get loggy ():String
> {
>  return _loggy;
> }
> 
> public function set loggy ( loggy:String ):void
> {
>  // checking to make sure loggy's new value is kosher etc...
>  _loggy = loggy;
> }
> This syntax made the concept easy to understand and implement in an 
> ActionScript class (even though it also uses the same name for both function).
> 
> I do NOT want to start any kind of language flame war.  I am really just 
> trying to understand the reasons behind why this concept is implemented in 
> Python this way, so that I can wrap my head around it and teach it 
> effectively in my classes.
> 
> Irv
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

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


Re: What is wrong with this regex for matching emails?

2017-12-21 Thread Peter J. Holzer
On 2017-12-20 08:21:02 +1100, Chris Angelico wrote:
> If there are no MX records for a domain, either the domain doesn't
> exist, or it doesn't receive mail.

This is not necessarily correct. An MTA has to fall back to A and 
records if no MX record exists, so a domain can receive mail without an
MX record. This is rare, but I have seen it in the wild (although
usually not for email addresses for people but for services (e.g.
trouble ticket systems).

hp

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | h...@hjp.at | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


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


Re: Regarding the error: TypeError: can’t pickle _thread.lock objects

2017-12-21 Thread Terry Reedy

On 12/21/2017 8:11 AM, Winston Manuel Vijay wrote:

Hi,

It would be of immense help, if someone could provide a suitable solution or 
related information that helps to sort out the below stated issue-


Ø  I had installed the Python version 3.6.4

Ø  Then I installed the package: Tensorflow

Ø  Installed g2p.exe by downloading from GitHub

Ø  Then tried running the below command-

g2p-seq2seq --interactive --model  (model_folder_path: is 
the path to an English model 2-layer LSTM with 512 hidden units CMU Sphinx dictionary 
downloaded from the CMU Sphinx website)

Following the above procedure, I encountered the following error: TypeError: 
can’t pickle _thread.lock objects-please find the attached screenshot for your 
reference.


This is a text-only mailing list.  One should copy and paste an entire 
traceback.


That said, if Tensorflow or g2p are trying to pickle something that 
cannot be pickled, you would likely do better directing your inquiry to 
the authors.


If you possible can, omit the following nonsensical garbage.  When you 
submit to a public list like python-list, anyone in the world is an 
intended recipient and you implicitly authorize all of the listed 
activities.  If you do not want that, don't submit.





This e-mail and any files transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
This email is sent for the intended recipient(s) only. If by an addressing or 
transmission error, this mail has been misdirected to you, you are requested to 
delete this mail immediately. If you are not the intended recipient(s), please 
reply to the sender and destroy all copies of the original message. Any 
unauthorized review, use, disclosure, dissemination, forwarding, printing or 
copying of this email, and/or any action taken in reliance on the contents of 
this e-mail is strictly prohibited and may be unlawful. Where permitted by 
applicable law, this e-mail and other e-mail communications sent to and from 
GSR e-mail addresses may be monitored.




--
Terry Jan Reedy


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


Re: How to edit a function in an interactive python session?

2017-12-21 Thread Terry Reedy

On 12/20/2017 8:42 PM, Peng Yu wrote:


R has the function edit() which allows the editing of the definition
of a function. Does python have something similar so that users can
edit python functions on the fly? Thanks.

https://www.rdocumentation.org/packages/utils/versions/3.4.3/topics/edit


In general, no.  In general, it is not possible since the definition may 
not be in Python.  (The equivalent must be true in R also.)


In a decent Python IDE, like IDLE, that allows one to enter, retrieve, 
and edit complete statements, then yes for function definitions entered 
in the same session.  It is also possible to edit multi-line code 
line-by-line in the standard REPL, but it is more painful and error prone.


One can monkey-patch an edited function into an imported module written 
in Python.  The original code can be copied from an editor and pasted 
into the REPL.


--
Terry Jan Reedy

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


Re: Problem with assignment. Python error or mine?

2017-12-21 Thread duncan smith
On 21/12/17 19:06, John Ladasky wrote:
> On Thursday, December 21, 2017 at 7:37:39 AM UTC-8, MRAB wrote:
> 
>> Python never makes a copy unless you ask it to.
>>
>> What x1=X does is make the name x1 refer to the same object that X 
>> refers to. No copying.
> 
> Well, except with very simple, mutable data types like scalars... compare 
> this:
> 
 x=5
 y=x
 x,y
> (5, 5)
 x+=1
 x,y
> (6, 5)
> 
> To this:
> 
 a=[1,2,3]
 b=a
 a,b
> ([1, 2, 3], [1, 2, 3])
 a[1]=9
 a,b
> ([1, 9, 3], [1, 9, 3])
> 

Except ints aren't mutable and there's still no copying.

For

x += 1

(where x is e.g. an int) read

x = x + 1

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


Re: Problem with assignment. Python error or mine?

2017-12-21 Thread Kirill Balunov
2017-12-21 22:06 GMT+03:00 John Ladasky :

> On Thursday, December 21, 2017 at 7:37:39 AM UTC-8, MRAB wrote:
>
> > Python never makes a copy unless you ask it to.
> >
> > What x1=X does is make the name x1 refer to the same object that X
> > refers to. No copying.
>
> Well, except with very simple, mutable data types like scalars... compare
> this:
>

No copy means no copy, it is the rule! What you see is really new binding
operation under the hood.
'x=1; x += 1', means calculate x+1 and bind it to the same name. Compare it
to this example:


>>> tpl = ((1,2),(3,4))
>>> tpl += ((1,2),)
>>> tpl

((1, 2), (3, 4), (1, 2))


No copy, new binding to the same name :)


With kind regards, -gdg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with assignment. Python error or mine?

2017-12-21 Thread John Ladasky
On Thursday, December 21, 2017 at 7:37:39 AM UTC-8, MRAB wrote:

> Python never makes a copy unless you ask it to.
> 
> What x1=X does is make the name x1 refer to the same object that X 
> refers to. No copying.

Well, except with very simple, mutable data types like scalars... compare this:

>>> x=5
>>> y=x
>>> x,y
(5, 5)
>>> x+=1
>>> x,y
(6, 5)

To this:

>>> a=[1,2,3]
>>> b=a
>>> a,b
([1, 2, 3], [1, 2, 3])
>>> a[1]=9
>>> a,b
([1, 9, 3], [1, 9, 3])

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


Re: Python Learning

2017-12-21 Thread Python
On Fri, Dec 15, 2017 at 04:51:09PM -0500, Bill wrote:
> >I'm new to programming, can anyone guide me, how to start learning python 
> >programming language,...plz suggest some books also.
> >
> >Thanks all
> 
> Are you sure you want to learn Python first?
> Python does enough things "behind the scene"
> that it makes me question the wisdom of that.
> Other points of view are welcome, of course.
> Learning the primitives of C++ first, may make for an easier transition.

This suggestion seems completely backwards to me.  One of Python's
greatest strengths is its relative simplicity, as compared to
lower level languages like C++ or assembly, or even other scripting
languages like Perl (which is comparitively large lexicographically
and syntactically).  Part of the process of learning is being rewarded
for what you have learned; Python does this exceptionally well by
enabling the student to write useful programs with simple syntax in a
very short time.

Pyhon is extremely well suited to teaching basic programming skills
like *using* data structures, flow control, subroutines, etc.
*without* having to grasp more difficult concepts like addressing and
pointers, static typing, low-level data structure implementation, etc..
Those topics would perhaps be better suited to a subsequent course,
once the student has mastered (or at least gained familiarity) with
some of the more introductory concents.

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


Re: Problem with assignment. Python error or mine?

2017-12-21 Thread MarkA
On Thu, 21 Dec 2017 07:05:33 -0800, rafaeltfreire wrote:
From docs.python.org:

8.10. copy — Shallow and deep copy operations

Source code: Lib/copy.py

Assignment statements in Python do not copy objects, they create bindings 
between a target and an object. For collections that are mutable or 
contain mutable items, a copy is sometimes needed so one can change one 
copy without changing the other. This module provides generic shallow and 
deep copy operations (explained below)...


> Dear community, I am having the following problem when I am assigning
> the elements of a vector below a certain number to zero or any other
> value.
> I am creating a new variable but Python edits the root variable. Why?
> 
> import numpy as np
> 
> X=np.arange(1, 1, 1) #root variable x1=X x1[x1<1]=0
> 
> print(X)
> Out[1]: array([ 0.,  0.,  0., ...,  0.,  0.,  0.])
> 
> Why? It is supposed to be the original value Thank you for your
> time Rafael



-- 
MarkA

We hang petty theives, and appoint the great theives to public office
  -- Aesop
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with assignment. Python error or mine?

2017-12-21 Thread MRAB

On 2017-12-21 15:05, rafaeltfre...@gmail.com wrote:

Dear community, I am having the following problem when I am assigning the 
elements of a vector below a certain number to zero or any other value.
I am creating a new variable but Python edits the root variable. Why?

import numpy as np

X=np.arange(1, 1, 1) #root variable
x1=X
x1[x1<1]=0

print(X)
Out[1]: array([ 0.,  0.,  0., ...,  0.,  0.,  0.])

Why? It is supposed to be the original value
Thank you for your time
Rafael


Python never makes a copy unless you ask it to.

What x1=X does is make the name x1 refer to the same object that X 
refers to. No copying.


As you're using numpy, you can use the .copy method:

x1 = X.copy()

This makes the name x1 refer to a new copy of the object that X refers to.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with assignment. Python error or mine?

2017-12-21 Thread rafaeltfreire
Em quinta-feira, 21 de dezembro de 2017 16:21:57 UTC+1, Neil Cerutti  escreveu:
> On 2017-12-21, rafaeltfre...@gmail.com  wrote:
> > Dear community, I am having the following problem when I am
> > assigning the elements of a vector below a certain number to
> > zero or any other value. I am creating a new variable but
> > Python edits the root variable. Why?
> >
> > import numpy as np
> >
> > X=np.arange(1, 1, 1) #root variable
> 
> np.arange creates an object. The assignment makes X refer to that
> object.
> 
> > x1=X 
> 
> X refers to the previous object, and then the assignment makes x1
> refer to that same object.
> 
> -- 
> Neil Cerutti

Ok, great thank you. I am kind of new in python. I use to program in MATLAB but 
I am trying to migrate. 
So, to fix it what should I do? because my X is an NMR spectrum of many 
samples. 
Thank you very much!
Rafael
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem with assignment. Python error or mine?

2017-12-21 Thread Neil Cerutti
On 2017-12-21, rafaeltfre...@gmail.com  wrote:
> Dear community, I am having the following problem when I am
> assigning the elements of a vector below a certain number to
> zero or any other value. I am creating a new variable but
> Python edits the root variable. Why?
>
> import numpy as np
>
> X=np.arange(1, 1, 1) #root variable

np.arange creates an object. The assignment makes X refer to that
object.

> x1=X 

X refers to the previous object, and then the assignment makes x1
refer to that same object.

-- 
Neil Cerutti

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


Re: property decorator?

2017-12-21 Thread Cholo Lennon

On 20/12/17 21:39, Stefan Ram wrote:

Irv Kalb  writes:
about property decorators.

   The code

@property
def salary(self): pass

@salary.setter
def salary(self, newSalary): pass

   is an abbreviation for

def salary_get(self): pass
salary = property( salary_get )

def salary_set(self, newSalary): pass
salary = salary.setter( salary_set )

   . »property« is a class, »property( salaray )« constructs an
   instance with salary_get as getter and no setter. Later,
   »salary.setter« adds »salaray_set« as a setter to that
   instance.

   One cannot use »@salary.getter« instead of »@property«,
   because at that point in time, the instance »salaray« does
   not already exist.



Best answser IMHO, it's clear and concise.

--
Cholo Lennon
Bs.As.
ARG
--
https://mail.python.org/mailman/listinfo/python-list


Problem with assignment. Python error or mine?

2017-12-21 Thread rafaeltfreire
Dear community, I am having the following problem when I am assigning the 
elements of a vector below a certain number to zero or any other value. 
I am creating a new variable but Python edits the root variable. Why?

import numpy as np

X=np.arange(1, 1, 1) #root variable
x1=X 
x1[x1<1]=0

print(X)
Out[1]: array([ 0.,  0.,  0., ...,  0.,  0.,  0.])

Why? It is supposed to be the original value
Thank you for your time
Rafael
-- 
https://mail.python.org/mailman/listinfo/python-list


Regarding the error: TypeError: can’t pickle _thread.lock objects

2017-12-21 Thread Winston Manuel Vijay
Hi,

It would be of immense help, if someone could provide a suitable solution or 
related information that helps to sort out the below stated issue-


Ø  I had installed the Python version 3.6.4

Ø  Then I installed the package: Tensorflow

Ø  Installed g2p.exe by downloading from GitHub

Ø  Then tried running the below command-

g2p-seq2seq --interactive --model  (model_folder_path: is 
the path to an English model 2-layer LSTM with 512 hidden units CMU Sphinx 
dictionary downloaded from the CMU Sphinx website)

Following the above procedure, I encountered the following error: TypeError: 
can’t pickle _thread.lock objects-please find the attached screenshot for your 
reference.


Thanks,
A.Winston Manuel Vijay




This e-mail and any files transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
This email is sent for the intended recipient(s) only. If by an addressing or 
transmission error, this mail has been misdirected to you, you are requested to 
delete this mail immediately. If you are not the intended recipient(s), please 
reply to the sender and destroy all copies of the original message. Any 
unauthorized review, use, disclosure, dissemination, forwarding, printing or 
copying of this email, and/or any action taken in reliance on the contents of 
this e-mail is strictly prohibited and may be unlawful. Where permitted by 
applicable law, this e-mail and other e-mail communications sent to and from 
GSR e-mail addresses may be monitored.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Learning

2017-12-21 Thread Larry Martell
On Mon, Dec 18, 2017 at 3:22 PM, Marko Rauhamaa  wrote:
>
> Larry Martell :
>
> > On Mon, Dec 18, 2017 at 11:33 AM, Marko Rauhamaa  wrote:
> >> However, one great way to stand out is a portfolio of GitHub
> >> projects. Several people have gotten an offer largely based on those
> >> (after they aced the technical interviews). For example, we just
> >> hired someone who had written a game in sed. That doesn't make him an
> >> "interesting person," nor do we look for game or sed developers. But
> >> that silly exercise deeply resonated with our team. We expect to have
> >> great synergy with him.
> >
> > I have been excluded from even getting an interview because I did not
> > have a portfolio of GitHub projects. I think that is a bad filter. I
> > work 60-70 hours a week for pay, and I have a family and personal
> > interests.
>
> Personal programming projects are not a requirement. They are just a
> very effective advertising tool.
>
> As for 60—70 hours a week... sounds horrible. My sympathies.

Nah - I get paid by the hour and I love what I do.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problems with imports on multiple threads, with embedded Python

2017-12-21 Thread geoff . bache
On Thursday, 21 December 2017 00:33:54 UTC+1, Lawrence D’Oliveiro  wrote:
> On Thursday, December 21, 2017 at 5:13:33 AM UTC+13, geoff...@gmail.com wrote:
> > 
> > I have a multithreaded application using an embedded Python 3.6.4 ...
> 
> Avoid multithreading if you can. Is your application CPU-bound? If not, you 
> are getting no benefit from it.

Unfortunately that's not an option. As I say, Python is embedded and is only a 
part of what the application does. The multithreading is not there for the 
Python part but is a well-established fact in the application.
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: property decorator?

2017-12-21 Thread Kirill Balunov
2017-12-21 2:56 GMT+03:00 Irv Kalb :

> My questions about this are really historical.  From my reading, it looks
> like using an @property decorator is a reference to an older approach using
> a built in "property" function.  But here goes:
>
> 1) Why were these decorator names chosen?  These two names @property and
> @.setter don't seem to be very clear to me.  At a minimum, they don't
> match.  Wouldn't decorator names like @.getter and @.setter
> have been better - more explicit?
>
> 2)  Alternatively, if the getter was going to use the @property decorator,
> then it would seem complimentary  to have the decorator name for the
> associated setter function to have the word "property" in its also,
> something like @propertySetter.
>
> 3)  If I create a method with the @property decorator, is there anything
> else that is implied about the name of the method other than you can now
> refer to the . - which calls the appropriate method?  My
> guess/understanding is that in my example above, "salary" is considered the
> property name, which is how you would refer to it outside of the object.
> Inside the class, you use the property name as the name of both the setter
> and the getter methods.  Is that the right way to think about it?
>

There are nothing special with decorators, the are simply functions which
take at least one argument (of course they can be implemented as classes,
but lets make things simple), and *`@decorator*` is a syntactic sugar
for *`func
= decorator(func)`*. As I see it, the primary idea to introduce them in
Python was readability, and possibility for special syntax highlighting and
nothing more. To sum it up, while* `property*` is often used as a
decorator, the `*property`* built-in is actually a class. So it is not "*an
older approach using a built in "property" function*" but in reality it is
the same class as it was but can be applied with new decorator syntax. And
defined in stdlib as *`class property(fget=None, fset=None, fdel=None,
doc=None)`*.


Finally, it seems very odd to me that when you use the @property decorator
> and the @.setter, that both of the methods that are decorated
> need to have the same name (but of course different set of parameters.)  As
> a teacher, this seems like it would be an extremely difficult concept to
> get across to students, as this does not work the same way as other Python
> functions (and methods).  Without a decorator, the second function of the
> same name overrides an earlier function of the same name, as in this simple
> example:
>


This is not true, actually they all work the same way following *descriptor
protocol* - the mechanism behind properties, methods, static methods, and
others. It is not simple topic, but it essential, I will provide some
references which can help you to grasp:

Descriptor HowTo Guide 
brilliant tutorial by Raymond Hettinger, which is a part of official
documentation. It is very well written, but if you need more on this topic
this books helped me a lot:

"*Python in a Nutshell, 2E by Alex Martelli*" while this book covers Python
2.5, the key idea of descriptors was introduced as a part of new style
classes in Python 2.2.

"*Python Cookbook, 3E by David Beazley and Brian K. Jones*" covers Python 3
with a lot of practical examples.

"*Fluent Python by Luciano Ramalho*" especially Chapter 20, but my advise
to read the book sequentially.

With kind regards, -gdg
-- 
https://mail.python.org/mailman/listinfo/python-list