Design: method in class or general function?

2017-09-07 Thread Leam Hall

OOP newbie on Python 2.6.

I create instances of Character class with an attribute dict of 
'skills'. The 'skills' dict has the name of a skill as the key and an 
int as a value. The code adds or modifies skills before outputting the 
Character.


Is it better design to have a Character.method that takes a 'skill' key 
and optional value or to have a general function that takes an instance, 
a dict, a key, and an optional value?



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


Re: Design: method in class or general function?

2017-09-07 Thread leam hall
On Thu, Sep 7, 2017 at 8:16 AM, Steve D'Aprano 
wrote:

> On Thu, 7 Sep 2017 07:20 pm, Leam Hall wrote:
>
> > OOP newbie on Python 2.6.
>
> Python 2.6 is ancient, and is missing many nice features. You should
> consider
> using the latest version, 3.6.
>

I've wrestled with that discussion for a while and Python 3 loses every
time. There's literally no good reason for me to move to Python 3 earlier
than mid-2020's. Please accept the fact that there are hundreds of
thousands of servers, if not millions, running Python 2.x. Whether or not
Python 3 has any neat cool stuff is irrelevant to those of us seeking to
use Python to get today's work done.

> I create instances of Character class with an attribute dict of
> > 'skills'. The 'skills' dict has the name of a skill as the key and an
> > int as a value. The code adds or modifies skills before outputting the
> > Character.
> >
> > Is it better design to have a Character.method that takes a 'skill' key
> > and optional value or to have a general function that takes an instance,
> > a dict, a key, and an optional value?
>
> I'm afraid your example is too generic for me to give an opinion. Do you
> literally mean a method called "method"? What does it do?
>


Using this:
https://github.com/makhidkarun/py_tools/blob/master/lib/character.py

Line 19 sets "self.skills" either from the passed in data or from
https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py#L34-L48

So Character.skills is a dict with a string key and an int value. I need to
be able to add skills and my first attempt is a function:
https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py#L52-L56

Should the "add_skills" function be a method in the character class or be
made a more generic function to add/modify a key/value pair in a dict that
is an attribute of an instance? Other tasks will require the add/modify
functionality but coding that increases complexity. At least for me, anyway.

Sorry about being unclear earlier, coffee was still kicking in and I'm
still a newbie that mixes up terms.

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


Re: Design: method in class or general function?

2017-09-08 Thread Leam Hall

On 09/08/2017 03:06 AM, Peter Otten wrote:


I'm pleading "method" as it allows per-class implementation.


Peter, as always you are a wealth of information! I have some extra time 
today to digest your notes and visualize tap dancing Marines.


Thank you!
--
https://mail.python.org/mailman/listinfo/python-list


Using Python 2 (was: Design: method in class or general function?)

2017-09-08 Thread Leam Hall

On 09/08/2017 05:45 AM, Chris Angelico wrote:

On Thu, Sep 7, 2017 at 11:31 PM, Ben Finney  wrote:

leam hall  writes:


I've wrestled with that discussion for a while and Python 3 loses every
time.



The context of the thread you started was that you are a *newcomer* to
Python. Now you say you've considered Python 2 versus Python 3 many
times? What explains that apparent contradiction?


The original comment was "OOP newbie". My reading is that s/he has
used Py2 for years but never actually created a class - which is a
perfectly reasonable thing in Python, unlike some languages.

That said, though: even if you're not going to move to Python 3, I
*strongly* recommend moving to 2.7. Python 2.6 is ancient and not in
support; Python 2.7 is still old, but is in support (for a few more
years with python.org, and then possibly after that if you have
pay-for support eg with Red Hat). There should be very few reasons for
sticking with 2.6.

Those millions of servers running Python 2? You'd be surprised how
many of them are now actually running Python 3 - but the rest of them
NEED to be on 2.7 if they want bug fixes and security patches. Don't
wait for a major problem.

ChrisA



Chris, there's a big part of me that agrees with you.

However, those millions of servers are running Python 2.6 and a smaller 
number running 2.7. At least in the US market since Red Hat Enterprise 
Linux and its derivatives run 2.6.6 (RHEL 6) or 2.7.5 (RHEL 7). Not sure 
what Python SuSE uses but they seem to have a fairly large European 
footprint. RHEL 7 goes out the active support door (End of Production 
Phase 3) mid-2024.


I've read comments about Python 3 moving from the Zen of Python. I'm a 
"plain and simple" person myself. Complexity to support what CompSci 
folks want, which was used to describe some of the Python 3 changes, 
doesn't help me get work done.


That said, if the next job I go to is 100% Python 3 then I guess I'm 
doing a lot more Python 3.

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


Re: Using Python 2

2017-09-08 Thread Leam Hall

On 09/08/2017 06:40 AM, Marko Rauhamaa wrote:

Leam Hall :

However, those millions of servers are running Python 2.6 and a
smaller number running 2.7. At least in the US market since Red Hat
Enterprise Linux and its derivatives run 2.6.6 (RHEL 6) or 2.7.5 (RHEL
7). Not sure what Python SuSE uses but they seem to have a fairly
large European footprint. RHEL 7 goes out the active support door (End
of Production Phase 3) mid-2024.


Ok, the owners of those millions of servers have a problem in their
hands.

What you are saying is that there will be a bonanza next year for Python
2-to-3 consultants. It will also involve a forced upgrade to RHEL 8
(which is nowhere in sight yet).


Not really, though a growing market is good. The OS system tools are in 
Python 2 so that's what is installed. Nothing prevents an application 
from installing Python 3, it just can't overwrite the OS python.


Application developers can put Python 3 in /usr/local or can use one of 
the probably older python3 rpm stacks. My dev box has both the OS Python 
2.6.6 and Python 3.6.2 called as python3.



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


Re: Using Python 2

2017-09-08 Thread Leam Hall

Various responses in no particular order:

On 09/08/2017 09:57 AM, Ned Batchelder wrote:

I've heard a lot of FUD about the Python 3 transition, but this one is
new to me.  What is it that CompSci folks want that developers don't
want, that ruined Python 3?



It's not FUD if it's true. Calling it FUD without checking is, um, FUD. 
The phrase was "many of the changes in Python 3 are theoretically based, 
cleaning up of how Python does things to make them fit with what 
Computer Science teaches."



On 09/08/2017 08:51 AM, Chris Angelico wrote:
> Let's see. You can port your code from Python 2.7 to Python 3.6 by
> running a script and then checking the results for bytes/text
> problems.

I ran 2to3 on some code that worked under 2.6.6. and 3.6.2. 2to3 broke 
it for both versions and it was a fairly trivial script.




On 09/08/2017 08:42 AM, Marko Rauhamaa wrote:
> That's somewhat irrelevant. Point is, Python 2 will quickly become a
> pariah in many corporations during or after 2018, and we are going to
> see emergency measures similar to the Y2K craze twenty years ago.
>
> The risk to Python will be whether the occasion is exploited by
> fanboys of competing programming languages. The migration from 
Python2 > might be to something else than Python 3 in some circles.


To me this is where the Python community comes in. Moving 3,000 servers 
from RHEL 6 to something that uses Python 3 isn't a trivial task when 
most of those servers are not homogenous HPC nodes.


If Python 2 has bugs that aren't going to be fixed, then let's ask the 
question. If Python 3 was a total re-write that is not backwards 
compatible then it likely has some of the same bugs (due to same coders) 
plus new ones. If Python 3 is not a total re-write then why break 
compatibility?


To say Python 2 is old is true. What does it matter though? Unless 
Python 3 provides a business value for spending lots of time and money 
to change then "old" doesn't matter.


