[Tutor] Is nesting functions only for data hiding overkill?

2019-08-21 Thread James Hartley
Yes, nesting functions is valuable & necessary for closures and wrapping functions for creating properties. But is nesting, simply for hiding data, a preferred solution? I have a number of member functions which are prefaced with underscores pointing out that they should not be called by client c

[Tutor] Is nesting functions only for data hiding overkill?

2019-08-21 Thread James Hartley
Yes, nesting functions is valuable & necessary for closures and wrapping functions for creating properties. But is nesting, simply for hiding data, a preferred solution? I have a number of member functions which are prefaced with underscores pointing out that they should not _

[Tutor] class functions/staticmethod?

2019-08-11 Thread James Hartley
I am lacking in understanding of the @staticmethod property. Explanation(s)/links might be helpful. I have not found the descriptions found in the Internet wild to be particularly instructive. Given the code below: =8<-- from collections import namedtuple class Foo(): Dim

[Tutor] Inserting long URL's into comments & docstrings?

2019-07-29 Thread James Hartley
This should be a slow ball pitch. Unfortunately, I haven't stumbled across a reasonable answer yet. On occasion, I put long URL's into comments/docstrings simply to document where I found specific information. However, to be a good disciple of PEP8, anything which can't fit within 72 characters

[Tutor] raising exceptions in constructor code?

2019-07-16 Thread James Hartley
I ask this having more C++ knowledge than sense. There is an adage in the halls of everything Stroustrup that one needs to think about how resource allocation will be unwound if an exception is thrown. This gets watered down to the mantra "Don't throw exceptions from within constructors." Does t

[Tutor] Lengthy copyright notices?

2019-07-15 Thread James Hartley
help(module_name) will place any text in the *first* module-level docstring into the description section of the help page in Python 3.4.5. Subsequent docstrings found at module level are ignored. I have been using this factoid for placement of a copyright & licensing notice. By placing a rather

[Tutor] directory structure with tests?

2019-03-06 Thread James Hartley
It is preferable to sprinkle tests files throughout the directories of a project, or coalesce all tests in a test directory? Thanks! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/li

[Tutor] overriding brackets in lvalue assignment possible?

2016-12-27 Thread James Hartley
I can successfully override __getitem__() for rvalues, but the following example shows that more is required when used as an lvalue: ===8<- #!/usr/bin/env python class Foo(): def __init__(self, n): self.d = dict.fromkeys([i for i in range(0, n)]) def __getitem__(self, i):

[Tutor] enforcing specific types in Python 3.5?

2016-10-13 Thread James Hartley
I have implemented the equivalent of "insert if unique" in Python & SQLAlchemy to help with data normalization. However to help minimize the number of preliminary SELECT statements needed, it helps to check types through calls to isinstance() before getting to the salient code. Unfortunately, the

[Tutor] relative imports within a package?

2015-11-07 Thread James Hartley
The Python 3 tutorial discusses relative imports at: https://docs.python.org/3/tutorial/modules.html#intra-package-references I have the following directory structure for a package in development: + outer_package/ + __init__.py + inner_package | + __init__.py | + mycl

[Tutor] accessing modules found throughout a package?

2015-10-17 Thread James Hartley
In my current project, I am developing a package. It makes sense to embed tests throughout the package's directory structure as they should be part of the package & its distribution. It may raise eyebrows that I have tests sprinkled through various directories, but there are reasons for keeping s

Re: [Tutor] telnetlib's read_very_eager() method?

2011-09-14 Thread James Hartley
On Wed, Sep 14, 2011 at 1:13 PM, Walter Prins wrote: > On 14 September 2011 21:03, James Hartley wrote: > >> On Wed, Sep 14, 2011 at 12:54 PM, Walter Prins wrote: >> > Aside: If you want to interact with a mail server there's probably better >> modules to

Re: [Tutor] telnetlib's read_very_eager() method?

2011-09-14 Thread James Hartley
On Wed, Sep 14, 2011 at 12:54 PM, Walter Prins wrote: > Hence, try using read_some() instead of read_very_eager(). > read_some() captures what I was hoping to catch. Thanks! > > Aside: If you want to interact with a mail server there's probably better > modules to be using than the telnet mod

[Tutor] telnetlib's read_very_eager() method?

2011-09-14 Thread James Hartley
I'm trying to programmatically create a telnet session. Within the interactive environment, this appears to work very well as server messages can be saved as strings: $ python Python 2.7.1 (r271:86832, Sep 3 2011, 01:32:33) [GCC 4.2.1 20070719 ] on openbsd5 Type "help", "copyright", "credits" or

[Tutor] throwing exception across modules?

2011-09-08 Thread James Hartley
This is more a design question. One lesson C++ programmers might learn is that throwing exceptions from within library code is fraught with problems because the internals of exception handling were spelled out in the C++ standard. This manifests itself as problems when the library was compiled wi

Re: [Tutor] use of logging module is shared by all?

2011-09-01 Thread James Hartley
Thanks, Peter for taking the time to respond. I need to study the reference further, & your comments pointed out some of my misconceptions. Thank you for clearing up some of my half-researched understanding. Jim On Thu, Sep 1, 2011 at 10:53 PM, Peter Otten <__pete...@web.de> wrote

[Tutor] use of logging module is shared by all?

2011-09-01 Thread James Hartley
I'm just needing to verify some behavior. Functionality within the logging module is exercised by calling functions defined within the module itself. I am using SQLAlchemy for database access, but it can be configured to dump out intermediate access information & queries to the logging module --

Re: [Tutor] system()? popen2()? How to execute a command & save itsoutput?

2010-09-30 Thread James Hartley
On Thu, Sep 30, 2010 at 7:27 AM, R. Alan Monroe wrote: > > >> I'm needing to transfer the following shell construct to Python, > >> plus save > >> the output of execution: > > >> FTP_SITE='ftp.somesite.com' > >> ftp -a $FTP_SITE < >> binary > >> prompt off > >> cd /some_dir > >> dir > >> bye > >>

[Tutor] system()? popen2()? How to execute a command & save its output?

2010-09-29 Thread James Hartley
I'm needing to transfer the following shell construct to Python, plus save the output of execution: FTP_SITE='ftp.somesite.com' ftp -a $FTP_SITE <___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.o

[Tutor] sorting dictionary keys?

2008-05-13 Thread James Hartley
I suspect this is a brain-dead question... Given the following code, output is as expected: $ cat test.py d = { 'a' : 1, 'd' : 2, 'b' : 3, 'c' : 0 } for i in d.keys(): print "%s\t%s" % (i, d[i]) $ python test.py a 1 c 0 b 3 d 2 $ But if the keys are sorted, I get an

[Tutor] opening a pipe?

2008-02-12 Thread James Hartley
A Perl script can easily serve as a filter within a pipe as seen in the following: use strict; use warnings; open(IN, 'cat hello.txt |') or die 'unable to open file'; while () { print; } close(IN); Can I do the same within Python? Thanks. Jim ___

Re: [Tutor] Regex Ordering

2007-07-23 Thread James Hartley
On 7/23/07, Shidan <[EMAIL PROTECTED]> wrote: > I'm looking for a Python module that provides methods for ordering > regexes based on > how general they are ( how much they match). Do I have to write it Your question is relative. Classifying which regular expression is more general depends upon t