Re: [Tutor] Borrowing restricted code

2018-12-05 Thread Steven D'Aprano
On Wed, Dec 05, 2018 at 07:49:58PM +, Mark Lawrence wrote:
> On 05/12/2018 16:22, Avi Gross wrote:
> 
> [huge snip]
> 
> Please take yourself to another forum, your ramblings have no place on 
> the *PYTHON TUTOR* mailing list.

Steady on Mark, a lot of what Avi says is misinformed or close to 
stream-of-consciousness irrelevant chatter (no offense Avi, but you do 
go on and on with no apparent point sometimes), but some of it is 
relevant to Python programming.

Every programmer who distributes or copies software needs to have at 
least a basic understanding of copyright and licencing.

We allow discussions about IDEs or the best graphical libraries, and 
they too are only peripherally related to Python. But they are related, 
just as licencing and copyright are.



-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Borrowing restricted code

2018-12-05 Thread Steven D'Aprano
On Wed, Dec 05, 2018 at 11:22:35AM -0500, Avi Gross wrote:

> I am NOT advocating copying code. Not even "free" code.
> 
> I am saying there may be times you want to package the code for special
> purposes.

"Packaging" the code IS copying the code.


> Perhaps someone can enlighten me on a subtle aspect here.
> 
> What does it mean to include something?

https://en.wiktionary.org/wiki/include


[... description of how #include works in C ...]
> The above is not meant to be a precise description but indicates that your
> code was rarely all your own. You could literally set it up so if someone
> else left their code unguarded, you could arrange to grab text or library
> code into your finished executable.

The precise details of what an individual programming language means by 
"including" code will, naturally, depend on the language in question.

This is not really the place to go into a detailed description of all 
the possible variations (this is supposed to be a *Python* forum after 
all) but briefly there are at least two kinds of code which we might 
"include": source code and compiled object code.

When "including" source code, the interpreter might read a command like 
"load spam", look up a file "spam", read the contents into memory, parse 
it and run it through the interpreter as if it had been copied and 
pasted into the original file in place of the "load" line.

When "including" object code, the compiler (or often a separate program 
called a linker) can make a copy of the object code and insert that code 
directly into the object code it is generating. This is called "static 
linking".

An alternative is to leave the object code where it is, but instead 
insert instructions for how to access it at runtime. This is called 
"dynamic linking".

https://kb.iu.edu/d/akqn

Python's import is (I think) closer to dynamic linking than the others.


> In python, you can generally have access to the python code of what you can
> import or at least to the byte code. But there may be different rules
> attached to several categories.
> 
> If you use "import" you don't so much copy as USE the code. I mean the
> interpreter pauses evaluating the current file and opens the one you asked
> for and reads it as if it were your code.

That is not entirely wrong, but its not quite right either.

The action of the import command is surprisingly complex, and so I may 
have got some subtle details wrong. But the high-level overview of what 
the interpreter does when you run "import spam" is as follows.

1. Look for an already loaded module "spam"; if the interpreter finds 
one, it creates an new variable called "spam" in the current namespace, 
and assigns that module object to that name. The import is complete.

# Pseudo-code
if "spam" in sys.modules:
spam = sys.modules["spam"]
return


2. If no such already loaded module, then search a set of known 
locations for a library called "spam":

# Pseudo-code
for location in sys.path:
for filename in os.listdir(location):
name, ext = path.splitext(filename)
if name == "spam":
if ext == ".py":
read the source code from spam.py into memory
parse it into bytecode into memory
write out the bytecode to spam.pyc
elif ext == ".pyc":
read the bytecode from spam.pyc into memory
else:
# other cases handled here, e.g. packages, zip files,
# C libraries (.dll or .so), other extensions etc.
# Assuming we get to here...
create a module object in memory
run that bytecode, using that module object as the namespace
cache the module object in sys.modules['spam']
spam = module object
return
# no such "spam" module or package found
raise ImportError


So you can see that modules are only executed the first time the 
interpreter imports them, not on subsequent imports.

There really isn't a distinction to make between code treated "as if it 
were your code" and other code. All code is treated the same.

How could it not be? The interpreter cannot know which modules or 
libraries you wrote, which were collaborative efforts between you and 
other people, and which were written by other people.



> Some actions are transient. A line
> like "5+3" evaluates to 8 and you ignore it. But many and perhaps most lines
> end up creating instantiations of objects (yes, classes are also objects)
> which then sit in memory.

Or get used and then disposed of by the garbage collector.


> Functions are also objects and pretty much contain
> within them everything you need to reconstruct the function if you know
> where to look. Is what is copied really different than the original text
> used? 

Yes.


> If you import the base modules that come with python, can you assume it is
> freely given with few strings other than the kind discussed?

There is no need to assume anything, you 

Re: [Tutor] Any 'graphical' ways of learning Python

2018-12-05 Thread Sarfraaz Ahmed
Hello Matthew,

Although, its not for Graphics, I have noticed that
http://www.pythontutor.com is a good place that can come in handy for
students who are new to programming.

It gives a graphical view of how memory is allocated for variables and how
functions are invoked in a program.

I have seen students strengthen their fundamental programming concepts
through the visual representation of code flow on this website.

You could try this as well.

On Wed, Dec 5, 2018 at 1:54 PM Matthew Polack <
matthew.pol...@htlc.vic.edu.au> wrote:

> Hi All,
>
> We're using Python with our Year 9 and 10 students to teach programming.
> I've started with basic console programming...doing simple games like a
> quiz game etc.
>
> Students always seem to like 'graphics'..one of the reasons things like
> 'Scratch' are so popular in schools is because of  the ready made GUI.
>
> My concern with things like 'Scratch' and 'Game Engines' is that perhaps
> kids can miss out on  learning core fundamentals...but can appreciate some
> visuals can be very motivating...
>
> Can anyone recommend any ways of integrating 'graphics' but in a simpler
> way.
>
> I've had some experience with TKinter...(which is still quite a jump for
> beginners)also can see that 'Pygame' might offer some of this...
>
> also have seen some tutorials on Udemy that encourages using the 'Turtle'.
>
> Does anything else come to find for helping kids stay engaged when they
> start to get tired of just text based console programming?
>
> Thanks for any suggestions.
>
>
> Matthew Polack | Teacher
>
> --
> **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@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


