From rkc_chaitu at yahoo.co.in  Sat Sep  1 07:41:42 2018
From: rkc_chaitu at yahoo.co.in (krishna chaitanya)
Date: Sat, 1 Sep 2018 11:41:42 +0000 (UTC)
Subject: [Tutor] REG : Pexpect timeout issue
References: <1601965793.1957416.1535802102468.ref@mail.yahoo.com>
Message-ID: <1601965793.1957416.1535802102468@mail.yahoo.com>

Hi Team,
Below is my code, i am frequently hitting timeout issue to login to linux or router.
import pexpectfrom pexpect import *child = spawn('su xxxxx',timeout = 50)child.expect('Password:',timeout = 50)child.sendline('XXXXXXX')#child.sendline('ls -l')#chasis = child.before.decode('utf-8')child.expect('krishna at krishna-desktop:~/python_excercises$',timeout = 50)child.sendline('ls -l')chasis = child.before.decode('utf-8')print(chasis)
Error :
? ? raise TIMEOUT(msg)pexpect.exceptions.TIMEOUT: Timeout exceeded.<pexpect.pty_spawn.spawn object at 0x7f068506fa20>

Please guide me.
Krishna.


From steve at pearwood.info  Sat Sep  1 10:31:11 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Sun, 2 Sep 2018 00:31:11 +1000
Subject: [Tutor] REG : Pexpect timeout issue
In-Reply-To: <1601965793.1957416.1535802102468@mail.yahoo.com>
References: <1601965793.1957416.1535802102468.ref@mail.yahoo.com>
 <1601965793.1957416.1535802102468@mail.yahoo.com>
Message-ID: <20180901143111.GP27312@ando.pearwood.info>

On Sat, Sep 01, 2018 at 11:41:42AM +0000, krishna chaitanya via Tutor wrote:
> Hi Team,
> Below is my code, i am frequently hitting timeout issue to login to linux or router.

Timeout issues are a network problem. Perhaps your network is too busy, 
or the cable is faulty, or your router is being hammered by attackers 
and can't respond.

You would need to discuss this with an experienced network administrator 
to determine what is causing the timeouts.

> import pexpect
> from pexpect import *
> child = spawn('su xxxxx',timeout = 50)
> child.expect('Password:',timeout = 50)
> child.sendline('XXXXXXX') #child.sendline('ls -l')#
> chasis = child.before.decode('utf-8')
> child.expect('krishna at krishna-desktop:~/python_excercises$',timeout = 50)
> child.sendline('ls -l')
> chasis = child.before.decode('utf-8')
> print(chasis)
>
> Error :
> ? ? raise TIMEOUT(msg)pexpect.exceptions.TIMEOUT: Timeout exceeded.<pexpect.pty_spawn.spawn object at 0x7f068506fa20>
> 
> Please guide me.
> Krishna.
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From oconnord at allegheny.edu  Sat Sep  1 13:40:19 2018
From: oconnord at allegheny.edu (Dana O'Connor)
Date: Sat, 1 Sep 2018 13:40:19 -0400
Subject: [Tutor] "Python not recognized as a command"
Message-ID: <CAGMJoRGzYFAs6HEgQMmvWUDoX84iBQ8qDi0o65syOfkha1gMmw@mail.gmail.com>

Hi,
I've been trying to download and use Python 3.7 for the past few days and
every time I try to open it it tells me I don't have "pip" which should be
impossible because this version of Python is supposed to automatically come
with pip (?).  Additionally, whenever I open the command prompt on my
computer, the command "python" is not even recognized by the system even
though Python is downloaded onto the computer.  I cannot use Python at all
until I figure out this problem, so I guess my overall question is why
doesn't my computer acknowledge Python when it has been downloaded (and
redownloaded) several times on my computer?
Thanks and warmest regards,
Dana

-- 
Dana O'Connor
Allegheny College, Class of 2019
Chemistry Major, Mathematics and History Minor
Calculus Tutor, Department of Mathematics
Beta Chi Tutor, Department of Chemistry
Chemistry Teaching Assistant

From alan.gauld at yahoo.co.uk  Sat Sep  1 15:33:35 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sat, 1 Sep 2018 20:33:35 +0100
Subject: [Tutor] REG : Pexpect timeout issue
In-Reply-To: <1601965793.1957416.1535802102468@mail.yahoo.com>
References: <1601965793.1957416.1535802102468.ref@mail.yahoo.com>
 <1601965793.1957416.1535802102468@mail.yahoo.com>
Message-ID: <pmepec$4o6$1@blaine.gmane.org>

On 01/09/18 12:41, krishna chaitanya via Tutor wrote:

> Below is my code, i am frequently hitting timeout issue to login to linux or router.

Have you tried extending the timeout?


> child = spawn('su xxxxx',timeout = 50)

What is the timeout interval? If its in milliseconds
then 50 is much too short, try 5000.
If its in seconds then you have a problem...

How long does it take to connect manually using ssh?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From alan.gauld at yahoo.co.uk  Sat Sep  1 15:44:59 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sat, 1 Sep 2018 20:44:59 +0100
Subject: [Tutor] "Python not recognized as a command"
In-Reply-To: <CAGMJoRGzYFAs6HEgQMmvWUDoX84iBQ8qDi0o65syOfkha1gMmw@mail.gmail.com>
References: <CAGMJoRGzYFAs6HEgQMmvWUDoX84iBQ8qDi0o65syOfkha1gMmw@mail.gmail.com>
Message-ID: <pmeq3o$tiu$1@blaine.gmane.org>

On 01/09/18 18:40, Dana O'Connor wrote:

> I've been trying to download and use Python 3.7 for the past few days 

How exactly did you download it (from which site and in which format?)
And how did you then install it?

> every time I try to open it it tells me I don't have "pip" 

That seems unlikely, I've never seen an OS give a warning
about pip when trying to open Python.

Can you tell us:
1) The OS you use - Linux? MacOSX? Windows? Something else?
2) The exact command you type (and from where)
3) The exact error message you get not a summary.

> the command "python" is not even recognized by the system even

Again the exact command used and the exact error
message please.

> doesn't my computer acknowledge Python when it has been downloaded (and
> redownloaded) several times on my computer?

It mat be that although you downloaded it you didn't
install it? Or maybe the installer didn't set a PATH
value properly?

But we need much more specific information to
do anything other than guess.



The US education system is a perpetual mystery to me.
Can you explain, just for my curiosity:

> Allegheny College, Class of 2019

I thought "class of" was the year you graduated from
high school but clearly that can't be true here.
So what does "class of 2019" refer to?

> Beta Chi Tutor,

I've seen references to Beta Chi before but have
no idea what it is, or how you would tutor it?
Can you explain what it is? (I probably should
just google it!)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From marc.tompkins at gmail.com  Sat Sep  1 18:24:22 2018
From: marc.tompkins at gmail.com (Marc Tompkins)
Date: Sat, 1 Sep 2018 15:24:22 -0700
Subject: [Tutor] "Python not recognized as a command"
In-Reply-To: <CAGMJoRGzYFAs6HEgQMmvWUDoX84iBQ8qDi0o65syOfkha1gMmw@mail.gmail.com>
References: <CAGMJoRGzYFAs6HEgQMmvWUDoX84iBQ8qDi0o65syOfkha1gMmw@mail.gmail.com>
Message-ID: <CAKK8jXZBBLV_L1wc-74AiCs_1-ydLE76zi1D2VtEYi4Y3m6XKQ@mail.gmail.com>

On Sat, Sep 1, 2018 at 10:40 AM, Dana O'Connor <oconnord at allegheny.edu>
wrote:

> Hi,
> I've been trying to download and use Python 3.7 for the past few days and
> every time I try to open it it tells me I don't have "pip" which should be
> impossible because this version of Python is supposed to automatically come
> with pip (?).  Additionally, whenever I open the command prompt on my
> computer, the command "python" is not even recognized by the system even
> though Python is downloaded onto the computer.  I cannot use Python at all
> until I figure out this problem, so I guess my overall question is why
> doesn't my computer acknowledge Python when it has been downloaded (and
> redownloaded) several times on my computer?
>

A bit more on Alan's point:
I believe that your question is a bit more of an operating system question
than purely a Python question; I also suspect (though I could be wrong)
that your previous experience has been with iOS or Android, and that you're
relatively unfamiliar with older desktop operating systems.
In iOS and Android, programs are packaged in such a way (and the package
installer is configured in such a way) that "downloading" and "installing"
are practically the same thing.  Apple OSx is nearly as seamless, and the
various Linux distros have been trying to move in this direction as well.
Even Windows - with "Universal" apps in Windows 8 and 10 - has been moving
in this direction.

But traditional "desktop"-side Windows, and traditional Windows programs
such as Python, still leave many details to the the user, and so the
process involves a few steps:
-  You download the installer.  This is actually a combination package: a
compressed archive of the actual program you want, wrapped up with a
program that knows how to unpack the archive, distribute its contents to
the appropriate locations, and register its various bits with the operating
system.
-  Once you've downloaded the installer, you run it, and it does its
magic.  It may prompt you to make some choices about where to put things.
-  Now that you've installed the program (Python in this case), you can run
it.  BUT - when you type a command at the prompt, the operating system
needs to know where to find the program file to fulfill your request.
That's where the PATH comes in - it's a list of locations where the OS can
look for, e.g. "python.exe" when you type "python" at the prompt.
-  PATH is a system variable, and it should be set by the installer when
you run it.  But the installer is a program, and sometimes programs fail.
So it's possible that you'd need to fix that; it's easy to do, but we need
more info first.

Hope that helps -

From cs at cskk.id.au  Sat Sep  1 19:57:37 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Sun, 2 Sep 2018 09:57:37 +1000
Subject: [Tutor] REG : Pexpect timeout issue
In-Reply-To: <pmepec$4o6$1@blaine.gmane.org>
References: <pmepec$4o6$1@blaine.gmane.org>
Message-ID: <20180901235737.GA79347@cskk.homeip.net>

On 01Sep2018 20:33, Alan Gauld <alan.gauld at yahoo.co.uk> wrote:
>On 01/09/18 12:41, krishna chaitanya via Tutor wrote:
>> child = spawn('su xxxxx',timeout = 50)
>
>What is the timeout interval? If its in milliseconds
>then 50 is much too short, try 5000.
>If its in seconds then you have a problem...
>
>How long does it take to connect manually using ssh?

He's not using ssh - it is all local.

Cheers,
Cameron Simpson <cs at cskk.id.au>

From cs at cskk.id.au  Sat Sep  1 20:01:02 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Sun, 2 Sep 2018 10:01:02 +1000
Subject: [Tutor] REG : Pexpect timeout issue
In-Reply-To: <20180901143111.GP27312@ando.pearwood.info>
References: <20180901143111.GP27312@ando.pearwood.info>
Message-ID: <20180902000102.GA81155@cskk.homeip.net>

On 02Sep2018 00:31, Steven D'Aprano <steve at pearwood.info> wrote:
>On Sat, Sep 01, 2018 at 11:41:42AM +0000, krishna chaitanya via Tutor wrote:
>> Below is my code, i am frequently hitting timeout issue to login to linux or 
>> router.
>
>Timeout issues are a network problem. Perhaps your network is too busy,
>or the cable is faulty, or your router is being hammered by attackers
>and can't respond.

No, timeout issues are "the target input didn't arrive in this timeframe".

All his commands are _local_.

Krishna: if you're blocking waiting for a pattern (eg "Password:") and it times 
out, even for big timeouts, then maybe the pattern is wrong. A command like 
"su" will prompt for a password and then wait indefinitely. If your prompt 
pattern is incorrect, you will wait indefinitely waiting for the pattern to 
show up, because it never will.

Run an interactive "su" and see if it matches your pattern.

And so on.

Cheers,
Cameron Simpson <cs at cskk.id.au>

From mats at wichmann.us  Sat Sep  1 21:11:02 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Sat, 1 Sep 2018 19:11:02 -0600
Subject: [Tutor] "Python not recognized as a command"
In-Reply-To: <CAKK8jXZBBLV_L1wc-74AiCs_1-ydLE76zi1D2VtEYi4Y3m6XKQ@mail.gmail.com>
References: <CAGMJoRGzYFAs6HEgQMmvWUDoX84iBQ8qDi0o65syOfkha1gMmw@mail.gmail.com>
 <CAKK8jXZBBLV_L1wc-74AiCs_1-ydLE76zi1D2VtEYi4Y3m6XKQ@mail.gmail.com>
Message-ID: <ccfd09e0-73c3-5192-6056-336b35de300e@wichmann.us>

On 09/01/2018 04:24 PM, Marc Tompkins wrote:
> On Sat, Sep 1, 2018 at 10:40 AM, Dana O'Connor <oconnord at allegheny.edu>
> wrote:
> 
>> Hi,
>> I've been trying to download and use Python 3.7 for the past few days and
>> every time I try to open it it tells me I don't have "pip" which should be
>> impossible because this version of Python is supposed to automatically come
>> with pip (?).  Additionally, whenever I open the command prompt on my
>> computer, the command "python" is not even recognized by the system even
>> though Python is downloaded onto the computer.  I cannot use Python at all
>> until I figure out this problem, so I guess my overall question is why
>> doesn't my computer acknowledge Python when it has been downloaded (and
>> redownloaded) several times on my computer?
>>

So, yeah... if this is Windows (and it nearly always is when someone has
this kind of problem):

windows is a graphical system, and it expects pretty much everything
"normal users" do to be through the gui.  Python follows along and
probably is there and working.  Can you find it by starting to type
python in the search box? the "gui for Python" is called IDLE, and you
can probably find this by starting to type its name into the search box.
 if these resolve to something, python is installed and working.

now, to go the extra step and make it available in the command shell, or
in powershell, or other place where you will type instead of click a
mouse, it needs to be added to the path, as the others have said.  there
was a checkbox for this in the python installer (perhaps in the advanced
section). you may or may not need that.

the installer will have asked you about installing Python Launcher. If
you agreed to this, the command "py" should work from the command shell,
even if "python" did not.  Try it.  the launcher goes in an
always-findable place to try to minimize the kinds of problems you are
finding. but almost no older docs or tutorials talk about it, because
it's a fairly new concept.

if you can bring up the python interpreter by typing "py", you can now
run pip to install packages. quit out of python first (in windows, ^Z
followed by Enter should do it).

ignore the instructions that say to type "pip install something"
directly into the command shell.  instead prefix that with "py -m".

So to install package foo, where your instructions said to type "pip
install foo", instead type "py -m pip install foo".

hope this gets you on the air.


From steve at pearwood.info  Sun Sep  2 00:29:04 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Sun, 2 Sep 2018 14:29:04 +1000
Subject: [Tutor] REG : Pexpect timeout issue
In-Reply-To: <20180902000102.GA81155@cskk.homeip.net>
References: <20180901143111.GP27312@ando.pearwood.info>
 <20180902000102.GA81155@cskk.homeip.net>
Message-ID: <20180902042904.GR27312@ando.pearwood.info>

On Sun, Sep 02, 2018 at 10:01:02AM +1000, Cameron Simpson wrote:
> On 02Sep2018 00:31, Steven D'Aprano <steve at pearwood.info> wrote:
> >On Sat, Sep 01, 2018 at 11:41:42AM +0000, krishna chaitanya via Tutor 
> >wrote:
> >>Below is my code, i am frequently hitting timeout issue to login to linux 
> >>or router.
> >
> >Timeout issues are a network problem. Perhaps your network is too busy,
> >or the cable is faulty, or your router is being hammered by attackers
> >and can't respond.
> 
> No, timeout issues are "the target input didn't arrive in this timeframe".
> 
> All his commands are _local_.

Krishna wrote:

"i am frequently hitting timeout issue to login to linux or router."

Given that Krishna says he's trying to login to a router, what tells you 
that it is local?



-- 
Steve

From cs at cskk.id.au  Sun Sep  2 01:00:02 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Sun, 2 Sep 2018 15:00:02 +1000
Subject: [Tutor] REG : Pexpect timeout issue
In-Reply-To: <20180902042904.GR27312@ando.pearwood.info>
References: <20180902042904.GR27312@ando.pearwood.info>
Message-ID: <20180902050002.GA70199@cskk.homeip.net>

On 02Sep2018 14:29, Steven D'Aprano <steve at pearwood.info> wrote:
>On Sun, Sep 02, 2018 at 10:01:02AM +1000, Cameron Simpson wrote:
>> On 02Sep2018 00:31, Steven D'Aprano <steve at pearwood.info> wrote:
>> >On Sat, Sep 01, 2018 at 11:41:42AM +0000, krishna chaitanya via Tutor
>> >wrote:
>> >>Below is my code, i am frequently hitting timeout issue to login to linux
>> >>or router.
>> >
>> >Timeout issues are a network problem. Perhaps your network is too busy,
>> >or the cable is faulty, or your router is being hammered by attackers
>> >and can't respond.
>>
>> No, timeout issues are "the target input didn't arrive in this timeframe".
>>
>> All his commands are _local_.
>
>Krishna wrote:
>
>"i am frequently hitting timeout issue to login to linux or router."
>
>Given that Krishna says he's trying to login to a router, what tells you
>that it is local?

His script, which goes:

  import pexpect
  from pexpect import *
  child = spawn('su xxxxx',timeout = 50)
  child.expect('Password:',timeout = 50)
  child.sendline('XXXXXXX') #child.sendline('ls -l')#
  chasis = child.before.decode('utf-8')
  child.expect('krishna at krishna-desktop:~/python_excercises$',timeout = 50)
  child.sendline('ls -l')
  chasis = child.before.decode('utf-8')
  print(chasis)
 
  Error :
      raise TIMEOUT(msg)pexpect.exceptions.TIMEOUT: Timeout 
      exceeded.<pexpect.pty_spawn.spawn object at 0x7f068506fa20>

All his commands are local, with no remote login. He's probably just slightly 
misusing the term "timeout issue to login to linux" when tallking about "su".

The expect stuff matches command outputs against an expression. Any command 
which issues a prompt and pauses indefinitely, and whose prompt isn't matched 
by the expression, will inherently stall the output and cause a timeout if the 
expect() call has a timeout setting.

It could easily be that the su is working and that his pattern for his shell 
prompt is incorrect ("python_excercises" looks misspelled to me). Same 
situation and same symptom.

Cheers,
Cameron Simpson <cs at cskk.id.au>

From alan.gauld at yahoo.co.uk  Sun Sep  2 09:50:23 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sun, 2 Sep 2018 14:50:23 +0100
Subject: [Tutor] I found the octal and hexadecimal direct conversion
 method
In-Reply-To: <CAJ=N2h1B8PT2=p53sj3_WMWOVKkryfAeuzbvQsHsaSE+uDzBPg@mail.gmail.com>
References: <CAJ=N2h1B8PT2=p53sj3_WMWOVKkryfAeuzbvQsHsaSE+uDzBPg@mail.gmail.com>
Message-ID: <pmgpms$8i3$1@blaine.gmane.org>

On 02/09/18 14:27, kanzan wrote:
> ? I found direct method of octal and hexadecimal conversions ? (without
> using binary or decimal)

I'm not sure what you mean but numbertheory has been
around for along time and has long had methods to
convert from one base to another (not just computer
bases but base 3, base 24 and any others too) without
going via any intermediate bases.

> no-one's found this mathematical theory. 

You may be right and have found a new way to do
it but I doubt it.

> about this (e.g. how could i present this theory). 

You should try the various mathematical fora.
It's not a Python programming issue.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From dave at the-hills.org.uk  Sun Sep  2 11:36:36 2018
From: dave at the-hills.org.uk (Dave Hill)
Date: Sun, 2 Sep 2018 16:36:36 +0100
Subject: [Tutor] Problem compiling code from GitHub
In-Reply-To: <CAHVvXxT9zryU0nP0OZdWWZC6chdckmDGC59rEiXOx0mFvFB6iw@mail.gmail.com>
References: <64432655-d3e4-2ad8-262d-5df257941b6a@the-hills.org.uk>
 <CAHVvXxT9zryU0nP0OZdWWZC6chdckmDGC59rEiXOx0mFvFB6iw@mail.gmail.com>
Message-ID: <47bccda9-6d5f-74a8-d42b-b09b9023c719@the-hills.org.uk>

I now have 'odswriter' working, thank you.

I, eventually, uninstalled all versions of python and cleaned out as 
many references to python and odswriter as I could find. I then 
installed 3.7, and odswriter using

     $ cd odswriter
     $ python setup.py install

I guess that the first attempt at the latter steps was thwarted by some path problem re. Windows?

On 29/08/2018 14:04, Oscar Benjamin wrote:
> On Mon, 27 Aug 2018 at 13:18, Dave Hill <dave at the-hills.org.uk> wrote:
>> I have found 'odswriter' on GitHub
>> https://github.com/mmulqueen/odswriter which appears to provide what I
>> want. However, I have come to a halt, due to the limitation of my knowledge.
>>
>> I admit that I am confounded as to where/how to access this code.
> There are two ways. The code is there in github because that's where
> the author(s) are saving their work on it and where people could
> contribute to it.
>
> Normally as a "user" of the odswriter code you wouldn't access it from
> there. If you did want to access it from github in order to use the
> code you would normally use the git program to download it:
>
>      $ git clone https://github.com/mmulqueen/odswriter
>
> Alternatively you can download the .zip file from github using your
> browser and extract it. Either way you then need to *install* the
> package to use it:
>
>      $ cd odswriter
>      $ python setup.py install
>
> However as I said before someone who simply wants to use the odswriter
> code (and not contribute to writing it) would not normally access the
> code from github since Python has a better place for this which is
> PyPI. You can see the PyPI page for odswriter here:
> https://pypi.org/project/odswriter/
>
> Again though you wouldn't normally download the code from PyPI using
> the web browser. Python comes with a program called pip which can
> download and install it for you. So the command is:
>
>      $ pip install odswriter
>
> I don't know why Steve has difficulty with that but this is the
> easiest, fastest, officially-recommended etc. way to install Python
> packages.
>
>> I am using Python 3.6.4, in IDLE on a PC running windows.
>>
>> I am using the following code as a starting point , Test_ODS#1.py
>>
>>      import datetime
>>      import decimal
>>      ##import odswriter as ods
>>      try:
>>           from OdsWriter import odswriter as ods
>>      except RuntimeError:
>>           print("Error importing OdsWriter!")
> I have just installed odswriter in Python 3.6, on Linux, using pip and
> I get this:
>
>      >>> from OdsWriter import odswriter as ods
>      Traceback (most recent call last):
>        File "<stdin>", line 1, in <module>
>      ModuleNotFoundError: No module named 'OdsWriter'
>
> However if I instead write
>
>      >>> from odswriter import ODSWriter
>
> then it works fine. The package name odswriter should be all
> lower-case. This may not show an error on Windows because you may be
> using a case-insensitive filesystem but you should fix it anyway. The
> class-name ODSWriter needs to exactly match each upper and lower-case
> letter because Python is much fussier than Windows file systems.
>
> I think that misspelling the capitals in a package name can lead to
> import problems although I don't know if that explains the problem
> you're having. Most likely that is because you haven't "installed" the
> code correctly.
>
> --
> Oscar
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

From pandey.amrit at outlook.com  Mon Sep  3 09:29:01 2018
From: pandey.amrit at outlook.com (Amrit Pandey)
Date: Mon, 3 Sep 2018 13:29:01 +0000
Subject: [Tutor] How to read `https` url with urllib.request.urlopen?
Message-ID: <SG2PR01MB2442DEADD46B403E4A8FCCB0960C0@SG2PR01MB2442.apcprd01.prod.exchangelabs.com>

I am learning web scraping with python.

With urllib.request.urlopen() I am able to fetch http urls, but https give some certificate error. How can we bypass the certificate check or is there any other configuration that is used for https urls?

From mats at wichmann.us  Mon Sep  3 16:11:00 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Mon, 3 Sep 2018 14:11:00 -0600
Subject: [Tutor] How to read `https` url with urllib.request.urlopen?
In-Reply-To: <SG2PR01MB2442DEADD46B403E4A8FCCB0960C0@SG2PR01MB2442.apcprd01.prod.exchangelabs.com>
References: <SG2PR01MB2442DEADD46B403E4A8FCCB0960C0@SG2PR01MB2442.apcprd01.prod.exchangelabs.com>
Message-ID: <03fba3d5-8ce7-55b2-6204-44f550430cec@wichmann.us>

On 09/03/2018 07:29 AM, Amrit Pandey wrote:
> I am learning web scraping with python.
> 
> With urllib.request.urlopen() I am able to fetch http urls, but https give some certificate error. How can we bypass the certificate check or is there any other configuration that is used for https urls?

if you really want to ignore (and usually problems mean a problem on
your end, not on the other end, so you should probably not do that - the
exception being if you're scraping your own test server, which might not
have official certs), you create an ssl context and set the appropriate
settings, passing that to urllib.  /Conceptually/ something like this,
but there may be quite a few more details needed:

ctx = ssl.create_default_context()
ctx.verify_mode = ssl.CERT_NONE
with urllib.request.urlopen(url, context=ctx) as f:
    data = f.read()


But in general your life will be much more pleasant if you use the
requests module instead of urllib.


there are also extensive and well debugged web scraping packages in
Python, if you're actually looking to deploy something, as opposed to
learning something (and there's definitely nothing wrong with a learning
exercise!!!) you should look at scrapy and others.


From wachobc at gmail.com  Tue Sep  4 11:10:36 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Tue, 4 Sep 2018 11:10:36 -0400
Subject: [Tutor] Accessing variables from other modules
Message-ID: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>

Hello,

Hoping that this comes through as text only.  Not sure how to force
that with Gmail.

Very new to Python and trying to follow the instructions I've read on
the tutorial and other places.  But, I'm not meeting with any success.
I have a feeling this is something simple but a search of the archives
didn't provide any useful results.  Perhaps I just don't know the
'lingo' yet.  So I apologize for the likelihood that this is a
duplicate.

I have a background in C and other asm languages so that should give
you some idea of my current understanding related to programming.
Forgive any incorrect use of terms..

I started writing code in Python for a little project I'm working on.
I used examples from the tutorial provided by the DIY board (Adafruit
FT232H Breakout).  Those instructions were the basis for my working
code.

As time went on, I had a _whole_ lot of code and it was getting
unmanageable.  So I looked into breaking it into separate modules
(like I would do in C).  I then used the import statement to 'include'
them into the main.py file.

I ran into a problem in that the code which was moved to the module
could no longer 'see' the ft232h variable (object?).  After many
attempts, I figured out that the best solution seemed to be to put the
ft232h setup code into yet another file.  I then imported that file
into both my main.py and foo.py files.  And, that seemed to work.. on
Friday.

This morning, I came back to continue working on the code, and now the
ft232h variable can no longer be 'seen' by my modules...

When I was running the code on Friday it was being run from a command
line each time.  So, I'm assuming that the dictionary disappears and
that there is a new 'fresh' start each time I execute.  Is this
correct?

I'm running Python 2.7 and it is running on a native Ubuntu machine at
16.04 LTS.

I'll refrain from posting a bunch of code, but here is the 5000 foot view:

main.py - calls various functions from other *.py files (foo.py, etc).
It also creates a console-based menu selection which determines which
of the functions to call.

foo.py (and others) - contain the actual functions for the different
work that I want to get done.

spi.py - contains the setup and initialization code for the Adafruit
board and configures it to function as a SPI peripheral via USB.

execution looks like this:

$ sudo python main.py

So, the important questions are:

- Was I mislead by the fact that there was a power cycle on the
machine and it has now forgotten something that was staying resident
when I tested the code on Friday?  Or, does each 'run' of the script
start fresh?

- What approach do I need to use to be able to initialize the
interface in spi.py and have it be something that is accessible to all
the other modules in my project?

Thank you in advance for your time.

From steve at pearwood.info  Tue Sep  4 13:19:56 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Wed, 5 Sep 2018 03:19:56 +1000
Subject: [Tutor] Accessing variables from other modules
In-Reply-To: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
References: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
Message-ID: <20180904171956.GX27312@ando.pearwood.info>

Hi Chip, and welcome!

On Tue, Sep 04, 2018 at 11:10:36AM -0400, Chip Wachob wrote:

> I'll refrain from posting a bunch of code, but here is the 5000 foot view:

Not posting a mountain of code is a great idea, but from 5000 ft away 
we can't see what is going on.

Try posting *a little bit of code*. This is written for Java programmers 
but the principle is the same for Python:

http://sscce.org/

If I had to make a *wild guess* as to what is going on, it would be that 
you have a couple of modules like this:

# Module spam.py
x = 1  # global variable
def foo():
    print(x)


# Module eggs.py
import spam
from spam import x
foo()  # prints 1, as you expect
x = 999
foo()  # still prints 1, instead of 999


Is that what is going on? On something different?


A few more comments:

> execution looks like this:
> 
> $ sudo python main.py

Do you really need this to be run with root permissions?

> So, the important questions are:
> 
> - Was I mislead by the fact that there was a power cycle on the
> machine and it has now forgotten something that was staying resident
> when I tested the code on Friday?  Or, does each 'run' of the script
> start fresh?

Um, yes no maybe?

Was there a power cycle? How were you running the scripts?


> - What approach do I need to use to be able to initialize the
> interface in spi.py and have it be something that is accessible to all
> the other modules in my project?




> 
> Thank you in advance for your time.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 

From alan.gauld at yahoo.co.uk  Tue Sep  4 19:41:46 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 5 Sep 2018 00:41:46 +0100
Subject: [Tutor] Accessing variables from other modules
In-Reply-To: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
References: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
Message-ID: <pmn53o$eqp$1@blaine.gmane.org>

On 04/09/18 16:10, Chip Wachob wrote:

> (like I would do in C).  I then used the import statement to 'include'
> them into the main.py file.

OK a basically good idea but how did you use the import statement?
There are many forms:

import foo
from foo import name1, name2,...
from foo import *
import foo as f
from foo import name1 as n1


Now to access name1 (which could be a function,
class or global variable within foo) you could
do any of (depending on your import):

x = foo.name1
x = name1
x = name1
x = f.name1
x = n1

Does your import statememt and access method
match the above?

The other thing to remember is that local variables
(defined inside functions) are not visible outside
the function.

> I ran into a problem in that the code which was moved to the module
> could no longer 'see' the ft232h variable (object?).  After many
> attempts, I figured out that the best solution seemed to be to put the
> ft232h setup code into yet another file.  I then imported that file
> into both my main.py and foo.py files.  And, that seemed to work.. on
> Friday.

That may be a good idea, but it shouldn't really
have been necessary. And it should work any day
of the week :-)

> This morning, I came back to continue working on the code, and now the
> ft232h variable can no longer be 'seen' by my modules...

We need to see some actual code to figure that one out.

> When I was running the code on Friday it was being run from a command
> line each time.  So, I'm assuming that the dictionary disappears and
> that there is a new 'fresh' start each time I execute.  Is this
> correct?

Everything disappears at the end of the interpreter session,
so yes it starts afresh every time. (Unlike if you run your
modules from inside the interpreter in which case values
stick around.)

> main.py - calls various functions from other *.py files (foo.py, etc).
> It also creates a console-based menu selection which determines which
> of the functions to call.
> 
> foo.py (and others) - contain the actual functions for the different
> work that I want to get done.
> 
> spi.py - contains the setup and initialization code for the Adafruit
> board and configures it to function as a SPI peripheral via USB.

It is a good idea to keep the hardware specifics in one
place but for the purpose of this discussion it shouldn't
make any difference it's just another module.

> - Was I mislead by the fact that there was a power cycle on the
> machine and it has now forgotten something that was staying resident
> when I tested the code on Friday?  Or, does each 'run' of the script
> start fresh?

Each run should start afresh.
(The only caveat is that if there is some process still
running on your hardware(I don't know anything about the
board in question) it may retain memory and pass it back
to the init code in spi.py on startup. Does the board get
power cycled between runs?)

> - What approach do I need to use to be able to initialize the
> interface in spi.py and have it be something that is accessible to all
> the other modules in my project?

It depends a lot on your actual code. Without it
we are just guessing.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From wachobc at gmail.com  Tue Sep  4 23:12:58 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Tue, 4 Sep 2018 23:12:58 -0400
Subject: [Tutor] Fwd:  Accessing variables from other modules
In-Reply-To: <CADUn+-LgXEM1Mj1y4tYuYDuUmPRmaqouCU64atc1Jui-m+o=yA@mail.gmail.com>
References: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
 <20180904171956.GX27312@ando.pearwood.info>
 <CADUn+-LgXEM1Mj1y4tYuYDuUmPRmaqouCU64atc1Jui-m+o=yA@mail.gmail.com>