You're right that people may migrate to something besides Python. For me 
that question is real and some of the fuel is how the community can't 
understand that I work on servers that only have an old version of 
python. So far one person has answered the original design question. 
Everyone else has tried to convince me of something that is financially 
and professionally impossible and completely useless.


If you want to encourage people to move from Python 2 to 3 then continue 
to help answer questions when they are Python 2 based. Over time an 
individuals preference will be to move to Python 3 since 90% of the 
skill is already there. From a purely "is python a good language for 
many use cases" perspective the answer is yes. Welcome people and let 
their task needs and passions drive the change.


Leam

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


Not appending ("lib") to sys.path breaks tests.

2017-09-08 Thread Leam Hall
A kind soul pointed out that my code uses a sys.path.append("lib") to 
get files to be imported:


sys.path.append("lib")
from character_tools import *

He noted that having an __init__.py in lib and using:

from .character_tools import *

Should be sufficient for "please don't comment yet about 'import *'" 
levels of sufficient.   :P


The code works under python 2.6.6 and 3.6.2. However, py.test (python 2) 
and pytest (python 3) fails. Besides my usual clue, what am I missing?




### py.test (python 2)
= test session starts 
=

platform linux2 -- Python 2.6.6 -- pytest-2.3.5
collected 0 items / 3 errors

=== ERRORS 

__ ERROR collecting tests/test_base_tools.py 
__

tests/test_base_tools.py:6: in 
>   import lib.base_tools
E   ImportError: No module named lib.base_tools
__ ERROR collecting tests/test_character.py 
___

/usr/lib/python2.6/site-packages/_pytest/python.py:352: in _importtestmodule
>   mod = self.fspath.pyimport(ensuresyspath=True)
/usr/lib/python2.6/site-packages/py/_path/local.py:621: in pyimport
>   __import__(modname)
E File 
"/home/leam/lang/git/makhidkarun/py_tools/tests/test_character.py", line 6

E   import .lib.character
E  ^
E   SyntaxError: invalid syntax
___ ERROR collecting 
tests/test_character_tools.py 

tests/test_character_tools.py:6: in 
>   from ..lib.character_tools import *
E   ValueError: Attempted relative import in non-package
=== 3 error in 0.05 seconds 
===




### pytest (python 3)

= test session starts 
=

platform linux -- Python 3.6.2, pytest-3.2.2, py-1.4.34, pluggy-0.4.0
rootdir: /home/leam/lang/git/makhidkarun/py_tools, inifile:
collected 0 items / 3 errors 



=== ERRORS 

__ ERROR collecting tests/test_base_tools.py 
__
ImportError while importing test module 
'/home/leam/lang/git/makhidkarun/py_tools/tests/test_base_tools.py'.

Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_base_tools.py:6: in 
import lib.base_tools
E   ModuleNotFoundError: No module named 'lib'
__ ERROR collecting tests/test_character.py 
___
/usr/local/lib/python3.6/site-packages/_pytest/python.py:395: in 
_importtestmodule

mod = self.fspath.pyimport(ensuresyspath=importmode)
/usr/local/lib/python3.6/site-packages/py/_path/local.py:662: in pyimport
__import__(modname)
E File 
"/home/leam/lang/git/makhidkarun/py_tools/tests/test_character.py", line 6

E   import .lib.character
E  ^
E   SyntaxError: invalid syntax
___ ERROR collecting 
tests/test_character_tools.py 

tests/test_character_tools.py:6: in 
from ..lib.character_tools import *
E   ValueError: attempted relative import beyond top-level package
!!! Interrupted: 3 errors during collection 
!!!
=== 3 error in 0.22 seconds 
===

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


Re: Not appending ("lib") to sys.path breaks tests.

2017-09-08 Thread Leam Hall

On 09/08/2017 05:41 PM, Ian Kelly wrote:


I'm confused about where the character_tools import is made. If that's
within a module in the lib package, it should be fine.



It looks like it's failing to find the lib package. Since you removed
the "lib" directory from sys.path, does its parent directory exist in
sys.path?


The path is not in the modules path or in sys.path. Hence the append. I 
thought I could add the local "lib" path via "." or "lib.", but it seems 
not.


import lib.character fails in the tests/ directory.



Relative imports are only allowed with the "from .foo import bar" syntax.

However if you fix that, I suspect you're then going to run into the
next error below here. I think you actually just want an absolute
import like "import lib.character" here.





Packages and directories are not the same thing. This is saying that
the tests directory is not a package, so you can't do a relative
import within it. You probably just want "from lib.character_tools
import *".

The Python 3 errors are the same as the above.


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


Re: Using Python 2

2017-09-08 Thread leam hall
On Fri, Sep 8, 2017 at 6:35 PM, Christopher Reimer <
christopher_rei...@icloud.com> wrote:

> > On Sep 8, 2017, at 6:57 AM, Ned Batchelder 
> wrote:
> >
> > What is it that CompSci folks want that developers don't
> > want, that ruined Python 3?
>
> Long-winded debates about obscure language features that left the layman
> programmers in the bit bucket about 50+ comments ago.
>
> While some of this can be informative and enlightening, it can also be a
> bit  tedious to read. Just saying...
>


Chris;  Ned and I have had a great chat off-line. Hopefully the layman
programmers are coming out of the bucket soon.  :)

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


Re: People choosing Python 3

2017-09-10 Thread Leam Hall

On 09/10/2017 04:19 AM, Chris Warrick wrote:

On 10 September 2017 at 09:30, Marko Rauhamaa  wrote:

INADA Naoki :


I can't wait Python 3 is the default Python of Red Hat, and "python"
command means Python 3 on Debian and Ubuntu.


I can't wait till Python 3 is available on Red Hat.


Python 3.4 is available in EPEL. RHEL 8 will switch to Python 3 as the
main Python interpreter (assuming dnf replaces yum, as it did in
Fedora a while back).


I'm not sure that RHEL 8 will be Python 3 for the OS tools. Even if it 
is, which version?


From a non-rpm perspective Python 3.6.2 compiles nicely on CentOS 6. 
Once compiled it seems easy to use pip3 to install stuff without 
trampling on the OS's Python 2 install.


Just have to make sure your PATH is set right. By putting /usr/local/bin 
after /usr/bin I can use "py.test" to run tests under Python 2 and 
"pytest" for Python 3.


Leam

p.s. Sorry Chris, meant to send this to the list. You get it twice.
--
https://mail.python.org/mailman/listinfo/python-list


Python in Perspective

2017-09-10 Thread Leam Hall

y'all,

My god-kids and their proginators lost most everything because of 
Harvey. I spent much of yesterday worrying about a friend who had gone 
quiet as he evacuated his family ahead of Irma.


Please keep Python in perspective. Whether we use 1.5 or 4rc1 is a lot 
less critical than using Python to work together well and solving big 
problems as friends.


In years gone by I spent time on the soapbox but never came away cleaner 
or with stronger friendships. I just ranted and spent years wondering 
why nothing actually changed. Please don't make my mistake; come up with 
your own.


Together. As friends.

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


Re: [Tutor] beginning to code

2017-09-10 Thread leam hall
I will add my +1 to the careful editing of code. Python's use of white
space is pretty good once you get used to it. My Ruby code looks a lot like
my Python code.  :)

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


Re: Design: method in class or general function?

2017-09-10 Thread Leam Hall

On 09/08/2017 03:06 AM, Peter Otten wrote:

leam hall wrote:


On Thu, Sep 7, 2017 at 8:16 AM, Steve D'Aprano
 wrote:


On Thu, 7 Sep 2017 07:20 pm, Leam Hall wrote:


OOP newbie on Python 2.6.


Python 2.6 is ancient, and is missing many nice features. You should
consider
using the latest version, 3.6.