-- 
Thanks
   -- Sarfraaz Ahmed
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Borrowing restricted code

2018-12-05 Thread Mark Lawrence

On 05/12/2018 16:22, Avi Gross wrote:

[huge snip]

Please take yourself to another forum, your ramblings have no place on 
the *PYTHON TUTOR* mailing list.


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

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Borrowing restricted code

2018-12-05 Thread Avi Gross
I don't want to start (and continue) another sideways discussion. Alan and
Steven (not Stephen) both made very good points and helped clarify my
understanding.

I am NOT advocating copying code. Not even "free" code.

I am saying there may be times you want to package the code for special
purposes.

Perhaps someone can enlighten me on a subtle aspect here.

What does it mean to include something?

If we return to the days of yesteryear, albeit much of it exists this year,
a major programming paradigm was to compile a language like C or PASCAL into
some machine language or a binary form. But you only wrote a part of the
final program and inserted parts from what had been written, mainly, by
others.

One inclusion in languages like C was variants of lines like this:

#include "stdio.h"

What would happen was when a phase of the compile process read your file and
saw a request to include, it would pause, try to find the file in the usual
places, and then copy the text and continue. This could be recursive if that
file included another. It is in one sense similar to how "import" works in
python or "library" in R and similar features in other languages.

What was different was that one large file was created which was a flattened
version of this tree of code. Another pass of the compiler would then
process it. Nothing was RUN until later and only if there were no
compilation errors. Along the way, another form of inclusion had to happen.
If your code (directly or indirectly) called functions not defined in your
own code, and not already compiled in, it had to search assorted libraries
of such code, find the segments needed, and link them in. Eventually, it got
even worse and shared libraries would be mounted in memory and when your
code ran, it would link in what was needed.

