Re: Python getters and setters

2013-08-17 Thread Fernando Saldanha
The debate got more interesting than I expected. Without taking sides, I would like to add that perhaps my "length" example was misleading: length is easy to calculate. The information could be hard to extract from the data, either because complex calculations are involved, or because it is not

Re: PEP 450 Adding a statistics module to Python

2013-08-17 Thread Jason Friedman
> NumPy and SciPy are not available for many Python users, including those > using a Python implementation for which there is no Numpy support > http://new.scipy.org/faq.html#python-version-support> and those for > whom large, dependency-heavy third-party packages are too much burden. > > See the R

Re: Python getters and setters

2013-08-17 Thread Chris Angelico
On Sun, Aug 18, 2013 at 12:40 AM, Steven D'Aprano wrote: > The Law of Demeter is really about being careful about what interface > your classes provide. Customers should provide a get_payment method; dogs > should provide a walk method. You shouldn't have to send individual step > messages to the

Re: Encapsulation unpythonic?

2013-08-17 Thread Chris Angelico
On Sat, Aug 17, 2013 at 10:22 PM, Terry Reedy wrote: > On 8/17/2013 11:50 AM, Chris Angelico wrote: >> >> On Sat, Aug 17, 2013 at 1:26 PM, wrote: >>> >>> 2) If it is in fact true that encapsulation is rarely used, how do I deal >>> with the fact that other programmers can easily alter the values

Re: Python getters and setters

2013-08-17 Thread Steven D'Aprano
On Sun, 18 Aug 2013 00:52:06 +0200, Irmen de Jong wrote: > On 17-8-2013 19:18, Steven D'Aprano wrote: [...] >> How is this: >> >> obj.data_length() >> >> easier for the user than this? >> >> len(obj.data) >> >> > It's not easier for the user perse, but it might be preferable from a > design p

Re: .split() Qeustion

2013-08-17 Thread Gregory Ewing
wxjmfa...@gmail.com wrote: Na + Cl --> NaCl the chemist combines *one mole* of sodium and *one mole* of chlorine to get *one mole* of sodium chloride It's independent of the number of "particles" in a mole. The actual number chosen for the unit is arbitrary, but number of particles is st

Re: Python getters and setters

2013-08-17 Thread Irmen de Jong
On 17-8-2013 19:18, Steven D'Aprano wrote: > On Sat, 17 Aug 2013 09:53:07 -0700, Fernando Saldanha wrote: > >> Suppose my class contains an attribute called "data" that can >> potentially provide a lot of information that will be needed by class >> users. I have two options: >> >> 1) For each piec

Re: log incoming ip/porrt connections

2013-08-17 Thread Irmen de Jong
On 17-8-2013 22:23, D. Xenakis wrote: > Hi there. I have a script-service running on a remote server, listening on a > specific port. What i need here is to make this also maintain a log file of > ALL incoming connections. > > Could someone suggest to me a simple codefunction example to implemen

Re: Encapsulation unpythonic?

2013-08-17 Thread Terry Reedy
On 8/17/2013 11:50 AM, Chris Angelico wrote: On Sat, Aug 17, 2013 at 1:26 PM, wrote: 2) If it is in fact true that encapsulation is rarely used, how do I deal with the fact that other programmers can easily alter the values of members of my classes? Very simply: You accept it. Let them! I

Re: log incoming ip/porrt connections

2013-08-17 Thread D. Xenakis
Or point me the right way in case this is not that simple to do. -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation unpythonic?

2013-08-17 Thread Gary Herron
On 08/17/2013 05:26 AM, fsald...@gmail.com wrote: I am new to Python, with experience in Java, C++ and R. As I understand encapsulation is not a big thing in the Python world. I read that you can put two underscores before the name of a variable within a class declaration but in the many examp

log incoming ip/porrt connections

2013-08-17 Thread D. Xenakis
Hi there. I have a script-service running on a remote server, listening on a specific port. What i need here is to make this also maintain a log file of ALL incoming connections. Could someone suggest to me a simple codefunction example to implement that on my main running service? THX!! -- h

Re: Python getters and setters

2013-08-17 Thread Tim Chase
On 2013-08-17 17:18, Steven D'Aprano wrote: > # Yes, this is good, consistent design > len(myrecord.field) > len(obj.data) > len(data.value) > len(collection[key]) I would also add that, if the primary goal of your class is to encapsulate the data, you can do class MyClass: def __init__(sel

Re: Python getters and setters

2013-08-17 Thread Steven D'Aprano
On Sat, 17 Aug 2013 09:53:07 -0700, Fernando Saldanha wrote: > Suppose my class contains an attribute called "data" that can > potentially provide a lot of information that will be needed by class > users. I have two options: > > 1) For each piece of information within data (e.g., length) I write

Re: Python getters and setters

2013-08-17 Thread MRAB
On 17/08/2013 17:53, Fernando Saldanha wrote: I am new to Python. I understand that it is "unpythonic" to write getters and setters, and that property() can be used if necessary. This deals with the case of attributes, but there are other kinds of information available within a class. Suppos

Python getters and setters