Message-ID: <CADUn+-+La+-hSwtK_Cvr7OCnd45_3-2q47nWEj=bs8BXtgzY4w@mail.gmail.com>

My apologies.  I hit reply and not reply to all.

Alan,

I think I answered many of your questions in this message to Steven.




---------- Forwarded message ----------
From: Chip Wachob <wachobc at gmail.com>
Date: Tue, Sep 4, 2018 at 1:48 PM
Subject: Re: [Tutor] Accessing variables from other modules
To: Steven D'Aprano <steve at pearwood.info>


Steven,

Thank you.

Responding to your comments in order:

# module AdafruitInit.py
# from the Adafruit tutorials..
import Adafruit_GPIO.FT232H as FT232H
import Adafruit_GPIO as GPIO

FT232H.use_FT232H()

ft232h = FT232H.FT232H()

# config settings for the SPI 'machine'
spi = FT232.SPI(ft232h, 4, 20000, 2, FT232H.MSBFIRST)



# module RSI.py
def write(byte):
   spi.write(byte)

# toggle the latch signal
   ft232h.output(5, GPIO.LOW)
   ft232h.output(5, GPIO.HIGH)



# module main.py
import RSI
import AdafruitInit.py

ft232.setup(5, GPIO.OUT)

write(0xAA)


"write()" tells me that

"global name 'ft232h' is not defined"


Regarding permissions.  I'm not sure about the need for sudo, but that
was used in the example.  The script will fail to run without it.  I
can't say for certain that I understand why sudo is required.  It may
have something to do with disabling the "built in" FTDI driver and
enabling the Adafruit version.  I had hoped to just get things
'working' before worrying about trying to get rid of the sudo
requirement.

I had been working most of the day on Friday and the scripts were
running fine.  I was running the scripts from the command line as
noted above (and related to your question re: sudo).  I powered off
the machine Friday night, and started it back up this morning.

Does some of the FTDI (AdafruitInit.py) remain resident even though
I've exited out of the script.  My menu has an entry that will permit
breaking the while() loop and ending the script.



...



On Tue, Sep 4, 2018 at 1:19 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> Hi Chip, and welcome!
>
> On Tue, Sep 04, 2018 at 11:10:36AM -0400, Chip Wachob wrote:
>
>> I'll refrain from posting a bunch of code, but here is the 5000 foot view:
>
> Not posting a mountain of code is a great idea, but from 5000 ft away
> we can't see what is going on.
>
> Try posting *a little bit of code*. This is written for Java programmers
> but the principle is the same for Python:
>
> http://sscce.org/
>
> If I had to make a *wild guess* as to what is going on, it would be that
> you have a couple of modules like this:
>
> # Module spam.py
> x = 1  # global variable
> def foo():
>     print(x)
>
>
> # Module eggs.py
> import spam
> from spam import x
> foo()  # prints 1, as you expect
> x = 999
> foo()  # still prints 1, instead of 999
>
>
> Is that what is going on? On something different?
>
>
> A few more comments:
>
>> execution looks like this:
>>
>> $ sudo python main.py
>
> Do you really need this to be run with root permissions?
>
>> So, the important questions are:
>>
>> - Was I mislead by the fact that there was a power cycle on the
>> machine and it has now forgotten something that was staying resident
>> when I tested the code on Friday?  Or, does each 'run' of the script
>> start fresh?
>
> Um, yes no maybe?
>
> Was there a power cycle? How were you running the scripts?
>
>
>> - What approach do I need to use to be able to initialize the
>> interface in spi.py and have it be something that is accessible to all
>> the other modules in my project?
>
>
>
>
>>
>> Thank you in advance for your time.
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From wachobc at gmail.com  Tue Sep  4 23:39:09 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Tue, 4 Sep 2018 23:39:09 -0400
Subject: [Tutor] Accessing variables from other modules
In-Reply-To: <pmn53o$eqp$1@blaine.gmane.org>
References: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
 <pmn53o$eqp$1@blaine.gmane.org>
Message-ID: <CADUn+-Lg5Rae0qBvsRfG0LJ7UYZzfPs6znwC1C+45jMKv9bSqw@mail.gmail.com>

Alan,

Thanks for your comments.

I just forwarded a copy of a message to the list that I inadvertently
sent as a reply only.

So in that message there's information about the code.

Thank you for confirming that once the interpreter is finished running
my script that all the data is gone.

The board was cycled with the PC since it's powered off the USB port.

I believe that when the script closes, the Adafruit driver is removed
and the Ubuntu driver is reinstated (at least that's what the
documentation says).  So, my presumption would be that there would be
no TSR action going on.  The part on the board is 'dumb' and requires
configuration to run in whatever mode is desired.

I realize that the day of the week doesn't have anything to do with
it, but it sure was feeling like it when I wrote.  The only idea I
could come up with was that maybe something was still running in the
background and was 'helping' my code run properly, and today, that
code was not running.  Friday was a day filled with a _lot_ of trial
and error as I attempted to split this code into manageable chunks..
so anything could have happened.  But, I never ran anything in the
interpreter itself.  The script was always run from the command line
as noted in the forwarded message.







On Tue, Sep 4, 2018 at 7:41 PM, Alan Gauld via Tutor <tutor at python.org> wrote:
> On 04/09/18 16:10, Chip Wachob wrote:
>
>> (like I would do in C).  I then used the import statement to 'include'
>> them into the main.py file.
>
> OK a basically good idea but how did you use the import statement?
> There are many forms:
>
> import foo
> from foo import name1, name2,...
> from foo import *
> import foo as f
> from foo import name1 as n1
>
>
> Now to access name1 (which could be a function,
> class or global variable within foo) you could
> do any of (depending on your import):
>
> x = foo.name1
> x = name1
> x = name1
> x = f.name1
> x = n1
>
> Does your import statememt and access method
> match the above?
>
> The other thing to remember is that local variables
> (defined inside functions) are not visible outside
> the function.
>
>> I ran into a problem in that the code which was moved to the module
>> could no longer 'see' the ft232h variable (object?).  After many
>> attempts, I figured out that the best solution seemed to be to put the
>> ft232h setup code into yet another file.  I then imported that file
>> into both my main.py and foo.py files.  And, that seemed to work.. on
>> Friday.
>
> That may be a good idea, but it shouldn't really
> have been necessary. And it should work any day
> of the week :-)
>
>> This morning, I came back to continue working on the code, and now the
>> ft232h variable can no longer be 'seen' by my modules...
>
> We need to see some actual code to figure that one out.
>
>> When I was running the code on Friday it was being run from a command
>> line each time.  So, I'm assuming that the dictionary disappears and
>> that there is a new 'fresh' start each time I execute.  Is this
>> correct?
>
> Everything disappears at the end of the interpreter session,
> so yes it starts afresh every time. (Unlike if you run your
> modules from inside the interpreter in which case values
> stick around.)
>
>> main.py - calls various functions from other *.py files (foo.py, etc).
>> It also creates a console-based menu selection which determines which
>> of the functions to call.
>>
>> foo.py (and others) - contain the actual functions for the different
>> work that I want to get done.
>>
>> spi.py - contains the setup and initialization code for the Adafruit
>> board and configures it to function as a SPI peripheral via USB.
>
> It is a good idea to keep the hardware specifics in one
> place but for the purpose of this discussion it shouldn't
> make any difference it's just another module.
>
>> - Was I mislead by the fact that there was a power cycle on the
>> machine and it has now forgotten something that was staying resident
>> when I tested the code on Friday?  Or, does each 'run' of the script
>> start fresh?
>
> Each run should start afresh.
> (The only caveat is that if there is some process still
> running on your hardware(I don't know anything about the
> board in question) it may retain memory and pass it back
> to the init code in spi.py on startup. Does the board get
> power cycled between runs?)
>
>> - What approach do I need to use to be able to initialize the
>> interface in spi.py and have it be something that is accessible to all
>> the other modules in my project?
>
> It depends a lot on your actual code. Without it
> we are just guessing.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From alan.gauld at yahoo.co.uk  Wed Sep  5 04:53:30 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 5 Sep 2018 09:53:30 +0100
Subject: [Tutor] Fwd: Accessing variables from other modules
In-Reply-To: <CADUn+-+La+-hSwtK_Cvr7OCnd45_3-2q47nWEj=bs8BXtgzY4w@mail.gmail.com>
References: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
 <20180904171956.GX27312@ando.pearwood.info>
 <CADUn+-LgXEM1Mj1y4tYuYDuUmPRmaqouCU64atc1Jui-m+o=yA@mail.gmail.com>
 <CADUn+-+La+-hSwtK_Cvr7OCnd45_3-2q47nWEj=bs8BXtgzY4w@mail.gmail.com>
Message-ID: <pmo5e7$5dd$1@blaine.gmane.org>

On 05/09/18 04:12, Chip Wachob wrote:

> # module RSI.py
> def write(byte):
>    spi.write(byte)

You don't have any import statements here.
You need to import spi to use it.

> # toggle the latch signal
>    ft232h.output(5, GPIO.LOW)
>    ft232h.output(5, GPIO.HIGH)

And the same for ft232h

> 
> # module main.py
> import RSI
> import AdafruitInit.py

Note you do NOT use the .py extension when
importing, just the base name.

> ft232.setup(5, GPIO.OUT)

But again you have not imported ft232
Also I note that you use ft232 here but ft232h elsewhere.
Is that correct?

You must import any external names that
you intend to use.

> write(0xAA)

And here you need to prefix with RSI:

import RSI

....

RSI.write(....)

A Python import is very different to a C include.
In C you actually include the source text in your
file so everything inside the file becomes visible.
In a Python import you add names to a dictionary.
In this case the only name added is RSI. The code
inside the RSI module is effectively invisible to
your main.py, only the name of the module is seen.
So you must prefix the RSI contents before you use it.


> "write()" tells me that
> 
> "global name 'ft232h' is not defined"

Please always post full error texts, never summarize.

> Regarding permissions.  I'm not sure about the need for sudo, but that
> was used in the example.  

I suspect it's needed because you are accessing
privileged IO ports. It would not normally be
needed to run a Python script.

> I had been working most of the day on Friday and the scripts were
> running fine.  

That is the real mystery since the above code
should not have worked.

> Does some of the FTDI (AdafruitInit.py) remain resident

No, it will be deleted.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From wachobc at gmail.com  Wed Sep  5 09:05:10 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Wed, 5 Sep 2018 09:05:10 -0400
Subject: [Tutor] Fwd: Accessing variables from other modules
In-Reply-To: <pmo5e7$5dd$1@blaine.gmane.org>
References: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
 <20180904171956.GX27312@ando.pearwood.info>
 <CADUn+-LgXEM1Mj1y4tYuYDuUmPRmaqouCU64atc1Jui-m+o=yA@mail.gmail.com>
 <CADUn+-+La+-hSwtK_Cvr7OCnd45_3-2q47nWEj=bs8BXtgzY4w@mail.gmail.com>
 <pmo5e7$5dd$1@blaine.gmane.org>
Message-ID: <CADUn+-K_KF+ric-GHgAo2n_bqCcw-w66P9tzmvOyNZJNAMd3qA@mail.gmail.com>

Alan,

Once again, thank you for the feedback and comments.

Revised code snips: Sorry they were not complete.  Several typos while
trying to create the SSCCE version.

# module AdafruitInit.py
# from the Adafruit tutorials..
import Adafruit_GPIO.FT232H as FT232H
import Adafruit_GPIO as GPIO

FT232H.use_FT232H()

ft232h = FT232H.FT232H()

# config settings for the SPI 'machine'
spi = FT232.SPI(ft232h, 4, 20000, 2, FT232H.MSBFIRST)

---------------module separator ------------------------

# module RSI.py
import AdafruitInit

def write(byte):
   spi.write(byte)

# toggle the latch signal
   ft232h.output(5, GPIO.LOW)
   ft232h.output(5, GPIO.HIGH)

---------------module separator ------------------------

# module main.py
import RSI
import AdafruitInit

ft232h.setup(5, GPIO.OUT)

write(0xAA)




The actual error message for the ft232h... line is:

NameError: global name 'ft232h' is not defined


So, my write line should have read?

RSI.write(0xAA)

Does this mean that I need to call the ft232h like this?

AdafruitInit.ft232h.setup(5, GPIO.OUT)

And, this is why it is not visible?

I feel like I _thought_ I understood the import statements, but I
guess I didn't and that's what is getting me into trouble.

Earlier in the thread you mentioned that there are several ways to
import.  Obviously there's small differences between the methods.  If
you know of a good resource I can use to get a better understanding /
contrast of the different import types I'll read over it and make sure
I'm using the right one for my situation.

And, at this point, I'm pretty clear on the fact that the script that
runs leaves no trace behind when I exit the call to the interpreter
from the command line.

I appreciate your patience with my questions and foibles.




On Wed, Sep 5, 2018 at 4:53 AM, Alan Gauld via Tutor <tutor at python.org> wrote:
> On 05/09/18 04:12, Chip Wachob wrote:
>
>> # module RSI.py
>> def write(byte):
>>    spi.write(byte)
>
> You don't have any import statements here.
> You need to import spi to use it.
>
>> # toggle the latch signal
>>    ft232h.output(5, GPIO.LOW)
>>    ft232h.output(5, GPIO.HIGH)
>
> And the same for ft232h
>
>>
>> # module main.py
>> import RSI
>> import AdafruitInit.py
>
> Note you do NOT use the .py extension when
> importing, just the base name.
>
>> ft232.setup(5, GPIO.OUT)
>
> But again you have not imported ft232
> Also I note that you use ft232 here but ft232h elsewhere.
> Is that correct?
>
> You must import any external names that
> you intend to use.
>
>> write(0xAA)
>
> And here you need to prefix with RSI:
>
> import RSI
>
> ....
>
> RSI.write(....)
>
> A Python import is very different to a C include.
> In C you actually include the source text in your
> file so everything inside the file becomes visible.
> In a Python import you add names to a dictionary.
> In this case the only name added is RSI. The code
> inside the RSI module is effectively invisible to
> your main.py, only the name of the module is seen.
> So you must prefix the RSI contents before you use it.
>
>
>> "write()" tells me that
>>
>> "global name 'ft232h' is not defined"
>
> Please always post full error texts, never summarize.
>
>> Regarding permissions.  I'm not sure about the need for sudo, but that
>> was used in the example.
>
> I suspect it's needed because you are accessing
> privileged IO ports. It would not normally be
> needed to run a Python script.
>
>> I had been working most of the day on Friday and the scripts were
>> running fine.
>
> That is the real mystery since the above code
> should not have worked.
>
>> Does some of the FTDI (AdafruitInit.py) remain resident
>
> No, it will be deleted.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From alan.gauld at yahoo.co.uk  Wed Sep  5 09:42:25 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 5 Sep 2018 14:42:25 +0100
Subject: [Tutor] Fwd: Accessing variables from other modules
In-Reply-To: <CADUn+-K_KF+ric-GHgAo2n_bqCcw-w66P9tzmvOyNZJNAMd3qA@mail.gmail.com>
References: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
 <20180904171956.GX27312@ando.pearwood.info>
 <CADUn+-LgXEM1Mj1y4tYuYDuUmPRmaqouCU64atc1Jui-m+o=yA@mail.gmail.com>
 <CADUn+-+La+-hSwtK_Cvr7OCnd45_3-2q47nWEj=bs8BXtgzY4w@mail.gmail.com>
 <pmo5e7$5dd$1@blaine.gmane.org>
 <CADUn+-K_KF+ric-GHgAo2n_bqCcw-w66P9tzmvOyNZJNAMd3qA@mail.gmail.com>
Message-ID: <5c90cc90-cf4c-b628-0d0e-e04637965e0c@yahoo.co.uk>

On 05/09/18 14:05, Chip Wachob wrote:
> # module AdafruitInit.py
> # from the Adafruit tutorials..
> import Adafruit_GPIO.FT232H as FT232H
> import Adafruit_GPIO as GPIO
>
> FT232H.use_FT232H()
>
> ft232h = FT232H.FT232H()
>
> # config settings for the SPI 'machine'
> spi = FT232.SPI(ft232h, 4, 20000, 2, FT232H.MSBFIRST)
>

That last line created a new variable inside the AdafruitInit module.
It is not visible anywhere else.

> # module RSI.py
> import AdafruitInit
>
> def write(byte):
>    spi.write(byte)

You use spi but it is not visible. It is inside AdafriuitInit
so you need to prefix the name (I'd suggest importing
as an alias!)

?????? AdafruitInit.spi.write(byte)

> # toggle the latch signal
>    ft232h.output(5, GPIO.LOW)
>    ft232h.output(5, GPIO.HIGH)

And the same here. ft232h is a variable inside AdafriotInit,
so you must prefix it.

BUT GPIO is defined in some other module which
you will also need to import that....

import Adafruit_GPIO as GPIO

adafruitInit.ft232h.output(5, GPIO.LOW)


Any name that you try to use must be
- defined in this module or
- imported or
- prefixed with the name of a module that you imported.

If you do not define it in this module you must import
or prefix.


> ---------------module separator ------------------------
>
> # module main.py
> import RSI
> import AdafruitInit
>
> ft232h.setup(5, GPIO.OUT)
>
> write(0xAA)

Again you need to use the prefixes (and import GPIO)

AdafruitInit.ft232h.setup(...)
RSI.write(...)

> The actual error message for the ft232h... line is:
>
> NameError: global name 'ft232h' is not defined

Please send the full error text, they contain a lot of useful
information. In this case the summary line is enough but in
future we really need the full text.

The name error is because your main module cannpt see
ft232h defined anywhere - it is inside the other module.

So, my write line should have read?
> RSI.write(0xAA)
>
> Does this mean that I need to call the ft232h like this?
>
> AdafruitInit.ft232h.setup(5, GPIO.OUT)

Exactly. And import GPIO too.

> Earlier in the thread you mentioned that there are several ways to
> import.  Obviously there's small differences between the methods.  If
> you know of a good resource I can use to get a better understanding /

Since you know C already you should probably just read the official
tutorial.
It covers all the different styles.

The only guidance i'll add is to avoid the

from foo import *

style since it easily leads to hard to spot name collisions.
Only use it for experiments in the >>> prompt.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


From wachobc at gmail.com  Wed Sep  5 10:06:39 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Wed, 5 Sep 2018 10:06:39 -0400
Subject: [Tutor] Fwd: Accessing variables from other modules
In-Reply-To: <5c90cc90-cf4c-b628-0d0e-e04637965e0c@yahoo.co.uk>
References: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
 <20180904171956.GX27312@ando.pearwood.info>
 <CADUn+-LgXEM1Mj1y4tYuYDuUmPRmaqouCU64atc1Jui-m+o=yA@mail.gmail.com>
 <CADUn+-+La+-hSwtK_Cvr7OCnd45_3-2q47nWEj=bs8BXtgzY4w@mail.gmail.com>
 <pmo5e7$5dd$1@blaine.gmane.org>
 <CADUn+-K_KF+ric-GHgAo2n_bqCcw-w66P9tzmvOyNZJNAMd3qA@mail.gmail.com>
 <5c90cc90-cf4c-b628-0d0e-e04637965e0c@yahoo.co.uk>
Message-ID: <CADUn+-KGDaZLZ9r2iVW6wxL5B=CAUFjmxDC-62M9=3be6Xs1Gw@mail.gmail.com>

Thank you!

Okay, I think I'm starting to get a handle on the visibility of
things.  As you said, much different than C.

Just to confirm that I'm understanding correctly:

Even through the import Adafruit_GPIO as GPIO line exists in the
AdafruitInit.py file, which is imported by the import AdafruitInit
line in main.py, main.py does not automatically inherit the
Adafruit_GPIO.  Which is why you indicate that I need to also import
it in main.py





On Wed, Sep 5, 2018 at 9:42 AM, Alan Gauld <alan.gauld at yahoo.co.uk> wrote:
> On 05/09/18 14:05, Chip Wachob wrote:
>> # module AdafruitInit.py
>> # from the Adafruit tutorials..
>> import Adafruit_GPIO.FT232H as FT232H
>> import Adafruit_GPIO as GPIO
>>
>> FT232H.use_FT232H()
>>
>> ft232h = FT232H.FT232H()
>>
>> # config settings for the SPI 'machine'
>> spi = FT232.SPI(ft232h, 4, 20000, 2, FT232H.MSBFIRST)
>>
>
> That last line created a new variable inside the AdafruitInit module.
> It is not visible anywhere else.
>
>> # module RSI.py
>> import AdafruitInit
>>
>> def write(byte):
>>    spi.write(byte)
>
> You use spi but it is not visible. It is inside AdafriuitInit
> so you need to prefix the name (I'd suggest importing
> as an alias!)
>
>        AdafruitInit.spi.write(byte)
>
>> # toggle the latch signal
>>    ft232h.output(5, GPIO.LOW)
>>    ft232h.output(5, GPIO.HIGH)
>
> And the same here. ft232h is a variable inside AdafriotInit,
> so you must prefix it.
>
> BUT GPIO is defined in some other module which
> you will also need to import that....
>
> import Adafruit_GPIO as GPIO
>
> adafruitInit.ft232h.output(5, GPIO.LOW)
>
>
> Any name that you try to use must be
> - defined in this module or
> - imported or
> - prefixed with the name of a module that you imported.
>
> If you do not define it in this module you must import
> or prefix.
>
>
>> ---------------module separator ------------------------
>>
>> # module main.py
>> import RSI
>> import AdafruitInit
>>
>> ft232h.setup(5, GPIO.OUT)
>>
>> write(0xAA)
>
> Again you need to use the prefixes (and import GPIO)
>
> AdafruitInit.ft232h.setup(...)
> RSI.write(...)
>
>> The actual error message for the ft232h... line is:
>>
>> NameError: global name 'ft232h' is not defined
>
> Please send the full error text, they contain a lot of useful
> information. In this case the summary line is enough but in
> future we really need the full text.
>
> The name error is because your main module cannpt see
> ft232h defined anywhere - it is inside the other module.
>
> So, my write line should have read?
>> RSI.write(0xAA)
>>
>> Does this mean that I need to call the ft232h like this?
>>
>> AdafruitInit.ft232h.setup(5, GPIO.OUT)
>
> Exactly. And import GPIO too.
>
>> Earlier in the thread you mentioned that there are several ways to
>> import.  Obviously there's small differences between the methods.  If
>> you know of a good resource I can use to get a better understanding /
>
> Since you know C already you should probably just read the official
> tutorial.
> It covers all the different styles.
>
> The only guidance i'll add is to avoid the
>
> from foo import *
>
> style since it easily leads to hard to spot name collisions.
> Only use it for experiments in the >>> prompt.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>

From alan.gauld at yahoo.co.uk  Wed Sep  5 12:58:20 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 5 Sep 2018 17:58:20 +0100
Subject: [Tutor] Fwd: Accessing variables from other modules
In-Reply-To: <CADUn+-KGDaZLZ9r2iVW6wxL5B=CAUFjmxDC-62M9=3be6Xs1Gw@mail.gmail.com>
References: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
 <20180904171956.GX27312@ando.pearwood.info>
 <CADUn+-LgXEM1Mj1y4tYuYDuUmPRmaqouCU64atc1Jui-m+o=yA@mail.gmail.com>
 <CADUn+-+La+-hSwtK_Cvr7OCnd45_3-2q47nWEj=bs8BXtgzY4w@mail.gmail.com>
 <pmo5e7$5dd$1@blaine.gmane.org>
 <CADUn+-K_KF+ric-GHgAo2n_bqCcw-w66P9tzmvOyNZJNAMd3qA@mail.gmail.com>
 <5c90cc90-cf4c-b628-0d0e-e04637965e0c@yahoo.co.uk>
 <CADUn+-KGDaZLZ9r2iVW6wxL5B=CAUFjmxDC-62M9=3be6Xs1Gw@mail.gmail.com>
Message-ID: <pmp1ra$kti$1@blaine.gmane.org>

On 05/09/18 15:06, Chip Wachob wrote:

> Okay, I think I'm starting to get a handle on the visibility of
> things.  As you said, much different than C.

Yes. The significant thing is to remember that in
Python you are importing names. In C you include
the contents of the file.

#include <stdio.h>

Lets you access everything in the stdio.h file
as if it were part of your own file.

import sys

Lets you see the sys module but not whats inside it.
To access whats inside you must use the name as
a prefix.

The Pytho import idiom

from sys import *

is similar in effect to the C style include
(although by an entirely different mechanism)
but is considered bad practice (for the same
reasons C++ has its scope operator(::))

> Even through the import Adafruit_GPIO as GPIO line exists in the
> AdafruitInit.py file, which is imported by the import AdafruitInit
> line in main.py, 

The critical conceptual error here is that the
file is not imported(*), only the name. Importing
in Python is all about visibility control

(*)In practice although the module is not
imported into your file it is executed, so any
new variables, classes and functions are created,
but their names are not visible in your code
except via the module name.

Let me revisit the different import styles
in more detail. Remember we are discussing visibility
of names not code.


##############################
import modulename

This makes modulename visible to the importing module.
Nothing inside modulename is visible. To access the
contents you must use modulename as a prefix.

x = modulename.name1

###############################
import modulename as alias

Exactly the same except that you can refer to
modulename using the (usually shorter) alias.

x = alias.name1

There are a few community standard aliases such as

import numpy as np
import tkinter as tk

But they are purely conventions, you can use
any alias you like. For those who enjoy typing
they could even do

import os as operating_system

And access the functions as

operating_system.listdir('.')

instead of

os.listdir('.')

if they really wanted to...

################################
from module import name1, name2

This imports specific names from within module.

You can now access name1 and name2 directly:

x - name1  # accesses module.name1

But it does NOT import module itself,
only name1, name2, etc. If you try

x = module.name3

You will get an error about module (not name3!)
not being recognised.


################################
from module import name1 as n1

Same as above but use the alias n1 instead of
the longer name1.

x = n1   # like x = module.name1

This is very like you doing the following:

from module import name1
n1 = name1

################################
from module import *

This makes all the names defined in module visible
within the importing module. Again it does not make
module itself visible, only the names inside.

This is considered bad practice because if you have
multiple modules containing the same name (things
like open() and write() are common then only the
last name imported will be visible and that can
lead to unexpected errors.


HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From wachobc at gmail.com  Wed Sep  5 13:12:40 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Wed, 5 Sep 2018 13:12:40 -0400
Subject: [Tutor] Fwd: Accessing variables from other modules
In-Reply-To: <pmp1ra$kti$1@blaine.gmane.org>
References: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
 <20180904171956.GX27312@ando.pearwood.info>
 <CADUn+-LgXEM1Mj1y4tYuYDuUmPRmaqouCU64atc1Jui-m+o=yA@mail.gmail.com>
 <CADUn+-+La+-hSwtK_Cvr7OCnd45_3-2q47nWEj=bs8BXtgzY4w@mail.gmail.com>
 <pmo5e7$5dd$1@blaine.gmane.org>
 <CADUn+-K_KF+ric-GHgAo2n_bqCcw-w66P9tzmvOyNZJNAMd3qA@mail.gmail.com>
 <5c90cc90-cf4c-b628-0d0e-e04637965e0c@yahoo.co.uk>
 <CADUn+-KGDaZLZ9r2iVW6wxL5B=CAUFjmxDC-62M9=3be6Xs1Gw@mail.gmail.com>
 <pmp1ra$kti$1@blaine.gmane.org>
Message-ID: <CADUn+-KdTSV5ZJu0wqWm3gt=3OEYT0pETJ0+9COidbYkb7_s-g@mail.gmail.com>

This helps tremendously!

One last question.

In your examples name1 and name2 could be anything that is contained
in that module.. a variable, function, class, etc..  correct?





On Wed, Sep 5, 2018 at 12:58 PM, Alan Gauld via Tutor <tutor at python.org> wrote:
> On 05/09/18 15:06, Chip Wachob wrote:
>
>> Okay, I think I'm starting to get a handle on the visibility of
>> things.  As you said, much different than C.
>
> Yes. The significant thing is to remember that in
> Python you are importing names. In C you include
> the contents of the file.
>
> #include <stdio.h>
>
> Lets you access everything in the stdio.h file
> as if it were part of your own file.
>
> import sys
>
> Lets you see the sys module but not whats inside it.
> To access whats inside you must use the name as
> a prefix.
>
> The Pytho import idiom
>
> from sys import *
>
> is similar in effect to the C style include
> (although by an entirely different mechanism)
> but is considered bad practice (for the same
> reasons C++ has its scope operator(::))
>
>> Even through the import Adafruit_GPIO as GPIO line exists in the
>> AdafruitInit.py file, which is imported by the import AdafruitInit
>> line in main.py,
>
> The critical conceptual error here is that the
> file is not imported(*), only the name. Importing
> in Python is all about visibility control
>
> (*)In practice although the module is not
> imported into your file it is executed, so any
> new variables, classes and functions are created,
> but their names are not visible in your code
> except via the module name.
>
> Let me revisit the different import styles
> in more detail. Remember we are discussing visibility
> of names not code.
>
>
> ##############################
> import modulename
>
> This makes modulename visible to the importing module.
> Nothing inside modulename is visible. To access the
> contents you must use modulename as a prefix.
>
> x = modulename.name1
>
> ###############################
> import modulename as alias
>
> Exactly the same except that you can refer to
> modulename using the (usually shorter) alias.
>
> x = alias.name1
>
> There are a few community standard aliases such as
>
> import numpy as np
> import tkinter as tk
>
> But they are purely conventions, you can use
> any alias you like. For those who enjoy typing
> they could even do
>
> import os as operating_system
>
> And access the functions as
>
> operating_system.listdir('.')
>
> instead of
>
> os.listdir('.')
>
> if they really wanted to...
>
> ################################
> from module import name1, name2
>
> This imports specific names from within module.
>
> You can now access name1 and name2 directly:
>
> x - name1  # accesses module.name1
>
> But it does NOT import module itself,
> only name1, name2, etc. If you try
>
> x = module.name3
>
> You will get an error about module (not name3!)
> not being recognised.
>
>
> ################################
> from module import name1 as n1
>
> Same as above but use the alias n1 instead of
> the longer name1.
>
> x = n1   # like x = module.name1
>
> This is very like you doing the following:
>
> from module import name1
> n1 = name1
>
> ################################
> from module import *
>
> This makes all the names defined in module visible
> within the importing module. Again it does not make
> module itself visible, only the names inside.
>
> This is considered bad practice because if you have
> multiple modules containing the same name (things
> like open() and write() are common then only the
> last name imported will be visible and that can
> lead to unexpected errors.
>
>
> HTH
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From alan.gauld at yahoo.co.uk  Wed Sep  5 19:13:11 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 6 Sep 2018 00:13:11 +0100
Subject: [Tutor] Fwd: Accessing variables from other modules
In-Reply-To: <CADUn+-KdTSV5ZJu0wqWm3gt=3OEYT0pETJ0+9COidbYkb7_s-g@mail.gmail.com>
References: <CADUn+-JX9SpAO+StYHaifM7Cgb3c68QLpUi5w-CoEp=z4E2onQ@mail.gmail.com>
 <20180904171956.GX27312@ando.pearwood.info>
 <CADUn+-LgXEM1Mj1y4tYuYDuUmPRmaqouCU64atc1Jui-m+o=yA@mail.gmail.com>
 <CADUn+-+La+-hSwtK_Cvr7OCnd45_3-2q47nWEj=bs8BXtgzY4w@mail.gmail.com>
 <pmo5e7$5dd$1@blaine.gmane.org>
 <CADUn+-K_KF+ric-GHgAo2n_bqCcw-w66P9tzmvOyNZJNAMd3qA@mail.gmail.com>
 <5c90cc90-cf4c-b628-0d0e-e04637965e0c@yahoo.co.uk>
 <CADUn+-KGDaZLZ9r2iVW6wxL5B=CAUFjmxDC-62M9=3be6Xs1Gw@mail.gmail.com>
 <pmp1ra$kti$1@blaine.gmane.org>
 <CADUn+-KdTSV5ZJu0wqWm3gt=3OEYT0pETJ0+9COidbYkb7_s-g@mail.gmail.com>
Message-ID: <pmpnq4$f2d$1@blaine.gmane.org>

On 05/09/18 18:12, Chip Wachob wrote:

> In your examples name1 and name2 could be anything that is contained
> in that module.. a variable, function, class, etc..  correct?

Correct. They are just names.

Again a difference between Python and C.
In C a name is a label associated with a memory address
which in turn is associated with a specified data type.

In Python a name is just a name, a key in a dictionary.
It's value is any kind of object and can change throughout
the program's lifetime. A string now, an integer later,
then a list and maybe even a class or instance. Of course,
it's probably not a good idea to change a variables type
too often but it is possible.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From donna.black at me.com  Wed Sep  5 23:14:00 2018
From: donna.black at me.com (Donna Black)
Date: Thu, 06 Sep 2018 11:14:00 +0800
Subject: [Tutor] Python
Message-ID: <1ED96AFA-CE01-4C00-A6D9-C3B90F8CEB12@me.com>

How do we save our work on python? IDLE hasn?t installed itself on my computer 

Sent from my iPhone

From alan.gauld at yahoo.co.uk  Thu Sep  6 04:21:52 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 6 Sep 2018 09:21:52 +0100
Subject: [Tutor] Python
In-Reply-To: <1ED96AFA-CE01-4C00-A6D9-C3B90F8CEB12@me.com>
References: <1ED96AFA-CE01-4C00-A6D9-C3B90F8CEB12@me.com>
Message-ID: <pmqnuu$fdu$1@blaine.gmane.org>

On 06/09/18 04:14, Donna Black via Tutor wrote:
> How do we save our work on python? IDLE hasn?t installed itself on my computer 

Which OS are you using? That will help us
find/install IDLE.

However, you don't need IDLE to work with Python,
just a text editor.

If I assume you are using Windows then start notepad
and type the 2 lines

print("Hello world")
input("hit return to exit...")

Then save the file as hello.py

You should now be able to run that file by
double clicking it in your file manager.

Alternatively, start a CMD session
(Windows+R type cmd, hit OK) and at the
prompt type

python \the\folder\where\you\saved\the\file\hello.py

If you have problems with any of that let us know.
copy any error messages you get into your
mail message.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From bdcreech91 at gmail.com  Thu Sep  6 12:32:37 2018
From: bdcreech91 at gmail.com (Brandon Creech)
Date: Thu, 6 Sep 2018 12:32:37 -0400
Subject: [Tutor] Writing for loop output to csv
Message-ID: <CAOiKO1jVRdgcckEiMLJuot5fFUWg7VFZxMn2v48oxP-ivaur+w@mail.gmail.com>

Hi, I am working to forecast the temperatures for the next 5 days using an
API and a for loop. I would like write the output of this loop to a csv in
this format::

Columns: City, min1, max1, min2, max2,min3,max3,min4,max4,min5,max5
data:         Athens,Greece 25.4,26.7....etc.
                 Nantou,Taiwan 16.18, ......etc

the data prints out on top of each other like this:

Nantou, Taiwan 29.49 20.79
Nantou, Taiwan 30. 49 21.56

Code I have:

from forecastiopy import *
import csv

api_key = 'XXXXXXX'

cities = {"Taree, Australia":(-31.8895,152.4444), "Belmopan,
Belize":(17.251,-88.759), "Nanaimo, Canada":(49.1659,-123.9401),
       "Sherbrooke,Canada":(45.4042,-71.8929),
"Shenyang,China":(41.8057,123.4315),"Crewe,England (UK)":(53.1004,-2.4438),
       "Cairo, Egypt":(30.0444,31.2357),
"Kaiserslautern,Germany":(49.4401,7.7491),
"Athens,Greece":(37.9838,23.7275),
       "Bengaluru,India":(12.9716,77.5946),
"Incheon,Korea":(37.4563,126.7052), "Kathmandu, Nepal":(27.7172,85.3240),

 "Lahore,Pakistan":(31.5204,74.3587),"Lima,Peru":(-12.0464,-77.0428),"Belgrade,Serbia":(44.7866,20.4489),
       "Nantou,Taiwan":(23.961,120.9719),"Des Moines,United
States":(41.5868,-93.625)}



for city, coords in cities.items():
    weather = ForecastIO.ForecastIO( api_key, latitude=coords[0],
longitude=coords[1] )
    daily = FIODaily.FIODaily(weather)
    for day in range(2,7):
        print(str(city) + " " + str(daily.get_day(day)['temperatureMax']) +
" " + str(daily.get_day(day)['temperatureMin']))

From rls4jc at gmail.com  Thu Sep  6 15:09:12 2018
From: rls4jc at gmail.com (Roger Lea Scherer)
Date: Thu, 6 Sep 2018 12:09:12 -0700
Subject: [Tutor] localhosting
In-Reply-To: <55925a4a-ceb0-2a43-33fc-bb649134ba39@wichmann.us>
References: <CAPvEsMzeGsoNUe1UxP=96fM_6aD6AG4YQb+RhUBQF6imiyJ1ng@mail.gmail.com>
 <pm8b7t$re4$1@blaine.gmane.org>
 <55925a4a-ceb0-2a43-33fc-bb649134ba39@wichmann.us>
Message-ID: <CAPvEsMy8sk9v-kU25w5JPn0UXe=8F6SFs5-yXEVF5KXQ2ZQ+5w@mail.gmail.com>

Thank you all for your help. I am still chugging away at this problem. I've
switched to Windows PowerShell Version 5.1 since I can select, copy, and
paste more easily in PowerShell. (I can't figure out how to do that in
Anaconda and I get the same errors in PowerShell.)

I removed the "3" in "python3" and it works; along with moving the "www"
folder to where python resides. Thanks for the help.

So it appears the local host is running correctly, but when I run this code:

print("Hello World")

Chrome does not render and I get an error message in PowerShell:
127.0.0.1 - - [06/Sep/2018 11:22:46] "GET /cgi-bin/hello.py HTTP/1.1" 200 -
127.0.0.1 - - [06/Sep/2018 11:22:46] command:
C:\Users\Roger\AppData\Local\Programs\Python\Python37-32\python.exe -u
C:\Users\Roger\documents\roger\python\www\cgi-bin\hello.py ""
127.0.0.1 - - [06/Sep/2018 11:22:46] b'  File
"C:\\Users\\Roger\\documents\\roger\\python\\www\\cgi-bin\\hello.py", line
1\r\n    print "<html>"\r\n                 ^\r\nSyntaxError: Missing
parentheses in call to \'print\'. Did you mean print("<html>")?\r\n'
127.0.0.1 - - [06/Sep/2018 11:22:46] CGI script exit status 0x1

BUT when I run this code:
def fib(n):
    if n < 2:
        return n
    return fib(n-1) + fib(n-2)

print(fib(15))

Chrome does not render but I DON'T get an error message, I get this:
127.0.0.1 - - [06/Sep/2018 11:33:30] "GET /cgi-bin/recursive%20fibonacci.py
HTTP/1.1" 200 -
127.0.0.1 - - [06/Sep/2018 11:33:30] command:
C:\Users\Roger\AppData\Local\Programs\Python\Python37-32\python.exe -u
"C:\Users\Roger\documents\roger\python\www\cgi-bin\recursive fibonacci.py"
""
127.0.0.1 - - [06/Sep/2018 11:33:30] CGI script exited OK

So I'm confused about 2 things:
1. Why does the one file cause an error in PowerShell (and Anaconda
actually) when it seems to be the same as the other file which appears to
run with no error, but just not render? and,
2. What am I missing: why won't it render since the instructions I have at
the very beginning of this email say, basically, this is all I have to do
to get it to render?

I know this second question is maybe a little bit outside this forum, but I
am struggling to make sense out of what little I know and, truly, this
forum seems the nicest and most helpful I've encountered.

Thank you as always.


On Thu, Aug 30, 2018 at 6:01 AM Mats Wichmann <mats at wichmann.us> wrote:

> On 08/30/2018 02:54 AM, Alan Gauld via Tutor wrote:
> > On 30/08/18 00:09, Roger Lea Scherer wrote:
> >> I'm trying to implement a local host. My instructions tell me to type
> the
> >> following command in the command line, make sure I'm in the "www" folder
> >
> > So this is not the folder where python3 is installed. (See below)
> >
> >> python3 -m http.server --cgi 8000
> >
> >> I'm running Anaconda in Windows 10. I get an error: 'python3' is not
> >> recognized as an internal or external command, operable program or batch
> >> file.
> >> But this is the folder that I thought Python 3.6 was in.
> >
> > you said you were in www which is not where Python should
> > be installed.
> >
> > It is likely that Python is not in your system PATH.
> > You need to find out where it is installed and add it.
> > In a standard Python install it would either be in
> > C:\PROGRAM FILES\PYTHON or
> > C:\PYTHON
> >
> > But Anaconda (version please?) could use its own path
> > such as
> >
> > C:\ANACONDA\PYTHON
> >
> >> So how do I correct this? I suspect python3 isn't in this folder. I
> know I
> >> have python3 because I run python3.6 shell practically every day.
> >
> > How do you run it?
> >>From a command line or via a menu/shortcut?
> >
> >> looked in the Program Files folder, came up empty as far as python is
> >> concerned, but I don't know where else to look?
>
> Several things that could help:
>
> you can ask python itself to tell you where it is, since you say python
> works for you.
>
>     >>> import sys
>     >>> print(sys.executable)
>
> the standard Windows python defaults to a "user install", so it could be
> in a place like
>
> {yourhomdirectory}/AppData/Local/Programs/Python
>
> Anaconda, as Alan says, likely puts it somewhere different.
>
> Python 3 isn't named python3 on Windows unless you take steps to make it
> so, it's just called python.  So modify your instructions accordingly.
>
> Also on Windows, if it was installed, there is a separate thing called
> the Python Launcher, which lets you run the command "py" which typically
> gets put in a place that is always found, and avoids the fiddling with
> getting Python itself into your PATH.  But I'm unsure whether the
> Anaconda install actually installs that. You could try... just type: py
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
Roger Lea Scherer
623.255.7719

                  *Strengths:*
   Input, Strategic,
Responsibility,

Learner, Ideation

From alan.gauld at yahoo.co.uk  Thu Sep  6 18:04:36 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 6 Sep 2018 23:04:36 +0100
Subject: [Tutor] Writing for loop output to csv
In-Reply-To: <CAOiKO1jVRdgcckEiMLJuot5fFUWg7VFZxMn2v48oxP-ivaur+w@mail.gmail.com>
References: <CAOiKO1jVRdgcckEiMLJuot5fFUWg7VFZxMn2v48oxP-ivaur+w@mail.gmail.com>
Message-ID: <pms85h$l7u$1@blaine.gmane.org>

On 06/09/18 17:32, Brandon Creech wrote:
> Hi, I am working to forecast the temperatures for the next 5 days using an
> API and a for loop. I would like write the output of this loop to a csv in
> this format::
> 
> Columns: City, min1, max1, min2, max2,min3,max3,min4,max4,min5,max5
> data:         Athens,Greece 25.4,26.7....etc.
>                  Nantou,Taiwan 16.18, ......etc
> 
> the data prints out on top of each other like this:
> 
> Nantou, Taiwan 29.49 20.79
> Nantou, Taiwan 30. 49 21.56

Sorry, can you elaborate I don;t understand what you mean?
The data you show does not seem to be related to the output
you show?

Also having the city be a dual name separated by a comma
within a csv file is likely to create confusion, not least
for yourself. I would suggest splitting it to city and
country. If that doesn't work (for your API perhaps)
then consider changing the separator.  If that doesn't
work for you then tough luck, you'll need to persevere.


> from forecastiopy import *
> import csv

You import csv but don't seem to use it anywhere below?

> 
> api_key = 'XXXXXXX'
> 
> cities = {"Taree, Australia":(-31.8895,152.4444), "Belmopan,
> Belize":(17.251,-88.759), "Nanaimo, Canada":(49.1659,-123.9401),

Again this does not seem to match either the the
data sample shown above or the output.

> for city, coords in cities.items():
>     weather = ForecastIO.ForecastIO( api_key, latitude=coords[0],
> longitude=coords[1] )
>     daily = FIODaily.FIODaily(weather)
>     for day in range(2,7):
>         print(str(city) + " " + str(daily.get_day(day)['temperatureMax']) +
> " " + str(daily.get_day(day)['temperatureMin']))

This will produce something like the output you showed
(although I don't think you need all the str() calls).
But it is nothing like the output you said you wanted
in the csv file and you are not using csv anywhere
to generate it.

What exactly are you asking us to help you with?
Everything seems to be doing exactly what you are
asking it to do.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From cs at cskk.id.au  Thu Sep  6 18:06:46 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Fri, 7 Sep 2018 08:06:46 +1000
Subject: [Tutor] localhosting
In-Reply-To: <CAPvEsMy8sk9v-kU25w5JPn0UXe=8F6SFs5-yXEVF5KXQ2ZQ+5w@mail.gmail.com>
References: <CAPvEsMy8sk9v-kU25w5JPn0UXe=8F6SFs5-yXEVF5KXQ2ZQ+5w@mail.gmail.com>
Message-ID: <20180906220646.GA6713@cskk.homeip.net>

Note: replies inline below, and irrelevant verbiage trimmed. We prefer this 
format on this list: it makes it easy to respond point by point and makes the 
reply read like a conversation. Please consider adopting this style here.

Anyway, to your message:

On 06Sep2018 12:09, Roger Lea Scherer <rls4jc at gmail.com> wrote:
>Thank you all for your help. I am still chugging away at this problem. I've
>switched to Windows PowerShell Version 5.1 since I can select, copy, and
>paste more easily in PowerShell. (I can't figure out how to do that in
>Anaconda and I get the same errors in PowerShell.)
>
>I removed the "3" in "python3" and it works; along with moving the "www"
>folder to where python resides. Thanks for the help.

Now switch back to python3 and see if it still works, even temporarily. You 
want to isolate what was the fix and what was irrelevant.

>So it appears the local host is running correctly, but when I run this code:
>
>print("Hello World")
>
>Chrome does not render and I get an error message in PowerShell:
>127.0.0.1 - - [06/Sep/2018 11:22:46] "GET /cgi-bin/hello.py HTTP/1.1" 200 -
>127.0.0.1 - - [06/Sep/2018 11:22:46] command:
>C:\Users\Roger\AppData\Local\Programs\Python\Python37-32\python.exe -u
>C:\Users\Roger\documents\roger\python\www\cgi-bin\hello.py ""
>127.0.0.1 - - [06/Sep/2018 11:22:46] b'  File
>"C:\\Users\\Roger\\documents\\roger\\python\\www\\cgi-bin\\hello.py", line
>1\r\n    print "<html>"\r\n                 ^\r\nSyntaxError: Missing
>parentheses in call to \'print\'. Did you mean print("<html>")?\r\n'
>127.0.0.1 - - [06/Sep/2018 11:22:46] CGI script exit status 0x1

I'm guessing you "Hello World" print was after the start of the <HTML> tag.  
Look at the rrror message you've recited above: it is talking about line 1 of 
your hello.py file, which has this:

  print "<html>"

That is an old-style print _statement_, which will not work in Python 3. So 
your other print isn't the source of this error message: likely it is never 
reached.

Edit your python files to start with this import:

  from __future__ import print_function

That will cause python 2 to expect print to be a function (needing brackets) 
and not a statement, meaning the same syntax will be required for both python 2 
and 3, providing you with consistent behaviour.

Then change the print statement into a print function call:

  print("<html>")

>BUT when I run this code:
>def fib(n):
>    if n < 2:
>        return n
>    return fib(n-1) + fib(n-2)
>
>print(fib(15))

Note: python 3 print function.

>Chrome does not render but I DON'T get an error message, I get this:
>127.0.0.1 - - [06/Sep/2018 11:33:30] "GET /cgi-bin/recursive%20fibonacci.py
>HTTP/1.1" 200 -
>127.0.0.1 - - [06/Sep/2018 11:33:30] command:
>C:\Users\Roger\AppData\Local\Programs\Python\Python37-32\python.exe -u
>"C:\Users\Roger\documents\roger\python\www\cgi-bin\recursive fibonacci.py"
>""
>127.0.0.1 - - [06/Sep/2018 11:33:30] CGI script exited OK

There should be more than a bare number in the output. CGI scripts require one 
to provide HTTP response headers before the body text: that way they can return 
other stuff than HTML (eg an image or CSV data etc). Try putting these print 
calls at the start of that script:

  print('Content-Type: text/html')
  print()

which mark the rest of the script output as HTML and then provide a blank line 
to indicate the end of the headers. The objective is that your script produces 
this output:

  Content-Type: text/html

  325

That's a made up number, I haven't bothered to compute fib(15), sorry.

>So I'm confused about 2 things:
>1. Why does the one file cause an error in PowerShell (and Anaconda
>actually) when it seems to be the same as the other file which appears to
>run with no error, but just not render? and,

Because you're running the file with Python 2 by hand and Python 3 from the web 
server (see the "Python\Python37-32\python.exe" in the log?) Apply the 
suggested __future__ import and you'll get consistent behaviour.

>2. What am I missing: why won't it render since the instructions I have at
>the very beginning of this email say, basically, this is all I have to do
>to get it to render?
>
>I know this second question is maybe a little bit outside this forum, but I
>am struggling to make sense out of what little I know and, truly, this
>forum seems the nicest and most helpful I've encountered.

The output of a CGI script should be a valid HTTP response: you need some HTTP 
headers describing the output format and _then_ the core programme output. The 
minimal header is a Content-Type: header to denote the program result format.  
See above for how to stick one at the top of any of your CGI scripts.

Cheers,
Cameron Simpson <cs at cskk.id.au>

From cs at cskk.id.au  Thu Sep  6 18:17:33 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Fri, 7 Sep 2018 08:17:33 +1000
Subject: [Tutor] Writing for loop output to csv
In-Reply-To: <CAOiKO1jVRdgcckEiMLJuot5fFUWg7VFZxMn2v48oxP-ivaur+w@mail.gmail.com>
References: <CAOiKO1jVRdgcckEiMLJuot5fFUWg7VFZxMn2v48oxP-ivaur+w@mail.gmail.com>
Message-ID: <20180906221733.GA52282@cskk.homeip.net>

On 06Sep2018 12:32, Brandon Creech <bdcreech91 at gmail.com> wrote:
>Hi, I am working to forecast the temperatures for the next 5 days using an
>API and a for loop. I would like write the output of this loop to a csv in
>this format::
>
>Columns: City, min1, max1, min2, max2,min3,max3,min4,max4,min5,max5
>data:         Athens,Greece 25.4,26.7....etc.
>                 Nantou,Taiwan 16.18, ......etc
>
>the data prints out on top of each other like this:
>
>Nantou, Taiwan 29.49 20.79
>Nantou, Taiwan 30. 49 21.56

Normally there would be more commas in CSV output, eg:

  Nantou, Taiwan,29.49,20.79

and because "Nantou, Taiwan" is a single string, it would typically look like 
this:

  "Nantou, Taiwan",29.49,20.79

to make that clear, otherwise the embedded comma would make it two CSV columns.

>Code I have:
>
>from forecastiopy import *
>import csv

I see you're importing the csv module, but not using it. [...]

[...snip...]
>for city, coords in cities.items():
>    weather = ForecastIO.ForecastIO( api_key, latitude=coords[0],
>longitude=coords[1] )
>    daily = FIODaily.FIODaily(weather)
>    for day in range(2,7):
>        print(str(city) + " " + str(daily.get_day(day)['temperatureMax']) +
>" " + str(daily.get_day(day)['temperatureMin']))

First a small suggestion. Change this:

  print(str(city) + " " + str(daily.get_day(day)['temperatureMax']) + " " + str(daily.get_day(day)['temperatureMin']))

like this:

  day_data = daily.get_day(day)
  print(str(city) + " " + str(day_data['temperatureMax']) + " " + str(day_data['temperatureMin']))

It fetches the daily data just once and makes your subsequent code easily to 
read and debug.

Second, your actual problem. Your loop is basicly sound, but you're using a 
print call for the output.  The csv module provides a writer object which does 
all the heavy lifting for you: turns strings into quotes strings, puts in 
commas, etc. Try this change:

  csvw = csv.writer(sys.stdout)
  for city, coords in cities.items():
      weather = ForecastIO.ForecastIO( api_key, latitude=coords[0], longitude=coords[1] )
      daily = FIODaily.FIODaily(weather)
      for day in range(2,7):
          day_data = daily.get_day(day)
          csvw.writerow([city, day_data['temperatureMax'], day_data['temperatureMin']])

You'll also need to "import sys" up the top to use the name "sys.stdout".

See how now you're just passing a list of the values to the csv writer?

Cheers,
Cameron Simpson <cs at cskk.id.au>

From alan.gauld at yahoo.co.uk  Thu Sep  6 18:54:39 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 6 Sep 2018 23:54:39 +0100
Subject: [Tutor] localhosting
In-Reply-To: <CAPvEsMy8sk9v-kU25w5JPn0UXe=8F6SFs5-yXEVF5KXQ2ZQ+5w@mail.gmail.com>
References: <CAPvEsMzeGsoNUe1UxP=96fM_6aD6AG4YQb+RhUBQF6imiyJ1ng@mail.gmail.com>
 <pm8b7t$re4$1@blaine.gmane.org>
 <55925a4a-ceb0-2a43-33fc-bb649134ba39@wichmann.us>
 <CAPvEsMy8sk9v-kU25w5JPn0UXe=8F6SFs5-yXEVF5KXQ2ZQ+5w@mail.gmail.com>
Message-ID: <pmsb3c$2u5$1@blaine.gmane.org>

On 06/09/18 20:09, Roger Lea Scherer wrote:

> I removed the "3" in "python3" and it works; along with moving the "www"
> folder to where python resides. Thanks for the help.

That may appear to work but I suspect its just hiding the real issue
which is about setting the correct path values.

Did you try using the py launcher that Mats suggested.
I think that is the officially recommended solution
for these issues on Windows...

Anyway...
> So it appears the local host is running correctly, 

I assume you mean some kind of web server running
on the localhost network port? ie 127.0.0.1?

> print("Hello World")
> 
> Chrome does not render and I get an error message in PowerShell:
> 127.0.0.1 - - [06/Sep/2018 11:22:46] "GET /cgi-bin/hello.py HTTP/1.1" 200 -
> 127.0.0.1 - - [06/Sep/2018 11:22:46] command:
> C:\Users\Roger\AppData\Local\Programs\Python\Python37-32\python.exe -u
> C:\Users\Roger\documents\roger\python\www\cgi-bin\hello.py ""
> 127.0.0.1 - - [06/Sep/2018 11:22:46] b'  File
> "C:\\Users\\Roger\\documents\\roger\\python\\www\\cgi-bin\\hello.py", line
> 1\r\n    print "<html>"\r\n                 ^\r\nSyntaxError: Missing
> parentheses in call to \'print\'. Did you mean print("<html>")?\r\n'
> 127.0.0.1 - - [06/Sep/2018 11:22:46] CGI script exit status 0x1

Are you sure that the file hello.py in cgi-bin only
contains the one line? It looks like you may have a
default one with Python 2.7 code in it?



> 1. Why does the one file cause an error in PowerShell (and Anaconda
> actually) when it seems to be the same as the other file which appears to
> run with no error, but just not render? and,

Neither of them output valid html, so I guess that's
why they don't render. The first doesn't appear to be
the hello.py that you think it is - try opening it
in your text editor to check (using the exact path
that the log message uses).

> 2. What am I missing: why won't it render since the instructions I have at
> the very beginning of this email say, basically, this is all I have to do
> to get it to render?

Maybe your instructions are wrong? Maybe they are for Python 2 and you
are running Python 3?

You might find it helpful to read the section on writing web
applications in my tutorial:

http://www.alan-g.me.uk/l2p2/index.htm

Look in the Applications section and read the Web Server
topic for a short example of how to use the basic http.server

> I know this second question is maybe a little bit outside this forum, 

Nope, explanations of why things go wrong are entirely apropos

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From __peter__ at web.de  Fri Sep  7 02:45:23 2018
From: __peter__ at web.de (Peter Otten)
Date: Fri, 07 Sep 2018 08:45:23 +0200
Subject: [Tutor] Writing for loop output to csv
References: <CAOiKO1jVRdgcckEiMLJuot5fFUWg7VFZxMn2v48oxP-ivaur+w@mail.gmail.com>
 <20180906221733.GA52282@cskk.homeip.net>
Message-ID: <pmt6m5$ein$1@blaine.gmane.org>

Cameron Simpson wrote:

> On 06Sep2018 12:32, Brandon Creech <bdcreech91 at gmail.com> wrote:
>>Hi, I am working to forecast the temperatures for the next 5 days using an
>>API and a for loop. I would like write the output of this loop to a csv in
>>this format::
>>
>>Columns: City, min1, max1, min2, max2,min3,max3,min4,max4,min5,max5
>>data:         Athens,Greece 25.4,26.7....etc.
>>                 Nantou,Taiwan 16.18, ......etc

> print call for the output.  The csv module provides a writer object which
> does all the heavy lifting for you: turns strings into quotes strings,
> puts in commas, etc. Try this change:
> 
>   csvw = csv.writer(sys.stdout)
>   for city, coords in cities.items():
>       weather = ForecastIO.ForecastIO( api_key, latitude=coords[0],
>       longitude=coords[1] ) 
>       daily = FIODaily.FIODaily(weather)
>       for day in range(2,7):
>           day_data = daily.get_day(day)
>           csvw.writerow([city, day_data['temperatureMax'],
>           day_data['temperatureMin']])

If you want all min/max pairs in the same row you can prebuild that row in a 
list. With minimal changes to Cameron's code:

# untested
csvw = csv.writer(sys.stdout)
for city, coords in cities.items():
    weather = ForecastIO.ForecastIO(
        api_key, latitude=coords[0], longitude=coords[1]
    )
    daily = FIODaily.FIODaily(weather)
    row = [city]
    for day in range(2, 7):
        day_data = daily.get_day(day)
        row.append(day_data['temperatureMin'])
        row.append(day_data['temperatureMax'])
    csvw.writerow(row)



From jf_byrnes at comcast.net  Fri Sep  7 17:10:57 2018
From: jf_byrnes at comcast.net (Jim)
Date: Fri, 7 Sep 2018 16:10:57 -0500
Subject: [Tutor] No module named uno in virtual environment
Message-ID: <pmupd4$r12$1@blaine.gmane.org>

Mint 18.1
System python3 3.5.2

Python3-uno is available to the system python3. How can I make it 
available to python 3.6.5 in a virtual environment I installed using venv?



(env36) jfb at jims-mint18 ~ $ python
Python 3.6.5 (default, May  3 2018, 10:08:28)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> import oosheet
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File 
"/home/jfb/EVs/env36/lib/python3.6/site-packages/oosheet/__init__.py", 
line 38, in <module>
     import uno, re, zipfile, types, inspect, tempfile, shutil, subprocess
ModuleNotFoundError: No module named 'uno'

Thanks,  Jim


From wachobc at gmail.com  Fri Sep  7 15:45:50 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Fri, 7 Sep 2018 15:45:50 -0400
Subject: [Tutor] Help with building bytearray arrays
Message-ID: <CADUn+-LjZkwjsSi-ntP2eTa1YkarPrKoCDVGfu08EM+uT=ks1g@mail.gmail.com>

Hello,

I've been struggling with this for the last day or so and I can't seem
to figure out how to make it work.

I'll start out by saying that if there's a better approach, then I'm all ears.

I'm using the Adafruit Breakout board for the FTDI FT232H part.  Along
with this comes the Python libraries and Adafruit libraries which I'm
using.  I don't think that the libraries are the real issue here, but
I thought I should mention it just for the sake of information.

Basically I'm trying to write a block of unsigned bytes to the device
and read back an equal sized block of unsigned bytes.  There's a
function that is provided called transfer(data_to_send, num_of_bytes)
that handles the heavy lifting.  Unfortunately there seems to be a bug
in the part and if I attempt to send the entire block of bytes (64),
the device will lock up.  I've been able to determine that if I send
16 bytes at a time, I'm okay.

So, I take my bytearray(64) and step through it 16 bytes at a time like this:

my function's main pieces are:

def transfer_byte_array():
   MAX_LOOP_COUNT = 64
   slice_size = 16
   read_ary = bytearray(MAX_LOOP_COUNT)
   scratch_ary = bytearray()

   for step in range (0, MAX_LOOP_COUNT, slice_size):
      scratch_ary = transfer(data_to_send, slice_size)

      for bytes in range (0, slice_size):
         read_ary = scratch_ary[bytes]

   return(read_ary)


Ideally, I'd like to take the slice_size chunks that have been read
and concatenate them back togetjer into a long MAX_LOOP_COUNT size
array to pass back to the rest of my code.  Eg:

read_ary = ary_slice[0] + ary_slice[1] + ary_slice[2] + ary_slice[3]

I know that the + version doesn't work (or didn't for me) but it is
just my attempt at illustrating the overall goal.

The problem that I repeatedly run into is with the line:

read_ary = scratch_ary[bytes]  (or variants thereof)

The traceback is this:

Traceback (most recent call last):
  File "SW8T_5.py", line 101, in <module>
    loop_size = RSI_size_the_loop(Print)
  File "/home/temp/Python_Scratch/examples/RSI.py", line 350, in
RSI_size_the_loop
    read_ary.append(scratch_ary[singles])
TypeError: an integer or string of size 1 is required

or, one of the other common ones that I've seen is

TypeError: can't concat bytearray to list

This one is confusing because both of the operands are bytearry
types.. or at least I thought they should be...

when I try to replace the same line with :

read_ary += scratch_ary[bytes]

or

read_ary.append(scratch[bytes])

or

read_ary = read_ary + scratch_ary[bytes]


I'm obviously missing something fundamental here.  Problem is I can't
seem to find any examples of people asking this question before on the
inter-webs..

Thank you in advance to taking time to read.

From wachobc at gmail.com  Fri Sep  7 15:54:04 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Fri, 7 Sep 2018 15:54:04 -0400
Subject: [Tutor] Additionally
Message-ID: <CADUn+-Kg836iwHVNasg5o-j_61V6NxA7WNPFg57QKh2wJGM+Ag@mail.gmail.com>

Sorry admin, I don't know how to append a message I already sent:


the transfer function expects an input of a bytearray and returns the same:

    def transfer(self, data):
        """Full-duplex SPI read and write.  The specified array of bytes will be
        clocked out the MOSI line, while simultaneously bytes will be read from
        the MISO line.  Read bytes will be returned as a bytearray object.
        """
        # Build command to read and write SPI data.
        command = 0x30 | (self.lsbfirst << 3) | (self.read_clock_ve <<
2) | self.write_clock_ve
        logger.debug('SPI transfer with command {0:2X}.'.format(command))
        # Compute length low and high bytes.
        # NOTE: Must actually send length minus one because the MPSSE engine
        # considers 0 a length of 1 and FFFF a length of 65536
        length = len(data)
        len_low  = (length-1) & 0xFF
        len_high = ((length-1) >> 8) & 0xFF
        # Send command and length.
        self._assert_cs()
        self._ft232h._write(str(bytearray((command, len_low, len_high))))
        self._ft232h._write(str(bytearray(data)))
        self._ft232h._write('\x87')
        self._deassert_cs()
        # Read response bytes.
        return bytearray(self._ft232h._poll_read(length))

From cs at cskk.id.au  Fri Sep  7 18:23:55 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Sat, 8 Sep 2018 08:23:55 +1000
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <CADUn+-LjZkwjsSi-ntP2eTa1YkarPrKoCDVGfu08EM+uT=ks1g@mail.gmail.com>
References: <CADUn+-LjZkwjsSi-ntP2eTa1YkarPrKoCDVGfu08EM+uT=ks1g@mail.gmail.com>
Message-ID: <20180907222355.GA24273@cskk.homeip.net>

On 07Sep2018 15:45, Chip Wachob <wachobc at gmail.com> wrote:
>Basically I'm trying to write a block of unsigned bytes to the device
>and read back an equal sized block of unsigned bytes.  There's a
>function that is provided called transfer(data_to_send, num_of_bytes)
>that handles the heavy lifting.  Unfortunately there seems to be a bug
>in the part and if I attempt to send the entire block of bytes (64),
>the device will lock up.  I've been able to determine that if I send
>16 bytes at a time, I'm okay.
>
>So, I take my bytearray(64) and step through it 16 bytes at a time like this:
>
>my function's main pieces are:
>
>def transfer_byte_array():
>   MAX_LOOP_COUNT = 64
>   slice_size = 16
>   read_ary = bytearray(MAX_LOOP_COUNT)
>   scratch_ary = bytearray()
>
>   for step in range (0, MAX_LOOP_COUNT, slice_size):
>      scratch_ary = transfer(data_to_send, slice_size)
>
>      for bytes in range (0, slice_size):
>         read_ary = scratch_ary[bytes]
>
>   return(read_ary)
>
>
>Ideally, I'd like to take the slice_size chunks that have been read
>and concatenate them back togetjer into a long MAX_LOOP_COUNT size
>array to pass back to the rest of my code.  Eg:
>
>read_ary = ary_slice[0] + ary_slice[1] + ary_slice[2] + ary_slice[3]

Minor remark: don't use the name "bytes" for a variable, it is a builtin type 
name and you're shadowing it.

It looks to me like "transfer" hands you back a buffer with the read data, so 
this:

  scratch_ary = bytearray()

don't do anything (it gets discarded).

If you're getting back a bytes or bytearray object from transfer, just gather 
them all up in an list:

  returned_buffers = []
  for ......
      response = transfer(data_to_send, slice_size)
      returned_buffers.append(response)
  .......
  read_ary = b''.join(returned_buffers)

Note that that makes a new bytes object for read_ary to refer to. You don't 
need the earlier initialisation of read_ary.

Also note that the bytes object is read only; if that is a problem you'll need 
to construct a bytearray instead.

[...]
>The problem that I repeatedly run into is with the line:
>
>read_ary = scratch_ary[bytes]  (or variants thereof)
>
>The traceback is this:
>
>Traceback (most recent call last):
>  File "SW8T_5.py", line 101, in <module>
>    loop_size = RSI_size_the_loop(Print)
>  File "/home/temp/Python_Scratch/examples/RSI.py", line 350, in
>RSI_size_the_loop
>    read_ary.append(scratch_ary[singles])
>TypeError: an integer or string of size 1 is required

Yeah I thought that looked weird to me too. 

>or, one of the other common ones that I've seen is
>
>TypeError: can't concat bytearray to list
>
>This one is confusing because both of the operands are bytearry
>types.. or at least I thought they should be...

No, one will be a list :-) putting a bunch of:

  print(repr(foo))

replacing "foo" with relevant variables will be illuminating to you; you can 
see immediately where this are not what you expected.

>I'm obviously missing something fundamental here.  Problem is I can't
>seem to find any examples of people asking this question before on the
>inter-webs..

You have the opposite of my problem. I can often find people asking the same 
question, but less often an answer. Or a decent answer, anyway.

Cheers,
Cameron Simpson <cs at cskk.id.au>

From steve at pearwood.info  Fri Sep  7 22:05:04 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Sat, 8 Sep 2018 12:05:04 +1000
Subject: [Tutor] Additionally
In-Reply-To: <CADUn+-Kg836iwHVNasg5o-j_61V6NxA7WNPFg57QKh2wJGM+Ag@mail.gmail.com>
References: <CADUn+-Kg836iwHVNasg5o-j_61V6NxA7WNPFg57QKh2wJGM+Ag@mail.gmail.com>
Message-ID: <20180908020504.GH27312@ando.pearwood.info>

On Fri, Sep 07, 2018 at 03:54:04PM -0400, Chip Wachob wrote:
> Sorry admin, I don't know how to append a message I already sent:

The same way you append to a paper letter you've already posted... by 
sending a new letter, with enough context to understand what you're 
talking about.



-- 
Steve


From wachobc at gmail.com  Fri Sep  7 22:15:22 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Fri, 7 Sep 2018 22:15:22 -0400
Subject: [Tutor] Help with building bytearray arrays
Message-ID: <CADUn+-JMFjDMAyAYiwqSs5DOoh7rNtZmDWnbiWxEMTybLpzJnA@mail.gmail.com>

Admin, please remove my earlier messages.

This message is a properly 'self contained' message.

Hello,

I've been struggling with this for the last day or so and I can't seem
to figure out how to make it work.

I'll start out by saying that if there's a better approach, then I'm all ears.

I'm using the Adafruit Breakout board for the FTDI FT232H part.  Along
with this comes the Python libraries and Adafruit libraries which I'm
using.  I don't think that the libraries are the real issue here, but
I thought I should mention it just for the sake of information.

Basically I'm trying to write a block of unsigned bytes to the device
and read back an equal sized block of unsigned bytes.  There's a
function that is provided called transfer(data_to_send, num_of_bytes)
that handles the heavy lifting.  Unfortunately there seems to be a bug
in the part and if I attempt to send the entire block of bytes (64),
the device will lock up.  I've been able to determine that if I send
16 bytes at a time, I'm okay.

So, I take my bytearray(64) and step through it 16 bytes at a time like this:

my function's main pieces are:

def transfer_byte_array():
   MAX_LOOP_COUNT = 64
   slice_size = 16
   read_ary = bytearray(MAX_LOOP_COUNT)
   scratch_ary = bytearray()

   for step in range (0, MAX_LOOP_COUNT, slice_size):
      scratch_ary = transfer(data_to_send, slice_size)

      for bytes in range (0, slice_size):
         read_ary = scratch_ary[bytes]

   return(read_ary)


Ideally, I'd like to take the slice_size chunks that have been read
and concatenate them back togetjer into a long MAX_LOOP_COUNT size
array to pass back to the rest of my code.  Eg:

read_ary = ary_slice[0] + ary_slice[1] + ary_slice[2] + ary_slice[3]

I know that the + version doesn't work (or didn't for me) but it is
just my attempt at illustrating the overall goal.

The problem that I repeatedly run into is with the line:

read_ary = scratch_ary[bytes]  (or variants thereof)

The traceback is this:

Traceback (most recent call last):
  File "SW8T_5.py", line 101, in <module>
    loop_size = RSI_size_the_loop(Print)
  File "/home/temp/Python_Scratch/examples/RSI.py", line 350, in
RSI_size_the_loop
    read_ary.append(scratch_ary[singles])
TypeError: an integer or string of size 1 is required

or, one of the other common ones that I've seen is

TypeError: can't concat bytearray to list

This one is confusing because both of the operands are bytearry
types.. or at least I thought they should be...

when I try to replace the same line with :

read_ary += scratch_ary[bytes]

or

read_ary.append(scratch[bytes])

or

read_ary = read_ary + scratch_ary[bytes]


I'm obviously missing something fundamental here.  Problem is I can't
seem to find any examples of people asking this question before on the
inter-webs..

the transfer function expects an input of a bytearray and returns the same:

    def transfer(self, data):
        """Full-duplex SPI read and write.  The specified array of bytes will be
        clocked out the MOSI line, while simultaneously bytes will be read from
        the MISO line.  Read bytes will be returned as a bytearray object.
        """
        # Build command to read and write SPI data.
        command = 0x30 | (self.lsbfirst << 3) | (self.read_clock_ve <<
2) | self.write_clock_ve
        logger.debug('SPI transfer with command {0:2X}.'.format(command))
        # Compute length low and high bytes.
        # NOTE: Must actually send length minus one because the MPSSE engine
        # considers 0 a length of 1 and FFFF a length of 65536
        length = len(data)
        len_low  = (length-1) & 0xFF
        len_high = ((length-1) >> 8) & 0xFF
        # Send command and length.
        self._assert_cs()
        self._ft232h._write(str(bytearray((command, len_low, len_high))))
        self._ft232h._write(str(bytearray(data)))
        self._ft232h._write('\x87')
        self._deassert_cs()
        # Read response bytes.
        return bytearray(self._ft232h._poll_read(length))


Thank you in advance to taking time to read.

From wachobc at gmail.com  Fri Sep  7 23:57:41 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Fri, 7 Sep 2018 23:57:41 -0400
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <20180907222355.GA24273@cskk.homeip.net>
References: <CADUn+-LjZkwjsSi-ntP2eTa1YkarPrKoCDVGfu08EM+uT=ks1g@mail.gmail.com>
 <20180907222355.GA24273@cskk.homeip.net>
Message-ID: <CADUn+-+vo_gKkHuTB3F6xZJSTSd+RHw3_TcoNBjhNbx_oxGt1w@mail.gmail.com>

Point taken on 'bytes'..  thanks.

the

scratch_ary = bytearray()

was my attempt at 'setting' the type of the variable.  I had hoped
that it would help resolve the error messages telling me that the
types didn't go together.

Coming from a 'C' background, I find the lack of typing in Python to
be confusing.  I'm used to working with bytes / words signed and
unsigned for a reason.

So, if I'm understanding the transfer() function correctly, the
function takes and returns a bytearray type.  You mentioned about
constructing a bytearray if I need one.  Can you expand on how I
approach that?

I'm going to try the experiment you mentioned in hopes of it giving me
a better understanding of the 'types' and what happens with the
variables.

Thank you,


On Fri, Sep 7, 2018 at 6:23 PM, Cameron Simpson <cs at cskk.id.au> wrote:
> On 07Sep2018 15:45, Chip Wachob <wachobc at gmail.com> wrote:
>>
>> Basically I'm trying to write a block of unsigned bytes to the device
>> and read back an equal sized block of unsigned bytes.  There's a
>> function that is provided called transfer(data_to_send, num_of_bytes)
>> that handles the heavy lifting.  Unfortunately there seems to be a bug
>> in the part and if I attempt to send the entire block of bytes (64),
>> the device will lock up.  I've been able to determine that if I send
>> 16 bytes at a time, I'm okay.
>>
>> So, I take my bytearray(64) and step through it 16 bytes at a time like
>> this:
>>
>> my function's main pieces are:
>>
>> def transfer_byte_array():
>>   MAX_LOOP_COUNT = 64
>>   slice_size = 16
>>   read_ary = bytearray(MAX_LOOP_COUNT)
>>   scratch_ary = bytearray()
>>
>>   for step in range (0, MAX_LOOP_COUNT, slice_size):
>>      scratch_ary = transfer(data_to_send, slice_size)
>>
>>      for bytes in range (0, slice_size):
>>         read_ary = scratch_ary[bytes]
>>
>>   return(read_ary)
>>
>>
>> Ideally, I'd like to take the slice_size chunks that have been read
>> and concatenate them back togetjer into a long MAX_LOOP_COUNT size
>> array to pass back to the rest of my code.  Eg:
>>
>> read_ary = ary_slice[0] + ary_slice[1] + ary_slice[2] + ary_slice[3]
>
>
> Minor remark: don't use the name "bytes" for a variable, it is a builtin
> type name and you're shadowing it.
>
> It looks to me like "transfer" hands you back a buffer with the read data,
> so this:
>
>  scratch_ary = bytearray()
>
> don't do anything (it gets discarded).
>
> If you're getting back a bytes or bytearray object from transfer, just
> gather them all up in an list:
>
>  returned_buffers = []
>  for ......
>      response = transfer(data_to_send, slice_size)
>      returned_buffers.append(response)
>  .......
>  read_ary = b''.join(returned_buffers)
>
> Note that that makes a new bytes object for read_ary to refer to. You don't
> need the earlier initialisation of read_ary.
>
> Also note that the bytes object is read only; if that is a problem you'll
> need to construct a bytearray instead.
>
> [...]
>>
>> The problem that I repeatedly run into is with the line:
>>
>> read_ary = scratch_ary[bytes]  (or variants thereof)
>>
>> The traceback is this:
>>
>> Traceback (most recent call last):
>>  File "SW8T_5.py", line 101, in <module>
>>    loop_size = RSI_size_the_loop(Print)
>>  File "/home/temp/Python_Scratch/examples/RSI.py", line 350, in
>> RSI_size_the_loop
>>    read_ary.append(scratch_ary[singles])
>> TypeError: an integer or string of size 1 is required
>
>
> Yeah I thought that looked weird to me too.
>>
>> or, one of the other common ones that I've seen is
>>
>> TypeError: can't concat bytearray to list
>>
>> This one is confusing because both of the operands are bytearry
>> types.. or at least I thought they should be...
>
>
> No, one will be a list :-) putting a bunch of:
>
>  print(repr(foo))
>
> replacing "foo" with relevant variables will be illuminating to you; you can
> see immediately where this are not what you expected.
>
>> I'm obviously missing something fundamental here.  Problem is I can't
>> seem to find any examples of people asking this question before on the
>> inter-webs..
>
>
> You have the opposite of my problem. I can often find people asking the same
> question, but less often an answer. Or a decent answer, anyway.
>
> Cheers,
> Cameron Simpson <cs at cskk.id.au>

From steve at pearwood.info  Sat Sep  8 04:26:58 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Sat, 8 Sep 2018 18:26:58 +1000
Subject: [Tutor] Additionally
In-Reply-To: <CADUn+-+Xqjbg+CTziOWu+8Or_XVTu7KivqMLWhmr3xGdtd-BsA@mail.gmail.com>
References: <CADUn+-Kg836iwHVNasg5o-j_61V6NxA7WNPFg57QKh2wJGM+Ag@mail.gmail.com>
 <20180908020504.GH27312@ando.pearwood.info>
 <CADUn+-+Xqjbg+CTziOWu+8Or_XVTu7KivqMLWhmr3xGdtd-BsA@mail.gmail.com>
Message-ID: <20180908082658.GI27312@ando.pearwood.info>

On Fri, Sep 07, 2018 at 10:16:38PM -0400, Chip Wachob wrote:
> Thank you.
> 
> I sent a message with the contents of both previous messages.
> 
> Hopefully the admin can just delete the two previous messages
> 
> Thanks for bearing with me.  I'm used to posting on forum boards, not via email.

No problem. 

And if I come across as a bit short tempered, its because I'm suffering 
a lot of pain and discomfort at the moment due to illness. I'm trying 
not to let it show, but sometimes it might.


-- 
Steve


From cs at cskk.id.au  Sat Sep  8 06:01:48 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Sat, 8 Sep 2018 20:01:48 +1000
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <CADUn+-+vo_gKkHuTB3F6xZJSTSd+RHw3_TcoNBjhNbx_oxGt1w@mail.gmail.com>
References: <CADUn+-+vo_gKkHuTB3F6xZJSTSd+RHw3_TcoNBjhNbx_oxGt1w@mail.gmail.com>
Message-ID: <20180908100148.GA77175@cskk.homeip.net>

Please try to adopt the inline reply style; we prefer it here. It lets us reply 
point by point and makes messages read like conversations. Anyway...

On 07Sep2018 23:57, Chip Wachob <wachobc at gmail.com> wrote:
>Point taken on 'bytes'..  thanks.
>
>the
>scratch_ary = bytearray()
>
>was my attempt at 'setting' the type of the variable.  I had hoped
>that it would help resolve the error messages telling me that the
>types didn't go together.
>Coming from a 'C' background, I find the lack of typing in Python to
>be confusing.  I'm used to working with bytes / words signed and
>unsigned for a reason.

Ok. Variables aren't typed. Variables are references to objects, which _are_ 
typed. So pointing a variable at a bytearray doesn't set its type in any 
persistent sense.

Thus:

  x = 1
  x = "a string"
  x = bytearray()

All just point "x" at different objects. If you'd like a C metaphor, variables 
are _like_ (void*) pointers: they can reference any kind of object.

Aside: they're not pointers, avoid the term - people will complain. As far as 
the language spec goes they're references. Which may in a particular 
implementation be _implemented internally_ using pointers.

>So, if I'm understanding the transfer() function correctly, the
>function takes and returns a bytearray type.

It would be good to see the specification for the transfer function. They we 
can adhere to its requirements. Can you supply a URL?

>You mentioned about
>constructing a bytearray if I need one.  Can you expand on how I
>approach that?

Well, you were getting several bytes or bytearray objects back from transfer 
and wanted to join them together. The efficient way is to accumulate them in a 
list and then join them all together later using the bytearry (or bytes) .join 
method:

  https://docs.python.org/3/library/stdtypes.html#bytearray.join

So:

  data_list = []
  for ....
    # send some data, get some data back
    data = transfer(...)
    # add that buffer to the data_list
    data_list.append(data)
  # make a single bytes object being the concatenation of all the smaller data 
  # chunks
  all_data = bytes.join(data_list)

It looks to me like your transfer() function is handed a bytes or bytearray and 
returns one. Normally that would be a separate bytes or bytearray.

Aside: bytes and bytearray objects are generally the way Python 3 deals with 
chunks of bytes. A "bytes" is readonly and a bytearray may have its contents 
modified. From a C background, they're like an array of unsigned chars.

>I'm going to try the experiment you mentioned in hopes of it giving me
>a better understanding of the 'types' and what happens with the
>variables.

Sounds good.

Cheers,
Cameron Simpson <cs at cskk.id.au>

From alan.gauld at yahoo.co.uk  Sat Sep  8 06:13:19 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sat, 8 Sep 2018 11:13:19 +0100
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <CADUn+-+vo_gKkHuTB3F6xZJSTSd+RHw3_TcoNBjhNbx_oxGt1w@mail.gmail.com>
References: <CADUn+-LjZkwjsSi-ntP2eTa1YkarPrKoCDVGfu08EM+uT=ks1g@mail.gmail.com>
 <20180907222355.GA24273@cskk.homeip.net>
 <CADUn+-+vo_gKkHuTB3F6xZJSTSd+RHw3_TcoNBjhNbx_oxGt1w@mail.gmail.com>
Message-ID: <pn077t$eqe$1@blaine.gmane.org>

On 08/09/18 04:57, Chip Wachob wrote:

> was my attempt at 'setting' the type of the variable.  

A variable in Python is just a name. It has no type.
Only values have types. So you can set (or change)
the type of a value but not of a variable.

> Coming from a 'C' background, I find the lack of typing in Python to
> be confusing.  

There is no shortage of typing in Python its just
applied to the values(objects) not to their labels.

> I'm used to working with bytes / words signed and
> unsigned for a reason.

The same applies in Python. You just have to separate
the concepts of variable name and variable value.
In C those two concepts get kind of squished together
but in Python the name/value duality is strong.

You can always check the type of an object by using
the type() function or if you think a type error is
likely catch it when it happens with:

try:...
except TypeError:....


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From alan.gauld at yahoo.co.uk  Sat Sep  8 06:15:48 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sat, 8 Sep 2018 11:15:48 +0100
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <CADUn+-JMFjDMAyAYiwqSs5DOoh7rNtZmDWnbiWxEMTybLpzJnA@mail.gmail.com>
References: <CADUn+-JMFjDMAyAYiwqSs5DOoh7rNtZmDWnbiWxEMTybLpzJnA@mail.gmail.com>
Message-ID: <pn07ch$eqe$2@blaine.gmane.org>

On 08/09/18 03:15, Chip Wachob wrote:
> Admin, please remove my earlier messages.

No can do, once the emails are sent by the server
they are out there on the net, stored in people's
mailboxes and in various internet archives.

When using a mailing list always check before
sending, there's no going back...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From alan.gauld at yahoo.co.uk  Sat Sep  8 06:40:55 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sat, 8 Sep 2018 11:40:55 +0100
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <CADUn+-JMFjDMAyAYiwqSs5DOoh7rNtZmDWnbiWxEMTybLpzJnA@mail.gmail.com>
References: <CADUn+-JMFjDMAyAYiwqSs5DOoh7rNtZmDWnbiWxEMTybLpzJnA@mail.gmail.com>
Message-ID: <pn08rk$uc5$1@blaine.gmane.org>

On 08/09/18 03:15, Chip Wachob wrote:

> my function's main pieces are:

It would probably be better to post the entire function,
a partial code sample like this just gives us an inkling
of what you are trying to do but not enough to be sure
of where the errors lie.

> def transfer_byte_array():
>    MAX_LOOP_COUNT = 64
>    slice_size = 16
>    read_ary = bytearray(MAX_LOOP_COUNT)
>    scratch_ary = bytearray()
> 
>    for step in range (0, MAX_LOOP_COUNT, slice_size):
>       scratch_ary = transfer(data_to_send, slice_size)

You pass in two arguments here but in your description
of transfer below it is a method of an object that
only takes one (self being the object). Something is
broken here.

I would expect, given the code below, to see something
like
        scratch_ary = someObject.transfer(data_to_send)

>       for bytes in range (0, slice_size):
>          read_ary = scratch_ary[bytes]

This is replacing rad_ary each time with a single value from scratch_ary.
At the end of theloop read_ary wil;l cpontain the last valuye in
scratch_ary. You can achieve the same result without a loop:

raed_ary = scratch_ary[-1]

But I suspect that's not what you want.
I think what you really want is the first
slice_size elements of scratch_ary:

read_ary = scratch_ary[:slice_size]   # use slicing

> Ideally, I'd like to take the slice_size chunks that have been read
> and concatenate them back togetjer into a long MAX_LOOP_COUNT size
> array to pass back to the rest of my code.  Eg:

You need to create a list of read_ary

results = []

then after creating each read_ary value append it
to results.

results.append(read_ary)

Then, at the very end, return the summation of all
the lists in results.

return sum(results,[])

>     def transfer(self, data):

The self parameter indicates that this is a method
definition from a class. That implies that to use
it you must create an instance of the class and
call the method on that instance.

HTH

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From cs at cskk.id.au  Sat Sep  8 06:49:45 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Sat, 8 Sep 2018 20:49:45 +1000
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <20180908100148.GA77175@cskk.homeip.net>
References: <20180908100148.GA77175@cskk.homeip.net>
Message-ID: <20180908104945.GA75660@cskk.homeip.net>

On 08Sep2018 20:01, Cameron Simpson <cs at cskk.id.au> wrote:
>>So, if I'm understanding the transfer() function correctly, the
>>function takes and returns a bytearray type.
>
>It would be good to see the specification for the transfer function. 
>They we can adhere to its requirements. Can you supply a URL?

I see you supplied the whole transfer function in your first message :-(

I'll recite it here and walk through its contents to explain:

    def transfer(self, data):

Ok, this is a method, a particular type of function associated with a class 
instance. (All objects are class instances, and the class is their type.)

So to call this you would normally have a control object of some kind. [...] 
Ah, it looks like you should have an SpiDev instance, inferring from this code:

  https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/SPI.py

So suppose you've got such an object and a variable referring to it, let's say 
it is named "spi". You'd normally call the transfer function like this:

  spi.transfer(some_data)

instead of calling transfer() "bare", as it were.

When you call a Python method, the instance itself is implicitly passed as the 
parameter "self" (well, the first parameter - in Python we always call this 
"self" like C++ uses "this").

        """Full-duplex SPI read and write.  The specified array of bytes will be
        clocked out the MOSI line, while simultaneously bytes will be read from
        the MISO line.  Read bytes will be returned as a bytearray object.
        """

This is a docstring. It is like a comment but it gets attached to the function 
and can be inspected. Not your problem.

        # Build command to read and write SPI data.
        command = 0x30 | (self.lsbfirst << 3) | (self.read_clock_ve << 2) | self.write_clock_ve

This constructs a value just as you would in C.

        logger.debug('SPI transfer with command {0:2X}.'.format(command))

Write a debugging message.

        # Compute length low and high bytes.
        # NOTE: Must actually send length minus one because the MPSSE engine
        # considers 0 a length of 1 and FFFF a length of 65536
        length = len(data)
        len_low  = (length-1) & 0xFF
        len_high = ((length-1) >> 8) & 0xFF

All just like C.

        # Send command and length.
        self._assert_cs()

I would guess that this raises a control signal. Ah, RS-232? So clear-to-send 
then.

        self._ft232h._write(str(bytearray((command, len_low, len_high))))

Ok, it looks like this is Python 2, not Python 3. Let's unpack it.

"(command, len_low, len_high)" is a tuple of 3 values. A tuple is like a read 
only list. We're passing that to the bytearray() constructor, which will accept 
an iterable of values and make a bytes buffer. And we want to write that to 
"self._ft232h". Which expects a str, which is why I think this is Python 2. In 
Python 2 there's no "bytes" type and str is an immutable array of 8-bit 
character values. So writing bytes uses str.

So this tabkes a tuple of values, to be bytes, makes those into a bytearray and 
makes that into a str, and writes that str to the serial line.

        self._ft232h._write(str(bytearray(data)))

We write that data itself.

        self._ft232h._write('\x87')
        self._deassert_cs()

And here we lower the control signal.

        # Read response bytes.
        return bytearray(self._ft232h._poll_read(length))

This calls the _poll_read method, presumably requesting "length" bytes, the 
same length as the supplied data. I presume we get a str back: we make a new 
bytearray with those bytes in it and return it.

So you do get a new bytearray back from each call, so we can accumulate them 
into a list and then join them together later to make a single bytearray.

Why this faffing about with str and bytearray? Probably for Python 2/3 
compatibility, and because you want to deal with bytes (small ints) instead of 
characters. Ignore it: we're dealing with bytes.

Cheers,
Cameron Simpson <cs at cskk.id.au>

From mats at wichmann.us  Sat Sep  8 18:26:41 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Sat, 8 Sep 2018 16:26:41 -0600
Subject: [Tutor] No module named uno in virtual environment
In-Reply-To: <pmupd4$r12$1@blaine.gmane.org>
References: <pmupd4$r12$1@blaine.gmane.org>
Message-ID: <79f0b3ec-e752-4186-b573-c2aff96fc060@wichmann.us>

On 09/07/2018 03:10 PM, Jim wrote:
> Mint 18.1
> System python3 3.5.2
> 
> Python3-uno is available to the system python3. How can I make it
> available to python 3.6.5 in a virtual environment I installed using venv?

with your virtualenv activated, just install it.

python -m pip install uno


From jf_byrnes at comcast.net  Sat Sep  8 19:46:46 2018
From: jf_byrnes at comcast.net (Jim)
Date: Sat, 8 Sep 2018 18:46:46 -0500
Subject: [Tutor] No module named uno in virtual environment
In-Reply-To: <79f0b3ec-e752-4186-b573-c2aff96fc060@wichmann.us>
References: <pmupd4$r12$1@blaine.gmane.org>
 <79f0b3ec-e752-4186-b573-c2aff96fc060@wichmann.us>
Message-ID: <pn1mt4$8lr$1@blaine.gmane.org>

On 09/08/2018 05:26 PM, Mats Wichmann wrote:
> On 09/07/2018 03:10 PM, Jim wrote:
>> Mint 18.1
>> System python3 3.5.2
>>
>> Python3-uno is available to the system python3. How can I make it
>> available to python 3.6.5 in a virtual environment I installed using venv?
> 
> with your virtualenv activated, just install it.
> 
> python -m pip install uno
> 

My bad, I did not explain what python3-uno does. It is a system package 
that lets python interact with libreoffice. The uno that pip installs is 
a html generator.

I used apt to install python3-uno on my system. System python3 can use 
it and the python 3.5 in one of my virtual environments can use it. 
Python 3.6 in my other virtual environment cannot access it.

So to re-phrase my question. Python3-uno is installed on my system what 
do I need to do to get python 3.6 in a virtual environment to use it?

Maybe I am missing something obvious. With all the advice given to use 
virtual environments I would think that this problem has come up, but 
googling did not produce a solution.

Regards,  Jim


From cs at cskk.id.au  Sat Sep  8 21:14:59 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Sun, 9 Sep 2018 11:14:59 +1000
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <pn08rk$uc5$1@blaine.gmane.org>
References: <pn08rk$uc5$1@blaine.gmane.org>
Message-ID: <20180909011459.GA22760@cskk.homeip.net>

On 08Sep2018 11:40, Alan Gauld <alan.gauld at yahoo.co.uk> wrote:
>On 08/09/18 03:15, Chip Wachob wrote:
>> Ideally, I'd like to take the slice_size chunks that have been read
>> and concatenate them back togetjer into a long MAX_LOOP_COUNT size
>> array to pass back to the rest of my code.  Eg:
>
>You need to create a list of read_ary
>
>results = []
>
>then after creating each read_ary value append it
>to results.
>
>results.append(read_ary)
>
>Then, at the very end, return the summation of all
>the lists in results.
>
>return sum(results,[])

Actually he's getting back bytearray instances from transfer and wants to join 
them up (his function does a few small transfers to work around an issue with 
one big transfer). His earlier code is just confused. So he wants:

  bytearray().join(results)

Hacked example:

  >>> bytearray().join( (bytearray("foo"),bytearray("bah")) )
  bytearray(b'foobah')

And he's working with bytearrays because the target library is Python 2, where 
there's no bytes type.

Cheers,
Cameron Simpson <cs at cskk.id.au>

From mats at wichmann.us  Sat Sep  8 21:35:30 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Sat, 08 Sep 2018 19:35:30 -0600
Subject: [Tutor] No module named uno in virtual environment
In-Reply-To: <pn1mt4$8lr$1@blaine.gmane.org>
References: <pmupd4$r12$1@blaine.gmane.org>
 <79f0b3ec-e752-4186-b573-c2aff96fc060@wichmann.us>
 <pn1mt4$8lr$1@blaine.gmane.org>
Message-ID: <2BD42920-A491-4D9B-B900-B101AF248F7D@wichmann.us>

On September 8, 2018 5:46:46 PM MDT, Jim <jf_byrnes at comcast.net> wrote:
>On 09/08/2018 05:26 PM, Mats Wichmann wrote:
>> On 09/07/2018 03:10 PM, Jim wrote:
>>> Mint 18.1
>>> System python3 3.5.2
>>>
>>> Python3-uno is available to the system python3. How can I make it
>>> available to python 3.6.5 in a virtual environment I installed using
>venv?
>> 
>> with your virtualenv activated, just install it.
>> 
>> python -m pip install uno
>> 
>
>My bad, I did not explain what python3-uno does. It is a system package
>
>that lets python interact with libreoffice. The uno that pip installs
>is 
>a html generator.
>
>I used apt to install python3-uno on my system. System python3 can use 
>it and the python 3.5 in one of my virtual environments can use it. 
>Python 3.6 in my other virtual environment cannot access it.
>
>So to re-phrase my question. Python3-uno is installed on my system what
>
>do I need to do to get python 3.6 in a virtual environment to use it?
>
>Maybe I am missing something obvious. With all the advice given to use 
>virtual environments I would think that this problem has come up, but 
>googling did not produce a solution.
>
>Regards,  Jim
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor

ok, awkward naming issue. try openoffice-python instead?
-- 
Sent from a mobile device with K-9 Mail. Please excuse my brevity.

From jf_byrnes at comcast.net  Sun Sep  9 12:49:21 2018
From: jf_byrnes at comcast.net (Jim)
Date: Sun, 9 Sep 2018 11:49:21 -0500
Subject: [Tutor] No module named uno in virtual environment
In-Reply-To: <2BD42920-A491-4D9B-B900-B101AF248F7D@wichmann.us>
References: <pmupd4$r12$1@blaine.gmane.org>
 <79f0b3ec-e752-4186-b573-c2aff96fc060@wichmann.us>
 <pn1mt4$8lr$1@blaine.gmane.org>
 <2BD42920-A491-4D9B-B900-B101AF248F7D@wichmann.us>
Message-ID: <pn3iqf$4ub$1@blaine.gmane.org>

On 09/08/2018 08:35 PM, Mats Wichmann wrote:
> On September 8, 2018 5:46:46 PM MDT, Jim <jf_byrnes at comcast.net> wrote:
>> On 09/08/2018 05:26 PM, Mats Wichmann wrote:
>>> On 09/07/2018 03:10 PM, Jim wrote:
>>>> Mint 18.1
>>>> System python3 3.5.2
>>>>
>>>> Python3-uno is available to the system python3. How can I make it
>>>> available to python 3.6.5 in a virtual environment I installed using
>> venv?
>>>
>>> with your virtualenv activated, just install it.
>>>
>>> python -m pip install uno
>>>
>>
>> My bad, I did not explain what python3-uno does. It is a system package
>>
>> that lets python interact with libreoffice. The uno that pip installs
>> is
>> a html generator.
>>
>> I used apt to install python3-uno on my system. System python3 can use
>> it and the python 3.5 in one of my virtual environments can use it.
>> Python 3.6 in my other virtual environment cannot access it.
>>
>> So to re-phrase my question. Python3-uno is installed on my system what
>>
>> do I need to do to get python 3.6 in a virtual environment to use it?
>>
>> Maybe I am missing something obvious. With all the advice given to use
>> virtual environments I would think that this problem has come up, but
>> googling did not produce a solution.
>>
>> Regards,  Jim
>>python

> 
> ok, awkward naming issue. try openoffice-python instead?
> 

Unfortunately it produces the same result, no module uno found. I think 
all of the packages on pipy need the uno module to be installed to function.

When I installed python3-uno using apt it was installed at 
/usr/lib/python3/dist-packages/uno.py. I have python 3.5 installed in a 
virtual environment and it can load the uno module.  I have python 3.6 
installed in virtual environment and it cannot load the uno module.

Ok, I think I have solved it. Looking at the site-packages folder in the 
3.5 virtual environment shows uno.py and unohelper.py. In the 3.6 
virtual environment they are missing. Simply putting a copy of them in 
the python3.6 site-packages folder allows me to import uno and run a 
program that depends on importing uno.

I don't know if they should have been put there when I installed the 3.6 
virtual environment or if I did something wrong when I installed it, but 
now it works.

Mats, thanks for all your help.

Regards,  Jim




From mats at wichmann.us  Sun Sep  9 14:29:07 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Sun, 9 Sep 2018 12:29:07 -0600
Subject: [Tutor] No module named uno in virtual environment
In-Reply-To: <pn3iqf$4ub$1@blaine.gmane.org>
References: <pmupd4$r12$1@blaine.gmane.org>
 <79f0b3ec-e752-4186-b573-c2aff96fc060@wichmann.us>
 <pn1mt4$8lr$1@blaine.gmane.org>
 <2BD42920-A491-4D9B-B900-B101AF248F7D@wichmann.us>
 <pn3iqf$4ub$1@blaine.gmane.org>
Message-ID: <53ddad1d-d6ec-71f7-d411-026e4ea27d6e@wichmann.us>

On 09/09/2018 10:49 AM, Jim wrote:

>> ok, awkward naming issue. try openoffice-python instead?
>>
> 
> Unfortunately it produces the same result, no module uno found. I think
> all of the packages on pipy need the uno module to be installed to
> function.
> 
> When I installed python3-uno using apt it was installed at
> /usr/lib/python3/dist-packages/uno.py. I have python 3.5 installed in a
> virtual environment and it can load the uno module.? I have python 3.6
> installed in virtual environment and it cannot load the uno module.
> 
> Ok, I think I have solved it. Looking at the site-packages folder in the
> 3.5 virtual environment shows uno.py and unohelper.py. In the 3.6
> virtual environment they are missing. Simply putting a copy of them in
> the python3.6 site-packages folder allows me to import uno and run a
> program that depends on importing uno.
> 
> I don't know if they should have been put there when I installed the 3.6
> virtual environment or if I did something wrong when I installed it, but
> now it works.
> 
> Mats, thanks for all your help.

Glad it works, but you've left me curious now.  On a Fedora system these
two files come from libreoffice-pyuno:

/usr/lib64/python3.6/site-packages/uno.py
/usr/lib64/python3.6/site-packages/unohelper.py

and I don't presently see any way they are going to make it into a
virtualenv that is *not* set up to grab the system site-packages (that
is, created with the --system-site-packages option), I'm not finding
anything in PyPi that looks like it can provide this. The package I
mentioned above certainly doesn't.

uno.py imports the binary (shared object) pyuno module, which is fine,
that one is located wherever the {open,libre}office install puts it - on
my system just before the import it has done:

  sys.path.append('/usr/lib64/libreoffice/program')

maybe your 3.5 virtualenv was created differently than your 3.6 one and
that's why you have it there?

meanwhile, this is looking to my untrained eye like a small hole.

From jf_byrnes at comcast.net  Sun Sep  9 15:38:15 2018
From: jf_byrnes at comcast.net (Jim)
Date: Sun, 9 Sep 2018 14:38:15 -0500
Subject: [Tutor] No module named uno in virtual environment
In-Reply-To: <53ddad1d-d6ec-71f7-d411-026e4ea27d6e@wichmann.us>
References: <pmupd4$r12$1@blaine.gmane.org>
 <79f0b3ec-e752-4186-b573-c2aff96fc060@wichmann.us>
 <pn1mt4$8lr$1@blaine.gmane.org>
 <2BD42920-A491-4D9B-B900-B101AF248F7D@wichmann.us>
 <pn3iqf$4ub$1@blaine.gmane.org>
 <53ddad1d-d6ec-71f7-d411-026e4ea27d6e@wichmann.us>
Message-ID: <pn3sn5$bnt$1@blaine.gmane.org>

On 09/09/2018 01:29 PM, Mats Wichmann wrote:
> On 09/09/2018 10:49 AM, Jim wrote:
> 
>>> ok, awkward naming issue. try openoffice-python instead?
>>>
>>
>> Unfortunately it produces the same result, no module uno found. I think
>> all of the packages on pipy need the uno module to be installed to
>> function.
>>
>> When I installed python3-uno using apt it was installed at
>> /usr/lib/python3/dist-packages/uno.py. I have python 3.5 installed in a
>> virtual environment and it can load the uno module.? I have python 3.6
>> installed in virtual environment and it cannot load the uno module.
>>
>> Ok, I think I have solved it. Looking at the site-packages folder in the
>> 3.5 virtual environment shows uno.py and unohelper.py. In the 3.6
>> virtual environment they are missing. Simply putting a copy of them in
>> the python3.6 site-packages folder allows me to import uno and run a
>> program that depends on importing uno.
>>
>> I don't know if they should have been put there when I installed the 3.6
>> virtual environment or if I did something wrong when I installed it, but
>> now it works.
>>
>> Mats, thanks for all your help.
> 
> Glad it works, but you've left me curious now.  On a Fedora system these
> two files come from libreoffice-pyuno:
> 
> /usr/lib64/python3.6/site-packages/uno.py
> /usr/lib64/python3.6/site-packages/unohelper.py
> 
> and I don't presently see any way they are going to make it into a
> virtualenv that is *not* set up to grab the system site-packages (that
> is, created with the --system-site-packages option), I'm not finding
> anything in PyPi that looks like it can provide this. The package I
> mentioned above certainly doesn't.
> 
> uno.py imports the binary (shared object) pyuno module, which is fine,
> that one is located wherever the {open,libre}office install puts it - on
> my system just before the import it has done:
> 
>    sys.path.append('/usr/lib64/libreoffice/program')
> 
> maybe your 3.5 virtualenv was created differently than your 3.6 one and
> that's why you have it there?
> 
> meanwhile, this is looking to my untrained eye like a small hole.

I am puzzled also. My memory isn't what it used to be but I think I 
created them the same way. Looking at the config files I see.

home = /usr/bin
include-system-site-packages = false
version = 3.5.2

and

home = /usr/bin
include-system-site-packages = false
version = 3.6.3

I don't know if it makes a difference or not, but python3.5 is the 
system default python3 and python3.6 was installed from 
LP-PPA-jonathonf-python-3.6/now and LP_PPA-jonathonf-python-3.6/xenial. 
Maybe the install script malfunctioned or was lacking some step. I may 
email jonathon to see if he has any ideas.

Regards,  Jim




From glennmschultz at me.com  Sun Sep  9 17:25:10 2018
From: glennmschultz at me.com (Glenn Schultz)
Date: Sun, 09 Sep 2018 21:25:10 +0000 (GMT)
Subject: [Tutor] building package on mac os
Message-ID: <c002c43c-62a8-410c-a0cd-66e6d1237de1@me.com>

I have a package that I am working on. ?I am using Pycharm. ?The directories are set up correctly. ?
In my frameworks I have
Python 2.7
Python 3.5
Python 3.6
Python 3.7
Current - which is Python 2.7

After navigating to the directory with the package I run the following in my terminal

python3 setup.py sdist bdist_wheel

This runs fine and it appears all is correct with no messages or warning. ?Then I go to the main user directory
and pip install directory/packagename

It appears the wheel installs in a private/var/ folder

if I change the statement to python3.6 pip install ?directory/packagename

I get an error 2 cannot find director. ?I need to change my current python to 3.6 and also figure out how to install the package. ?I have seen some instructions to edit the bash file but before I do this I would like to resolve the install issue

Glenn

From wachobc at gmail.com  Sun Sep  9 17:06:57 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Sun, 9 Sep 2018 17:06:57 -0400
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <20180908104945.GA75660@cskk.homeip.net>
References: <20180908100148.GA77175@cskk.homeip.net>
 <20180908104945.GA75660@cskk.homeip.net>
Message-ID: <CADUn+-K5Ws4OdOvu2orku3x+M8+x2m1OFXDcG6KgWbrs5abNrA@mail.gmail.com>

Cameron, et al.

First off, thank you for being patient with me.  I'm not used to the
email list communication style.

Since Cameron's response was the one that raised the most questions /
comments, I'm going to reply to it.

Inline.. now that I know that this is the preferred method...

Before I jump in, the 1000 foot view is I have to send an array of 512
bytes down the SPI loop, and read back 512 bytes that were latched in
from a control interface.  Unfortunately, there's a glitch in the FTDI
part and I can't just send the 512 bytes.. the part times out and and
causes the script to terminate early...  So, my solution was to
'chunk' the data into smaller groups which the part _can_ handle.
This works fine until I come to the point where I concatenate the
'chunks' into my 512 byte array..  which other functions will then
process.

The libraries that I'm using are from the project link below.  I'm
learning from all of you how much code to post, I didn't want to post
the entire library, but the way it's set up it is hard not to.. as has
been pointed out.. methods of classes and then there's other files
that contain some of the low-level workings..

https://github.com/adafruit/Adafruit_Python_GPIO

Anyhow, on with the 'show'..


On Sat, Sep 8, 2018 at 6:49 AM, Cameron Simpson <cs at cskk.id.au> wrote:
> On 08Sep2018 20:01, Cameron Simpson <cs at cskk.id.au> wrote:
>>>
>>> So, if I'm understanding the transfer() function correctly, the
>>> function takes and returns a bytearray type.
>>
>>
>> It would be good to see the specification for the transfer function. They
>> we can adhere to its requirements. Can you supply a URL?
>
>
> I see you supplied the whole transfer function in your first message :-(

Yes, I realize now that I left out important information.  I have my
own transfer function which is the supplied transfer function with a
bunch of GPIO wrapped around it, and the 'chunking'.  This way I can
call it when I need to send and receive data from the loop, which is
often.  In the end, I will have to talk with several different SPI
devices, all of which will have to have different GPIO line wiggling
going on before and after they call the spi.transfer.

You're walk-through is very helpful.

>
> I'll recite it here and walk through its contents to explain:
>
>    def transfer(self, data):
>
> Ok, this is a method, a particular type of function associated with a class
> instance. (All objects are class instances, and the class is their type.)
>
> So to call this you would normally have a control object of some kind. [...]
> Ah, it looks like you should have an SpiDev instance, inferring from this
> code:
>
>
> https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/SPI.py
>
> So suppose you've got such an object and a variable referring to it, let's
> say it is named "spi". You'd normally call the transfer function like this:
>
>  spi.transfer(some_data)
>
> instead of calling transfer() "bare", as it were.

Again, I was generalizing and also being somewhat lazy and not typing
it all... my bad.

>
> When you call a Python method, the instance itself is implicitly passed as
> the parameter "self" (well, the first parameter - in Python we always call
> this "self" like C++ uses "this").

Ah, the one 'thorn' in my side is "this".  I have considerable
difficulty with the 'this' concept.  That probably means that my code
could be 'better', but I tend to avoid "this" like the plague.

>
>        """Full-duplex SPI read and write.  The specified array of bytes will
> be
>        clocked out the MOSI line, while simultaneously bytes will be read
> from
>        the MISO line.  Read bytes will be returned as a bytearray object.
>        """
>
> This is a docstring. It is like a comment but it gets attached to the
> function and can be inspected. Not your problem.
>
>        # Build command to read and write SPI data.
>        command = 0x30 | (self.lsbfirst << 3) | (self.read_clock_ve << 2) |
> self.write_clock_ve
>
> This constructs a value just as you would in C.
>
>        logger.debug('SPI transfer with command {0:2X}.'.format(command))
>
> Write a debugging message.

I saw this, but I don't know how to turn it 'on' so I could see the
log messages.  I wouldn't mind doing this with my code as well.
Perhaps creating my own log?  Right now, I have a verbose flag that I
pass to all my functions.. called disp.  Then for each place where I
want to see a value, etc, I have a line that reads:  if(disp): print "
What data is this ", data

>
>        # Compute length low and high bytes.
>        # NOTE: Must actually send length minus one because the MPSSE engine
>        # considers 0 a length of 1 and FFFF a length of 65536
>        length = len(data)
>        len_low  = (length-1) & 0xFF
>        len_high = ((length-1) >> 8) & 0xFF
>
> All just like C.
>
>        # Send command and length.
>        self._assert_cs()
>
> I would guess that this raises a control signal. Ah, RS-232? So
> clear-to-send then.

This is actually a chip select line that electrically wiggles a pin on
a device telling it 'Hey, I'm talking to YOU".

>
>        self._ft232h._write(str(bytearray((command, len_low, len_high))))
>
> Ok, it looks like this is Python 2, not Python 3. Let's unpack it.

Yes, Adafruit insists that this work has to be done in Python 2.7.  I
started working on this and tried to use Python 3.x but things were
failing all over the place.  Unfortunately, at the time I didn't
understand that Python 3 wasn't backward compatible with Python 2.x,
1.x, etc..  Lesson learned.

>
> "(command, len_low, len_high)" is a tuple of 3 values. A tuple is like a
> read only list. We're passing that to the bytearray() constructor, which
> will accept an iterable of values and make a bytes buffer. And we want to
> write that to "self._ft232h". Which expects a str, which is why I think this
> is Python 2. In Python 2 there's no "bytes" type and str is an immutable
> array of 8-bit character values. So writing bytes uses str.

Okay, so in Python 2 (the world I'm left to live within) if I want to
handle bytes, they actually have to be strings?  This sort of makes
sense.  When I try to display the contents of my arrays via a print
statement, I will get \xnn for my values, but at some point the nn
becomes what appears to be ASCII characters.  Sometimes I get, what I
would call, extended ASCII 'art' when I try to print the arrays.
Interesting art, but not very helpful in the information department.

>
> So this tabkes a tuple of values, to be bytes, makes those into a bytearray
> and makes that into a str, and writes that str to the serial line.
>
>        self._ft232h._write(str(bytearray(data)))
>
> We write that data itself.
>
>        self._ft232h._write('\x87')
>        self._deassert_cs()
>
> And here we lower the control signal.
>
>        # Read response bytes.
>        return bytearray(self._ft232h._poll_read(length))
>
> This calls the _poll_read method, presumably requesting "length" bytes, the
> same length as the supplied data. I presume we get a str back: we make a new
> bytearray with those bytes in it and return it.
>
> So you do get a new bytearray back from each call, so we can accumulate them
> into a list and then join them together later to make a single bytearray.

faffing is a new term, but given the context I'm guessing it is
equivalent to 'mucking about' or more colorful wording which I won't
even attempt to publish here.

>
> Why this faffing about with str and bytearray? Probably for Python 2/3
> compatibility, and because you want to deal with bytes (small ints) instead
> of characters. Ignore it: we're dealing with bytes.

More questions in the next installment since the reconstruction
methods are discussed there..

>
> Cheers,
> Cameron Simpson <cs at cskk.id.au>

Thank you all.

From cs at cskk.id.au  Mon Sep 10 01:21:13 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Mon, 10 Sep 2018 15:21:13 +1000
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <CADUn+-K5Ws4OdOvu2orku3x+M8+x2m1OFXDcG6KgWbrs5abNrA@mail.gmail.com>
References: <CADUn+-K5Ws4OdOvu2orku3x+M8+x2m1OFXDcG6KgWbrs5abNrA@mail.gmail.com>
Message-ID: <20180910052113.GA49101@cskk.homeip.net>

On 09Sep2018 17:06, Chip Wachob <wachobc at gmail.com> wrote:
>Before I jump in, the 1000 foot view is I have to send an array of 512
>bytes down the SPI loop, and read back 512 bytes that were latched in
>from a control interface.  Unfortunately, there's a glitch in the FTDI
>part and I can't just send the 512 bytes.. the part times out and and
>causes the script to terminate early...  So, my solution was to
>'chunk' the data into smaller groups which the part _can_ handle.
>This works fine until I come to the point where I concatenate the
>'chunks' into my 512 byte array..  which other functions will then
>process.

Sounds good to me.

>The libraries that I'm using are from the project link below.  I'm
>learning from all of you how much code to post, I didn't want to post
>the entire library, but the way it's set up it is hard not to.. as has
>been pointed out.. methods of classes and then there's other files
>that contain some of the low-level workings..
>
>https://github.com/adafruit/Adafruit_Python_GPIO

Thanks.

>Yes, I realize now that I left out important information.  I have my
>own transfer function which is the supplied transfer function with a
>bunch of GPIO wrapped around it, and the 'chunking'.  This way I can
>call it when I need to send and receive data from the loop, which is
>often.  In the end, I will have to talk with several different SPI
>devices, all of which will have to have different GPIO line wiggling
>going on before and after they call the spi.transfer.
[...]
>>    def transfer(self, data):
>> Ok, this is a method, a particular type of function associated with a class
>> instance. (All objects are class instances, and the class is their type.)
>>
>> So to call this you would normally have a control object of some kind. [...]
>> Ah, it looks like you should have an SpiDev instance, inferring from this
>> code:
>> https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/SPI.py
>>
>> So suppose you've got such an object and a variable referring to it, let's
>> say it is named "spi". You'd normally call the transfer function like this:
>>  spi.transfer(some_data)
[...]
>> When you call a Python method, the instance itself is implicitly passed as
>> the parameter "self" (well, the first parameter - in Python we always call
>> this "self" like C++ uses "this").
>
>Ah, the one 'thorn' in my side is "this".  I have considerable
>difficulty with the 'this' concept.  That probably means that my code
>could be 'better', but I tend to avoid "this" like the plague.

It isn't as big a deal as you might imagine. An object method essentially gets 
the object as a piece of context. So a method call like this:

  spi.transfer(data)

just has the "spi" object available within the method for use, for example is 
probably is already set up with all the hardware access you're going to make 
use of.


So lower down in the function, when it 
goes:

  self._ft232h._write(str(bytearray(data)))

all you're doing is making use of the already initialised _ft232h object to do 
the write, and that comes along with the "spi" object you called the transfer 
method through.

So from your point of view it's just context for the transfer function.

>>        logger.debug('SPI transfer with command {0:2X}.'.format(command))
>>
>> Write a debugging message.
>
>I saw this, but I don't know how to turn it 'on' so I could see the
>log messages.  I wouldn't mind doing this with my code as well.
>Perhaps creating my own log?  Right now, I have a verbose flag that I
>pass to all my functions.. called disp.  Then for each place where I
>want to see a value, etc, I have a line that reads:  if(disp): print "
>What data is this ", data

Ah, logging. Yes, it is probably worth learning a little about, just to hook it 
it. You can at least get away from passing your "disp" variable around - just 
call the right logging call (warning, info, debug, error etc) and tune which 
messages get out from your main programme.

The logging module is documented here:

  https://docs.python.org/2.7/library/logging.html#module-logging

So your main programme would set up the logging, including a logging level. The 
module comes with five predefined levels from DEBUG through to CRITICAL. Then 
in your code you write messages like the debug one above. When you're debugging 
you might set the systems level to DEBUG and see heaps of messages, or INFO to 
see progress reporting, or WARNING to just see when things go wrong. Then your 
code just writes messages are a suitable level and the global setting controls 
which ones get out.

All you really need to do is "import logging" and then just call 
"logging.warning" or "logging.debug" etc. There's a tutorial here:

  https://docs.python.org/2.7/howto/logging.html#logging-basic-tutorial

Get off the ground like that and return to your main programme. The whole 
logging system can be rather complicated if you get sucked into learning it 
thoroughly.

[...]
>>        # Send command and length.
>>        self._assert_cs()
>> I would guess that this raises a control signal. Ah, RS-232? So
>> clear-to-send then.
>
>This is actually a chip select line that electrically wiggles a pin on
>a device telling it 'Hey, I'm talking to YOU".

Ah, hence the "assert". Ok, thanks.

>>        self._ft232h._write(str(bytearray((command, len_low, len_high))))
>>
>> Ok, it looks like this is Python 2, not Python 3. Let's unpack it.
>
>Yes, Adafruit insists that this work has to be done in Python 2.7.  I
>started working on this and tried to use Python 3.x but things were
>failing all over the place.  Unfortunately, at the time I didn't
>understand that Python 3 wasn't backward compatible with Python 2.x,
>1.x, etc..  Lesson learned.

Python 3 was the big break to the language to make a swathe of changes which 
broke backward compatibility, all for the good as far as I can see. Previous to 
that changes worked hard to remain backward compatible and not break code. The 
idea with Python 3 was to make several breaking changes which had been bubbling 
away for years, and hopefully never make that break again in future.

Bytes versus strings versus unicode was a big change with Python 2/3, and code 
working at the hardware levewl like your tends to notice it. So the library is 
working with bytearrays (because Python 2 and 3 have them and they look like 
buffers of bytes) but still having to convert these into str to write them to 
"files".

In Python 2 the "str" type is 8 bit characters (or no specified character set, 
btw) that look like characters (yea, even unto characters really just being 
strings of length 1) and there's a separate "unicode" type for decent strings 
which support Unicode text.

In Python 3 "str" is Unicode, and there's a bytes types for bytes, which looks 
like a list if integers with values 0..255.

>> "(command, len_low, len_high)" is a tuple of 3 values. A tuple is like a
>> read only list. We're passing that to the bytearray() constructor, which
>> will accept an iterable of values and make a bytes buffer. And we want to
>> write that to "self._ft232h". Which expects a str, which is why I think this
>> is Python 2. In Python 2 there's no "bytes" type and str is an immutable
>> array of 8-bit character values. So writing bytes uses str.
>
>Okay, so in Python 2 (the world I'm left to live within) if I want to
>handle bytes, they actually have to be strings?  This sort of makes
>sense.

Well, yes and no. File I/O .write methods tend to accept str. Which is 8-bit 
character values, so you can use them for bytes. Thing genuinely using bytes 
(as small integers, as you do when assemble a flags value etc) can get by with 
bytearrays, which look like arrays of bytes (because they are).

But for historic reasons these interfaces will be writing "str" because that's 
what they expect to get.

>When I try to display the contents of my arrays via a print
>statement, I will get \xnn for my values, but at some point the nn
>becomes what appears to be ASCII characters.  Sometimes I get, what I
>would call, extended ASCII 'art' when I try to print the arrays.
>Interesting art, but not very helpful in the information department.

Yeah, not so great. Python's trying to be slightly nice here. Values with 
printable ASCII correspondents get prints as that character and other values 
get the \xnn treatment. Handy if you're working with text (because many many 
character sets has the 128 ASCII values as their lower portion, so this is 
usually not insane), less handy for nontext.

Try importing the hexlify function from the binascii module:

  from binascii import hexlify
  bs = bytearray( (1,2,3,65,66) )
  print(repr(bs))
  print(hexlify(bs))

[...]
>faffing is a new term, but given the context I'm guessing it is
>equivalent to 'mucking about' or more colorful wording which I won't
>even attempt to publish here.

You are correct:

https://en.wikipedia.org/wiki/Glossary_of_British_terms_not_widely_used_in_the_United_States#F

>> Why this faffing about with str and bytearray? Probably for Python 2/3
>> compatibility, and because you want to deal with bytes (small ints) instead
>> of characters. Ignore it: we're dealing with bytes.
>
>More questions in the next installment since the reconstruction
>methods are discussed there..

Excellent.

Cheers,
Cameron Simpson <cs at cskk.id.au>

From wachobc at gmail.com  Sun Sep  9 23:00:45 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Sun, 9 Sep 2018 23:00:45 -0400
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <20180909011459.GA22760@cskk.homeip.net>
References: <pn08rk$uc5$1@blaine.gmane.org>
 <20180909011459.GA22760@cskk.homeip.net>
Message-ID: <CADUn+-JWPbpjyiCmnQdBmw32TUHEssVKsptrL-igXLcn0enkNA@mail.gmail.com>

On Sat, Sep 8, 2018 at 9:14 PM, Cameron Simpson <cs at cskk.id.au> wrote:
> On 08Sep2018 11:40, Alan Gauld <alan.gauld at yahoo.co.uk> wrote:
>>
>> On 08/09/18 03:15, Chip Wachob wrote:
>>>
>>> Ideally, I'd like to take the slice_size chunks that have been read
>>> and concatenate them back togetjer into a long MAX_LOOP_COUNT size
>>> array to pass back to the rest of my code.  Eg:
>>
>>
>> You need to create a list of read_ary
>>
>> results = []
>>
>> then after creating each read_ary value append it
>> to results.
>>
>> results.append(read_ary)
>>
>> Then, at the very end, return the summation of all
>> the lists in results.
>>
>> return sum(results,[])
>

Cameron is correct (Gold Star for you Cameron)

>
> Actually he's getting back bytearray instances from transfer and wants to
> join them up (his function does a few small transfers to work around an
> issue with one big transfer). His earlier code is just confused. So he
> wants:
>
>  bytearray().join(results)
>
> Hacked example:
>
>  >>> bytearray().join( (bytearray("foo"),bytearray("bah")) )
>  bytearray(b'foobah')

I understand this example and I can replicate it in the interpreter..

But, I'm still missing something here.

I presume that I need to instantiate an array of slice_size-sized bytearrays.

So, when I'm looping through, I can do:

for i in range (0, slice_count):
   results[i] = spi.transfer(data_out)

Then I can :

all_together = butearray().join(results)

But I can't seem to be able to find the proper syntax to create the
initial array.

And any attempt at filling the arrays to test some stand-alone code
only give me errors.

Here's my code (all of it)

#
#
#

import sys

slice_size = 16    # in bytes
MAX_LOOP_COUNT = 64    # in bytes

slice_count = MAX_LOOP_COUNT / slice_size

print " slice size = ", slice_size
print " MLC = ", MAX_LOOP_COUNT
print " slice count = ", slice_count

#results = bytearray( (bytearray(slice_size)*slice_count) )
results = bytearray(slice_size)    # why isn't this 16 bytes long?

res_list = (results)*slice_count

print " results ", [results]
print " results size ", sys.getsizeof(results)
print " res_list ", [res_list]
print " res_list size ", sys.getsizeof(res_list)
print " type = ", type(results)

results[0] = ([1,3,5,7,9])

all_together = bytearray().join(results)

But I'm getting:

$ python merge_1.py
 slice size =  16
 MLC =  64
 slice count =  4
 results  [bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')]
 results size  65
 res_list  [bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')]
 res_list size  113
 type =  <type 'bytearray'>
Traceback (most recent call last):
  File "merge_1.py", line 27, in <module>
    results[0] = ([1,3,5,7,9])
TypeError: an integer or string of size 1 is required

Again, I feel like I'm circling the target, but not able to divine the
proper syntax

I hope this makes sense.


>
> And he's working with bytearrays because the target library is Python 2,
> where there's no bytes type.
>
> Cheers,
> Cameron Simpson <cs at cskk.id.au>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From cs at cskk.id.au  Mon Sep 10 05:22:01 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Mon, 10 Sep 2018 19:22:01 +1000
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <CADUn+-JWPbpjyiCmnQdBmw32TUHEssVKsptrL-igXLcn0enkNA@mail.gmail.com>
References: <CADUn+-JWPbpjyiCmnQdBmw32TUHEssVKsptrL-igXLcn0enkNA@mail.gmail.com>
Message-ID: <20180910092201.GA56239@cskk.homeip.net>

On 09Sep2018 23:00, Chip Wachob <wachobc at gmail.com> wrote:
>On Sat, Sep 8, 2018 at 9:14 PM, Cameron Simpson <cs at cskk.id.au> wrote:
>> Actually he's getting back bytearray instances from transfer and wants to
>> join them up (his function does a few small transfers to work around an
>> issue with one big transfer). His earlier code is just confused. So he
>> wants:
>>
>>  bytearray().join(results)
>>
>> Hacked example:
>>
>>  >>> bytearray().join( (bytearray("foo"),bytearray("bah")) )
>>  bytearray(b'foobah')
>
>I understand this example and I can replicate it in the interpreter..
>
>But, I'm still missing something here.
>I presume that I need to instantiate an array of slice_size-sized bytearrays.

But no!

>So, when I'm looping through, I can do:
>for i in range (0, slice_count):
>   results[i] = spi.transfer(data_out)

Python lists are a variable size data structure, so our example goess:

  results = []

which allocates an empty list. Then:

  for i in range(slice_count):
    results.append(spi.transfer(data_out))

suitably adjusted (data_out will be different pieces of the larger data, yes?) 
which grows the array by one item with each append. Your spi.transfer function 
allocates a new bytearray for each return value, so you end up with a list of 
distinct bytearrays.

>Then I can :
>
>all_together = butearray().join(results)

Yes.

>But I can't seem to be able to find the proper syntax to create the
>initial array.
>And any attempt at filling the arrays to test some stand-alone code
>only give me errors.

You _can_ allocate a presized list, but there's almost no benefit and it isn't 
what people normally do.

>Here's my code (all of it)
[...]
>#results = bytearray( (bytearray(slice_size)*slice_count) )
>results = bytearray(slice_size)    # why isn't this 16 bytes long?

It is 16 bytes long when I do it:

    >>> bs=bytearray(16)
    >>> bs
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')

>res_list = (results)*slice_count

This is a single 64 byte bytearray. You may have intended to make a single 
element tuple with "(results)", but that is just the same as "results" 
(rundundant brackets). To make a single element tuple you go "(results,)" - see 
the trailing comma?

Example of each:

    >>> bs*16
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
    >>> (bs,)*16
    (bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'), 
    bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'))

But you don't need any of that.

First, the list "results" can start empty and just get things appended to it 
and second, you don't need to preallocate any bytearrays because the internal, 
primary, transfer allocates a new bytearray for each return chunk.

Cheers,
Cameron Simpson <cs at cskk.id.au>

From alan.gauld at yahoo.co.uk  Mon Sep 10 06:44:05 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 10 Sep 2018 11:44:05 +0100
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <CADUn+-JWPbpjyiCmnQdBmw32TUHEssVKsptrL-igXLcn0enkNA@mail.gmail.com>
References: <pn08rk$uc5$1@blaine.gmane.org>
 <20180909011459.GA22760@cskk.homeip.net>
 <CADUn+-JWPbpjyiCmnQdBmw32TUHEssVKsptrL-igXLcn0enkNA@mail.gmail.com>
Message-ID: <pn5hpi$g89$1@blaine.gmane.org>

On 10/09/18 04:00, Chip Wachob wrote:

> I presume that I need to instantiate an array of slice_size-sized bytearrays.

Cameron has already addressed this and explained
that you don't need to and if you did how to do it.

I'd only add that you need to readjust your thinking
when it comes to Python data structures versus C.
In C data structures are very primitive (little more
than an allocated chunk of memory).

In Python data structures are extremely rich and indeed
much of Python's power comes from exploiting the
richness of the standard data structures. It is well
worth while just playing around with these in the >>>
prompt using dir() and help() to explore all of the
functionality embodied in strings, lists, tuples,
sets and dictionaries.


> And any attempt at filling the arrays to test some stand-alone code
> only give me errors.

There are several ways of doing this and Cameron
showed you a couple. There is another option which
is very powerful, especially for generating more
complex data sets. Its called a generator expression
and the most commonly used version is a list
comprehension:

new_list = [expression for item in collection if condition]

The expression can be any valid Python expression.
The condition can be any valid Python expression that
evaluates to a boolean result (and is also optional).

It is equivalent to:

new_list = []
for item in collection:
   if condition:
      new_list.append(expression)


Some examples to clarify:

num_list = [num for num in range(5)]

which is the same result as

numlist = list(range(5))

odds = [num for num in range(5) if num % 2] ->[1,3]

evens = [num for num in range(5) if num %2 == 0] -> [0,2,4]

squares = [num*num for num in range(5)]

odd_squares = [n*n for n in odds]

You can make them as complex as you like by
creating helper functions too:

fancy_list = [func1(n) for n in my_data if func2(n)]

The syntax can look a little confusing at first
(its somewhat like set notation) but once you
get used to it its OK.


> results = bytearray(slice_size)    # why isn't this 16 bytes long?

It is for me.

> res_list = (results)*slice_count

And this is 64 bytes long

> print " results ", [results]

And this prints a list with a single, 16 byte, bytearray inside it.

> print " results size ", sys.getsizeof(results)

This prints(on my system) 65 which may be confusing you.
But remember what I said about Python data structures
being rich, the bytearray has more than just the raw data
in it. The size reflects allthe other stuff that Python
uses to create a bytearray object. Try

>>> sys.getsizeof("")

and

>>> sys.getsizeof(bytearray())
>>> sys.getsizeof(bytearray("1"))
>>> sys.getsizeof(bytearray("12"))

Do the results surprize you?

Remember, Python data structures are not just chunks of memory.

> print " res_list ", [res_list]

Note that you are putting res_list into a list here,
but it is already a bytearray... There is no adavantage
in enclosing it in a list.

> Again, I feel like I'm circling the target, but not able to divine the
> proper syntax

Its not so much the syntax but your mental model
of what's going on under the covers. It's not C
(at least not at the first level down).

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From steve at pearwood.info  Mon Sep 10 07:51:17 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Mon, 10 Sep 2018 21:51:17 +1000
Subject: [Tutor] building package on mac os
In-Reply-To: <c002c43c-62a8-410c-a0cd-66e6d1237de1@me.com>
References: <c002c43c-62a8-410c-a0cd-66e6d1237de1@me.com>
Message-ID: <20180910115116.GW27312@ando.pearwood.info>

Hi Glenn,

Sorry, I don't think many people here are experts on building packages, 
especially on MacOS. You could try the "Python-List" mailing list as 
well.

I know I can't do more than offer a few vague, general questions which 
may or may not point you in the right direction. See below.

On Sun, Sep 09, 2018 at 09:25:10PM +0000, Glenn Schultz via Tutor wrote:

> I have a package that I am working on. ?I am using Pycharm. ?The 
> directories are set up correctly. ?
> In my frameworks I have
> Python 2.7
> Python 3.5
> Python 3.6
> Python 3.7
> Current - which is Python 2.7
> 
> After navigating to the directory with the package I run the following in 
> my terminal
> 
> python3 setup.py sdist bdist_wheel
> 
> This runs fine and it appears all is correct with no messages or warning. 

Are you running that command as the root user, as a priviledged user 
with elevated permissions, or an ordinary user?

After you run, where is the package installed?

You have three different Python 3.x versions, which one does python3 
run?


[steve at ando ~]$ which python3
/usr/local/bin/python3

[steve at ando ~]$ python3 --version
Python 3.3.0rc3


>?Then I go to the main user directory
> and pip install directory/packagename

What is the main user directory?

Which user are you running pip as? What version of Python does that pip 
work with?

[steve at ando ~]$ pip --version
pip 8.1.2 from /usr/local/lib/python2.7/site-packages (python 2.7)

So on my system, "pip" with no given version number relies on Python 
2.7. If your system is the same, then you're running setup using Python 
3 and pip with Python 2, and I have no idea whether or not that will 
work.

> It appears the wheel installs in a private/var/ folder

What do you mean by "a private/var/ folder"? It would help if you state 
the actual path, rather than something that looks like a fake path. If 
you want to obfuscate the username, you may change it to something 
generic like "fred":

    # real path with amusing Monty Python reference
    /home/biggusdickus/.somethingprivate/var/packages

    # more professional sounding path
    /home/fred/.somethingprivate/var/packages

for example.


> if I change the statement to python3.6 pip install ?directory/packagename
> 
> I get an error 2 cannot find director.


Can you copy and paste the full error message? Are you sure that it 
cannot find *director*, or is it *directory*?


>?I need to change my current python 
> to 3.6 and also figure out how to install the package. ?I have seen some 
> instructions to edit the bash file but before I do this I would like to 
> resolve the install issue

What does your OS expect "python" to point to? It is dangerous to change 
the system-wide "python" unless you really know what you are doing.

It should be harmless to use an alias as an ordinary user. Under bash, 
you can test it in a shell like this:

    # check that python3.6 does points where you expect
    which python3.6

    # and if so, run this
    alias python='python3.6'

    # now confirm python points to Python 3.6
    which python


When you are satisfied that works, you can make it permanent by editing 
your .bashrc file (under your home directory) and inserting that alias 
line. The alias will take effect in any new shells you open (but not 
existing shells).


Hope this was helpful.



-- 
Steve

From mats at wichmann.us  Mon Sep 10 08:57:38 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Mon, 10 Sep 2018 06:57:38 -0600
Subject: [Tutor] building package on mac os
In-Reply-To: <20180910115116.GW27312@ando.pearwood.info>
References: <c002c43c-62a8-410c-a0cd-66e6d1237de1@me.com>
 <20180910115116.GW27312@ando.pearwood.info>
Message-ID: <db8da49e-1222-be64-0e83-93eb3fda2bb2@wichmann.us>

On 09/10/2018 05:51 AM, Steven D'Aprano wrote:
> Hi Glenn,
> 
> Sorry, I don't think many people here are experts on building packages, 
> especially on MacOS. You could try the "Python-List" mailing list as 
> well.
> 
> I know I can't do more than offer a few vague, general questions which 
> may or may not point you in the right direction. See below.
> 
> On Sun, Sep 09, 2018 at 09:25:10PM +0000, Glenn Schultz via Tutor wrote:
> 
>> I have a package that I am working on. ?I am using Pycharm. ?The 
>> directories are set up correctly. ?
>> In my frameworks I have
>> Python 2.7
>> Python 3.5
>> Python 3.6
>> Python 3.7
>> Current - which is Python 2.7
>>
>> After navigating to the directory with the package I run the following in 
>> my terminal

echoing Steven... PyCharm has some support for package construction, but
I've never used it; if the problem is particular to that environment,
there may be some help available on their forums.

>>
>> python3 setup.py sdist bdist_wheel
>>
>> This runs fine and it appears all is correct with no messages or warning. 
> 
> Are you running that command as the root user, as a priviledged user 
> with elevated permissions, or an ordinary user?
> 
> After you run, where is the package installed?
> 
> You have three different Python 3.x versions, which one does python3 
> run?
> 
> 
> [steve at ando ~]$ which python3
> /usr/local/bin/python3
> 
> [steve at ando ~]$ python3 --version
> Python 3.3.0rc3
> 
> 
>> ?Then I go to the main user directory
>> and pip install directory/packagename
> 
> What is the main user directory?
> 
> Which user are you running pip as? What version of Python does that pip 
> work with?
> 
> [steve at ando ~]$ pip --version
> pip 8.1.2 from /usr/local/lib/python2.7/site-packages (python 2.7)
> 
> So on my system, "pip" with no given version number relies on Python 
> 2.7. If your system is the same, then you're running setup using Python 
> 3 and pip with Python 2, and I have no idea whether or not that will 
> work.

Indeed this is why the recommendation these days is to install as

  python -m pip install

instead of standalone

  pip install

... that way the pip is sure to match the python, for when you're using
a particular virtualenv, etc.


> 
>> It appears the wheel installs in a private/var/ folder

Just a thought: wheels are /cached/, if that's what you meant... so if
you repeat an operation it doesn't have to be re-fetched. On Linux that
is often $HOME/.cache/pip, although it can vary.


> What do you mean by "a private/var/ folder"? It would help if you state 
> the actual path, rather than something that looks like a fake path. If 
> you want to obfuscate the username, you may change it to something 
> generic like "fred":
> 
>     # real path with amusing Monty Python reference
>     /home/biggusdickus/.somethingprivate/var/packages
> 
>     # more professional sounding path
>     /home/fred/.somethingprivate/var/packages
> 
> for example.
> 
> 
>> if I change the statement to python3.6 pip install ?directory/packagename
>>
>> I get an error 2 cannot find director.
> 
> 
> Can you copy and paste the full error message? Are you sure that it 
> cannot find *director*, or is it *directory*?
> 
> 
>> ?I need to change my current python 
>> to 3.6 and also figure out how to install the package. ?I have seen some 
>> instructions to edit the bash file but before I do this I would like to 
>> resolve the install issue
> 
> What does your OS expect "python" to point to? It is dangerous to change 
> the system-wide "python" unless you really know what you are doing.
> 
> It should be harmless to use an alias as an ordinary user. Under bash, 
> you can test it in a shell like this:
> 
>     # check that python3.6 does points where you expect
>     which python3.6
> 
>     # and if so, run this
>     alias python='python3.6'
> 
>     # now confirm python points to Python 3.6
>     which python
> 
> 
> When you are satisfied that works, you can make it permanent by editing 
> your .bashrc file (under your home directory) and inserting that alias 
> line. The alias will take effect in any new shells you open (but not 
> existing shells).

You can also use 'pyenv' to manage multiple pythons.  It will do some
setup magic for you, which can let you switch between versions fairly
smoothly.  Pycharm has its own mechanism for managing multiple versions,
that works fine too, you can assign an interpreter per project (as some
of the commentary above suggests you probably know).




From oscar.j.benjamin at gmail.com  Mon Sep 10 09:49:32 2018
From: oscar.j.benjamin at gmail.com (Oscar Benjamin)
Date: Mon, 10 Sep 2018 14:49:32 +0100
Subject: [Tutor] building package on mac os
In-Reply-To: <c002c43c-62a8-410c-a0cd-66e6d1237de1@me.com>
References: <c002c43c-62a8-410c-a0cd-66e6d1237de1@me.com>
Message-ID: <CAHVvXxRBfcC1mNBjzWAuUbG5RkqXuy7bcO74-u4LyqPLLfMbLw@mail.gmail.com>

Hi Glen,

I feel like I would be able to offer you some help but you haven't
provided precise enough information for me to know exactly what your
problem is.

On Mon, 10 Sep 2018 at 00:02, Glenn Schultz via Tutor <tutor at python.org> wrote:
>
> I have a package that I am working on.  I am using Pycharm.  The directories are set up correctly.
> In my frameworks I have

I guess "frameworks" is a reference to OSX frameworks... Are you using
OSX (you need to explain things like this)?

> Python 2.7
> Python 3.5
> Python 3.6
> Python 3.7
> Current - which is Python 2.7

So I guess you have installed several framework builds of Python on OSX.

> After navigating to the directory with the package I run the following in my terminal
>
> python3 setup.py sdist bdist_wheel
>
> This runs fine and it appears all is correct with no messages or warning.

Okay that's good. But which Python is python3? Is it any of the
framework builds listed above or is it the OSX system Python?

What is the name of the resulting wheel? I expect something like:
numpy-1.15.1-cp27-cp27m-manylinux1_i686.whl

The name of the wheel is important as it tells you which versions of
Python it will work with.

> Then I go to the main user directory
> and pip install directory/packagename

And which pip is this? Does it correspond to the python3 you
mentioned? If the wheel you built contains e.g. any C code then it
will most likely not be usable with other versions of Python. See the
wheel name above...

> It appears the wheel installs in a private/var/ folder
>
> if I change the statement to python3.6 pip install  directory/packagename
> I get an error 2 cannot find director.  I need to change my current python to 3.6 and also figure out how to install the package.  I have seen some instructions to edit the bash file but before I do this I would like to resolve the install issue

The command gives me the following error:

$ python3.6 pip install directory/packagename
python3.6: can't open file 'pip': [Errno 2] No such file or directory

That's because it's trying to run a Python script called pip but there
isn't one in the current directory. I think you want to use the -m
switch to invoke the pip *module* that is connected to the Python that
you run with "python3.6". So then I get:

$ python3.6 -m pip install directory/packagename
Invalid requirement: 'directory/packagename'
It looks like a path. Does it exist ?

This is now running pip for python3.6 but it doesn't work because
directory/packagename isn't really the name of a wheel file or of a
Python project on PyPI. That may fix your problem provided you put the
actual name of the wheel there.

--
Oscar

From wachobc at gmail.com  Mon Sep 10 10:23:53 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Mon, 10 Sep 2018 10:23:53 -0400
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <20180910092201.GA56239@cskk.homeip.net>
References: <CADUn+-JWPbpjyiCmnQdBmw32TUHEssVKsptrL-igXLcn0enkNA@mail.gmail.com>
 <20180910092201.GA56239@cskk.homeip.net>
Message-ID: <CADUn+-+woOWF46vMGVtdcFkxxHO_rDQwGi_6J=ChqWbzU_Xj9A@mail.gmail.com>

Cameron,

Thank you again for the insight.

Yes, data_out is an equivalently-sized 'chunk' of a larger array.

I'm 'getting' this now..

So, without all the fluff associated with wiggling lines, my function
now looks like this:

def RSI_size_the_loop():
   results = []
   all_together = []   # not certain if I need this, put it in in an
attempt to fix the incompatibility if it existed

   for x in range (0, MAX_LOOP_COUNT, slice_size):
      results.append(my_transfer(disp, data_out, slice_size)

      print " results ", x, " = ", results  # show how results grows
on each iteration

   all_together = bytearray().join(results)

   print " all together ", all_together


I can observe results increasing in size and the last time through the loop:

 results  48  =
[[bytearray(b'\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')],
[bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')],
[bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')],
[bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')]]

So, now when I hit the line:

all_together = bytearray().join(results)

I'm getting the Traceback :

Traceback (most recent call last):
  File "SW8T_5.py", line 101, in <module>      # this is my main script
    loop_size = RSI_size_the_loop(Print)
  File "/home/temp/Python_Scratch/examples/RSI.py", line 359, in
RSI_size_the_loop
    all_together = bytearray().join(results)
TypeError: can only join an iterable of bytes (item 0 has type 'list')

I looked this up, and there's very few search engine results on this
type of TypeError.

I wanted to clarify my understanding of iterable, and looked that up here:

https://infohost.nmt.edu/tcc/help/pubs/python/web/iterable.html

And, as far as I can tell I'm using a compatible sequence type.

I've even added in print statements for the types, so I could double
check, and I get:

results returns <type 'list'>
all_together returns <type 'list'>

So both are type 'list' which is referred to here :

https://infohost.nmt.edu/tcc/help/pubs/python/web/sequence-types.html

as a valid sequence type but apparently there's a detail I'm still missing...


On Mon, Sep 10, 2018 at 5:22 AM, Cameron Simpson <cs at cskk.id.au> wrote:
> On 09Sep2018 23:00, Chip Wachob <wachobc at gmail.com> wrote:
>>
>> On Sat, Sep 8, 2018 at 9:14 PM, Cameron Simpson <cs at cskk.id.au> wrote:
>>>
>>> Actually he's getting back bytearray instances from transfer and wants to
>>> join them up (his function does a few small transfers to work around an
>>> issue with one big transfer). His earlier code is just confused. So he
>>> wants:
>>>
>>>  bytearray().join(results)
>>>
>>> Hacked example:
>>>
>>>  >>> bytearray().join( (bytearray("foo"),bytearray("bah")) )
>>>  bytearray(b'foobah')
>>
>>
>> I understand this example and I can replicate it in the interpreter..
>>
>> But, I'm still missing something here.
>> I presume that I need to instantiate an array of slice_size-sized
>> bytearrays.
>
>
> But no!
>
>> So, when I'm looping through, I can do:
>> for i in range (0, slice_count):
>>   results[i] = spi.transfer(data_out)
>
>
> Python lists are a variable size data structure, so our example goess:
>
>  results = []
>
> which allocates an empty list. Then:
>
>  for i in range(slice_count):
>    results.append(spi.transfer(data_out))
>
> suitably adjusted (data_out will be different pieces of the larger data,
> yes?) which grows the array by one item with each append. Your spi.transfer
> function allocates a new bytearray for each return value, so you end up with
> a list of distinct bytearrays.
>
>> Then I can :
>>
>> all_together = butearray().join(results)
>
>
> Yes.
>
>> But I can't seem to be able to find the proper syntax to create the
>> initial array.
>> And any attempt at filling the arrays to test some stand-alone code
>> only give me errors.
>
>
> You _can_ allocate a presized list, but there's almost no benefit and it
> isn't what people normally do.
>
>> Here's my code (all of it)
>
> [...]
>>
>> #results = bytearray( (bytearray(slice_size)*slice_count) )
>> results = bytearray(slice_size)    # why isn't this 16 bytes long?
>
>
> It is 16 bytes long when I do it:
>
>    >>> bs=bytearray(16)
>    >>> bs
>
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
>
>> res_list = (results)*slice_count
>
>
> This is a single 64 byte bytearray. You may have intended to make a single
> element tuple with "(results)", but that is just the same as "results"
> (rundundant brackets). To make a single element tuple you go "(results,)" -
> see the trailing comma?
>
> Example of each:
>
>    >>> bs*16
>
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
>    >>> (bs,)*16
>
> (bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
> bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'))
>
> But you don't need any of that.
>
> First, the list "results" can start empty and just get things appended to it
> and second, you don't need to preallocate any bytearrays because the
> internal, primary, transfer allocates a new bytearray for each return chunk.
>
> Cheers,
> Cameron Simpson <cs at cskk.id.au>

From akleider at sonic.net  Mon Sep 10 11:10:19 2018
From: akleider at sonic.net (Alex Kleider)
Date: Mon, 10 Sep 2018 08:10:19 -0700
Subject: [Tutor] python -m pip install vs pip install
Message-ID: <e5e8a8ceeb4abed18c47435267257fd0@sonic.net>

In another currently active thread Mats Wichmann recommends using:
   python -m pip install ...
vs
   pip install ...

The question is how to install a specific version of python itself.

I'm running Ubuntu 16.04 and have the following notes to myself as to 
how to install version 3.6 which was the one I wanted at the time:

   sudo add-apt-repository ppa:jonathonf/python-3.6
   sudo apt-get update
   sudo apt-get install python3.6
   pip install --user virtualenvwrapper
   echo "source virtualenvwrapper.sh" >> ~/.bashrc
   source ~/.bashrc
   mkvirtualenv --python=python3.6 p36

Should I modify these notes?
What should I do if/when I'm looking to use the next version (3.7 and 
beyond?)
Will things be completely different if/when I finally decide to move up 
to Ubuntu 18.04?

Thanks,
Alex

-- 
Alex Kleider
(sent from my current gizmo)

From mats at wichmann.us  Mon Sep 10 11:37:20 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Mon, 10 Sep 2018 09:37:20 -0600
Subject: [Tutor] python -m pip install vs pip install
In-Reply-To: <e5e8a8ceeb4abed18c47435267257fd0@sonic.net>
References: <e5e8a8ceeb4abed18c47435267257fd0@sonic.net>
Message-ID: <4bba5b08-f1d6-d199-6cac-9787e2d71879@wichmann.us>

On 09/10/2018 09:10 AM, Alex Kleider wrote:
> In another currently active thread Mats Wichmann recommends using:
> ? python -m pip install ...
> vs
> ? pip install ...
> 
> The question is how to install a specific version of python itself.
> 
> I'm running Ubuntu 16.04 and have the following notes to myself as to
> how to install version 3.6 which was the one I wanted at the time:
> 
> ? sudo add-apt-repository ppa:jonathonf/python-3.6
> ? sudo apt-get update
> ? sudo apt-get install python3.6
> ? pip install --user virtualenvwrapper
> ? echo "source virtualenvwrapper.sh" >> ~/.bashrc
> ? source ~/.bashrc
> ? mkvirtualenv --python=python3.6 p36
> 
> Should I modify these notes?
> What should I do if/when I'm looking to use the next version (3.7 and
> beyond?)
> Will things be completely different if/when I finally decide to move up
> to Ubuntu 18.04?
> 
> Thanks,
> Alex
> 

I have done it this way, assuming I don't want to replace the system
Python. This is a completely optional framework, but I've found it useful.

One time only:
$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
# set up environment variables for use by pyenv,
# as noted in pyenv readme:
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile

Any time I want to install a Python version:
$ pyenv rehash
$ pyenv install 3.7.0

Inside a project that wants to use 3.7.0:
$ pyenv local 3.7.0

To see what is available to install:
$ pyenv install list

To simplify creating virtualenvs, there is a pyenv-virtualenv plugin
described here:
https://github.com/pyenv/pyenv-virtualenv

From __peter__ at web.de  Mon Sep 10 13:42:00 2018
From: __peter__ at web.de (Peter Otten)
Date: Mon, 10 Sep 2018 19:42 +0200
Subject: [Tutor] Help with building bytearray arrays
References: <CADUn+-JWPbpjyiCmnQdBmw32TUHEssVKsptrL-igXLcn0enkNA@mail.gmail.com>
 <20180910092201.GA56239@cskk.homeip.net>
 <CADUn+-+woOWF46vMGVtdcFkxxHO_rDQwGi_6J=ChqWbzU_Xj9A@mail.gmail.com>
Message-ID: <pn6a98$6cl$1@blaine.gmane.org>

Chip Wachob wrote:

> Cameron,
> 
> Thank you again for the insight.
> 
> Yes, data_out is an equivalently-sized 'chunk' of a larger array.
> 
> I'm 'getting' this now..
> 
> So, without all the fluff associated with wiggling lines, my function
> now looks like this:
> 
> def RSI_size_the_loop():
>    results = []
>    all_together = []   # not certain if I need this, put it in in an
> attempt to fix the incompatibility if it existed
> 
>    for x in range (0, MAX_LOOP_COUNT, slice_size):
>       results.append(my_transfer(disp, data_out, slice_size)
> 
>       print " results ", x, " = ", results  # show how results grows
> on each iteration
> 
>    all_together = bytearray().join(results)
> 
>    print " all together ", all_together
> 
> 
> I can observe results increasing in size and the last time through the
> loop:
> 
>  results  48  =
> 
[[bytearray(b'\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')],

Note that there are two '[' at the start of the list. This means that the 
first list item is another list. In fact you seem to have a list of single 
item lists like

[["foo"], ["bar"], ...]

when you need

["foo", "bar", ...]

Of course join will fail with that:

>>> "".join(["foo", "bar"])
'foobar'
>>> "".join([["foo"], ["bar"]])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: sequence item 0: expected string, list found

I think the error message is pretty clear ;)

Have a look into your my_transfer() function to find out why it returns a 
list (or show us the code).


From wachobc at gmail.com  Mon Sep 10 14:15:43 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Mon, 10 Sep 2018 14:15:43 -0400
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <pn6a98$6cl$1@blaine.gmane.org>
References: <CADUn+-JWPbpjyiCmnQdBmw32TUHEssVKsptrL-igXLcn0enkNA@mail.gmail.com>
 <20180910092201.GA56239@cskk.homeip.net>
 <CADUn+-+woOWF46vMGVtdcFkxxHO_rDQwGi_6J=ChqWbzU_Xj9A@mail.gmail.com>
 <pn6a98$6cl$1@blaine.gmane.org>
Message-ID: <CADUn+-Jkg+2BeAA3AR6dsp_fykncfd4nwtwDkcxu1LF4Tyeo2A@mail.gmail.com>

Peter,

I see that clue "[[".

The thread history pretty much sums up what is going on up to this point.

I'll cover it once more:


I'm using Adafruit FT232H Breakout board and Adafruit's library.

https://github.com/adafruit/Adafruit_Python_GPIO

Per Adafruit's example code, I create an SPI interface:

https://learn.adafruit.com/adafruit-ft232h-breakout?view=all

I can access this interface with the spi.transfer() spi.write() and
spi.read() functions.

The transfer() function (see link above) accepts and returns bytearray
objects data.

My application requires me to send a large payload down the SPI port
to my circuit, and read back the same in full duplex.

Due to a limitation of the part, I can't send my whole bytearray at
one time.  It crashes out.

So, my solution was to send as large of a chunk of data at one time as
I can inside a loop until I get to the end of the data to be sent.

Meanwhile, the transfer() function is returning 'chunks' of bytearrays.

Earlier discussions here indicated that the best way was to :

results = []

for i in range (0, slice_size):
   results.append(transfer(data_out))

Then, concatenate the results into a long bytearray so I can use it
elsewhere in my code.

all_together = bytearray().join(results)

I _thought_ that this was going to create a concatenated list of all
the returned results:

all_together = [results[0] + results[1] + results [2] + results[3]]
-- for example

but, as you point out, I got:

all_together = [[results[0]], [results[1]], [results[2]]. [results[3]]
 -- I'm sure that the brackets and braces are not syntactically
correct, but I think you get the idea.

So I see why my .join() isn't working.  I'm not sure how to fix it though.


Related to this, but I'm not yet at that point until I get this
resolved, I need to walk through the all_together data and find where
the data changes from one value to another..

My background is in C and other 'historical' languages, so I'm trying
to get a hold of the way Python handles arrays, which is different
that the way I've thought for 20+ years.. :)

I hope this helps.

I'm beginning to wonder if Python was the right choice for this
project.. but it's too late for me to switch now.

Thanks to everyone for your comments and patience.



On Mon, Sep 10, 2018 at 1:42 PM, Peter Otten <__peter__ at web.de> wrote:
> Chip Wachob wrote:
>
>> Cameron,
>>
>> Thank you again for the insight.
>>
>> Yes, data_out is an equivalently-sized 'chunk' of a larger array.
>>
>> I'm 'getting' this now..
>>
>> So, without all the fluff associated with wiggling lines, my function
>> now looks like this:
>>
>> def RSI_size_the_loop():
>>    results = []
>>    all_together = []   # not certain if I need this, put it in in an
>> attempt to fix the incompatibility if it existed
>>
>>    for x in range (0, MAX_LOOP_COUNT, slice_size):
>>       results.append(my_transfer(disp, data_out, slice_size)
>>
>>       print " results ", x, " = ", results  # show how results grows
>> on each iteration
>>
>>    all_together = bytearray().join(results)
>>
>>    print " all together ", all_together
>>
>>
>> I can observe results increasing in size and the last time through the
>> loop:
>>
>>  results  48  =
>>
> [[bytearray(b'\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')],
>
> Note that there are two '[' at the start of the list. This means that the
> first list item is another list. In fact you seem to have a list of single
> item lists like
>
> [["foo"], ["bar"], ...]
>
> when you need
>
> ["foo", "bar", ...]
>
> Of course join will fail with that:
>
>>>> "".join(["foo", "bar"])
> 'foobar'
>>>> "".join([["foo"], ["bar"]])
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: sequence item 0: expected string, list found
>
> I think the error message is pretty clear ;)
>
> Have a look into your my_transfer() function to find out why it returns a
> list (or show us the code).
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From cs at cskk.id.au  Mon Sep 10 18:07:44 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Tue, 11 Sep 2018 08:07:44 +1000
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <CADUn+-+woOWF46vMGVtdcFkxxHO_rDQwGi_6J=ChqWbzU_Xj9A@mail.gmail.com>
References: <CADUn+-+woOWF46vMGVtdcFkxxHO_rDQwGi_6J=ChqWbzU_Xj9A@mail.gmail.com>
Message-ID: <20180910220744.GA54394@cskk.homeip.net>

On 10Sep2018 10:23, Chip Wachob <wachobc at gmail.com> wrote:
>So, without all the fluff associated with wiggling lines, my function
>now looks like this:
>
>def RSI_size_the_loop():
>   results = []
>   all_together = []   # not certain if I need this, put it in in an
>attempt to fix the incompatibility if it existed

You don't need this. all_together doesn't need to be mentioned until you 
initiate it with your bytearray.join.

>   for x in range (0, MAX_LOOP_COUNT, slice_size):
>      results.append(my_transfer(disp, data_out, slice_size)
>
>      print " results ", x, " = ", results  # show how results grows
>on each iteration
>
>   all_together = bytearray().join(results)
>
>   print " all together ", all_together
>
>I can observe results increasing in size and the last time through the loop:
>
> results  48  =
>[[bytearray(b'\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')],
>[bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')],
>[bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')],
>[bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')]]

Peter has pointed out that you have a list of list-of-bytearray instead of a 
flat list-of-bytearray.

The inference here is that your my_transfer function is returning a single 
element list-of-bytearray.

>So, now when I hit the line:
>all_together = bytearray().join(results)
>
>I'm getting the Traceback :
[...]
>Traceback (most recent call last):
>  File "SW8T_5.py", line 101, in <module>      # this is my main script
>    loop_size = RSI_size_the_loop(Print)
>  File "/home/temp/Python_Scratch/examples/RSI.py", line 359, in
>RSI_size_the_loop
>    all_together = bytearray().join(results)
>TypeError: can only join an iterable of bytes (item 0 has type 'list')

So because you have a list-of-list, item[0] is indeed a list, not a bytearray.

If you change this:

  results.append(my_transfer(disp, data_out, slice_size)

into:

  result = my_transfer(disp, data_out, slice_size)
  print("result =", repr(result))
  results.append(result)

this should be apparent. So this issue lies with your my_transfer function; the 
main loop above now looks correct.

>I've even added in print statements for the types, so I could double
>check, and I get:
>
>results returns <type 'list'>
>all_together returns <type 'list'>
>
>So both are type 'list' which is referred to here :
>
>https://infohost.nmt.edu/tcc/help/pubs/python/web/sequence-types.html
>
>as a valid sequence type but apparently there's a detail I'm still missing...

Yeah. bytearray().join wants bytes or bytearrays in the list/iterable you hand 
it. You've got lists, with the bytearrays further in.

Cheers,
Cameron Simpson <cs at cskk.id.au>

From alan.gauld at yahoo.co.uk  Mon Sep 10 18:13:46 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 10 Sep 2018 23:13:46 +0100
Subject: [Tutor] Help with building bytearray arrays
In-Reply-To: <CADUn+-Jkg+2BeAA3AR6dsp_fykncfd4nwtwDkcxu1LF4Tyeo2A@mail.gmail.com>
References: <CADUn+-JWPbpjyiCmnQdBmw32TUHEssVKsptrL-igXLcn0enkNA@mail.gmail.com>
 <20180910092201.GA56239@cskk.homeip.net>
 <CADUn+-+woOWF46vMGVtdcFkxxHO_rDQwGi_6J=ChqWbzU_Xj9A@mail.gmail.com>
 <pn6a98$6cl$1@blaine.gmane.org>
 <CADUn+-Jkg+2BeAA3AR6dsp_fykncfd4nwtwDkcxu1LF4Tyeo2A@mail.gmail.com>
Message-ID: <pn6q6n$h8u$1@blaine.gmane.org>

On 10/09/18 19:15, Chip Wachob wrote:

> So I see why my .join() isn't working.  I'm not sure how to fix it though.

I already showed you the sum() function.

It can take a list of lists and add them together

end_array = sum(results,[])

> My background is in C and other 'historical' languages, so I'm trying
> to get a hold of the way Python handles arrays, which is different
> that the way I've thought for 20+ years.. :)

Yes, as per my other message, Python data structures are
very powerful. They are not just bare chunks of memory.

> I'm beginning to wonder if Python was the right choice for this
> project.. but it's too late for me to switch now.

Looks like a very good choice to me. Almost any other language
would be much more work. :-)


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From __peter__ at web.de  Tue Sep 11 03:16:11 2018
From: __peter__ at web.de (Peter Otten)
Date: Tue, 11 Sep 2018 09:16:11 +0200
Subject: [Tutor] Help with building bytearray arrays
References: <CADUn+-JWPbpjyiCmnQdBmw32TUHEssVKsptrL-igXLcn0enkNA@mail.gmail.com>
 <20180910092201.GA56239@cskk.homeip.net>
 <CADUn+-+woOWF46vMGVtdcFkxxHO_rDQwGi_6J=ChqWbzU_Xj9A@mail.gmail.com>
 <pn6a98$6cl$1@blaine.gmane.org>
 <CADUn+-Jkg+2BeAA3AR6dsp_fykncfd4nwtwDkcxu1LF4Tyeo2A@mail.gmail.com>
Message-ID: <pn7pvs$c2o$1@blaine.gmane.org>

Chip Wachob wrote:

> Peter,
> 
> I see that clue "[[".
> 
> The thread history pretty much sums up what is going on up to this point.
> 
> I'll cover it once more:

[snip]

> I hope this helps.

Unfortunately it doesn't as the problem is in my_transfer.
 
> I'm beginning to wonder if Python was the right choice for this
> project.. 

You mean you'd rather debug a segfault in C than an exception with a 
traceback and an error message that is spot on in Python?

You have an error in your program logic, and you'll eventually run into 
those no matter what language you choose.
 
> Thanks to everyone for your comments and patience.

If you are too frustrated to look into the actual problem at the moment you 
can change the following loop

> Earlier discussions here indicated that the best way was to :
> 
> results = []
> 
> for i in range (0, slice_size):
>    results.append(transfer(data_out))

by replacing the append() with the extend() method

results = []
for i in range (0, slice_size):
    results.extend(transfer(data_out))

for now.




From rls4jc at gmail.com  Tue Sep 11 14:57:20 2018
From: rls4jc at gmail.com (Roger Lea Scherer)
Date: Tue, 11 Sep 2018 11:57:20 -0700
Subject: [Tutor] IDLE
Message-ID: <CAPvEsMw1q98Yw95-9kO3F8oWenkzBgYbGpHVSVveLoQrMQMRDg@mail.gmail.com>

Can you direct me to where or how to update from Python 3.6.5 Shell, I
think it is also called IDLE 3.6.5, to Python 3.7 Shell? I looked at the
documentation which seems like there is another one, slightly improved.
I've downloaded Python 3.7, but can't figure out how to upgrade the
IDLE/Shell. And I can't for the life of me remember how I originally got
the Python 3.6.5 Shell.

Thank you

-- 
Roger Lea Scherer
623.255.7719

                  *Strengths:*
   Input, Strategic,
Responsibility,

Learner, Ideation

From mats at wichmann.us  Tue Sep 11 18:09:12 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Tue, 11 Sep 2018 16:09:12 -0600
Subject: [Tutor] IDLE
In-Reply-To: <CAPvEsMw1q98Yw95-9kO3F8oWenkzBgYbGpHVSVveLoQrMQMRDg@mail.gmail.com>
References: <CAPvEsMw1q98Yw95-9kO3F8oWenkzBgYbGpHVSVveLoQrMQMRDg@mail.gmail.com>
Message-ID: <2fb9019a-df0c-ce1b-4f63-330fe09017a7@wichmann.us>

On 09/11/2018 12:57 PM, Roger Lea Scherer wrote:
> Can you direct me to where or how to update from Python 3.6.5 Shell, I
> think it is also called IDLE 3.6.5, to Python 3.7 Shell? I looked at the
> documentation which seems like there is another one, slightly improved.
> I've downloaded Python 3.7, but can't figure out how to upgrade the
> IDLE/Shell. And I can't for the life of me remember how I originally got
> the Python 3.6.5 Shell.
> 
> Thank you
> 

what are you running on?

From dzhindo at outlook.com  Tue Sep 11 18:31:38 2018
From: dzhindo at outlook.com (Denis Dzhindo)
Date: Tue, 11 Sep 2018 22:31:38 +0000
Subject: [Tutor] Clean the Shell
Message-ID: <BN6PR10MB155470D0F353DF5B07B9B53BA6040@BN6PR10MB1554.namprd10.prod.outlook.com>

Hello!
May I know, how I can clean the Shell,

Best, Denis

From alan.gauld at yahoo.co.uk  Tue Sep 11 19:57:45 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 12 Sep 2018 00:57:45 +0100
Subject: [Tutor] IDLE
In-Reply-To: <CAPvEsMw1q98Yw95-9kO3F8oWenkzBgYbGpHVSVveLoQrMQMRDg@mail.gmail.com>
References: <CAPvEsMw1q98Yw95-9kO3F8oWenkzBgYbGpHVSVveLoQrMQMRDg@mail.gmail.com>
Message-ID: <pn9klm$9uo$1@blaine.gmane.org>

On 11/09/18 19:57, Roger Lea Scherer wrote:
> Can you direct me to where or how to update from Python 3.6.5 Shell, I
> think it is also called IDLE 3.6.5, to Python 3.7 Shell? 

The Python shell and IDLE are really two different things.

The shell is normally considered to mean the interactive
interpreter, in any of its guises. There is a shell within
IDLE but it is only part of the IDLE toolset not all of it.

That having been said, where it lives depends on your OS.
Whether it was installed along with Python depends on
how you installed Python.

On Windows the download should include IDLE and the
installer should have set up the links/menu entries
for you.

On Linux, from the software manager you probably need
to install IDLE separately - but I doubt if any distros
have 3.7 available yet. Not officially at least.

On MacOS I have no idea, I never found IDLE worked very
well on a Macc.

> I've downloaded Python 3.7, but can't figure out how to upgrade the
> IDLE/Shell. And I can't for the life of me remember how I originally got
> the Python 3.6.5 Shell.
BTW. Do you really need 3.7? Unless there is some vital
feature you need why not just stick with 3.6 - or even 3.5?
I am still using 3.5 on 2 of my PCs and only upgraded
the third to 3.6 last month. You really don't need to
sweat about using the latest version, not that much
changes.

But if you really do think you need some new feature
from 3.7 (from your recent posts the new http.server
features might qualify) then by all means let us
know what OS you are using and how you installed it
and we can try to point you in the right direction.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From alan.gauld at yahoo.co.uk  Tue Sep 11 20:00:20 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 12 Sep 2018 01:00:20 +0100
Subject: [Tutor] Clean the Shell
In-Reply-To: <BN6PR10MB155470D0F353DF5B07B9B53BA6040@BN6PR10MB1554.namprd10.prod.outlook.com>
References: <BN6PR10MB155470D0F353DF5B07B9B53BA6040@BN6PR10MB1554.namprd10.prod.outlook.com>
Message-ID: <pn9kqh$9uo$2@blaine.gmane.org>

On 11/09/18 23:31, Denis Dzhindo wrote:
> Hello!
> May I know, how I can clean the Shell,

I'm not sure what you mean by that, however,
if you mean reset the IDLE shell back to square
one there is a menu option to restart the shell.
Shell->Restart Shell.

If you mean the command line interpreter the
easiest (and most reliable) way is just exit
and restart.

If you mean something else you will need to
explain.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From mats at wichmann.us  Tue Sep 11 20:03:05 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Tue, 11 Sep 2018 18:03:05 -0600
Subject: [Tutor] Clean the Shell
In-Reply-To: <BN6PR10MB155470D0F353DF5B07B9B53BA6040@BN6PR10MB1554.namprd10.prod.outlook.com>
References: <BN6PR10MB155470D0F353DF5B07B9B53BA6040@BN6PR10MB1554.namprd10.prod.outlook.com>
Message-ID: <b91bfdcd-4663-2e31-b77c-fe1e4e689bc0@wichmann.us>

On 09/11/2018 04:31 PM, Denis Dzhindo wrote:
> Hello!
> May I know, how I can clean the Shell,
> 
> Best, Denis

Denis, I, at least, have no idea what you are asking.  Could you be a
bit more specific?  What shell? Why does whatever it is need cleaning?
What are you running on? Is this even a Python question?



From steve at pearwood.info  Wed Sep 12 02:49:22 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Wed, 12 Sep 2018 16:49:22 +1000
Subject: [Tutor] Clean the Shell
In-Reply-To: <BN6PR10MB155470D0F353DF5B07B9B53BA6040@BN6PR10MB1554.namprd10.prod.outlook.com>
References: <BN6PR10MB155470D0F353DF5B07B9B53BA6040@BN6PR10MB1554.namprd10.prod.outlook.com>
Message-ID: <20180912064922.GM1596@ando.pearwood.info>

On Tue, Sep 11, 2018 at 10:31:38PM +0000, Denis Dzhindo wrote:
> Hello!
> May I know, how I can clean the Shell,

I find warm water, bicarb of soda and vinegar is best.

*wink*

Can you give a bit more detail? Which shell, and what do you mean by 
"clean"?

Depending on which shell, you might 
find that typing Ctrl-L will clear the screen. Your terminal window 
might also include commands like 

Clear Terminal
Reset & Clear Terminal

which can help if you have messed up the terminal settings.

If you want to start from a completely fresh session, the easier way is 
to quite the shell and start a new one.

Does any of this help?


-- 
Steve

From ryan at allwegot.net  Wed Sep 12 09:08:48 2018
From: ryan at allwegot.net (Ryan Smith)
Date: Wed, 12 Sep 2018 09:08:48 -0400
Subject: [Tutor] Help understanding base64 decoding
Message-ID: <CADYLmeG4XGXTnUas7fJAAf0_Gz_5H02QcGx5rF_jBN+baG2z7w@mail.gmail.com>

Hello All,

I am currently working on a small utility that finds any base64
encoded strings in files and decodes them. I am having issue
understanding how the Base64 module actually works. The regular
expression that I am using correctly matches on the encoded strings. I
simply want to be able to convert the match of the encoded ascii
string to it's decoded ascii equivalent. For example the base64
encoded ascii string 'UwB5AHMAdABlAG0ALgBkAGwAbAA=' will decode to
'System.dll' if I use an online base64 decoder. However I get a
completely different output when trying to codify this using python
3.6.5:

>>>import base64
>>>import binascii

>>>test_str = 'UwB5AHMAdABlAG0ALgBkAGwAbAA='
>>> base64.b64decode(test_str)
b'S\x00y\x00s\x00t\x00e\x00m\x00.\x00d\x00l\x00l\x00'

>>>temp = base64.b64decode(test_str)
>>>binascii.b2a_base64(temp)
b'UwB5AHMAdABlAG0ALgBkAGwAbAA=\n'

I understand that when decoding and encoding you have to use bytes
objects but what I don't understand is why I can't get the proper
conversion of the original ascii string. Can someone please point me
in the right direction?

Thank you,

Ryan

From __peter__ at web.de  Thu Sep 13 02:57:13 2018
From: __peter__ at web.de (Peter Otten)
Date: Thu, 13 Sep 2018 08:57:13 +0200
Subject: [Tutor] Help understanding base64 decoding
References: <CADYLmeG4XGXTnUas7fJAAf0_Gz_5H02QcGx5rF_jBN+baG2z7w@mail.gmail.com>
Message-ID: <pnd1ka$m89$1@blaine.gmane.org>

Ryan Smith wrote:

> Hello All,
> 
> I am currently working on a small utility that finds any base64
> encoded strings in files and decodes them. I am having issue
> understanding how the Base64 module actually works. The regular
> expression that I am using correctly matches on the encoded strings. I
> simply want to be able to convert the match of the encoded ascii
> string to it's decoded ascii equivalent. For example the base64
> encoded ascii string 'UwB5AHMAdABlAG0ALgBkAGwAbAA=' will decode to
> 'System.dll' if I use an online base64 decoder. However I get a
> completely different output when trying to codify this using python
> 3.6.5:
> 
>>>>import base64
>>>>import binascii
> 
>>>>test_str = 'UwB5AHMAdABlAG0ALgBkAGwAbAA='
>>>> base64.b64decode(test_str)
> b'S\x00y\x00s\x00t\x00e\x00m\x00.\x00d\x00l\x00l\x00'
> 
>>>>temp = base64.b64decode(test_str)
>>>>binascii.b2a_base64(temp)
> b'UwB5AHMAdABlAG0ALgBkAGwAbAA=\n'
> 
> I understand that when decoding and encoding you have to use bytes
> objects but what I don't understand is why I can't get the proper
> conversion of the original ascii string. Can someone please point me
> in the right direction?

Look closely at the odd bytes in 

> b'S\x00y\x00s\x00t\x00e\x00m\x00.\x00d\x00l\x00l\x00'

or just do

>>> b'S\x00y\x00s\x00t\x00e\x00m\x00.\x00d\x00l\x00l\x00'[::2]
b'System.dll'

The even bytes are all NUL:

>>> b'S\x00y\x00s\x00t\x00e\x00m\x00.\x00d\x00l\x00l\x00'[1::2]
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

This means that your byte string already *is* the original string, encoded 
as UTF-16. You can convert it into a string with

>>> b'S\x00y\x00s\x00t\x00e\x00m\x00.\x00d\x00l\x00l\x00'.decode("utf-16")
'System.dll'

which will handle non-ascii characters correctly, too.


From ryan at allwegot.net  Thu Sep 13 08:23:10 2018
From: ryan at allwegot.net (Ryan Smith)
Date: Thu, 13 Sep 2018 08:23:10 -0400
Subject: [Tutor] Help understanding base64 decoding
In-Reply-To: <pnd1ka$m89$1@blaine.gmane.org>
References: <CADYLmeG4XGXTnUas7fJAAf0_Gz_5H02QcGx5rF_jBN+baG2z7w@mail.gmail.com>
 <pnd1ka$m89$1@blaine.gmane.org>
Message-ID: <CADYLmeF0iWorkY+46n0cMQwUn_iP4i6tHWrCketrBScwDViZZw@mail.gmail.com>

Hi Peter,

Thank you for the explanation! I have been banging my head around this
for almost two days. I'm still getting familiar with all of the
different encodings at play. For example the way I currently
understand things is that python supports unicode which ultimately
defaults to being encoded in UTF-8. Hence I'm guessing is  the reason
for converting strings to a bytes object in the first place. Again
thank you for the assistance!

Ryan

On Thu, Sep 13, 2018 at 2:57 AM, Peter Otten <__peter__ at web.de> wrote:
> Ryan Smith wrote:
>
>> Hello All,
>>
>> I am currently working on a small utility that finds any base64
>> encoded strings in files and decodes them. I am having issue
>> understanding how the Base64 module actually works. The regular
>> expression that I am using correctly matches on the encoded strings. I
>> simply want to be able to convert the match of the encoded ascii
>> string to it's decoded ascii equivalent. For example the base64
>> encoded ascii string 'UwB5AHMAdABlAG0ALgBkAGwAbAA=' will decode to
>> 'System.dll' if I use an online base64 decoder. However I get a
>> completely different output when trying to codify this using python
>> 3.6.5:
>>
>>>>>import base64
>>>>>import binascii
>>
>>>>>test_str = 'UwB5AHMAdABlAG0ALgBkAGwAbAA='
>>>>> base64.b64decode(test_str)
>> b'S\x00y\x00s\x00t\x00e\x00m\x00.\x00d\x00l\x00l\x00'
>>
>>>>>temp = base64.b64decode(test_str)
>>>>>binascii.b2a_base64(temp)
>> b'UwB5AHMAdABlAG0ALgBkAGwAbAA=\n'
>>
>> I understand that when decoding and encoding you have to use bytes
>> objects but what I don't understand is why I can't get the proper
>> conversion of the original ascii string. Can someone please point me
>> in the right direction?
>
> Look closely at the odd bytes in
>
>> b'S\x00y\x00s\x00t\x00e\x00m\x00.\x00d\x00l\x00l\x00'
>
> or just do
>
>>>> b'S\x00y\x00s\x00t\x00e\x00m\x00.\x00d\x00l\x00l\x00'[::2]
> b'System.dll'
>
> The even bytes are all NUL:
>
>>>> b'S\x00y\x00s\x00t\x00e\x00m\x00.\x00d\x00l\x00l\x00'[1::2]
> b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
>
> This means that your byte string already *is* the original string, encoded
> as UTF-16. You can convert it into a string with
>
>>>> b'S\x00y\x00s\x00t\x00e\x00m\x00.\x00d\x00l\x00l\x00'.decode("utf-16")
> 'System.dll'
>
> which will handle non-ascii characters correctly, too.
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From cs at cskk.id.au  Thu Sep 13 18:19:11 2018
From: cs at cskk.id.au (Cameron Simpson)
Date: Fri, 14 Sep 2018 08:19:11 +1000
Subject: [Tutor] Help understanding base64 decoding
In-Reply-To: <CADYLmeF0iWorkY+46n0cMQwUn_iP4i6tHWrCketrBScwDViZZw@mail.gmail.com>
References: <CADYLmeF0iWorkY+46n0cMQwUn_iP4i6tHWrCketrBScwDViZZw@mail.gmail.com>
Message-ID: <20180913221911.GA86738@cskk.homeip.net>

On 13Sep2018 08:23, Ryan Smith <ryan at allwegot.net> wrote:
>[...] I'm still getting familiar with all of the
>different encodings at play. For example the way I currently
>understand things is that python supports unicode which ultimately
>defaults to being encoded in UTF-8. Hence I'm guessing is  the reason
>for converting strings to a bytes object in the first place.

Yeah. "str" is text, using Unicode code points.

To store this in a file, the text must be transcribed in some encoding. The 
default encoding in Python is UTF-8, which has some advantages: the bottom 128 
values are one to one with ASCII, and it is fairly compact when the source text 
live in or near that range.

Windows often works with UTF-16, which is why your source bytes look the way 
they do.

So the path is:

  base64 text (which fits in a conservative subset of ASCII)
  => bytes holding a UTF-16 encoding of your target text
  => decode to a Python str

Cheers,
Cameron Simpson <cs at cskk.id.au>

From alan.gauld at btinternet.com  Wed Sep 19 16:01:19 2018
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 19 Sep 2018 21:01:19 +0100
Subject: [Tutor] Fwd: How to roughly associate the values of two numpy
 arrays, or python lists if necessary
In-Reply-To: <b4a33704-bee0-0534-9e5c-e26597e85931@kcl.ac.uk>
References: <b4a33704-bee0-0534-9e5c-e26597e85931@kcl.ac.uk>
Message-ID: <16a74aaf-92dc-36a0-d384-c217b5100e6d@btinternet.com>

Forwarded to list....

----------------------------

I have, I suspect, an elementary problem that I am too inexperienced to 
resolve.

I have two numpy arrays, each representing the values of a specific 
property of a set of cells.

Now, I want to associate the two values for each cell, that is for each 
index of the numpy array. But I want to associate them ROUGHLY, that 
means, APPROXIMATELY, so that there is a weak, linear correlation 
between the values representing one property and the values representing 
the second property of each individual cell.

Up to now I have used the following procedure.
I have divided each population of values into four segments based on the 
value of the standard deviation thus.

1. values > mean + 1 std (sigma)
2. values > mean but < mean + 1 std (sigma)
3. values < mean but > mean + 1 std (sigma)
4. values < mean + 1 std (sigma).

Then I randomly select a value from group 1 for the first property and I 
associate it with a randomly selected sample of the second property from 
its group 1. And so on through the total population. This gave me a very 
rough linear association between the two properties, but I am wondering 
whether I can do it in a simpler and better way.


-- 

Sydney


_________

Professor Sydney Shall
Department of Haematology/Oncology
Phone: +(0)2078489200
E-Mail: sydney.shall
[Correspondents outside the College should add @kcl.ac.uk]


From wachobc at gmail.com  Wed Sep 19 17:47:07 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Wed, 19 Sep 2018 17:47:07 -0400
Subject: [Tutor] Best solution to modifying code within a distributed library
Message-ID: <CADUn+-K+KNjy9HJSLta8JnUEN_+_+Z0Jt324MZW3xt2rF3zbKA@mail.gmail.com>

Hello once again,

I'm sure this is probably way outside my 'pay grade' but I would like
to try an experiment and I'm not sure how to go about it.

I'm using the Adafruit FT232 libraries found here:

https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/SPI.py

I'm experiencing some wiggling of the IO lines when I configure the IO
pin direction.

I've looked through the code in the FT232H.py file and found what I
believe to be the culprit.

I would like to comment out line 340 (self.mpsse_write_gpio()) to
prove that this is what is causing glitches that I do not want.

Using the .__file__ inside the interpreter I learned that the file is
located here on my machine:

/usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-1.0.3-py2.7.egg/Adafruit_GPIO/FT232H.pyc

But obviously, this is a binary file.

If I understand enough about Python, I believe that I need to edit the
FT232H.py file in the .egg file to implement the change.  There is
also likely some sort of compilation that needs to be done once the
change is made...

BUT

As I've also learned from our friend Google, one should not be editing
.egg files, etc.

So, can the experts out there point me to the proper method of
implementing the change?

IF, this ends up resolving my issues, then I presume that I will need
to create my own .egg file.  Is this accurate?

As always thank you in advance for your time,

From mats at wichmann.us  Wed Sep 19 19:51:12 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Wed, 19 Sep 2018 17:51:12 -0600
Subject: [Tutor] Best solution to modifying code within a distributed
 library
In-Reply-To: <CADUn+-K+KNjy9HJSLta8JnUEN_+_+Z0Jt324MZW3xt2rF3zbKA@mail.gmail.com>
References: <CADUn+-K+KNjy9HJSLta8JnUEN_+_+Z0Jt324MZW3xt2rF3zbKA@mail.gmail.com>
Message-ID: <d4b091df-95bc-3175-d259-104af78583e3@wichmann.us>

On 09/19/2018 03:47 PM, Chip Wachob wrote:
> Hello once again,
> 
> I'm sure this is probably way outside my 'pay grade' but I would like
> to try an experiment and I'm not sure how to go about it.
> 
> I'm using the Adafruit FT232 libraries found here:
> 
> https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/SPI.py
> 
> I'm experiencing some wiggling of the IO lines when I configure the IO
> pin direction.
> 
> I've looked through the code in the FT232H.py file and found what I
> believe to be the culprit.
> 
> I would like to comment out line 340 (self.mpsse_write_gpio()) to
> prove that this is what is causing glitches that I do not want.
> 
> Using the .__file__ inside the interpreter I learned that the file is
> located here on my machine:
> 
> /usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-1.0.3-py2.7.egg/Adafruit_GPIO/FT232H.pyc
> 
> But obviously, this is a binary file.
> 
> If I understand enough about Python, I believe that I need to edit the
> FT232H.py file in the .egg file to implement the change.  There is
> also likely some sort of compilation that needs to be done once the
> change is made...
> 
> BUT
> 
> As I've also learned from our friend Google, one should not be editing
> .egg files, etc.

You'll want to get the original and work from there. You already know
where it is - you've included the github link.

It's hard to know how much needs to be explained here... roughly, in
your project you want to clone the git tree, and make sure that's what
your experiment is picking up.  That would start as:

git clone https://github.com/adafruit/Adafruit_Python_GPIO.git

or of you want to start with something you might want to create a github
pull request to the maintainer, make sure you have a github account,
click the fork button on the github page, then in your own account find
the URL to give to "git clone" for your fork, and start from there.

to do an experiment, the former ought to be enough, but "there are more
details", depending on what you're familiar with as far as these tools.

Do write back with more questions if you go down this path...




From david at graniteweb.com  Wed Sep 19 22:35:59 2018
From: david at graniteweb.com (David Rock)
Date: Wed, 19 Sep 2018 21:35:59 -0500
Subject: [Tutor] Best solution to modifying code within a distributed
 library
In-Reply-To: <d4b091df-95bc-3175-d259-104af78583e3@wichmann.us>
References: <CADUn+-K+KNjy9HJSLta8JnUEN_+_+Z0Jt324MZW3xt2rF3zbKA@mail.gmail.com>
 <d4b091df-95bc-3175-d259-104af78583e3@wichmann.us>
Message-ID: <F2EAB161-2C1A-4168-911B-D535D6D3C259@graniteweb.com>


> On Sep 19, 2018, at 18:51, Mats Wichmann <mats at wichmann.us> wrote:
> 
> On 09/19/2018 03:47 PM, Chip Wachob wrote:
>> Hello once again,
>> 
>> I would like to comment out line 340 (self.mpsse_write_gpio()) to
>> prove that this is what is causing glitches that I do not want.
>> 
> 
> You'll want to get the original and work from there. You already know
> where it is - you've included the github link.
> 

There?s another option? Ask Adafruit directly.

They are amazingly helpful and would be more than happy to hear if there?s a potential issue with their code.


? 
David Rock
david at graniteweb.com





From wachobc at gmail.com  Wed Sep 19 23:22:11 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Wed, 19 Sep 2018 23:22:11 -0400
Subject: [Tutor] Best solution to modifying code within a distributed
 library
In-Reply-To: <F2EAB161-2C1A-4168-911B-D535D6D3C259@graniteweb.com>
References: <CADUn+-K+KNjy9HJSLta8JnUEN_+_+Z0Jt324MZW3xt2rF3zbKA@mail.gmail.com>
 <d4b091df-95bc-3175-d259-104af78583e3@wichmann.us>
 <F2EAB161-2C1A-4168-911B-D535D6D3C259@graniteweb.com>
Message-ID: <CADUn+-Krsn7BJJK+qT=BYfTncSE7sqkTnDQ7Ux1Zbs7suvOGVw@mail.gmail.com>

David,

I should have pointed out that I've already posted to the forums there
and there is only crickets.

So, I've taken it upon myself to attempt to solve it for myself.  But,
as I noted, I'm very very new to Python and the whole .egg, pip, git
thing, and that's what lead to my query here.

Mats,

Thanks for the pointer on the clone.  I think I'll take that approach
for now.  Since this is an experiment, this seems like the right path
to take.

Thanks to all for the information.


On Wed, Sep 19, 2018 at 10:35 PM, David Rock <david at graniteweb.com> wrote:
>
>> On Sep 19, 2018, at 18:51, Mats Wichmann <mats at wichmann.us> wrote:
>>
>> On 09/19/2018 03:47 PM, Chip Wachob wrote:
>>> Hello once again,
>>>
>>> I would like to comment out line 340 (self.mpsse_write_gpio()) to
>>> prove that this is what is causing glitches that I do not want.
>>>
>>
>> You'll want to get the original and work from there. You already know
>> where it is - you've included the github link.
>>
>
> There?s another option? Ask Adafruit directly.
>
> They are amazingly helpful and would be more than happy to hear if there?s a potential issue with their code.
>
>
> ?
> David Rock
> david at graniteweb.com
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From wachobc at gmail.com  Wed Sep 19 23:59:32 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Wed, 19 Sep 2018 23:59:32 -0400
Subject: [Tutor] Best solution to modifying code within a distributed
 library
In-Reply-To: <d4b091df-95bc-3175-d259-104af78583e3@wichmann.us>
References: <CADUn+-K+KNjy9HJSLta8JnUEN_+_+Z0Jt324MZW3xt2rF3zbKA@mail.gmail.com>
 <d4b091df-95bc-3175-d259-104af78583e3@wichmann.us>
Message-ID: <CADUn+-LX9cexmznj_h1hQcmq5XzuJMs_JY7H2Mdvk+7CG4Rr5w@mail.gmail.com>

Mats,

Silly question here..

But after using the git clone command, I've got a directory of the
Adafruit project in the same directory as my project.

When I import the library, will I get the 'installed' library, or do I
get the library that is in the project directory?

If I have to specify which library to use, how is that done?

Thanks,


On Wed, Sep 19, 2018 at 7:51 PM, Mats Wichmann <mats at wichmann.us> wrote:
> On 09/19/2018 03:47 PM, Chip Wachob wrote:
>> Hello once again,
>>
>> I'm sure this is probably way outside my 'pay grade' but I would like
>> to try an experiment and I'm not sure how to go about it.
>>
>> I'm using the Adafruit FT232 libraries found here:
>>
>> https://github.com/adafruit/Adafruit_Python_GPIO/blob/master/Adafruit_GPIO/SPI.py
>>
>> I'm experiencing some wiggling of the IO lines when I configure the IO
>> pin direction.
>>
>> I've looked through the code in the FT232H.py file and found what I
>> believe to be the culprit.
>>
>> I would like to comment out line 340 (self.mpsse_write_gpio()) to
>> prove that this is what is causing glitches that I do not want.
>>
>> Using the .__file__ inside the interpreter I learned that the file is
>> located here on my machine:
>>
>> /usr/local/lib/python2.7/dist-packages/Adafruit_GPIO-1.0.3-py2.7.egg/Adafruit_GPIO/FT232H.pyc
>>
>> But obviously, this is a binary file.
>>
>> If I understand enough about Python, I believe that I need to edit the
>> FT232H.py file in the .egg file to implement the change.  There is
>> also likely some sort of compilation that needs to be done once the
>> change is made...
>>
>> BUT
>>
>> As I've also learned from our friend Google, one should not be editing
>> .egg files, etc.
>
> You'll want to get the original and work from there. You already know
> where it is - you've included the github link.
>
> It's hard to know how much needs to be explained here... roughly, in
> your project you want to clone the git tree, and make sure that's what
> your experiment is picking up.  That would start as:
>
> git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
>
> or of you want to start with something you might want to create a github
> pull request to the maintainer, make sure you have a github account,
> click the fork button on the github page, then in your own account find
> the URL to give to "git clone" for your fork, and start from there.
>
> to do an experiment, the former ought to be enough, but "there are more
> details", depending on what you're familiar with as far as these tools.
>
> Do write back with more questions if you go down this path...
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From mats at wichmann.us  Thu Sep 20 18:14:39 2018
From: mats at wichmann.us (Mats Wichmann)
Date: Thu, 20 Sep 2018 16:14:39 -0600
Subject: [Tutor] Best solution to modifying code within a distributed
 library
In-Reply-To: <CADUn+-LX9cexmznj_h1hQcmq5XzuJMs_JY7H2Mdvk+7CG4Rr5w@mail.gmail.com>
References: <CADUn+-K+KNjy9HJSLta8JnUEN_+_+Z0Jt324MZW3xt2rF3zbKA@mail.gmail.com>
 <d4b091df-95bc-3175-d259-104af78583e3@wichmann.us>
 <CADUn+-LX9cexmznj_h1hQcmq5XzuJMs_JY7H2Mdvk+7CG4Rr5w@mail.gmail.com>
Message-ID: <96c5629e-7eb9-e5b8-3b5e-e37cce6da299@wichmann.us>

On 09/19/2018 09:59 PM, Chip Wachob wrote:
> Mats,
> 
> Silly question here..
> 
> But after using the git clone command, I've got a directory of the
> Adafruit project in the same directory as my project.
> 
> When I import the library, will I get the 'installed' library, or do I
> get the library that is in the project directory?
> 
> If I have to specify which library to use, how is that done?

you look at, and possibly modify, sys.path


  >>> import sys
  >>> sys.path
  ['', '/usr/lib64/python36.zip', '/usr/lib64/python3.6',
'/usr/lib64/python3.6/lib-dynload',
'/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages']


the first element '' is the local directory, so with my sys.path, it
would pick the local one first.


if you wanted the opposite, that is be _sure_ you get the installed one,
you could use a stanza something like this:


   savepath = sys.path
   sys.path = [path for path in sys.path if path.strip('.')]
   import foo
   sys.path = savepath


but this is actually kind of tricky stuff, trying to deal with possibly
two modules of the same name, so tread carefully.



From oscar.j.benjamin at gmail.com  Thu Sep 20 19:01:54 2018
From: oscar.j.benjamin at gmail.com (Oscar Benjamin)
Date: Fri, 21 Sep 2018 00:01:54 +0100
Subject: [Tutor] Fwd: How to roughly associate the values of two numpy
 arrays, or python lists if necessary
In-Reply-To: <16a74aaf-92dc-36a0-d384-c217b5100e6d@btinternet.com>
References: <b4a33704-bee0-0534-9e5c-e26597e85931@kcl.ac.uk>
 <16a74aaf-92dc-36a0-d384-c217b5100e6d@btinternet.com>
Message-ID: <CAHVvXxTA3LvxPXwSYjnob3qGPU1jT343c4UuoDp+=yDejYr20w@mail.gmail.com>

Sydney wrote and Alan forwarded:

>
> I have, I suspect, an elementary problem that I am too inexperienced to
> resolve.
>
> I have two numpy arrays, each representing the values of a specific
> property of a set of cells.
>
> Now, I want to associate the two values for each cell, that is for each
> index of the numpy array. But I want to associate them ROUGHLY, that
> means, APPROXIMATELY, so that there is a weak, linear correlation
> between the values representing one property and the values representing
> the second property of each individual cell.
>
> Up to now I have used the following procedure.
> I have divided each population of values into four segments based on the
> value of the standard deviation thus.
>
> 1. values > mean + 1 std (sigma)
> 2. values > mean but < mean + 1 std (sigma)
> 3. values < mean but > mean + 1 std (sigma)
> 4. values < mean + 1 std (sigma).
>
> Then I randomly select a value from group 1 for the first property and I
> associate it with a randomly selected sample of the second property from
> its group 1. And so on through the total population. This gave me a very
> rough linear association between the two properties, but I am wondering
> whether I can do it in a simpler and better way.
>

Hi Sydney,

I feel like I would definitely be able to solve your problem if I
understood what you're talking about (I'm sure others here could as well).
Please don't be put off by this but I don't think you've explained it very
well.

Perhaps if you give an example of what the input and output of this
operation is supposed to look like then you would get a response. The
example might look like:

I have these arrays as input:

>>> property_a = [1, 6, 2, 4]
>>> property_b = [6, 3, 4, 6]

Then I want a function that gives me this output

>>> associated_values = myfunction(a, b)
>>> associated_values
[1, 3, 5, 2]

Some explanation why you want this, how you know that's the output you
want, and what any of it means would likely help...

If you already have something that does what you want then it would make
sense to show it but if your code is complicated then please try to
simplify it and use only a small amount of data when showing it here. There
is some advice for posting this kind of thing to a mailing list here:
http://sscce.org/

--
Oscar

From giannhskarlathras at gmail.com  Fri Sep 21 11:12:32 2018
From: giannhskarlathras at gmail.com (V E G E T A L)
Date: Fri, 21 Sep 2018 18:12:32 +0300
Subject: [Tutor] Python programming help!
Message-ID: <CAPzTrZHsYogndJG0tWrpTAxfL9kBwZUzUbWBihBpHpD+6JAgzw@mail.gmail.com>

Hello folks! So, I'm pretty much a noob still experimenting with basic
commands. I wanted to make a code that checks if the value of one variable
is less, equal or greater than the other. Pretty simple right? But then,
this problem emerged. I would really love some help, since I'm stuck and
can't figure out what I've done wrong.

PS: I'm using Anaconda and JupyterNotebook.

From sydney.shall at kcl.ac.uk  Fri Sep 21 07:16:37 2018
From: sydney.shall at kcl.ac.uk (Shall, Sydney)
Date: Fri, 21 Sep 2018 12:16:37 +0100
Subject: [Tutor] Fwd: How to roughly associate the values of two numpy
 arrays, or python lists if necessary
In-Reply-To: <CAHVvXxTA3LvxPXwSYjnob3qGPU1jT343c4UuoDp+=yDejYr20w@mail.gmail.com>
References: <b4a33704-bee0-0534-9e5c-e26597e85931@kcl.ac.uk>
 <16a74aaf-92dc-36a0-d384-c217b5100e6d@btinternet.com>
 <CAHVvXxTA3LvxPXwSYjnob3qGPU1jT343c4UuoDp+=yDejYr20w@mail.gmail.com>
Message-ID: <1aa3ffb7-43f3-fa59-6605-a009f29c5702@kcl.ac.uk>

On 21/09/2018 00:01, Oscar Benjamin wrote:
> Sydney wrote and Alan forwarded:
> 
>>
>> I have, I suspect, an elementary problem that I am too inexperienced to
>> resolve.
>>
>> I have two numpy arrays, each representing the values of a specific
>> property of a set of cells.
>>
>> Now, I want to associate the two values for each cell, that is for each
>> index of the numpy array. But I want to associate them ROUGHLY, that
>> means, APPROXIMATELY, so that there is a weak, linear correlation
>> between the values representing one property and the values representing
>> the second property of each individual cell.
>>
>> Up to now I have used the following procedure.
>> I have divided each population of values into four segments based on the
>> value of the standard deviation thus.
>>
>> 1. values > mean + 1 std (sigma)
>> 2. values > mean but < mean + 1 std (sigma)
>> 3. values < mean but > mean + 1 std (sigma)
>> 4. values < mean + 1 std (sigma).
>>
>> Then I randomly select a value from group 1 for the first property and I
>> associate it with a randomly selected sample of the second property from
>> its group 1. And so on through the total population. This gave me a very
>> rough linear association between the two properties, but I am wondering
>> whether I can do it in a simpler and better way.
>>
> 
> Hi Sydney,
> 
> I feel like I would definitely be able to solve your problem if I
> understood what you're talking about (I'm sure others here could as well).
> Please don't be put off by this but I don't think you've explained it very
> well.
> 
> Perhaps if you give an example of what the input and output of this
> operation is supposed to look like then you would get a response. The
> example might look like:
> 
> I have these arrays as input:
> 
>>>> property_a = [1, 6, 2, 4]
>>>> property_b = [6, 3, 4, 6]
> 
> Then I want a function that gives me this output
> 
>>>> associated_values = myfunction(a, b)
>>>> associated_values
> [1, 3, 5, 2]
> 
> Some explanation why you want this, how you know that's the output you
> want, and what any of it means would likely help...
> 
> If you already have something that does what you want then it would make
> sense to show it but if your code is complicated then please try to
> simplify it and use only a small amount of data when showing it here. There
> is some advice for posting this kind of thing to a mailing list here:
> https://emea01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fsscce.org%2F&amp;data=01%7C01%7Csydney.shall%40kcl.ac.uk%7C77fe088889364c79190308d61f4d4112%7C8370cf1416f34c16b83c724071654356%7C0&amp;sdata=DAhLxDli1vM%2BBcRXKemRo0sa%2BVJErJPZ%2Bwy5UHvUR4s%3D&amp;reserved=0
> 
> --
> Oscar
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutor&amp;data=01%7C01%7Csydney.shall%40kcl.ac.uk%7C77fe088889364c79190308d61f4d4112%7C8370cf1416f34c16b83c724071654356%7C0&amp;sdata=Benb%2BsxqZr1Rhdj8jG81KRurndfNVnBGx0%2B3z9VXd54%3D&amp;reserved=0
> 
Thank you Oscar. Fair comment.

What I want is the following.

I have:
 > property_a = [1, 6, 2, 4]
 > property_b = [62, 73, 31 102]

Result should approximately be:
 > property_b = [31, 102, 62, 73]

That is both lists change in value in exactly the same order.

Now, this is easy to achieve. I could simply sort both lists is 
ascending order and I would then have an exact alignment of values is 
ascending order. The correlation would be a perfect linear relationship, 
I suppose.

But my actual scientific problem requires that the correlation should be 
only approximate and I do not know how close to to a perfect correlation 
it should be. So, I need to introduce some lack of good correlation when 
I set up the correlation. How to do that is my problem.

I hope this helps to clarify what my problem is.

Sydney

-- 

_________

Professor Sydney Shall
Department of Haematology/Oncology
Phone: +(0)2078489200
E-Mail: sydney.shall
[Correspondents outside the College should add @kcl.ac.uk]

From wachobc at gmail.com  Fri Sep 21 08:21:27 2018
From: wachobc at gmail.com (Chip Wachob)
Date: Fri, 21 Sep 2018 08:21:27 -0400
Subject: [Tutor] Best solution to modifying code within a distributed
 library
In-Reply-To: <96c5629e-7eb9-e5b8-3b5e-e37cce6da299@wichmann.us>
References: <CADUn+-K+KNjy9HJSLta8JnUEN_+_+Z0Jt324MZW3xt2rF3zbKA@mail.gmail.com>
 <d4b091df-95bc-3175-d259-104af78583e3@wichmann.us>
 <CADUn+-LX9cexmznj_h1hQcmq5XzuJMs_JY7H2Mdvk+7CG4Rr5w@mail.gmail.com>
 <96c5629e-7eb9-e5b8-3b5e-e37cce6da299@wichmann.us>
Message-ID: <CADUn+-+1NNFHfuZzy-npVicLxtmiYA_j-rK7Nr79K4_sjD7XuA@mail.gmail.com>

Looks like I'm golden in this regard.  My first path element is ''
which is what I'd want if I'm including a modified library.

Thank you,



On Thu, Sep 20, 2018 at 6:14 PM, Mats Wichmann <mats at wichmann.us> wrote:
> On 09/19/2018 09:59 PM, Chip Wachob wrote:
>> Mats,
>>
>> Silly question here..
>>
>> But after using the git clone command, I've got a directory of the
>> Adafruit project in the same directory as my project.
>>
>> When I import the library, will I get the 'installed' library, or do I
>> get the library that is in the project directory?
>>
>> If I have to specify which library to use, how is that done?
>
> you look at, and possibly modify, sys.path
>
>
>   >>> import sys
>   >>> sys.path
>   ['', '/usr/lib64/python36.zip', '/usr/lib64/python3.6',
> '/usr/lib64/python3.6/lib-dynload',
> '/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages']
>
>
> the first element '' is the local directory, so with my sys.path, it
> would pick the local one first.
>
>
> if you wanted the opposite, that is be _sure_ you get the installed one,
> you could use a stanza something like this:
>
>
>    savepath = sys.path
>    sys.path = [path for path in sys.path if path.strip('.')]
>    import foo
>    sys.path = savepath
>
>
> but this is actually kind of tricky stuff, trying to deal with possibly
> two modules of the same name, so tread carefully.
>
>

From breamoreboy at gmail.com  Sun Sep 23 05:03:09 2018
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Sun, 23 Sep 2018 10:03:09 +0100
Subject: [Tutor] Python programming help!
In-Reply-To: <CAPzTrZHsYogndJG0tWrpTAxfL9kBwZUzUbWBihBpHpD+6JAgzw@mail.gmail.com>
References: <CAPzTrZHsYogndJG0tWrpTAxfL9kBwZUzUbWBihBpHpD+6JAgzw@mail.gmail.com>
Message-ID: <po7koa$j87$1@blaine.gmane.org>

On 21/09/18 16:12, V E G E T A L wrote:
> Hello folks! So, I'm pretty much a noob still experimenting with basic
> commands. I wanted to make a code that checks if the value of one variable
> is less, equal or greater than the other. Pretty simple right? But then,
> this problem emerged. I would really love some help, since I'm stuck and
> can't figure out what I've done wrong.
> 
> PS: I'm using Anaconda and JupyterNotebook.

Please post your code as there are some smart people on this list but 
we're not mind readers :)  Also state your OS and the Python version.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


From __peter__ at web.de  Sun Sep 23 05:42:00 2018
From: __peter__ at web.de (Peter Otten)
Date: Sun, 23 Sep 2018 11:42 +0200
Subject: [Tutor] Fwd: How to roughly associate the values of two numpy
 arrays, or python lists if necessary
References: <b4a33704-bee0-0534-9e5c-e26597e85931@kcl.ac.uk>
 <16a74aaf-92dc-36a0-d384-c217b5100e6d@btinternet.com>
 <CAHVvXxTA3LvxPXwSYjnob3qGPU1jT343c4UuoDp+=yDejYr20w@mail.gmail.com>
 <1aa3ffb7-43f3-fa59-6605-a009f29c5702@kcl.ac.uk>
Message-ID: <po7n18$krq$1@blaine.gmane.org>

Shall, Sydney via Tutor wrote:

> What I want is the following.
> 
> I have:
> > property_a = [1, 6, 2, 4]
> > property_b = [62, 73, 31 102]
> 
> Result should approximately be:
> > property_b = [31, 102, 62, 73]
> 
> That is both lists change in value in exactly the same order.
> 
> Now, this is easy to achieve. I could simply sort both lists is
> ascending order and I would then have an exact alignment of values is
> ascending order. The correlation would be a perfect linear relationship,
> I suppose.
> 
> But my actual scientific problem requires that the correlation should be
> only approximate and I do not know how close to to a perfect correlation
> it should be. So, I need to introduce some lack of good correlation when
> I set up the correlation. How to do that is my problem.
> 
> I hope this helps to clarify what my problem is.

Maybe you could sort the already-sorted property_b again, with some random 
offset:

>>> import itertools
>>> def wiggled(items, sigma):
...     counter = itertools.count()
...     def key(item): return random.gauss(next(counter), sigma)
...     return sorted(items, key=key)
... 
>>> wiggled(range(20), 3)
[0, 5, 2, 4, 1, 6, 7, 8, 3, 9, 11, 10, 13, 14, 16, 12, 18, 17, 19, 15]
>>> wiggled([31, 102, 62, 73], .8)
[102, 31, 62, 73]
>>> wiggled([31, 102, 62, 73], .8)
[31, 102, 62, 73]
>>> wiggled([31, 102, 62, 73], .8)
[31, 102, 62, 73]
>>> wiggled([31, 102, 62, 73], .8)
[31, 62, 102, 73]



From __peter__ at web.de  Sun Sep 23 08:04:32 2018
From: __peter__ at web.de (Peter Otten)
Date: Sun, 23 Sep 2018 14:04:32 +0200
Subject: [Tutor] Fwd: How to roughly associate the values of two numpy
 arrays, or python lists if necessary
References: <b4a33704-bee0-0534-9e5c-e26597e85931@kcl.ac.uk>
 <16a74aaf-92dc-36a0-d384-c217b5100e6d@btinternet.com>
 <CAHVvXxTA3LvxPXwSYjnob3qGPU1jT343c4UuoDp+=yDejYr20w@mail.gmail.com>
 <1aa3ffb7-43f3-fa59-6605-a009f29c5702@kcl.ac.uk>
 <po7n18$krq$1@blaine.gmane.org>
Message-ID: <po7vch$mqa$1@blaine.gmane.org>

Peter Otten wrote:

> Maybe you could sort the already-sorted property_b again, with some random
> offset:
> 
>>>> import itertools
>>>> def wiggled(items, sigma):
> ...     counter = itertools.count()
> ...     def key(item): return random.gauss(next(counter), sigma)
> ...     return sorted(items, key=key)
> ...

One more example:

>>> s = """\
... But my actual scientific problem requires that the correlation should be 
... only approximate and I do not know how close to to a perfect correlation 
... it should be. So, I need to introduce some lack of good correlation when 
... I set up the correlation. How to do that is my problem.
... """
>>> print(textwrap.fill(" ".join(wiggled(s.split(), 2))))
But actual my scientific the requires that problem should only
correlation approximate be and not do I know how close to a perfect to
correlation should it So, be. I to lack need some introduce
correlation I of good when set correlation. up How to the that do
problem. is my

:)


From bgailer at gmail.com  Sun Sep 23 09:25:10 2018
From: bgailer at gmail.com (Bob Gailer)
Date: Sun, 23 Sep 2018 09:25:10 -0400
Subject: [Tutor] Python programming help!
In-Reply-To: <CAPzTrZHsYogndJG0tWrpTAxfL9kBwZUzUbWBihBpHpD+6JAgzw@mail.gmail.com>
References: <CAPzTrZHsYogndJG0tWrpTAxfL9kBwZUzUbWBihBpHpD+6JAgzw@mail.gmail.com>
Message-ID: <CAP1rxO6HG3RY-Cj=Sq58ATORy86PvYV7_e40cMn8RDTUtVxuug@mail.gmail.com>

On Sep 23, 2018 3:33 AM, "V E G E T A L" <giannhskarlathras at gmail.com>
wrote:
>
> Hello folks! So, I'm pretty much a noob still experimenting with basic
> commands. I wanted to make a code that checks if the value of one variable
> is less, equal or greater than the other. Pretty simple right? But then,

> this problem emerged.

What problem? I don't see any problem here. If you provided an attachment
this email list does not forward attachments.

The proper way is to copy and paste directly into the body of the email.

If you did not attempt to show us the problem, why? You certainly can't
expect us to read your mind.

I would really love some help, since I'm stuck and
> can't figure out what I've done wrong.
>
> PS: I'm using Anaconda and JupyterNotebook.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

From sydney.shall at kcl.ac.uk  Sun Sep 23 07:00:55 2018
From: sydney.shall at kcl.ac.uk (Shall, Sydney)
Date: Sun, 23 Sep 2018 12:00:55 +0100
Subject: [Tutor] Fwd: How to roughly associate the values of two numpy
 arrays, or python lists if necessary
In-Reply-To: <po7n18$krq$1@blaine.gmane.org>
References: <b4a33704-bee0-0534-9e5c-e26597e85931@kcl.ac.uk>
 <16a74aaf-92dc-36a0-d384-c217b5100e6d@btinternet.com>
 <CAHVvXxTA3LvxPXwSYjnob3qGPU1jT343c4UuoDp+=yDejYr20w@mail.gmail.com>
 <1aa3ffb7-43f3-fa59-6605-a009f29c5702@kcl.ac.uk>
 <po7n18$krq$1@blaine.gmane.org>
Message-ID: <b9c5af24-63c0-8adb-5755-0327129c8e60@kcl.ac.uk>

On 23/09/2018 10:42, Peter Otten wrote:
> Shall, Sydney via Tutor wrote:
> 
>> What I want is the following.
>>
>> I have:
>>> property_a = [1, 6, 2, 4]
>>> property_b = [62, 73, 31 102]
>>
>> Result should approximately be:
>>> property_b = [31, 102, 62, 73]
>>
>> That is both lists change in value in exactly the same order.
>>
>> Now, this is easy to achieve. I could simply sort both lists is
>> ascending order and I would then have an exact alignment of values is
>> ascending order. The correlation would be a perfect linear relationship,
>> I suppose.
>>
>> But my actual scientific problem requires that the correlation should be
>> only approximate and I do not know how close to to a perfect correlation
>> it should be. So, I need to introduce some lack of good correlation when
>> I set up the correlation. How to do that is my problem.
>>
>> I hope this helps to clarify what my problem is.
> 
> Maybe you could sort the already-sorted property_b again, with some random
> offset:
> 
>>>> import itertools
>>>> def wiggled(items, sigma):
> ...     counter = itertools.count()
> ...     def key(item): return random.gauss(next(counter), sigma)
> ...     return sorted(items, key=key)
> ...
>>>> wiggled(range(20), 3)
> [0, 5, 2, 4, 1, 6, 7, 8, 3, 9, 11, 10, 13, 14, 16, 12, 18, 17, 19, 15]
>>>> wiggled([31, 102, 62, 73], .8)
> [102, 31, 62, 73]
>>>> wiggled([31, 102, 62, 73], .8)
> [31, 102, 62, 73]
>>>> wiggled([31, 102, 62, 73], .8)
> [31, 102, 62, 73]
>>>> wiggled([31, 102, 62, 73], .8)
> [31, 62, 102, 73]
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutor&amp;data=01%7C01%7Csydney.shall%40kcl.ac.uk%7Cb9cbdce8c20e45dd3ff508d621390143%7C8370cf1416f34c16b83c724071654356%7C0&amp;sdata=yNo7hMVl7dYmH6d74MBaab5e5g6bPoWoqkza5TS1bXY%3D&amp;reserved=0
> 


Thanks to Oscar and to Pater for their help. They have set me on the 
correct path.
The crucial advice to was to look at the randomisation procedures. I 
have used a procedure similar to that suggested by Peter and it works well.

Cheers,

Sydney

_________

Professor Sydney Shall
Department of Haematology/Oncology
Phone: +(0)2078489200
E-Mail: sydney.shall
[Correspondents outside the College should add @kcl.ac.uk]

From sydney.shall at kcl.ac.uk  Sun Sep 23 08:08:42 2018
From: sydney.shall at kcl.ac.uk (Shall, Sydney)
Date: Sun, 23 Sep 2018 13:08:42 +0100
Subject: [Tutor] Fwd: How to roughly associate the values of two numpy
 arrays, or python lists if necessary
In-Reply-To: <po7vch$mqa$1@blaine.gmane.org>
References: <b4a33704-bee0-0534-9e5c-e26597e85931@kcl.ac.uk>
 <16a74aaf-92dc-36a0-d384-c217b5100e6d@btinternet.com>
 <CAHVvXxTA3LvxPXwSYjnob3qGPU1jT343c4UuoDp+=yDejYr20w@mail.gmail.com>
 <1aa3ffb7-43f3-fa59-6605-a009f29c5702@kcl.ac.uk>
 <po7n18$krq$1@blaine.gmane.org> <po7vch$mqa$1@blaine.gmane.org>
Message-ID: <54ccc8b0-93c0-d8b1-6890-d3426eb1f6c1@kcl.ac.uk>

On 23/09/2018 13:04, Peter Otten wrote:
> Peter Otten wrote:
> 
>> Maybe you could sort the already-sorted property_b again, with some random
>> offset:
>>
>>>>> import itertools
>>>>> def wiggled(items, sigma):
>> ...     counter = itertools.count()
>> ...     def key(item): return random.gauss(next(counter), sigma)
>> ...     return sorted(items, key=key)
>> ...
> 
> One more example:
> 
>>>> s = """\
> ... But my actual scientific problem requires that the correlation should be
> ... only approximate and I do not know how close to to a perfect correlation
> ... it should be. So, I need to introduce some lack of good correlation when
> ... I set up the correlation. How to do that is my problem.
> ... """
>>>> print(textwrap.fill(" ".join(wiggled(s.split(), 2))))
> But actual my scientific the requires that problem should only
> correlation approximate be and not do I know how close to a perfect to
> correlation should it So, be. I to lack need some introduce
> correlation I of good when set correlation. up How to the that do
> problem. is my
> 
> :)
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutor&amp;data=01%7C01%7Csydney.shall%40kcl.ac.uk%7C185332cee28f49ed465108d6214ce8ab%7C8370cf1416f34c16b83c724071654356%7C0&amp;sdata=GBAb%2FdY2zrBqSwOl33ejT%2BzzknQx5RYNXsNEqZQXCX4%3D&amp;reserved=0
> 
Thanks. Most useful.

Sydney

-- 

_________

Professor Sydney Shall
Department of Haematology/Oncology
Phone: +(0)2078489200
E-Mail: sydney.shall
[Correspondents outside the College should add @kcl.ac.uk]

From noflaco at gmail.com  Sun Sep 23 09:29:38 2018
From: noflaco at gmail.com (Carlton Banks)
Date: Sun, 23 Sep 2018 15:29:38 +0200
Subject: [Tutor] Python programming help!
In-Reply-To: <CAP1rxO6HG3RY-Cj=Sq58ATORy86PvYV7_e40cMn8RDTUtVxuug@mail.gmail.com>
References: <CAPzTrZHsYogndJG0tWrpTAxfL9kBwZUzUbWBihBpHpD+6JAgzw@mail.gmail.com>
 <CAP1rxO6HG3RY-Cj=Sq58ATORy86PvYV7_e40cMn8RDTUtVxuug@mail.gmail.com>
Message-ID: <CAEwV4UbG3sPD8Sx088032Vh94Ztzmz839RNF=xAjM2fPvPSzsg@mail.gmail.com>

Without having Seen the code, use og statements.. but please provide is the
code...

s?n. 23. sep. 2018 15.26 skrev Bob Gailer <bgailer at gmail.com>:

> On Sep 23, 2018 3:33 AM, "V E G E T A L" <giannhskarlathras at gmail.com>
> wrote:
> >
> > Hello folks! So, I'm pretty much a noob still experimenting with basic
> > commands. I wanted to make a code that checks if the value of one
> variable
> > is less, equal or greater than the other. Pretty simple right? But then,
>
> > this problem emerged.
>
> What problem? I don't see any problem here. If you provided an attachment
> this email list does not forward attachments.
>
> The proper way is to copy and paste directly into the body of the email.
>
> If you did not attempt to show us the problem, why? You certainly can't
> expect us to read your mind.
>
> I would really love some help, since I'm stuck and
> > can't figure out what I've done wrong.
> >
> > PS: I'm using Anaconda and JupyterNotebook.
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

From giannhskarlathras at gmail.com  Sun Sep 23 09:31:51 2018
From: giannhskarlathras at gmail.com (V E G E T A L)
Date: Sun, 23 Sep 2018 16:31:51 +0300
Subject: [Tutor] Python programming help!
In-Reply-To: <CAP1rxO6HG3RY-Cj=Sq58ATORy86PvYV7_e40cMn8RDTUtVxuug@mail.gmail.com>
References: <CAPzTrZHsYogndJG0tWrpTAxfL9kBwZUzUbWBihBpHpD+6JAgzw@mail.gmail.com>
 <CAP1rxO6HG3RY-Cj=Sq58ATORy86PvYV7_e40cMn8RDTUtVxuug@mail.gmail.com>
Message-ID: <CAPzTrZFJgB0UjexsKC66LqnNhFQ3hAtu_nFLbTFT=--iLYy0Mw@mail.gmail.com>

Wow, didn't know attachments didn't work. I had posted my screenshot as an
attachment, never expected you to read my mind. I solved the problem, it
was a spelling mistake (I know, I'm stupid). Thank a lot though!

???? ???, 23 ??? 2018 - 16:25 ? ??????? Bob Gailer <bgailer at gmail.com>
??????:

> On Sep 23, 2018 3:33 AM, "V E G E T A L" <giannhskarlathras at gmail.com>
> wrote:
> >
> > Hello folks! So, I'm pretty much a noob still experimenting with basic
> > commands. I wanted to make a code that checks if the value of one
> variable
> > is less, equal or greater than the other. Pretty simple right? But then,
>
> > this problem emerged.
>
> What problem? I don't see any problem here. If you provided an attachment
> this email list does not forward attachments.
>
> The proper way is to copy and paste directly into the body of the email.
>
> If you did not attempt to show us the problem, why? You certainly can't
> expect us to read your mind.
>
> I would really love some help, since I'm stuck and
> > can't figure out what I've done wrong.
> >
> > PS: I'm using Anaconda and JupyterNotebook.
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
>

From rahulkoparde5 at gmail.com  Fri Sep 28 15:03:45 2018
From: rahulkoparde5 at gmail.com (Rahul Koparde)
Date: Sat, 29 Sep 2018 00:33:45 +0530
Subject: [Tutor] Installing new modules
Message-ID: <CAB8G7hPs8=1o_paM=irF-dzs=K6uF27SZF3XfWiEKiMxZF_UEg@mail.gmail.com>

How to install twilio module in python?

From breamoreboy at gmail.com  Fri Sep 28 18:56:00 2018
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Fri, 28 Sep 2018 23:56:00 +0100
Subject: [Tutor] Installing new modules
In-Reply-To: <CAB8G7hPs8=1o_paM=irF-dzs=K6uF27SZF3XfWiEKiMxZF_UEg@mail.gmail.com>
References: <CAB8G7hPs8=1o_paM=irF-dzs=K6uF27SZF3XfWiEKiMxZF_UEg@mail.gmail.com>
Message-ID: <pombdt$dvg$1@blaine.gmane.org>

On 28/09/18 20:03, Rahul Koparde wrote:
> How to install twilio module in python?

pip

I'll let you do the rest of the research.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


From alan.gauld at yahoo.co.uk  Sat Sep 29 04:00:29 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sat, 29 Sep 2018 09:00:29 +0100
Subject: [Tutor] Installing new modules
In-Reply-To: <CAB8G7hPs8=1o_paM=irF-dzs=K6uF27SZF3XfWiEKiMxZF_UEg@mail.gmail.com>
References: <CAB8G7hPs8=1o_paM=irF-dzs=K6uF27SZF3XfWiEKiMxZF_UEg@mail.gmail.com>
Message-ID: <ponbaq$skg$1@blaine.gmane.org>

On 28/09/18 20:03, Rahul Koparde wrote:
> How to install twilio module in python?

Searching "python install twilio" on Google yielded:

https://stackoverflow.com/questions/51985401/how-to-install-twilio-via-pip

It may help.


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From steve at pearwood.info  Sat Sep 29 11:58:47 2018
From: steve at pearwood.info (Steven D'Aprano)
Date: Sun, 30 Sep 2018 01:58:47 +1000
Subject: [Tutor] Best solution to modifying code within a distributed
 library
In-Reply-To: <CADUn+-K+KNjy9HJSLta8JnUEN_+_+Z0Jt324MZW3xt2rF3zbKA@mail.gmail.com>
References: <CADUn+-K+KNjy9HJSLta8JnUEN_+_+Z0Jt324MZW3xt2rF3zbKA@mail.gmail.com>
Message-ID: <20180929155847.GD19437@ando.pearwood.info>

On Wed, Sep 19, 2018 at 05:47:07PM -0400, Chip Wachob wrote:

[...]
> I've looked through the code in the FT232H.py file and found what I
> believe to be the culprit.
> 
> I would like to comment out line 340 (self.mpsse_write_gpio()) to
> prove that this is what is causing glitches that I do not want.

Since you don't have the source file, it might work to monkey patch the 
library. Beware: monkey patching is an advanced technique, hard to get 
right. But when it works, it can work very well.

https://en.wikipedia.org/wiki/Monkey_patch

Not to be confused with this:
https://en.wikipedia.org/wiki/Scratch_monkey


Let me assume that self.mpsse_write_gpio is *only* called from that one 
line 340, and nowhere else. If that's the case, you take your code which 
might look something like this:

import FT232H
obj = FT232H.SomeClass()  # initialise an instance
obj.run()

(let's say), and add a monkey patch that replaces the suspect 
mpsse_write_gpio method with a Do Nothing function:


import FT232H
obj = FT232H.SomeClass()  # initialise an instance
obj.mpsse_write_gpio = lambda self: None
obj.run()


The beauty of this is you don't need the source code! It all happens 
with the live code in the interpreter.

On the other hand, it might be that the suspect method is called from 
all over the place, and you only want to patch that *one* call on a 
single line. That's much harder and will require much ingenuity to 
solve. At that point, you might be better of just getting the source 
code and editing it.



-- 
Steve

From jorgherrera96 at gmail.com  Sat Sep 29 21:22:14 2018
From: jorgherrera96 at gmail.com (Jorge Herrera)
Date: Sat, 29 Sep 2018 20:22:14 -0500
Subject: [Tutor] tkinter
Message-ID: <CAOUPs1H1hwW2crBo1Shwtg2mO0xW5RyT6Vtw_YpZUq4gv2N1Pw@mail.gmail.com>

Hello, I'm new to Python and I've been having a frustrating time with
python because I'm trying to import tkinter and it's saying that tkinter is
not defined, that it doesn't exist and now i'm not able to run some of my
programs since it states that there is no module named tkinter. If you
could help that would be great!

Sincerely,

Jorge Herrera
jorgherrera96 at gmail.com

From alan.gauld at yahoo.co.uk  Sun Sep 30 03:47:32 2018
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sun, 30 Sep 2018 08:47:32 +0100
Subject: [Tutor] tkinter
In-Reply-To: <CAOUPs1H1hwW2crBo1Shwtg2mO0xW5RyT6Vtw_YpZUq4gv2N1Pw@mail.gmail.com>
References: <CAOUPs1H1hwW2crBo1Shwtg2mO0xW5RyT6Vtw_YpZUq4gv2N1Pw@mail.gmail.com>
Message-ID: <popuuh$juu$1@blaine.gmane.org>

On 30/09/18 02:22, Jorge Herrera wrote:
> Hello, I'm new to Python and I've been having a frustrating time with
> python because I'm trying to import tkinter and it's saying that tkinter is
> not defined, that it doesn't exist 

That suggests that Tkinter is not installed on your system.
What OS are you using?

If it is Linux then its common that you have to install tkinter
separately from the basic python package. Its usually called
python-tkinter or somesuch in the package manager.
Be sure to match the version number with your Python version.

If its MacOS then the system python doesn't (or didn't last
time I tried)  come with tkinter so you need to download
the latest MacOS python installer and install it (Do not
uninstall the system version though - the OS needs it!)

On Windows tkinter should be present.

If the suggestions above don't work then come back to
us with more details:
- Your OS
- Your Python version
- A cut n' paste of the full error message that you get

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



From breamoreboy at gmail.com  Sun Sep 30 15:44:13 2018
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Sun, 30 Sep 2018 20:44:13 +0100
Subject: [Tutor] tkinter
In-Reply-To: <popuuh$juu$1@blaine.gmane.org>
References: <CAOUPs1H1hwW2crBo1Shwtg2mO0xW5RyT6Vtw_YpZUq4gv2N1Pw@mail.gmail.com>
 <popuuh$juu$1@blaine.gmane.org>
Message-ID: <por8ua$so8$1@blaine.gmane.org>

On 30/09/18 08:47, Alan Gauld via Tutor wrote:
> On 30/09/18 02:22, Jorge Herrera wrote:
>> Hello, I'm new to Python and I've been having a frustrating time with
>> python because I'm trying to import tkinter and it's saying that tkinter is
>> not defined, that it doesn't exist
> 
> That suggests that Tkinter is not installed on your system.
> What OS are you using?
>

It could be as simple as the spelling, it's Tkinter for Python 2 but 
tkinter for Python 3.

> If it is Linux then its common that you have to install tkinter
> separately from the basic python package. Its usually called
> python-tkinter or somesuch in the package manager.
> Be sure to match the version number with your Python version.
> 
> If its MacOS then the system python doesn't (or didn't last
> time I tried)  come with tkinter so you need to download
> the latest MacOS python installer and install it (Do not
> uninstall the system version though - the OS needs it!)
> 
> On Windows tkinter should be present.
> 
> If the suggestions above don't work then come back to
> us with more details:
> - Your OS
> - Your Python version
> - A cut n' paste of the full error message that you get
> 
> HTH
> 

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence