From george at fischhof.hu  Fri Feb  1 10:42:13 2019
From: george at fischhof.hu (George Fischhof)
Date: Fri, 1 Feb 2019 16:42:13 +0100
Subject: [Tutor] How to get Selenium to wait for page load
In-Reply-To: <001601d4b94e$e62ddce0$b28996a0$@gmail.com>
References: <001601d4b94e$e62ddce0$b28996a0$@gmail.com>
Message-ID: <CAFwcP0gvm5vYELmtZ4uXs9HaiDf1mE2nsS1h345J98RZ6KgZjg@mail.gmail.com>

<mhysnm1964 at gmail.com> ezt ?rta (id?pont: 2019. jan. 31., Cs 12:07):

> Hi all,
>
>
>
> I have found an excellent article on identifying stale elements. The issue
> is when I try and use their example code. I get a failure where for_wait is
> not defined.
>
>
> http://www.obeythetestinggoat.com/how-to-get-selenium-to-wait-for-page-load-
> after-a-click.html
> <http://www.obeythetestinggoat.com/how-to-get-selenium-to-wait-for-page-load-after-a-click.html>
>
>
>
> Traceback (most recent call last):
> File "<stdin>", line 5, in <module>
> NameError: name 'wait_for' is not defined
> >>>
>
>
>
> When I look through the examples. I only find one reference for the above
> function. But it doesn't look correct and I am confused. The author
> indicates the definition of the function is half way up the page. As I
> cannot see, this reference doesn't help. So can someone help and provide
> the
> definition for this method/function?
>
>
>
> The code which generated the error:
>
>
>
> rows = []
>
> pageNav = browser.find_element_by_id("center-5")
>
> curr_page = pageNav.find_element_by_css_selector('span
> .pageNumberElement').text
>
> prev_page = ""
>
> while prev_page in curr_page:
>
> #    wait_for(link_has_gone_stale):
>
>     prev_page = curr_page
>
>     rows.extend(tableNavigation (pageNav))
>
>     if wait_for(link_has_gone_stale):
>
>         pageNav = browser.find_element_by_id("center-5")
>
>     curr_page = pageNav.find_element_by_css_selector('span
> .pageNumberElement').text
>
>     if prev_page == curr_page:
>
>         print ("Page no has not changed:",curr_page)
>
>     else:
>
>         prev_page = curr_page
>
>
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor



Hi,

Try splinter package.
That is an abstraction layer over selenium, and exactly does similar things.

__george__

>
>

From mhysnm1964 at gmail.com  Fri Feb  1 16:27:55 2019
From: mhysnm1964 at gmail.com (mhysnm1964 at gmail.com)
Date: Sat, 2 Feb 2019 08:27:55 +1100
Subject: [Tutor] How to get Selenium to wait for page load
In-Reply-To: <CAFwcP0gvm5vYELmtZ4uXs9HaiDf1mE2nsS1h345J98RZ6KgZjg@mail.gmail.com>
References: <001601d4b94e$e62ddce0$b28996a0$@gmail.com>
 <CAFwcP0gvm5vYELmtZ4uXs9HaiDf1mE2nsS1h345J98RZ6KgZjg@mail.gmail.com>
Message-ID: <005a01d4ba75$00e95a60$02bc0f20$@gmail.com>

Everyone,

 

Thanks for the pointers. 

 

From: George Fischhof <george at fischhof.hu> 
Sent: Saturday, 2 February 2019 2:42 AM
To: mhysnm1964 at gmail.com
Cc: tutor at python.org
Subject: Re: [Tutor] How to get Selenium to wait for page load

 

 

<mhysnm1964 at gmail.com <mailto:mhysnm1964 at gmail.com> > ezt ?rta (id?pont: 2019. jan. 31., Cs 12:07):

Hi all,



I have found an excellent article on identifying stale elements. The issue
is when I try and use their example code. I get a failure where for_wait is
not defined.

http://www.obeythetestinggoat.com/how-to-get-selenium-to-wait-for-page-load- <http://www.obeythetestinggoat.com/how-to-get-selenium-to-wait-for-page-load-after-a-click.html> 
after-a-click.html



Traceback (most recent call last): 
File "<stdin>", line 5, in <module> 
NameError: name 'wait_for' is not defined 
>>>



When I look through the examples. I only find one reference for the above
function. But it doesn't look correct and I am confused. The author
indicates the definition of the function is half way up the page. As I
cannot see, this reference doesn't help. So can someone help and provide the
definition for this method/function?



The code which generated the error:



rows = []

pageNav = browser.find_element_by_id("center-5")

curr_page = pageNav.find_element_by_css_selector('span
.pageNumberElement').text

prev_page = ""

while prev_page in curr_page:

#    wait_for(link_has_gone_stale):

    prev_page = curr_page  

    rows.extend(tableNavigation (pageNav))

    if wait_for(link_has_gone_stale):

        pageNav = browser.find_element_by_id("center-5")

    curr_page = pageNav.find_element_by_css_selector('span
.pageNumberElement').text

    if prev_page == curr_page:

        print ("Page no has not changed:",curr_page)

    else:

        prev_page = curr_page





_______________________________________________
Tutor maillist  -  Tutor at python.org <mailto:Tutor at python.org> 
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

 

 

Hi, 

 

Try splinter package.

That is an abstraction layer over selenium, and exactly does similar things.

 

__george__

 


From matthew.polack at htlc.vic.edu.au  Mon Feb  4 00:14:39 2019
From: matthew.polack at htlc.vic.edu.au (Matthew Polack)
Date: Mon, 4 Feb 2019 16:14:39 +1100
Subject: [Tutor] Recommended Resurce or strategy for beginning students
In-Reply-To: <BFD53651-10EF-4111-A683-ED0A0EEABF43@gmail.com>
References: <CAFkpTin2MMDYzZsHv-JHGFDJafMaJ8xRp8BnAVai_kdEqLQf0A@mail.gmail.com>
 <MWHPR11MB17107F8F47ABE097F721F8B6E0980@MWHPR11MB1710.namprd11.prod.outlook.com>
 <BFD53651-10EF-4111-A683-ED0A0EEABF43@gmail.com>
Message-ID: <CAFkpTi=eCXyF8yrzPfL51cB3Jbmk03nD7=SVCd0cEx2tWqgdEg@mail.gmail.com>

Hi All,

Firstly thanks so much for all the suggestions a while back re: recommended
method for Python...really appreciate the ideas.

We had our first lesson today (With 15 year olds) where I started with the
basic command line..and did a simple "Hello World" type program...just to
show how something could be run straight from notepad and command line...

We then went to IDLE and made a simple 'Maths Calculator'....

All of this went quite well...but as the long session started to wind down
(Is a double lesson on a Monday)...I did start to notice the following:

1.) One group of students (probably most)..actively problem solving..trying
things...googling all sorts of ways of improving their code...figuring out
new ways of doing things...will go a long way.
2.) Another smaller group started to hit the wall...and were struggling for
internal drive...needed to be 'hand fed'

Is going to be interesting going forward how to both cater for the
'indpendent workers' whilst still keeping the 'unenthused unless
entertained' group engaged! The joys of teaching...but will certainly try
some of the suggestions mentioned...PySimpleGUI..Turtle graphics
etc....they will be very helpful. Thanks.


Matthew Polack | Teacher


[image: Emailbanner3.png]

Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.polack at htlc.vic.edu.au

w. www.htlc.vic.edu.au


On Wed, Jan 23, 2019 at 1:21 PM Sean Murphy <mhysnm1964 at gmail.com> wrote:

> I like this concept. The only additional information I would add in
> relation to any training or educational information. You must include
> accessibility. As the laws in many countries require this to be a part of
> the product. So it is a perfect time to educate students on this important
> topic. A high level awareness is required only.
> Introducing the basics. Keyboard navigation, colour contrast, ensuring the
> GUI works with a screen reader. The platforms used for GUI should do most
> of the heavy lifting.
>
> The other aspect is you need to ensure the course is accessible to
> possible disable students for now and the future. If you are based in the
> Usa. Then there could be legal requirements for this. Not sure. Out of my
> scope of focus in the accessibility world.
>
>
> A bare minimum is to understand the bare basics which are called POUR.
> Reference W3C for the explaination.
>
> Sean
>
> My experience is the part
>
> > On 23 Jan 2019, at 1:17 am, Mike Barnett <mike_barnett at hotmail.com>
> wrote:
> >
> > I like the idea of starting out right away on a GUI.  I know this is
> completely backwards to what would normally be taught, but hear me out.
> Kids today are used to GUI interfaces.  They're on their phones, their
> computers, their TV  sets.
> >
> > Why not teach kids to output to a window instead of a command line?
> What if it's just was easy, or easier, to work with a GUI as it is the
> command line?
> >
> > To output to the command line in standard Python:
> > print('my string', variable1, variable2)
> >
> > To output the same information to a window using PySimpleGUI:
> > Popup('my string', variable1, variable2)
> >
> > Or, you can "print" to a debug window if that's your thing.
> > Print('takes the same parameters as print')
> >
> > If the ultimate goal is to teach kids about how to design a GUI window,
> how to lay out a GUI using good user interface design principals, then it
> would be nice to get the GUI coding out of the way and let the focus
> instead be on the GUI itself.  This is when having a drag-and-drop Designer
> Tool is handy.  If not, then the next best thing is a simple programming
> interface.
> >
> > PySimpleGUI was designed so that the code visually matches the window
> layout.
> >
> > It's capable of duplicating pretty much any layout and widget
> combination that you can create coding directly to tkinter's (or Qt's or
> WxPython's) interfaces.  PySimpleGUI simply creates and executes the
> "boilerplate" code that is often brought up when GUIs are discussed.
> >
> > A goal was to remove all of the boilerplate code and provide a
> programmer with a simple, friendly and flexible set of APIs.  You write a
> single line of code per row of widgets in your window plus a 1/2 dozen
> lines to implement the event loop.
> >
> > I don't see the harm in approaching the problem from a different
> direction.  It could be wildly successful.  Or... not...  The worst that
> can happen is you screw up a classroom full of future programmers, creating
> a warped vision that GUIs can be fun and easy.
> >
> >
> > @mike
> >
> > -----Original Message-----
> > From: Matthew Polack <matthew.polack at htlc.vic.edu.au>
> > Sent: Tuesday, January 22, 2019 1:58 AM
> > To: tutor at python.org
> > Subject: [Tutor] Recommended Resurce or strategy for beginning students
> >
> > Hi All,
> >
> > In our growing school we're teaching Python programming for the first
> time as an elective subject with Year 9 and 10 students. (Had a dabble at
> this last year with 3 students in Year 11)
> >
> > I'm wondering what specific resource or stategy people would recommend
> for absolute beginners?
> >
> > ie. a course or program, book,...set of activities to follow that
> strategically introduces and develops key skills.
> >
> > At this age level I don't think we need to be achieving 'rocket
> science'..but rather giving the students a good solid introduction.
> >
> > Some of the leadership wanted me to use this programming in combination
> with building robots...I've even wondered whether this is trying to achieve
> too many things...and we're better off focused on programming itself... but
> am open to this idea too...
> >
> > I've had a play with using the excellent PySimpleGUI...which is an
> excellent resource for building a GUI...but I've realised before doing too
> much of this we might need to get a grip on core fundamentals....
> >
> > The challenge is trying to find a way to making this 'fun' for students
> whilst also having them genuinely learn rather than just 'copying pasting'
> > code...achieving something that looks good...but not really
> understanding what they are doing.
> >
> > So far my strategy will be:
> >
> > 1.) Establish some core basics(utlising some form of 'course',,,which
> goes through basics of syntax..variables...loops etc. utilising just raw
> code...(probably a simple 'Adventure Game')
> > 2.) Build some simple programs using PySimple GUi..eg. Some quiz games
> etc.
> > (there are some great examples on Github by another teacher and also the
> author Mike of PySimpleGUI.
> > 3.) Possibly explore robotics.
> >
> > Can anyone make any recommendations on either resources or
> teaching/learning strategy/curriculum.
> >
> > Thank you,
> > Matt
> >
> >
> > Matthew Polack | Teacher
> >
> >
> > [image: Emailbanner3.png]
> >
> > Trinity Drive  |  PO Box 822
> >
> > Horsham Victoria 3402
> >
> > p. 03 5382 2529   m. 0402456854
> >
> > e. matthew.polack at htlc.vic.edu.au
> >
> > w. www.htlc.vic.edu.au
> >
> > --
> > **Disclaimer: *Whilst every attempt has been made to ensure that
> material contained in this email is free from computer viruses or other
> defects, the attached files are provided, and may only be used, on the
> basis that the user assumes all responsibility for use of the material
> transmitted. This email is intended only for the use of the individual or
> entity named above and may contain information that is confidential and
> privileged. If you are not the intended recipient, please note that any
> dissemination, distribution or copying of this email is strictly
> prohibited. If you have received this email in error, please notify us
> immediately by return email or telephone +61 3 5382 2529** and destroy the
> original message.*
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
>

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529**?and destroy the original message.*

From alan.gauld at yahoo.co.uk  Mon Feb  4 05:06:36 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 4 Feb 2019 10:06:36 +0000
Subject: [Tutor] Recommended Resurce or strategy for beginning students
In-Reply-To: <CAFkpTi=eCXyF8yrzPfL51cB3Jbmk03nD7=SVCd0cEx2tWqgdEg@mail.gmail.com>
References: <CAFkpTin2MMDYzZsHv-JHGFDJafMaJ8xRp8BnAVai_kdEqLQf0A@mail.gmail.com>
 <MWHPR11MB17107F8F47ABE097F721F8B6E0980@MWHPR11MB1710.namprd11.prod.outlook.com>
 <BFD53651-10EF-4111-A683-ED0A0EEABF43@gmail.com>
 <CAFkpTi=eCXyF8yrzPfL51cB3Jbmk03nD7=SVCd0cEx2tWqgdEg@mail.gmail.com>
Message-ID: <q392re$14hl$1@blaine.gmane.org>

On 04/02/2019 05:14, Matthew Polack wrote:

> We had our first lesson today

Congrats, hope it goes well.
But...

> 2.) Another smaller group started to hit the wall...

I'm not a professional or trained teacher but over
the last 30 years or so I've been involved in classes
teaching everything from 11 years to 70+ years old
students. I've always, without fail, found that some
students (say 10-20% of a class) just don't get
programming. It seems to me that some folks just
don't have their brains wired the right way. It
doesn't matter what tools or languages you use, it
even happens with graphical tools like flow charts.
Some people just don't understand the concepts of
logical flow and problem decomposition.

You can, of course, force feed these folks to some
extent and they will pick up the basics with a
struggle but they will never be able to create
any significant body of code on their own. I'm
sure psychologists etc will have an explanation
for this but I've given up trying to explain it,
I now just accept that some people don't think
that way.

It's a bit like math. Some people don't get that
either. They can learn Pythagoras' theorem and
that it applies to right angled triangles and
that triangles have 3 sides and that it is right
angled if one corner is 90 degrees. But turn such
a triangle on its side and they can no longer see
the right angle, and don't understand how turning
it around doesn't change the size of the angles etc.
It just doesn't make any sense to them. And it
seems the same is true for programming logic.

-- 
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 mike_barnett at hotmail.com  Mon Feb  4 11:01:13 2019
From: mike_barnett at hotmail.com (Mike Barnett)
Date: Mon, 4 Feb 2019 16:01:13 +0000
Subject: [Tutor] Recommended Resurce or strategy for beginning students
In-Reply-To: <CAFkpTi=eCXyF8yrzPfL51cB3Jbmk03nD7=SVCd0cEx2tWqgdEg@mail.gmail.com>
References: <CAFkpTin2MMDYzZsHv-JHGFDJafMaJ8xRp8BnAVai_kdEqLQf0A@mail.gmail.com>
 <MWHPR11MB17107F8F47ABE097F721F8B6E0980@MWHPR11MB1710.namprd11.prod.outlook.com>
 <BFD53651-10EF-4111-A683-ED0A0EEABF43@gmail.com>
 <CAFkpTi=eCXyF8yrzPfL51cB3Jbmk03nD7=SVCd0cEx2tWqgdEg@mail.gmail.com>
Message-ID: <MWHPR11MB1710DD74800B856061A283D4E06D0@MWHPR11MB1710.namprd11.prod.outlook.com>

Be cautious when using IDLE with tkinter based programs (PySimpleGUI falls into this category).

IDLE is written using tkinter.  You can sometimes end up with tkinter complaining about the mainloop running in multiple locations or freeing resources in the wrong thread.


@mike<mailto:mike_barnett at hotmail.com>

From: Matthew Polack <matthew.polack at htlc.vic.edu.au>
Sent: Monday, February 4, 2019 12:15 AM
To: Sean Murphy <mhysnm1964 at gmail.com>
Cc: Mike Barnett <mike_barnett at hotmail.com>; tutor at python.org
Subject: Re: [Tutor] Recommended Resurce or strategy for beginning students

Hi All,

Firstly thanks so much for all the suggestions a while back re: recommended method for Python...really appreciate the ideas.

We had our first lesson today (With 15 year olds) where I started with the basic command line..and did a simple "Hello World" type program...just to show how something could be run straight from notepad and command line...

We then went to IDLE and made a simple 'Maths Calculator'....

All of this went quite well...but as the long session started to wind down (Is a double lesson on a Monday)...I did start to notice the following:

1.) One group of students (probably most)..actively problem solving..trying things...googling all sorts of ways of improving their code...figuring out new ways of doing things...will go a long way.
2.) Another smaller group started to hit the wall...and were struggling for internal drive...needed to be 'hand fed'

Is going to be interesting going forward how to both cater for the 'indpendent workers' whilst still keeping the 'unenthused unless entertained' group engaged! The joys of teaching...but will certainly try some of the suggestions mentioned...PySimpleGUI..Turtle graphics etc....they will be very helpful. Thanks.



Matthew Polack | Teacher



[Emailbanner3.png]


Trinity Drive  |  PO Box 822

Horsham Victoria 3402

p. 03 5382 2529   m. 0402456854

e. matthew.polack at htlc.vic.edu.au<mailto:matthew.polack at htlc.vic.edu.au>

w. www.htlc.vic.edu.au<https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.htlc.vic.edu.au%2F&data=02%7C01%7C%7C5bac6b102d1b43f778c608d68a5fb081%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636848540919281041&sdata=wZPuSdzAKYKZ6PEFA3XoI5lu6yoWt9zY%2FChV6Tpl7xA%3D&reserved=0>



On Wed, Jan 23, 2019 at 1:21 PM Sean Murphy <mhysnm1964 at gmail.com<mailto:mhysnm1964 at gmail.com>> wrote:
I like this concept. The only additional information I would add in relation to any training or educational information. You must include accessibility. As the laws in many countries require this to be a part of the product. So it is a perfect time to educate students on this important topic. A high level awareness is required only.
Introducing the basics. Keyboard navigation, colour contrast, ensuring the GUI works with a screen reader. The platforms used for GUI should do most of the heavy lifting.

The other aspect is you need to ensure the course is accessible to possible disable students for now and the future. If you are based in the Usa. Then there could be legal requirements for this. Not sure. Out of my scope of focus in the accessibility world.


A bare minimum is to understand the bare basics which are called POUR. Reference W3C for the explaination.

Sean

My experience is the part

> On 23 Jan 2019, at 1:17 am, Mike Barnett <mike_barnett at hotmail.com<mailto:mike_barnett at hotmail.com>> wrote:
>
> I like the idea of starting out right away on a GUI.  I know this is completely backwards to what would normally be taught, but hear me out.  Kids today are used to GUI interfaces.  They're on their phones, their computers, their TV  sets.
>
> Why not teach kids to output to a window instead of a command line?  What if it's just was easy, or easier, to work with a GUI as it is the command line?
>
> To output to the command line in standard Python:
> print('my string', variable1, variable2)
>
> To output the same information to a window using PySimpleGUI:
> Popup('my string', variable1, variable2)
>
> Or, you can "print" to a debug window if that's your thing.
> Print('takes the same parameters as print')
>
> If the ultimate goal is to teach kids about how to design a GUI window, how to lay out a GUI using good user interface design principals, then it would be nice to get the GUI coding out of the way and let the focus instead be on the GUI itself.  This is when having a drag-and-drop Designer Tool is handy.  If not, then the next best thing is a simple programming interface.
>
> PySimpleGUI was designed so that the code visually matches the window layout.
>
> It's capable of duplicating pretty much any layout and widget combination that you can create coding directly to tkinter's (or Qt's or WxPython's) interfaces.  PySimpleGUI simply creates and executes the "boilerplate" code that is often brought up when GUIs are discussed.
>
> A goal was to remove all of the boilerplate code and provide a programmer with a simple, friendly and flexible set of APIs.  You write a single line of code per row of widgets in your window plus a 1/2 dozen lines to implement the event loop.
>
> I don't see the harm in approaching the problem from a different direction.  It could be wildly successful.  Or... not...  The worst that can happen is you screw up a classroom full of future programmers, creating a warped vision that GUIs can be fun and easy.
>
>
> @mike
>
> -----Original Message-----
> From: Matthew Polack <matthew.polack at htlc.vic.edu.au<mailto:matthew.polack at htlc.vic.edu.au>>
> Sent: Tuesday, January 22, 2019 1:58 AM
> To: tutor at python.org<mailto:tutor at python.org>
> Subject: [Tutor] Recommended Resurce or strategy for beginning students
>
> Hi All,
>
> In our growing school we're teaching Python programming for the first time as an elective subject with Year 9 and 10 students. (Had a dabble at this last year with 3 students in Year 11)
>
> I'm wondering what specific resource or stategy people would recommend for absolute beginners?
>
> ie. a course or program, book,...set of activities to follow that strategically introduces and develops key skills.
>
> At this age level I don't think we need to be achieving 'rocket science'..but rather giving the students a good solid introduction.
>
> Some of the leadership wanted me to use this programming in combination with building robots...I've even wondered whether this is trying to achieve too many things...and we're better off focused on programming itself... but am open to this idea too...
>
> I've had a play with using the excellent PySimpleGUI...which is an excellent resource for building a GUI...but I've realised before doing too much of this we might need to get a grip on core fundamentals....
>
> The challenge is trying to find a way to making this 'fun' for students whilst also having them genuinely learn rather than just 'copying pasting'
> code...achieving something that looks good...but not really understanding what they are doing.
>
> So far my strategy will be:
>
> 1.) Establish some core basics(utlising some form of 'course',,,which goes through basics of syntax..variables...loops etc. utilising just raw code...(probably a simple 'Adventure Game')
> 2.) Build some simple programs using PySimple GUi..eg. Some quiz games etc.
> (there are some great examples on Github by another teacher and also the author Mike of PySimpleGUI.
> 3.) Possibly explore robotics.
>
> Can anyone make any recommendations on either resources or teaching/learning strategy/curriculum.
>
> Thank you,
> Matt
>
>
> Matthew Polack | Teacher
>
>
> [image: Emailbanner3.png]
>
> Trinity Drive  |  PO Box 822
>
> Horsham Victoria 3402
>
> p. 03 5382 2529   m. 0402456854
>
> e. matthew.polack at htlc.vic.edu.au<mailto:matthew.polack at htlc.vic.edu.au>
>
> w. www.htlc.vic.edu.au<https://nam05.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.htlc.vic.edu.au&data=02%7C01%7C%7C5bac6b102d1b43f778c608d68a5fb081%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636848540919291064&sdata=XT3ugym%2F3hDIFsUDUkvScU0DG6Fv%2BkNIfT0iN5B%2FSTY%3D&reserved=0>
>
> --
> **Disclaimer: *Whilst every attempt has been made to ensure that material contained in this email is free from computer viruses or other defects, the attached files are provided, and may only be used, on the basis that the user assumes all responsibility for use of the material transmitted. This email is intended only for the use of the individual or entity named above and may contain information that is confidential and privileged. If you are not the intended recipient, please note that any dissemination, distribution or copying of this email is strictly prohibited. If you have received this email in error, please notify us immediately by return email or telephone +61 3 5382 2529** and destroy the original message.*
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org<mailto:Tutor at python.org>
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor<https://nam05.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutor&data=02%7C01%7C%7C5bac6b102d1b43f778c608d68a5fb081%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636848540919311080&sdata=ObE%2FwoXRr1%2FUFzob7ZyDKyVmen4JbcUrI9UN8hQfkes%3D&reserved=0>

Disclaimer: Whilst every attempt has been made to ensure that material contained in this email is free from computer viruses or other defects, the attached files are provided, and may only be used, on the basis that the user assumes all responsibility for use of the material transmitted. This email is intended only for the use of the individual or entity named above and may contain information that is confidential and privileged. If you are not the intended recipient, please note that any dissemination, distribution or copying of this email is strictly prohibited. If you have received this email in error, please notify us immediately by return email or telephone +61 3 5382 2529 and destroy the original message.

From valerio at pbds.eu  Mon Feb  4 12:13:03 2019
From: valerio at pbds.eu (Valerio Pachera)
Date: Mon, 4 Feb 2019 18:13:03 +0100 (CET)
Subject: [Tutor] Remove soft line break
Message-ID: <431086936.29.1549300383777.JavaMail.zimbra@pbds.eu>


I have a file with row that split at the 80th character.
The next row start with a blank space, meaning that i part of the previous row.

Example:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam non justo enim. Viv
 amus dapibus quis neque vitae ornare. Pellentesque at pharetra sapien, id eleif
 end lacus. Nullam ut semper enim, vulputate venenatis justo. Vestibulum vehicul
 a dolor sit amet ultricies vulputate. Aenean lobortis, nulla eu scelerisque hen

What do you suggest to get the text on a single line?


From mats at wichmann.us  Mon Feb  4 14:09:02 2019
From: mats at wichmann.us (Mats Wichmann)
Date: Mon, 4 Feb 2019 12:09:02 -0700
Subject: [Tutor] Remove soft line break
In-Reply-To: <431086936.29.1549300383777.JavaMail.zimbra@pbds.eu>
References: <431086936.29.1549300383777.JavaMail.zimbra@pbds.eu>
Message-ID: <0644b9ac-952e-f7f7-b6c5-a96fa7d8f534@wichmann.us>

On 2/4/19 10:13 AM, Valerio Pachera wrote:
> 
> I have a file with row that split at the 80th character.
> The next row start with a blank space, meaning that i part of the previous row.
> 
> Example:
> 
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam non justo enim. Viv
>  amus dapibus quis neque vitae ornare. Pellentesque at pharetra sapien, id eleif
>  end lacus. Nullam ut semper enim, vulputate venenatis justo. Vestibulum vehicul
>  a dolor sit amet ultricies vulputate. Aenean lobortis, nulla eu scelerisque hen
> 
> What do you suggest to get the text on a single line?

joining the lines is simple - use an empty string as the thing to join
on, and if you want to ditch the beginning space there's a function for
that too (lstrip). But... if you don't have a precise way to know if a
word was split in the middle or on a space (or do you know this?), you
probably need human intervention to reassemble the original.



From __peter__ at web.de  Mon Feb  4 14:23:59 2019
From: __peter__ at web.de (Peter Otten)
Date: Mon, 04 Feb 2019 20:23:59 +0100
Subject: [Tutor] Remove soft line break
References: <431086936.29.1549300383777.JavaMail.zimbra@pbds.eu>
Message-ID: <q3a3gg$4f6g$1@blaine.gmane.org>

Valerio Pachera wrote:

> 
> I have a file with row that split at the 80th character.
> The next row start with a blank space, meaning that i part of the previous
> row.
> 
> Example:
> 
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam non justo
> enim. Viv
>  amus dapibus quis neque vitae ornare. Pellentesque at pharetra sapien, id
>  eleif end lacus. Nullam ut semper enim, vulputate venenatis justo.
>  Vestibulum vehicul a dolor sit amet ultricies vulputate. Aenean lobortis,
>  nulla eu scelerisque hen
> 
> What do you suggest to get the text on a single line?

Neglecting the corner cases:

$ cat mergelines.py 
def merge_lines(lines):
    lines = (line.rstrip("\n") for line in lines)
    accu = [next(lines)]
    for line in lines:
        if line.startswith(" "):
            accu.append(line[1:])
        else:
            yield "".join(accu) + "\n"
            accu = [line]
    yield "".join(accu) + "\n"


SAMPLE =  """\
foo bar baz
  ham spam
alpha beta
  gamma
 delta
  epsilon
""".splitlines(True)

for line in merge_lines(SAMPLE):
    print(line, end="")
$ python3 mergelines.py 
foo bar baz ham spam
alpha beta gammadelta epsilon

I hope this isn't homework ;)



From bouncingcats at gmail.com  Mon Feb  4 23:03:18 2019
From: bouncingcats at gmail.com (David)
Date: Tue, 5 Feb 2019 15:03:18 +1100
Subject: [Tutor] Recommended Resurce or strategy for beginning students
In-Reply-To: <CAFkpTin2MMDYzZsHv-JHGFDJafMaJ8xRp8BnAVai_kdEqLQf0A@mail.gmail.com>
References: <CAFkpTin2MMDYzZsHv-JHGFDJafMaJ8xRp8BnAVai_kdEqLQf0A@mail.gmail.com>
Message-ID: <CAMPXz=phFzHPsFAnDMPakAOaCh1+XkiB0SWYkDJ7OdB+HRuBAg@mail.gmail.com>

On Tue, 22 Jan 2019 at 20:30, Matthew Polack
<matthew.polack at htlc.vic.edu.au> wrote:
>
> Hi All,
>
> In our growing school we're teaching Python programming for the first time
> as an elective subject with Year 9 and 10 students. (Had a dabble at this
> last year with 3 students in Year 11)

Hi Matthew and other readers,

I wonder if you and any others here involved in classroom/group teaching
might be interested in this recent presentation that I stumbled across:
https://media.ccc.de/v/35c3-9800-how_to_teach_programming_to_your_loved_ones

The section of this video which motivates me to write here is the two minutes
from 19:00 to 21:00.

What I find most interesting is his motivation mentioned there: he claims his
procedure solves the problem of any students becoming "lost", feeling "stuck"
at any particular step, not knowing what to do next, and unable to proceed
without guidance.

Quoting from the synopsis:
The talk is based on many years of research by the Program by Design,
DeinProgramm, and Bootstrap educational projects, as well as over 30 years
of personal teaching experience in school, university and industrial contexts.
A word of warning: The resulting approach is radically different from most
teaching approaches used in universities and schools. In particular, it avoids
teaching purely through examples and expecting students to develop the
skills to arrive at the solutions on their own. Instead, it teaches explicit
methodology that enables students to solve problems of surprising complexity
on their own, whether they are 11 or 55, whether in a classroom, a training
facility, or your home. Extensive documentation, material, and software to
support this methodology is available for free.

For anyone considering watching the whole presentation, I expect that there
are many other aspects of this presentation to which people here could react
negatively, for example:

1) The given title is misleading, in my opinion its subtitle would be much more
representative: "Enabling students [by] example-driven teaching".

2) It recommends against Python, about this I have no opinion (except
to respect the presenter's experience) and that is not why I am posting it here.

3) It emphasises functional programming style.

4) Despite possibly having an audience including skilled programmers, in the
second half of the presentation the presenter does not skip quickly over the
concept, but instead he chooses to demonstrate his concept by reproducing
the same deliberate steps that he would use in a classroom of students
with low ability.

Despite all these possibly alienating aspects, and possibly others, I'm not
really interested in those aspects, because they're not useful to me and so
I choose to ignore them, instead focussing on what might be useful.

Years ago I spent about a decade teaching undergraduate engineering
students, from that context I consider this interesting and relevant.
This presenter mentions that he has 30 years of of experience
and commitment to teaching this subject, and considers most of his
efforts a "failure" (at 02:00). Learning from such a person can save other
practitioners a great deal of effort.

So I felt that this was worth sharing here, I hope negative reactions
or distractions don't distract from possibly useful information.

From bouncingcats at gmail.com  Mon Feb  4 23:59:41 2019
From: bouncingcats at gmail.com (David)
Date: Tue, 5 Feb 2019 15:59:41 +1100
Subject: [Tutor] Recommended Resurce or strategy for beginning students
In-Reply-To: <CAMPXz=phFzHPsFAnDMPakAOaCh1+XkiB0SWYkDJ7OdB+HRuBAg@mail.gmail.com>
References: <CAFkpTin2MMDYzZsHv-JHGFDJafMaJ8xRp8BnAVai_kdEqLQf0A@mail.gmail.com>
 <CAMPXz=phFzHPsFAnDMPakAOaCh1+XkiB0SWYkDJ7OdB+HRuBAg@mail.gmail.com>
Message-ID: <CAMPXz=rgDzdac7DvEAs1Nrep2qdtLn30uSoGn32eNwYwV_5H+A@mail.gmail.com>

On Tue, 5 Feb 2019 at 15:03, David <bouncingcats at gmail.com> wrote:
>
> 1) The given title is misleading, in my opinion its subtitle would be much more
> representative: "Enabling students [by] example-driven teaching".

Hi again,

Sorry for replying to myself, but I want to correct something wrong that
I wrote above. The actual subtitle of the presentation is
"Enabling students over example-driven teaching"
and I think the intendend meaning of that is
"Enabling students [is better than] example-driven teaching".

Also I forgot to mention that part of my motivation for writing is some
things Alan wrote:

On Tue, 22 Jan 2019 at 20:59, Alan Gauld via Tutor <tutor at python.org> wrote:
>
> In the UK many schools use the RaspberryPi project to teach robots to
> kids as part of their Technology courses. The programming is picked up
> by osmosis on an as-needed basis. The upside is that it's a lot of fun
> and gets kids used to the concepts of hardware and software working in
> unison. The downside is that they learn a lot of bad coding habits and
> don't understand the theoretical underpinnings of either the hardware or
> software. But as a way to get them hooked it works well .

On Mon, 4 Feb 2019 at 21:07, Alan Gauld via Tutor <tutor at python.org> wrote:
>
> I'm not a professional or trained teacher but over
> the last 30 years or so I've been involved in classes
> teaching everything from 11 years to 70+ years old
> students. I've always, without fail, found that some
> students (say 10-20% of a class) just don't get
> programming. It seems to me that some folks just
> don't have their brains wired the right way. It
> doesn't matter what tools or languages you use, it
> even happens with graphical tools like flow charts.
> Some people just don't understand the concepts of
> logical flow and problem decomposition.
>
> You can, of course, force feed these folks to some
> extent and they will pick up the basics with a
> struggle but they will never be able to create
> any significant body of code on their own. I'm
> sure psychologists etc will have an explanation
> for this but I've given up trying to explain it,
> I now just accept that some people don't think
> that way.

I believe the video presentation addresses exactly these points.

From sonia.miglani33 at gmail.com  Tue Feb  5 07:32:34 2019
From: sonia.miglani33 at gmail.com (Sonia Miglani)
Date: Tue, 5 Feb 2019 13:32:34 +0100
Subject: [Tutor] help
Message-ID: <CACw0__eh7kCMDCZw306uaK1jh_mMybESRdXr5MVwkSh=rDBNoA@mail.gmail.com>

Hi Team,

I am learning puthon and trying the following code.

But getting the following error.

Please help me in knowing the code in better way.


OS Linux
Python version 2.7.13



def  demo(s, exclaim):
#    """
 #   Returns the string 's' repeated 3 times.
  #  If exclaim is true, add exclamation marks.


    result = s + s + s
    if exclaim:
        result = result + '!!!'
    return result


def main():
    print demo('Yay', False)      ## YayYayYay
    print demo('Woo Hoo', True)   ## Woo HooWoo HooWoo Hoo!!!


Error:
./python2.py: line 1: syntax error near unexpected token `('
./python2.py: line 1: `def  demo(s,exclaim):





Regards
Sonia

From alan.gauld at yahoo.co.uk  Tue Feb  5 08:06:39 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Tue, 5 Feb 2019 13:06:39 +0000
Subject: [Tutor] help
In-Reply-To: <CACw0__eh7kCMDCZw306uaK1jh_mMybESRdXr5MVwkSh=rDBNoA@mail.gmail.com>
References: <CACw0__eh7kCMDCZw306uaK1jh_mMybESRdXr5MVwkSh=rDBNoA@mail.gmail.com>
Message-ID: <q3c1ov$57td$1@blaine.gmane.org>

On 05/02/2019 12:32, Sonia Miglani wrote:

> OS Linux
> Python version 2.7.13

Can you tell us how you are creating the file?
Which editor are you using? It looks like there may be
some spurious characters in your file.

> def  demo(s, exclaim):
> #    """
>  #   Returns the string 's' repeated 3 times.
>   #  If exclaim is true, add exclamation marks.
> 
> 
>     result = s + s + s
>     if exclaim:
>         result = result + '!!!'
>     return result
> 
> 
> def main():
>     print demo('Yay', False)      ## YayYayYay
>     print demo('Woo Hoo', True)   ## Woo HooWoo HooWoo Hoo!!!