The above is not meant to be a precise description but indicates that your
code was rarely all your own. You could literally set it up so if someone
else left their code unguarded, you could arrange to grab text or library
code into your finished executable.

In python, you can generally have access to the python code of what you can
import or at least to the byte code. But there may be different rules
attached to several categories.

If you use "import" you don't so much copy as USE the code. I mean the
interpreter pauses evaluating the current file and opens the one you asked
for and reads it as if it were your code. Some actions are transient. A line
like "5+3" evaluates to 8 and you ignore it. But many and perhaps most lines
end up creating instantiations of objects (yes, classes are also objects)
which then sit in memory. Functions are also objects and pretty much contain
within them everything you need to reconstruct the function if you know
where to look. Is what is copied really different than the original text
used? 

If you import the base modules that come with python, can you assume it is
freely given with few strings other than the kind discussed? If it is
outside but available from a standard download location, perhaps you need to
see the documentation for each item. If it is sold to you, I suspect you
need to be very careful about including any.

Back to the main topic, for me. What kind of uses might be considered legal
or at least not worth prosecuting? The law in various countries likely
differs, Alan and I are definitely using different legal systems but
possibly not as different as where Asad is. (His phone number would be in
India.) Clearly if you make a product and sell it, then borrowing code can
be a serious thing. If you are a student doing a homework assignment and
will never use it again, few might care especially if you use small amounts
and don't claim it is your own work.

But the question I would like answered is DOES IT MAKE A DIFFERENCE how you
borrow the use of the code? 

We talked about the normal intended method:

Load the file into a place on your local machine.
Write one or more python files and one of them imports it.

A second method I suggested WHEN NEEDED AND ALLOWED is to find the code you
need, perhaps on another machine where you can download it, or in some other
public repository. Copy the minimum you need into your own code, with
perhaps enough attribution and explanation.

Now what about a third way? No edit needed. Simply use a program like "cat"
to concatenate multiple files including the one with your code into a bigger
lump. Feed that to the python interpreter.  Included would be the code you
want. True, the code would now all be in one namespace. But is this form of
copying all that much different than was intended? 

I am not going to continue in any further discussion. But I do think this
could be useful to people learning python as often the best way to find out
how to do something is to study the code of someone who did it. You might
want to play with it and see if you can improve it or vary some part ...

So it would be good to know what can be done legally and what to avoid.

As 

Re: [Tutor] Any 'graphical' ways of learning Python

2018-12-05 Thread Adam Eyring
I've liked turtle and make my graphing more interesting by asking for user
input such as dimensions, then graph automatically.

One starter source for using pygame graphics is
https://inventwithpython.com/pygame/
It jumps into game writing very quickly, but provides explanations of
commands.

The one I'm working on now is using the arcade library developed by a
python college professor:
http://arcade.academy
Many many examples of code (including videos of student projects) are
provided to help you write games that resemble many of our favorites.


On Wed, Dec 5, 2018, 3:40 AM Alan Gauld via Tutor  wrote:

> On 05/12/2018 00:39, Matthew Polack wrote:
>
> > Can anyone recommend any ways of integrating 'graphics' but in a simpler
> > way.
> >
>
> Have you considered the turtle module.
>
> Its limited to drawing shapes but does give some immediate results.
> You can of course create functions to draw more sophisticated shapes
> etc. And you write the code in an ordinary IDE/editor so its a good
> transition from fully graphical scratch to fully text mode Python.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>

On Dec 5, 2018 3:40 AM, "Alan Gauld via Tutor"  wrote:

On 05/12/2018 00:39, Matthew Polack wrote:

> Can anyone recommend any ways of integrating 'graphics' but in a simpler
> way.
>

Have you considered the turtle module.