2013-08-17 Thread Fernando Saldanha
I am new to Python. I understand that it is "unpythonic" to write getters and setters, and that property() can be used if necessary. This deals with the case of attributes, but there are other kinds of information available within a class. Suppose my class contains an attribute called "data" t

Re: Encapsulation unpythonic?

2013-08-17 Thread Steven D'Aprano
On Sat, 17 Aug 2013 05:26:32 -0700, fsaldan1 wrote: > I am new to Python, with experience in Java, C++ and R. > > As I understand encapsulation is not a big thing in the Python world. Utter nonsense. Whoever told you this doesn't understand what encapsulation is. Python encapsulates related c

Re: Check for the type of arguments

2013-08-17 Thread Fernando Saldanha
Thanks for the insightful answers. PTVS is Python Tools for Visual Studio. -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation unpythonic?

2013-08-17 Thread Chris Angelico
On Sat, Aug 17, 2013 at 1:26 PM, wrote: > 2) If it is in fact true that encapsulation is rarely used, how do I deal > with the fact that other programmers can easily alter the values of members > of my classes? Very simply: You accept it. Let them! It's their responsibility. Python scripts a

Re: Check for the type of arguments

2013-08-17 Thread Steven D'Aprano
On Sat, 17 Aug 2013 05:34:54 -0700, Fernando Saldanha wrote: > I am new to Python, with some experience in Java, C++ and R. > > Writing in other languages I usually check the type and values of > function arguments. Surely not in Java and C++. Being static-typed languages, the compiler checks

Re: Importing variables non-deterministic?

2013-08-17 Thread Steven D'Aprano
On Sat, 17 Aug 2013 07:25:43 -0700, tmellman wrote: > I have this file that has this: > > from struct_global import y > from struct_global import x The import of x appears to be irrelevant, so I'll ignore it. Here you import y from the struct_global module. This creates a new name y in

Re: Check for the type of arguments

2013-08-17 Thread Joshua Landau
On 17 August 2013 13:34, Fernando Saldanha wrote: > I am new to Python, with some experience in Java, C++ and R. > > Writing in other languages I usually check the type and values of function > arguments. In the Python code examples I have seen this is rarely done. > > Questions: > > 1) Is this b

Importing variables non-deterministic?

2013-08-17 Thread tmellman
I have this file that has this: from struct_global import y from struct_global import x and this usage (a few lines later in a class method definition in the same file): if y == x: If I stop there in pdb, I can observe this: (Pdb) p x 66 (Pdb) p y -1

Re: Check for the type of arguments

2013-08-17 Thread Chris Angelico
On Sat, Aug 17, 2013 at 1:34 PM, Fernando Saldanha wrote: > Writing in other languages I usually check the type and values of function > arguments. In the Python code examples I have seen this is rarely done. > > Questions: > > 1) Is this because it would be "unpythonic" or just because the examp

Re: Encapsulation unpythonic?

2013-08-17 Thread David
On 17 August 2013 22:26, wrote: > > 1) Is there a good text where I can read about the language philosophy? What > practices are "pythonic" or "unpythonic"? > > 2) If it is in fact true that encapsulation is rarely used, how do I deal > with the fact that other programmers can easily alter the

Re: Check for the type of arguments

2013-08-17 Thread Skip Montanaro
Read up on "duck typing." Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: Encapsulation unpythonic?

2013-08-17 Thread Skip Montanaro
In Guido's own words: "We're all consenting adults here." http://importthis.tumblr.com/post/6719643315/public-private-attributes Skip -- http://mail.python.org/mailman/listinfo/python-list

Check for the type of arguments

2013-08-17 Thread Fernando Saldanha
I am new to Python, with some experience in Java, C++ and R. Writing in other languages I usually check the type and values of function arguments. In the Python code examples I have seen this is rarely done. Questions: 1) Is this because it would be "unpythonic" or just because the examples ar

Encapsulation unpythonic?

2013-08-17 Thread fsaldan1
I am new to Python, with experience in Java, C++ and R. As I understand encapsulation is not a big thing in the Python world. I read that you can put two underscores before the name of a variable within a class declaration but in the many examples of code I looked at this is not widely used. I

Re: PEP 450 Adding a statistics module to Python

2013-08-17 Thread Josef Pktd
I think the install issues in the pep are exaggerated, and are in my opinion not a sufficient reason to get something into the standard lib. google appengine includes numpy https://developers.google.com/appengine/docs/python/tools/libraries27 I'm on Windows, and installing numpy and scipy are ju

Re: .split() Qeustion

2013-08-17 Thread Roy Smith
I wrote: >> The recipe says, "Add one mole of carbon atoms". So, does the >> chemist follow the recipe and count out 6.022 x 10^23 atoms like >> he's supposed to? No. He says, "I don't have time for that. I'll >> just weigh out 12 grams. Good enough for government work." Sheesh. In articl

Re: .split() Qeustion

2013-08-17 Thread wxjmfauth
Le vendredi 16 août 2013 15:23:37 UTC+2, Roy Smith a écrit : > In article <2d88bc0f-fdcb-4685-87ed-c17998dd3...@googlegroups.com>, > > wxjmfa...@gmail.com wrote: > > > > > A chemist has to work and is always working in mole; as his > > > balance can only measure a mass, the calculation mole <