I've wrestled with that discussion for a while and Python 3 loses every
time. There's literally no good reason for me to move to Python 3 earlier
than mid-2020's. Please accept the fact that there are hundreds of
thousands of servers, if not millions, running Python 2.x. Whether or not
Python 3 has any neat cool stuff is irrelevant to those of us seeking to
use Python to get today's work done.


I create instances of Character class with an attribute dict of

'skills'. The 'skills' dict has the name of a skill as the key and an
int as a value. The code adds or modifies skills before outputting the
Character.

Is it better design to have a Character.method that takes a 'skill' key
and optional value or to have a general function that takes an
instance, a dict, a key, and an optional value?


I'm afraid your example is too generic for me to give an opinion. Do you
literally mean a method called "method"? What does it do?




Using this:
https://github.com/makhidkarun/py_tools/blob/master/lib/character.py

Line 19 sets "self.skills" either from the passed in data or from
https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py
#L34-L48

So Character.skills is a dict with a string key and an int value. I need
to be able to add skills and my first attempt is a function:
https://github.com/makhidkarun/py_tools/blob/master/lib/character_tools.py
#L52-L56

Should the "add_skills" function be a method in the character class or be
made a more generic function to add/modify a key/value pair in a dict that
is an attribute of an instance? Other tasks will require the add/modify
functionality but coding that increases complexity. At least for me,
anyway.

Sorry about being unclear earlier, coffee was still kicking in and I'm
still a newbie that mixes up terms.


I'm pleading "method" as it allows per-class implementation.

Say you use per-career subclasses of a general Character class. There are
default per-career skill sets, but usually a Character can acquire a skill
that is not needed in his career -- with the exception that Rogues cannot
tap dance ;)

Below is a way to implement that with a specialised add_skill() method:

$ cat basic_oo.py
from __future__ import print_function
import random
from collections import defaultdict


class Character(object):
 DEFAULT_SKILLS = ['Blade', 'GunCbt', 'Admin', 'Streetwise']

 def __init__(self):
 self.skills = defaultdict(int)

 def add_random_skills(self, terms):
 skillnames = self.DEFAULT_SKILLS
 for _ in range(2*terms):
 self.add_skill(random.choice(skillnames))

 def add_skill(self, name, amount=1):
 self.skills[name] += amount

 def __str__(self):
 skills = ", ".join(
 "{}={}".format(name, amount)
 for name, amount in sorted(self.skills.items())
 if amount != 0
 )
 return "{}({})".format(self.__class__.__name__, skills)


class Rogue(Character):
 def add_skill(self, name, amount=1):
 if name == "TapDance":
 raise ValueError("Sorry, this rogue will never tap dance")
 super(Rogue, self).add_skill(name, amount)


class Marine(Character):
 DEFAULT_SKILLS = ['GunCbt', 'VaccSuit', 'Leadership', 'Vehicle']


def main():
 NUM_CHARACTERS = 5
 CHARACTERS = [Marine, Rogue]

 characters = [
 random.choice(CHARACTERS)() for _ in range(NUM_CHARACTERS)
 ]

 for c in characters:
 c.add_random_skills(5)
 c.add_skill("RepairBicycles", random.randrange(3))
 try:
 c.add_skill("TapDance", 3)
 except ValueError as err:
 print(err)

 for c in characters:
 print(c)


if __name__ == "__main__":
 main()

$ python basic_oo.py
Sorry, this rogue will never tap dance
Sorry, this rogue will never tap dance
Sorry, this rogue will never tap dance
Rogue(Admin=3, Blade=4, GunCbt=2, Streetwise=1)
Marine(GunCbt=5, Leadership=4, TapDance=3, VaccSuit=1)
Rogue(Blade=3, GunCbt=2, RepairBicycles=2, Streetwise=5)
Rogue(Admin=1, Blade=2, GunCbt=5, RepairBicycles=1, Streetwise=2)
Marine(GunCbt=1, Leadership=3, RepairBicycles=2, TapDance=3, VaccSuit=2,
Vehicle=4)



Okay Peter, I took your idea and mangled it beyond recognition. There's 
a design constraint I hadn't mentioned: an instance of Character should 
be able to have multiple careers.


Also, an in

Re: Design: method in class or general function?

2017-09-11 Thread Leam Hall

On 09/11/2017 03:30 AM, Peter Otten wrote:

Leam Hall wrote:



Okay Peter, I took your idea and mangled it beyond recognition. There's
a design constraint I hadn't mentioned: an instance of Character should
be able to have multiple careers.

Also, an instance can be created from scratch, created from a full set
of data, or created from a partial set of data.

Here's my current code, focusing on creating a lot of merchants:


https://github.com/makhidkarun/py_tools/blob/merchant/lib/character.py#L60-L61


python chargen.py
Toby Verstraeten 564775 [M] Age: 41
Merchant (5 terms)
Computer-2 Engineering-5 Navigation-2 Pilot-1

Captain Ian Domici   789987 [M] Age: 24
Firster (3 terms) Merchant (3 terms) Noble (2 terms)
Broker-2 GunCbt-1 Streetwise-2

Rosa 66495B [F] Age: 24
Merchant (1 terms)
Computer-1 Navigation-1


As you can see, lots to work on. However, with a very loose definition
of "work", this works.

The goal is to have a set of Career classes. The program will allow a
user to select one or more Careers. The program will create a basic
character and then modify the character by the selected Career class(es).

If the Career does not exist in a file then the character gets assigned
a generic Career based on social status.

Careers are each in their own file and the program builds the list of
available careers by slurping up those file names.
Adding a Career should just be adding a properly formatted file.
Import happens when a Career is selected to modify the character

I've done this in Ruby so my guess is it can be done in Python. Even
Python 2.  :D

The Career seems to be a "Decorator" pattern given my limited
understanding of design patterns. Concur? If so I'll go study that some
more.


The first thought that triggered was @decorator, and only then, because that
didn't make sense, the focus changed on "design patterns". While I would
tend to "composite" rather than "decorator" it's been some time since I read
the book...
  

Do you feel this path should still make a Career a class?


As long as it's only a dictionary entry

 self.character.careers['Merchant'] = self.terms

and the addition of some skills a function would work fine, too.
If you expect that you will later add other features which vary over careers
you should consider a Career base class that you can subclass as needed. If
you use a class it's worthwhile to keep the instance around

 self.character.careers['Merchant'] = self  # a careers set
# would work, too.

(If you want to avoid the reference cycle do not store the character as an
attribute.)



Haven't read the GoF book. Last time I checked it said "this is only 
useful if you know Java", and I don't. Is there a good Python 2 
compatible reference? I just picked up an old copy of "Programming 
Python" and haven't gotten far into it yet.


My goal isn't to use patterns for the pattern's sake, but to use a 
decently right tool for the job. There will be a Career class that gets 
sub-classed. There are enough differences between the careers to need that.


I do not understand your last sentence about reference cycle. That may 
be where I'm struggling.


A character is an instance of class Character.
All characters have base attributes: upp, name, gender.
A character will usually have a career.
A character may have more than one career.
A career modifies the character in one or more of the following:
attribute skills
attribute careers
attribute age
attribute stuff
attribute background_info

Should the "run_career()" process be a method of character, with 
parameters of career and terms? Or a composite-ing class that created 
the character and then run them through the careers?


The composite model might work better as a future step will be to offer 
different ways to output the character; text to screen, json, sql, etc.


Hmm...thinking about the composite seems useful. That way users could 
add extra composite steps for their needs without flooding class 
Character with extra methods for each use case.


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


Re: Design: method in class or general function?

2017-09-11 Thread leam hall
On Mon, Sep 11, 2017 at 7:48 AM, Stefan Ram  wrote:

> Leam Hall  writes:
> >Haven't read the GoF book. Last time I checked it said "this is only
> >useful if you know Java"
>
>   In the edition of 1997, some design patterns are accompanied
>   with examples in C++ or Smalltalk, but the majority of the
>   patterns is language agnostic (often UML diagrams are used).
>

Also, I may have been thinking of the "Head First Design Patterns" book.
Looks like I need to talk to my good buddy Amazon...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: People choosing Python 3

2017-09-11 Thread leam hall
On Mon, Sep 11, 2017 at 8:00 AM, Pavol Lisy  wrote:

>
>
> Which part of third party ecosystem surrounding Python 3 is not (and
> could not be any time soon) sufficiently mature?
> --
>
>
yum, twisted.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The Incredible Growth of Python (stackoverflow.blog)

2017-09-12 Thread Leam Hall

On 09/12/2017 12:29 AM, Chris Angelico wrote:

On Tue, Sep 12, 2017 at 1:42 PM, Paul Rubin  wrote:

Chris Angelico  writes:

students learning Python *today* ... they're learning Python 3.


I'm not so sure of that.  I do know a few people currently learning
Python, and they're using Python 2.


Why? Unless they're going to be maintaining a Py2 codebase, why should
they learn the older version with less features?

At Thinkful (shameless plug[1]), students learn Python 3 almost
exclusively (we do have a data science course in which students learn
either or both, but in the web dev course, it's definitely Py3). I
haven't had anyone run into difficulties with annotations/type hints
(we don't teach them, so how would they be bothered?), print being a
function (everything else is a function so it's no surprise that print
is too), etc, and even the text/bytes split is only a problem when
students are working with non-ASCII data files provided by third
parties, at which point they have to learn about encoding="...". Now,
I just need to convince people to stop putting "first name" and
"surname" fields on their web forms [2], and things will be about
perfect...

ChrisA

[1] I teach via www.thinkful.com. My views are my own, not that of my employer.
[2] 
http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/



Hey Chris,

This is an area the Python community can improve on. Even I would 
encourage someone new to Python and wanting to do webdev to use Python 3.


But if someone comes onto the list, or IRC, and says they need to stay 
on Python 2 then please drop the dozens of e-mails and comments about 
upgrading. Help the person learn; that makes them happier with Python 
and when the time comes to switch to Python 3 they probably will.


My recent experience with some people's inability to take "Sorry, I 
can't" for an answer has been a real turn-off. I have requirements that 
dictate Python. If this was a personal venture I'd already be elsewhere 
purely because the Python community on the list and IRC is so unwelcoming.


I encourage those of you who are Python experts, trainers, or authors: 
lead by example. Help people learn Python. Grow the community. Just 
because TIOBE and IEEE say Python is top dog today doesn't mean those 
stats can't change. The community will drive the success of Python, not 
the technical features.


Leam

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


Re: The Incredible Growth of Python (stackoverflow.blog)

2017-09-12 Thread Leam Hall

On 09/12/2017 07:27 AM, Chris Angelico wrote:

On Tue, Sep 12, 2017 at 9:20 PM, Leam Hall  wrote:

Hey Chris,

This is an area the Python community can improve on. Even I would encourage
someone new to Python and wanting to do webdev to use Python 3.

But if someone comes onto the list, or IRC, and says they need to stay on
Python 2 then please drop the dozens of e-mails and comments about
upgrading. Help the person learn; that makes them happier with Python and
when the time comes to switch to Python 3 they probably will.


If you read back in my emails, you may find that I actually wasn't
telling you to upgrade to Python 3 - just to Python 2.7, which is an
easy upgrade from 2.6, and gives you the security fixes and other
improvements that come from using a supported version of the language.
Is it "hostile" to tell people to upgrade like that? If someone is
using Python 3.2 today, I'm going to strongly recommend upgrading to
the latest 3.x. If someone's using Windows 98, I'm not going to say
"well, here's how to get everything working under Win98", I'm going to
say "upgrade to a better OS".

If that's hostile, I am not sorry to be hostile. At some point, you
have to either get onto something supported, or do all the support
work yourself.

ChrisA



Hey Chris; only some folks were overtly hostile.  :)

Yet look at your answer; "upgrade". For a person working on a server 
there's usually no economic choice to do. The OS python must stay in 
place and the newly installed upgrade must be personally maintained, 
updated, and tested when security patches come out. For one desktop 
that's not an issue. For dozens, or hundreds, or thousands, its not 
likely to happen.


I stand by my position; accept the "no" and move forward. Let "no" mean 
"no".


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


Re: The Incredible Growth of Python (stackoverflow.blog)

2017-09-12 Thread Leam Hall

Steve,

Thank you very much. I appreciate your wisdom and support.

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


Re: The Incredible Growth of Python (stackoverflow.blog)

2017-09-12 Thread Leam Hall

On 09/12/2017 08:28 AM, Steve D'Aprano wrote:

On Tue, 12 Sep 2017 09:20 pm, Leam Hall wrote:


But if someone comes onto the list, or IRC, and says they need to stay
on Python 2 then please drop the dozens of e-mails and comments about
upgrading.

[...]

My recent experience with some people's inability to take "Sorry, I
can't" for an answer has been a real turn-off. I have requirements that
dictate Python. If this was a personal venture I'd already be elsewhere
purely because the Python community on the list and IRC is so unwelcoming.


Leam, I've defended people choosing to remain on older versions of Python, even
as old as 1.5. The most recent was just a couple of minutes ago, in my response
to Chris. It's not nice or friendly of you to tar the entire community with a
reputation because of one or two people saying something you don't want to
debate.

But it isn't all about you. Just because you started this thread -- oh wait, you
didn't *wink* -- doesn't mean you control its direction. If people want to
discuss the pros and cons of upgrading, without specifically badgering you, you
should remember that *it isn't about you* and don't take it personally.


WHAT?!?!?!  It isn't all about me?  Dang...

Steve, you're right; sorry for painting with such a broad brush. Even 
the people who occasionally post something that seems problematic (to 
me) are usually helpful.


A few months ago my manager asked about what direction I recommended for 
the team. I'm the opinionated old guy who is new to this team. At the 
time I was really enjoying Ruby; just so dang fun!


I told my manager that we should use python. It is the best choice for 
the team since we're on RHEL 6. Ruby wasn't on the machines but Python 
2.6.6 is. Any code I write that is python 2.6.6 compatible should run on 
every machine.


My answer meant I had to re-direct personal time and attention so I 
could help the team move forward. There are certain things I can do; 
learn to code better, write more tests, and figure out OOP. Some things 
I can't do; changing the supported python version is on that list.


Python is the right choice for a lot of use cases. Python 3 is the right 
choice for a large sub-set of those use cases. Python 2 is the best 
choice for a much smaller subset.



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


Re: The Incredible Growth of Python (stackoverflow.blog)

2017-09-12 Thread leam hall
On Tue, Sep 12, 2017 at 8:28 AM, Steve D'Aprano 
wrote:

> On Tue, 12 Sep 2017 09:20 pm, Leam Hall wrote:
>
> > But if someone comes onto the list, or IRC, and says they need to stay
> > on Python 2 then please drop the dozens of e-mails and comments about
> > upgrading.
> [...]
> > My recent experience with some people's inability to take "Sorry, I
> > can't" for an answer has been a real turn-off. I have requirements that
> > dictate Python. If this was a personal venture I'd already be elsewhere
> > purely because the Python community on the list and IRC is so
> unwelcoming.
>
> Leam, I've defended people choosing to remain on older versions of Python,
> even
> as old as 1.5. The most recent was just a couple of minutes ago, in my
> response
> to Chris. It's not nice or friendly of you to tar the entire community
> with a
> reputation because of one or two people saying something you don't want to
> debate.
>
> But it isn't all about you. Just because you started this thread -- oh
> wait, you
> didn't *wink* -- doesn't mean you control its direction. If people want to
> discuss the pros and cons of upgrading, without specifically badgering
> you, you
> should remember that *it isn't about you* and don't take it personally.
>

Steve, just a quick follow-up. Thank you for calling me out on this! It's
wrong for me to do something I complain about others doing. Feel free to
reach through the ether and smack me if I do this again.

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


Re: Python dress

2017-09-12 Thread Leam Hall

On 09/12/2017 04:00 PM, Ben Finney wrote:

Larry Martell  writes:


https://svahausa.com/collections/shop-by-interest-1/products/python-code-fit-flare-dress
(And if any guys want to wear this, there's nothing wrong with that.)


Boo, the code is not PEP 8 conformant :-)

If it weren't for the bad code style, I might consider it. The dress
looks good!



Note that a google search of "python muscle shirt" didn't seem to come 
up with any code. Wonder why?  :P

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


Re: "tkinter"

2017-09-13 Thread leam hall
On Wed, Sep 13, 2017 at 8:28 AM, Stefan Ram  wrote:

>   I presume that "tkinter" is intended to be pronounced
>   "logically":
>
> T K inter (tee kay inter /ti keI In t%/)
>
>   . But it would be faster to pronounce it
>
> T kinter (tee kinter /ti kIn t%/)
>
>   . So far I've only ever read it, never heard it.
>   But while I am aware that the logical pronunciation should
>   be the correct one, I actually like the faster one.
>
>
I heard a speaker mention GvR by name and it took me a bit, and IRC, to
find out the Dutch pronunciation is different from the American. I've seen
his name lots, hadn't heard it.

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


Re: the core values of the Python "platform"

2017-09-13 Thread leam hall
On Wed, Sep 13, 2017 at 9:08 AM, Darin Gordon  wrote:

> Bryan Cantrill gave an interesting talk recently at a Node conference about
> "platform values" [1]. The talk lead me to think about what the core values
> of the Python "platform" are and I thought it would be good to ask this
> question of the community. What would you consider the top (<= 5) core
> values?
>
>
Would that be close to the Zen of Python?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Old Man Yells At Cloud

2017-09-17 Thread Leam Hall
Different view, I guess. I'm glad all the young Javascripters have that 
issue. As an old guy trying to re-learn more python it gives me an 
advantage. I'm usually interested in the best thislanguage-native way to 
do something. Doing so makes me learn the language faster and tends to 
generate better code.


That said, I'll often steal what I've learned before to understand the 
new. Some helpful folks on IRC asked why I was using getopt instead of 
argparse. Mostly because I come from a bash background. Looking at 
Python's argparse would have stumped me if I hadn't already done the 
same thing with Ruby's argparse.


I'm still trying to figure out how to convert a string to unicode in 
Python 2. I've done it in Ruby 1.8.7 so I assume Python 2 can do it and 
that I'm just a bit slow.


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


Re: Old Man Yells At Cloud

2017-09-17 Thread Leam Hall
Hmm... scratch the "young" and "Javascripters". Why lump them together 
since I bet it's just a vocal few? Better to have said "people who don't 
want to really learn the new language".


On 09/17/2017 06:03 AM, Leam Hall wrote:
Different view, I guess. I'm glad all the young Javascripters have that 
issue. As an old guy trying to re-learn more python it gives me an 
advantage. I'm usually interested in the best thislanguage-native way to 
do something. Doing so makes me learn the language faster and tends to 
generate better code.


That said, I'll often steal what I've learned before to understand the 
new. Some helpful folks on IRC asked why I was using getopt instead of 
argparse. Mostly because I come from a bash background. Looking at 
Python's argparse would have stumped me if I hadn't already done the 
same thing with Ruby's argparse.


I'm still trying to figure out how to convert a string to unicode in 
Python 2. I've done it in Ruby 1.8.7 so I assume Python 2 can do it and 
that I'm just a bit slow.


Leam

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


Unicode (was: Old Man Yells At Cloud)

2017-09-17 Thread Leam Hall

On 09/17/2017 07:25 AM, Steve D'Aprano wrote:

On Sun, 17 Sep 2017 08:03 pm, Leam Hall wrote:


I'm still trying to figure out how to convert a string to unicode in
Python 2.



A Python 2 string is a string of bytes, so you need to know what encoding they
are in. Let's assume you got them from a source using UTF-8. Then you would do:

mystring.decode('utf-8')

and it will return a Unicode string of "code points" (think: more or less
characters).



Still trying to keep this Py2 and Py3 compatible.

The Py2 error is:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6'
in position 8: ordinal not in range(128)

even when the string is manually converted:
name= unicode(self.name)

Same sort of issue with:
name= self.name.decode('utf-8')


Py3 doesn't like either version.


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


Re: Unicode

2017-09-17 Thread Leam Hall

On 09/17/2017 08:30 AM, Chris Angelico wrote:

On Sun, Sep 17, 2017 at 9:38 PM, Leam Hall  wrote:

Still trying to keep this Py2 and Py3 compatible.

The Py2 error is:
 UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6'
 in position 8: ordinal not in range(128)

even when the string is manually converted:
 name= unicode(self.name)

Same sort of issue with:
 name= self.name.decode('utf-8')


Py3 doesn't like either version.


You got a Unicode *EN*code error when you tried to *DE* code. That's a
quirk of Py2's coercion behaviours, so the error's a bit obscure, but
it means that you (most likely) actually have a Unicode string
already. Check what type(self.name) is, and see if the problem is
actually somewhere else.

(It's hard to give more specific advice based on this tiny snippet, sorry.)

ChrisA



Chris, thanks! I see what you mean.

The string source is a SQLite3 database with a bunch of names. Some have 
non-ASCII characters. The database is using varchar which seems to be 
utf-8, utf-16be or utf-16le. I probably need to purge the data.


What I find interesting is that utf-8 works in the Ruby script that 
pulls from the same database. That's what makes me think it's utf-8.


I've tried different things in lines 45 and 61.

https://gist.github.com/LeamHall/054f9915af17dc1b1a33597b9b45d2da

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


Re: Unicode

2017-09-17 Thread leam hall
On Sun, Sep 17, 2017 at 9:13 AM, Peter Otten <__pete...@web.de> wrote:

> Leam Hall wrote:
>
> > On 09/17/2017 08:30 AM, Chris Angelico wrote:
> >> On Sun, Sep 17, 2017 at 9:38 PM, Leam Hall  wrote:
> >>> Still trying to keep this Py2 and Py3 compatible.
> >>>
> >>> The Py2 error is:
> >>>  UnicodeEncodeError: 'ascii' codec can't encode character
> >>>  u'\xf6' in position 8: ordinal not in range(128)
> >>>
> >>> even when the string is manually converted:
> >>>  name= unicode(self.name)
> >>>
> >>> Same sort of issue with:
> >>>  name= self.name.decode('utf-8')
> >>>
> >>>
> >>> Py3 doesn't like either version.
> >>
> >> You got a Unicode *EN*code error when you tried to *DE* code. That's a
> >> quirk of Py2's coercion behaviours, so the error's a bit obscure, but
> >> it means that you (most likely) actually have a Unicode string
> >> already. Check what type(self.name) is, and see if the problem is
> >> actually somewhere else.
> >>
> >> (It's hard to give more specific advice based on this tiny snippet,
> >> sorry.)
> >>
> >> ChrisA
> >>
> >
> > Chris, thanks! I see what you mean.
>
> I don't think so. You get a unicode from the database,
>
> $ python
> Python 2.7.6 (default, Oct 26 2016, 20:30:19)
> [GCC 4.8.4] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import sqlite3
> >>> db = sqlite3.connect(":memory:")
> >>> cs = db.cursor()
> >>> cs.execute("select 'foo';").fetchone()
> (u'foo',)
> >>>
>
> and when you try to decode it (which is superfluous as you already have
> unicode!) Python does what you ask for. But to be able to decode it has to
> encode first and by default it uses the ascii codec for that attempt. For
> an
> all-ascii string
>
> u"foo".encode("ascii") --> "foo"
>
> and thus
>
> u"foo".decode("utf-8)
>
> implemented as
>
> u"foo".encode("ascii").decode("utf-8") --> u"foo"
>
> is basically a noop. However
>
> u"äöü".encode("ascii") --> raises UnicodeENCODEError
>
> and thus
>
> u"äöü".decode("utf-8")
>
> fails with that. Unfortunately nobody realizes that the encoding failed and
> thus will unsuccessfully try and specify other encodings for the decoding
> step
>
> u"äöü".decode("latin1")  # also fails
>
> Solution: if you already have unicode, leave it alone.
>

Doesn't seem to work. The failing code takes the strings as is from the
database. it will occasionally fail when a name comes up that uses
a non-ascii character.

Lines 44, 60, 66, 67.

https://github.com/makhidkarun/py_tools/blob/master/lib/character.py

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


Re: Unicode

2017-09-17 Thread leam hall
On Sun, Sep 17, 2017 at 3:27 PM, Peter Otten <__pete...@web.de> wrote:

> leam hall wrote:
>
> > Doesn't seem to work. The failing code takes the strings as is from the
> > database. it will occasionally fail when a name comes up that uses
> > a non-ascii character.
>
> Your problem in nuce: the Python 2 __str__() method must not return
> unicode.
>
> >>> class Character:
> ... def __str__(self): return u"Brösel"
> ...
> >>> print(Character())
> Traceback (most recent call last):
>   File "", line 1, in 
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in
> position
> 2: ordinal not in range(128)
>
> While you may define a __unicode__ method it has to be called explicitly:
>
> >>> class Character:
> ... def __unicode__(self): return u"Brösel"
> ...
> >>> print(Character())
> <__main__.Character instance at 0x7fc10020f5a8>
> >>> print(unicode(Character()))
> Brösel
>
> Another alternative is to convert explicitly, to some encoding, and hope it
> works in the actual environment:
>
> >>> class Character:
> ... def __unicode__(self): return u"Brösel"
> ... def __str__(self): return unicode(self).encode("utf-8")
> ...
> >>> print(Character())
> Brösel
>

Ah! So this works in Py2:
   def __str__(self):
 name= self.name.encode("utf-8")


It completely fails in Py3:
  PVT b'Lakeisha F\xc3\xa1bi\xc3\xa1n' 7966A4 [F] Age: 22


Note that moving __str__() to display() gets the same results. Not sure it
is an issue with __str__.



> The more you think about it the more attractive a switch to Python 3 will
> appear.
>

Not for me, actually. I'm trying to learn better OOP and coding in general.
I'm using Python because there's a work related use case for Py2. There
isn't one for Py3. If the work use case it removed then there are lots of
languages to try out.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unicode

2017-09-17 Thread leam hall
Matt wrote:

Hi Leam-
>
> Targeting Python 2.6 for deployment on RHEL/CentOS 6 is a perfectly
> valid use case, and after the recent discussions in multiple threads
> (your "Design: method in class or general function?" and INADA Naoki's
> "People choosing Python 3"), I doubt it would be very useful to
> reiterate the same points.
>
> I can't speak for Peter Otten, but I suspect he was making a very narrow
> statement about one of the large backwards-incompatible changes in
> Python 3: strict separation between text (str) and binary data (bytes).
> This stricter distinction eliminates the conceptual problems you
> described, in terms of ensuring that you need to use the right type at
> the right time in the right place, and would probably have prevented
> your problem entirely.
>
> Additionally, your note of "this works in Python 2 but fails in Python
> 3" shows some text-related confusion that is quite common when dealing
> with the text model in Python 2. It is always the case that the
> `__str__` method should return a `str` object under whichever version of
> Python you're using, and your attempt of `self.name.encode("utf-8")`
> returns the wrong type under Python 3. *Encoding* Unicode text (class
> `unicode` under Python 2, `str` under 3) produces binary data (class
> `str` under Python 2, `bytes` under 3). As such, you're returning a
> `bytes` object from `__str__` in Python 3, which is incorrect. It would
> be appropriate to do something like
>
> """
> def __str__(self):
> if sys.version_info[0] < 3:
> return self.name.encode("utf-8")
> return self.name
> """
>
> Django provides a `python_2_unicode_compatible` decorator that allows
> always returning text (class `unicode` under Python 2, `str` under 3)
> from `__str__`, and automatically rewrites a class' methods under Python
> 2. That decorator renames `__str__` to `__unicode__`, and creates a new
> `__str__` method that essentially returns
> `self.__unicode__().encode('utf-8')`.
>
> (Hopefully this is clear enough, but I intended this message to be
> practical advice for your current task and mental model of what's going
> on, *not* as Python 3 evangelism.)
>
> MMR...
>
>
Matt, thanks! I figured there was a way to get the python major version,
just hadn't gotten there yet. Your code passes user typing and testing.

Peter has earned a lot of leeway due to his expert help and reasonable
manner. I took his comment as a friendly note and, like yours, not Py3
evangelism.

Most of my frustration isn't with the community though I think it has come
off that way. I'm not a good enough coder to get a job with pay close to
what I make as a Linux guy. I just have to deal with the pay check coming
from where I am and not where the rest of the gang is.  :(

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


The Python-List community

2017-09-18 Thread Leam Hall
A few days ago I pointed out that this list's community had 
"opportunities to improve". While we still have lots of those 
opportunities, it is good to see several community members raise the bar 
in welcoming new folks into the community.


Thank you for your help and positive attitude!

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


How to share class relationship representations?

2017-09-19 Thread leam hall
I'm working on designing the classes, sub-classes, and relationships in my
code. What is a good visual way to represent it so it can be stored in git
and shared on the list without large images or attachments?

Thanks!

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


Re: Research paper "Energy Efficiency across Programming Languages: How does energy, time, and memory relate?"

2017-09-19 Thread leam hall
On Tue, Sep 19, 2017 at 2:37 PM, Stephan Houben <
stephan...@gmail.com.invalid> wrote:

> Op 2017-09-19, Steven D'Aprano schreef  pearwood.info>:
>
> > There is a significant chunk of the Python community for whom "just pip
> > install it" is not easy, legal or even possible. For them, if its not in
> > the standard library, it might as well not even exist.
>
> But numpy *is* in the standard library, provided you download the
> correct version of Python, namely the one from:
>
> https://python-xy.github.io/
>
> Stephan
>
>
Many of us can't pip install; it's in the OS supplied vendor repo or it
doesn't go on the machines.

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


Re: How to share class relationship representations?

2017-09-20 Thread Leam Hall

On 09/19/2017 11:16 AM, Stefan Ram wrote:

leam hall  writes:

I'm working on designing the classes, sub-classes, and relationships in my
code. What is a good visual way to represent it so it can be stored in git
and shared on the list without large images or attachments?


   Code /is/ design.



I tried that with the small bit of code I have and was told it was too 
confusing. Still working on this.

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


Re: Change project licence?

2017-09-23 Thread Leam Hall

On 09/23/2017 05:14 AM, Chris Angelico wrote:

On Sat, Sep 23, 2017 at 7:07 PM, Kryptxy  wrote:

Thank you all! I opened a ticket about the same (on github).
I got response from most of them, and all are agreeing to the change.
However, one contributor did not respond at all. I tried e-mailing, but no
response.
Can I still proceed changing the licence? It has been more than a week since
the ticket was opened.


Nope. Contributions made under the GPL have a guarantee that they will
only and forever be used in open source projects. You're trying to
weaken that guarantee, so you have to get clear permission from
everyone involved.

Unless you can show that the contributions in question are so trivial
that there's no code that can be pinpointed as that person's, or you
replace all that person's code, you can't proceed to relicense it
without permission.


I'm with Chris on this one. You made a social, and in many places 
legally binding, agreement. Can't change it without everyone's agreement.


Like Chris said, evaluate the level of effort on the code. Wait, or 
replace. You will be happier when you take the honorable path.


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


Re: Beginners and experts (Batchelder blog post)

2017-09-23 Thread Leam Hall

On 09/23/2017 02:40 PM, Terry Reedy wrote:

https://nedbatchelder.com//blog/201709/beginners_and_experts.html

Great post.


Yup. Thanks for the link. I often have that "I bet Fred> doesn't get frustrated." thing going. Nice to know Ned bangs his 
head now and again.  :P


Leam


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


Re: Beginners and experts (Batchelder blog post)

2017-09-27 Thread leam hall
On Sat, Sep 23, 2017 at 5:26 PM, Ned Batchelder 
wrote:

> On 9/23/17 2:52 PM, Leam Hall wrote:
>
>> On 09/23/2017 02:40 PM, Terry Reedy wrote:
>>
>>> https://nedbatchelder.com//blog/201709/beginners_and_experts.html
>>>
>>> Great post.
>>>
>>
>> Yup. Thanks for the link. I often have that "I bet > Fred> doesn't get frustrated." thing going. Nice to know Ned bangs his head
>> now and again.  :P
>>
>>
> "Ow!" --me


Hehe...I've been trying to figure out how to phrase a question. Knowing I'm
not the only one who gets frustrated really helps.

I'm trying to learn to be a programmer. I can look at a book and read basic
code in a few languages but it would be unfair to hire myself out as a
programmer. I'm just not yet worth what it costs to pay my bills.

To move forward takes a plan and time bound goals. At least for us old
folks; we only have so much time left. I want to avoid retirement and just
work well until I keel over.

I don't come from a CS background but as a Linux sysadmin. My current push
is OOP. Grady Booch's book on Analysis and Design is great and I've got the
GoF for right after that. I've been doing more testing but need to write
more tests. Writing code and starting to work with others on that code as
well.

The question is, what should a person "know" when hiring out as a
programmer? What is 'know" and what should be "known"? Specifically with
Python.

Thanks!

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


Re: Beginners and experts (Batchelder blog post)

2017-09-28 Thread Leam Hall

My question has received several helpful responses, thanks!

On 09/28/2017 01:01 PM, Dennis Lee Bieber wrote:

On Wed, 27 Sep 2017 12:41:24 -0400, leam hall 
declaimed the following:
"Programmer"... or "Software Engineer"?

I haven't kept up on "job titles" but for my history, "programmer" is
an entry level position, just a few steps up from "data entry operator"
(aka "keypunch operator" -- to show my age)


"Person who automates routine tasks".

I used to get asked for MAC addresses. I was playing with TCL at the 
time and it had a built in webserver sort of thing. The boxes were 
Solaris. Made a cron job to run Explorer on the servers and another to 
collate them to a node with the TCL webserver. Gave the Network team the 
URL.


I'll show my age; 5 bit ASCII punched tape and actual ferrite core 
memory.   :P



As a "programmer" (in my archaic world): be fluent in the language and
core of the runtime (though perhaps not a master -- I still don't get
Python's decorators and meta-class concepts; my uses haven't needed them).
Be able to read language agnostic requirement/design documentation and
translate to the language in question. At this level, knowledge of the
problem domain is probably not needed. At the higher levels, the language
begins to be irrelevant, but more knowledge of the problem domain becomes
important -- the difference between designing/coding a web-based
store-front (HTTP/HTML, database, security) vs number-crunching image
streams from space probes...

Afraid I've likely just tossed it back to you -- what really is your
goal? 


As an introvert with a speech impediment I live by "Don't call me, I 
won't call you."


Well, okay, yes. I did to Toastmasters and can shine at an interview. 
Still, day to day I prefer to create solutions that solve problems and 
answer questions before they are asked so no one asks me. I know a 
little Networking, Database, Systems Engineering, Project Management, 
Security, large datacenter, and other cool buzzwords to easily find a 
job doing Linux system admin. What I want to move away from is doing now 
what I was doing 10-15 years ago.


A couple years ago I was back into C. A RHEL bug came up and management 
needed to understand the severity of the issue. I was able to read the 
reports, dig through the kernel code, and explain the issues and risks 
to MBA and PM types. I'm not about to represent myself as a C programmer 
but I can follow #include files.


One place brought on Unix people and your first day was split between 
the Eng team lead and the Ops team lead. They would decide which you 
were more suited for. The Eng team lead wrote Perl and asked me to 
explain some of their code. I did and also pointed out a bug. Seems I 
was a better fit for the Ops team.  :P


My short term goals are to use Python to get better at OOP coding and to 
automate in Python stuff that might work in shell/awk but are more fun 
in python. To that end I'm reading Booch, just ordered an old copy of 
the Python Cookbook, and am coding a game/fiction tool to help me keep 
track of characters.


It is often said to learn a language you grab the basics and then join a 
project. I'm happy to contribute to open source projects but the 
learning curve to "useful" has always been steep for me. There's gap 
between reading "Learning {language}" and contributing code.


Python is very useful because all my RHEL boxes have it installed. If I 
build a tool I know it will be able to run. While I enjoy Ruby more, 
it's not on the servers and it ain't going on the servers. I need to be 
useful to keep getting paid. Due to developer count the ability to 
instigate a python project is easier than a non-rails ruby project so I 
can build my "software engineering team" skills as well.


I appreciate your guidance and feedback; keep it coming!

Leam




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


Re: Beginners and experts (Batchelder blog post)

2017-09-28 Thread Leam Hall

On 09/28/2017 07:35 AM, Stefan Ram wrote:


   But remember that paid programmers usually do not "code",
   in the sense of "write a program from scratch". Most of the
   work is maintenance programming, where an important part of
   the job is to read and understand a piece of code.
   Coding from scratch also happens, it just less common.

   (So that would be a reasonable interview test: Being able
   to understand a piece of given code and do some requested
   modification to it.)


Another Perl story. I used to love Perl and then got to the point where 
trying to code in it made me physically nauseous. Not sure why.


Guy had written a perl based time tracker for our contractor team. We'd 
enter tasks done and it would give a text based output to send to mgmt. 
Of course the guy hadn't planned on leaving after a few months and his 
program stored data by date but didn't separate by year. So I had to go 
figure out what it was doing since he was using a perl specific data 
archiver. Eventually just wound up blowing away the data store so each 
year was new. Told others how to handle it as I didn't want to do more 
perl and wasn't good enough at anything to replicate it all myself.


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


Re: Beginners and experts (Batchelder blog post)

2017-09-28 Thread Leam Hall

On 09/28/2017 04:15 AM, Paul Moore wrote:

With Python, I'd say that an appreciation of the available libraries
is key - both what's in the stdlib, and what's available from PyPI.
That's not to say you should memorise the standard library, but rather
cultivate an approach of "hmm, I'm pretty sure I remember there being
a library for that" and going to look. The best way of getting this is
to actually work with code - you can start with doing coding projects
of your own (it's *always* a good exercise to have a problem that
interests you, and work on coding it - no matter what it is, you'll
learn more about understanding requirements, testing, bug fixing, and
practical programming by working on a project you care about than
you'll ever get reading books) and/or you can look at existing open
source projects that you're interested in, and offer help (there's
always a bug tracker, and typically some simpler items - and you'll
learn a lot from interacting with a larger project).



When I first started in Unix/Linux there was a group called SAGE. They 
had a list of tasks a system admin was expected to be able to do and 
they sorted the list by "Junior", "Senior", or somesuch. I started at 
the bottom of the list and worked my way up.


One useful thing was to make a sorted list of commands in /usr/bin, 
/bin, /usr/sbin, and /sbin, and then read the first bit of the man page 
that showed what the command did. Fun stuff.


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


Re: Beginners and experts (Batchelder blog post)

2017-09-29 Thread Leam Hall

On 09/27/2017 10:33 PM, Stefan Ram wrote:


   Some areas of knowledge follow, a programmer should not be
   ignorant in all of them:


---

Stefan, this is list AWESOME!

I have started mapping skills I have to the list and ways to build 
skills I don't have. Last night I started working on a project that has 
been on my mind for over a year; taking a CSV list of game characters 
and putting them into a MongoDB datastore. Now I need to figure out how 
to build an interface for CRUD operations using Python, pymongo, and 
maybe Tk.


I appreciate the structure your list provides. Thank you!

Leam

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


Re: Beginners and experts (Batchelder blog post)

2017-09-29 Thread leam hall
On Fri, Sep 29, 2017 at 10:52 AM, justin walters  wrote:

>
> I got through writing all of the above without realizing that you meant you
> wanted to build a
> desktop application and not a web application. Though, I think the advice
> is still helpful.
>
>
Yes and no. Seriously thanks!

I am at first targeting a desktop app just to be simpler and to push me to
learn Tkinter. However, it's more likely to end up a simple web app once I
learn enough Bottle/Flask to make it work. Or I may just skip Tkinter for
the nonce and see if I can do it with web forms.

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


Good virtualenv and packaging tutorials for beginner?

2017-10-04 Thread Leam Hall
Folks on IRC have suggested using virtualenv to test code under 
different python versions. Sadly, I've not found a virtualenv tutorial I 
understand. Anyone have a link to a good one?


The next step will be to figure out how to package a project; a good 
tutorial URL would be appreciated on that, too.


Thanks!

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


Python community "welcoming" feedback

2017-10-04 Thread Leam Hall
A while back I pointed out some challenges for the Python community's 
intake of new coders. Mostly focusing on IRC and the Python e-mail list.


Several people have stepped up their "welcome" game and I've been very 
impressed with the way things are going.


Great job!

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


Re: Good virtualenv and packaging tutorials for beginner?

2017-10-04 Thread leam hall
On Wed, Oct 4, 2017 at 7:15 AM, Ben Finney 
wrote:

> Leam Hall  writes:
>
> > Folks on IRC have suggested using virtualenv to test code under
> > different python versions. Sadly, I've not found a virtualenv tutorial
> > I understand. Anyone have a link to a good one?
>
> The Python Packaging Authority has a guide
> https://packaging.python.org/tutorials/installing-
> packages/#creating-virtual-environments>
> which seems good to me.
>
> The standard library documentation for the ‘venv’ library
> https://docs.python.org/3/library/venv.html> is essential.
>
> > The next step will be to figure out how to package a project; a good
> > tutorial URL would be appreciated on that, too.
>
> Follow the documentation maintained by the Python Packaging Authority
> https://packaging.python.org/>.
>
>
Ben, thanks! I'm off to print and study...

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


Re: OT again sorry [Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"]]

2017-10-08 Thread leam hall
On Sun, Oct 8, 2017 at 8:15 AM, Gregory Ewing 
wrote:

>
> The thing that *really* annoys me is Linux insisting on colourising
> the output to a tty, since it invariably seems to pick an undreadable
> colour scheme. And the case-insensitive sorting... there's a reason
> Makefile starts with a capital M, dammit!
>

Actually, it doesn't. The color output may come from
/etc/profile.d/colorls.sh configs. Either dump that or "unalias ls" in your
~/.bash_profile.

Colorized ls is something the distrobution people like and they put it in.
Others of us don't care for it. But it's not "Linux", is the profile. Easy
to customize.

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


Re: OT again sorry [Re: Interactive scripts (back on topic for once) [was Re: The "loop and a half"]]

2017-10-08 Thread Leam Hall

On 10/08/2017 12:43 PM, Marko Rauhamaa wrote:

leam hall :
"Linux" means so many things to people. 


Yes, but just because someone can spell it doesn't mean they can 
redefine it.  :)



Closer to home, systemd has taken a central role in the main Linux
distributions. I think it would be more accurate to call them "systemd
distros" than "Linux distros".


I have other words for them; mostly ones I try not to say.


It is not at all easy for the Linux user to figure out what
configuration options there are, and which ones are intended for
end-user configuration.


Agree! I had to look this up and I've been doing Linux for a few years.


Marko


I knew your e-mail address was familiar; saluton!

Leam
  -- Who hasn't practiced that language in years. Sadly...

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


PyYaml not using Yaml 1.2?

2017-08-04 Thread leam hall
Getting in to Ansible and back into Python. Ansible uses pyyaml which says
it parses yaml version 1.1. Is there a reason it doesn't do yaml version
1.2?

Thanks!

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


Re: PyYaml not using Yaml 1.2?

2017-08-04 Thread leam hall
On Fri, Aug 4, 2017 at 11:52 AM, Skip Montanaro 
wrote:

> > Getting in to Ansible and back into Python. Ansible uses pyyaml which
> says
> > it parses yaml version 1.1. Is there a reason it doesn't do yaml version
> > 1.2?
>
> Nobody's done the work? Note that on the PyPI page:
>
> https://pypi.python.org/pypi/PyYAML
>
> the last release was almost a year ago. That said, 1.2 has been out
> for awhile. There is an open ticket, nearly four years old:
>
> https://bitbucket.org/xi/pyyaml/issues/23/support-yaml-12
>
> Perhaps you can help move that forward.
>
> Skip
>

Hey Skip, thanks!

Tracked down the GitHub repo (https://github.com/yaml/pyyaml) and it seems
to be gearing back up. I'll see what I can do to help.

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


Re: SQLObject 3.4.0

2017-08-05 Thread leam hall
#I'm pleased to announce version 3.4.0, the first stable release of branch
#3.4 of SQLObject.
#
#
#What's new in SQLObject
#===
#
#* Python 2.6 is no longer supported. The minimal supported version is
#  Python 2.7.

Is there a particular reason to eliminate RHEL 6 (Python 2.6) support? That
would seem to limit your enterprise adoption.
-- 
https://mail.python.org/mailman/listinfo/python-list


doctest random output?

2017-08-28 Thread Leam Hall
Is this a good way to test if random numeric output? It seems to work 
under Python 2.6 and 3.6 but that doesn't make it 'good'.


###  Code
import random

def my_thing():
  """ Return a random number from 1-6
  >>> 0 < my_thing() <=6
  True
  >>> 6 < my_thing()
  False
  """

  return random.randint(1,6)


if __name__ == "__main__":
  import doctest
  doctest.testmod()


###  Results
python3 test_doctest.py -v
Trying:
0 < my_thing() <=6
Expecting:
True
ok
Trying:
6 < my_thing()
Expecting:
False
ok
1 items had no tests:
__main__
1 items passed all tests:
   2 tests in __main__.my_thing
2 tests in 2 items.
2 passed and 0 failed.
Test passed.

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


Re: doctest random output?

2017-08-28 Thread Leam Hall

On 08/28/2017 11:40 AM, Dennis Lee Bieber wrote:

... a bunch of good stuff ...

I'm (re-)learning python and just trying make sure my function works. 
Not at the statistical or cryptographic level.   :)


Thanks!

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