Its limited to drawing shapes but does give some immediate results.
You can of course create functions to draw more sophisticated shapes
etc. And you write the code in an ordinary IDE/editor so its a good
transition from fully graphical scratch to fully text mode Python.


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



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Any 'graphical' ways of learning Python

2018-12-05 Thread Steven D'Aprano
On Wed, Dec 05, 2018 at 11:39:49AM +1100, Matthew Polack wrote:
> Hi All,
> 
> We're using Python with our Year 9 and 10 students to teach programming.

Yay! And I see you're a fellow Aussie :-)


> I've started with basic console programming...doing simple games like a
> quiz game etc.
> 
> Students always seem to like 'graphics'..one of the reasons things like
> 'Scratch' are so popular in schools is because of  the ready made GUI.

Indeed.

Alas, graphics is one of Python's weaknesses, especially at the 
beginners' level.

The easiest to use will be the turtle module, although its fairly 
limited in what it does. Its basically a simulation of the turtle 
from the Logo programming language. Logo was cutting edge about half a 
century ago.

You might try PyGame, although I don't know how easy it will be for you 
to pre-install it for the students, or how difficult it is to use (I've 
never used it myself).

https://www.pygame.org/


Another option is PySimpleGUI:

https://pypi.org/project/PySimpleGUI/




-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Beginners Book, Python and PyScripter

2018-12-05 Thread Steven D'Aprano
On Wed, Dec 05, 2018 at 08:44:14AM +, Alan Gauld via Tutor wrote:
> On 04/12/2018 23:52, James Stapleton-Cotton wrote:
> 
> > USERs-MacBook-Pro:~ user$ python hello.py
> > python: can't open file 'hello.py': [Errno 2] No such file or directory
> 
> You need to provide the full path to the Python file.
> 
> > I previously created a python file called 'hello.py' using the PyCharmEdu
> > editor (as instructed). This file is saved in my 'Documents' in a folder
> > called 'Pycharm Projects' 
> 
> So you would have needed to type
> 
> user$ python "~/Documents/Pycharm Projects/hello.py"

To be absolutely clear here, the "user$" part is the prompt, you don't 
type that.



-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Copyleft

2018-12-05 Thread Steven D'Aprano
Avi,

Why do you keep changing the subject line? You started a new thread 
about "borrowing" (copying) code, people responded to that thread, and 
you've immediately changed the subject to "Copyleft" even though you 
talk about much more than copyleft licences.

(You barely mention copyleft at all -- and what you say about it is 
very inaccurate.)


On Tue, Dec 04, 2018 at 07:50:21PM -0500, Avi Gross wrote:
> Alan,
> 
> Just a reminder. I am NOT suggesting the first way to solve a problem 
> is what I described. I am saying that sometimes a roadblock (real or 
> imagined) can be gotten around using methods like that.

In my experience, the sorts of organisations which make it difficult to 
install third-party software (whether FOSS or proprietary) are also the 
sorts of organisations which will fire you immediately for copying 
someone else's code.

YMMV.


> Agreed. There are copyrights that have to be considered, albeit often 
> SMALL amounts are considered OK. Attribution is a good idea in 
> general.

There's another factor to consider: software patents. If you're going to 
copy a small amount of code, you may still violate their patent. 
(Disclaimer: I am not a patent lawyer.) In that case, giving credit to 
them will be tantamount to admitting to willful infringement, which in 
most jurisdictions that I know of receives triple damages.

That's how broken the patent system is: the penalties for infringement 
encourage people to avoid doing a patent search. Its better to say "We 
couldn't be bothered doing a patent search" than to say "We tried to do 
due diligence but failed to spot this patent", because when it comes to 
patents, if you make the effort but fail, you are deemed to have 
willfully infringed, whereas if you intentionally make no attempt to 
avoid infringing, your infringement is deemed to have been an innocent 
mistake.

Crazy but true.



> The problem that began this is when someone puts roadblocks in the way of 
> what works.