It all works perfectly for me.

> Error:
> ./python2.py: line 1: syntax error near unexpected token `('
> ./python2.py: line 1: `def  demo(s,exclaim):

Notice the odd backtick (`) characters?
They aren't in your code above, did you retype it or
actually copy/paste your real code? It is important that
you post the actual code you get the error from.


-- 
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 Feb  5 09:15:35 2019
From: __peter__ at web.de (Peter Otten)
Date: Tue, 05 Feb 2019 15:15:35 +0100
Subject: [Tutor] help
References: <CACw0__eh7kCMDCZw306uaK1jh_mMybESRdXr5MVwkSh=rDBNoA@mail.gmail.com>
Message-ID: <q3c5q8$7cko$1@blaine.gmane.org>

Sonia Miglani wrote:

> Hi Team,
> 
> I am learning puthon and trying the following code.
> 
> But getting the following error.
> 
> Please help me in knowing the code in better way.
> 
> 
> OS Linux
> Python version 2.7.13
> 
> 
> 
> def  demo(s, exclaim):
> #    """
>  #   Returns the string 's' repeated 3 times.
>   #  If exclaim is true, add exclamation marks.
> 
> 
>     result = s + s + s
>     if exclaim:
>         result = result + '!!!'
>     return result
> 
> 
> def main():
>     print demo('Yay', False)      ## YayYayYay
>     print demo('Woo Hoo', True)   ## Woo HooWoo HooWoo Hoo!!!
> 
> 
> Error:
> ./python2.py: line 1: syntax error near unexpected token `('

That is not a Python error, that's a complaint of your shell.
If you make a Python script executable you also have to insert the proper 
hash-bang line. In the case of Python 2

#!/usr/bin/python2

will probably work. Example shell session:

$ cat tmp.py
def  demo():
    print "heureka"

demo()
$ ./tmp.py
./tmp.py: line 1: syntax error near unexpected token `('
./tmp.py: line 1: `def  demo():'
$ cat tmp2.py
#!/usr/bin/python2

def  demo():
    print "heureka"

demo()
$ ./tmp2.py
heureka
$ 


> ./python2.py: line 1: `def  demo(s,exclaim):
> 
> 
> 
> 
> 
> Regards
> Sonia
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor



From mats at wichmann.us  Tue Feb  5 10:42:32 2019
From: mats at wichmann.us (Mats Wichmann)
Date: Tue, 5 Feb 2019 08:42:32 -0700
Subject: [Tutor] help
In-Reply-To: <q3c5q8$7cko$1@blaine.gmane.org>
References: <CACw0__eh7kCMDCZw306uaK1jh_mMybESRdXr5MVwkSh=rDBNoA@mail.gmail.com>
 <q3c5q8$7cko$1@blaine.gmane.org>
Message-ID: <045703c6-3162-4e90-ad28-7f7c4e0e2889@wichmann.us>


>> Error:
>> ./python2.py: line 1: syntax error near unexpected token `('
> 
> That is not a Python error, that's a complaint of your shell.
> If you make a Python script executable you also have to insert the proper 
> hash-bang line. In the case of Python 2
> 
> #!/usr/bin/python2
> 
> will probably work. Example shell session:
> 
> $ cat tmp.py
> def  demo():
>     print "heureka"
> 
> demo()
> $ ./tmp.py
> ./tmp.py: line 1: syntax error near unexpected token `('
> ./tmp.py: line 1: `def  demo():'
or, of course, run it with python explicitly:

$ python tmp.py


From alan.gauld at yahoo.co.uk  Tue Feb  5 12:56:58 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Tue, 5 Feb 2019 17:56:58 +0000
Subject: [Tutor] help
In-Reply-To: <q3c5q8$7cko$1@blaine.gmane.org>
References: <CACw0__eh7kCMDCZw306uaK1jh_mMybESRdXr5MVwkSh=rDBNoA@mail.gmail.com>
 <q3c5q8$7cko$1@blaine.gmane.org>
Message-ID: <q3cipa$6c0b$1@blaine.gmane.org>

On 05/02/2019 14:15, Peter Otten wrote:

>> Error:
>> ./python2.py: line 1: syntax error near unexpected token `('
> 
> That is not a Python error, that's a complaint of your shell.

Oh, good catch Peter.
I never noticed the start of the line I just read the text and saw the
weird backtick...


-- 
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 matthew.polack at htlc.vic.edu.au  Wed Feb  6 00:42:04 2019
From: matthew.polack at htlc.vic.edu.au (Matthew Polack)
Date: Wed, 6 Feb 2019 16:42:04 +1100
Subject: [Tutor] Recommended Resurce or strategy for beginning students
In-Reply-To: <CAMPXz=rgDzdac7DvEAs1Nrep2qdtLn30uSoGn32eNwYwV_5H+A@mail.gmail.com>
References: <CAFkpTin2MMDYzZsHv-JHGFDJafMaJ8xRp8BnAVai_kdEqLQf0A@mail.gmail.com>
 <CAMPXz=phFzHPsFAnDMPakAOaCh1+XkiB0SWYkDJ7OdB+HRuBAg@mail.gmail.com>
 <CAMPXz=rgDzdac7DvEAs1Nrep2qdtLn30uSoGn32eNwYwV_5H+A@mail.gmail.com>
Message-ID: <CAFkpTi=DAADiUH8t9uNs4gvSpRpCB+YeUqjsUhEUfdOUEmG++g@mail.gmail.com>

Thanks Alan, David and Mike,

Really appreciate those thoughts and ideas suggested.. I will check out the
full video David...but the part I've looked at has some great food for
thought..is extremely relevant.This quote from the description is very true:

"showing them how to copy-paste a few example programs and change a few
parameters is easy, but bridging from there to building substantial
programs is a different game entirely. This talk is about how to teach
programming successfully, through comprehensible *design recipes*, which
anyone can follow "

Is interesting also his reference to robots....that we could spend a year
using robots...but not really getting deep learning happening...which is
what I was wondering too...

I think initially I do have to start with some example programs....and if
nothing else try and get them inspired to go further....
Anyway thanks...is going to be quite an interesting journey of learning for
both students and teacher this Semester!

Will keep looking through the suggestions and resources mentioned.

Thank you,

Matthew



On Tue, Feb 5, 2019 at 4:02 PM David <bouncingcats at gmail.com> wrote:

> On Tue, 5 Feb 2019 at 15:03, David <bouncingcats at gmail.com> wrote:
> >
> > 1) The given title is misleading, in my opinion its subtitle would be
> much more
> > representative: "Enabling students [by] example-driven teaching".
>
> Hi again,
>
> Sorry for replying to myself, but I want to correct something wrong that
> I wrote above. The actual subtitle of the presentation is
> "Enabling students over example-driven teaching"
> and I think the intendend meaning of that is
> "Enabling students [is better than] example-driven teaching".
>
> Also I forgot to mention that part of my motivation for writing is some
> things Alan wrote:
>
> On Tue, 22 Jan 2019 at 20:59, Alan Gauld via Tutor <tutor at python.org>
> wrote:
> >
> > In the UK many schools use the RaspberryPi project to teach robots to
> > kids as part of their Technology courses. The programming is picked up
> > by osmosis on an as-needed basis. The upside is that it's a lot of fun
> > and gets kids used to the concepts of hardware and software working in
> > unison. The downside is that they learn a lot of bad coding habits and
> > don't understand the theoretical underpinnings of either the hardware or
> > software. But as a way to get them hooked it works well .
>
> On Mon, 4 Feb 2019 at 21:07, Alan Gauld via Tutor <tutor at python.org>
> wrote:
> >
> > I'm not a professional or trained teacher but over
> > the last 30 years or so I've been involved in classes
> > teaching everything from 11 years to 70+ years old
> > students. I've always, without fail, found that some
> > students (say 10-20% of a class) just don't get
> > programming. It seems to me that some folks just
> > don't have their brains wired the right way. It
> > doesn't matter what tools or languages you use, it
> > even happens with graphical tools like flow charts.
> > Some people just don't understand the concepts of
> > logical flow and problem decomposition.
> >
> > You can, of course, force feed these folks to some
> > extent and they will pick up the basics with a
> > struggle but they will never be able to create
> > any significant body of code on their own. I'm
> > sure psychologists etc will have an explanation
> > for this but I've given up trying to explain it,
> > I now just accept that some people don't think
> > that way.
>
> I believe the video presentation addresses exactly these points.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529**?and destroy the original message.*

From ingoogni at gmail.com  Wed Feb  6 11:33:50 2019
From: ingoogni at gmail.com (ingo janssen)
Date: Wed, 6 Feb 2019 17:33:50 +0100
Subject: [Tutor] text processing lines variable content
Message-ID: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>

For parsing the out put of the Voro++ program and writing the data to a 
POV-Ray include file I created a bunch of functions.

def pop_left_slice(inputlist, length):
   outputlist = inputlist[0:length]
   del inputlist[:length]
   return outputlist

this is used by every function to chop of the required part of the input 
line.
Two examples of the functions that proces a chopped of slice of the line 
and append the data to the approriate list.

def f_vector(outlist):
   x,y,z = pop_left_slice(line,3)
   outlist.append(f"<{x},{y},{z}>,")

def f_vector_array(outlist, length):
   rv = pop_left_slice(line, length)
   rv = [f'<{i[1:-1]}>' for i in rv]  #i format is: '(1.234,2.345,3.456)'
   rv = ",".join(rv)
   outlist.append(f"  //label: {lbl}\n  array[{length}]"+"{\n 
"+rv+"\n  }\n")

Every line can contain up to 21 data chunks. Within one file each line 
contains the same amount of chunks, but it varies between files. The 
types of chunks vary and their position varies. I know beforehand how a 
line in a file is constructed. I'd like to adapt the order in that the 
functions are applied, but how?

for i, line in enumerate(open("vorodat.vol",'r')):
   points = i+1
   line = line.strip()
   line = line.split(" ")
   lbl = f_label(label)
   f_vector(point)
   f_value(radius)
   v=f_number(num_vertex)
   f_vector_array(rel_vertex,v)
   f_vector_array(glob_vertex,v)
   f_value_array(vertex_orders,v)
   f_value(max_radius)
   e=f_number(num_edge)
   f_value(edge_dist)
   ...etc

I thought about putting the functions in a dict and then create a list 
with the proper order, but can't get it to work.

A second question, all this works for small files with hundreds of 
lines, but some have 100000. Then I can get at max 22 lists with 100000 
items. Not fun. I tried writing the data to a file "out of sequence", 
not fun either. What would be the way to do this?
I thought about writing each data chunk to a proper temporary file 
instead of putting it in a list first. This would require at max 22 temp 
files and then a merge of the files into one.

TIA,

ingo

From beech48 at hotmail.com  Wed Feb  6 09:03:01 2019
From: beech48 at hotmail.com (beech 48)
Date: Wed, 6 Feb 2019 14:03:01 +0000
Subject: [Tutor] Proxy for Python?
Message-ID: <YQBPR0101MB19216D326CE3CB098F9231E3AA6F0@YQBPR0101MB1921.CANPRD01.PROD.OUTLOOK.COM>

Hi i am totally new to this, i am not a coder and am lost. I have  python working on just 1 of my instagram account right now and its working great but i have no proxy in and im afraid i will get kicked off from IG and i cannot loose this account.  i am having the hardest time trying to put my newly purchased Proxy from Highproxies.com into the code. I have tried so many combos and it fails everytime i try loading.

This is what i am entering

proxy="http://183.172.92.206:22313",


All i was given from them was an option to use my proxy is the two choices of
User & Password Authentication
or
IP Authentication

Right now i have it on IP Authentication by imputing my actual IP address in one of there 3 IP fields and hit setup to activate. But nothing works. I have asked them but they have no idea.

Can anyone please help me?


Thank you


From breamoreboy at gmail.com  Wed Feb  6 13:07:10 2019
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Wed, 6 Feb 2019 18:07:10 +0000
Subject: [Tutor] text processing lines variable content
In-Reply-To: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
Message-ID: <q3f7oe$178p$1@blaine.gmane.org>

On 06/02/2019 16:33, ingo janssen wrote:
> For parsing the out put of the Voro++ program and writing the data to a 
> POV-Ray include file I created a bunch of functions.
> 
> def pop_left_slice(inputlist, length):
>  ? outputlist = inputlist[0:length]
>  ? del inputlist[:length]
>  ? return outputlist

That's going to a lot of work slicing and dicing the input lists. 
Perhaps a chunked recipe like this 
https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.chunked 
would be better.

> 
> this is used by every function to chop of the required part of the input 
> line.
> Two examples of the functions that proces a chopped of slice of the line 
> and append the data to the approriate list.
> 
> def f_vector(outlist):
>  ? x,y,z = pop_left_slice(line,3)
>  ? outlist.append(f"<{x},{y},{z}>,")
> 
> def f_vector_array(outlist, length):
>  ? rv = pop_left_slice(line, length)
>  ? rv = [f'<{i[1:-1]}>' for i in rv]? #i format is: '(1.234,2.345,3.456)'
>  ? rv = ",".join(rv)
>  ? outlist.append(f"? //label: {lbl}\n? array[{length}]"+"{\n "+rv+"\n  
> }\n")
> 
> Every line can contain up to 21 data chunks. Within one file each line 
> contains the same amount of chunks, but it varies between files. The 
> types of chunks vary and their position varies. I know beforehand how a 
> line in a file is constructed. I'd like to adapt the order in that the 
> functions are applied, but how?

I suspect that you're trying to over complicate things, what's wrong 
with a simple if/elif chain, a switch based on a dict or similar?

> 
> for i, line in enumerate(open("vorodat.vol",'r')):
>  ? points = i+1

enumerate takes a start argument so you shouldn't need the above line.

>  ? line = line.strip()
>  ? line = line.split(" ")
>  ? lbl = f_label(label)
>  ? f_vector(point)

Presumably the above is points?

>  ? f_value(radius)
>  ? v=f_number(num_vertex)
>  ? f_vector_array(rel_vertex,v)
>  ? f_vector_array(glob_vertex,v)
>  ? f_value_array(vertex_orders,v)
>  ? f_value(max_radius)
>  ? e=f_number(num_edge)
>  ? f_value(edge_dist)
>  ? ...etc
> 
> I thought about putting the functions in a dict and then create a list 
> with the proper order, but can't get it to work.

Please show us your code and exactly why it didn't work.

> 
> A second question, all this works for small files with hundreds of 
> lines, but some have 100000. Then I can get at max 22 lists with 100000 
> items. Not fun. I tried writing the data to a file "out of sequence", 
> not fun either. What would be the way to do this?
> I thought about writing each data chunk to a proper temporary file 
> instead of putting it in a list first. This would require at max 22 temp 
> files and then a merge of the files into one.

I'm not absolutely sure what you're saying here, but would something 
like the SortedList from 
http://www.grantjenks.com/docs/sortedcontainers/ help?

> 
> TIA,
> 
> ingo
> _______________________________________________
> Tutor maillist? -? Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> 


-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


From ingoogni at gmail.com  Wed Feb  6 13:51:58 2019
From: ingoogni at gmail.com (ingo janssen)
Date: Wed, 6 Feb 2019 19:51:58 +0100
Subject: [Tutor] text processing lines variable content
In-Reply-To: <q3f7oe$178p$1@blaine.gmane.org>
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
Message-ID: <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>


On 06/02/2019 19:07, Mark Lawrence wrote:

> That's going to a lot of work slicing and dicing the input lists. 
> Perhaps a chunked recipe like this 
> https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.chunked 
> would be better.

The length of the text chunks varies from a single character to a list 
of ~30 3D vectors.

>> I'd like to adapt the order in that 
>> the functions are applied, but how?
> 
> I suspect that you're trying to over complicate things, what's wrong 
> with a simple if/elif chain, a switch based on a dict or similar?
> 

You mean create a list with the order=[a,b,e,d...]
if a in order:
   f_vector_array(a, 3)
elseif b in order:
   f_value(max_radius)

that would run the proper function, but not in the right order?

>>
>> for i, line in enumerate(open("vorodat.vol",'r')):
>> ?? points = i+1
> 
> enumerate takes a start argument so you shouldn't need the above line.

points is needed later on in the program and I don't know beforehand how 
many lines I have.

>> I thought about putting the functions in a dict and then create a list 
>> with the proper order, but can't get it to work.
> 
> Please show us your code and exactly why it didn't work.
> 

def f_vector_array(outlist, length):
   rv = pop_left_slice(line, length)
   rv = [f'<{i[1:-1]}>' for i in rv]  #i format is: '(1.234,2.345,3.456)'
   rv = ",".join(rv)
   outlist.append(f"  //label: {lbl}\n  array[{length}]"+"{\n "+rv+"\n 
}\n")

functions={
  'a':f_number(num_vertex),
  'b':f_vector_array(rel_vertex,v)
}
where rel_vertex is the list where to move the processed data to and v 
the amount of text to chop of the front of the line. v is not known when 
defining the dictionary. v comes from an other function 
v=f_number(num_vertex) that also should live in the dict.

then loop order=[a,b,e,d...] for each line

> 
> I'm not absolutely sure what you're saying here, but would something 
> like the SortedList from 
> http://www.grantjenks.com/docs/sortedcontainers/ help?

Maybe this explains it better, assume the split input lines:
line1=[a,b,c,d,e,f,...]
line2=[a,b,c,d,e,f,...]
line3=[a,b,c,d,e,f,...]
...
line100000=...

all data on position a should go to list a

a=[a1,a2,a3,...a_n]
b=[b1,b2,b3,...b_n]
c=[c1,c2,c3,...n_n]
etc.

this is what for example the function f_vector_array(a, 3) does.

All these lists have to be written to a single file, each list contains 
100000 items. Instead of keeping it all in memory I could write a1 to a 
temp file A instead of putting it in a list first and b1 to a temp file 
B etc. in the next loop a2 to file A, b2 to file B etc. When all lines 
are processed combine the files A,B,C ... to a single file. Or is there 
a more practical way? Speed is not important.

ingo

From breamoreboy at gmail.com  Wed Feb  6 15:45:27 2019
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Wed, 6 Feb 2019 20:45:27 +0000
Subject: [Tutor] text processing lines variable content
In-Reply-To: <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
 <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
Message-ID: <q3fh17$1p6f$1@blaine.gmane.org>

On 06/02/2019 18:51, ingo janssen wrote:
> 
> On 06/02/2019 19:07, Mark Lawrence wrote:
> 
>> That's going to a lot of work slicing and dicing the input lists. 
>> Perhaps a chunked recipe like this 
>> https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.chunked 
>> would be better.
> 
> The length of the text chunks varies from a single character to a list 
> of ~30 3D vectors.

So what, you still don't need to chop the front from the list, just 
process the data.

> 
>>> I'd like to adapt the order in that the functions are applied, but how?
>>
>> I suspect that you're trying to over complicate things, what's wrong 
>> with a simple if/elif chain, a switch based on a dict or similar?
>>
> 
> You mean create a list with the order=[a,b,e,d...]
> if a in order:
>  ? f_vector_array(a, 3)
> elseif b in order:
>  ? f_value(max_radius)
> 
> that would run the proper function, but not in the right order?

Again I've no idea what you're saying here.

> 
>>>
>>> for i, line in enumerate(open("vorodat.vol",'r')):
>>> ?? points = i+1
>>
>> enumerate takes a start argument so you shouldn't need the above line.
> 
> points is needed later on in the program and I don't know beforehand how 
> many lines I have.

Now you tell us :-(

> 
>>> I thought about putting the functions in a dict and then create a 
>>> list with the proper order, but can't get it to work.
>>
>> Please show us your code and exactly why it didn't work.
>>
> 
> def f_vector_array(outlist, length):
>  ? rv = pop_left_slice(line, length)
>  ? rv = [f'<{i[1:-1]}>' for i in rv]? #i format is: '(1.234,2.345,3.456)'
>  ? rv = ",".join(rv)
>  ? outlist.append(f"? //label: {lbl}\n? array[{length}]"+"{\n "+rv+"\n 
> }\n")
> 
> functions={
>  ?'a':f_number(num_vertex),
>  ?'b':f_vector_array(rel_vertex,v)
> }
> where rel_vertex is the list where to move the processed data to and v 
> the amount of text to chop of the front of the line. v is not known when 
> defining the dictionary. v comes from an other function 
> v=f_number(num_vertex) that also should live in the dict.

You don't need to specify the parameters in the dict, just give the 
function name.
> 
> then loop order=[a,b,e,d...] for each line
> 

What has a loop order got to do with using a dict?

>>
>> I'm not absolutely sure what you're saying here, but would something 
>> like the SortedList from 
>> http://www.grantjenks.com/docs/sortedcontainers/ help?
> 
> Maybe this explains it better, assume the split input lines:
> line1=[a,b,c,d,e,f,...]
> line2=[a,b,c,d,e,f,...]
> line3=[a,b,c,d,e,f,...]
> ...
> line100000=...
> 
> all data on position a should go to list a
> 
> a=[a1,a2,a3,...a_n]
> b=[b1,b2,b3,...b_n]
> c=[c1,c2,c3,...n_n]
> etc.
> 
> this is what for example the function f_vector_array(a, 3) does.

Why bother, just have a list of lists and index on the position, or are 
we talking at cross purposes?

> 
> All these lists have to be written to a single file, each list contains 
> 100000 items. Instead of keeping it all in memory I could write a1 to a 
> temp file A instead of putting it in a list first and b1 to a temp file 
> B etc. in the next loop a2 to file A, b2 to file B etc. When all lines 
> are processed combine the files A,B,C ... to a single file. Or is there 
> a more practical way? Speed is not important.

What is your definition of "combine the files A,B,C ... to a single file"?

> 
> ingo

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


From ingoogni at gmail.com  Wed Feb  6 16:22:53 2019
From: ingoogni at gmail.com (ingo janssen)
Date: Wed, 6 Feb 2019 22:22:53 +0100
Subject: [Tutor] text processing lines variable content
In-Reply-To: <q3fh17$1p6f$1@blaine.gmane.org>
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
 <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
 <q3fh17$1p6f$1@blaine.gmane.org>
Message-ID: <cf52adcb-1d99-4119-1c98-f3c897c989e5@gmail.com>



On 06/02/2019 21:45, Mark Lawrence wrote:

> So what, you still don't need to chop the front from the list, just 
> process the data.

just slice

>>
>>>> I'd like to adapt the order in that the functions are applied, but how?
>>>
>>> I suspect that you're trying to over complicate things, what's wrong 
>>> with a simple if/elif chain, a switch based on a dict or similar?
>>>
>>
>> You mean create a list with the order=[a,b,e,d...]
> Again I've no idea what you're saying here.

depending on how the input file is created data packet a can be in an 
other position for every line.
figured out how to do it though

order=[a,b,e,d...]
for i in lines:
   i=i.split(" ")
     for j in order:
       if j = a:
	use function for processing data chunk a
       elseif j = b:
         use proper function for processing data type b
       ...

>> I don't know beforehand 
>> how many lines I have.
> 
> Now you tell us :-(

sorry

>> then loop order=[a,b,e,d...] for each line
>>
> 
> What has a loop order got to do with using a dict?

order of data chunks varies per file

> Why bother, just have a list of lists and index on the position, or are 
> we talking at cross purposes?

Sorry for the amount of text below, I hope it clarifies
one line of space delimited input data:

0 1094.82 0.1 582.419 0.5 14 (0.200231,1.13714,-8.35338) 
(-10.2097,1.13714,-4.05001) (-10.2097,-14.3466,-4.05001) 
(-2.4419,-39.895,9.65513) (-0.382375,-100.1,7.27361) 
(0.200231,-100.1,-8.35338) (-2.43137,1.58294,9.64296) 
(-10.1818,1.514,-4.00085) (-2.4419,1.51399,9.65513) 
(3.73705,-100.1,2.51013) (0.220825,1.58294,-8.29013) 
(-6.42082,-100.1,-5.61629) (-10.1626,1.58294,-3.9977) 
(3.73705,1.58294,2.51013) (1095.02,1.23714,574.066) 
(1084.61,1.23714,578.369) (1084.61,-14.2466,578.369) 
(1092.38,-39.795,592.074) (1094.44,-100,589.693) (1095.02,-100,574.066) 
(1092.39,1.68294,592.062) (1084.64,1.614,578.418) 
(1092.38,1.61399,592.074) (1098.56,-100,584.929) 
(1095.04,1.68294,574.129) (1088.4,-100,576.803) 
(1084.66,1.68294,578.421) (1098.56,1.68294,584.929) 3 3 3 3 3 3 3 3 3 3 
3 3 3 3 10092.8 21 550.726 9 23.4034 221.001 102.986 190.388 219.178 
39.1211 226.154 47.7032 31.5186 4765.01 5 5 5 4 6 4 5 4 4 0 0 0 0 4 4 1 
5.07336 964.581 451.085 1100.75 865.736 81.7357 1161.69 133.262 1.10745 
(1,0,10,12,7) (1,2,11,5,0) (1,7,8,3,2) (2,3,4,11) (3,8,6,13,9,4) 
(4,9,5,11) (5,9,13,10,0) (6,12,10,13) (6,8,7,12) 
(-0.377877,0.147157,-0.914086) (-0.382036,2.8913e-18,-0.924147) 
(-0.869981,0,0.493086) (-0.904528,-0.0477043,0.423738) 
(0.75639,-5.72053e-15,0.654121) (-0,-1,0) 
(0.950875,4.0561e-18,-0.309575) (-5.99268e-17,1,-1.44963e-16) 
(-0.849681,0.21476,0.481581) 9205 9105 3062 9946 5786 -3 1483 100 3262 
11680.5 -2.00777 -44.9048 -0.428504 1092.81 -44.8048 581.99

this one line as it is in the output file. For a file with 100000 lines 
the outer arrays will be 100000 items long:

#declare Labels = array[0]{0}
#declare Points = array[0]{<1094.82,0.1,582.419>}
#declare Radii = array[0]{0.5}
#declare NumVertices = array[0]{14}
#declare RelVertices = array[0]{
   //label: 0
   array[14]{
 
<0.200231,1.13714,-8.35338>,<-10.2097,1.13714,-4.05001>,<-10.2097,-14.3466,-4.05001>,<-2.4419,-39.895,9.65513>,<-0.382375,-100.1,7.27361>,<0.200231,-100.1,-8.35338>,<-2.43137,1.58294,9.64296>,<-10.1818,1.514,-4.00085>,<-2.4419,1.51399,9.65513>,<3.73705,-100.1,2.51013>,<0.220825,1.58294,-8.29013>,<-6.42082,-100.1,-5.61629>,<-10.1626,1.58294,-3.9977>,<3.73705,1.58294,2.51013>
   }
}
#declare GlobalVertices = array[0]{
   //label: 0
   array[14]{
 
<1095.02,1.23714,574.066>,<1084.61,1.23714,578.369>,<1084.61,-14.2466,578.369>,<1092.38,-39.795,592.074>,<1094.44,-100,589.693>,<1095.02,-100,574.066>,<1092.39,1.68294,592.062>,<1084.64,1.614,578.418>,<1092.38,1.61399,592.074>,<1098.56,-100,584.929>,<1095.04,1.68294,574.129>,<1088.4,-100,576.803>,<1084.66,1.68294,578.421>,<1098.56,1.68294,584.929>
   }
}
#declare MaxRadius = array[0]{10092.8}
#declare NumEdges = array[0]{21}
#declare EdgeDistance = array[0]{550.726}
#declare NumFaces = array[0]{9}
#declare FacePerimeter = array[0]{
   //label: 0
 
array[9]{23.4034,221.001,102.986,190.388,219.178,39.1211,226.154,47.7032,31.5186}
}
#declare SurfaceArea = array[0]{4765.01}
#declare FacesOrders = array[0]{
   //label: 0
   array[9]{5,5,5,4,6,4,5,4,4}
}
#declare FreqFaces = array[0]{
   //label: 0
   array[7]{0,0,0,0,4,4,1}
}
#declare FaceArea = array[0]{
   //label: 0
 
array[9]{5.07336,964.581,451.085,1100.75,865.736,81.7357,1161.69,133.262,1.10745}
}
#declare FaceVerticesIndex = array[0]{
   //label: 0
   array[9]{
     array[5]{1,0,10,12,7},
     array[5]{1,2,11,5,0},
     array[5]{1,7,8,3,2},
     array[4]{2,3,4,11},
     array[6]{3,8,6,13,9,4},
     array[4]{4,9,5,11},
     array[5]{5,9,13,10,0},
     array[4]{6,12,10,13},
     array[4]{6,8,7,12},
   }
}
#declare FaceNormal = array[0]{
   //label: 0
   array[9]{
 
<-0.377877,0.147157,-0.914086>,<-0.382036,2.8913e-18,-0.924147>,<-0.869981,0,0.493086>,<-0.904528,-0.0477043,0.423738>,<0.75639,-5.72053e-15,0.654121>,<-0,-1,0>,<0.950875,4.0561e-18,-0.309575>,<-5.99268e-17,1,-1.44963e-16>,<-0.849681,0.21476,0.481581>
   }
}
#declare Neighbours = array[0]{
   //label: 0
   array[9]{9205,9105,3062,9946,5786,-3,1483,100,3262},
}
#declare Volume = array[0]{11680.5}
#declare RelCentroid = array[0]{<-2.00777,-44.9048,-0.428504>}
#declare GlobalCentroid = array[0]{<1092.81,-44.8048,581.99>}

ingo

From michaelrbms at gmail.com  Wed Feb  6 16:22:11 2019
From: michaelrbms at gmail.com (Michael Munn)
Date: Wed, 6 Feb 2019 16:22:11 -0500
Subject: [Tutor] learning python from scratch
Message-ID: <CAERKcycrfMf8Uj-RqtrU5j7vYfLuMCJkGX20XB0RwT7tkf-szQ@mail.gmail.com>

dear fellow programmeers, this is michael. I have a question for Python.
I'm a beginner Pythonist. I havee been learning the history and it's use
for past years. My main focus this year is to learn it's code and begin
coding.
Where can I find resource for this?
All comment  are greatly appreciate it
Best regards
Michael Munn

Michael Munn
Member: Virginia Association of Blind students
 National Federation of the Blind of   Virginia   www.nfbv.org
Member: Maryland Association of Blind Students
National Federation of the Blind of  Maryland www.nfbmd.org
Students of: Hadley Institute of the Blind
www.hadley.edu

From steve at pearwood.info  Thu Feb  7 01:51:12 2019
From: steve at pearwood.info (Steven D'Aprano)
Date: Thu, 7 Feb 2019 17:51:12 +1100
Subject: [Tutor] Proxy for Python?
In-Reply-To: <YQBPR0101MB19216D326CE3CB098F9231E3AA6F0@YQBPR0101MB1921.CANPRD01.PROD.OUTLOOK.COM>
References: <YQBPR0101MB19216D326CE3CB098F9231E3AA6F0@YQBPR0101MB1921.CANPRD01.PROD.OUTLOOK.COM>
Message-ID: <20190207065111.GE1834@ando.pearwood.info>

On Wed, Feb 06, 2019 at 02:03:01PM +0000, beech 48 wrote:

> Hi i am totally new to this, i am not a coder and am lost.

We are coders and we are still lost, because we can't read your mind and 
we have no idea what you are talking about.

Instagram? How is that relevant?

You say you are entering a proxy, but *where* are you entering it and 
what are you doing with it?



-- 
Steven

From __peter__ at web.de  Thu Feb  7 03:29:16 2019
From: __peter__ at web.de (Peter Otten)
Date: Thu, 07 Feb 2019 09:29:16 +0100
Subject: [Tutor] text processing lines variable content
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
 <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
 <q3fh17$1p6f$1@blaine.gmane.org>
 <cf52adcb-1d99-4119-1c98-f3c897c989e5@gmail.com>
Message-ID: <q3gq8t$5l2q$1@blaine.gmane.org>

ingo janssen wrote:

> depending on how the input file is created data packet a can be in an
> other position for every line.
> figured out how to do it though
> 
> order=[a,b,e,d...]
> for i in lines:
>    i=i.split(" ")
>      for j in order:
>        if j = a:
> use function for processing data chunk a
>        elseif j = b:
>          use proper function for processing data type b
>        ...

Where will you get the order from? If you plan to specify it manually, e. g.

lookup_steps = {
    "foo": [a, b, c, ...],
    "bar": [a, a, f, ...],
}
fileformat =  sys.argv[1]
steps = lookup_steps[fileformat]
...
for line in lines:
    for step in steps:
        if step == a:
            ...
        elif step == b:
            ...

then I recommend storing one function per file format instead:

def process_foo(line):
    ...  # process one line in foo format

def process_bar(line):
    ...

lineprocessors = {
    "foo": process_foo,
    "bar": process_bar,
}
fileformat =  sys.argv[1]
process = lineprocessors[fileformat]
...
for line in lines:
    process(line)

That way you deal with Python functions instead of a self-invented 
minilanguage.


From ingoogni at gmail.com  Thu Feb  7 03:58:48 2019
From: ingoogni at gmail.com (ingo janssen)
Date: Thu, 7 Feb 2019 09:58:48 +0100
Subject: [Tutor] text processing lines variable content
In-Reply-To: <q3gq8t$5l2q$1@blaine.gmane.org>
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
 <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
 <q3fh17$1p6f$1@blaine.gmane.org>
 <cf52adcb-1d99-4119-1c98-f3c897c989e5@gmail.com>
 <q3gq8t$5l2q$1@blaine.gmane.org>
Message-ID: <b04e6fc5-5f94-fa2b-bb5e-a49173306bba@gmail.com>


On 07/02/2019 09:29, Peter Otten wrote:
> Where will you get the order from?

Peter,

the order comes from the command line. I intend to call the python 
program with the same command line options as the Voro++ program. Make 
the python program call the Voro++ and process its output.

one command line option contains a string for formatting the output. 
That is what I use for order.

#all output formatting options
order = "%i %q %r %w %p %P %o %m %g %E %s %e %F %a %A %f %t %l %n %v %c %C"
order = re.findall("%[a-z]",order,re.M|re.I)
for i, line in enumerate(open("vorodat.vol",'r')):
   points = i
   line = line.strip()
   line = line.split(" ")
   for action in order:
     if action == "%i":
       try:
         lbl = f_label(label)
       except NameError as e:
          lbl = f_number(label)
          label=[lbl]
     elif action == "%q":
       try:
         f_vector(point)
       except NameError as e:
           point = [f_vector(point)]
     elif action == "%r":
       try:
         f_value(radius)
       except NameError as e:
         radius=[f_value(radius)]
etc.

order is important as %w tells me how long %p, %P and %o will be. This 
varies per line.

I'll look into what you wrote,

thanks,

ingo

From alan.gauld at yahoo.co.uk  Thu Feb  7 04:02:10 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 7 Feb 2019 09:02:10 +0000
Subject: [Tutor] learning python from scratch
In-Reply-To: <CAERKcycrfMf8Uj-RqtrU5j7vYfLuMCJkGX20XB0RwT7tkf-szQ@mail.gmail.com>
References: <CAERKcycrfMf8Uj-RqtrU5j7vYfLuMCJkGX20XB0RwT7tkf-szQ@mail.gmail.com>
Message-ID: <q3gs6i$2n7o$1@blaine.gmane.org>

On 06/02/2019 21:22, Michael Munn wrote:
> dear fellow programmeers, this is michael. I have a question for Python.
> I'm a beginner Pythonist. I havee been learning the history and it's use
> for past years. My main focus this year is to learn it's code and begin
> coding.

Can you program in any other language?
If so the official tutorial on python.org is a
good starting point.

If you have never programmed before there are
several tutorials (including mine, see below).
There is a list of them on the Python web site,
here:

https://wiki.python.org/moin/BeginnersGuide/NonProgrammers


-- 
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 ingoogni at gmail.com  Thu Feb  7 04:27:09 2019
From: ingoogni at gmail.com (ingo janssen)
Date: Thu, 7 Feb 2019 10:27:09 +0100
Subject: [Tutor] text processing lines variable content
In-Reply-To: <b04e6fc5-5f94-fa2b-bb5e-a49173306bba@gmail.com>
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
 <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
 <q3fh17$1p6f$1@blaine.gmane.org>
 <cf52adcb-1d99-4119-1c98-f3c897c989e5@gmail.com>
 <q3gq8t$5l2q$1@blaine.gmane.org>
 <b04e6fc5-5f94-fa2b-bb5e-a49173306bba@gmail.com>
Message-ID: <e4e3f88a-01c4-487a-85cc-20a5d977000d@gmail.com>



On 07/02/2019 09:58, ingo janssen wrote:
> 
> On 07/02/2019 09:29, Peter Otten wrote:
>> Where will you get the order from?
> 

Ahrg, that should have been:

> #all output formatting options
> order = "%i %q %r %w %p %P %o %m %g %E %s %e %F %a %A %f %t %l %n %v %c %C"
> order = re.findall("%[a-z]",order,re.M|re.I)
> for i, line in enumerate(open("vorodat.vol",'r')):
>  ? points = i
>  ? line = line.strip()
>  ? line = line.split(" ")
>  ? for action in order:
>  ??? if action == "%i":
>  ????? try:
>  ??????? lbl = f_label(label)
>  ????? except NameError as e:
             label=[]
>  ???????? lbl = f_number(label)          
>  ??? elif action == "%q":
>  ????? try:
>  ??????? f_vector(point)
>  ????? except NameError as e:
              point = []
   ?????????  f_vector(point)
>  ??? elif action == "%r":
>  ????? try:
>  ??????? f_value(radius)
>  ????? except NameError as e:
            radius = []
>  ?????? f_value(radius)

From alan.gauld at yahoo.co.uk  Thu Feb  7 04:40:59 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 7 Feb 2019 09:40:59 +0000
Subject: [Tutor] text processing lines variable content
In-Reply-To: <b04e6fc5-5f94-fa2b-bb5e-a49173306bba@gmail.com>
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
 <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
 <q3fh17$1p6f$1@blaine.gmane.org>
 <cf52adcb-1d99-4119-1c98-f3c897c989e5@gmail.com>
 <q3gq8t$5l2q$1@blaine.gmane.org>
 <b04e6fc5-5f94-fa2b-bb5e-a49173306bba@gmail.com>
Message-ID: <q3gufb$doq$1@blaine.gmane.org>

On 07/02/2019 08:58, ingo janssen wrote:

>        try:
>          lbl = f_label(label)
>        except NameError as e:
>           lbl = f_number(label)
>           label=[lbl]

Just a minor point but since you aren't doing
anything with the error you don't need the
'as e' bit at the end of each line...

Just saves a little typing is all.

-- 
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  Thu Feb  7 05:08:46 2019
From: __peter__ at web.de (Peter Otten)
Date: Thu, 07 Feb 2019 11:08:46 +0100
Subject: [Tutor] text processing lines variable content
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
 <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
 <q3fh17$1p6f$1@blaine.gmane.org>
 <cf52adcb-1d99-4119-1c98-f3c897c989e5@gmail.com>
 <q3gq8t$5l2q$1@blaine.gmane.org>
 <b04e6fc5-5f94-fa2b-bb5e-a49173306bba@gmail.com>
Message-ID: <q3h03o$5cgs$1@blaine.gmane.org>

ingo janssen wrote:

> 
> On 07/02/2019 09:29, Peter Otten wrote:
>> Where will you get the order from?
> 
> Peter,
> 
> the order comes from the command line. 

Then my one-function-per-format approach won't work.

> I intend to call the python
> program with the same command line options as the Voro++ program. Make
> the python program call the Voro++ and process its output.
> 
> one command line option contains a string for formatting the output.
> That is what I use for order.
> 
> #all output formatting options
> order = "%i %q %r %w %p %P %o %m %g %E %s %e %F %a %A %f %t %l %n %v %c
> %C" order = re.findall("%[a-z]",order,re.M|re.I)
> for i, line in enumerate(open("vorodat.vol",'r')):
>    points = i
>    line = line.strip()
>    line = line.split(" ")
>    for action in order:
>      if action == "%i":
>        try:
>          lbl = f_label(label)
>        except NameError as e:
>           lbl = f_number(label)
>           label=[lbl]

Personally I would avoid the NameError and start with empty lists. If you 
manage to wrap all branches into functions with the same signature you can 
replace the sequence of tests with dictionary lookups. Here's a sketch:


# the f_...() functions take a parsed line and return a value and the
# as yet unused rest of the parsed line

labels = []
points = []
...
def add_label(parts):
   label, rest = f_label(parts)
   labels.append(label)
   return rest

def add_point(parts):
    point, rest = f_vector(parts)
    points.append(point)
    return rest

def add_point(parts):
    global width
    width, rest = f_width(parts)
    return rest

lookup_actions = {
    "%i": add_label,
    "%q": add_point,
    "%w": set_width,
    ...
}

actions = [lookup_actions[action] for action in order]

with open("vorodat.vol") as instream:
    for points, line in enumerate(instream, 1):  # as per Mark's advice
        width = None  # dummy value to provoke error when width
                      # is not explicitly set
        parts = line.split()
        for action in actions:
            parts = actions(parts)


>      elif action == "%q":
>        try:
>          f_vector(point)
>        except NameError as e:
>            point = [f_vector(point)]
>      elif action == "%r":
>        try:
>          f_value(radius)
>        except NameError as e:
>          radius=[f_value(radius)]
> etc.
> 
> order is important as %w tells me how long %p, %P and %o will be. This
> varies per line.
> 
> I'll look into what you wrote,


From ingoogni at gmail.com  Thu Feb  7 06:24:49 2019
From: ingoogni at gmail.com (ingo janssen)
Date: Thu, 7 Feb 2019 12:24:49 +0100
Subject: [Tutor] text processing lines variable content
In-Reply-To: <q3gufb$doq$1@blaine.gmane.org>
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
 <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
 <q3fh17$1p6f$1@blaine.gmane.org>
 <cf52adcb-1d99-4119-1c98-f3c897c989e5@gmail.com>
 <q3gq8t$5l2q$1@blaine.gmane.org>
 <b04e6fc5-5f94-fa2b-bb5e-a49173306bba@gmail.com>
 <q3gufb$doq$1@blaine.gmane.org>
Message-ID: <8b114040-9d74-3329-5bfb-4118842a928b@gmail.com>



On 07/02/2019 10:40, Alan Gauld via Tutor wrote:
> Just saves a little typing is all.

Sensei,

be lazy, I will study


current state of code is at
https://gist.github.com/ingoogni/e99c561f23777e59a5aa6b4ef5fe37c8

ingo

From ingoogni at gmail.com  Thu Feb  7 06:26:54 2019
From: ingoogni at gmail.com (ingo janssen)
Date: Thu, 7 Feb 2019 12:26:54 +0100
Subject: [Tutor] text processing lines variable content
In-Reply-To: <q3h03o$5cgs$1@blaine.gmane.org>
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
 <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
 <q3fh17$1p6f$1@blaine.gmane.org>
 <cf52adcb-1d99-4119-1c98-f3c897c989e5@gmail.com>
 <q3gq8t$5l2q$1@blaine.gmane.org>
 <b04e6fc5-5f94-fa2b-bb5e-a49173306bba@gmail.com>
 <q3h03o$5cgs$1@blaine.gmane.org>
Message-ID: <0e56107c-7ea5-3929-c852-a88b5f0d5f71@gmail.com>



On 07/02/2019 11:08, Peter Otten wrote:
> Personally I would avoid the NameError and start with empty lists. If you
> manage to wrap all branches into functions with the same signature you can
> replace the sequence of tests with dictionary lookups.

Just before I saw your post I put my current code up here:

https://gist.github.com/ingoogni/e99c561f23777e59a5aa6b4ef5fe37c8

I will study yours,

ingo

From ingoogni at gmail.com  Thu Feb  7 10:20:54 2019
From: ingoogni at gmail.com (ingo janssen)
Date: Thu, 7 Feb 2019 16:20:54 +0100
Subject: [Tutor] text processing lines variable content
In-Reply-To: <q3h03o$5cgs$1@blaine.gmane.org>
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
 <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
 <q3fh17$1p6f$1@blaine.gmane.org>
 <cf52adcb-1d99-4119-1c98-f3c897c989e5@gmail.com>
 <q3gq8t$5l2q$1@blaine.gmane.org>
 <b04e6fc5-5f94-fa2b-bb5e-a49173306bba@gmail.com>
 <q3h03o$5cgs$1@blaine.gmane.org>
Message-ID: <4fd0e134-116f-8e69-5e7c-65c3a29061c3@gmail.com>



On 07/02/2019 11:08, Peter Otten wrote:
> replace the sequence of tests with dictionary lookups

updated the gist a few times, now I could pre calculate the slices to be 
taken per line, but will there be much gain compared to the copping from 
the left side of the list?

ingo

From __peter__ at web.de  Thu Feb  7 12:06:39 2019
From: __peter__ at web.de (Peter Otten)
Date: Thu, 07 Feb 2019 18:06:39 +0100
Subject: [Tutor] text processing lines variable content
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
 <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
 <q3fh17$1p6f$1@blaine.gmane.org>
 <cf52adcb-1d99-4119-1c98-f3c897c989e5@gmail.com>
 <q3gq8t$5l2q$1@blaine.gmane.org>
 <b04e6fc5-5f94-fa2b-bb5e-a49173306bba@gmail.com>
 <q3h03o$5cgs$1@blaine.gmane.org>
 <4fd0e134-116f-8e69-5e7c-65c3a29061c3@gmail.com>
Message-ID: <q3hojh$p05$1@blaine.gmane.org>

ingo janssen wrote:

> 
> 
> On 07/02/2019 11:08, Peter Otten wrote:
>> replace the sequence of tests with dictionary lookups
> 
> updated the gist a few times, now I could pre calculate the slices to be
> taken per line, but will there be much gain compared to the copping from
> the left side of the list?

Sorry, I don't understand the question.


Looking at your code

>         if action == "%i":
>             lbl = function[action](content[action])

you really do not need the function[action] lookup here because you know 
that the result will always be f_number. Likewise you could bind 
content["%i"] to a name, labels, say, and then write

if action == "%s":
    lbl = f_number(labels)

which I find much more readable. 

A lookup table only makes sense if provides all necessary information. I 
tried to apply the idea to one of your gist versions:

def set_lbl(items):
    global lbl
    lbl = f_number(items)

def set_w(items):
    global v
    v = f_number(items)

def set_f(items):
    global f
    f = f_number(items)

def set_mx(items):
    global mx
    mx = mx_value_array(items, f)

function = {
    "%i" : set_lbl,
    "%w" : set_w,
    "%s" : set_f,
    "%a" : set_mx,
    "%q" : f_vector,
    "%r" : f_value,
    "%p" : lambda items: f_vector_array(items, v),
    "%P" : lambda items: f_vector_array(items, v),
    "%o" : lambda items: f_value_array(items, v),
    "%m" : f_value,
    "%g" : f_number,
    "%E" : f_value,
    "%e" : lambda items: f_value_array(items, f),
    "%F" : f_value,
    "%A" : lambda items: f_value_array(items, mx + 1),
    "%f" : lambda items: f_value_array(items, f),
    "%t" : lambda items: f_nested_value_array(items, f),
    "%l" : lambda items: f_vector_array(items, f),
    "%n" : lambda items: f_value_array(items, f),
    "%v" : f_value,
    "%c" : f_vector,
    "%C" : f_vector
} 

order = "%i %q %r %w %p %P %o %m %g %E %s %e %F %a %A %f %t %l %n %v %c %C"
order = re.findall("%[a-z]",order,re.M|re.I)
content = {}

actions = []

for i in order:
    items = content[i] = []
    actions.append(partial(function[i], items))

for points, line in enumerate(open("vorodat.txt.vol",'r'), 1):
    line = line.strip()
    line = line.split(" ")
    for action in actions:
        action()

However, while the loop is rather clean now the rest of the code is 
sprinkled with implicit arguments and thus much worse than what you have.


From ingoogni at gmail.com  Thu Feb  7 14:50:34 2019
From: ingoogni at gmail.com (ingo janssen)
Date: Thu, 7 Feb 2019 20:50:34 +0100
Subject: [Tutor] text processing lines variable content
In-Reply-To: <q3hojh$p05$1@blaine.gmane.org>
References: <713157f6-726d-7b44-8dfc-69e864f91e66@gmail.com>
 <q3f7oe$178p$1@blaine.gmane.org>
 <2c57561b-e303-2e21-0f8d-5c12f9285255@gmail.com>
 <q3fh17$1p6f$1@blaine.gmane.org>
 <cf52adcb-1d99-4119-1c98-f3c897c989e5@gmail.com>
 <q3gq8t$5l2q$1@blaine.gmane.org>
 <b04e6fc5-5f94-fa2b-bb5e-a49173306bba@gmail.com>
 <q3h03o$5cgs$1@blaine.gmane.org>
 <4fd0e134-116f-8e69-5e7c-65c3a29061c3@gmail.com>
 <q3hojh$p05$1@blaine.gmane.org>
Message-ID: <7b448cbf-4211-fb7b-22bc-ab2323a7f2ba@gmail.com>


On 07/02/2019 18:06, Peter Otten wrote:
> Sorry, I don't understand the question.

after a quick look not unlike what you propose but I have to investigate 
further,

lengths of chunks are known or can be found (sketchy):

order= [%i,%q,%r,%w,%p,%P,%o,%m,%g,%E,%s,%e,%F,%a,%A,%f,%t,%l,%n,%v,%c,%C]
length=[ 1, 3, 1, 1,%w,%w,%w, 1, 1, 1, 1,%s, 1,%s,%a,%s,%s,%s,%s, 1, 3, 3]

from there calculate the slices per line
slices={"%i":(0,1), "%q":(1,4), "%r":(4:5)....etc

modify all functions to accept and deal with the slice tuple, then the 
action loop gets very simple:

for points, line in enumerate(open("vorodat.txt.vol",'r'), 1):
   line = line.strip()
   line = line.split(" ")
   slices = calculate_slices(line)
   function[action](content[action],slices[action])

thanks for your time and insight, I'll try a few different ways

ingo

From wachobc at gmail.com  Fri Feb  8 13:18:43 2019
From: wachobc at gmail.com (Chip Wachob)
Date: Fri, 8 Feb 2019 13:18:43 -0500
Subject: [Tutor] Putting a Bow on It
Message-ID: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>

Hello,

I've been off working on other projects, but I'm finally back to the
project that so many here have helped me work through.  Thank you to the
group at large.

So, this leads me to my question for today.

I'm not sure what the "correct" term is for this, but I want to create what
I'll call a Package.

I want to bundle all my scripts, extra libraries, etc into one file.  If I
can include a copy of Python with it that would be even better.

I'm looking for the simplest approach for the user to install.  Eg:
libraries will install themselves in the correct directories, etc, so that
there is minimal pain on the part of the user.

I would need to do this for both Windows and Linux so something that is
platform agnostic would be great.

Precise Questions:

A) What sort of term is the proper term for this process that I want to do?
B) Good link suggestions where I can go read / learn about it?
C) Can I just include the .pyc files and the main .py file in the
'release'?  I'm thinking about protecting accidental editing of the .py
files leading to malfunctions.
D) Any other tips or pointers that you would offer as part of attempting
this process?

Again, thank you for all the assistance along the way.

Best,

From robertvstepp at gmail.com  Sun Feb 10 00:51:11 2019
From: robertvstepp at gmail.com (boB Stepp)
Date: Sat, 9 Feb 2019 23:51:11 -0600
Subject: [Tutor] Putting a Bow on It
In-Reply-To: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>
References: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>
Message-ID: <CANDiX9J5BedvFp9Fajk4gYdqLsYGZGG6+2aLhJPb6JWm5F+mRQ@mail.gmail.com>

On Fri, Feb 8, 2019 at 12:35 PM Chip Wachob <wachobc at gmail.com> wrote:
>
> Hello,
>
> I've been off working on other projects, but I'm finally back to the
> project that so many here have helped me work through.  Thank you to the
> group at large.
>
> So, this leads me to my question for today.
>
> I'm not sure what the "correct" term is for this, but I want to create what
> I'll call a Package.

I have not looked into this topic, but your term is very close to the
mark as I understand it.

> I want to bundle all my scripts, extra libraries, etc into one file.  If I
> can include a copy of Python with it that would be even better.
>
> I'm looking for the simplest approach for the user to install.  Eg:
> libraries will install themselves in the correct directories, etc, so that
> there is minimal pain on the part of the user.

Searching for "python packaging tutorials" a sampling of what I get is:

1)  Packaging Python Projects:
https://packaging.python.org/tutorials/packaging-projects/

2)  A Simple Guide for Python Packaging:
https://medium.com/small-things-about-python/lets-talk-about-python-packaging-6d84b81f1bb5

Etc.

There are also ways to create frozen binaries.

I just bought a book today that I have been flipping through tonight,
"Serious Python" by Julien Danjou.  His chapter 5 is entitled
"Distributing Your Software".  He discusses the history of Python
packaging and says that setuptools is "... the standard for advanced
package installations, was at first deprecated but is now back in
active development and the de facto standard."  This book has just
been released this year and is written around Python 3.7 being the
latest version, so hopefully his comment is accurate for 2019.

> I would need to do this for both Windows and Linux so something that is
> platform agnostic would be great.

In the book's chapter I mentioned, the author gives a warning about
portability (from page 63):

"If the Wheel you build contains binary programs or libraries (like a
Python extension written in C), the binary Wheel might not be as
portable as you imagine.  It will work by default on some platforms,
such as Darwin (macOS) or Microsoft Windows, but it might not work on
all Linux distributions.  The PEP 513
(https://www.python.org/dev/peps/pep-0513) targets this Linux problem
by defining a new platform tag named manylinux1 and a minimal set of
libraries that are guaranteed to be available on that platform."

So apparently there is not yet a platform agnostic panacea for program
installations with all of their possible dependencies.

Sorry I know so little about this, but perhaps this might get you
pointed in a helpful direction.  Hopefully the professionals will
weigh in on your questions soon.

-- 
boB

From sjeik_appie at hotmail.com  Sun Feb 10 07:11:17 2019
From: sjeik_appie at hotmail.com (Albert-Jan Roskam)
Date: Sun, 10 Feb 2019 12:11:17 +0000
Subject: [Tutor] Putting a Bow on It
In-Reply-To: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>
Message-ID: <DB6PR0701MB24241E4044041F070E792100836B0@DB6PR0701MB2424.eurprd07.prod.outlook.com>



On 8 Feb 2019 19:18, Chip Wachob <wachobc at gmail.com> wrote:

Hello,

I've been off working on other projects, but I'm finally back to the
project that so many here have helped me work through.  Thank you to the
group at large.

So, this leads me to my question for today.

I'm not sure what the "correct" term is for this, but I want to create what
I'll call a Package.

I want to bundle all my scripts, extra libraries, etc into one file.  If I
can include a copy of Python with it that would be even better.


==? Hi, also check out pyscaffold or the similar cookiecutter to generate "package skeletons". Directory structure, default setup.py, Readme.md file template, etc etc. I've never used them, but py2exe or cx_freeze might also interest you.

From robertvstepp at gmail.com  Sun Feb 10 11:52:44 2019
From: robertvstepp at gmail.com (boB Stepp)
Date: Sun, 10 Feb 2019 10:52:44 -0600
Subject: [Tutor] Fwd: [Tkinter-discuss] New docs: using tkinter GUIs on
 Android
In-Reply-To: <43x3xx5gvkzFqxh@mail.python.org>
References: <43x3xx5gvkzFqxh@mail.python.org>
Message-ID: <CANDiX9+EniGJRhxDTr5jet-1VeJAsjvVjHWDt7F+TM6KJGVtsQ@mail.gmail.com>

I thought that this might be of interest to the group for those who do
not follow the Tkinter mailing list as I have seen questions here
about how to do Python GUIs in Android where the usual response is to
try Kivy.  Perhaps there is now a tkinter solution?

---------- Forwarded message ---------
From: Mark Lutz <lutz at learning-python.com>
Date: Sun, Feb 10, 2019 at 10:07 AM
Subject: [Tkinter-discuss] New docs: using tkinter GUIs on Android
To: <tkinter-discuss at python.org>, <python-announce-list at python.org>


I've just posted guides for running Python tkinter programs on
Android in the Pydroid 3 app's IDE.  The first covers multiple
programs, and the second focuses on a content-sync program:

  https://learning-python.com/using-tkinter-programs-on-android.html
  https://learning-python.com/mergeall-android-scripts/_README.html

And yes, you read that right: Python tkinter GUIs, including
the calendar, calculator, text editor, and incremental backup
tool described in these docs, now work on your smartphone in
addition to your PC, though they come with a few rough edges
(and advertising) on Android today.

And there was much rejoicing,
--M. Lutz (http://learning-python.com)
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss at python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


-- 
boB

From lokesh.20111994 at gmail.com  Mon Feb 11 04:13:49 2019
From: lokesh.20111994 at gmail.com (lokesh kumar)
Date: Mon, 11 Feb 2019 14:43:49 +0530
Subject: [Tutor] regarding minhash and lsh
Message-ID: <CAHpcj5=Fo9a-hm-SwXELPiszF8Vy-Fwik81OjZ-BtRUS83HguA@mail.gmail.com>

Hi There,
i want to make a code to run few DNA seg. so that i will be able to find
similarity in them. file are in million as well as seq. are large so i
tried developing program but fails in it i think minhash and lsh can able
to solve my problem.
i need kind of program that will be easy to handle.

from scipy.spatial.distance import cosine
from random import randint
import numpy as np
N = 128
max_val = (2**32)-1

perms = [ (randint(0,max_val), randint(0,max_val)) for i in range(N)]
vec = [float('inf') for i in range(N)]

def minhash(s, prime=4294967311):
  '''
  Given a set `s`, pass each member of the set through all permutation
  functions, and set the `ith` position of `vec` to the `ith` permutation
  function's output if that output is smaller than `vec[i]`.
  '''

  vec = [float('inf') for i in range(N)]

  for val in s:


    if not isinstance(val, int): val = hash(val)


    for perm_idx, perm_vals in enumerate(perms):
      a, b = perm_vals


      output = (a * val + b) % prime
       if vec[perm_idx] > output:
        vec[perm_idx] = output

    return vec

From alan.gauld at yahoo.co.uk  Mon Feb 11 05:10:36 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 11 Feb 2019 10:10:36 +0000
Subject: [Tutor] regarding minhash and lsh
In-Reply-To: <CAHpcj5=Fo9a-hm-SwXELPiszF8Vy-Fwik81OjZ-BtRUS83HguA@mail.gmail.com>
References: <CAHpcj5=Fo9a-hm-SwXELPiszF8Vy-Fwik81OjZ-BtRUS83HguA@mail.gmail.com>
Message-ID: <q3rhmt$eqi$1@blaine.gmane.org>

On 11/02/2019 09:13, lokesh kumar wrote:

> i want to make a code to run few DNA seg. so that i will be able to find
> similarity in them. file are in million as well as seq. are large so i
> tried developing program but fails in it i think minhash and lsh can able
> to solve my problem.

Bear in mind that this is a general programming forum and
relatively few of us are from a scientific background and
even fewer work with DNA sequences. So I'm glad you have
an idea about your solution but have no idea what minhash
or lsh are, let alone whether they will help you.

Also you may find more people who understand your
work area on the scipy forums.

> i need kind of program that will be easy to handle.

What does that mean? Easy to operate? Easy to maintain?
Easy to distribute to others? All of the above?
Or something else?

As for your code, I'm not sure what that is for?
Do you want us to critique it?
Or is there a problem?
If so you will need to describe the issue and include
any error messages.

At the moment it just defines a function which is
never called...

> from scipy.spatial.distance import cosine
> from random import randint
> import numpy as np
> N = 128
> max_val = (2**32)-1
> 
> perms = [ (randint(0,max_val), randint(0,max_val)) for i in range(N)]
> vec = [float('inf') for i in range(N)]
> 
> def minhash(s, prime=4294967311):
>   '''
>   Given a set `s`, pass each member of the set through all permutation
>   functions, and set the `ith` position of `vec` to the `ith` permutation
>   function's output if that output is smaller than `vec[i]`.
>   '''
>   vec = [float('inf') for i in range(N)]
> 
>   for val in s:
>     if not isinstance(val, int): val = hash(val)
> 
>     for perm_idx, perm_vals in enumerate(perms):
>       a, b = perm_vals
>       output = (a * val + b) % prime
>        if vec[perm_idx] > output:
>         vec[perm_idx] = output
> 
>     return vec

Notice that the last if statement appears to
be incorrectly indented. But that may just be an
email glitch...

-- 
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  Mon Feb 11 05:38:30 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 11 Feb 2019 10:38:30 +0000
Subject: [Tutor] regarding minhash and lsh
In-Reply-To: <q3rhmt$eqi$1@blaine.gmane.org>
References: <CAHpcj5=Fo9a-hm-SwXELPiszF8Vy-Fwik81OjZ-BtRUS83HguA@mail.gmail.com>
 <q3rhmt$eqi$1@blaine.gmane.org>
Message-ID: <q3rjb6$3oql$1@blaine.gmane.org>

On 11/02/2019 10:10, Alan Gauld via Tutor wrote:

>> def minhash(s, prime=4294967311):
>>   vec = [float('inf') for i in range(N)]
>>
>>   for val in s:
>>     if not isinstance(val, int): val = hash(val)
>>
>>     for perm_idx, perm_vals in enumerate(perms):
>>       a, b = perm_vals
>>       output = (a * val + b) % prime
>>        if vec[perm_idx] > output:
>>         vec[perm_idx] = output
>>
>>     return vec
> 
> Notice that the last if statement appears to
> be incorrectly indented. But that may just be an
> email glitch...

I just noticed that the return statement appears
to be inside the outer for loop so that loop
will only run once.

-- 
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  Mon Feb 11 08:48:34 2019
From: wachobc at gmail.com (Chip Wachob)
Date: Mon, 11 Feb 2019 08:48:34 -0500
Subject: [Tutor] Putting a Bow on It
In-Reply-To: <DB6PR0701MB24241E4044041F070E792100836B0@DB6PR0701MB2424.eurprd07.prod.outlook.com>
References: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>
 <DB6PR0701MB24241E4044041F070E792100836B0@DB6PR0701MB2424.eurprd07.prod.outlook.com>
Message-ID: <CADUn+-JW7E5c9ghH+Gdz11=9pAu1k7y0NCmJ9bBTopzLoKstRQ@mail.gmail.com>

Thanks.  These are both great helps to get me started.

The little bit of searching does leave me a little bit confused, but the
reference to the book is somewhat helpful / encouraging.

I see a lot of people saying that certain approaches have been depreciated,
then re-appreciated (?) then depreciated once more and so on..  that sure
makes it confusing to me.  Unfortunately since I'm using someone's pre-made
libraries, and that requires 2.7, I'm sort of locked at that version, but
it seems like most, if not all, of these options will work for any version
of Python.

These posts give me some keywords that should help me narrow the field a
bit.

I realize that choosing a tool is always a case of personal preference.  I
don't want to start a 'this is better than that' debate.

If the 'pros' out there have more input, I'm all ears.

Best,






On Sun, Feb 10, 2019 at 7:11 AM Albert-Jan Roskam <sjeik_appie at hotmail.com>
wrote:

>
>
> On 8 Feb 2019 19:18, Chip Wachob <wachobc at gmail.com> wrote:
>
> Hello,
>
> I've been off working on other projects, but I'm finally back to the
> project that so many here have helped me work through.  Thank you to the
> group at large.
>
> So, this leads me to my question for today.
>
> I'm not sure what the "correct" term is for this, but I want to create
> what
> I'll call a Package.
>
> I want to bundle all my scripts, extra libraries, etc into one file.  If I
> can include a copy of Python with it that would be even better.
>
>
>
> ==? Hi, also check out pyscaffold or the similar cookiecutter to generate
> "package skeletons". Directory structure, default setup.py, Readme.md file
> template, etc etc. I've never used them, but py2exe or cx_freeze might also
> interest you.
>
>

From mats at wichmann.us  Mon Feb 11 11:29:52 2019
From: mats at wichmann.us (Mats Wichmann)
Date: Mon, 11 Feb 2019 09:29:52 -0700
Subject: [Tutor] Putting a Bow on It
In-Reply-To: <CADUn+-JW7E5c9ghH+Gdz11=9pAu1k7y0NCmJ9bBTopzLoKstRQ@mail.gmail.com>
References: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>
 <DB6PR0701MB24241E4044041F070E792100836B0@DB6PR0701MB2424.eurprd07.prod.outlook.com>
 <CADUn+-JW7E5c9ghH+Gdz11=9pAu1k7y0NCmJ9bBTopzLoKstRQ@mail.gmail.com>
Message-ID: <4a255d85-c8f8-6c7e-66d5-2d3fd94e5a24@wichmann.us>

On 2/11/19 6:48 AM, Chip Wachob wrote:
> Thanks.  These are both great helps to get me started.
> 
> The little bit of searching does leave me a little bit confused, but the
> reference to the book is somewhat helpful / encouraging.
> 
> I see a lot of people saying that certain approaches have been depreciated,
> then re-appreciated (?) then depreciated once more and so on..  that sure
> makes it confusing to me.  Unfortunately since I'm using someone's pre-made
> libraries, and that requires 2.7, I'm sort of locked at that version, but
> it seems like most, if not all, of these options will work for any version
> of Python.
> 
> These posts give me some keywords that should help me narrow the field a
> bit.
> 
> I realize that choosing a tool is always a case of personal preference.  I
> don't want to start a 'this is better than that' debate.
> 
> If the 'pros' out there have more input, I'm all ears.

I'm having the same problems, everybody seems to have an idea of what is
state of the art, and they don't often agree. And sadly, people do not
always date their blog entries so you can eliminate what is too old to
be useful to a "newbie" (a category I fall into with packaging)

There are really two classes of solution:

base tools for manually packaging.  The Python Packaging Authority is
supposed to be definitive for what the state of these is.

smart systems which automate some or all of the steps.  These are often
labeled with some sort of hypelabel - Python packaging finally done
right or some such.  (I've tried a couple and they have failed utterly
for the project I want to redo the packaging on. My impression is these
will usually fail if your project is not meant to be imported)



From alan.gauld at yahoo.co.uk  Mon Feb 11 12:28:28 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 11 Feb 2019 17:28:28 +0000
Subject: [Tutor] Putting a Bow on It
In-Reply-To: <CADUn+-JW7E5c9ghH+Gdz11=9pAu1k7y0NCmJ9bBTopzLoKstRQ@mail.gmail.com>
References: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>
 <DB6PR0701MB24241E4044041F070E792100836B0@DB6PR0701MB2424.eurprd07.prod.outlook.com>
 <CADUn+-JW7E5c9ghH+Gdz11=9pAu1k7y0NCmJ9bBTopzLoKstRQ@mail.gmail.com>
Message-ID: <q3sbbs$2u96$1@blaine.gmane.org>

On 11/02/2019 13:48, Chip Wachob wrote:

> I realize that choosing a tool is always a case of personal preference.  I
> don't want to start a 'this is better than that' debate.
> 
> If the 'pros' out there have more input, I'm all ears.
To be fair this is not just a Python problem but applies
to almost all languages. Java and Smalltalk probably come
closest to having a solution that genuinely works
across multiple platforms.

Three is a lot of work going on in Python land but no universal
solution. Some things work better on particular platforms.
And building library packages is easier than complete applications.

But for now, if you have more than a pure Python application,
you are pretty much stuck with building multiple solutions with
multiple tools.

I think.... ;-)

-- 
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  Mon Feb 11 11:36:20 2019
From: wachobc at gmail.com (Chip Wachob)
Date: Mon, 11 Feb 2019 11:36:20 -0500
Subject: [Tutor] Putting a Bow on It
In-Reply-To: <4a255d85-c8f8-6c7e-66d5-2d3fd94e5a24@wichmann.us>
References: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>
 <DB6PR0701MB24241E4044041F070E792100836B0@DB6PR0701MB2424.eurprd07.prod.outlook.com>
 <CADUn+-JW7E5c9ghH+Gdz11=9pAu1k7y0NCmJ9bBTopzLoKstRQ@mail.gmail.com>
 <4a255d85-c8f8-6c7e-66d5-2d3fd94e5a24@wichmann.us>
Message-ID: <CADUn+-+Ov41eQkuwZ2SU=BLx2z=s5D5KTEQhRMFinh-Kczp-tA@mail.gmail.com>

Mats,

You put just the right words to my difficulties.  Thank you.

Since I last posted, I attempted to use Setuptools, and got a handful of
files that were less than 1kB.  I also attempted to use py2exe (I know this
is only for Windoze, but I wanted to find some sliver of success) and
py2exe does not like the fact that I have Python 2.7.15 installed (which I
am locked to).  I tried using pip to install py2exe==0.6.9 (a version that
says it supports Python 2.7) but pip is telling me that it can't find any
version of Python 2.7.

I'm trying to make the installation of the script / executable as simple as
possible because I know those who will be using it will NOT be Python savvy
in the remotest way.

Thanks for confirming that I'm not simply going mad...

Best,


On Mon, Feb 11, 2019 at 11:30 AM Mats Wichmann <mats at wichmann.us> wrote:

> On 2/11/19 6:48 AM, Chip Wachob wrote:
> > Thanks.  These are both great helps to get me started.
> >
> > The little bit of searching does leave me a little bit confused, but the
> > reference to the book is somewhat helpful / encouraging.
> >
> > I see a lot of people saying that certain approaches have been
> depreciated,
> > then re-appreciated (?) then depreciated once more and so on..  that sure
> > makes it confusing to me.  Unfortunately since I'm using someone's
> pre-made
> > libraries, and that requires 2.7, I'm sort of locked at that version, but
> > it seems like most, if not all, of these options will work for any
> version
> > of Python.
> >
> > These posts give me some keywords that should help me narrow the field a
> > bit.
> >
> > I realize that choosing a tool is always a case of personal preference.
> I
> > don't want to start a 'this is better than that' debate.
> >
> > If the 'pros' out there have more input, I'm all ears.
>
> I'm having the same problems, everybody seems to have an idea of what is
> state of the art, and they don't often agree. And sadly, people do not
> always date their blog entries so you can eliminate what is too old to
> be useful to a "newbie" (a category I fall into with packaging)
>
> There are really two classes of solution:
>
> base tools for manually packaging.  The Python Packaging Authority is
> supposed to be definitive for what the state of these is.
>
> smart systems which automate some or all of the steps.  These are often
> labeled with some sort of hypelabel - Python packaging finally done
> right or some such.  (I've tried a couple and they have failed utterly
> for the project I want to redo the packaging on. My impression is these
> will usually fail if your project is not meant to be imported)
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

From robertvstepp at gmail.com  Wed Feb 13 19:30:16 2019
From: robertvstepp at gmail.com (boB Stepp)
Date: Wed, 13 Feb 2019 18:30:16 -0600
Subject: [Tutor] Good tutorials about Python 2 and 3 OOP by Leonardo Giordani
Message-ID: <CANDiX9+vVqR3bkrB4n9ML8vVnbB_5_LV9yraS7wqADC9GQmktQ@mail.gmail.com>

I have stumbled upon some articles by Leonardo Giordani that deal with
OOP in Python.  He has two sets of articles.  The one concerning
Python 2 is located at:
http://blog.thedigitalcatonline.com/blog/2014/03/05/oop-concepts-in-python-2-dot-x-part-1/

The one concerning Python 3 is at:
http://blog.thedigitalcatonline.com/blog/2014/08/20/python-3-oop-part-1-objects-and-types/

The links for the next in each series is at the end of each article.

I have read most of the Python 2 first article and find it very well
written.  I hope these will be useful to others.  Also, it looks like
he has quite a few other articles that look equally interesting!

-- 
boB

From alan.gauld at yahoo.co.uk  Thu Feb 14 05:38:44 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 14 Feb 2019 10:38:44 +0000
Subject: [Tutor] Good tutorials about Python 2 and 3 OOP by Leonardo
 Giordani
In-Reply-To: <CANDiX9+vVqR3bkrB4n9ML8vVnbB_5_LV9yraS7wqADC9GQmktQ@mail.gmail.com>
References: <CANDiX9+vVqR3bkrB4n9ML8vVnbB_5_LV9yraS7wqADC9GQmktQ@mail.gmail.com>
Message-ID: <q43gfk$2k5a$1@blaine.gmane.org>

On 14/02/2019 00:30, boB Stepp wrote:
> I have stumbled upon some articles by Leonardo Giordani that deal with
> OOP in Python.  He has two sets of articles.  The one concerning
> Python 2 is located at:
> http://blog.thedigitalcatonline.com/blog/2014/03/05/oop-concepts-in-python-2-dot-x-part-1/

An interesting article on how the class/object internals
work.

I note there are another 2 in the series but haven't had
time to read them yet.


-- 
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 scopensource at gmail.com  Thu Feb 14 11:44:19 2019
From: scopensource at gmail.com (Simon Connah)
Date: Thu, 14 Feb 2019 16:44:19 +0000
Subject: [Tutor] Python Websocket Server
Message-ID: <3c7621a1-ec54-a0a4-fe9f-512950546f54@gmail.com>

Hi,

I was wondering what the best practice for writing web socket servers in 
Python was in 2019? I found an old example on the web which used the 
tornado library but that was talking about Chrome 22 as the client which 
is ancient now so I'm not sure if things have changed?

Any suggestions on the best library to use would be greatfully accepted. 
I'd ideally like to be able to do it in an asynchronous manner.


From alan.gauld at yahoo.co.uk  Thu Feb 14 17:04:22 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 14 Feb 2019 22:04:22 +0000
Subject: [Tutor] Python Websocket Server
In-Reply-To: <3c7621a1-ec54-a0a4-fe9f-512950546f54@gmail.com>
References: <3c7621a1-ec54-a0a4-fe9f-512950546f54@gmail.com>
Message-ID: <q44ol6$6orl$1@blaine.gmane.org>

On 14/02/2019 16:44, Simon Connah wrote:

> I was wondering what the best practice for writing web socket servers in 
> Python was in 2019? 

I can't answer that directly since I've never used web
sockets in Python (and only played with them in Java).
But...

> I found an old example on the web which used the 
> tornado library but that was talking about Chrome 22 as the client which 
> is ancient now so I'm not sure if things have changed?

THe Websocket API standard was finalized at the end of 2011
so since 2012 there should have been little or no changes.
I would therefore expect your Tornado tutorial to be
fairly reliable.

However, I'd suggest follow up questions are addressed to
either the main python list or to the Tornadso community
directly since it's a bit off the beaten path for the
tutor list community.

-- 
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  Thu Feb 14 18:19:19 2019
From: mats at wichmann.us (Mats Wichmann)
Date: Thu, 14 Feb 2019 16:19:19 -0700
Subject: [Tutor] Python Websocket Server
In-Reply-To: <3c7621a1-ec54-a0a4-fe9f-512950546f54@gmail.com>
References: <3c7621a1-ec54-a0a4-fe9f-512950546f54@gmail.com>
Message-ID: <3234f2c7-3522-593b-59b7-8cb446c7bd80@wichmann.us>

On 2/14/19 9:44 AM, Simon Connah wrote:
> Hi,
> 
> I was wondering what the best practice for writing web socket servers in
> Python was in 2019? I found an old example on the web which used the
> tornado library but that was talking about Chrome 22 as the client which
> is ancient now so I'm not sure if things have changed?
> 
> Any suggestions on the best library to use would be greatfully accepted.
> I'd ideally like to be able to do it in an asynchronous manner.
> 
> _______________________________________________
> Tutor maillist? -? Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor


Full Stack Python's page on the topic has quite a lot of resources:

https://www.fullstackpython.com/websockets.html


The thing to keep in mind with old tutorials is that the state of
Python's own async support has evolved a lot recently.  Before, you
absolutely had to depend on a framework which would do the work of
supporting concurrenct connections or you would go insane, but now
you'll start to see examples, I expect, of doing simple things without
bringing in one of the frameworks.  (If your intent is production work,
the well tested frameworks are still going to be the best bet)




From asad.hasan2004 at gmail.com  Sun Feb 17 03:50:56 2019
From: asad.hasan2004 at gmail.com (Asad)
Date: Sun, 17 Feb 2019 14:20:56 +0530
Subject: [Tutor] Visual studio Code -Python
Message-ID: <CAG3LsKG3Sgdz3dOS0KBPz=PQc+6Bs_vutqf-Kz83=DJo5XY1SA@mail.gmail.com>

Hi All ,

            I am using Visual Studio Code for Python . However I was using
the debug option F5 i see it list the variables in my program neatly ,I set
breakpoints it stops there  but I am unable  to preview each line of the
execution of the code .

Thanks,
--

From mats at wichmann.us  Sun Feb 17 10:27:54 2019
From: mats at wichmann.us (Mats Wichmann)
Date: Sun, 17 Feb 2019 08:27:54 -0700
Subject: [Tutor] Visual studio Code -Python
In-Reply-To: <CAG3LsKG3Sgdz3dOS0KBPz=PQc+6Bs_vutqf-Kz83=DJo5XY1SA@mail.gmail.com>
References: <CAG3LsKG3Sgdz3dOS0KBPz=PQc+6Bs_vutqf-Kz83=DJo5XY1SA@mail.gmail.com>
Message-ID: <171539f7-405e-23be-0510-be75f4274e33@wichmann.us>

On 2/17/19 1:50 AM, Asad wrote:
> Hi All ,
> 
>             I am using Visual Studio Code for Python . However I was using
> the debug option F5 i see it list the variables in my program neatly ,I set
> breakpoints it stops there  but I am unable  to preview each line of the
> execution of the code .
> 
> Thanks,

You'll need to go to the source for that... the Python extension should
have limited instructions, and a bunch of pointers for where to go find
out more, and some animations that intend to show how things work.

Best of luck!



From oscar.j.benjamin at gmail.com  Mon Feb 18 08:27:12 2019
From: oscar.j.benjamin at gmail.com (Oscar Benjamin)
Date: Mon, 18 Feb 2019 13:27:12 +0000
Subject: [Tutor] Putting a Bow on It
In-Reply-To: <q3sbbs$2u96$1@blaine.gmane.org>
References: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>
 <DB6PR0701MB24241E4044041F070E792100836B0@DB6PR0701MB2424.eurprd07.prod.outlook.com>
 <CADUn+-JW7E5c9ghH+Gdz11=9pAu1k7y0NCmJ9bBTopzLoKstRQ@mail.gmail.com>
 <q3sbbs$2u96$1@blaine.gmane.org>
Message-ID: <CAHVvXxSoqdo-MsLJrqSy19DSL=e135WjLQWEA2uLW9HAXYuGoQ@mail.gmail.com>

On Mon, 11 Feb 2019 at 17:30, Alan Gauld via Tutor <tutor at python.org> wrote:
>
> Three is a lot of work going on in Python land but no universal
> solution. Some things work better on particular platforms.
> And building library packages is easier than complete applications.

I think this is the basic problem. There has been a lot of progress in
distributing libraries with pip, wheel etc. For an experienced
programmer it's easy to set something up with pip and venv that gets
you all the libraries you want. It's also pretty straight-forward to
write a setup.py and use setuptools to build the wheels that pop can
then install.

Distributing applications is still problematic though and that's what
Chip wants to do. In particular people often want to be able to do
this in a single file hence py2exe, pyinstaller etc.

But note that most professional software doesn't work that way.
Normally a user can download a single file but that file will be the
installer that then puts all the other files in position.

> But for now, if you have more than a pure Python application,
> you are pretty much stuck with building multiple solutions with
> multiple tools.

Chip is yours a pure Python application?

If it is then my suggestion would be to ask your users (if using
Windows) to install Python from the normal Python downloads page:
https://www.python.org/downloads/

Then you can give them a zipapp of your application:
https://docs.python.org/3/library/zipapp.html

I think if your zipapp has the .py extension and the shebang then it
should be possible to double-click the file to run it on Windows (it's
possible this depends on options ticked/unticked in the Windows
installer - might need to be installed for all users).

The advantage of this approach is that Python already has a
well-maintained installer so you don't have to bother with that part
yourself. It does mean that it's a two step-process for your users but
once they have done the first step you can send them as many zipapps
as you like and it should be fairly easy from there.

I haven't actually tested all of these steps together properly though
so there's a good chance if you try this that you will quickly
encounter some difficulty...

--
Oscar

From wachobc at gmail.com  Mon Feb 18 08:41:25 2019
From: wachobc at gmail.com (Chip Wachob)
Date: Mon, 18 Feb 2019 08:41:25 -0500
Subject: [Tutor] Putting a Bow on It
In-Reply-To: <CAHVvXxSoqdo-MsLJrqSy19DSL=e135WjLQWEA2uLW9HAXYuGoQ@mail.gmail.com>
References: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>
 <DB6PR0701MB24241E4044041F070E792100836B0@DB6PR0701MB2424.eurprd07.prod.outlook.com>
 <CADUn+-JW7E5c9ghH+Gdz11=9pAu1k7y0NCmJ9bBTopzLoKstRQ@mail.gmail.com>
 <q3sbbs$2u96$1@blaine.gmane.org>
 <CAHVvXxSoqdo-MsLJrqSy19DSL=e135WjLQWEA2uLW9HAXYuGoQ@mail.gmail.com>
Message-ID: <CADUn+-JXv9kGyPDQ02seeBy-VqwhsQ5+_BdgQKzWMSSQpGMVZA@mail.gmail.com>

Oscar,

Thanks for your full understanding of my situation.  And putting it into
better words than I did.

The code that I've written is entirely Python.  There are necessary
libraries that go along with that, and, due to my inexperience, I am not
100% certain they are pure Python or not.  Some of the drivers from the IC
manufacturer (FTDI) are .dll files that get installed on the machine, and
I'm sure that's going to have to be a separate step.

I've been tooling around with PyInstaller over the last couple of days, and
it seems to be getting me closer to what I would like.  Unfortunately, I
seem to have hundreds of 'missing' modules.  I'm sure that something must
be missing because I can't launch the .exe file that is created.  It looks
like it is going to run, then it comes up and says it can't execute the
script (not the exact words, but you get the idea).  I'm just not sure how
to cull the 'necessary' modules from the ancillary ones.

I fear that once this is 'in the wild' that folks who don't have much / any
experience with Python will have a really hard time getting all the pieces
together.  Maybe I'm over-concerned, but I've always liked to err on the
side of caution when it comes to 'anyone' being able to do something.

I'm also certain that the 'pros' out there are sitting and saying, 'this
isn't hard to do...  he's being a ninny', but I'm really new to the
language, and feel fortunate that I've gotten to the point where I can
actually 'release' something.

One of the other posts, which I don't think I answered, asked about the
Python version.  Since I have libraries that are locked at 2.7, that is
where I have to stay, and that means that some tools are already off the
table since they are for 3.3, etc.

I really appreciate the input from everyone here.  With the pieces of
information you've offered, I've been able to make a little progress.

Best,



On Mon, Feb 18, 2019 at 8:27 AM Oscar Benjamin <oscar.j.benjamin at gmail.com>
wrote:

> On Mon, 11 Feb 2019 at 17:30, Alan Gauld via Tutor <tutor at python.org>
> wrote:
> >
> > Three is a lot of work going on in Python land but no universal
> > solution. Some things work better on particular platforms.
> > And building library packages is easier than complete applications.
>
> I think this is the basic problem. There has been a lot of progress in
> distributing libraries with pip, wheel etc. For an experienced
> programmer it's easy to set something up with pip and venv that gets
> you all the libraries you want. It's also pretty straight-forward to
> write a setup.py and use setuptools to build the wheels that pop can
> then install.
>
> Distributing applications is still problematic though and that's what
> Chip wants to do. In particular people often want to be able to do
> this in a single file hence py2exe, pyinstaller etc.
>
> But note that most professional software doesn't work that way.
> Normally a user can download a single file but that file will be the
> installer that then puts all the other files in position.
>
> > But for now, if you have more than a pure Python application,
> > you are pretty much stuck with building multiple solutions with
> > multiple tools.
>
> Chip is yours a pure Python application?
>
> If it is then my suggestion would be to ask your users (if using
> Windows) to install Python from the normal Python downloads page:
> https://www.python.org/downloads/
>
> Then you can give them a zipapp of your application:
> https://docs.python.org/3/library/zipapp.html
>
> I think if your zipapp has the .py extension and the shebang then it
> should be possible to double-click the file to run it on Windows (it's
> possible this depends on options ticked/unticked in the Windows
> installer - might need to be installed for all users).
>
> The advantage of this approach is that Python already has a
> well-maintained installer so you don't have to bother with that part
> yourself. It does mean that it's a two step-process for your users but
> once they have done the first step you can send them as many zipapps
> as you like and it should be fairly easy from there.
>
> I haven't actually tested all of these steps together properly though
> so there's a good chance if you try this that you will quickly
> encounter some difficulty...
>
> --
> Oscar
> _______________________________________________
> 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  Mon Feb 18 13:03:49 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 18 Feb 2019 18:03:49 +0000
Subject: [Tutor] Putting a Bow on It
In-Reply-To: <CADUn+-JXv9kGyPDQ02seeBy-VqwhsQ5+_BdgQKzWMSSQpGMVZA@mail.gmail.com>
References: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>
 <DB6PR0701MB24241E4044041F070E792100836B0@DB6PR0701MB2424.eurprd07.prod.outlook.com>
 <CADUn+-JW7E5c9ghH+Gdz11=9pAu1k7y0NCmJ9bBTopzLoKstRQ@mail.gmail.com>
 <q3sbbs$2u96$1@blaine.gmane.org>
 <CAHVvXxSoqdo-MsLJrqSy19DSL=e135WjLQWEA2uLW9HAXYuGoQ@mail.gmail.com>
 <CADUn+-JXv9kGyPDQ02seeBy-VqwhsQ5+_BdgQKzWMSSQpGMVZA@mail.gmail.com>
Message-ID: <q4es25$j8f$1@blaine.gmane.org>

On 18/02/2019 13:41, Chip Wachob wrote:

> The code that I've written is entirely Python.  There are necessary
> libraries that go along with that, and, due to my inexperience, I am not
> 100% certain they are pure Python or not.  Some of the drivers from the IC
> manufacturer (FTDI) are .dll files that get installed on the machine, and
> I'm sure that's going to have to be a separate step.

OK, that tells us something. The app can only run on Windows since DLLs
are Windows specific and won't work on Mac or Linux. That greatly
simplifies your task and means that py2exe is probably your best bet.


> I'm also certain that the 'pros' out there are sitting and saying, 'this
> isn't hard to do...  he's being a ninny', 

Nope, building a distributable application is one of the harder
bits. It's not technically difficult, in that it requires deep math
or anything, it's just a PITA bit of configuration. You can see
just how hard it is by the number of commercial (and freewaare)
apps that exist just for creating Windows installers. If it was
easy there would not be such a 3rd party market!

It's one reason I have tended to work on server based projects
because desktop distribution is a pain. It's also the main reason
most corporates favour web based apps rather than desktop,
despite the performance penalties inherent in the web,
because web apps are so much easier to distribute and maintain.

-- 
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 oscar.j.benjamin at gmail.com  Mon Feb 18 16:06:28 2019
From: oscar.j.benjamin at gmail.com (Oscar Benjamin)
Date: Mon, 18 Feb 2019 21:06:28 +0000
Subject: [Tutor] Putting a Bow on It
In-Reply-To: <CADUn+-JXv9kGyPDQ02seeBy-VqwhsQ5+_BdgQKzWMSSQpGMVZA@mail.gmail.com>
References: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>
 <DB6PR0701MB24241E4044041F070E792100836B0@DB6PR0701MB2424.eurprd07.prod.outlook.com>
 <CADUn+-JW7E5c9ghH+Gdz11=9pAu1k7y0NCmJ9bBTopzLoKstRQ@mail.gmail.com>
 <q3sbbs$2u96$1@blaine.gmane.org>
 <CAHVvXxSoqdo-MsLJrqSy19DSL=e135WjLQWEA2uLW9HAXYuGoQ@mail.gmail.com>
 <CADUn+-JXv9kGyPDQ02seeBy-VqwhsQ5+_BdgQKzWMSSQpGMVZA@mail.gmail.com>
Message-ID: <CAHVvXxR=0zWiPorWdWD_OaaT7nkVQ=kkkwkJF+XDWtX5VsRTYg@mail.gmail.com>

On Mon, 18 Feb 2019 at 13:41, Chip Wachob <wachobc at gmail.com> wrote:
>
> The code that I've written is entirely Python.  There are necessary libraries that go along with that, and, due to my inexperience, I am not 100% certain they are pure Python or not.  Some of the drivers from the IC manufacturer (FTDI) are .dll files that get installed on the machine, and I'm sure that's going to have to be a separate step.

Do you mean that the users will already need to run a separate
installer for the drivers which is already available somewhere? Or do
you mean that you want to bundle those DLLs yourself?

If you are bundling the DLLs then it's no longer pure Python and the
zipapp approach won't work (DLLs cannot be used from inside a zip
file). In that case py2exe/pyinstaller would be the only possible one
file solutions I know of - they also basically zip up your code but in
a self-extracting exe.

> I've been tooling around with PyInstaller over the last couple of days, and it seems to be getting me closer to what I would like.  Unfortunately, I seem to have hundreds of 'missing' modules.  I'm sure that something must be missing because I can't launch the .exe file that is created.  It looks like it is going to run, then it comes up and says it can't execute the script (not the exact words, but you get the idea).  I'm just not sure how to cull the 'necessary' modules from the ancillary ones.

Yeah, you can spend a long time going through that. I guess you've
probably already read this:
https://pyinstaller.readthedocs.io/en/v3.3.1/operating-mode.html#analysis-finding-the-files-your-program-needs
The suggestion there is to get everything working in one folder mode
before trying one file mode.

Before that though: have you got it working with a hello world type
Python script (no dependencies)?

--
Oscar

From wachobc at gmail.com  Mon Feb 18 17:27:12 2019
From: wachobc at gmail.com (Chip Wachob)
Date: Mon, 18 Feb 2019 17:27:12 -0500
Subject: [Tutor] Putting a Bow on It
In-Reply-To: <CAHVvXxR=0zWiPorWdWD_OaaT7nkVQ=kkkwkJF+XDWtX5VsRTYg@mail.gmail.com>
References: <CADUn+-+w-F5xEEKYbuV4pFsmbn4jky+mS7vNAQfRDAs=fPQ7QQ@mail.gmail.com>
 <DB6PR0701MB24241E4044041F070E792100836B0@DB6PR0701MB2424.eurprd07.prod.outlook.com>
 <CADUn+-JW7E5c9ghH+Gdz11=9pAu1k7y0NCmJ9bBTopzLoKstRQ@mail.gmail.com>
 <q3sbbs$2u96$1@blaine.gmane.org>
 <CAHVvXxSoqdo-MsLJrqSy19DSL=e135WjLQWEA2uLW9HAXYuGoQ@mail.gmail.com>
 <CADUn+-JXv9kGyPDQ02seeBy-VqwhsQ5+_BdgQKzWMSSQpGMVZA@mail.gmail.com>
 <CAHVvXxR=0zWiPorWdWD_OaaT7nkVQ=kkkwkJF+XDWtX5VsRTYg@mail.gmail.com>
Message-ID: <CADUn+-LkRMjGDsz_6o2RXvDqu45srq4N+iMKH7iOBGEv7=mztw@mail.gmail.com>

Yes, the .dll files will have to be installed separately.  So that's one
step.

I'd like to package the Python code together and have it all in one
directory (which it currently is).  Trying to limit human intervention
(error) as much as possible.

It does look like I'm going to have to have them pip install some modules
though.  Things like numpy, etc.  I wish I could avoid that, but I don't
see a way around it.

I'll try the Hello World first and see what happens.  Thanks for the
reminder.  Sometimes you get so far into the forest you can't find a tree
to save your behind.

Thank you,


On Mon, Feb 18, 2019 at 4:08 PM Oscar Benjamin <oscar.j.benjamin at gmail.com>
wrote:

> On Mon, 18 Feb 2019 at 13:41, Chip Wachob <wachobc at gmail.com> wrote:
> >
> > The code that I've written is entirely Python.  There are necessary
> libraries that go along with that, and, due to my inexperience, I am not
> 100% certain they are pure Python or not.  Some of the drivers from the IC
> manufacturer (FTDI) are .dll files that get installed on the machine, and
> I'm sure that's going to have to be a separate step.
>
> Do you mean that the users will already need to run a separate
> installer for the drivers which is already available somewhere? Or do
> you mean that you want to bundle those DLLs yourself?
>
> If you are bundling the DLLs then it's no longer pure Python and the
> zipapp approach won't work (DLLs cannot be used from inside a zip
> file). In that case py2exe/pyinstaller would be the only possible one
> file solutions I know of - they also basically zip up your code but in
> a self-extracting exe.
>
> > I've been tooling around with PyInstaller over the last couple of days,
> and it seems to be getting me closer to what I would like.  Unfortunately,
> I seem to have hundreds of 'missing' modules.  I'm sure that something must
> be missing because I can't launch the .exe file that is created.  It looks
> like it is going to run, then it comes up and says it can't execute the
> script (not the exact words, but you get the idea).  I'm just not sure how
> to cull the 'necessary' modules from the ancillary ones.
>
> Yeah, you can spend a long time going through that. I guess you've
> probably already read this:
>
> https://pyinstaller.readthedocs.io/en/v3.3.1/operating-mode.html#analysis-finding-the-files-your-program-needs
> The suggestion there is to get everything working in one folder mode
> before trying one file mode.
>
> Before that though: have you got it working with a hello world type
> Python script (no dependencies)?
>
> --
> Oscar
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

From ontiveros at dawson3d.com  Wed Feb 20 09:30:16 2019
From: ontiveros at dawson3d.com (Mario Ontiveros)
Date: Wed, 20 Feb 2019 14:30:16 +0000
Subject: [Tutor] Help Please
Message-ID: <28F88D0972EA6045BF19CA533D7FA64A031C0391E1@ExchangeMBX01.dawsonmail.local>

Hello,
    I am new to python and have been stuck on this for a while. What I am trying to do is to remove rows with void, disconnected, and error on lines. The code I have does that, the only problem is that it removes my header because void is in header. I need to keep header.

Any help will be greatly appreciated.

with open("PSS.csv","r+") as f:
    new_f = f.readlines()
    f.seek(0)
    for line in new_f:
        if "Void" not in line:
            if "Disconnected" not in line:
                if "Error" not in line:
                 f.write(line)
    f.truncate()



Mario Ontiveros


---------------------------------------------------------------------------------------
Confidentiality Warning: This message and any attachments are intended only for the 
use of the intended recipient(s), are confidential, and may be privileged. If you are 
not the intended recipient, you are hereby notified that any review, retransmission, 
conversion to hard copy, copying, circulation or other use of all or any portion of 
this message and any attachments is strictly prohibited. If you are not the intended 
recipient, please notify the sender immediately by return e-mail, and delete this 
message and any attachments from your system.
---------------------------------------------------------------------------------------

From breamoreboy at gmail.com  Wed Feb 20 20:23:29 2019
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Thu, 21 Feb 2019 01:23:29 +0000
Subject: [Tutor] Help Please
In-Reply-To: <28F88D0972EA6045BF19CA533D7FA64A031C0391E1@ExchangeMBX01.dawsonmail.local>
References: <28F88D0972EA6045BF19CA533D7FA64A031C0391E1@ExchangeMBX01.dawsonmail.local>
Message-ID: <q4kuih$7kun$1@blaine.gmane.org>

On 20/02/2019 14:30, Mario Ontiveros wrote:
> Hello,
>      I am new to python and have been stuck on this for a while. What I am trying to do is to remove rows with void, disconnected, and error on lines. The code I have does that, the only problem is that it removes my header because void is in header. I need to keep header.
> 
> Any help will be greatly appreciated.
> 
> with open("PSS.csv","r+") as f:
>      new_f = f.readlines()
>      f.seek(0)
>      for line in new_f:
>          if "Void" not in line:
>              if "Disconnected" not in line:
>                  if "Error" not in line:
>                   f.write(line)
>      f.truncate()
> 
> 
> 
> Mario Ontiveros
> 

Something like (completely from memory so untested) :-

with open("PSS.csv","r") as inf:
    lines = inf.readlines()

with open("PSS.csv","w") as outf:
    fiter = iter(lines)
    line = next(fiter)
    outf.write(line)
    for line in fiter:
       if "Void" not in line and "Disconnected" not in line and "Error" 
not in line: # probably a simpler way of writing this but I'm knackered :-)
            outf.write(line)
-- 
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  Wed Feb 20 20:27:01 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 21 Feb 2019 01:27:01 +0000
Subject: [Tutor] Help Please
In-Reply-To: <28F88D0972EA6045BF19CA533D7FA64A031C0391E1@ExchangeMBX01.dawsonmail.local>
References: <28F88D0972EA6045BF19CA533D7FA64A031C0391E1@ExchangeMBX01.dawsonmail.local>
Message-ID: <q4kup6$874q$1@blaine.gmane.org>

On 20/02/2019 14:30, Mario Ontiveros wrote:
> Hello,
>     I am new to python and have been stuck on this for a while. What I am trying to do is to remove rows with void, disconnected, and error on lines. The code I have does that, the only problem is that it removes my header because void is in header. I need to keep header.
> 
> Any help will be greatly appreciated.
> 
> with open("PSS.csv","r+") as f:
>     new_f = f.readlines()
>     f.seek(0)
>     for line in new_f:

I don't know how long your header is but assuming it is
only 1 line you can simply use slicing to remove the first
line:

      for line in new_f[1:]:

If the header is multi line simply change to the first line you need to
process, for example to remove 3 lines use new_f[3:]

>         if "Void" not in line:
>             if "Disconnected" not in line:
>                 if "Error" not in line:
>                    f.write(line)

This only writes the line if all three terms are present. Assuming thats
what you want it might be more obviously written as

if ("Void" in line and
   "Disconnected in line and
   "Error" in line):
      f.write(line)

You could also use a regex to search for all three and if its
a long file that will probably be faster since it only traverses
the list once. The snag is the regex gets complex if you need
all three in any order. But if you know the order in which
the terms arise it's probably the best option.

>     f.truncate()

While overwriting the original file works, it's slightly dangerous
in that you lose the original data if anything goes wrong.
The more usual way to do things is to create a new file for writing
then rename it to the original if, and only if, everything works.
You might even rename the original to .bak first to be really safe.

The other advantage of this approach is that you don't need the
readlines)() call but can just process the file line by line
directly which should also be faster.

-- 
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 akleider at sonic.net  Wed Feb 20 23:20:28 2019
From: akleider at sonic.net (Alex Kleider)
Date: Wed, 20 Feb 2019 20:20:28 -0800
Subject: [Tutor] Help Please
In-Reply-To: <28F88D0972EA6045BF19CA533D7FA64A031C0391E1@ExchangeMBX01.dawsonmail.local>
References: <28F88D0972EA6045BF19CA533D7FA64A031C0391E1@ExchangeMBX01.dawsonmail.local>
Message-ID: <899d5097d9608939b1e10eec0f41c7fc@sonic.net>

On 2019-02-20 06:30, Mario Ontiveros wrote:
> Hello,
>     I am new to python and have been stuck on this for a while. What I
> am trying to do is to remove rows with void, disconnected, and error
> on lines. The code I have does that, the only problem is that it
> removes my header because void is in header. I need to keep header.
> 
> Any help will be greatly appreciated.
> 
> with open("PSS.csv","r+") as f:
>     new_f = f.readlines()
>     f.seek(0)
>     for line in new_f:
>         if "Void" not in line:
>             if "Disconnected" not in line:
>                 if "Error" not in line:
>                  f.write(line)
>     f.truncate()
> 
> 
> 
> Mario Ontiveros

Since your file seems to be a csv file, can we assume your 'header' line 
is really a comma separated list of column names?

If so, then using the csv module and specifically csv.DictReader (+/- 
DictWriter) might make things easier for you.

From bouncingcats at gmail.com  Thu Feb 21 02:05:49 2019
From: bouncingcats at gmail.com (David)
Date: Thu, 21 Feb 2019 18:05:49 +1100
Subject: [Tutor] Recommended Resurce or strategy for beginning students
In-Reply-To: <CAFkpTi=P5dj8yQ6fTzEkdzLwH7gsn9ugroCSSdocSAfEBW04iQ@mail.gmail.com>
References: <CAFkpTin2MMDYzZsHv-JHGFDJafMaJ8xRp8BnAVai_kdEqLQf0A@mail.gmail.com>
 <CAMPXz=phFzHPsFAnDMPakAOaCh1+XkiB0SWYkDJ7OdB+HRuBAg@mail.gmail.com>
 <CAFkpTi=P5dj8yQ6fTzEkdzLwH7gsn9ugroCSSdocSAfEBW04iQ@mail.gmail.com>
Message-ID: <CAMPXz=ovv0h1gCjoJvuar9CX7Kgo4dgdQ4HfmXKqETVCHV+1gg@mail.gmail.com>

On Thu, 21 Feb 2019 at 14:35, Matthew Polack
<matthew.polack at htlc.vic.edu.au> wrote:
>
> Just wanted to update this thread regarding a resource for beginning students. We are now 4 weeks into the course and have found ...

Hi Matthew,

Thanks for sharing your progress here! I'm very pleased to hear
you are finding classroom resources that work for you.

I can't resist to throw another left-field link at you, it is not
directly related
to anything you mentioned, but simply in case you or anyone else finds it
interesting.

micropython ... I just discovered it myself recently, here is a video
presentation by its creator:
https://www.youtube.com/watch?v=Zm08hXeuv-I

It is worth watching from the beginning, but there is specific mention
of its use in UK education around time 39:00.

Personally I think that it's very cool to be able to control hardware with
a Python REPL interface.

If you search the web for micropython you will find more resources,
as I currently doing myself, for a specific hardware project.

From matthew.polack at htlc.vic.edu.au  Wed Feb 20 22:35:19 2019
From: matthew.polack at htlc.vic.edu.au (Matthew Polack)
Date: Thu, 21 Feb 2019 14:35:19 +1100
Subject: [Tutor] Recommended Resurce or strategy for beginning students
In-Reply-To: <CAMPXz=phFzHPsFAnDMPakAOaCh1+XkiB0SWYkDJ7OdB+HRuBAg@mail.gmail.com>
References: <CAFkpTin2MMDYzZsHv-JHGFDJafMaJ8xRp8BnAVai_kdEqLQf0A@mail.gmail.com>
 <CAMPXz=phFzHPsFAnDMPakAOaCh1+XkiB0SWYkDJ7OdB+HRuBAg@mail.gmail.com>
Message-ID: <CAFkpTi=P5dj8yQ6fTzEkdzLwH7gsn9ugroCSSdocSAfEBW04iQ@mail.gmail.com>

Hi All,

Just wanted to update this thread regarding a resource for beginning
students. We are now 4 weeks into the course and have found an excellent
youtube series that goes from absolute basics.
https://www.youtube.com/playlist?list=PLLAZ4kZ9dFpMMs5lskzBApYXn0bl7emsW

The big advantage for us in a classroom context is that students can work
through this at their own pace using an Ipad to watch videos and then a
computer to code..

I have some students who are flying through the course and are ready for
more advanced topics..others are working more slowly...but all of them are
enthusiastic and engaged...and the beauty of using a series like this is
they can just go onto the harder topics when they are ready.

After we finish this series my plan is then to go onto Mike's excellent
PySimpleGUI resource...https://pysimplegui.readthedocs.io/tutorial/

I'm sure the students will then enjoy the GUI elements of the code.

We'll also use the Turtle import option to add some graphics interactions

We then might look to use a robotics  resource which is GoPiGo
https://www.dexterindustries.com/gopigo-in-python-tutorials/ which gives us
a chance to explore robotics with Python.

The pleasing thing is how keen the students are to keep learning and asking
questions....

Thanks again for all your support and ideas!

Matthew Polack

On Tue, Feb 5, 2019 at 3:05 PM David <bouncingcats at gmail.com> wrote:

> On Tue, 22 Jan 2019 at 20:30, Matthew Polack
> <matthew.polack at htlc.vic.edu.au> wrote:
> >
> > Hi All,
> >
> > In our growing school we're teaching Python programming for the first
> time
> > as an elective subject with Year 9 and 10 students. (Had a dabble at this
> > last year with 3 students in Year 11)
>
> Hi Matthew and other readers,
>
> I wonder if you and any others here involved in classroom/group teaching
> might be interested in this recent presentation that I stumbled across:
>
> https://media.ccc.de/v/35c3-9800-how_to_teach_programming_to_your_loved_ones
>
> The section of this video which motivates me to write here is the two
> minutes
> from 19:00 to 21:00.
>
> What I find most interesting is his motivation mentioned there: he claims
> his
> procedure solves the problem of any students becoming "lost", feeling
> "stuck"
> at any particular step, not knowing what to do next, and unable to proceed
> without guidance.
>
> Quoting from the synopsis:
> The talk is based on many years of research by the Program by Design,
> DeinProgramm, and Bootstrap educational projects, as well as over 30 years
> of personal teaching experience in school, university and industrial
> contexts.
> A word of warning: The resulting approach is radically different from most
> teaching approaches used in universities and schools. In particular, it
> avoids
> teaching purely through examples and expecting students to develop the
> skills to arrive at the solutions on their own. Instead, it teaches
> explicit
> methodology that enables students to solve problems of surprising
> complexity
> on their own, whether they are 11 or 55, whether in a classroom, a training
> facility, or your home. Extensive documentation, material, and software to
> support this methodology is available for free.
>
> For anyone considering watching the whole presentation, I expect that there
> are many other aspects of this presentation to which people here could
> react
> negatively, for example:
>
> 1) The given title is misleading, in my opinion its subtitle would be much
> more
> representative: "Enabling students [by] example-driven teaching".
>
> 2) It recommends against Python, about this I have no opinion (except
> to respect the presenter's experience) and that is not why I am posting it
> here.
>
> 3) It emphasises functional programming style.
>
> 4) Despite possibly having an audience including skilled programmers, in
> the
> second half of the presentation the presenter does not skip quickly over
> the
> concept, but instead he chooses to demonstrate his concept by reproducing
> the same deliberate steps that he would use in a classroom of students
> with low ability.
>
> Despite all these possibly alienating aspects, and possibly others, I'm not
> really interested in those aspects, because they're not useful to me and so
> I choose to ignore them, instead focussing on what might be useful.
>
> Years ago I spent about a decade teaching undergraduate engineering
> students, from that context I consider this interesting and relevant.
> This presenter mentions that he has 30 years of of experience
> and commitment to teaching this subject, and considers most of his
> efforts a "failure" (at 02:00). Learning from such a person can save other
> practitioners a great deal of effort.
>
> So I felt that this was worth sharing here, I hope negative reactions
> or distractions don't distract from possibly useful information.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

-- 
**Disclaimer: *Whilst every attempt has been made to ensure that material 
contained in this email is free from computer viruses or other defects, the 
attached files are provided, and may only be used, on the basis that the 
user assumes all responsibility for use of the material transmitted. This 
email is intended only for the use of the individual or entity named above 
and may contain information that is confidential and privileged. If you are 
not the intended recipient, please note that any dissemination, 
distribution or copying of this email is strictly prohibited. If you have 
received this email in error, please notify us immediately by return email 
or telephone +61 3 5382 2529**?and destroy the original message.*

From mike_barnett at hotmail.com  Wed Feb 20 22:47:44 2019
From: mike_barnett at hotmail.com (Mike Barnett)
Date: Thu, 21 Feb 2019 03:47:44 +0000
Subject: [Tutor] Recommended Resurce or strategy for beginning students
In-Reply-To: <CAFkpTi=P5dj8yQ6fTzEkdzLwH7gsn9ugroCSSdocSAfEBW04iQ@mail.gmail.com>
References: <CAFkpTin2MMDYzZsHv-JHGFDJafMaJ8xRp8BnAVai_kdEqLQf0A@mail.gmail.com>
 <CAMPXz=phFzHPsFAnDMPakAOaCh1+XkiB0SWYkDJ7OdB+HRuBAg@mail.gmail.com>
 <CAFkpTi=P5dj8yQ6fTzEkdzLwH7gsn9ugroCSSdocSAfEBW04iQ@mail.gmail.com>
Message-ID: <MWHPR11MB1710996A34E93F12DE4A0AC2E07E0@MWHPR11MB1710.namprd11.prod.outlook.com>

Congratulations!!

When going through PySimpleGUI?.
There are some tutorial videos if your students like to learn that way.
https://www.reddit.com/r/Python/comments/9nvdmw/tutorial_beginning_as_in_your_first_time_gui/

And be sure and check out the new PySimpleGUIWeb implementation.

https://www.reddit.com/r/Python/comments/ar3x3b/embedding_entire_python_guis_in_webpages_with/

The latest Cookbook takes advantage of this early port of PySimpleGUIWeb running in the repl.it environment.

It uses repl.it to show how to implement various cookbook Recipes.

The PySimpleGUI account for Repl.it is https://repl.it/@PySimpleGUI which is where you?ll find a number of example programs that run using PySimpleGUIWeb.

Repl.it is AMAZING!  They?re even doing AI contests on there.  Imagine doing Python AI programs without Python even being installed on your computer.

Now your students can program PySimpleGUI code on an iPad if they really wanted.  Any browser window will work with repl.it.

You can write your PySimpleGUI code one time and run it on the web, tkinter, Qt, or WxPython all by just changing the import statement (in theory).

The downside is that each port is a little bit further along than the others.  Tkinter is pretty much done.  Qt is in Alpha.  Wx is Pre-Alpha.  Web is Engineering release.

For doing the basics, PySimpleGUIWeb does remarkably well.  I?m able to use it to demonstrate PySimpleGUI concepts in a way that any reader can understand and execute without  even needing Python installed on their computer.

It?s Remi<https://github.com/dddomodossola/remi>, by the way, that is the magic behind PySimpleGUIWeb.



@mike<mailto:mike_barnett at hotmail.com>

From: Matthew Polack <matthew.polack at htlc.vic.edu.au>
Sent: Wednesday, February 20, 2019 10:35 PM
To: David <bouncingcats at gmail.com>; Mike Barnett <mike_barnett at hotmail.com>; Alan Gauld <alan.gauld at yahoo.co.uk>
Cc: tutor at python.org
Subject: Re: [Tutor] Recommended Resurce or strategy for beginning students

Hi All,

Just wanted to update this thread regarding a resource for beginning students. We are now 4 weeks into the course and have found an excellent youtube series that goes from absolute basics.
https://www.youtube.com/playlist?list=PLLAZ4kZ9dFpMMs5lskzBApYXn0bl7emsW<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fplaylist%3Flist%3DPLLAZ4kZ9dFpMMs5lskzBApYXn0bl7emsW&data=02%7C01%7C%7Cb9d9a4d30a4542f68a5708d697ada125%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636863169316775701&sdata=gCftFiMvcghFeAcNeXmeZaT426VsV2Enb5UnfbowfUw%3D&reserved=0>

The big advantage for us in a classroom context is that students can work through this at their own pace using an Ipad to watch videos and then a computer to code..

I have some students who are flying through the course and are ready for more advanced topics..others are working more slowly...but all of them are enthusiastic and engaged...and the beauty of using a series like this is they can just go onto the harder topics when they are ready.

After we finish this series my plan is then to go onto Mike's excellent PySimpleGUI resource...https://pysimplegui.readthedocs.io/tutorial/<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpysimplegui.readthedocs.io%2Ftutorial%2F&data=02%7C01%7C%7Cb9d9a4d30a4542f68a5708d697ada125%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636863169316785707&sdata=3bpI7rXaMWfLh06x5wZV6wVlS8yFM5hui2cipegkLro%3D&reserved=0>

I'm sure the students will then enjoy the GUI elements of the code.

We'll also use the Turtle import option to add some graphics interactions

We then might look to use a robotics  resource which is GoPiGo https://www.dexterindustries.com/gopigo-in-python-tutorials/<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.dexterindustries.com%2Fgopigo-in-python-tutorials%2F&data=02%7C01%7C%7Cb9d9a4d30a4542f68a5708d697ada125%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636863169316795718&sdata=DbcV4Auj9wYyFZGu7AcKlSWxFPiIdzhbNkW5%2BHKIOcQ%3D&reserved=0> which gives us a chance to explore robotics with Python.

The pleasing thing is how keen the students are to keep learning and asking questions....

Thanks again for all your support and ideas!

Matthew Polack

On Tue, Feb 5, 2019 at 3:05 PM David <bouncingcats at gmail.com<mailto:bouncingcats at gmail.com>> wrote:
On Tue, 22 Jan 2019 at 20:30, Matthew Polack
<matthew.polack at htlc.vic.edu.au<mailto:matthew.polack at htlc.vic.edu.au>> wrote:
>
> Hi All,
>
> In our growing school we're teaching Python programming for the first time
> as an elective subject with Year 9 and 10 students. (Had a dabble at this
> last year with 3 students in Year 11)

Hi Matthew and other readers,

I wonder if you and any others here involved in classroom/group teaching
might be interested in this recent presentation that I stumbled across:
https://media.ccc.de/v/35c3-9800-how_to_teach_programming_to_your_loved_ones<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmedia.ccc.de%2Fv%2F35c3-9800-how_to_teach_programming_to_your_loved_ones&data=02%7C01%7C%7Cb9d9a4d30a4542f68a5708d697ada125%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636863169316805729&sdata=wKSTBNo3pu6C8aEh9nDIrsTEoTWIxnKrp%2Fc8LD4XHRY%3D&reserved=0>

The section of this video which motivates me to write here is the two minutes
from 19:00 to 21:00.

What I find most interesting is his motivation mentioned there: he claims his
procedure solves the problem of any students becoming "lost", feeling "stuck"
at any particular step, not knowing what to do next, and unable to proceed
without guidance.

Quoting from the synopsis:
The talk is based on many years of research by the Program by Design,
DeinProgramm, and Bootstrap educational projects, as well as over 30 years
of personal teaching experience in school, university and industrial contexts.
A word of warning: The resulting approach is radically different from most
teaching approaches used in universities and schools. In particular, it avoids
teaching purely through examples and expecting students to develop the
skills to arrive at the solutions on their own. Instead, it teaches explicit
methodology that enables students to solve problems of surprising complexity
on their own, whether they are 11 or 55, whether in a classroom, a training
facility, or your home. Extensive documentation, material, and software to
support this methodology is available for free.

For anyone considering watching the whole presentation, I expect that there
are many other aspects of this presentation to which people here could react
negatively, for example:

1) The given title is misleading, in my opinion its subtitle would be much more
representative: "Enabling students [by] example-driven teaching".

2) It recommends against Python, about this I have no opinion (except
to respect the presenter's experience) and that is not why I am posting it here.

3) It emphasises functional programming style.

4) Despite possibly having an audience including skilled programmers, in the
second half of the presentation the presenter does not skip quickly over the
concept, but instead he chooses to demonstrate his concept by reproducing
the same deliberate steps that he would use in a classroom of students
with low ability.

Despite all these possibly alienating aspects, and possibly others, I'm not
really interested in those aspects, because they're not useful to me and so
I choose to ignore them, instead focussing on what might be useful.

Years ago I spent about a decade teaching undergraduate engineering
students, from that context I consider this interesting and relevant.
This presenter mentions that he has 30 years of of experience
and commitment to teaching this subject, and considers most of his
efforts a "failure" (at 02:00). Learning from such a person can save other
practitioners a great deal of effort.

So I felt that this was worth sharing here, I hope negative reactions
or distractions don't distract from possibly useful information.
_______________________________________________
Tutor maillist  -  Tutor at python.org<mailto:Tutor at python.org>
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor<https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Ftutor&data=02%7C01%7C%7Cb9d9a4d30a4542f68a5708d697ada125%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636863169316815734&sdata=w8%2BdSnetEZ6IpCpGooi2SDQwkOOM2I6ZFIqMW2AAjsw%3D&reserved=0>

Disclaimer: Whilst every attempt has been made to ensure that material contained in this email is free from computer viruses or other defects, the attached files are provided, and may only be used, on the basis that the user assumes all responsibility for use of the material transmitted. This email is intended only for the use of the individual or entity named above and may contain information that is confidential and privileged. If you are not the intended recipient, please note that any dissemination, distribution or copying of this email is strictly prohibited. If you have received this email in error, please notify us immediately by return email or telephone +61 3 5382 2529 and destroy the original message.

From phillor1948 at gmail.com  Thu Feb 21 00:41:03 2019
From: phillor1948 at gmail.com (Phil)
Date: Thu, 21 Feb 2019 16:11:03 +1030
Subject: [Tutor] Conway's game of life
Message-ID: <CAGmYHSUncXx+TYo6xj_7hkbt3cueBPQP-gttkCM=xh86kktL4w@mail.gmail.com>

Thank you for reading this.

It's been quite some time since I've attempted any programming and since
I've recently discovered PySimpleGUI I thought I'd have a go at programming
Conway's game of life. Unfortunately, I've been stuck trying to resolve a
logic error for the past couple of weeks using the IDLE debugger and a host
of print statements. I can see where the error occurs but I cannot see why.

The error occurs at the point of the third generation which results in a
fixed pattern of cells rather that a looping pattern. It's always the third
generation no matter what the initial pattern is. The error seems to be in
the area where the rules are applied.

Can a kind person spend a couple of minutes to find what is most likely an
obvious error?

import sys
import PySimpleGUI as sg
import time
import numpy

layout = [[sg.Graph(canvas_size=(400, 400),
                   graph_bottom_left=(0,20),
                   graph_top_right=(20,0),
                   background_color='white',
                   key='graph')],]

window = sg.Window('The game of life',
grab_anywhere=True).Layout(layout).Finalize()

graph = window.FindElement('graph')

board_size = 8#20

dead = 0
live = 1

#board = [[dead] * board_size for i in range(board_size)]
#next_board = [[dead] * board_size for i in range(board_size)]

board = numpy.zeros(board_size * board_size, dtype='i').reshape(board_size,
board_size)
#board = numpy.zeros((board_size, board_size))

#next_board = numpy.zeros((board_size, board_size))
next_board = numpy.zeros(board_size * board_size,
dtype='i').reshape(board_size, board_size)


'''
seed board[y][x] NOT board[x][y]
'''

board [1][1] = dead
board [1][2] = live
board [1][3] = dead

board [2][1] = dead
board [2][2] = dead
board [2][3] = live

board [3][1] = live
board [3][2] = live
board [3][3] = live

def display():
    event, values = window.Read(timeout = 0)

    for y in range(board_size):
        for x in range(board_size):

            if (board[x][y]) == 0:
                graph.DrawCircle((y,x), 5, line_color='white',
fill_color='red')#'white')

            else:
                graph.DrawCircle((y,x), 5, line_color='black',
fill_color='black')

    window.Refresh()

    time.sleep(2)

def count_live_neighbours(x, y):
    live_neighbours = 0

    debug_cell = board[x][y]

    for i in range(-1, 2):
        for j in range(-1, 2):
            live_neighbours += board[x + i][y + j]

    #don't count the cell at x = 0 and y = 0
    live_neighbours -= board[x][y]

    return live_neighbours

#display initial board
display()

while True:
    #clear next_board
    #next_board.fill(0)

    for x in range(1, board_size - 1):
        for y in range(1, board_size - 1):

            live_neighbours = count_live_neighbours(x, y)

            '''
Any live cell with fewer than two live neighbors dies, as if by
underpopulation.
Any live cell with two or three live neighbors lives on to the next
generation.
Any live cell with more than three live neighbors dies, as if by
overpopulation.
Any dead cell with exactly three live neighbors becomes a live cell, as if
by reproduction.

            '''
            if board[x][y] == 1 and live_neighbours <  2:
                next_board[x][y] = 0

            elif board[x][y] == 1 and live_neighbours >  3:
                next_board[x][y] = 0

            elif board[x][y] == 0 and live_neighbours == 3:
                next_board[x][y] = 1

            elif board[x][y] == 1 and (live_neighbours == 2 or
live_neighbours == 3):
                next_board[x][y] = 1

            #else:
                #next_board[x][y] = board[x][y]

    board = next_board

    display()





-- 
Regards,
Phil

From PyTutor at danceswithmice.info  Thu Feb 21 00:27:21 2019
From: PyTutor at danceswithmice.info (DL Neil)
Date: Thu, 21 Feb 2019 18:27:21 +1300
Subject: [Tutor] Help Please
In-Reply-To: <28F88D0972EA6045BF19CA533D7FA64A031C0391E1@ExchangeMBX01.dawsonmail.local>
References: <28F88D0972EA6045BF19CA533D7FA64A031C0391E1@ExchangeMBX01.dawsonmail.local>
Message-ID: <6e7e1c3d-b321-acf9-ac04-a38d78e6734c@DancesWithMice.info>

Mario,

On 21/02/19 3:30 AM, Mario Ontiveros wrote:
> Hello,
>      I am new to python and have been stuck on this for a while. What I am trying to do is to remove rows with void, disconnected, and error on lines. The code I have does that, the only problem is that it removes my header because void is in header. I need to keep header.
> with open("PSS.csv","r+") as f:
>      new_f = f.readlines()
>      f.seek(0)
>      for line in new_f:
>          if "Void" not in line:
>              if "Disconnected" not in line:
>                  if "Error" not in line:
>                   f.write(line)
>      f.truncate()


Would it be 'safer' to create a separate output file?

Rather than reading the entire file (easily managed if short, but 
unwieldy and RAM-hungry if thousands of records!), consider that a file 
object is an iterable and process it one line/record at a time.

with open( ... ) as f:
	header = f.readline()
	# deal with the header record
	for record in f:
		function_keep_or_discard( record )
	#etc


In case it helps you to follow the above, and possibly to learn other 
applications of this thinking, herewith:-

An iterable matches a for-each-loop very neatly (by design). It consists 
of two aspects: next() ie give me the next value (thus for each value in 
turn), and the StopIteration exception (when next() asks for another 
value after they have all been processed). The for 'swallows' the 
exception because it is expected. Hence, you don't need to try...except!

Something a lot of pythonistas don't stop to consider, is that once code 
starts iterating an object, the iteration does not 'reset' until 
"exhausted" (unlike your use of f.seek(0) against the output file). 
Accordingly, we can use a 'bare' next() to pick-out the first (header) 
record and then pass the rest of the job (all the other next()s) to a 
for-each-loop:

with open( ... ) as f:
	header = next( f )	# grab the first record
	# deal with the header record
	for record in f:	# iterate through the remaining records
		#etc

-- 
Regards =dn

From akleider at sonic.net  Fri Feb 22 11:55:52 2019
From: akleider at sonic.net (Alex Kleider)
Date: Fri, 22 Feb 2019 08:55:52 -0800
Subject: [Tutor] import failure
Message-ID: <f8c63681d86317d1551844c04909b6a3@sonic.net>


I'm trying to programmatically manipulate my google contacts using
a library (https://github.com/google/gdata-python-client) which I've
cloned.  The documentation suggests running a test to start with
which I did (OS: Ubuntu 18.4, running in a python2.7 venv 'p2')
with the following rather puzzling results (explanation below):

(p2) alex at one:$ pwd
/home/alex/Proj/G/gdata-python-client
(p2) alex at one:$ ls
build                INSTALL.txt  pydocs             samples             
src
contacts_example.py  Makefile     README.txt         set_python_path.sh  
tests
__init__.py          MANIFEST.in  RELEASE_NOTES.txt  setup.py            
upload-diffs.py
(p2) alex at one:$ ./tests/run_data_tests.py
Traceback (most recent call last):
   File "./tests/run_data_tests.py", line 19, in <module>
     import gdata_tests.auth_test
   File 
"/home/alex/Proj/G/gdata-python-client/tests/gdata_tests/auth_test.py", 
line 24, in <module>
     import gdata.auth
   File "/home/alex/Proj/G/gdata-python-client/src/gdata/auth.py", line 
29, in <module>
     import gdata.oauth.rsa as oauth_rsa
   File "/home/alex/Proj/G/gdata-python-client/src/gdata/oauth/rsa.py", 
line 10, in <module>
     from tlslite.utils import keyfactory
ImportError: No module named tlslite.utils
(p2) alex at one:$ pip install tlslite
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 
2020. Please upgrade your Python as Python 2.7 won't be maintained after 
that date. A future version of pip will drop support for Python 2.7.
Collecting tlslite
   Downloading 
https://files.pythonhosted.org/packages/92/2b/7904cf913d9bf150b3e408a92c9cb5ce0b97a9ec19f998af48bf4c607f0e/tlslite-0.4.9.tar.gz 
(105kB)
     100% |                               | 112kB 174kB/s
     100% |                               | 112kB 174kB/s
Building wheels for collected packages: tlslite
   Building wheel for tlslite (setup.py) ... done
   Stored in directory: 
/home/alex/.cache/pip/wheels/f8/de/72/213ac7112be37bc832e971c092757ae92aa5ae4b433e214ba9
Successfully built tlslite
Installing collected packages: tlslite
Successfully installed tlslite-0.4.9
(p2) alex at one:$ ./tests/run_data_tests.py
Traceback (most recent call last):
   File "./tests/run_data_tests.py", line 19, in <module>
     import gdata_tests.auth_test
   File 
"/home/alex/Proj/G/gdata-python-client/tests/gdata_tests/auth_test.py", 
line 24, in <module>
     import gdata.auth
   File "/home/alex/Proj/G/gdata-python-client/src/gdata/auth.py", line 
29, in <module>
     import gdata.oauth.rsa as oauth_rsa
   File "/home/alex/Proj/G/gdata-python-client/src/gdata/oauth/rsa.py", 
line 10, in <module>
     from tlslite.utils import keyfactory
ImportError: No module named tlslite.utils
(p2) alex at one:$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tlslite
>>> exit()
(p2) alex at one:$ vim src/gdata/oauth/rsa.py
(p2) alex at one:$ cat src/gdata/oauth/rsa.py | tail -n 4
if __name__ == "__main__":
     print("key_factory = " + repr(keyfactory))
(p2) alex at one:$ python src/gdata/oauth/rsa.py
key_factory = <module 'tlslite.utils.keyfactory' from 
'/home/alex/.virtualenvs/p2/local/lib/python2.7/site-packages/tlslite/utils/keyfactory.pyc'>
(p2) alex at one:$ python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from tlslite.utils import keyfactory
>>> 

Details: The initial run failed because of unavailability of a module.
A little reading led to the discovery that it could be easily installed
using pip but after doing so: Still the same failure.
Running the interpreter proves that the module is now available but the
test still fails.
Adding a bit of code to the bottom of the failing module shows that it
in fact can import the module in question.
Ran the interpreter again just to be sure that the function is available
and indeed it is.
I don't understand how this could be possible.

Any suggestions as to what the problem might be or how to investigate
further would be very much appreciated.

Cheers,
Alex

-- 
Alex Kleider
(sent from my current gizmo)

From __peter__ at web.de  Fri Feb 22 12:42:36 2019
From: __peter__ at web.de (Peter Otten)
Date: Fri, 22 Feb 2019 18:42:36 +0100
Subject: [Tutor] import failure
References: <f8c63681d86317d1551844c04909b6a3@sonic.net>
Message-ID: <q4pcac$7b6v$1@blaine.gmane.org>

Alex Kleider wrote:

> (p2) alex at one:$ ./tests/run_data_tests.py

Here you let the script decide which interpreter to pick...

> Traceback (most recent call last):

> ImportError: No module named tlslite.utils

...and it looks like it's not the one you'd like to have:

> (p2) alex at one:$ python
> Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
> [GCC 7.3.0] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import tlslite
>>>> exit()

> Any suggestions as to what the problem might be or how to investigate
> further would be very much appreciated.

Try

(p2) alex at one:$ python ./tests/run_data_tests.py




From mats at wichmann.us  Fri Feb 22 12:48:10 2019
From: mats at wichmann.us (Mats Wichmann)
Date: Fri, 22 Feb 2019 09:48:10 -0800
Subject: [Tutor] import failure
In-Reply-To: <f8c63681d86317d1551844c04909b6a3@sonic.net>
References: <f8c63681d86317d1551844c04909b6a3@sonic.net>
Message-ID: <3daf6ae7-e9dd-bbd2-20f5-46bac759984e@wichmann.us>

On 2/22/19 9:55 AM, Alex Kleider wrote:

> (p2) alex at one:$ python src/gdata/oauth/rsa.py
> key_factory = <module 'tlslite.utils.keyfactory' from 
> '/home/alex/.virtualenvs/p2/local/lib/python2.7/site-packages/tlslite/utils/keyfactory.pyc'> 
> 
> (p2) alex at one:$ python
> Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
> [GCC 7.3.0] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from tlslite.utils import keyfactory
>>>>
> 
> Details: The initial run failed because of unavailability of a module.
> A little reading led to the discovery that it could be easily installed
> using pip but after doing so: Still the same failure.
> Running the interpreter proves that the module is now available but the
> test still fails.
> Adding a bit of code to the bottom of the failing module shows that it
> in fact can import the module in question.
> Ran the interpreter again just to be sure that the function is available
> and indeed it is.
> I don't understand how this could be possible.
> 
> Any suggestions as to what the problem might be or how to investigate
> further would be very much appreciated.
> 
> Cheers,
> Alex

pip installs are specific to the interpreter, you're probably getting a 
mismatch there.

Rule one: install this way:

python -m pip install sheepdip

that way you're sure the pip matches the python and things go in the 
expected place.

Rule 2:
you can do some inspection by printing the values of sys.executable and 
sys.path both in your interactive environment where it works and in your 
script where it doesn't work.

My guess is you'll find a mismatch... but this is only surmise, 
something to try out, we can't see your precise environment.




From ontiveros at dawson3d.com  Fri Feb 22 12:41:43 2019
From: ontiveros at dawson3d.com (Mario Ontiveros)
Date: Fri, 22 Feb 2019 17:41:43 +0000
Subject: [Tutor] [EXTERNAL] Re:  Help Please
In-Reply-To: <899d5097d9608939b1e10eec0f41c7fc@sonic.net>
References: <28F88D0972EA6045BF19CA533D7FA64A031C0391E1@ExchangeMBX01.dawsonmail.local>
 <899d5097d9608939b1e10eec0f41c7fc@sonic.net>
Message-ID: <28F88D0972EA6045BF19CA533D7FA64A031C03AFCD@ExchangeMBX01.dawsonmail.local>

Thanks Alex,
This helped.

Mario Ontiveros



-----Original Message-----
From: Alex Kleider [mailto:akleider at sonic.net] 
Sent: Wednesday, February 20, 2019 10:20 PM
To: Mario Ontiveros
Cc: tutor at python.org; Tutor
Subject: [EXTERNAL] Re: [Tutor] Help Please

On 2019-02-20 06:30, Mario Ontiveros wrote:
> Hello,
>     I am new to python and have been stuck on this for a while. What I
> am trying to do is to remove rows with void, disconnected, and error
> on lines. The code I have does that, the only problem is that it
> removes my header because void is in header. I need to keep header.
> 
> Any help will be greatly appreciated.
> 
> with open("PSS.csv","r+") as f:
>     new_f = f.readlines()
>     f.seek(0)
>     for line in new_f:
>         if "Void" not in line:
>             if "Disconnected" not in line:
>                 if "Error" not in line:
>                  f.write(line)
>     f.truncate()
> 
> 
> 
> Mario Ontiveros

Since your file seems to be a csv file, can we assume your 'header' line 
is really a comma separated list of column names?

If so, then using the csv module and specifically csv.DictReader (+/- 
DictWriter) might make things easier for you.


---------------------------------------------------------------------------------------
Confidentiality Warning: This message and any attachments are intended only for the 
use of the intended recipient(s), are confidential, and may be privileged. If you are 
not the intended recipient, you are hereby notified that any review, retransmission, 
conversion to hard copy, copying, circulation or other use of all or any portion of 
this message and any attachments is strictly prohibited. If you are not the intended 
recipient, please notify the sender immediately by return e-mail, and delete this 
message and any attachments from your system.
---------------------------------------------------------------------------------------

From akleider at sonic.net  Sat Feb 23 13:51:44 2019
From: akleider at sonic.net (Alex Kleider)
Date: Sat, 23 Feb 2019 10:51:44 -0800
Subject: [Tutor] import failure
In-Reply-To: <3daf6ae7-e9dd-bbd2-20f5-46bac759984e@wichmann.us>
References: <f8c63681d86317d1551844c04909b6a3@sonic.net>
 <3daf6ae7-e9dd-bbd2-20f5-46bac759984e@wichmann.us>
Message-ID: <22a5580f842660bdd64b40ebb0d07e3a@sonic.net>

On 2019-02-22 09:48, Mats Wichmann wrote:
> 

> 
> pip installs are specific to the interpreter, you're probably getting
> a mismatch there.
> 
> Rule one: install this way:
> 
> python -m pip install sheepdip
> 
> that way you're sure the pip matches the python and things go in the
> expected place.
> 
> Rule 2:
> you can do some inspection by printing the values of sys.executable
> and sys.path both in your interactive environment where it works and
> in your script where it doesn't work.
> 
> My guess is you'll find a mismatch... but this is only surmise,
> something to try out, we can't see your precise environment.

Thanks again for the input.
As I mentioned in response to Peter's response, a mismatch was 
definitely the problem.
The program I was trying to run had as its first line:
     #!/usr/bin/python
I wrongly reported that the 'shebang' was
     #!/usr/bin/env python
When changed to the latter, the program runs as I expected.

Thanks to both of you for your guidance.
Alex

From breamoreboy at gmail.com  Sat Feb 23 14:41:48 2019
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Sat, 23 Feb 2019 19:41:48 +0000
Subject: [Tutor] import failure
In-Reply-To: <f8c63681d86317d1551844c04909b6a3@sonic.net>
References: <f8c63681d86317d1551844c04909b6a3@sonic.net>
Message-ID: <q4s7ls$2nu8$1@blaine.gmane.org>

On 22/02/2019 16:55, Alex Kleider wrote:
> 
> I'm trying to programmatically manipulate my google contacts using
> a library (https://github.com/google/gdata-python-client) which I've
> cloned.? The documentation suggests running a test to start with
> which I did (OS: Ubuntu 18.4, running in a python2.7 venv 'p2')
> with the following rather puzzling results (explanation below):
> 
> (p2) alex at one:$ pwd
> /home/alex/Proj/G/gdata-python-client
> (p2) alex at one:$ ls
> build??????????????? INSTALL.txt? pydocs???????????? samples src
> contacts_example.py? Makefile???? README.txt???????? set_python_path.sh 
> tests
> __init__.py????????? MANIFEST.in? RELEASE_NOTES.txt? setup.py 
> upload-diffs.py
> (p2) alex at one:$ ./tests/run_data_tests.py
> Traceback (most recent call last):
>  ? File "./tests/run_data_tests.py", line 19, in <module>
>  ??? import gdata_tests.auth_test
>  ? File 
> "/home/alex/Proj/G/gdata-python-client/tests/gdata_tests/auth_test.py", 
> line 24, in <module>
>  ??? import gdata.auth
>  ? File "/home/alex/Proj/G/gdata-python-client/src/gdata/auth.py", line 
> 29, in <module>
>  ??? import gdata.oauth.rsa as oauth_rsa
>  ? File "/home/alex/Proj/G/gdata-python-client/src/gdata/oauth/rsa.py", 
> line 10, in <module>
>  ??? from tlslite.utils import keyfactory
> ImportError: No module named tlslite.utils
> (p2) alex at one:$ pip install tlslite
> DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 
> 2020. Please upgrade your Python as Python 2.7 won't be maintained after 
> that date. A future version of pip will drop support for Python 2.7.
> Collecting tlslite
>  ? Downloading 
> https://files.pythonhosted.org/packages/92/2b/7904cf913d9bf150b3e408a92c9cb5ce0b97a9ec19f998af48bf4c607f0e/tlslite-0.4.9.tar.gz 
> (105kB)
>  ??? 100% |?????????????????????????????? | 112kB 174kB/s
>  ??? 100% |?????????????????????????????? | 112kB 174kB/s
> Building wheels for collected packages: tlslite
>  ? Building wheel for tlslite (setup.py) ... done
>  ? Stored in directory: 
> /home/alex/.cache/pip/wheels/f8/de/72/213ac7112be37bc832e971c092757ae92aa5ae4b433e214ba9 
> 
> Successfully built tlslite
> Installing collected packages: tlslite
> Successfully installed tlslite-0.4.9
> (p2) alex at one:$ ./tests/run_data_tests.py
> Traceback (most recent call last):
>  ? File "./tests/run_data_tests.py", line 19, in <module>
>  ??? import gdata_tests.auth_test
>  ? File 
> "/home/alex/Proj/G/gdata-python-client/tests/gdata_tests/auth_test.py", 
> line 24, in <module>
>  ??? import gdata.auth
>  ? File "/home/alex/Proj/G/gdata-python-client/src/gdata/auth.py", line 
> 29, in <module>
>  ??? import gdata.oauth.rsa as oauth_rsa
>  ? File "/home/alex/Proj/G/gdata-python-client/src/gdata/oauth/rsa.py", 
> line 10, in <module>
>  ??? from tlslite.utils import keyfactory
> ImportError: No module named tlslite.utils
> (p2) alex at one:$ python
> Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
> [GCC 7.3.0] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import tlslite
>>>> exit()
> (p2) alex at one:$ vim src/gdata/oauth/rsa.py
> (p2) alex at one:$ cat src/gdata/oauth/rsa.py | tail -n 4
> if __name__ == "__main__":
>  ??? print("key_factory = " + repr(keyfactory))
> (p2) alex at one:$ python src/gdata/oauth/rsa.py
> key_factory = <module 'tlslite.utils.keyfactory' from 
> '/home/alex/.virtualenvs/p2/local/lib/python2.7/site-packages/tlslite/utils/keyfactory.pyc'> 
> 
> (p2) alex at one:$ python
> Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
> [GCC 7.3.0] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from tlslite.utils import keyfactory
>>>>
> 
> Details: The initial run failed because of unavailability of a module.
> A little reading led to the discovery that it could be easily installed
> using pip but after doing so: Still the same failure.
> Running the interpreter proves that the module is now available but the
> test still fails.
> Adding a bit of code to the bottom of the failing module shows that it
> in fact can import the module in question.
> Ran the interpreter again just to be sure that the function is available
> and indeed it is.
> I don't understand how this could be possible.
> 
> Any suggestions as to what the problem might be or how to investigate
> further would be very much appreciated.
> 
> Cheers,
> Alex
> 

Just to follow up there are some useful tips in this 
https://mail.python.org/pipermail/python-list/2019-February/739643.html 
as to how to debug these type of problems.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


From mats at wichmann.us  Sat Feb 23 18:40:27 2019
From: mats at wichmann.us (Mats Wichmann)
Date: Sat, 23 Feb 2019 15:40:27 -0800
Subject: [Tutor] Visual studio Code -Python
In-Reply-To: <CAG3LsKENMB9FSf=AK7ki9az9BzuH1iRnM-rN-o8EGucN3VF0aw@mail.gmail.com>
References: <CAG3LsKG3Sgdz3dOS0KBPz=PQc+6Bs_vutqf-Kz83=DJo5XY1SA@mail.gmail.com>
 <171539f7-405e-23be-0510-be75f4274e33@wichmann.us>
 <CAG3LsKENMB9FSf=AK7ki9az9BzuH1iRnM-rN-o8EGucN3VF0aw@mail.gmail.com>
Message-ID: <6470f89c-97fe-c904-27f1-2686b11a22ea@wichmann.us>

On 2/23/19 5:23 AM, Asad wrote:
> Hi All ,
> 
>  ? ? ? ? ?I am using : pdb.set_trace()
>  ? ? ? ? ? can you all share some good tricks i using n ,s , l . The 
> tedious part which I see is? if it is a loop like for loop then I need 
> to do next till the length for the data is completed
> 
> for x in string :
>  ? ? ?if re.search(x,line)
> 
> len(string)
>  ? ? = 2500
> 
> therefore I need to press n 2500 time so that the loop completes and 
> goes to another line of code . Any suggestions? how can run the for loop 
> without doing n for 2500 times ?

pdb has an "until" command you can use to get it to run until the line 
after the loop, if that's what you are looking for.  sorry, it's a 
little hard to tell what you *are* looking for.



From asad.hasan2004 at gmail.com  Sat Feb 23 07:23:42 2019
From: asad.hasan2004 at gmail.com (Asad)
Date: Sat, 23 Feb 2019 17:53:42 +0530
Subject: [Tutor] Visual studio Code -Python
In-Reply-To: <171539f7-405e-23be-0510-be75f4274e33@wichmann.us>
References: <CAG3LsKG3Sgdz3dOS0KBPz=PQc+6Bs_vutqf-Kz83=DJo5XY1SA@mail.gmail.com>
 <171539f7-405e-23be-0510-be75f4274e33@wichmann.us>
Message-ID: <CAG3LsKENMB9FSf=AK7ki9az9BzuH1iRnM-rN-o8EGucN3VF0aw@mail.gmail.com>

Hi All ,

         I am using : pdb.set_trace()

          can you all share some good tricks i using n ,s , l . The tedious
part which I see is  if it is a loop like for loop then I need to do next
till the length for the data is completed

for x in string :
     if re.search(x,line)

len(string)
    = 2500

therefore I need to press n 2500 time so that the loop completes and goes
to another line of code . Any suggestions? how can run the for loop without
doing n for 2500 times ?

Thanks,

On Sun, Feb 17, 2019 at 8:58 PM Mats Wichmann <mats at wichmann.us> wrote:

> On 2/17/19 1:50 AM, Asad wrote:
> > Hi All ,
> >
> >             I am using Visual Studio Code for Python . However I was
> using
> > the debug option F5 i see it list the variables in my program neatly ,I
> set
> > breakpoints it stops there  but I am unable  to preview each line of the
> > execution of the code .
> >
> > Thanks,
>
> You'll need to go to the source for that... the Python extension should
> have limited instructions, and a bunch of pointers for where to go find
> out more, and some animations that intend to show how things work.
>
> Best of luck!
>
>
>

-- 
Asad Hasan
+91 9582111698

From breamoreboy at gmail.com  Sat Feb 23 19:42:06 2019
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Sun, 24 Feb 2019 00:42:06 +0000
Subject: [Tutor] Visual studio Code -Python
In-Reply-To: <CAG3LsKENMB9FSf=AK7ki9az9BzuH1iRnM-rN-o8EGucN3VF0aw@mail.gmail.com>
References: <CAG3LsKG3Sgdz3dOS0KBPz=PQc+6Bs_vutqf-Kz83=DJo5XY1SA@mail.gmail.com>
 <171539f7-405e-23be-0510-be75f4274e33@wichmann.us>
 <CAG3LsKENMB9FSf=AK7ki9az9BzuH1iRnM-rN-o8EGucN3VF0aw@mail.gmail.com>
Message-ID: <q4sp8v$7547$1@blaine.gmane.org>

On 23/02/2019 12:23, Asad wrote:

Please don't top post, it is so irritating when trying to read threads, TIA.

> Hi All ,
> 
>           I am using : pdb.set_trace()
> 
>            can you all share some good tricks i using n ,s , l . The tedious
> part which I see is  if it is a loop like for loop then I need to do next
> till the length for the data is completed
> 
> for x in string :
>       if re.search(x,line)
> 
> len(string)
>      = 2500
> 
> therefore I need to press n 2500 time so that the loop completes and goes
> to another line of code . Any suggestions? how can run the for loop without
> doing n for 2500 times ?
> 

Set a breakpoint on the first line after the loop, please see 
https://code.visualstudio.com/docs/python/debugging#_invoking-a-breakpoint-in-code

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


From robertvstepp at gmail.com  Sun Feb 24 00:00:04 2019
From: robertvstepp at gmail.com (boB Stepp)
Date: Sat, 23 Feb 2019 23:00:04 -0600
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
Message-ID: <CANDiX9LhFdOO8d0PaDMAXhjHen8WnAeAmEz9x9Fy1GNazMqQ7Q@mail.gmail.com>

I am trying to understand the functionality that the Python module,
curses, provides.  But I am stuck on how to use the command,
curses.resizeterm(nlines, ncols).  At
https://docs.python.org/3/library/curses.html#curses.resizeterm it says:

<quote>
curses.resizeterm(nlines, ncols)?

Resize the standard and current windows to the specified dimensions,
and adjusts other bookkeeping data used by the curses library that
record the window dimensions (in particular the SIGWINCH handler).
</quote>

After much experimentation -- to no good effect -- I have concluded
that "resizeterm" does *not* mean resize the terminal window that the
curses program is running within.  Can someone give me a working
example of how to use this command?

TIA!

-- 
boB

From cs at cskk.id.au  Sun Feb 24 02:32:27 2019
From: cs at cskk.id.au (Cameron Simpson)
Date: Sun, 24 Feb 2019 18:32:27 +1100
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <CANDiX9LhFdOO8d0PaDMAXhjHen8WnAeAmEz9x9Fy1GNazMqQ7Q@mail.gmail.com>
References: <CANDiX9LhFdOO8d0PaDMAXhjHen8WnAeAmEz9x9Fy1GNazMqQ7Q@mail.gmail.com>
Message-ID: <20190224073227.GA86372@cskk.homeip.net>

On 23Feb2019 23:00, boB Stepp <robertvstepp at gmail.com> wrote:
>I am trying to understand the functionality that the Python module,
>curses, provides.  But I am stuck on how to use the command,
>curses.resizeterm(nlines, ncols).  At
>https://docs.python.org/3/library/curses.html#curses.resizeterm it says:
>
><quote>
>curses.resizeterm(nlines, ncols)?
>
>Resize the standard and current windows to the specified dimensions,
>and adjusts other bookkeeping data used by the curses library that
>record the window dimensions (in particular the SIGWINCH handler).
></quote>
>
>After much experimentation -- to no good effect -- I have concluded
>that "resizeterm" does *not* mean resize the terminal window that the
>curses program is running within.  Can someone give me a working
>example of how to use this command?

I think you might misunderstand the purpose of the function; I have to 
say the doco doesn't help you much here.

It looks like the resizeterm() function updates the curses _internal_ 
records of what it believes the physcial terminal size to be.  When you 
physically resize a terminal the processes within it receive a SIGWINCH 
signal, and those which pay attention to that signal should then consult 
the terminal to find out its new size.

The curses library notices this signal, and calls resizeterm() to update 
its own internal idea of the terminal size so that it knows how to draw 
correctly on the screen. It does _not_ change the terminal; it changes 
curses' beliefs _about_ the terminal.

If you call resizeterm() yourself you will cause curses to act from then 
on as though the physcial terminal has the size you supplied. That may 
make for bad rendering if that size does not match reality (consider 
cursor motions "from the right edge" or "from the bottom edge" - their 
sizes are computed from where curses thinks those edges are).

Test the function curses.is_term_resized(nlines,ncols), whose doco says:

  Return True if resize_term() would modify the window structure, False 
  otherwise.

The is_term_resized() function looks up the current physical size and 
reports False if that matches curses current beliefs, and True if it 
does not match, meaning that the physical size has changed since curses 
last set up its beliefs (for example, in some environment where the 
resize _doesn't_ propagate a SIGWINCH to the process using curses, so it 
hasn't noticed).

Does this clarify things for you?

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

From alan.gauld at yahoo.co.uk  Sun Feb 24 03:49:52 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Sun, 24 Feb 2019 08:49:52 +0000
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <CANDiX9LhFdOO8d0PaDMAXhjHen8WnAeAmEz9x9Fy1GNazMqQ7Q@mail.gmail.com>
References: <CANDiX9LhFdOO8d0PaDMAXhjHen8WnAeAmEz9x9Fy1GNazMqQ7Q@mail.gmail.com>
Message-ID: <q4tlrh$7um4$1@blaine.gmane.org>

On 24/02/2019 05:00, boB Stepp wrote:

> curses.resizeterm(nlines, ncols)?
> 
> Resize the standard and current windows to the specified dimensions,
> and adjusts other bookkeeping data used by the curses library that
> record the window dimensions (in particular the SIGWINCH handler).
> </quote>
> 
> After much experimentation -- to no good effect -- I have concluded
> that "resizeterm" does *not* mean resize the terminal window that the
> curses program is running within.

Correct. curses knows nothing about the GUI window.
Curses is a windowing toolkit for use inside a
standard 24x80 text terminal. You can have multiple
small windows inside the screen and move/resize them.
Each one can have its own individual textual content.

It is how we built forms based applications before
GUIs were invented. Nowadays it's mostly used for screen
and cursor control within the single main window.
(A similar graphical text style framework on DOS
was TurboVision by Borland).

If you used curses to draw a border round your
window then call resizeterm you might see
something happening...

-- 
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 robertvstepp at gmail.com  Sun Feb 24 15:30:33 2019
From: robertvstepp at gmail.com (boB Stepp)
Date: Sun, 24 Feb 2019 14:30:33 -0600
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <20190224073227.GA86372@cskk.homeip.net>
References: <CANDiX9LhFdOO8d0PaDMAXhjHen8WnAeAmEz9x9Fy1GNazMqQ7Q@mail.gmail.com>
 <20190224073227.GA86372@cskk.homeip.net>
Message-ID: <CANDiX9KTZT1d-G+VyQsQ0NfLE2x_pp_8+o7P4z9_w0gNUBwN8A@mail.gmail.com>

On Sun, Feb 24, 2019 at 1:39 AM Cameron Simpson <cs at cskk.id.au> wrote:

> It looks like the resizeterm() function updates the curses _internal_
> records of what it believes the physcial terminal size to be.  When you
> physically resize a terminal the processes within it receive a SIGWINCH
> signal, and those which pay attention to that signal should then consult
> the terminal to find out its new size.
>
> The curses library notices this signal, and calls resizeterm() to update
> its own internal idea of the terminal size so that it knows how to draw
> correctly on the screen. It does _not_ change the terminal; it changes
> curses' beliefs _about_ the terminal.
>
> If you call resizeterm() yourself you will cause curses to act from then
> on as though the physcial terminal has the size you supplied. That may
> make for bad rendering if that size does not match reality (consider
> cursor motions "from the right edge" or "from the bottom edge" - their
> sizes are computed from where curses thinks those edges are).
>
> Test the function curses.is_term_resized(nlines,ncols), whose doco says:
>
>   Return True if resize_term() would modify the window structure, False
>   otherwise.
>
> The is_term_resized() function looks up the current physical size and
> reports False if that matches curses current beliefs, and True if it
> does not match, meaning that the physical size has changed since curses
> last set up its beliefs (for example, in some environment where the
> resize _doesn't_ propagate a SIGWINCH to the process using curses, so it
> hasn't noticed).
>
> Does this clarify things for you?

What you say makes sense and supports much of what I had concluded
from my coding experiments.  However, I still cannot get the function
call, curses.resizeterm(), to do anything meaningful, which suggests
that I still do not truly understand its usage.  I created the
following script to test things out:

#!/usr/bin/env python3

import curses

def start_cli(stdscr):
    max_y, max_x = stdscr.getmaxyx()
    stdscr.clear()
    stdscr.border()
    stdscr.addstr(2, 2, "This is the beginning!")
    stdscr.refresh()
    while True:
        char = chr(stdscr.getch())
        if char in 'Qq':
            return
        if curses.is_term_resized(max_y, max_x):
            max_y, max_x = stdscr.getmaxyx()
            stdscr.clear()
            stdscr.addstr(max_y//2, max_x//2, "You resized the terminal!")
            stdscr.addstr(max_y//2 + 1, max_x//2, "Resizing your
window -- NOW!")
            #curses.resizeterm(max_y, max_x)
            stdscr.border()
            stdscr.refresh()

if __name__ == '__main__':
    curses.wrapper(start_cli)

Notice that I have "curses.resizeterm( ..." commented out.  Whether I
comment it out or leave it in, the behavior I observe while manually
resizing my terminal window is the same.  The stdscr.border() still
tracks around the limits of the full terminal screen size.  I had also
tried not adding stdscr.border() in the if block, thinking that maybe
curses.resizeterm() would redraw the border once I refreshed the
screen, but that did not happen.

So what am I misunderstanding?  Can someone show me a code snippet
that I can run which will demonstrate the usefulness and usage of
curses.resizeterm()?

TIA!
-- 
boB

From mats at wichmann.us  Sun Feb 24 15:52:23 2019
From: mats at wichmann.us (Mats Wichmann)
Date: Sun, 24 Feb 2019 12:52:23 -0800
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <CANDiX9KTZT1d-G+VyQsQ0NfLE2x_pp_8+o7P4z9_w0gNUBwN8A@mail.gmail.com>
References: <CANDiX9LhFdOO8d0PaDMAXhjHen8WnAeAmEz9x9Fy1GNazMqQ7Q@mail.gmail.com>
 <20190224073227.GA86372@cskk.homeip.net>
 <CANDiX9KTZT1d-G+VyQsQ0NfLE2x_pp_8+o7P4z9_w0gNUBwN8A@mail.gmail.com>
Message-ID: <be78cf8f-7740-337a-3be8-3382734d0384@wichmann.us>

On 2/24/19 1:30 PM, boB Stepp wrote:

> So what am I misunderstanding?  Can someone show me a code snippet
> that I can run which will demonstrate the usefulness and usage of
> curses.resizeterm()?
> 
> TIA!
> 

If it's snippets you want, I always look at programcreek.  These are 
always part of something bigger so they may not fit your request to have 
them be something you can run.

https://www.programcreek.com/python/example/57429/curses.is_term_resized

(I didn't get any hits when I tried resizeterm directly, even though the 
calls are there...)

From cs at cskk.id.au  Sun Feb 24 17:39:30 2019
From: cs at cskk.id.au (Cameron Simpson)
Date: Mon, 25 Feb 2019 09:39:30 +1100
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <CANDiX9KTZT1d-G+VyQsQ0NfLE2x_pp_8+o7P4z9_w0gNUBwN8A@mail.gmail.com>
References: <CANDiX9KTZT1d-G+VyQsQ0NfLE2x_pp_8+o7P4z9_w0gNUBwN8A@mail.gmail.com>
Message-ID: <20190224223930.GA72556@cskk.homeip.net>

On 24Feb2019 14:30, boB Stepp <robertvstepp at gmail.com> wrote:
>On Sun, Feb 24, 2019 at 1:39 AM Cameron Simpson <cs at cskk.id.au> wrote:
>> It looks like the resizeterm() function updates the curses _internal_
>> records of what it believes the physcial terminal size to be.  When you
>> physically resize a terminal the processes within it receive a SIGWINCH
>> signal, and those which pay attention to that signal should then consult
>> the terminal to find out its new size.
>>
>> The curses library notices this signal, and calls resizeterm() to update
>> its own internal idea of the terminal size so that it knows how to draw
>> correctly on the screen. It does _not_ change the terminal; it changes
>> curses' beliefs _about_ the terminal.
[...]
>> The is_term_resized() function looks up the current physical size and
>> reports False if that matches curses current beliefs, and True if it
>> does not match, meaning that the physical size has changed since curses
>> last set up its beliefs [...]
>
>What you say makes sense and supports much of what I had concluded
>from my coding experiments.  However, I still cannot get the function
>call, curses.resizeterm(), to do anything meaningful, which suggests
>that I still do not truly understand its usage.

Likely so. The important thing you may be missing is that curses 
_itself_ calls resizeterm() automatically when it gets a SIGWINCH, so in 
normal situations you do not need to call this function.

Because of this, getmaxyx() is always correct for the size of the 
terminal.

Secondarily, resizeterm() does not make a change to the terminal itself.

Note that is_term_resized(y,x) is a _test_: it asks whether curses' idea 
of the screen size does not match (y,x). (y,x) is a pair of numbers that 
_you_, the programmer, is keeping track of.

If you set it once at the start of the programme:

    max_y, max_x = stdscr.getmaxyx()

and never update it then is_term_resized(max_y, max_x) will report True 
if the terminal has changed size. If you update the (max_y,max_x) values 
regularly from getmaxyx() then they will always match and 
is_term_resized will always report False.

>I created the
>following script to test things out:
[...]

I've modified your script. Please try the script appended below. The 
short answer is that resizeterm() is _not_ normally useful to you, the 
programmer; it will only be useful if curses does not get to notice 
terminal size changes - _then_ you could use it to provide that 
facility.

The script below is like yours: 'q' to quit, other keys to refresh and 
retest. Notice that the version below does not update (max_y,max_x) or 
call resizeterm(); initially you want to see what is_term_resized() 
does. It also shows you what got tested.

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

#!/usr/bin/env python3

import curses

def start_cli(stdscr):
    max_y, max_x = stdscr.getmaxyx()
    stdscr.clear()
    stdscr.border()
    stdscr.addstr(2, 2, "This is the beginning!")
    stdscr.refresh()
    while True:
        char = chr(stdscr.getch())
        if char in 'Qq':
            return
        tested = "is_term_resized(max_x=%d, max_y=%d)" % (max_x, max_y)
        internal = "getmaxyx() => y=%d, x=%d" % stdscr.getmaxyx()
        resized = curses.is_term_resized(max_y, max_x)
        result = "%s => %s" % (tested, resized)
        stdscr.clear()
        stdscr.addstr(max_y//2, max_x//2, result)
        stdscr.addstr(max_y//2 + 1, max_x//2, internal)
        if curses.is_term_resized(max_y, max_x):
            ##max_y, max_x = stdscr.getmaxyx()
            stdscr.addstr(max_y//2 + 2, max_x//2, "You resized the terminal!")
            ##stdscr.addstr(max_y//2 + 2, max_x//2, "Resizing your window -- NOW!")
            ##curses.resizeterm(max_y, max_x)
        else:
            stdscr.addstr(max_y//2 + 2, max_x//2, "Not resized.")
        stdscr.border()
        stdscr.refresh()

if __name__ == '__main__':
    curses.wrapper(start_cli)

From breamoreboy at gmail.com  Sun Feb 24 17:51:28 2019
From: breamoreboy at gmail.com (Mark Lawrence)
Date: Sun, 24 Feb 2019 22:51:28 +0000
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <20190224223930.GA72556@cskk.homeip.net>
References: <CANDiX9KTZT1d-G+VyQsQ0NfLE2x_pp_8+o7P4z9_w0gNUBwN8A@mail.gmail.com>
 <20190224223930.GA72556@cskk.homeip.net>
Message-ID: <q4v75h$6nag$1@blaine.gmane.org>

On 24/02/2019 22:39, Cameron Simpson wrote:
> On 24Feb2019 14:30, boB Stepp <robertvstepp at gmail.com> wrote:
>> On Sun, Feb 24, 2019 at 1:39 AM Cameron Simpson <cs at cskk.id.au> wrote:
>>> It looks like the resizeterm() function updates the curses _internal_
>>> records of what it believes the physcial terminal size to be.? When you
>>> physically resize a terminal the processes within it receive a SIGWINCH
>>> signal, and those which pay attention to that signal should then consult
>>> the terminal to find out its new size.
>>>
>>> The curses library notices this signal, and calls resizeterm() to update
>>> its own internal idea of the terminal size so that it knows how to draw
>>> correctly on the screen. It does _not_ change the terminal; it changes
>>> curses' beliefs _about_ the terminal.
> [...]
>>> The is_term_resized() function looks up the current physical size and
>>> reports False if that matches curses current beliefs, and True if it
>>> does not match, meaning that the physical size has changed since curses
>>> last set up its beliefs [...]
>>
>> What you say makes sense and supports much of what I had concluded
>> from my coding experiments.? However, I still cannot get the function
>> call, curses.resizeterm(), to do anything meaningful, which suggests
>> that I still do not truly understand its usage.
> 
> Likely so. The important thing you may be missing is that curses 
> _itself_ calls resizeterm() automatically when it gets a SIGWINCH, so in 
> normal situations you do not need to call this function.
> 
> Because of this, getmaxyx() is always correct for the size of the terminal.
> 
> Secondarily, resizeterm() does not make a change to the terminal itself.
> 
> Note that is_term_resized(y,x) is a _test_: it asks whether curses' idea 
> of the screen size does not match (y,x). (y,x) is a pair of numbers that 
> _you_, the programmer, is keeping track of.
> 
> If you set it once at the start of the programme:
> 
>  ?? max_y, max_x = stdscr.getmaxyx()
> 
> and never update it then is_term_resized(max_y, max_x) will report True 
> if the terminal has changed size. If you update the (max_y,max_x) values 
> regularly from getmaxyx() then they will always match and 
> is_term_resized will always report False.
> 
>> I created the
>> following script to test things out:
> [...]
> 
> I've modified your script. Please try the script appended below. The 
> short answer is that resizeterm() is _not_ normally useful to you, the 
> programmer; it will only be useful if curses does not get to notice 
> terminal size changes - _then_ you could use it to provide that facility.
> 
> The script below is like yours: 'q' to quit, other keys to refresh and 
> retest. Notice that the version below does not update (max_y,max_x) or 
> call resizeterm(); initially you want to see what is_term_resized() 
> does. It also shows you what got tested.
> 
> Cheers,
> Cameron Simpson <cs at cskk.id.au>
> 
> #!/usr/bin/env python3
> 
> import curses
> 
> def start_cli(stdscr):
>  ?? max_y, max_x = stdscr.getmaxyx()
>  ?? stdscr.clear()
>  ?? stdscr.border()
>  ?? stdscr.addstr(2, 2, "This is the beginning!")
>  ?? stdscr.refresh()
>  ?? while True:
>  ?????? char = chr(stdscr.getch())
>  ?????? if char in 'Qq':
>  ?????????? return
>  ?????? tested = "is_term_resized(max_x=%d, max_y=%d)" % (max_x, max_y)
>  ?????? internal = "getmaxyx() => y=%d, x=%d" % stdscr.getmaxyx()
>  ?????? resized = curses.is_term_resized(max_y, max_x)
>  ?????? result = "%s => %s" % (tested, resized)
>  ?????? stdscr.clear()
>  ?????? stdscr.addstr(max_y//2, max_x//2, result)
>  ?????? stdscr.addstr(max_y//2 + 1, max_x//2, internal)
>  ?????? if curses.is_term_resized(max_y, max_x):
>  ?????????? ##max_y, max_x = stdscr.getmaxyx()
>  ?????????? stdscr.addstr(max_y//2 + 2, max_x//2, "You resized the 
> terminal!")
>  ?????????? ##stdscr.addstr(max_y//2 + 2, max_x//2, "Resizing your 
> window -- NOW!")
>  ?????????? ##curses.resizeterm(max_y, max_x)
>  ?????? else:
>  ?????????? stdscr.addstr(max_y//2 + 2, max_x//2, "Not resized.")
>  ?????? stdscr.border()
>  ?????? stdscr.refresh()
> 
> if __name__ == '__main__':
>  ?? curses.wrapper(start_cli)

As I know squat about the curses module is this a time when a bug report 
could be put into the docs to clarify things, or do you have to know 
something about curses before you try using the Python wrapper?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence


From cs at cskk.id.au  Sun Feb 24 18:03:23 2019
From: cs at cskk.id.au (Cameron Simpson)
Date: Mon, 25 Feb 2019 10:03:23 +1100
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <q4v75h$6nag$1@blaine.gmane.org>
References: <q4v75h$6nag$1@blaine.gmane.org>
Message-ID: <20190224230323.GA85935@cskk.homeip.net>

On 24Feb2019 22:51, Mark Lawrence <breamoreboy at gmail.com> wrote:
>As I know squat about the curses module is this a time when a bug 
>report could be put into the docs to clarify things, or do you have to 
>know something about curses before you try using the Python wrapper?

Well, both.

The Python curses module is mostly a thin shim around the curses(3) C 
library. So the real semantics come from that; the Python module doco 
test closely resembles the text from the curses(3) manual entry (what 
you get from the "man 3 curses" command).

The curses(3) manual entry (well, ncurses on my Mac here) says:

  The ncurses library includes facilities for responding to window resizing
  events, e.g., when running in an xterm.  See the resizeterm(3X) and
  wresize(3X) manual pages for details.  In addition, the library may  be
  configured with a SIGWINCH handler.

and resizeterm(3) says in part:

  resizeterm
    The function resizeterm resizes the standard and current windows to
    the specified  dimensions,  and  adjusts other bookkeeping data used by
    the ncurses library that record the window dimensions such as the 
    LINES and COLS variables.

However, since people using the Python module might reasonably be 
expected to know less than those using the C library directly it would 
be useful to make it more clear that resizeterm() is essentailly "tell 
curses the terminal size" function, not a "make the terminal a specific 
size" function, and that because curses normally notices changes 
automatically then it is uncommon to need to call resizeterm().

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

From robertvstepp at gmail.com  Sun Feb 24 18:25:00 2019
From: robertvstepp at gmail.com (boB Stepp)
Date: Sun, 24 Feb 2019 17:25:00 -0600
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <20190224223930.GA72556@cskk.homeip.net>
References: <CANDiX9KTZT1d-G+VyQsQ0NfLE2x_pp_8+o7P4z9_w0gNUBwN8A@mail.gmail.com>
 <20190224223930.GA72556@cskk.homeip.net>
Message-ID: <CANDiX9JF2we-qc0=rFBUeRXoQVvhB8gLPS04CKp8uV-8MM8Bew@mail.gmail.com>

On Sun, Feb 24, 2019 at 4:40 PM Cameron Simpson <cs at cskk.id.au> wrote:
>
> On 24Feb2019 14:30, boB Stepp <robertvstepp at gmail.com> wrote:

> >What you say makes sense and supports much of what I had concluded
> >from my coding experiments.  However, I still cannot get the function
> >call, curses.resizeterm(), to do anything meaningful, which suggests
> >that I still do not truly understand its usage.
>
> Likely so. The important thing you may be missing is that curses
> _itself_ calls resizeterm() automatically when it gets a SIGWINCH, so in
> normal situations you do not need to call this function.

AHA!  It is exactly that.  How am I to know this from reading the
existing Python 3 docs???  I spent *much* time trying different coding
efforts to get resizeterm() to do something, ANYTHING, when all along
this was happening automatically behind the scenes.

> Because of this, getmaxyx() is always correct for the size of the
> terminal.
>
> Secondarily, resizeterm() does not make a change to the terminal itself.

I realized this before I sent my original post.  I really think the
name chosen, resizeterm, is a very misleading name!

> >I created the
> >following script to test things out:
> [...]
>
> I've modified your script. Please try the script appended below. The
> short answer is that resizeterm() is _not_ normally useful to you, the
> programmer; it will only be useful if curses does not get to notice
> terminal size changes - _then_ you could use it to provide that
> facility.

Thanks for the additional clarity provided with your modifications!

boB

From robertvstepp at gmail.com  Sun Feb 24 18:48:48 2019
From: robertvstepp at gmail.com (boB Stepp)
Date: Sun, 24 Feb 2019 17:48:48 -0600
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <be78cf8f-7740-337a-3be8-3382734d0384@wichmann.us>
References: <CANDiX9LhFdOO8d0PaDMAXhjHen8WnAeAmEz9x9Fy1GNazMqQ7Q@mail.gmail.com>
 <20190224073227.GA86372@cskk.homeip.net>
 <CANDiX9KTZT1d-G+VyQsQ0NfLE2x_pp_8+o7P4z9_w0gNUBwN8A@mail.gmail.com>
 <be78cf8f-7740-337a-3be8-3382734d0384@wichmann.us>
Message-ID: <CANDiX9J7O1Nqee-eKeKojKdPYd79h1PHs=dTxJbCAW2EzAFeYA@mail.gmail.com>

On Sun, Feb 24, 2019 at 2:52 PM Mats Wichmann <mats at wichmann.us> wrote:
>
> On 2/24/19 1:30 PM, boB Stepp wrote:
>
> > So what am I misunderstanding?  Can someone show me a code snippet
> > that I can run which will demonstrate the usefulness and usage of
> > curses.resizeterm()?
> >
> > TIA!
> >
>
> If it's snippets you want, I always look at programcreek.  These are
> always part of something bigger so they may not fit your request to have
> them be something you can run.
>
> https://www.programcreek.com/python/example/57429/curses.is_term_resized

Thanks for the link!  It looks useful for future research!  However,
in the context of the current discussion, especially after Cameron's
revelations, I cannot help but wonder if the writers of the three code
snippets did not truly understand resizeterm()?  Especially the first
example is very similar to my testing script.  But I did not go to the
full-fledge programs to see if there was something unusual going on,
so I may be overly harsh is my first impression.



-- 
boB

From cs at cskk.id.au  Sun Feb 24 19:05:21 2019
From: cs at cskk.id.au (Cameron Simpson)
Date: Mon, 25 Feb 2019 11:05:21 +1100
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <CANDiX9J7O1Nqee-eKeKojKdPYd79h1PHs=dTxJbCAW2EzAFeYA@mail.gmail.com>
References: <CANDiX9J7O1Nqee-eKeKojKdPYd79h1PHs=dTxJbCAW2EzAFeYA@mail.gmail.com>
Message-ID: <20190225000521.GA47293@cskk.homeip.net>

On 24Feb2019 17:48, boB Stepp <robertvstepp at gmail.com> wrote:
>On Sun, Feb 24, 2019 at 2:52 PM Mats Wichmann <mats at wichmann.us> wrote:
>> If it's snippets you want, I always look at programcreek.  These are
>> always part of something bigger so they may not fit your request to have
>> them be something you can run.
>>
>> https://www.programcreek.com/python/example/57429/curses.is_term_resized
>
>Thanks for the link!  It looks useful for future research!

Seconded. I did not know about this either!

>However,
>in the context of the current discussion, especially after Cameron's
>revelations, I cannot help but wonder if the writers of the three code
>snippets did not truly understand resizeterm()?  Especially the first
>example is very similar to my testing script.  But I did not go to the
>full-fledge programs to see if there was something unusual going on,
>so I may be overly harsh is my first impression.

I think the first two snippets definitely don't. The third I'm less sure 
about. resizeterm is easy to misunderstand.

Anyway, I should add a few remarks:

1: the use case for resizeterm() is for when curses has not noticed a 
resize. This can happen in remote terminal environments or where for 
some very weird reason the curses programme isn't in the terminal's 
control group. Most remote facilities (eg ssh and telnet) try to 
propagate terminal resize information, so remote curses stays informed.

2: much more useful is is_term_resized(). Many curses programmes need to 
know the termianl size (from getmaxyx()) in order to size their output 
(crop long lines, scale subwindows, what have you). So you might 
reasonably keep a copy of the result of getmaxyx() at the start of the 
programme:

  tty_y, tty_x = getmaxyx()

and then call:

  if is_term_resized(tty_y, tty_x):
    # update size
    tty_y, tty_x = getmaxyx()
    # recompute the sizes for various displayed things
    # redisplay everything...

at suitable times, because is_term_resized() is exactly for checking if 
the actual size (known by curses) matches some notional size (tty_y, 
tty_x, known by you, the programmer).

All is is_term_resized, resizeterm and the "internal" resize_term 
functions are recent additions :-) From "man 3 resizeterm":

  This extension of ncurses was introduced in mid-1995.  It  was  
  adopted in NetBSD curses (2001) and PDCurses (2003).

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

From mats at wichmann.us  Sun Feb 24 20:30:08 2019
From: mats at wichmann.us (Mats Wichmann)
Date: Sun, 24 Feb 2019 17:30:08 -0800
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <20190225000521.GA47293@cskk.homeip.net>
References: <CANDiX9J7O1Nqee-eKeKojKdPYd79h1PHs=dTxJbCAW2EzAFeYA@mail.gmail.com>
 <20190225000521.GA47293@cskk.homeip.net>
Message-ID: <bfec41b6-7555-86f5-cefa-89af5ec4050b@wichmann.us>


> All is is_term_resized, resizeterm and the "internal" resize_term 
> functions are recent additions :-) From "man 3 resizeterm":
> 
>  ?This extension of ncurses was introduced in mid-1995.? It? was 
>  ?adopted in NetBSD curses (2001) and PDCurses (2003).

For some definition of "recent" :)

I have an odd relationship with curses, I was at UC Berkeley when Ken 
Arnold adapted it from bits of Bill Joy's vi - "we" needed a 
terminal-independent way to address things when the ADM3A terminal and a 
bit later the HP 2621 turned up, making such programming possible (he 
needed it for rogue, as I reacall); the version of curses we all use now 
was shepharded by Pavel Curtis, a classmate of mine from Berkeley High 
School.  That said I don't know any magic stories...  a number of Python 
modules have made an easier to use interface to a popular library but 
curses seems to be pretty much a direct transliteration, warts and all.

From robertvstepp at gmail.com  Sun Feb 24 22:22:44 2019
From: robertvstepp at gmail.com (boB Stepp)
Date: Sun, 24 Feb 2019 21:22:44 -0600
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <20190224223930.GA72556@cskk.homeip.net>
References: <CANDiX9KTZT1d-G+VyQsQ0NfLE2x_pp_8+o7P4z9_w0gNUBwN8A@mail.gmail.com>
 <20190224223930.GA72556@cskk.homeip.net>
Message-ID: <CANDiX9JHNiCjmVDyiw-0KB0Oge0KSAepEFdOpJ9ufuk8_dh6pQ@mail.gmail.com>

On Sun, Feb 24, 2019 at 4:40 PM Cameron Simpson <cs at cskk.id.au> wrote:

> I've modified your script. Please try the script appended below. The
> short answer is that resizeterm() is _not_ normally useful to you, the
> programmer; it will only be useful if curses does not get to notice
> terminal size changes - _then_ you could use it to provide that
> facility.
>
> The script below is like yours: 'q' to quit, other keys to refresh and
> retest. Notice that the version below does not update (max_y,max_x) or
> call resizeterm(); initially you want to see what is_term_resized()
> does. It also shows you what got tested.

> #!/usr/bin/env python3
>
> import curses
>
> def start_cli(stdscr):
>     max_y, max_x = stdscr.getmaxyx()
>     stdscr.clear()
>     stdscr.border()
>     stdscr.addstr(2, 2, "This is the beginning!")
>     stdscr.refresh()
>     while True:
>         char = chr(stdscr.getch())
>         if char in 'Qq':
>             return
>         tested = "is_term_resized(max_x=%d, max_y=%d)" % (max_x, max_y)
>         internal = "getmaxyx() => y=%d, x=%d" % stdscr.getmaxyx()
>         resized = curses.is_term_resized(max_y, max_x)
>         result = "%s => %s" % (tested, resized)
>         stdscr.clear()
>         stdscr.addstr(max_y//2, max_x//2, result)
>         stdscr.addstr(max_y//2 + 1, max_x//2, internal)
>         if curses.is_term_resized(max_y, max_x):
>             ##max_y, max_x = stdscr.getmaxyx()
>             stdscr.addstr(max_y//2 + 2, max_x//2, "You resized the terminal!")
>             ##stdscr.addstr(max_y//2 + 2, max_x//2, "Resizing your window -- NOW!")
>             ##curses.resizeterm(max_y, max_x)
>         else:
>             stdscr.addstr(max_y//2 + 2, max_x//2, "Not resized.")
>         stdscr.border()
>         stdscr.refresh()
>
> if __name__ == '__main__':
>     curses.wrapper(start_cli)

While playing around with the above as I manually resized the terminal
window I noticed the program crashing with a curses.ERR exception if I
shrank the window so much that the program could not place the text at
the programmed coordinates.  This makes sense.  But, as usual, this
has gotten me to wonder that if I ever use curses to write a program
that others would be using if it is worthwhile to at least warn the
users against overly shrinking their terminal window or somehow trying
to handle the resulting exception?  Or does such a user "deserve" what
he/she gets?  ~(:>))

-- 
boB

From alan.gauld at yahoo.co.uk  Mon Feb 25 05:34:20 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Mon, 25 Feb 2019 10:34:20 +0000
Subject: [Tutor] How to use "curses.resizeterm(nlines, ncols)"
In-Reply-To: <CANDiX9JF2we-qc0=rFBUeRXoQVvhB8gLPS04CKp8uV-8MM8Bew@mail.gmail.com>
References: <CANDiX9KTZT1d-G+VyQsQ0NfLE2x_pp_8+o7P4z9_w0gNUBwN8A@mail.gmail.com>
 <20190224223930.GA72556@cskk.homeip.net>
 <CANDiX9JF2we-qc0=rFBUeRXoQVvhB8gLPS04CKp8uV-8MM8Bew@mail.gmail.com>
Message-ID: <q50gbc$49ep$1@blaine.gmane.org>

On 24/02/2019 23:25, boB Stepp wrote:

>> Secondarily, resizeterm() does not make a change to the terminal itself.
> 
> I realized this before I sent my original post.  I really think the
> name chosen, resizeterm, is a very misleading name!

Only in a world of GUIs.
Remember that curses is pre GUI. They did not think
of people changing the physical terminal size, that
was impossible. All you could do was reconfigure the
number of columns of text (usually from 40 to 80 to 132)
and sometimes the number of rows from 24 to 30.

That was what curses resizeterm had in mind when it
was written. The idea that some user could just grab
the corner of a GUI window and drag it out to any
size was a completely foreign concept.

Curses has been tweaked to play better with modern
GUIs but its roots, including the terminology used,
are from a day when physical terminals could not really
be resized, merely reconfigured(slightly).

-- 
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 kabads at gmail.com  Tue Feb 26 04:09:56 2019
From: kabads at gmail.com (AdamC)
Date: Tue, 26 Feb 2019 09:09:56 +0000
Subject: [Tutor] Only appending one object to list,
 when I am expecting more than 1
Message-ID: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>

I'm creating lots of objects from json in a file. Part of reading the json
back means that it iterates over the file and loads a json object and then
creates the object from the dictionary.

This is my  file:

{"name": "Dwarf Fortress", "platform": "steam", "dateAdded":
"2019:02:25:16:56:1551113768", "tpe": "2019:02:21:13:49:1550756942"}
{"name": "Jaws", "platform": "Netflix", "dateAdded":
"2019:02:25:16:56:1551113768", "tpe": "2019:02:21:13:49:1550756960"}
{"name": "Wargames", "platform": "CLI", "dateAdded":
"2019:02:25:16:59:1551113984", "tpe": "Game"}

and these are the functions that help load that file:

media = []

def loadFile():
    filename = input('Filename? ')
    f = open(filename, 'r')
    createObjects(f)

def createObjects(f):
    '''Takes a file object and iterates through entries, passing them to
create
    object, depending on what object it is.'''
    for line in f:
        count = count + 1
        data = json.loads(line)
        print(type(data['tpe']))
        name = data['name']
        platform = data['platform']
        dateAdded = data['dateAdded']
        tpe = data['tpe']
        if data['tpe'] == 'Game':
            a = createGame(name, platform, dateAdded,tpe)
            game = {a: tpe}
            media.append(game)
        if data['tpe'] == 'Film':
            a = createFilm(name, platform, dateAdded,tpe)
            film = {a: tpe}
            media.append(film)
    # For some reason I'm only getting one object at a time now when
appending to media
    print(len(media))

def createGame(name, platform, dateAdded, tpe):
    return Game(name, platform, dateAdded)

def createFilm(name, platform, dateAdded, tpe):
    return Film(name, platform, dateAdded)

(This isn't the order that the functions are held in the module).
Why would I only get one object in media, even though all three are created?

Adam

--
You back your data up on the same planet?
http://kabads.monkeez.org <https://kabads.monkeez.org>
PGP key: 0x7111B833

From steve at pearwood.info  Tue Feb 26 04:30:23 2019
From: steve at pearwood.info (Steven D'Aprano)
Date: Tue, 26 Feb 2019 20:30:23 +1100
Subject: [Tutor] Only appending one object to list,
 when I am expecting more than 1
In-Reply-To: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>
References: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>
Message-ID: <20190226093023.GX4465@ando.pearwood.info>

On Tue, Feb 26, 2019 at 09:09:56AM +0000, AdamC wrote:

> def createObjects(f):
>     '''Takes a file object and iterates through entries, passing them to
> create
>     object, depending on what object it is.'''
>     for line in f:
>         count = count + 1

This cannot be the code you are actually using, because that raises 
UnboundLocalError. count is never initialised, so that function you give 
cannot possibly run as shown.


py> def test():
...     count = count + 1
...
py> test()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in test
UnboundLocalError: local variable 'count' referenced before assignment


There's no point us trying to debug code you aren't actually running. 
Try again with the actual working code. It might help if you read this:

http://www.sscce.org/



-- 
Steven

From __peter__ at web.de  Tue Feb 26 04:39:02 2019
From: __peter__ at web.de (Peter Otten)
Date: Tue, 26 Feb 2019 10:39:02 +0100
Subject: [Tutor] Only appending one object to list,
 when I am expecting more than 1
References: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>
Message-ID: <q531fn$29j4$1@blaine.gmane.org>

AdamC wrote:

> I'm creating lots of objects from json in a file. Part of reading the json
> back means that it iterates over the file and loads a json object and then
> creates the object from the dictionary.
> 
> This is my  file:
> 
> {"name": "Dwarf Fortress", "platform": "steam", "dateAdded":
> "2019:02:25:16:56:1551113768", "tpe": "2019:02:21:13:49:1550756942"}
> {"name": "Jaws", "platform": "Netflix", "dateAdded":
> "2019:02:25:16:56:1551113768", "tpe": "2019:02:21:13:49:1550756960"}
> {"name": "Wargames", "platform": "CLI", "dateAdded":
> "2019:02:25:16:59:1551113984", "tpe": "Game"}
> 
> and these are the functions that help load that file:
> 
> media = []
> 
> def loadFile():
>     filename = input('Filename? ')
>     f = open(filename, 'r')
>     createObjects(f)
> 
> def createObjects(f):
>     '''Takes a file object and iterates through entries, passing them to
> create
>     object, depending on what object it is.'''
>     for line in f:
>         count = count + 1
>         data = json.loads(line)
>         print(type(data['tpe']))
>         name = data['name']
>         platform = data['platform']
>         dateAdded = data['dateAdded']
>         tpe = data['tpe']
>         if data['tpe'] == 'Game':
>             a = createGame(name, platform, dateAdded,tpe)
>             game = {a: tpe}
>             media.append(game)
>         if data['tpe'] == 'Film':
>             a = createFilm(name, platform, dateAdded,tpe)
>             film = {a: tpe}
>             media.append(film)
>     # For some reason I'm only getting one object at a time now when
> appending to media
>     print(len(media))
> 
> def createGame(name, platform, dateAdded, tpe):
>     return Game(name, platform, dateAdded)
> 
> def createFilm(name, platform, dateAdded, tpe):
>     return Film(name, platform, dateAdded)
> 
> (This isn't the order that the functions are held in the module).
> Why would I only get one object in media, even though all three are
> created?

Only one record in your jsonl sample has a 'tpe' handled by createObjects(). 
To make it easier to catch this problem (invalid or unsuspected data) I 
suggest that you rewrite the

>         if data['tpe'] == 'Game':
>             a = createGame(name, platform, dateAdded,tpe)
>             game = {a: tpe}
>             media.append(game)
>         if data['tpe'] == 'Film':
>             a = createFilm(name, platform, dateAdded,tpe)
>             film = {a: tpe}
>             media.append(film)

part of your code as

        if data['tpe'] == 'Game':
            a = createGame(name, platform, dateAdded,tpe)
            game = {a: tpe}
            media.append(game)
        elif data['tpe'] == 'Film':
            a = createFilm(name, platform, dateAdded,tpe)
            film = {a: tpe}
            media.append(film)
        else:
            # Instead of the error message you may also raise an exception.
            print(
                "Warning: unknown tpe={!r}".format(data["tpe"]),
                file=sys.stderr
            )

The unconditional else allows you to ensure that every line will be handled.


From cs at cskk.id.au  Tue Feb 26 04:59:35 2019
From: cs at cskk.id.au (Cameron Simpson)
Date: Tue, 26 Feb 2019 20:59:35 +1100
Subject: [Tutor] Only appending one object to list,
 when I am expecting more than 1
In-Reply-To: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>
References: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>
Message-ID: <20190226095935.GA66451@cskk.homeip.net>

Thank you for a well formed problem description.

However, as Steven has remarked the code you've included doesn't run.  
Can you follow up/reply with your actual working script, and also 
include some of the output you get.

That said, I've a few small remarks about the code you have posted:

On 26Feb2019 09:09, AdamC <kabads at gmail.com> wrote:
>I'm creating lots of objects from json in a file. Part of reading the json
>back means that it iterates over the file and loads a json object and then
>creates the object from the dictionary.
>
>This is my  file:
>
>{"name": "Dwarf Fortress", "platform": "steam", "dateAdded":
>"2019:02:25:16:56:1551113768", "tpe": "2019:02:21:13:49:1550756942"}
>{"name": "Jaws", "platform": "Netflix", "dateAdded":
>"2019:02:25:16:56:1551113768", "tpe": "2019:02:21:13:49:1550756960"}
>{"name": "Wargames", "platform": "CLI", "dateAdded":
>"2019:02:25:16:59:1551113984", "tpe": "Game"}

BTW, I notice that only one of these rows has the "tpe" field set to 
"Game" or "Film", specificly the last one. So based on your code below, 
only one of these rows gets appended to the media array. Remarks below 
on writing code which is less prone to hiding this kind of problem.

>and these are the functions that help load that file:
>
>media = []
>
>def loadFile():
>    filename = input('Filename? ')
>    f = open(filename, 'r')
>    createObjects(f)

This f=open code would normally be written like this:

    with open(filename, 'r') as f:
        createObjects(f)

That construction ensures that the file gets closed after running 
"createObjects()". As it is in your code the file is not explicitly 
closed; the CPython interpreter will, as it happens, close the file 
pretty promptly when "f" goes out of scope, but the language definition 
doesn't require such immediacy.

>def createObjects(f):
>    '''Takes a file object and iterates through entries, passing them to
>create
>    object, depending on what object it is.'''
>    for line in f:
>        count = count + 1
>        data = json.loads(line)
>        print(type(data['tpe']))
>        name = data['name']
>        platform = data['platform']
>        dateAdded = data['dateAdded']
>        tpe = data['tpe']
>        if data['tpe'] == 'Game':
>            a = createGame(name, platform, dateAdded,tpe)
>            game = {a: tpe}
>            media.append(game)
>        if data['tpe'] == 'Film':
>            a = createFilm(name, platform, dateAdded,tpe)
>            film = {a: tpe}
>            media.append(film)

These if statements don't cover the case when "tpe" isn't "Game" or 
"Film", and (in other circumstances) could conceivably add two objects.  
If you construct it like this instead:

        if data['tpe'] == 'Game':
            a = createGame(name, platform, dateAdded,tpe)
            game = {a: tpe}
            media.append(game)
        elif data['tpe'] == 'Film':
            a = createFilm(name, platform, dateAdded,tpe)
            film = {a: tpe}
            media.append(film)
        else:
            print("Unhandled tpe value:", repr(tpe))

then (a) only 1 branch can ever apply and (b) reports any unexpected 
values which would otherwise _silently_ get ignored. By always having a 
final "else" in an if/elif/..../else chain you can catch/observe these 
unhandled situations.

>def createGame(name, platform, dateAdded, tpe):
>    return Game(name, platform, dateAdded)
>
>def createFilm(name, platform, dateAdded, tpe):
>    return Film(name, platform, dateAdded)

Unless there's more stuff happening in these functions which you've 
stripped out for clarity you could just call the object constructors 
directly from the if statements:

    if data['tpe'] == 'Game':
        a = Game(name, platform, dateAdded)
        game = {a: tpe}
        media.append(game)

>Why would I only get one object in media, even though all three are 
>created?

As you may gather, all three input lines are processed, but only one 
gets turned into an object to add to media. Change the if/if into an 
if/elif/else and see if things become more obvious.

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

From kabads at gmail.com  Tue Feb 26 09:39:55 2019
From: kabads at gmail.com (AdamC)
Date: Tue, 26 Feb 2019 14:39:55 +0000
Subject: [Tutor] Only appending one object to list,
 when I am expecting more than 1
In-Reply-To: <20190226095935.GA66451@cskk.homeip.net>
References: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>
 <20190226095935.GA66451@cskk.homeip.net>
Message-ID: <CAHZHVNpGBryMW_d-2o4g5OwW8jR13dzQj+W3+EGEUdaXD-ofSA@mail.gmail.com>

Sorry folks - my code didn't work due to my debug var count to ensure that
I was looping properly.

It should be:
media = []

def loadFile():
    filename = input('Filename? ')
    f = open(filename, 'r')
    createObjects(f)

def createObjects(f):
    '''Takes a file object and iterates through entries, passing them to
create
    object, depending on what object it is.'''
    for line in f:
        data = json.loads(line)
        print(type(data['tpe']))
        name = data['name']
        platform = data['platform']
        dateAdded = data['dateAdded']
        tpe = data['tpe']
        if data['tpe'] == 'Game':
            a = createGame(name, platform, dateAdded,tpe)
            game = {a: tpe}
            media.append(game)
        if data['tpe'] == 'Film':
            a = createFilm(name, platform, dateAdded,tpe)
            film = {a: tpe}
            media.append(film)
    # For some reason I'm only getting one object at a time now when
appending to media
    print(len(media))

def createGame(name, platform, dateAdded, tpe):
    return Game(name, platform, dateAdded)

def createFilm(name, platform, dateAdded, tpe):
    return Film(name, platform, dateAdded)

Also, there is a bug that places an instance variable of dateAdded to tpe,
which is causing an error. This might be why I'm not getting more objects
than I expect.

My class is:

import datetime
class Media:
    def __init__(self, name, platform, tpe):
        self.name = name
        self.platform = platform
        date = datetime.datetime.now()
        datestring = date.strftime("%Y:%m:%d:%H:%M:%s")
        self.dateAdded = datestring
        self.tpe = tpe
        #self.dateAdded = datetime.datetime.now()

and

from . import media
#import media
class Game(media.Media):
    #tpe = 'game'
    # def __init__(self):
    #    self.type = 'game'

Thanks.
Adam


On Tue, 26 Feb 2019 at 10:02, Cameron Simpson <cs at cskk.id.au> wrote:

> Thank you for a well formed problem description.
>
> However, as Steven has remarked the code you've included doesn't run.
> Can you follow up/reply with your actual working script, and also
> include some of the output you get.
>
> That said, I've a few small remarks about the code you have posted:
>
> On 26Feb2019 09:09, AdamC <kabads at gmail.com> wrote:
> >I'm creating lots of objects from json in a file. Part of reading the json
> >back means that it iterates over the file and loads a json object and then
> >creates the object from the dictionary.
> >
> >This is my  file:
> >
> >{"name": "Dwarf Fortress", "platform": "steam", "dateAdded":
> >"2019:02:25:16:56:1551113768", "tpe": "2019:02:21:13:49:1550756942"}
> >{"name": "Jaws", "platform": "Netflix", "dateAdded":
> >"2019:02:25:16:56:1551113768", "tpe": "2019:02:21:13:49:1550756960"}
> >{"name": "Wargames", "platform": "CLI", "dateAdded":
> >"2019:02:25:16:59:1551113984", "tpe": "Game"}
>
> BTW, I notice that only one of these rows has the "tpe" field set to
> "Game" or "Film", specificly the last one. So based on your code below,
> only one of these rows gets appended to the media array. Remarks below
> on writing code which is less prone to hiding this kind of problem.
>
> >and these are the functions that help load that file:
> >
> >media = []
> >
> >def loadFile():
> >    filename = input('Filename? ')
> >    f = open(filename, 'r')
> >    createObjects(f)
>
> This f=open code would normally be written like this:
>
>     with open(filename, 'r') as f:
>         createObjects(f)
>
> That construction ensures that the file gets closed after running
> "createObjects()". As it is in your code the file is not explicitly
> closed; the CPython interpreter will, as it happens, close the file
> pretty promptly when "f" goes out of scope, but the language definition
> doesn't require such immediacy.
>
> >def createObjects(f):
> >    '''Takes a file object and iterates through entries, passing them to
> >create
> >    object, depending on what object it is.'''
> >    for line in f:
> >        count = count + 1
> >        data = json.loads(line)
> >        print(type(data['tpe']))
> >        name = data['name']
> >        platform = data['platform']
> >        dateAdded = data['dateAdded']
> >        tpe = data['tpe']
> >        if data['tpe'] == 'Game':
> >            a = createGame(name, platform, dateAdded,tpe)
> >            game = {a: tpe}
> >            media.append(game)
> >        if data['tpe'] == 'Film':
> >            a = createFilm(name, platform, dateAdded,tpe)
> >            film = {a: tpe}
> >            media.append(film)
>
> These if statements don't cover the case when "tpe" isn't "Game" or
> "Film", and (in other circumstances) could conceivably add two objects.
> If you construct it like this instead:
>
>         if data['tpe'] == 'Game':
>             a = createGame(name, platform, dateAdded,tpe)
>             game = {a: tpe}
>             media.append(game)
>         elif data['tpe'] == 'Film':
>             a = createFilm(name, platform, dateAdded,tpe)
>             film = {a: tpe}
>             media.append(film)
>         else:
>             print("Unhandled tpe value:", repr(tpe))
>
> then (a) only 1 branch can ever apply and (b) reports any unexpected
> values which would otherwise _silently_ get ignored. By always having a
> final "else" in an if/elif/..../else chain you can catch/observe these
> unhandled situations.
>
> >def createGame(name, platform, dateAdded, tpe):
> >    return Game(name, platform, dateAdded)
> >
> >def createFilm(name, platform, dateAdded, tpe):
> >    return Film(name, platform, dateAdded)
>
> Unless there's more stuff happening in these functions which you've
> stripped out for clarity you could just call the object constructors
> directly from the if statements:
>
>     if data['tpe'] == 'Game':
>         a = Game(name, platform, dateAdded)
>         game = {a: tpe}
>         media.append(game)
>
> >Why would I only get one object in media, even though all three are
> >created?
>
> As you may gather, all three input lines are processed, but only one
> gets turned into an object to add to media. Change the if/if into an
> if/elif/else and see if things become more obvious.
>
> 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
>


-- 
--
You back your data up on the same planet?
http://www.monkeez.org
PGP key: 0x7111B833

From toby at tobiah.org  Tue Feb 26 11:23:29 2019
From: toby at tobiah.org (Tobiah)
Date: Tue, 26 Feb 2019 08:23:29 -0800
Subject: [Tutor] Only appending one object to list,
 when I am expecting more than 1
In-Reply-To: <CAHZHVNpGBryMW_d-2o4g5OwW8jR13dzQj+W3+EGEUdaXD-ofSA@mail.gmail.com>
References: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>
 <20190226095935.GA66451@cskk.homeip.net>
 <CAHZHVNpGBryMW_d-2o4g5OwW8jR13dzQj+W3+EGEUdaXD-ofSA@mail.gmail.com>
Message-ID: <4253f100-75ba-d18a-55cc-1828fec2bf29@tobiah.org>



On 2/26/19 6:39 AM, AdamC wrote:
> Sorry folks - my code didn't work due to my debug var count to ensure that
> I was looping properly.
> 
> It should be:

As was pointed out, the problem is not in your code.  It's in your
data.  You only have one record with a proper 'tpe' value, so that's
all you get in your media list.


Toby

From maninathsahoo06 at gmail.com  Tue Feb 26 13:36:40 2019
From: maninathsahoo06 at gmail.com (Maninath sahoo)
Date: Wed, 27 Feb 2019 00:06:40 +0530
Subject: [Tutor] Doubt
Message-ID: <CAE+MRZujuhN0_MuWuS3p4xEJfcRwTRAjdeq9dqbQ8NS4QkT0gw@mail.gmail.com>

is it possible reverse inheritance?
mean child class to parent class

From shaeffer at q.com  Tue Feb 26 15:34:33 2019
From: shaeffer at q.com (shaeffer at q.com)
Date: Tue, 26 Feb 2019 13:34:33 -0700
Subject: [Tutor] I flip a coin 1 million times what is the consecutive times
 it will come up head and come up tails
Message-ID: <028401d4ce12$af290020$0d7b0060$@q.com>

I am learning python.  I wanted to test my ability by making a program to
keep track of the flip of a coin to find how many consecutive times it came
up heads and tails.

 

Just want some criticism on what I have done.

 

 

 

 

 

import random

Hn = {}

Tn = {}

for i in range (0,31):

    vars()["Hn"+str(i)] = 0

for i in range (0,31):

    vars()["Tn"+str(i)] = 0    

total_Heads = 0

total_tails= 0 

tails_number = 0

Heads_number = 0

tries = 0

while tries < 10000:

    tries += 1

    coin = random.randint(1, 2)   #  Flip coin

    

    if coin == 1:

        Heads_number += 1         #  Incroment Heads count

        total_Heads += 1

        if tails_number > 0 :

             

            vars()["Tn"+ str(tails_number)] += 1   #  Incroment tails
consecutive count

            tails_number = 0

             

    if coin == 2:

        tails_number += 1       #  Incroment Talies count

        total_tails += 1

        if Heads_number > 0:

            

            vars()["Hn"+ str(Heads_number)] += 1  #  Incroment Heads
consecutive count

            Heads_number = 0

            

print (tries)

print (total_tails, total_Heads)

for i in range (30):

    

    print ('%-15s %-15s' %(("Tn"+str(i)+"
"+str(eval("Tn"+str(i)))),("Hn"+str(i)+" "+str(eval("Hn"+str(i))))))

 

 

 

 

print out

 

100000000

50000259 49999741

Tn0 0           Hn0 0          

Tn1 12497339    Hn1 12500186   

Tn2 6257043     Hn2 6251565    

Tn3 3120686     Hn3 3127257    

Tn4 1563418     Hn4 1561175    

Tn5 781938      Hn5 779381     

Tn6 390943      Hn6 389768     

Tn7 195569      Hn7 196513     

Tn8 97091       Hn8 97858      

Tn9 48717       Hn9 48745      

Tn10 24493      Hn10 24429     

Tn11 11966      Hn11 12237     

Tn12 6070       Hn12 6062      

Tn13 3021       Hn13 3039      

Tn14 1540       Hn14 1556      

Tn15 679        Hn15 726       

Tn16 403        Hn16 389       

Tn17 179        Hn17 206       

Tn18 94         Hn18 105       

Tn19 49         Hn19 45        

Tn20 26         Hn20 24        

Tn21 16         Hn21 13        

Tn22 5          Hn22 2         

Tn23 1          Hn23 3         

Tn24 2          Hn24 3         

Tn25 1          Hn25 2         

Tn26 0          Hn26 0         

Tn27 0          Hn27 0         

Tn28 0          Hn28 0         

Tn29 0          Hn29 0         

 


From alan.gauld at yahoo.co.uk  Tue Feb 26 18:06:12 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Tue, 26 Feb 2019 23:06:12 +0000
Subject: [Tutor] Doubt
In-Reply-To: <CAE+MRZujuhN0_MuWuS3p4xEJfcRwTRAjdeq9dqbQ8NS4QkT0gw@mail.gmail.com>
References: <CAE+MRZujuhN0_MuWuS3p4xEJfcRwTRAjdeq9dqbQ8NS4QkT0gw@mail.gmail.com>
Message-ID: <q54gp4$1m25$1@blaine.gmane.org>

On 26/02/2019 18:36, Maninath sahoo wrote:
> is it possible reverse inheritance?
> mean child class to parent class

I have no idea what you mean by that. How would it work?
Can you give an example of the kind of thing you want to do?

For example Circles and Rectangles are kinds of Shape
so their classes inherit from class Shape. How would you reverse
the inheritance in that scenario? What would you do with 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 alan.gauld at yahoo.co.uk  Tue Feb 26 18:31:39 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Tue, 26 Feb 2019 23:31:39 +0000
Subject: [Tutor] I flip a coin 1 million times what is the consecutive
 times it will come up head and come up tails
In-Reply-To: <028401d4ce12$af290020$0d7b0060$@q.com>
References: <028401d4ce12$af290020$0d7b0060$@q.com>
Message-ID: <q54i8s$56ve$1@blaine.gmane.org>

On 26/02/2019 20:34, shaeffer at q.com wrote:
> I am learning python. 

I assume you are coming from some other language?
If not you have managed to come up with the most
convoluted and un-pythonic way imaginable to do
a fairly simple task!

>  I wanted to test my ability by making a program to
> keep track of the flip of a coin to find how many consecutive times it came
> up heads and tails.
> 
> import random
> 
> Hn = {}
> Tn = {}
> 
> for i in range (0,31):
>     vars()["Hn"+str(i)] = 0

This is insane!
Just use a list which is indexed by number.
No need for string conversions and no need for
the cumbersome access to vars

Hn = [0 for i in range(31)]

You can then access each cell using

Hn[num]

Instead of having to compute the name every time
and then access a dictionary.

> for i in range (0,31):
>     vars()["Tn"+str(i)] = 0    

Same here.

> total_Heads = 0
> total_tails= 0 
> tails_number = 0
> Heads_number = 0

> tries = 0
> while tries < 10000:
>     tries += 1
This is essentially a for loop:

for tries in range(10000):

>     coin = random.randint(1, 2)   #  Flip coin
>     if coin == 1:
>         Heads_number += 1         #  Incroment Heads count
>         total_Heads += 1
>         if tails_number > 0 :
>             vars()["Tn"+ str(tails_number)] += 1   #  Incroment tails
> consecutive count

This becomes

Tn[tails_number] += 1

But why are you incrementing the head counts above but the tails_number
value here? That doesn't make sense. I assume you are trying to
terminate the count of consecutive values?

>             tails_number = 0

>     if coin == 2:
>         tails_number += 1       #  Incroment Talies count
>         total_tails += 1
>         if Heads_number > 0:
>             vars()["Hn"+ str(Heads_number)] += 1  #  Incroment Heads
> consecutive count

Hn[heads_number] += 1

>             Heads_number = 0

> print (tries)
> print (total_tails, total_Heads)
> for i in range (30):
>     print ('%-15s %-15s' %(("Tn"+str(i)+"

      print('Tn[%d] %d   \tHn[%d] %d' % (i,Tn[i],i, Hn[i])

I think. Your code is so complex that I may have misread it.

> "+str(eval("Tn"+str(i)))),
> ("Hn"+str(i)+" "+str(eval("Hn"+str(i))))))

Using eval() should hardly ever (never?) be necessary
in normal coding and poses a significant security risk.
Any time you think you need to use it ask for help
because you are probably wrong and there will be a
better option.


> print out
> 100000000
> 
> 50000259 49999741
> 
> Tn0 0           Hn0 0          
> 
> Tn1 12497339    Hn1 12500186   
> 
> Tn2 6257043     Hn2 6251565    
> 
> Tn3 3120686     Hn3 3127257    

Given you only looped to 10,000 these results seem
rather suspect.

Even if your algorithm is correct, which I suspect
it may not be, the code is way too complex.

If all you want is the max count of consecutive head
and tails you only need to keep one counter for each
and update it each time a new max is reached. Keep
track of the last face. If the new toss is the same
increment the appropriate count. If its not then check
if the current count is greater than the previous max
for that face and if necessary update it. Then reset
the current count and face.

-- 
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 Feb 26 19:55:05 2019
From: mats at wichmann.us (Mats Wichmann)
Date: Tue, 26 Feb 2019 16:55:05 -0800
Subject: [Tutor] Doubt
In-Reply-To: <CAE+MRZujuhN0_MuWuS3p4xEJfcRwTRAjdeq9dqbQ8NS4QkT0gw@mail.gmail.com>
References: <CAE+MRZujuhN0_MuWuS3p4xEJfcRwTRAjdeq9dqbQ8NS4QkT0gw@mail.gmail.com>
Message-ID: <56b38276-65d2-da91-c743-bf6caa9a0d0a@wichmann.us>

On 2/26/19 11:36 AM, Maninath sahoo wrote:
> is it possible reverse inheritance?
> mean child class to parent class


Well, it's Python, so you can do all sorts of things, some of them good 
ideas, some bad...

Like Alan says, the question as asked doesn't really make a lot of sense 
to us, but the way classes (really, user-defined types) work does give 
you a lot of flexibility.  Some people feel like we should express it as 
code reuse at a sophisticated level: if you see a method in another 
class that you'd like to use for your own class, you can inherit that 
method by listing the class in your definition.  Or, if you don't want 
to do so, you write your own method.  So while I wouldn't call it 
reverse inheritance, you as author of your class have all the control of 
what you do and don't take from other classes, and maybe it's not 
entirely accurate to call them child and parent classes because of that?


From arj.python at gmail.com  Wed Feb 27 04:35:39 2019
From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer)
Date: Wed, 27 Feb 2019 13:35:39 +0400
Subject: [Tutor] I flip a coin 1 million times what is the consecutive
 times it will come up head and come up tails
In-Reply-To: <028401d4ce12$af290020$0d7b0060$@q.com>
References: <028401d4ce12$af290020$0d7b0060$@q.com>
Message-ID: <CADrxXXn3U8q=Eh4Pm10n_eeKEzCW3CPQuzD3iycQc3hHVvB2VQ@mail.gmail.com>

maybe try dpaste.de or something like that for code pasting ^^_

Abdur-Rahmaan Janhangeer
http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ
Mauritius

From alan.gauld at yahoo.co.uk  Wed Feb 27 05:02:21 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 27 Feb 2019 10:02:21 +0000
Subject: [Tutor] I flip a coin 1 million times what is the consecutive
 times it will come up head and come up tails
In-Reply-To: <CADrxXXn3U8q=Eh4Pm10n_eeKEzCW3CPQuzD3iycQc3hHVvB2VQ@mail.gmail.com>
References: <028401d4ce12$af290020$0d7b0060$@q.com>
 <CADrxXXn3U8q=Eh4Pm10n_eeKEzCW3CPQuzD3iycQc3hHVvB2VQ@mail.gmail.com>
Message-ID: <q55n7d$19s4$1@blaine.gmane.org>

On 27/02/2019 09:35, Abdur-Rahmaan Janhangeer wrote:
> maybe try dpaste.de or something like that for code pasting ^^_

That can be useful if it's very long code but this is
actually quite a short program and it's much easier to
reply to if the code is in the message so I think the
OP did the right thing in this case.

-- 
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 kabads at gmail.com  Wed Feb 27 08:25:02 2019
From: kabads at gmail.com (AdamC)
Date: Wed, 27 Feb 2019 13:25:02 +0000
Subject: [Tutor] Only appending one object to list,
 when I am expecting more than 1
In-Reply-To: <4253f100-75ba-d18a-55cc-1828fec2bf29@tobiah.org>
References: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>
 <20190226095935.GA66451@cskk.homeip.net>
 <CAHZHVNpGBryMW_d-2o4g5OwW8jR13dzQj+W3+EGEUdaXD-ofSA@mail.gmail.com>
 <4253f100-75ba-d18a-55cc-1828fec2bf29@tobiah.org>
Message-ID: <CAHZHVNq5vm_F5cqDxtAErt6=yCD1s+313M1cWoOHq0G4BWyXfg@mail.gmail.com>

That's great - bug found. Thanks. However the next question is, how do I
create an instance of a class with variable parameters (i.e. with dateAdded
already computed and stored, or with dateAdded created for the first time)?

I hope that makes sense.

Adam

On Tue, 26 Feb 2019 at 18:24, Tobiah <toby at tobiah.org> wrote:

>
>
> On 2/26/19 6:39 AM, AdamC wrote:
> > Sorry folks - my code didn't work due to my debug var count to ensure
> that
> > I was looping properly.
> >
> > It should be:
>
> As was pointed out, the problem is not in your code.  It's in your
> data.  You only have one record with a proper 'tpe' value, so that's
> all you get in your media list.
>
>
> Toby
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
--
You back your data up on the same planet?
http://www.monkeez.org
PGP key: 0x7111B833

From steve at pearwood.info  Wed Feb 27 09:21:54 2019
From: steve at pearwood.info (Steven D'Aprano)
Date: Thu, 28 Feb 2019 01:21:54 +1100
Subject: [Tutor] I flip a coin 1 million times what is the consecutive
 times it will come up head and come up tails
In-Reply-To: <028401d4ce12$af290020$0d7b0060$@q.com>
References: <028401d4ce12$af290020$0d7b0060$@q.com>
Message-ID: <20190227142153.GB4465@ando.pearwood.info>

On Tue, Feb 26, 2019 at 01:34:33PM -0700, shaeffer at q.com wrote:

> I am learning python.  I wanted to test my ability by making a program to
> keep track of the flip of a coin to find how many consecutive times it came
> up heads and tails.

Here's how to count the number of times it comes up heads (1) or tails 
(0):

from collections import Counter
from random import randint
c = Counter(randint(0, 1) for i in range(1000000))
print(c)

Obviously when you do it you will get different results, but here's 
mine:

Counter({1: 500481, 0: 499519})


If you want to count how many *consecutive* heads or tails happen, we 
can do this:

from itertools import groupby
it = groupby(randint(0, 1) for i in range(1000000))
c = Counter(len(tuple(x[1])) for x in it)
print(c)


When I run it, I get this:

Counter({1: 250180, 2: 124648, 3: 62760, 4: 31075, 5: 15707, 6: 7998, 7: 
3778, 8: 1966, 9: 989, 10: 501, 11: 219, 12: 136, 13: 49, 14: 22, 15: 
11, 16: 6, 18: 4, 17: 1})


which tells me that there are 250180 sequences of one head or one tail; 
124648 sequences of two heads or two tails; 62760 sequences of three 
heads or three tails, and so on to 4 sequences of 18 heads or tails.

If you want to see what is going on a bit better:

it = groupby(randint(0, 1) for i in range(20)) # a bit smaller...
for k, x in it:
    t = tuple(x)
    print("got", len(t), "consecutive", ("heads" if k==1 else "tails"), t)


which when I ran it gave me:

got 1 consecutive heads (1,)
got 1 consecutive tails (0,)
got 4 consecutive heads (1, 1, 1, 1)
got 3 consecutive tails (0, 0, 0)
got 1 consecutive heads (1,)
got 1 consecutive tails (0,)
got 7 consecutive heads (1, 1, 1, 1, 1, 1, 1)
got 1 consecutive tails (0,)
got 1 consecutive heads (1,)




-- 
Steven

From arj.python at gmail.com  Wed Feb 27 05:50:26 2019
From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer)
Date: Wed, 27 Feb 2019 14:50:26 +0400
Subject: [Tutor] I flip a coin 1 million times what is the consecutive
 times it will come up head and come up tails
In-Reply-To: <q55n7d$19s4$1@blaine.gmane.org>
References: <028401d4ce12$af290020$0d7b0060$@q.com>
 <CADrxXXn3U8q=Eh4Pm10n_eeKEzCW3CPQuzD3iycQc3hHVvB2VQ@mail.gmail.com>
 <q55n7d$19s4$1@blaine.gmane.org>
Message-ID: <CADrxXXkU3c=b3zw+uqEjK=x5D1j5JRXhO_m7H0U8y+MWtO7MfA@mail.gmail.com>

XD that will help in the future, yes it was not unreadable this one.

Abdur-Rahmaan Janhangeer
http://www.pythonmembers.club | https://github.com/Abdur-rahmaanJ
Mauritius

From toby at tobiah.org  Wed Feb 27 10:18:38 2019
From: toby at tobiah.org (Tobiah)
Date: Wed, 27 Feb 2019 07:18:38 -0800
Subject: [Tutor] Only appending one object to list,
 when I am expecting more than 1
In-Reply-To: <CAHZHVNq5vm_F5cqDxtAErt6=yCD1s+313M1cWoOHq0G4BWyXfg@mail.gmail.com>
References: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>
 <20190226095935.GA66451@cskk.homeip.net>
 <CAHZHVNpGBryMW_d-2o4g5OwW8jR13dzQj+W3+EGEUdaXD-ofSA@mail.gmail.com>
 <4253f100-75ba-d18a-55cc-1828fec2bf29@tobiah.org>
 <CAHZHVNq5vm_F5cqDxtAErt6=yCD1s+313M1cWoOHq0G4BWyXfg@mail.gmail.com>
Message-ID: <a911c2df-68ad-cf1f-b58f-e6a97779f437@tobiah.org>

Without fully understanding what you're getting at, I'll offer this:

	class Car(object):

	        def __init__(self, **kwargs):

	                self.features = {
	                        'make': 'Hyundai',
	                        'color': 'purple'
	                }

	                self.features.update(kwargs)


	c = Car(color='yellow', year=2017)


	print c.features

output:

	{'color': 'yellow', 'make': 'Hyundai', 'year': 2017}





On 2/27/19 5:25 AM, AdamC wrote:
> That's great - bug found. Thanks. However the next question is, how do I
> create an instance of a class with variable parameters (i.e. with dateAdded
> already computed and stored, or with dateAdded created for the first time)?
> 
> I hope that makes sense.
> 
> Adam
> 
> On Tue, 26 Feb 2019 at 18:24, Tobiah <toby at tobiah.org> wrote:
> 
>>
>>
>> On 2/26/19 6:39 AM, AdamC wrote:
>>> Sorry folks - my code didn't work due to my debug var count to ensure
>> that
>>> I was looping properly.
>>>
>>> It should be:
>>
>> As was pointed out, the problem is not in your code.  It's in your
>> data.  You only have one record with a proper 'tpe' value, so that's
>> all you get in your media list.
>>
>>
>> Toby
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
> 
> 

From mats at wichmann.us  Wed Feb 27 11:01:25 2019
From: mats at wichmann.us (Mats Wichmann)
Date: Wed, 27 Feb 2019 08:01:25 -0800
Subject: [Tutor] Only appending one object to list,
 when I am expecting more than 1
In-Reply-To: <CAHZHVNq5vm_F5cqDxtAErt6=yCD1s+313M1cWoOHq0G4BWyXfg@mail.gmail.com>
References: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>
 <20190226095935.GA66451@cskk.homeip.net>
 <CAHZHVNpGBryMW_d-2o4g5OwW8jR13dzQj+W3+EGEUdaXD-ofSA@mail.gmail.com>
 <4253f100-75ba-d18a-55cc-1828fec2bf29@tobiah.org>
 <CAHZHVNq5vm_F5cqDxtAErt6=yCD1s+313M1cWoOHq0G4BWyXfg@mail.gmail.com>
Message-ID: <C5834549-AB5D-4FA2-9613-B9FF859BAB80@wichmann.us>

Without spending a lot of time on an answer, you can use default arguments in the cases where only the number of arts differs in your instance creation. If there's larger differences, look into @classmethod.

On February 27, 2019 5:25:02 AM PST, AdamC <kabads at gmail.com> wrote:
>That's great - bug found. Thanks. However the next question is, how do
>I
>create an instance of a class with variable parameters (i.e. with
>dateAdded
>already computed and stored, or with dateAdded created for the first
>time)?
>
>I hope that makes sense.
>
>Adam
>
>On Tue, 26 Feb 2019 at 18:24, Tobiah <toby at tobiah.org> wrote:
>
>>
>>
>> On 2/26/19 6:39 AM, AdamC wrote:
>> > Sorry folks - my code didn't work due to my debug var count to
>ensure
>> that
>> > I was looping properly.
>> >
>> > It should be:
>>
>> As was pointed out, the problem is not in your code.  It's in your
>> data.  You only have one record with a proper 'tpe' value, so that's
>> all you get in your media list.
>>
>>
>> Toby
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>
>
>-- 
>--
>You back your data up on the same planet?
>http://www.monkeez.org
>PGP key: 0x7111B833
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

From alan.gauld at yahoo.co.uk  Wed Feb 27 12:11:03 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Wed, 27 Feb 2019 17:11:03 +0000
Subject: [Tutor] Only appending one object to list,
 when I am expecting more than 1
In-Reply-To: <CAHZHVNq5vm_F5cqDxtAErt6=yCD1s+313M1cWoOHq0G4BWyXfg@mail.gmail.com>
References: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>
 <20190226095935.GA66451@cskk.homeip.net>
 <CAHZHVNpGBryMW_d-2o4g5OwW8jR13dzQj+W3+EGEUdaXD-ofSA@mail.gmail.com>
 <4253f100-75ba-d18a-55cc-1828fec2bf29@tobiah.org>
 <CAHZHVNq5vm_F5cqDxtAErt6=yCD1s+313M1cWoOHq0G4BWyXfg@mail.gmail.com>
Message-ID: <q56gb8$60ie$1@blaine.gmane.org>

On 27/02/2019 13:25, AdamC wrote:
> That's great - bug found. Thanks. However the next question is, how do I
> create an instance of a class with variable parameters (i.e. with dateAdded
> already computed and stored, or with dateAdded created for the first time)?
> 
> I hope that makes sense.

Not really.
There are several possible interpretations of your question.

When asking concept things it often helps to include some
hypothetical examples of what you would like to happen.
For example in this case you might say you want:

c = myClass()  # default
c2 = myClass(anInt,aString)  # two args
c3 = myClass(aDate,aFloat)   # two different args
etc.

Or you maybe wanted something else? If so show
us how you think it would work and we can then
show you how to get something close.

-- 
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 Feb 27 13:28:02 2019
From: wachobc at gmail.com (Chip Wachob)
Date: Wed, 27 Feb 2019 13:28:02 -0500
Subject: [Tutor] ANSI / VT100 Escape Codes in Windows 7 Environment
Message-ID: <CADUn+-JygSDfvcWQWVjb--+vZxZ9WbYw+40KoWRjYZMPh2gk2g@mail.gmail.com>

Hello again,

As always, this list has been very helpful, and thank you.

So, I thought I was good to go until I attempted to run my code on a
Windows 7 vintage machine this morning.  The application is intended to be
run in the command window in Windows, from the terminal in Linux...

In the code I had included the ANSI escape characters so I could invert the
text and change the color.  Basically, I wanted to make the warning / error
messages stand out from the crowd.

Eg:
        # there's an error in the loop, report it
        # format reverse with yellow background
        print "\033[7m\033[33m"
        print " ERROR IN LOOP SIZE"
.
.
.
        # clear formatting
        print "\033[m"

As I have now learned, Windows 7 does not support this functionality.
Development had been done on a Windows 10 (and Ubuntu) machine where this
worked just fine.

I've been spending the morning looking at different solutions.  Many of
them seem to involve either including yet aother module, or, worse (IMHO) a
C library that will 'emulate' the ANSI escape sequences, API calls, etc.

Before I go tearing into my currently working code, I'm looking for
feedback from those much more experienced.

I need this code to run correctly on both Windows 7 and 10 (future Linux)
and I'm stuck with Python 2.7 due to other module limitations.

What do the experts out there suggest as the path of least pain and
suffering?

Again, thank you for your time and guidance.

From alan.gauld at yahoo.co.uk  Wed Feb 27 20:03:28 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 28 Feb 2019 01:03:28 +0000
Subject: [Tutor] ANSI / VT100 Escape Codes in Windows 7 Environment
In-Reply-To: <CADUn+-JygSDfvcWQWVjb--+vZxZ9WbYw+40KoWRjYZMPh2gk2g@mail.gmail.com>
References: <CADUn+-JygSDfvcWQWVjb--+vZxZ9WbYw+40KoWRjYZMPh2gk2g@mail.gmail.com>
Message-ID: <q57c10$2veu$1@blaine.gmane.org>

On 27/02/2019 18:28, Chip Wachob wrote:
> Windows 7 vintage machine this morning. 

Caveat: I have no direct experience on Windows 7 - I jumped
from XP to Windows 8... Also I haven't used ANSIO codes in
Windows since the heady days of Windows 98! But...

> run in the command window in Windows, from the terminal in Linux...

Be aware that ANSI codes in DOS don't correspond directly
with the VT100 control codes commonly used in Linux etc.
You might get some things that either don;t work or work
slightly differently.

> In the code I had included the ANSI escape characters so I could invert the
> text and change the color. 

Again remember that old ANSI terminals didn't have colors.
(They were either green on black, white on black, or if you
were really fancy, amber on black).

Color came later so some terminal emulators won't do anything
with those codes.

> As I have now learned, Windows 7 does not support this functionality.
> What do the experts out there suggest as the path of least pain and
> suffering?

No idea if this works on Windows 7 but what we used to have
to do was load the ANSI.SYS driver in the CONFIG.SYS file
located in the root directory of the boot drive.

A quick Google suggests that Windows supports config.nt
as a replacement for CONFIG.SYS.

Try creating such a file (or editing the existing one) with the line

DEVICE=ANSI.SYS

And see if that helps. (You might need a reboot or at
least a restart of the console)

Also it seems that the 32 bit version of ANSI.SYS does not support
cursor positioning. But if you only want bold/flashing/underlined
text in differing colors you should be OK...


-- 
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 eryksun at gmail.com  Wed Feb 27 20:10:36 2019
From: eryksun at gmail.com (eryk sun)
Date: Wed, 27 Feb 2019 19:10:36 -0600
Subject: [Tutor] ANSI / VT100 Escape Codes in Windows 7 Environment
In-Reply-To: <CADUn+-JygSDfvcWQWVjb--+vZxZ9WbYw+40KoWRjYZMPh2gk2g@mail.gmail.com>
References: <CADUn+-JygSDfvcWQWVjb--+vZxZ9WbYw+40KoWRjYZMPh2gk2g@mail.gmail.com>
Message-ID: <CACL+1asCBDk_ua-FRxH3pH_Xb9oiMov03U5eDD+9hKru=5h=_w@mail.gmail.com>

On 2/27/19, Chip Wachob <wachobc at gmail.com> wrote:
>
> I've been spending the morning looking at different solutions.  Many of
> them seem to involve either including yet aother module, or, worse (IMHO) a
> C library that will 'emulate' the ANSI escape sequences, API calls, etc.

To support virtual-terminal sequences prior to Windows 10, you'll need
a package such as colorama [1] that implements VT sequences in terms
of the Windows console API -- unless you're willing to require an
alternate console such as ConEmu or an API hack such as ANSICON.

[1]: https://pypi.org/project/colorama

From robertvstepp at gmail.com  Wed Feb 27 20:48:57 2019
From: robertvstepp at gmail.com (boB Stepp)
Date: Wed, 27 Feb 2019 19:48:57 -0600
Subject: [Tutor] Why does using "window.addchr()" to place a character at
 the lower right corner raise an exception?
Message-ID: <CANDiX9+N6zHZ0EET6TSPyLx3Z5W5xma+5A9sj3motuWWpDW4KQ@mail.gmail.com>

Under https://docs.python.org/3/library/curses.html#window-objects in
the curses docs, it states:

<quote>
window.addch(ch[, attr])
window.addch(y, x, ch[, attr])
[...]

Note

Writing outside the window, subwindow, or pad raises a curses.error.
Attempting to write to the lower right corner of a window, subwindow,
or pad will cause an exception to be raised after the character is
printed.
</quote>

Why is this?  What is special about the lower right corner of a
terminal window?  I am guessing this is some relic of the original
terminal era.

TIA!

-- 
boB

From eryksun at gmail.com  Wed Feb 27 21:05:11 2019
From: eryksun at gmail.com (eryk sun)
Date: Wed, 27 Feb 2019 20:05:11 -0600
Subject: [Tutor] ANSI / VT100 Escape Codes in Windows 7 Environment
In-Reply-To: <q57c10$2veu$1@blaine.gmane.org>
References: <CADUn+-JygSDfvcWQWVjb--+vZxZ9WbYw+40KoWRjYZMPh2gk2g@mail.gmail.com>
 <q57c10$2veu$1@blaine.gmane.org>
Message-ID: <CACL+1atVARgdrVXXsmp9kg3OJD35g21Xe07=pOeZ5Vgpp3YoMw@mail.gmail.com>

On 2/27/19, Alan Gauld via Tutor <tutor at python.org> wrote:
> On 27/02/2019 18:28, Chip Wachob wrote:
>> Windows 7 vintage machine this morning.
>
> Caveat: I have no direct experience on Windows 7 - I jumped
> from XP to Windows 8... Also I haven't used ANSIO codes in
> Windows since the heady days of Windows 98! But...
>
>> run in the command window in Windows, from the terminal in Linux...
>
> Be aware that ANSI codes in DOS don't correspond directly
> with the VT100 control codes commonly used in Linux etc.
> You might get some things that either don;t work or work
> slightly differently.
>
>> In the code I had included the ANSI escape characters so I could invert
>> the
>> text and change the color.
>
> Again remember that old ANSI terminals didn't have colors.
> (They were either green on black, white on black, or if you
> were really fancy, amber on black).
>
> Color came later so some terminal emulators won't do anything
> with those codes.
>
>> As I have now learned, Windows 7 does not support this functionality.
>> What do the experts out there suggest as the path of least pain and
>> suffering?
>
> No idea if this works on Windows 7 but what we used to have
> to do was load the ANSI.SYS driver in the CONFIG.SYS file
> located in the root directory of the boot drive.

Windows NT systems use the Windows console API, which talks to a
console that's hosted in a system process. In Windows 7+, each console
is hosted in an instance of conhost.exe. In older versions of NT,
consoles are hosted by threads in the session server process,
csrss.exe.

In 32-bit builds of NT, there's integration between the console and
the virtual DOS machine (ntvdm.exe). This allows running old 16-bit
DOS programs/drivers such as COMMAND.COM and ANSI.SYS in an emulated
DOS environment. 64-bit builds no longer support NTVDM. Anyway, it
wouldn't apply to Windows console applications such as python.exe,
which have nothing to do with DOS.

The only practical option is to implement VT sequences using the
console API, such as is done by the colorama package. Other options
require installing an alternate console (e.g. ConEmu) or a program
that hacks the console API in each process via DLL injection (e.g.
ANSICON).

From akleider at sonic.net  Wed Feb 27 21:09:47 2019
From: akleider at sonic.net (Alex Kleider)
Date: Wed, 27 Feb 2019 18:09:47 -0800
Subject: [Tutor] Why does using "window.addchr()" to place a character
 at the lower right corner raise an exception?
In-Reply-To: <CANDiX9+N6zHZ0EET6TSPyLx3Z5W5xma+5A9sj3motuWWpDW4KQ@mail.gmail.com>
References: <CANDiX9+N6zHZ0EET6TSPyLx3Z5W5xma+5A9sj3motuWWpDW4KQ@mail.gmail.com>
Message-ID: <149acd519150187160e8d6097eb93d11@sonic.net>

On 2019-02-27 17:48, boB Stepp wrote:
> Under https://docs.python.org/3/library/curses.html#window-objects in
> the curses docs, it states:
> 
> <quote>
> window.addch(ch[, attr])
> window.addch(y, x, ch[, attr])
> [...]
> 
> Note
> 
> Writing outside the window, subwindow, or pad raises a curses.error.
> Attempting to write to the lower right corner of a window, subwindow,
> or pad will cause an exception to be raised after the character is
> printed.

Could it be that as soon as the character is printed the cursor moves to 
the 'next location' which is outside of the 'window, subwindow, or pad' 
and it is this which causes the error to be raised?

From robertvstepp at gmail.com  Wed Feb 27 21:15:44 2019
From: robertvstepp at gmail.com (boB Stepp)
Date: Wed, 27 Feb 2019 20:15:44 -0600
Subject: [Tutor] Why does using "window.addchr()" to place a character
 at the lower right corner raise an exception?
In-Reply-To: <149acd519150187160e8d6097eb93d11@sonic.net>
References: <CANDiX9+N6zHZ0EET6TSPyLx3Z5W5xma+5A9sj3motuWWpDW4KQ@mail.gmail.com>
 <149acd519150187160e8d6097eb93d11@sonic.net>
Message-ID: <CANDiX9+VvSOVo43fY7L7JqHHL40SWAmhbuwfuSMdYphp35MGnw@mail.gmail.com>

On Wed, Feb 27, 2019 at 8:09 PM Alex Kleider <akleider at sonic.net> wrote:
>
> On 2019-02-27 17:48, boB Stepp wrote:
> > Under https://docs.python.org/3/library/curses.html#window-objects in
> > the curses docs, it states:
> >
> > <quote>
> > window.addch(ch[, attr])
> > window.addch(y, x, ch[, attr])
> > [...]
> >
> > Note
> >
> > Writing outside the window, subwindow, or pad raises a curses.error.
> > Attempting to write to the lower right corner of a window, subwindow,
> > or pad will cause an exception to be raised after the character is
> > printed.
>
> Could it be that as soon as the character is printed the cursor moves to
> the 'next location' which is outside of the 'window, subwindow, or pad'
> and it is this which causes the error to be raised?

Alex, I think you have nailed it!  Everything I have read so far
indicates that an exception will be thrown whenever attempting to
write outside of a window, subwindow or pad.  So it would appear to
follow that if for some reason I need to write something to that very
last cell I will have to handle the exception generated.

Thanks!


-- 
boB

From robertvstepp at gmail.com  Wed Feb 27 21:40:13 2019
From: robertvstepp at gmail.com (boB Stepp)
Date: Wed, 27 Feb 2019 20:40:13 -0600
Subject: [Tutor] ANSI / VT100 Escape Codes in Windows 7 Environment
In-Reply-To: <CADUn+-JygSDfvcWQWVjb--+vZxZ9WbYw+40KoWRjYZMPh2gk2g@mail.gmail.com>
References: <CADUn+-JygSDfvcWQWVjb--+vZxZ9WbYw+40KoWRjYZMPh2gk2g@mail.gmail.com>
Message-ID: <CANDiX9K_-1RmJ25+RV2LyMMOs3sbCLBaKQR=bBLCGu2UouLYxQ@mail.gmail.com>

On Wed, Feb 27, 2019 at 6:50 PM Chip Wachob <wachobc at gmail.com> wrote:
>
> Hello again,
>
> As always, this list has been very helpful, and thank you.
>
> So, I thought I was good to go until I attempted to run my code on a
> Windows 7 vintage machine this morning.  The application is intended to be
> run in the command window in Windows, from the terminal in Linux...
>
> In the code I had included the ANSI escape characters so I could invert the
> text and change the color.  Basically, I wanted to make the warning / error
> messages stand out from the crowd.

As I have been on a "curses" kick lately, I wonder if it would work
for you?  Of course this means another module, but it is in the
standard lib on all non-Windows Python versions.  For Windows I found
this thread on stackoverflow:

https://stackoverflow.com/questions/32417379/what-is-needed-for-curses-in-python-3-4-on-windows7

The checked answer gives a link to binaries for Windows, which seems
to support all Python versions through 3.7, including 2.7.

Just a thought...

-- 
boB

From akleider at sonic.net  Wed Feb 27 22:03:26 2019
From: akleider at sonic.net (Alex Kleider)
Date: Wed, 27 Feb 2019 19:03:26 -0800
Subject: [Tutor] Only appending one object to list,
 when I am expecting more than 1
In-Reply-To: <CAHZHVNq5vm_F5cqDxtAErt6=yCD1s+313M1cWoOHq0G4BWyXfg@mail.gmail.com>
References: <CAHZHVNoSL1oS8i4i5uCEXyP35d+JLFrAMAy97y9-5qLPLYKHdw@mail.gmail.com>
 <20190226095935.GA66451@cskk.homeip.net>
 <CAHZHVNpGBryMW_d-2o4g5OwW8jR13dzQj+W3+EGEUdaXD-ofSA@mail.gmail.com>
 <4253f100-75ba-d18a-55cc-1828fec2bf29@tobiah.org>
 <CAHZHVNq5vm_F5cqDxtAErt6=yCD1s+313M1cWoOHq0G4BWyXfg@mail.gmail.com>
Message-ID: <5b79c1616c6819de2279907ac109514d@sonic.net>

On 2019-02-27 05:25, AdamC wrote:
> That's great - bug found. Thanks. However the next question is, how do 
> I
> create an instance of a class with variable parameters (i.e. with 
> dateAdded
> already computed and stored, or with dateAdded created for the first 
> time)?

Might this work?

class myClass(object):
   __init__(self, added_date=None):
         if added_date:
             self.date_attribute = added_date
         else:
             self.date_attribute = my_way_of_calculating_added_date()

You can then instantiate in either of these ways:

my_instance = myClass()

or

my_instance = myClass(my_way_of_calculating_added_date())

From mjch at mjch.net  Wed Feb 27 20:56:59 2019
From: mjch at mjch.net (Malcolm Herbert)
Date: Wed, 27 Feb 2019 20:56:59 -0500
Subject: [Tutor] 
 =?utf-8?q?Why_does_using_=22window=2Eaddchr=28=29=22_to_?=
 =?utf-8?q?place_a_character_at_the_lower_right_corner_raise_an_exception?=
 =?utf-8?q?=3F?=
In-Reply-To: <CANDiX9+N6zHZ0EET6TSPyLx3Z5W5xma+5A9sj3motuWWpDW4KQ@mail.gmail.com>
References: <CANDiX9+N6zHZ0EET6TSPyLx3Z5W5xma+5A9sj3motuWWpDW4KQ@mail.gmail.com>
Message-ID: <eed896ad-dae8-4310-adda-28220049706f@www.fastmail.com>

yes - usually that was the prompt for the terminal to insert a new line ... on some terminals this is a behaviour you can't control as it's implemented in hardware, so curses fakes things by moving the cursor back to where it "should" be afterward.

If you try and to something when the cursor is at the extreme bottom right of the window/region and the terminal is hard-coded to do $magic immediately after, then your screen will be all messed up.

-- 
Malcolm Herbert
mjch at mjch.net

From wachobc at gmail.com  Thu Feb 28 08:38:25 2019
From: wachobc at gmail.com (Chip Wachob)
Date: Thu, 28 Feb 2019 08:38:25 -0500
Subject: [Tutor] ANSI / VT100 Escape Codes in Windows 7 Environment
In-Reply-To: <CANDiX9K_-1RmJ25+RV2LyMMOs3sbCLBaKQR=bBLCGu2UouLYxQ@mail.gmail.com>
References: <CADUn+-JygSDfvcWQWVjb--+vZxZ9WbYw+40KoWRjYZMPh2gk2g@mail.gmail.com>
 <CANDiX9K_-1RmJ25+RV2LyMMOs3sbCLBaKQR=bBLCGu2UouLYxQ@mail.gmail.com>
Message-ID: <CADUn+-KR5tKcyZX9AB0b7KzG6X8HaBFjNxTYO+oEQVHiSxRtrg@mail.gmail.com>

Wow!  What a treasure of information.

>From the looks of it, I'm going to give colorama a try.  It seems like it
will do what I want to do, and, if I'm reading the documentation correctly,
it will work cross platform.  Ie: if I am in Linux, it will simply be
ignored.  And, it appears to interpret the ANSI codes (\033[xxxm) when it
comes to Windows...

As an aside, I enjoyed the trip down memory lane.  I still have my Hercules
graphics card and my AMBER monitor for my 286 machine.  You know, the
machine that has two full-height HDD with an MFM interface and provides a
combined 20Mbyte of storage space! And of course a math co-processor...  I
no longer recall how many Kbytes of onboard memory I had, maybe 1024...   :)

Thank you so much for sharing your insights.

Best,


On Wed, Feb 27, 2019 at 9:40 PM boB Stepp <robertvstepp at gmail.com> wrote:

> On Wed, Feb 27, 2019 at 6:50 PM Chip Wachob <wachobc at gmail.com> wrote:
> >
> > Hello again,
> >
> > As always, this list has been very helpful, and thank you.
> >
> > So, I thought I was good to go until I attempted to run my code on a
> > Windows 7 vintage machine this morning.  The application is intended to
> be
> > run in the command window in Windows, from the terminal in Linux...
> >
> > In the code I had included the ANSI escape characters so I could invert
> the
> > text and change the color.  Basically, I wanted to make the warning /
> error
> > messages stand out from the crowd.
>
> As I have been on a "curses" kick lately, I wonder if it would work
> for you?  Of course this means another module, but it is in the
> standard lib on all non-Windows Python versions.  For Windows I found
> this thread on stackoverflow:
>
>
> https://stackoverflow.com/questions/32417379/what-is-needed-for-curses-in-python-3-4-on-windows7
>
> The checked answer gives a link to binaries for Windows, which seems
> to support all Python versions through 3.7, including 2.7.
>
> Just a thought...
>
> --
> boB
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

From valerio at pbds.eu  Thu Feb 28 07:05:27 2019
From: valerio at pbds.eu (Valerio Pachera)
Date: Thu, 28 Feb 2019 13:05:27 +0100 (CET)
Subject: [Tutor] Remove soft line break
In-Reply-To: <q3a3gg$4f6g$1@blaine.gmane.org>
References: <431086936.29.1549300383777.JavaMail.zimbra@pbds.eu>
 <q3a3gg$4f6g$1@blaine.gmane.org>
Message-ID: <800104116.88.1551355527069.JavaMail.zimbra@pbds.eu>


I think it could be solved in a much easier way.

  s.replace('\n ', '')

In other words removing a new line followed by a space.
In such case, the approach is not by line.

f = open('file.ics')
content=f.read().replace('\n ', '')
f.close()

The real use case is an .ics file.
It works as expected but there's a thing I've to understand about the end of line in general.

The original file line break is CR CF

cat --show-all file.ics
METHOD:PUBLISH^M$
BEGIN:VTIMEZONE^M$

I noticed that the end of file doesn't get preserve if I create a copy of the file by simply

f = open('file.ics')
content=f.read()
f.close()

f = open('file_copy.ics', 'w')
write('content')
f.close()

cat --show-all file_copy.ics
METHOD:PUBLISH$
BEGIN:VTIMEZONE$

What am I missing?


----- Messaggio originale -----
Da: "Peter Otten" <__peter__ at web.de>
A: "Tutor Python" <tutor at python.org>
Inviato: Luned?, 4 febbraio 2019 20:23:59
Oggetto: Re: [Tutor] Remove soft line break

Valerio Pachera wrote:

> 
> I have a file with row that split at the 80th character.
> The next row start with a blank space, meaning that i part of the previous
> row.
> 
> Example:
> 
> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam non justo
> enim. Viv
>  amus dapibus quis neque vitae ornare. Pellentesque at pharetra sapien, id
>  eleif end lacus. Nullam ut semper enim, vulputate venenatis justo.
>  Vestibulum vehicul a dolor sit amet ultricies vulputate. Aenean lobortis,
>  nulla eu scelerisque hen
> 
> What do you suggest to get the text on a single line?

Neglecting the corner cases:

$ cat mergelines.py 
def merge_lines(lines):
    lines = (line.rstrip("\n") for line in lines)
    accu = [next(lines)]
    for line in lines:
        if line.startswith(" "):
            accu.append(line[1:])
        else:
            yield "".join(accu) + "\n"
            accu = [line]
    yield "".join(accu) + "\n"

From valerio at pbds.eu  Thu Feb 28 09:33:45 2019
From: valerio at pbds.eu (Valerio Pachera)
Date: Thu, 28 Feb 2019 15:33:45 +0100 (CET)
Subject: [Tutor] Remove soft line break
In-Reply-To: <800104116.88.1551355527069.JavaMail.zimbra@pbds.eu>
References: <431086936.29.1549300383777.JavaMail.zimbra@pbds.eu>
 <q3a3gg$4f6g$1@blaine.gmane.org>
 <800104116.88.1551355527069.JavaMail.zimbra@pbds.eu>
Message-ID: <1895021755.99.1551364425429.JavaMail.zimbra@pbds.eu>



----- Messaggio originale -----
> Da: "Valerio Pachera" <valerio at pbds.eu>
> A: "Tutor Python" <tutor at python.org>
> Inviato: Gioved?, 28 febbraio 2019 13:05:27
> Oggetto: Re: [Tutor] Remove soft line break
>...
> It works as expected but there's a thing I've to understand about the end of
> line in general.
> ...
> I noticed that the end of file doesn't get preserve if I create a copy of the
> file by simply
> 
> f = open('file.ics')
> content=f.read()
> f.close()
> 
> f = open('file_copy.ics', 'w')
> write('content')
> f.close()

Got it!
Python automatically convert new line to \n when it opens the file

open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)

This is my final script that overrides the original file.

---
import sys

f = open(sys.argv[1], newline='\r\n')
content = f.read().replace('\r\n ', '')
f.close()

f = open(sys.argv[1], 'w')
f.write(content)
f.close()
---

Valerio P.

From nathan-tech at hotmail.com  Thu Feb 28 09:45:59 2019
From: nathan-tech at hotmail.com (nathan tech)
Date: Thu, 28 Feb 2019 14:45:59 +0000
Subject: [Tutor] schedulers
Message-ID: <DB7PR05MB5769A8A9FFC00EE645183BA0E4750@DB7PR05MB5769.eurprd05.prod.outlook.com>

Hi there,

I recently started working on a backup program, and the one big feature 
everyone wants in backup programs is the ability to schedule backups, right?

but I'm thinking, should I do this?

def do_backup

 ?# backup code here, without prints to screen or anything so it just 
does it in the background...


def scheduler():

 ?global tus # tus=time until schedule

 ?while(time.time()>tus):

 ? time.sleep(5)

 ?scheduler()


Is that wise? Is that how it should be done?

This is a program for windows.

Thanks!

Nathan


From wachobc at gmail.com  Thu Feb 28 16:03:08 2019
From: wachobc at gmail.com (Chip Wachob)
Date: Thu, 28 Feb 2019 16:03:08 -0500
Subject: [Tutor] Exception not working as expected?
Message-ID: <CADUn+-J6Cs8nqBTR4crcaJKM1ygK-RhwCoZ4wp=aqXoXdhgPpQ@mail.gmail.com>

Hello,

Python 2.7 & Windows and also Linux are the platforms being used.  Running
the code from the command line / terminal as   python except.py.  Note that
it does work properly in Linux.  So I'm guessing I need to test for a
different exception along with the KeyboardInterrupt??

So, the code below is my example.

When I run it, everything is fine until I attempt to test the
KeyboardInterrupt exception.

When I do this, the traceback is as follows:
Traceback (most recent call last):
  File "except.py", line 71, in <module>
    start_menu()


What I was expecting was the message in the exception to be displayed ("
Keyboard Interrupt - Exiting "), then for the program to exit gracefully.

I'm sure that this is a NOOB mistake, but I can't seem to figure out why
the exception isn't being trapped and handled the way I had hoped.

Can someone shed some light on this for me?

Thank you,




# import standard libraries
import os
import time
import sys

DISPLAY_TIME = 5
g_user_num_items = -1

def start_menu():

    start_quit = False

    os.system('cls' if os.name == 'nt' else 'clear')

    print "\n\n\n\n Welcome to Test.\n"
    time.sleep(DISPLAY_TIME)

    try:
        while not start_quit:

            os.system('cls' if os.name == 'nt' else 'clear')

            print "\n +++ Test Start Menu +++"
            print "Enter the number of items to test,"
            print "or, 0 for individual testing."
            print "Then press <Enter>\n"

            # wait for it...
            num_items = int(raw_input(": "))

            if num_items == 0: # individual testing
                print "\nIndividual testing requested"
                g_user_num_items = num_items
                start_quit = True

            elif(num_items >= 1 and num_items <= 512):   # multi testing
                g_user_num_items = num_items
                print "\nItem count of ", g_user_num_items, ", accepted!"
                start_quit = True

            else:   # unexpected input eg A, >, ? etc
                print " Invalid number of items, please re-enter"

            time.sleep(DISPLAY_TIME / 2)

    ##### end item count input

    # detect ctrl-c
    except KeyboardInterrupt:
        # provides a clean exit
        print "\n\n Keyboard Interrupt - Exiting \n\n"
        time.sleep(5)

    # trap no choice, just Enter key cases
    except ValueError:
        # handles non-entry selections like 'Enter'
        print "Invalid selection please try again"
        time.sleep(DISPLAY_TIME / 2)
        start_menu()

    return
##### end main menu


##############################################
# Main entry point into program
#

if __name__ == "__main__":

    start_menu()

    print "End of Script\n"

From steve at pearwood.info  Thu Feb 28 18:13:17 2019
From: steve at pearwood.info (Steven D'Aprano)
Date: Fri, 1 Mar 2019 10:13:17 +1100
Subject: [Tutor] schedulers
In-Reply-To: <DB7PR05MB5769A8A9FFC00EE645183BA0E4750@DB7PR05MB5769.eurprd05.prod.outlook.com>
References: <DB7PR05MB5769A8A9FFC00EE645183BA0E4750@DB7PR05MB5769.eurprd05.prod.outlook.com>
Message-ID: <20190228231316.GE4465@ando.pearwood.info>

On Thu, Feb 28, 2019 at 02:45:59PM +0000, nathan tech wrote:
> Hi there,
> 
> I recently started working on a backup program, and the one big feature 
> everyone wants in backup programs is the ability to schedule backups, right?
> 
> but I'm thinking, should I do this?
[...]
> Is that wise? Is that how it should be done?

No. You should write your backup program to do backups, and then 
register that program with your operating system's scheduler. I don't 
know what that's called on Windows, but on Linux that would be "cron".

Basically, you have three problems:

1. Perform the backup.

2. Let the user decide when to do the backup.

3. Actually trigger the program to run at the correct time.


Parts 1 and 2 are your job. Number 3 is up to the OS. It will handle all 
the complex problems of clocks changing between jobs, computer reboots 
(what if the computer is off when the job is supposed to run?) etc.

If for some reason you need to write your own scheduler, using a "busy 
loop" where you run a loop continually checking the time is not the 
right answer. (I don't know what the right answer is, I just know that 
the OS has already solved that.)



-- 
Steven

From steve at pearwood.info  Thu Feb 28 18:19:20 2019
From: steve at pearwood.info (Steven D'Aprano)
Date: Fri, 1 Mar 2019 10:19:20 +1100
Subject: [Tutor] schedulers
In-Reply-To: <DB7PR05MB5769A8A9FFC00EE645183BA0E4750@DB7PR05MB5769.eurprd05.prod.outlook.com>
References: <DB7PR05MB5769A8A9FFC00EE645183BA0E4750@DB7PR05MB5769.eurprd05.prod.outlook.com>
Message-ID: <20190228231917.GF4465@ando.pearwood.info>

Sorry, I hit send too quick...

I realise you haven't written a busy loop, but the way you wrote your 
scheduler, you can only schedule jobs to the nearest 5 seconds. That's 
probably okay for a backup process that might take a few hours to run, 
but it is hardly a good solution to things that might need to be 
schedules 1 or 2 seconds apart.

And while you aren't *continuously* checking the time, you're still 
checking it pretty often. In the course of a day, you check the 
time 17280 times to see if you should run your backup program. That's 
pretty busy for something running once a day :-)

There's also the problem that you have to remember to launch your 
scheduler program every time you log in. Again, registering your backup 
program with the OS once means you don't have to think about it.

-- 
Steven

From alan.gauld at yahoo.co.uk  Thu Feb 28 18:23:51 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Thu, 28 Feb 2019 23:23:51 +0000
Subject: [Tutor] schedulers
In-Reply-To: <DB7PR05MB5769A8A9FFC00EE645183BA0E4750@DB7PR05MB5769.eurprd05.prod.outlook.com>
References: <DB7PR05MB5769A8A9FFC00EE645183BA0E4750@DB7PR05MB5769.eurprd05.prod.outlook.com>
Message-ID: <q59qi7$3dpk$1@blaine.gmane.org>

On 28/02/2019 14:45, nathan tech wrote:

> but I'm thinking, should I do this?

No. fOr several reasons...

> def do_backup
>  ?# backup code here, 

> 
> def scheduler():
>  ?global tus # tus=time until schedule
> 
>  ?while(time.time()>tus):
>  ? time.sleep(5)
>  ?scheduler()

scheduler doesn't actually do anything except
spin waiting for the time up. But you know the
current time and the due time so you can just
sleep until the due time, no need for the loop.

Also you exit the loop and then call scheduler
again - that will immediately exit the loop
and call scheduler again which will repeat
"forever". I suspect you meant to call do_backup?

However, if you really want to delay execution
of do_backup you can probably do it via the OS
Nearly every OS has a means of scheduling tasks.
So, by splitting your app into two parts - one
to create the scheduled task and the
other to actually do the backup.

That way the OS does all the heavy lifting,
including restoring the schedule after an OS
restart etc. And you only have the relatively
easy task of telling the os to schedule a task
and writing the backup function.

> This is a program for windows.

OK, I cant recall the Windows schedule
program - I think it was "at" or somesuch?

Then again you could just use the native Windows
backup program which doe it all for you...


-- 
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 david at graniteweb.com  Thu Feb 28 18:38:26 2019
From: david at graniteweb.com (David Rock)
Date: Thu, 28 Feb 2019 17:38:26 -0600
Subject: [Tutor] schedulers
In-Reply-To: <q59qi7$3dpk$1@blaine.gmane.org>
References: <DB7PR05MB5769A8A9FFC00EE645183BA0E4750@DB7PR05MB5769.eurprd05.prod.outlook.com>
 <q59qi7$3dpk$1@blaine.gmane.org>
Message-ID: <B177C74D-35EA-40D4-9671-CD4C6119A1B5@graniteweb.com>


> On Feb 28, 2019, at 17:23, Alan Gauld via Tutor <tutor at python.org> wrote:
> 
> On 28/02/2019 14:45, nathan tech wrote:
> 
>> but I'm thinking, should I do this?

Honestly, scheduling is the last thing to figure out.  As mentioned, it?s probably better to focus on backups and leave the scheduling to the OS tools that already exist. You need to write a solid backup routine, and an even more solid _restore_ routine.  Ultimately, the goal of backup software is to recover data.

Out of curiosity, what?s the driver behind doing this project in the first place?  
Do existing backup tools not do what you need (FOSS or otherwise)? 
Is this an academic exercise (i.e., for fun because you are curious)?
How complicated do you expect to get with the implementation?

If you are going to play with the scheduler, every 5 seconds is really overkill.  The reality is checking once a minute (even once every 5 minutes) is more than sufficient for even the most aggressive environments.  If you really need sub-minute starts, this is probably not something for a casual project.

have you thought about backup windows?  Defining the start time is one thing, but will you have an end time?  How long of a delay before you don?t try to start anymore?  What about media resources? How long will you wait if you have tape devices all in use?  Is this just a disk-based backup system?

Good backup software is not trivial to write.  Maybe if we better understood your goals, we could better direct you.


? 
David Rock
david at graniteweb.com





From alan.gauld at yahoo.co.uk  Thu Feb 28 20:34:14 2019
From: alan.gauld at yahoo.co.uk (Alan Gauld)
Date: Fri, 1 Mar 2019 01:34:14 +0000
Subject: [Tutor] Exception not working as expected?
In-Reply-To: <CADUn+-J6Cs8nqBTR4crcaJKM1ygK-RhwCoZ4wp=aqXoXdhgPpQ@mail.gmail.com>
References: <CADUn+-J6Cs8nqBTR4crcaJKM1ygK-RhwCoZ4wp=aqXoXdhgPpQ@mail.gmail.com>
Message-ID: <q5a26m$40bc$1@blaine.gmane.org>

On 28/02/2019 21:03, Chip Wachob wrote:

> it does work properly in Linux.  So I'm guessing I need to test for a
> different exception along with the KeyboardInterrupt??

Don't guess, test.

Write a single line script

raw_input('> ')

Run it in a console.
Hit Ctrl-C while it waits for input.
See what the stack trace says is the exception
Edit your script

try:
  raw_input('> ')
except <whatever e3xception you saw previously>:
  print "I got it that time!"

run the new script.
Did it work? Hooray! Transfer to the main script.
If not come back here armed with tracebacks...


-- 
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 eryksun at gmail.com  Thu Feb 28 21:31:00 2019
From: eryksun at gmail.com (eryk sun)
Date: Thu, 28 Feb 2019 20:31:00 -0600
Subject: [Tutor] Exception not working as expected?
In-Reply-To: <CADUn+-J6Cs8nqBTR4crcaJKM1ygK-RhwCoZ4wp=aqXoXdhgPpQ@mail.gmail.com>
References: <CADUn+-J6Cs8nqBTR4crcaJKM1ygK-RhwCoZ4wp=aqXoXdhgPpQ@mail.gmail.com>
Message-ID: <CACL+1as5HJS3BEORL1ZRZesm71pOMyTL9g2AZNp1iX3ZzSbgsQ@mail.gmail.com>

On 2/28/19, Chip Wachob <wachobc at gmail.com> wrote:
>
> Python 2.7 & Windows and also Linux are the platforms being used.  Running
> the code from the command line / terminal as   python except.py.  Note that
> it does work properly in Linux.  So I'm guessing I need to test for a
> different exception along with the KeyboardInterrupt??

When reading from the console, we depend on a particular error being
set in order to distinguish an interrupted read from end-of-file
(EOF), but this error doesn't get set in Windows 8+ due to a bug in
the Windows API. I created an issue with Microsoft's console team, but
thus far they've ignored it.

Due to this bug, Python 2 code that calls raw_input() or input() also
needs to handle EOFError, which should probably be handled anyway.
However, it's not enough to separately handle KeyboardInterrupt and
EOFError, since the KeyboardInterrupt may get raised while handling
EOFError. This can happen because Windows calls the console control
handler asynchronously in a new thread. We need a bit of a kludge that
checks for a delayed KeyboardInterrupt. For example, the following
shows a case that uses a common handler for EOF and Ctrl+C:

    import os
    import sys
    import time

    def main():
        try:
            os.system('cls' if os.name == 'nt' else 'clear')
            print "\n\n\n\n Welcome to Test.\n"
            time.sleep(DISPLAY_TIME)
            start_menu()
        except (KeyboardInterrupt, EOFError):
            try:
                time.sleep(0.1)
            except KeyboardInterrupt:
                pass
            # provides a clean exit
            print "\n\n Keyboard Interrupt or EOF - Exiting \n\n"
            time.sleep(5)
        print "End of Script\n"
        return 0

    if __name__ == "__main__":
        sys.exit(main())

>     # trap no choice, just Enter key cases
>     except ValueError:
>         # handles non-entry selections like 'Enter'
>         print "Invalid selection please try again"
>         time.sleep(DISPLAY_TIME / 2)
>         start_menu()

ValueError should be handled near the int() conversion that raises it,
and the exception handler should `continue` the loop instead of
recursively calling start_menu().

From nathan-tech at hotmail.com  Thu Feb 28 20:59:47 2019
From: nathan-tech at hotmail.com (nathan tech)
Date: Fri, 1 Mar 2019 01:59:47 +0000
Subject: [Tutor] schedulers
In-Reply-To: <q59qi7$3dpk$1@blaine.gmane.org>
References: <DB7PR05MB5769A8A9FFC00EE645183BA0E4750@DB7PR05MB5769.eurprd05.prod.outlook.com>
 <q59qi7$3dpk$1@blaine.gmane.org>
Message-ID: <DB7PR05MB57696A9999F826C5F1F33A43E4760@DB7PR05MB5769.eurprd05.prod.outlook.com>

Hopefully I am doing this right, wanted to reply to the tutor list, not 
a specific person... Anyway.

Thanks Steven and Alan for your help.

I'll look into the windows scheduler and go from there.


The code given in the original email was just an example, but none the 
less I appreciate you guys pointing out the floors. :)

Thanks again.

Nathan

On 28/02/2019 23:23, Alan Gauld via Tutor wrote:
> On 28/02/2019 14:45, nathan tech wrote:
>
>> but I'm thinking, should I do this?
> No. fOr several reasons...
>
>> def do_backup
>>   ?# backup code here,
>> def scheduler():
>>   ?global tus # tus=time until schedule
>>
>>   ?while(time.time()>tus):
>>   ? time.sleep(5)
>>   ?scheduler()
> scheduler doesn't actually do anything except
> spin waiting for the time up. But you know the
> current time and the due time so you can just
> sleep until the due time, no need for the loop.
>
> Also you exit the loop and then call scheduler
> again - that will immediately exit the loop
> and call scheduler again which will repeat
> "forever". I suspect you meant to call do_backup?
>
> However, if you really want to delay execution
> of do_backup you can probably do it via the OS
> Nearly every OS has a means of scheduling tasks.
> So, by splitting your app into two parts - one
> to create the scheduled task and the
> other to actually do the backup.
>
> That way the OS does all the heavy lifting,
> including restoring the schedule after an OS
> restart etc. And you only have the relatively
> easy task of telling the os to schedule a task
> and writing the backup function.
>
>> This is a program for windows.
> OK, I cant recall the Windows schedule
> program - I think it was "at" or somesuch?
>
> Then again you could just use the native Windows
> backup program which doe it all for you...
>
>