There may be very good reasons for this policy that you call a 
roadblock.

And we only have the Original Poster's word that he is not allowed 
to install pexpect. That could be his misunderstanding, or perhaps he 
can't be bothered going through the process to get approval.

In fairness, some places do make that process rather gruelling... in a 
previous position, I worked with a client whose change request process 
for installing new software on a production server could easily take 
three or four months for approval to come through, if it was given at 
all. Now, you might be tempted to roll your eyes and call that 
bureaucracy gone mad, but they had very good reasons for that level of 
caution and conservativeness.

A colleague got a figurative spanking after he accidentally brought 
their production server down (fortunately only for ten minutes, although 
that was ten minutes too long) by rolling out a buggy "bug fix" directly 
onto the production server without testing it on a staging server first, 
or getting approval for the change.

https://i.chzbgr.com/full/7756111616/hED5FBCC9/


 
> If someone for example wants to be able to use something as trivial as 
> math.pi but for some reason won't load the math module, you could 
> suggest they look up the value of pi to umpteen decimal places and 
> create an object called math Perhaps a class) containing nothing but a 
> value called pi 

[...]
> Or, I suggest you can copy the real math module into the same place. 
> You may want to edit it with a comment.

So rather than adding a single constant, you're going to risk infringing 
the copyright and moral rights of other programmers by copying a 75 
kilobyte C library that you don't need, just to get the value of pi 
which you could legally and easily copy from your calculator or Google 
in about five seconds.

Are you being paid by the hour? *wink*


> But, yes, bad example as pretty much any implementation of python will 
> include the math module as it is standard.

Indeed. Let's take a better example: the pexpect library.

The OP is not able (not permitted? not physically able? can't be 
bothered?) to install the pexpect library. So your advice for him is 
to... install the pexpect library, potentially ignoring its licence 
terms, making a copy of the source (hoping that its all Python and not C 
that needs compiling) and edit the source to "add a comment" (saying 
what?).

I think you haven't really considered that if the OP is not able to 
install the pexpect library, he probably won't be able to copy it into 
his application either. To say nothing of the ethical issues of copying 
software without obeying the licence terms.

Fortunately pexpect itself is licenced under a very permissive licence 
that allows copying with (almost) no restriction:

https://github.com/pexpect/pexpect/blob/master/LICENSE

but as a general matter of principle, suggesting people just copy the 
source code they want and stick it in their application is rather risky 
and 

Re: [Tutor] Regarding Python api script

2018-12-05 Thread Alan Gauld via Tutor
CCing the list, please use Reply All when responding to the tutor list.


On 05/12/2018 03:44, Ravi Kumar wrote:
> Yes  thats right I want to extract the xml and store into database(SQL
> Server) and I will have to cteate a new table
>
> Here is the sample output I am getting similarly there bulk data which
> I want to store in database format is as shown below
>
>
> b'[{"deviceSerial":"Q2XD-333X-G8Q8","occurredAt":1537565.640085,"type":"802.11
> association","details":{"radio":"1","vap":"0","clientMac":"C8:21:6679:B6:16","channel":"44","rssi":"57","aid":"31645681"}},{"deviceSerial":"Q2XD-97gX-G8Q8","occurredAt":153765.700095,"type":"WPA
> deauthentication","details":{"radio":"1","vap":"0","clientMac":"C621:58:79:B6:16","aid":"316681"}},{"deviceSerial":"Q2XD-97gX-G8Q8","occurredAt":1563369.780085,"type":"WPA
> deauthentication","details":{"radio":"1","vap":"0","clientMac":"C8:21:58:9:B6:16","aid":"31645681"}},{"deviceSerial":"Q297JX-G8Q8"
>
>
> Please let me whether this can be formatted into json in the code

It looks to me like it is already in JSON format.

It is a list of objects.

The json module will let you extract the objects into Python data objects.


> and also any other tips or links to refer if available  to store in
> database

Do you know SQL?

If so using the Python DBAPI is very easy.

If not you will need to learn some basic SQL.

You can try reading the database topic in my Python tutorial(see below)
which is based on SQLite rather than SQL Server but should be 90%
compatible.


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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Borrowing free code

2018-12-05 Thread Alan Gauld via Tutor
On 05/12/2018 06:14, Steven D'Aprano wrote:
> On Tue, Dec 04, 2018 at 11:43:05PM +, Alan Gauld via Tutor wrote:
>> On 04/12/2018 19:31, Avi Gross wrote:
>>
>>> But some packages are simply python code that you can 
>>> simply insert into your own python files. 
>>
>> If they are fully public domain that's probably true.
> 
> Almost nothing younger than 70 years is in the public domain. 

True and anything not public domain throws up lots
of issues as you point out! :-)

> Copyright infringement is typically handled through the civil courts: 

You say that as if "civil courts" were somehow not like
higher courts but in these parts there is no distinction
except in the processes used. They hold the same weight
and its all considered criminal activity.

> If you have a valid licence to use and copy the software, and you obey 
> the licence terms, then you are in no danger of being prosecuted for 
> copyright infringement because you are licenced to do so.

But it depends on the copyright. You may be free to use
it provided you include the original copyright/license
notice, or you may only need to give accreditation
(possibly in some fixed format), or maybe you can just use it.
Its all very murky and you need a lawyer to sort it out.

And that's really the point I was making.
Avi's suggestion is technically correct but if used
in any piece of production software can lead to a
world of pain.

> Regardless of the licence, you must obey the conditions

And that was my point.
It's misleading to say on a beginners list that you can
just copy code into your own files. Its much more
complicated than that.

> In a practical sense, copying trivial amounts of code from software 
> licenced under the MIT licence, or similar, would be highly unlikely to 
> get you sued.

Agreed, especially if its for private or limited use. If released into
the wider market then its a differentstory.
And some companies (I know of two at least) actively police
the market (Git hub and source forge inclyded) for corporate
code being abused(even if it's been GPL'd)

> Another factor may be that, regardless of the *actual* legal risk, some 
> employers may not allow copying or use of (some or all) FOSS software 
> even if licenced, because they may fear the unknown,

Again true and was the case in my old company.
To use FOSS code we had to jump through several
hoops with the company lawyers.
It had to be a major bit of work to make that worthwhile!

> Bottom line: yes, you can legally copy FOSS software, under certain 
> conditions, and need not fear being prosecuted.

Yes, the point being you need to find out what the conditions are.
And there are many permutations.

> (Actually, you could even copy closed-source proprietary software, if 
> you have a licence allowing you to do so.)

True.


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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Beginners Book, Python and PyScripter

2018-12-05 Thread Alan Gauld via Tutor
On 04/12/2018 23:52, James Stapleton-Cotton wrote:

> USERs-MacBook-Pro:~ user$ python hello.py
> python: can't open file 'hello.py': [Errno 2] No such file or directory

You need to provide the full path to the Python file.

> I previously created a python file called 'hello.py' using the PyCharmEdu
> editor (as instructed). This file is saved in my 'Documents' in a folder
> called 'Pycharm Projects' 

So you would have needed to type

user$ python "~/Documents/Pycharm Projects/hello.py"

> to the original, 'PycharmProjects'.]

Note that here you omit the space.
The OS is very particular about such details, you need
to get it exactly right. (Although in bash using the
tab key will usually fill things in the way you need it)

> 'hello.py' file into the tmp folder and attempted the above process of
> 'running' the 'python hello.py' file from the terminal, however the same
> result occurred.

Again you needthe patg:

user$ python /tmp/py/hello.py

The other option is to change directory to where the code is and then
just specify the name:

user$ cd /tmp/py
user$ python hello.py

Should work too.

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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Any 'graphical' ways of learning Python

2018-12-05 Thread Alan Gauld via Tutor
On 05/12/2018 00:39, Matthew Polack wrote:

> Can anyone recommend any ways of integrating 'graphics' but in a simpler
> way.
> 

Have you considered the turtle module.

Its limited to drawing shapes but does give some immediate results.
You can of course create functions to draw more sophisticated shapes
etc. And you write the code in an ordinary IDE/editor so its a good
transition from fully graphical scratch to fully text mode Python.

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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Any 'graphical' ways of learning Python

2018-12-05 Thread Matthew Polack
Hi All,

We're using Python with our Year 9 and 10 students to teach programming.
I've started with basic console programming...doing simple games like a
quiz game etc.

Students always seem to like 'graphics'..one of the reasons things like
'Scratch' are so popular in schools is because of  the ready made GUI.

My concern with things like 'Scratch' and 'Game Engines' is that perhaps
kids can miss out on  learning core fundamentals...but can appreciate some
visuals can be very motivating...

Can anyone recommend any ways of integrating 'graphics' but in a simpler
way.

I've had some experience with TKinter...(which is still quite a jump for
beginners)also can see that 'Pygame' might offer some of this...

also have seen some tutorials on Udemy that encourages using the 'Turtle'.

Does anything else come to find for helping kids stay engaged when they
start to get tired of just text based console programming?

Thanks for any suggestions.


Matthew Polack | Teacher

-- 
**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@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Beginners Book, Python and PyScripter

2018-12-05 Thread James Stapleton-Cotton
Thank you Adam.
I am currently going through the book, 'A Byte of Python' - found here -
https://python.swaroopch.com.
On pages 29-30 it writes about 'Using A Source File', creating a file
called '/tmp/py' on a Mac OS using the 'bash-terminal' and running the
saved PyCharm file, 'hello.py'. I type 'mkdir /tmp/py' into the terminal
and press return. This supposedly creates a new folder. I type 'mkdir
/tmp/py' a second time and press return as so:

USERs-MacBook-Pro:~ user$ mkdir /tmp/py

mkdir: /tmp/py: File exists


This shows that the file is indeed created and 'exists'. In the next
instructed step (typing 'python hello.py' into the terminal) there shows an
error as such:

USERs-MacBook-Pro:~ user$ mkdir /tmp/py

mkdir: /tmp/py: File exists

USERs-MacBook-Pro:~ user$ python hello.py
python: can't open file 'hello.py': [Errno 2] No such file or directory

I previously created a python file called 'hello.py' using the PyCharmEdu
editor (as instructed). This file is saved in my 'Documents' in a folder
called 'Pycharm Projects' [I tried changing the location of the file to
'/tmp/py', however this created an error during my 'print' function -
print("hello world") - in the editor, therefore I changed the location back
to the original, 'PycharmProjects'.]

I have found the /tmp/py folder within my 'Users' folder. I dragged the
'hello.py' file into the tmp folder and attempted the above process of
'running' the 'python hello.py' file from the terminal, however the same
result occurred.

Could you please help clarify where I am going wrong in the instructed
process given by the book mentioned above.

Regards

On Tue, Dec 4, 2018 at 9:16 PM Adam Eyring  wrote:

> I haven't gone through many python books, but have been using a copy of
> Automating the Boring Stuff with Python. It covers lists, dictionaries,
> scraping data from websites, etc.
> https://automatetheboringstuff.com/
> The PDF is free.
>
> Adam
>
> On Tue, Dec 4, 2018 at 1:09 PM James Stapleton-Cotton 
> wrote:
>
>> Thank you Mats and Steven. I'm back on track now with a different tutorial
>> which has lead to me to the relevant coding tools.
>> https://wiki.python.org/moin/BeginnersGuide/NonProgrammers
>> https://python.swaroopch.com
>>
>> On Mon, Dec 3, 2018 at 4:04 PM Mats Wichmann  wrote:
>>
>> > On 12/3/18 3:35 AM, James Stapleton-Cotton wrote:
>> > > Hello,
>> > >
>> > > On this page (
>> > >
>> >
>> http://openbookproject.net/thinkcs/python/english3e/way_of_the_program.html
>> > )
>> > > - a book for learning Computer Science using Python - I am directed
>> to (
>> > > http://code.google.com/p/pyscripter) in order to access the
>> appropriate
>> > > program development environment, PyScripter. I have downloaded the
>> latest
>> > > version of Python from Python.org and PyScripter from a site that I am
>> > > directed to from the original site mentioned in the beginning of this
>> > email
>> > > - (https://sourceforge.net/projects/pyscripter/files/), however I
>> can't
>> > > seem to be able to run PyScripter on my Mac.
>> >
>> > it looks like from the project's own description that PyScripter is
>> > intended solely for the Windows environment.
>> >
>> > But there are a TON of other IDE products, free and commercial, out
>> > there, many of which do run on the Mac.
>> >
>> > This may be information overload, but try looking here:
>> >
>> > https://wiki.python.org/moin/IntegratedDevelopmentEnvironments
>> >
>> >
>> > ___
>> > Tutor maillist  -  Tutor@python.org
>> > To unsubscribe or change subscription options:
>> > https://mail.python.org/mailman/listinfo/tutor
>> >
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> https://mail.python.org/mailman/listinfo/tutor
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Copyleft

2018-12-05 Thread Avi Gross
Alan,

Just a reminder. I am NOT suggesting the first way to solve a problem is what I 
described. I am saying that sometimes a roadblock (real or imagined) can be 
gotten around using methods like that.

Agreed. There are copyrights that have to be considered, albeit often SMALL 
amounts are considered OK. Attribution is a good idea in general.

The problem that began this is when someone puts roadblocks in the way of what 
works.

If someone for example wants to be able to use something as trivial as math.pi 
but for some reason won't load the math module, you could suggest they look up 
the value of pi to umpteen decimal places and create an object called math 
Perhaps a class) containing nothing but a value called pi 

This might even satisfy other code they have imported that expects to be able 
to invoke math.pi. But if that other code does an import too, then you might 
need to create an (almost) empty file called math.py containing 
pi=3.1415926535...

Just to make the rest work.

Or, I suggest you can copy the real math module into the same place. You may 
want to edit it with a comment.

But, yes, bad example as pretty much any implementation of python will include 
the math module as it is standard.

Your post does remind me that there are many versions of copyright including 
some with the silly naming of "copyleft" that allow rather free use but with 
limits. They may charge large businesses or government agencies. They may 
demand you leave in some text as in comments or not make changes or notify them 
to get permission so they can keep track or ...

I brought up some questions a while ago that boiled down to how a program can 
know what is already available on the machine the code is being run on. Clearly 
if you use an unfamiliar package, one solution would be to bring the needed 
files with you in the distribution of the program. Yes, it may not be the 
latest or greatest, but you can imagine many ways where it can conditionally 
fall back on the copies included if a regular import fails. 

This may be one reason someone would be asked to limit their code to the 
standard distribution. 



-Original Message-
From: Tutor  On Behalf Of Alan 
Gauld via Tutor
Sent: Tuesday, December 4, 2018 6:43 PM
To: tutor@python.org
Subject: Re: [Tutor] Borrowing free code

On 04/12/2018 19:31, Avi Gross wrote:

> But some packages are simply python code that you can simply insert 
> into your own python files.

If they are fully public domain that's probably true.
If they are copyright (even if open/free) you would be potentially liable for 
prosecution since you are copying someone else's work.

Even if it is open source then at the very least you should include a comment 
to the effect that the code is based on, say, M Palin's file parrot.py or 
whatever.

> And, yes, this means you do not get updates if the module changes.

And this is a big drawback for any non trivial code unless you are a 
significantly better programmer than whoever wrote it in the first place. 
(Since understanding somebody else's code is much harder than understanding 
your own!)

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


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor