Re: [Tutor] Search for Text in File

2019-08-15 Thread David Rock

> On Aug 15, 2019, at 09:10, Stephen P. Molnar  wrote:
> 
> 
> Everything that I have tried returns 'TypeError: 'str' object is not 
> callable’.

As a rule, posting actual output is better than paraphrasing.

We can’t tell what you have tried, or what the expected result actually is.  We 
also don’t know the context in which the TypeError occurs.
Please paste the actual text session showing your interaction with the program 
_and_ the full traceback so we can see what the TypeError is related to in the 
code.

— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] HELP PLEASE

2019-08-13 Thread David L Neil

On 13/08/19 7:11 AM, Marissa Russo wrote:

This is my code:

import math

def get_numbers():
 print("This program will compute the mean and standard deviation")
 file1 = input("Please enter the first filename: ")
 file2 = input("Please enter the second filename: ")
 x = open(file1, "r")
 y = open(file2, "r")
 nums = x.readlines()
 nums2 = y.readlines()

 return nums, nums2



Do you understand the concept of a "loop" - Code which is repeated as 
many times as necessary?


How many files must be opened, read, and then averaged?



def to_ints(strings):
 num_copy = []
 for num in nums:
 num_copy.append(float(num))
 return num_copy

 return to_ints(nums), to_ints(nums2)


What is the purpose of this line, given that the previous line has 
returned to the calling code?


Have I missed something? When is to_ints() used?



def mean(nums):
 _sum = 0
 return(sum(nums)/len(nums))

def main():
 data = get_numbers()
 m = mean(data[0])


Do you know what data[ 0 ] (or [ 1 ]) contains?
Might this knowledge be helpful?



 m2 = mean(data[1])
 print("The mean of the first file is: ", m)
 print("The mean of the second file is: ", m2)
main()


This is the output of my updated code:

Traceback (most recent call last):
   File "/Applications/Python 3.7/exercises .py", line 37, in 
 main()
   File "/Applications/Python 3.7/exercises .py", line 33, in main
 m = mean(data[0])
   File "/Applications/Python 3.7/exercises .py", line 29, in mean
 return(sum(nums)/len(nums))
TypeError: unsupported operand type(s) for +: 'int' and 'str'


What do you think "TypeError" means? Do you know the difference between 
an "int" and a "str[ing]"?


Given that both sum() and len() return numbers, what do you think is the 
"str"? Might this refer back to the earlier suggestion that you need to 
'see' the data being read?


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


Re: [Tutor] Name for this type of class?

2019-08-03 Thread David L Neil

NB am heading somewhat OT
NBB Python3+


On 3/08/19 12:38 PM, Alan Gauld via Tutor wrote:

On 03/08/2019 00:47, Malcolm Greene wrote:

Anyways, I'm looking for help coming up for the proper name for a class that 
collects the following type of telemetry data


Classes should never be named for their data but for their function.
What does this class do? What operations does it support.



This statement caused me to double-take. Do I misunderstand?


Quick survey of my PC's Projects directory:- sure-enough, few of my 
classNMs are verbs and convey little/no idea of function.
(to a degree one's expectations/experience lead to ideas of (what might 
be) included in its functionality)


They are almost exclusively nouns, eg Customer, Person, Organisation; 
rather than verbs/functions, eg Selling, Addressing, Billing.



[I'm not an OOP-native, and embraced OOP concepts as extensions to 
practices learned whilst programming with languages such as COBOL!]


Part of my introduction to OOP included the word "entity". A class was 
to represent an entity. An entity would be described (have attributes), 
just like a data-record; and it would have associated actions (methods 
or procedures) which acted on the entity's attributes. An entity was 
described as a 'thing' - no mention of an entity being an action, even 
though 'things' do 'stuff'.



Python is not particularly dogmatic or "pure" in its following of the 
OOP paradigm. Unlike some languages it does not insist on OOP and will 
support elements of both "procedural" and "functional" programming.


For this discussion then, a Wikipedia definition* 'will do'. What is 
included in OOP? [sometimes have 'translated' into Python terminology]


- objects
- data attributes
- methods
- inheritance
- instances and dynamic dispatch
- encapsulation [dotted notation]
- composition [will come back to this...]
- inheritance/delegation [ditto]
- polymorphism [sub-classing]

NB the article was no help with regard to the naming of objects/classes.


Simple comprehensions of inheritance and composition boil down to the 
phrases "is a" and "has a". The subjects and objects of such sentences 
will surely be a noun, rather than a verb?


Employee is a Person
Circle/Oval/Square/Triangle/Shape has a CentralPoint

Thus:

class Person(): ...

class Employee( Person ): ...


Python says "everything is an object" and makes little/no distinction 
between "type" and "class":


>>> class C: pass
...
>>> i = C()
>>> type( i )

>>> i.__class__

>>> type( C )

>>> C.__class__


So, what are Python's base types/objects/classes? eg int, str, list. Are 
these "data or function"?



Expand that outwards into the PSL. Same: numbers, decimals, fractions. 
However, does "math" convey more "function" than "data"?



There's current discussion about concerns of the 
age/relevance/maintenance of certain members within the PSL. So, let's 
look at a recent addition (it even features O-O in its description): 
"pathlib — Object-oriented filesystem paths". Function or data?


Let's argue that it is a library not a class/object per-se. Fine. 
However, the six (major) classes that library contains, eg Path, 
PosixPath, are all nouns!


At first I thought Inspect might be different, but (it is billed as a 
module of functions cf classes!) the classNMs are nouns (one is even 
called "Attribute"). The functions though, are indeed verbs, eg getargs().



Whither "Classes should never be named for their data but for their 
function."?



WebRef:
https://en.wikipedia.org/wiki/Object-oriented_programming

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


Re: [Tutor] Python code

2019-08-01 Thread David Rock
maybe a copy/paste of your terminal session so we can see the text of the steps 
you are actually performing will give use some clues.

—
David

> On Aug 1, 2019, at 18:22, David L Neil  wrote:
> 
> On 2/08/19 3:23 AM, Spencer Wannemacher wrote:
>> I'm new to python and I was trying to perform a simple one code. All that is 
>> included in the code is print(61). I save it as 61.py and change the 
>> directory before typing in python 61.py and I don't get an output. There is 
>> no error and the output is blank. Please let me know what I'm doing wrong. 
>> Thank you so much!
> 
> 
> What do you mean by "and change the directory before"?
> 
> Python will start searching for 61.py in the *current* directory!
> 
> -- 
> Regards =dn
> ___
> 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] Python code

2019-08-01 Thread David L Neil

On 2/08/19 3:23 AM, Spencer Wannemacher wrote:

I'm new to python and I was trying to perform a simple one code. All that is 
included in the code is print(61). I save it as 61.py and change the directory 
before typing in python 61.py and I don't get an output. There is no error and 
the output is blank. Please let me know what I'm doing wrong. Thank you so much!



What do you mean by "and change the directory before"?

Python will start searching for 61.py in the *current* directory!

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


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

2019-07-29 Thread David L Neil
On 30/07/19 8:36 AM, James Hartley wrote> On occasion, I put long URL's 
into comments/docstrings simply to document

where I found specific information.  However, to be a good disciple of
PEP8, anything which can't fit within 72 characters needs to be split
across multiple lines.  Since a number of you seem to be prolific Python
coders, what opinion do you have about splitting URL's in
comments/docstrings?



Assuming the use-case for including a URL-comment is to be able to 
locate the resource again, I'd leave it integral so that it is ready for 
a quick copy-paste. Otherwise you'd have to re-assemble the URL in the 
browser, from multiple comment-lines in the code...


In addition to PEP-8, please consider 'the Zen of Python' (practicality 
and purity).


python3 -c "import this"

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


Re: [Tutor] Fw: CSC1010H 4th assignment

2019-07-25 Thread David Rock

> On Jul 25, 2019, at 18:23, Alan Gauld via Tutor  wrote:
> 
> On 25/07/2019 20:04, Mahima Daya wrote:
>> hi there, please could you assist.
> 
> 
> Include any code, include the full text of any error messages.
> Tell us the OS and programming language (including versions)
> that you are using.
> 
> We will not do your homework for you. We expect to see your
> effort and a specific question that we can answer.


It also looks like you tried to attach some files that have code in them.   
Attachments won’t come through.  You will need to post any code in-line in the 
body of the email if we are going to be able to see it.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] A question about daunting KeyError

2019-07-24 Thread David L Neil

On 24/07/19 3:21 PM, TAISHI KAWAMURA wrote:

Hi tutors on Tutor,

I'm Taishi from Japan working in a data analytics team.

Currently, I'm trying to analyse purchase data of a fashion brand.
However, mysterious KeyErrors started occurring continuously when I was coding, 
and I haven't been able to get that fixed.

Although I asked this question on Stack Over Flow and another platform, I 
haven't got any solution.

I'm suspecting that Anaconda might keep raising the error, or simply there are 
bugs in the codes.
However, I can't be sure what the real cause is.

Do you think you can help me out?
If yes, please give me some assistance.



People here are happy to help, but you'll need to show us the relevant 
code and perhaps some data if that's possibly the source of the problem.


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


Re: [Tutor] Python Generator expressions

2019-07-23 Thread David L Neil

Hi Animesh,
Unfortunately the list server/email has removed the formatting from your 
sample, but no matter...



On 24/07/19 5:06 AM, Animesh Bhadra wrote:

# This code creates a generator and not a tuple comprehensions.
my_square =(num *num fornum inrange(11))
print(my_square) #  at 0x7f3c838c0ca8>
# We can iterate over the square generator like this.
try:
whileTrue:
print(next(my_square)) # Prints the value 0,1,4
exceptStopIterationasSI:
print("Stop Iteration")
# Another iteration
forx inmy_square:
print(x) # This prints nothing.
Does the generator exhausts its values when we run the iterator once?


Yes, it involves a "lazy" approach - the value is not calculated until 
the next() requests it. Whereas, a list comprehension calculates all its 
values at one time (and requires the storage space to hold them).


https://docs.python.org/3/reference/datamodel.html?highlight=generator - 
notice that there is a yield and a next facility, but when it terminates 
StopIteration is raised. There is no 'start again' command!



The Python docs are informative:
https://docs.python.org/3/reference/expressions.html?highlight=generator
https://docs.python.org/3/tutorial/classes.html?highlight=generator#generators


If you have an actual reason for running through a generator expression 
more than once, then consider return-ing it from a function/class (which 
will then be directly accessible to the for-loop/next method).




Lastly any specific reason for not having a tuple comprehensions?
Have checked this link, but could not understood the reason?
https://stackoverflow.com/questions/16940293/why-is-there-no-tuple-comprehension-in-python 


I don't know.

Have you understood the differences between lists and tuples - 
specifically "mutability" and "immutability"?


Let's take a list comprehension. If you 'unwind it', can you reproduce 
it as a multi-line for-loop? Yes, but before the loop the 'target' list 
must be defined/declared to be a list; and within the loop the list is 
appended with the 'generated' values.


Ok? (sorry, don't know if this will be new to you, or not)

Now, instead of a list, try using a tuple? How do you append() to a tuple?


Yes, many people have confused generator expressions - 
surrounded/"delimited" by parentheses, ie ( and ), with tuples.

However, try this little demonstration:


a, b = 1, 2
a

1

b

2

a, b = ( 1, 2 )
a

1

b

2

( a, b ) = ( 1, 2 )
a

1

b

2

type( a )



type( ( 1, 2 ) )



The principle here is known as "tuple unpacking". The two constants 
(right-hand side) are arranged as a tuple, as are the two variables (a 
and b/left-hand side), regardless of the presence/absence of the 
parentheses!


https://treyhunner.com/2018/03/tuple-unpacking-improves-python-code-readability/


Clarifying the difference/similarity in appearance between a generator 
expression and a tuple, it might help to think that it is the comma(s) 
which make it a tuple!



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


Re: [Tutor] Lengthy copyright notices?

2019-07-17 Thread David L Neil

On 18/07/19 10:08 AM, Alan Gauld via Tutor wrote:

On 17/07/2019 21:01, David L Neil wrote:


One line offers plenty of space to exert a claim (such can be very
simple and does not need to be lawyer-speak!) which should also refer to
the template's/package's external file or web-page.


Yes, I've seen that and if the lawyer speak is very verbose its
a good compromise.


Aside from possibly irritating 'the good guys', does such really 'stop'
a determined rapscallion?


Nothing will stop a determined rapscallion(love that phrase! ;-)
But it lets the good guys know who to contact at least if they
do need to.
For example, in my last book the publishers required me to
get a disclaimer from the author of some open source files
even though they clearly stated they could be used for any
purpose. Having the copyright notice with email link made
that easy.



Open source:
I've had the same - even for short "shazzam" or "drum-roll-please" 
sound-clips (which advertisers use all the time - who can name the 
pieces of music without saying "The lady loves Milk Tray" or "British 
Airways"?). That said, internationally there are many definitions and 
variations of "fair use" - and some jurisdictions don't even recognise 
such a thing! (I think the British law is quite 'tight').


I refused such a request?instruction, suggesting that the publishers AND 
their lawyers should enter 'the real world' and learn to understand 
(?and embrace) "open" concepts. In response to the inevitable grumpy 
push-back, I pointed-out that I am an author/content-producer and not 
legally-trained (not quite true, but they don't know that) so why on 
earth would they take MY advice...


Another one is 'images', which as a keen (amateur) photographer I 
readily understand from both 'sides'  - which simply meant that in a fit 
of pique at the aforementioned KYA-bureaucrats, I made a point of 
copyrighting EVERY training diagram/illustration/code-snippet that I 
produced and then REQUIRED 'the blighters' to license them from me...
(yet insisted that such be 'free' for trainees to download for their own 
use) Hah!



Closed source:
I was once contacted by someone who had hold of a small system I'd 
written way back in the mists-of-time. How, they ever obtained it, I 
can't imagine. The 'license' clearly said "no license", but he wanted to 
negotiate - which was great (although sadly, the client still "owned" 
the software, so no 'winning the lottery' for me then!)



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


Re: [Tutor] Lengthy copyright notices?

2019-07-17 Thread David L Neil

On 16/07/19 12:47 PM, Alan Gauld via Tutor wrote:

On 15/07/2019 23:34, Mats Wichmann wrote:


Rule #1: it's all opinion in the end...


Not quite. Different jurisdictions (remember, this list has an 
international membership!) have different understandings of (even, 
respect for) copyrights and permissions.


I live in a jurisdiction where whatever I write ("create") is mine - or 
my employer's. It is not even necessary to claim or "exert" copyright!


However, under the 'different strokes...' rule, I still include a 
copyright/license statement - if only to avoid misunderstandings in 
places that have other requirements and to at least 'make an effort' to 
communicate with those who have no such concepts - either in society, or 
(un)enshrined in law.




The common practice is that licence/copyright text is included as a
comment in the code, not in a docstring.


I'd second that opinion. I don't like losing the copyright stuff
to a separate file - too easy to get lost. But I certainly don't
want it in my help() output either.

A comment solves both for the downside of some initial scrolling
when reading or editing the file


Some disagreement here.
(but nothing worth fighting-over!)

One line offers plenty of space to exert a claim (such can be very 
simple and does not need to be lawyer-speak!) which should also refer to 
the template's/package's external file or web-page. The latter giving as 
much space for whatever you (or your legal representative(s) ) might 
want to say!


There can be quite an accumulation of 'paper-work' at the top of 
modules, which then has to be scrolled-through before we can get 
stuck-in to function/class/__main__ code - even with an editor's 
code-folding assistance.


Should it be left to the (far) end of the file? Would it lessen any 
legal implication?


Aside from possibly irritating 'the good guys', does such really 'stop' 
a determined rapscallion?

(...desperate student, lazy 'professional', corporate 'raider'...?)

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


Re: [Tutor] Reading .csv data vs. reading an array

2019-07-16 Thread David Rock

> On Jul 16, 2019, at 04:31, Alan Gauld via Tutor  wrote:
> 
> On 16/07/2019 09:59, Oscar Benjamin wrote:
> 
>>> All true, but sed - once you get used to it! - is easier IMHO
>>> and usually faster than Python - it's written in C...
>> 
>> I always think I'll like sed but whenever I actually try to use it I
>> just can't get the syntax together. 
> 
> 
> Id been using awk and sed for 15 years before I discovered
> Python (and perl) so they are kind of second nature.
> 
> If you can't settle with sed try awk, it's much simpler to
> use and almost as powerful but not as fast. I think awk is
> one of the most neglected of the *nix tools now that
> scripting languages like perl/python/ruby exist. But for
> line by line file processing it is superb.

The first O’Reilly book I ever purchased was “Sed & Awk”, and has been one of 
the most invaluable over the last 20 years.  While they are not the simplest 
tools to master, they are worth the effort; especially when you are trying to 
do inline “one-liners” to massage data or process large files.  That doesn’t 
mean it’s a requirement to know them, but it does get easier with practice.  
That said, if making a little python one-off filter to do what you need is 
faster (to write) and works (well enough), it comes down to what your time is 
worth.

— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Lengthy copyright notices?

2019-07-15 Thread David L Neil

On 16/07/19 10:34 AM, Mats Wichmann wrote:

On 7/15/19 3:25 PM, James Hartley wrote:

help(module_name) will place any text in the *first* module-level docstring
into the description section of the help page in Python 3.4.5.  Subsequent
docstrings found at module level are ignored.

I have been using this factoid for placement of a copyright & licensing
notice.  By placing a rather lengthy copyright & license in the code in a
the second module-level docstring, it is prominent within the code, but not
cluttering up help() output.

Two questions.  Is there a more standardized way of including long license
descriptions in code, & is it documented that any other module-level
docstring will be ignored in help() output?


Rule #1: it's all opinion in the end...

The common practice is that licence/copyright text is included as a
comment in the code, not in a docstring.


Packaging and project templating offer/recommend a separate file for 
'legal-stuff', eg licensing.


That said, I also include a one-liner at the top of every module, adding 
__license__ to several other similar labels/definitions.


One thing is for-sure: when calling for help or reminding myself of 
method signatures, I'd be greatly irritated by having to wade-through a 
flood of irrelevance.


On the other hand, if 'you' use my work...

Whether either/both of these pass for pythonic, I can't say.

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


Re: [Tutor] Fw: [docs] Python Embedding PyImport_ImportModule

2019-07-08 Thread David
On Tue, 9 Jul 2019 at 03:13, Alan Gauld via Tutor  wrote:
> On 08/07/2019 15:14, Ibarra, Jesse wrote:
> >
> > I cannot seem to figure this potential bug out.
>
> Neither can we since we cannot see any code.

I'm guessing this might be the original post:
https://mail.python.org/pipermail/docs/2019-June/041177.html

And while trying to find that one, I noticed that Jesse asked
another question on a similar topic:
https://mail.python.org/pipermail/docs/2019-June/041109.html

The questions are about calling Python functions from C code.
So asking the docs mailing list isn't likely to produce useful responses.

It appears that some good advice on what would be the best place to
ask these questions is needed, can anyone here provide that
information?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] pointers or references to variables or sub-sets of variables query.

2019-07-08 Thread David L Neil

On 8/07/19 10:54 AM, Alan Gauld via Tutor wrote:

On 07/07/2019 20:54, David L Neil wrote:


(However, some of us grew-up at a time when RAM was expensive and even
in our relaxed state, such 'costs' still impinge on our consciousness -


Indeed, my first computer was at the local university and had 64KB.
My second computer was a Sinclair ZX81 (Timex in the USA?) with 16K


Wow, go you! I could never cope with using analog tape decks as digital 
storage devices.


I've just decided to take a look at SBCs. I guess the 'splash' of news 
about the Raspberry Pi 4 contributed to that, and yet also contributes 
to my prevarication/procrastination...


My 'first' was at high school - an over-grown accounting machine. 
Paper-tape program-software, Teletype-style input and 'line-flow' 
output, and a magnetic drum for data-storage (and yes, I was computing 
physical locations in order to optimise response times - try that!)


At uni, we built Motorola D2 Kits - IIRC an 8-bit Motorola MC6800 
processor. Maybe a 6809 - or more likely, that was the one to which we 
aspired. Those who could 'afford' more hardware courses started building 
intelligent devices, eg embedding a microprocessor within a 'dumb 
terminal'/'green screen'. Intelligent devices, Internet of Things. Plus 
ça change!




My third, a CP/M machine with 64K and 256K RAM disk and dual
floppies - such luxury! :-)


Ah nostalgia.

One of my divertissements of that era (early-80s) was MP/M - a bus 
network of what were effectively single-board processors. It implemented 
my first 'computer lab' and we taught everything from COBOL to 
accounting software and word processing on it. Fantastic stuff in its day!
(interestingly, my SBC research last night, took me to a R.Pi device 
embodying exactly these concepts: 
https://www.notebookcheck.net/Raspberry-Pi-Combine-a-Raspberry-Pi-with-up-to-4-Raspberry-Pi-Zeros-for-less-than-US-50-with-the-Cluster-HAT.426998.0.html)




So I agree, it is hard to get out of that mode of thinking. But
today the minimum RAM is typically 4GB or more. My desktop
boxes all have 16GB and even my ancient Netbook has 4G.
My 20 year old iBook has 640M and even that is enough to
run Python with many thousands of data objects instantiated.


particularly temporary, DB tables into MySQL's MEMORY storage (and with
almost zero code-change/risk)!


Yes, I use SQLite's MEMORY facility reguilarly. Not for managing
high volumes but where I need flexible search capability.
A SQL SELECT statement is much more flexible and faster
than any Python search I could cobble together.


(appreciating that I have no difficulty moving from (Python) procedural
programming to (SQL) declarative, but many of our colleagues hate such,
and with a passion)


Yes, I've never quite understood why some programmers are
reluctant to use SQL. For complex structured data it is by far the
simplest approach and usually very efficient, especially with big
volumes. But simple searches on small datasets are easier (or as easy)
in native Python.


Agreed, but if we move beyond standard dict-s, into multi-keyed data 
structures - even with PSL and PyPI at our disposal, isn't it 
much-of-a-muchness to use MySQL/SQLite versus linked-lists or trees?

(or perhaps am showing too much bias from personal experience?)

The "reluctance" (good word!) is intriguing: (a) one more 
package/language to learn - yet such claimants might well have been the 
ones leaping into NoSQL a few years back; and (b) it is a different way 
of thinking - compare 'spaghetti' and monolithic code to "structured", 
procedural to OOP, OOP to 'functional'... I notice a similar likelihood 
to avoid HTML/CSS because of their 'declarative' approaches.


Hey, if you don't like the green ones, that's all the more Smarties/M&Ms 
for me!
(also, avoid the brown ones, they may be 'sheep pellets'/rabbit 
droppings...)

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


Re: [Tutor] pointers or references to variables or sub-sets of variables query.

2019-07-07 Thread David L Neil

On 8/07/19 2:48 AM, Alan Gauld via Tutor wrote:

On 07/07/2019 09:19, David L Neil wrote:

First-off, it has to be said that "100's of elements" suggests using an
RDBMS - particularly if 'age' (eg 23 and 99) is not the only likely
selection mechanism.


Multiple selection mechanisms might suggest an RDBMS but hundreds of
items is chickenfeed and an RDBMS would be overkill for such small
numbers, if volume was the only criteria. Millions of items would
certainly warrant such an approach but nowadays holding 10's of
thousands of items in memory is entirely reasonable.



Assuming plentiful RAM: agreed.
(However, some of us grew-up at a time when RAM was expensive and even 
in our relaxed state, such 'costs' still impinge on our consciousness - 
also, in another thread (here?Python list) we had someone frustrated 
about using an MS-Vista 'powered' machine and limited to 32-bits. We 
don't know the OP's circumstances. That said, loading an RDBMS, if (s)he 
doesn't already have one, is...)


As you point-out, with memory more-commonly available, I've obtained 
significant speed improvements by moving relatively small, and 
particularly temporary, DB tables into MySQL's MEMORY storage (and with 
almost zero code-change/risk)!

(so, it IS possible to teach old dogs new tricks)


The key justification for moving to RDBMS would be "not the only 
selection mechanism". Whereas a Python dictionary (hash) offers speedy 
access to data based upon a single index, it is hard to beat the bug- 
and time-saving facility of a DB managing multiple indices/indexes.
(appreciating that I have no difficulty moving from (Python) procedural 
programming to (SQL) declarative, but many of our colleagues hate such, 
and with a passion)



So, using the OP's data-example, and assuming the 'columns' to be 
perhaps employment_date, name, and age; respectively:


['2019-01-19','Fred Flintstone',23],
['2019-02-01','Scooby doo', 99]

- which Python (and pythonic - per OP's theme) structures and methods 
offer a relatively bug-unlikely solution to holding *multiple* indices 
into a base list (or other collection)?
(alternately, maybe we should wait for the OP, and allow opportunity to 
complete the homework first?)


(NB this may be veering OT, if the OP requires only the single access 
method, such as that illustrated earlier)

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


Re: [Tutor] pointers or references to variables or sub-sets of variables query.

2019-07-07 Thread David L Neil
First-off, it has to be said that "100's of elements" suggests using an 
RDBMS - particularly if 'age' (eg 23 and 99) is not the only likely 
selection mechanism.



On 7/07/19 2:39 PM, mhysnm1...@gmail.com wrote:

Hi all.
In C, you can use pointers to reference variables, arrays, ETC. In python, I
do not recall anything specifically that refers to such a capability. What I
want to do is:


Just because C has a construct does not imply that it does, nor even 
should, exist in another language! You're using Python because it is 
'better', right?


You are correct, Python does not use "pointers", and (a personal 
comment) I for one don't miss them and their many 'gotchas', eg 
out-by-one errors, preferring Python's constructs, eg for-each.


That said, Python's sequences (data structures, eg strings and lists) do 
offer indices, slicing, and striding. So, it is quite possible to 
(relatively) address the first item in a list as list_item[ 0 ]. You can 
read about these (and many other delights) in the docs...




I want to create different data structures such as dictionaries which
contain specific  list elements based upon specific keys. The original data
structure could look like:
Data = [
   ['2019-01-19','Fred Flintstone',23],
['2019-02-01','Scooby doo', 99]
]


Warning1: seem to be missing any identification of the "key"
Warning2: the intro text talked about "dictionaries" (the correct word) 
but the code-snippet is describing nested lists




The above structure does have 100's of elements. I want to reference
specific lists within the above structure. Using the only method I know how:

Category = {'under-50':[data[0]], 'over-50':[data[1]]}

If I understand things correctly with Python. The above will copy the value
into the list within the key. Not the memory address of the nested list I am
referencing. I am using a list within the key to permit multiple references
to different nested lists from the original data structure. The end result
of the structure for the dict could look like this (using example, not real
output)

Category['under-50'] = [ List1 pointer, List22 pointer, List52 pointer]

I hope the above makes sense. How can this be done?


I hope I've understood the description! One option would be to follow 
your line of thinking by turning the first data-structure into a 
dictionary (key-value) pairs, where the key is the character's age and 
the value is the inner list structure, previously outlined:


{
  23: ['2019-01-19','Fred Flintstone',23],
  99: ['2019-02-01','Scooby doo', 99]
}

Then it would be possible to maintain the two lists, each containing 
keys for the relevant dict-elements:


under_50 = [ 23 ]
over_50 = [ 99 ]

However, this would require that only one character be listed at a given 
age (dict keys must be unique), so another key might be a better choice!



Another data structure you might consider is a "linked list".

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


[Tutor] Python 3.7 Grids

2019-06-29 Thread David Merrick
Hi Looking for a way to use the determine the position of a card in a grid
using the mouse click event in Python. Code is attached. There are no
viruses.

Unfortunately using Tinkter grids / frames can't determine between the two
demo cards.

Any suggestions are welcome

-- 
Dave Merrick

TutorInvercargill

http://tutorinvercargill.co.nz

Daves Web Designs

Website http://www.daveswebdesigns.co.nz

Email merrick...@gmail.com

Ph   03 216 2053

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


[Tutor] Python 3.7 Grids

2019-06-28 Thread David Merrick
Hi Looking for a way to use the determine the position of a card in a grid
using the mouse click event in Python. Code is attached.

Unfortunately using Tinkter grids / frames can't determine between the two
demo cards.

The Relevant code is below

def showCardInitial(cardList):
cardsToPlay = []
length = len(cardList)

fileFaceDown = 'extracards/FACEDOWN.gif'
cardFaceDownCard = fileFaceDown.split('/')
cardFaceDownCard = cardFaceDownCard[1].split('.')[0]
photo = PhotoImage(file=fileFaceDown)
number = random.randrange(0,length)
fileFaceUp = cardList[number][2]
card = fileFaceUp.split('/')
card = card[1].split('.')[0]
w = Label(image=photo)
w.photo = photo
w.grid(row = 0,column = 0,padx = 10)

#print('cardListis ',cardList)

cardFile = cardList[1][2]
#print cardFile
photo = PhotoImage(file=cardFile)
cardToDisplay = Label(image=photo)
cardToDisplay.photo = photo
cardToDisplay.grid(row=0,column = 1,padx = 10)
#w.grid(row = row,column = count)
return

def determineCard():
global x
global y
print( "clicked at", x, y)
if(2 <= x and x <= 83) and (0 <= y and y <= 130):
print('Card One is Selected')
return

Any suggestions are welcome

-- 
Dave Merrick

TutorInvercargill

http://tutorinvercargill.co.nz

Daves Web Designs

Website http://www.daveswebdesigns.co.nz

Email merrick...@gmail.com

Ph   03 216 2053

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


[Tutor] Was: Basic Question about Visualization for enduser

2019-06-25 Thread David L Neil

On 26/06/19 4:56 AM, Alan Gauld via Tutor wrote:

On 25/06/2019 15:52, Sinardy Xing wrote:


My question is, how currently all of this great technology glue together
and as a final product for the enduser. Because I cant imagine that we
install Anaconda Jupyter Notebook at frontend for the enduser to use it,
and give end user bunch of *.py


You sort of can and there are tools for wrapping it all up in an
installable package. More commonly you create a desktop application
using the GUI toolkit of your choice and generate the graphical output
and display it yourself (using pyplot etc)



NB this is NOT intended as a discussion about the specifics of the OP's 
situation, nor of the OP personally!



This illustrates an interesting (at least to me?us) side-effect: in 
order to reduce "cognitive load" we often introduce training by using 
the most straight-forward or 'simple' tools. In this case Jupyter (which 
I think a most marvellous invention).


However, such illustrative devices are often not what is used in the 
'average' development department (assuming there is such a thing). Thus 
the training meets the knowledge-need (we hope) but not the requirements 
of practical application in the work-place.


On the other hand, should training in Python, and more specifically, the 
likes of matplotlib, involve any forlorn attempt at universal coverage 
of 'the programmer's tool-set'?



Your thoughts?
--
Regards =dn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] replacing a loop

2019-06-24 Thread David L Neil

Hi John,


On 25/06/19 4:15 AM, johnf wrote:

Hi folks,
I have the following loop (actually repeated many times )
def locChoices(self):
     locDS = self.eslocation.getDataSet()
     loc_Choices=['']
     locKeys=[0]
     for row in locDS:
     loc_Choices.append(row['facility'])
     locKeys.append(row['pkid'])
return loc_Choices,locKeys
where locDS is a tuple of dicts and a row is a dict.
Since I use a lot of similar loops to populate many dropdown controls I 
started investigating the use of list comprehensions.  But I can't 
figure out how to use them in this loop and wonder if it will improve 
the performance.  The data is not very big - about a thousand rows - 
give or take.

So what do you guys think?



Just because this morning I needed something to kick-start my sleepy 
brain into being able to "think"...



When most people think of 'multiples' in the context of 
list-comprehensions, they are talking about "nested-loops" - which are 
easy-enough (or at least, well-documented).


However, I've often wondered about the multiple being on the 'left-hand 
side' of the equation/expression, and whether that is even possible?


It is!
Thus:

python3
Python 3.6.8 (default, Mar 21 2019, 10:08:12)
[GCC 8.3.1 20190223 (Red Hat 8.3.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.

# build the data-structure (I hope)
>>> d1 = { 'pkid':1, 'facility':'here' }
>>> d2 = { 'pkid':2, 'facility':'there' }
>>> d3 = { 'pkid':3, 'facility':'nowhere' }
>>> locDS = ( d1, d2, d3 )

# let's check that the data-format is as-described?
>>> type( locDS )

>>> for row in locDS: print( row )
...
{'pkid': 1, 'facility': 'here'}
{'pkid': 2, 'facility': 'there'}
{'pkid': 3, 'facility': 'nowhere'}
# are we on the right track?

# this is the original code and approach
>>> loc_Choices = [ '' ]
>>> locKeys = [ 0 ]
>>> for row in locDS:
... loc_Choices.append( row[ 'facility' ] )
... locKeys.append( row[ 'pkid' ] )
...
# which (I hope) shows the existing (and desired) results
>>> print( loc_Choices )
['', 'here', 'there', 'nowhere']
>>> print( locKeys )
[0, 1, 2, 3]

# we can do the list inits, cf leaving it to the list comprehension
>>> loc_Choices = [ '' ]
>>> locKeys = [ 0 ]

# but how might we achieve this using a (single) list comprehension?
>>> [ [ loc_Choices.append( row[ 'facility' ] ), locKeys.append( row[ 
'pkid' ] ) ] for row in locDS ]

# in (proper) code, I'd format this over two lines (at least)

# correct me if I'm wrong, but these o/ps will
# 'disappear into the ether' when run within a pgm...
[[None, None], [None, None], [None, None]]

# leaving us with 'the proof of the pudding'
>>> print( loc_Choices )
['', 'here', 'there', 'nowhere']
>>> print( locKeys )
[0, 1, 2, 3]
>>>


Possible considerations:

1 some sample data would have eased the way/its lack leaves room for 
misinterpretation


2 a list comprehension normally executes more quickly than the 
traditional (long-form) multi-line code-block. However, it would be 
worth measuring that on your particular machine h/w and Py__version__. 
The other 'efficiency' is readability, but "elegance" is largely a 
matter of (personal) taste. So that ('mine-field') I leave to you...


3 taking the multi-line code-block and splitting it into TWO separate 
(consecutive) list comprehensions (one for loc_Choices and the other for 
locKeys) will most-likely be noticeably MORE 'expensive'


4 it is no matter if row/the locDS tuple dict-elements contain more 
key-value pairs


5 during code review, my colleagues would delight in criticising the 
choice of names such as locKeys - describing them as "JavaScript" (a 
'dirty word' to some), loc_Choices as contrary to PEP-8 ("flake", or 
whatever), etc - despite that I have a little 'set' of abbreviations 
with which I do the same, eg locNR. YMMV!


6 however, this simple boy will venture criticism of the inconsistency 
in using the underline word-separator, eg locKeys but loc_Choices. Even 
more potential for confusion: locChoices and loc_Choices!?


7 consider the data structures (outside of our view, here). Assuming 
there are more elements in each 'loc dict', might it be just as easy to 
leave the two pertinent elements 'there' and iterate over locDS when 
actually applied. Alternately, perhaps it might be better to construct a 
dictionary with the 'pkid's as keys and the 'facility' as values for 
direct-access application? Not knowing how the structure(s) will be 
utilised makes this pure speculation!


8 any?every time "similar loops" are found, re-factor to a function
(let's see if that philosophy kicks-off a retort or two...)

9 was it Knuth who described "premature optimisation" as "evil"? 
Certainly I'm a believer in 'make it work before you make it better'. 
So, (after all that!) what are we really achieving here? With such 
quantities, is it critical to 'save time'? If so, is this part of the 
code really the greatest time-sink?

(and we're back to t

Re: [Tutor] Hii

2019-06-20 Thread David Rock

> On Jun 20, 2019, at 03:28, Alan Gauld via Tutor  wrote:
> 
> On 19/06/2019 23:30, Antonio Arizpe wrote:
> 
>> i just need help with a script thats registers keystrikes and adds up all
>> the times youve struck a key and gives a number of the total amount of
>> times the keyboard was struck. nothing specific about characters. just how
>> many times it was struck in a real number.
> 
> It is possible, but it will likely be OS specific so you need to
> tell us which OS you are using/targeting.
> 
> Also any code that you've tried always helps along with any error
> messages. Also tell us about any 3rd party libraries you are using.


Also, what’s the use case?  Do you want this to be something that is only 
capturing keystrokes within the program itself, or do you mean to capture all 
keystrokes happening regardless of application focus (i.e., system-level key 
logging)?


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Follow-up on my removing elements from lists question.

2019-06-15 Thread David L Neil

On 15/06/19 9:35 PM, mhysnm1...@gmail.com wrote:

This is a follow-up on my previous question for removing elements. Below is
the code I am currently using. I am removing the elements at the end of the
outer loop. The data structure goes along this:
[
   ['123123',[2019-2-18', 'transaction text', 'amount'],
v  ['123123',[2019-2-18', 'transaction text', 'amount'],
   ['123123',[2019-2-18', 'transaction text', 'amount']
]
The 2nd column where the transaction text I am modifying the content and
using the end result of the built-up words as the string match as you will
see in the code. This is all working fine. The last loop in the code I am
trying to delete the elements in reverse order. This doesn't work. The
length of the list reduces by 1. When it should have reduced by 42. Is the
logic wrong? This is in Python 3.6 under windows 10.

unknown_transactions.sort(key=lambda x: x[2])
while True:
# re-initialise each time the current transaction text has been processed.
 for row in unknown_transactions:
 # remove common words from transactions which are not required. Such
as 'WITHDRAWAL' and 'DEPOSIT'.
 line = regex_transaction(row[2])
 # If the common words are not found, return a null and do not modify
the transaction description.



(from a very weak understanding of your previous question and the total 
code-base thus far)


Consideration nr1:
Write the code as comments first. Initially these will be at a fairly 
'high level'. These comments can later be turned into function/method 
names, and more comments added within those. Wash, rinse, and repeat. 
The idea is to help re-state your thinking into Python code, and to 
structure the code into functional units. Even skilled Python-coders 
often find that this helps to keep the use-case foremost in-mind.


Consideration nr2:
(assuming that the total data-volume is easily RAM-resident)
Rather than (appearing to) taking-in a 'group' of transactions and then 
select them according to ease/difficulty of 'translation', gradually 
removing/whittling the numbers down - hopefully to zero; why not 
consider adding another field to each record, which will note if it has 
already been processed (by whichever method) or conversely, which 
list-elements are yet to be completed? Thus each method of 
interpretation will first check the 'completed' field, and if not 
complete, apply the relevant analysis... Thus there is no concept of 
'removal' and no danger of 'losing' anything!


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


Re: [Tutor] Pickles and Shelves Concept

2019-06-07 Thread David Rock

> On Jun 7, 2019, at 12:42, Gursimran Maken  wrote:
> 
> Hi All,
> 
> I am not getting the concept of pickle and shelves in python, I mean what's
> the use of both the concepts, when to use them in code instead of using
> file read and write operations.
> 
> Could anyone please explain me the concepts.

The simplest way to look at it is they are ways to save python data objects to 
disk.  That way, you can have a dataset in an already-usable format for later 
on use.
By contrast, file read/write is usually for raw data in/out in an unprocessed 
form that is not readily usable in your program.

So you would see something like this:

read data from file 
store data in a dictionary
pickle and shelve the dictionary for later


Then later on…
grab the shelved pickle
access the dict that was shelved


If the data you are working with will always be fresh/new, the file reads is 
probably more usable.  The shelving of data is most useful for easier retrieval 
later so you don’t have to re-process the raw data every time.


— 
David Rock
da...@graniteweb.com




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


[Tutor] I'm having a small problem with my code

2019-05-23 Thread David Lifschitz
Hi.
I am currently working on a project for myself.
The code posted here is supposed to ask the user for an amount of numbers,
what those numbers are, and places those numbers in a list.
The next job of the code is to sort the list of numbers that were inputted
in an ascending fashion.
There is no error from the code, however, when I run the code the first
inputted number stays in its place and doesn't get sorted with the rest of
the numbers.
Any advice???

emptyList = []
nOFN = int(input("how many numbers do you want to sort: "))

for x in range(nOFN):
number1 = int(input("input number: "))
emptyList.append(number1)
firstElement = emptyList[0]
n = len(emptyList)
for j in range(1, n):
if emptyList[j-1] > emptyList[j]:
(emptyList[j-1], emptyList[j]) = (emptyList[j], emptyList[j-1])
print(emptyList)

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


Re: [Tutor] Looking for some direction

2019-05-18 Thread David L Neil

On 18/05/19 4:15 AM, Alan Gauld via Tutor wrote:

On 16/05/2019 04:17, Alex Kleider wrote:


Alt-Tab and the X cut 'n paste mechanism provides
enough integration between windows.


I tried this (Ubuntu 18.4) and Alt-Tab cycles between terminal and
browser but I can't make it cycle from one terminal to another. How do
you do that?


Sorry I've been busy, my mother passed away early this morning
and we've been with her the last few days.


Sympathies!



FWIW I just use Alt-Tab.
I'm on Linux Mint with Cinnamon.


Yes, and Ctrl-Tab to switch windows within an application (Cinnamon on 
Fedora)


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


Re: [Tutor] Looking for some direction

2019-05-18 Thread David L Neil

On 13/05/19 6:13 AM, Alan Gauld via Tutor wrote:

On 12/05/2019 10:15, David L Neil wrote:


Interestingly, I split these into two - my laziness for running/testing
is 'Save, Alt-Tab, Up-arrow, Enter' which would be 'ruined' by using the
cmdLN for anything else.


In a bash shell I use Ctr-R (for reverse search) and hit py to
run the last python command.

So for me its
Alt-Tab, Cmd-R, py

2 characters extra and I get to use the OS for whatever I like in
between... :-)



Good one!


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


Re: [Tutor] Looking for some direction

2019-05-12 Thread David L Neil

On 12/05/19 7:59 PM, Alan Gauld via Tutor wrote:

On 12/05/2019 00:24, David L Neil wrote:


"3 consoles": what is the purpose of each?
(my first reaction stemmed from many editors including a built-in console)


One for vim,


yes - that 'replaces' the window/app running an IDE/GUI-based editor.


*

One for the Python interpreter

*


One for an OS shell used for running/testing the app plus any
miscellaneous Unixy type things I need to do (sed/grep/awk/git etc).


Interestingly, I split these into two - my laziness for running/testing 
is 'Save, Alt-Tab, Up-arrow, Enter' which would be 'ruined' by using the 
cmdLN for anything else.


I might even 'raise' your bid, by adding a third terminal here - when 
needing to ssh into a VPS or other remote m/c.




I'll usually also have a web browser for reading
documentation if necessary, although that's mostly
done in the interpreter using dir()/help().


+1 (to make it 'worse', I have two web browsers open - plain-Firefox for 
'ordinary browsing' and the FF Development Edition for, well, 
development work. Yes, that habit probably came out of testing web stuff 
in multiple browsers, but now the DE is where I cruise the PSL docs, 
etc, as a de-facto separation-of-concerns in my mind.




Alt-Tab and the X cut 'n paste mechanism provides
enough integration between windows.


Very handy!


*
> One for the Python interpreter
*

I also do this, all-the-time. My youngest/new grad colleague observing 
this last week, was most puzzled. He felt it was 'double-handling' 
because "most ideas could/should be hashed-out in TDD design" cf 'code 
experimentation'. Will be interesting to see if he takes-on the idea, or 
continues to tease 'the old boy'...


(any comment if this is my failing to (fully) appreciate TDD philosophy?)


I'm using Gnome Terminal under Fedora (Linux). This allows multiple 
terminals in tabs (and thus Ctrl-Tab rapid-switching). However, it 
irritates me that whilst I can set "profiles" for particular purposes; 
there does not seem to be a way to save a 'session'. Thus each time 
Terminal re-starts, I have to re-build each terminal, manually.


(suggestions of other similar tools would be most welcome)


I'm also conscious of advising the OP on IDEs/editors: in that I am 
currently using Sublime Text but find the "build" mechanism quite alien 
to Python (HTML, CSS, JS, etc - but not Rust!). Similarly, I need to 
learn more about using ST's built-in terminal (preferably at full-size 
rather than a few lines at the bottom of the editing window). That might 
cut-down on one concurrent terminal...


(similarly, am open to suggestions for improving Python dev using ST)

Thanks for your feedback!
--
Regards =dn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Collating date data from a csv file

2019-05-12 Thread David L Neil

Hi Dave,

I also volunteer to do PAT safety testing during my "20% time". 
Clambering around Snowdonia as a boy, I eschewed* the Rheilffordd yr 
Wyddfa/SMR in favor of shanks' pony...


* OK, I was made to...! For the good of my soul???


On 9/05/19 8:04 AM, Dave Hill wrote:
I have a csv file which details the results of equipment tests, I carry 
out PAT testing as a volunteer at a heriatge railway in N. Wales. I want 
to extract how many items were tested on each test day. So far I have 
generated a List of test dates, but I am now stalled at how to 
efficiently count numbers tested on each date.


Can I have a list of tuples, where one item is the date and the second 
the count?


or is there a better construct?

Thanks in advance,

Dave

For completeness, I have listed below an extract from a target file, 
where the 10 digit number is the UNIX timestamp


182 1515001232
 Toaster 13 2000 1
183 1515001259    Contact Grill 13 2000 1
245 1515001367
 3G Cube Adaptor 13 0 1
246 1515001396     13A IEC Lead 5 0 1
248 1515001415
 Worktop Light 3 30 1
420 1515001440
 Fly killer 0 0 1
424 1515001461
 Dairy fridge 13 0 1
427 1513277293    Fire 13 0 1
429 1515001489
 Toaster Avanti 13 0 1



When you say "target file", is this coming off the tester via a link 
cable to your PC, or are you capturing by hand to a spreadsheet?


A tactic which many people 'miss' is that a workbook may contain 
multiple spreadsheets, and that the data on one spreadsheet may be 
auto-magically 'copied' onto another. Thus if the above is data coming 
off the PAT into one spreadsheet, I would immediately create a more 
meaningful sheet, 'for human consumption', which has column headings and 
converts (re-formats) the timestamp into a readable date (as suggested 
elsewhere), but is otherwise pretty-much a direct copy. We now have a 
sheet used for data capture/computer processing and something separate 
(and prettier) as a report/presentation for people.


From the spec, above, we are only interested in the date. Remember that 
considering the whole timestamp only makes life confusing. So convert 
them (only) to dates. These can be strings because Python compares 
strings as easily as dates!  The time component could be retained if 
sequence (of testing) might be important.


The sad reality is that a daily count could be accomplished in either 
LO-Writer or MS-Excel. No reason why you shouldn't use Python though.


(Assuming that the data appears in (forward or reverse) date sequence) 
Read-in the data sheet/CSV file, row-by-row, taking note of the date of 
the first data-entry, and starting to count from one. Then increment for 
each row where the date matches. When the dates don't match, report, 
reset the counter, and note the new date.


How will you lay-out and present this report? Another spreadsheet? 
Screen? Paper?


When you say "count numbers tested on each date", the above method will 
let you know a (single) daily total of tests-performed.


Did you (also) mean that you want to track how many of tests were 
performed within categories of devices, eg how many toasters on the one 
day? In which case, further design consideration is required, eg which 
devices fit into which category and how to match "Toaster" with "Toaster 
Avanti"...


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


Re: [Tutor] Looking for some direction

2019-05-12 Thread David L Neil

On 12/05/19 10:57 AM, Alan Gauld via Tutor wrote:

On 11/05/2019 19:59, Cranky Frankie wrote:

...

1) For the IDE I'm most comfortable with Netbeans/Java,


In that case use Netbeans. I use Netbeans myself when working
with Java and have played with its Python implementation and
its OK. Personally for serious Python work I just use vim
and 3 consoles, but that's a matter of taste. but you should
minimise the number of learning points and learning a new IDE
while also learning OOP (and a GUI framework?) is just
adding extra work.



"3 consoles": what is the purpose of each?
(my first reaction stemmed from many editors including a built-in console)

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


Re: [Tutor] self.name is calling the __set__ method of another class

2019-04-30 Thread David L Neil

Hi Arup,


On 30/04/19 5:55 AM, Arup Rakshit wrote:

class NonBlank:
 def __init__(self, storage_name):
 self.storage_name = storage_name
 
 def __set__(self, instance, value):

 if not isinstance(value, str):
 raise TypeError("%r must be of type 'str'" % self.storage_name)
 elif len(value) == 0:
 raise ValueError("%r must not be empty" % self.storage_name)
 instance.__dict__[self.storage_name] = value

class Customer:
 name = NonBlank('name')
 email = NonBlank('email')
 
 def __init__(self, name, email, fidelity=0):

 self.name = name
 self.email = email
 self.fidelity = fidelity
 
 def full_email(self):

 return '{0} <{1}>'.format(self.name, self.email)
 
if __name__ == '__main__':

 cus = Customer('Arup', 99)

Running this code throws an error:

Traceback (most recent call last):
   File 
"/Users/aruprakshit/python_playground/pycon2017/decorators_and_descriptors_decoded/customer.py",
 line 25, in 
 cus = Customer('Arup', 99)
   File 
"/Users/aruprakshit/python_playground/pycon2017/decorators_and_descriptors_decoded/customer.py",
 line 18, in __init__
 self.email = email
   File 
"/Users/aruprakshit/python_playground/pycon2017/decorators_and_descriptors_decoded/customer.py",
 line 7, in __set__
 raise TypeError("%r must be of type 'str'" % self.storage_name)
TypeError: 'email' must be of type 'str'
Process terminated with an exit code of 1

Now I am not getting how the __set__() method from NonBlank is being called 
inside the __init__() method. Looks like some magic is going on under the hood. 
Can anyone please explain this how self.name and self.email assignment is 
called the __set__ from NonBlank? What is the name of this concept?



Use the tools provided - follow the Traceback and interpret each step:-

>  cus = Customer('Arup', 99)

means: instantiate a Customer object, which takes us to

>  def __init__(self, name, email, fidelity=0):

where:
- name is set to a string: 'Arup'
- email is set to an *integer*: 99, and
- fidelity is set to become another integer with a value of 0
(in the first instance)

Ignoring name, we arrive at

>  self.email = email

which *appears to be* the creation of an integer(!) within the cus 
Customer instance.


However (the "magic") when the module was loaded into the Python 
interpreter self.email has already been defined as:


>  email = NonBlank('email')

which means that:

>  def __init__(self, storage_name):
>  self.storage_name = storage_name

made it (past tense!) an instance of the NonBlank object with a 
storage_name of email. (and with a __set__ method).


So, returning to the Trace, specifically:

>File 
"/Users/aruprakshit/python_playground/pycon2017/decorators_and_descriptors_decoded/customer.py", 
line 18, in __init__

>  self.email = email

what now happens is that the self.email instance of a NonBlank object 
receives the value passed-in as email (ie 99), and invokes the method:


>  def __set__(self, instance, value):

In due course, we find that 99 is not an acceptable value:

>  if not isinstance(value, str):
>  raise TypeError("%r must be of type 'str'" % 
self.storage_name)


and thus:

> TypeError: 'email' must be of type 'str'
> Process terminated with an exit code of 1

Crash!


Of course it is a 'toy example' - when you could plug two 'is it a 
string' checks straight into Customer, why not keep-it-simple and do 
just that? - without the added abstraction on top of an abstraction!


However, the author is illustrating a useful tool - should you find a 
situation where the 'checks' are much more involved or complex.



(NB in addition to, not an alternative to, the discussions Steven has 
offered)


Given previous conversations, I'm not surprised that you were mystified. 
The fact that I had to read it twice, and that the above explanation is 
NOT a 'straight line', indicates that there is probably a better (more 
simple) approach - and one which is MUCH more likely to be understood by 
our Python programming colleagues (possibly including our 'future selves'!)


As Steven explained, this is a complex environment where only those with 
a good understanding of the meta abstractions would even want to play 
(IMHO). Perhaps you would be better served by actually writing some 
Python applications, and with such experience under-your-belt, adding 
these 'advanced knowledge' ideas at some later time, if/when needed?)


Assuming use of a recent version of Python, you may like to solve this 
specific problem the same way you might in other programming languages:


<<<
typing — Support for type hints

New in version 3.5.

Note
The typing module has been included in the standard library on a 
provisional basis. New features might be added and API may change even 
between minor releases if deemed necessary by the core developers.


This module suppor

Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType

2019-04-28 Thread David
On Sun, 28 Apr 2019 at 02:57, Alan Gauld via Tutor  wrote:
> On 27/04/2019 01:22, David wrote:
>
> > It's no big deal, but I wonder why you wouldn't approve an address
> > the first time you see that it is being used for legitimate discussion.
>
> Time...
>
> It takes about 10 seconds to scan a message and click the button
> to pass it through (or reject it). It takes about 2-3 minutes to
> navigate to the admin screens, find the email address and change the
> moderation settings.
>
> So its only if I see the same address multiple times I feel the
> need to take the time to de-moderate it. If its only an occasional
> post its easier to just click Accept a few times.

Thanks for replying.

I'm sorry to hear it's such a headache. It sounds like the list
manager interface for that task is dreadful. It should be able to take
you straight to the configuration for the user who wrote the message.

Or even automatically change the moderation status of the user,
after one (or some configurable number) of their messages is
approved.

I think our timezones are out of sync. It seems to take around a day
for my messages to reach the list.

I guess I'll just remain as a reader, and only write if I have questions.
It's not a problem.

I'm grateful for the fact that it's a mailing list, not a forum. Thanks
for keeping it spam free.

I've written a question occasionally, but I usually manage to answer
them myself while writing them, before hitting send, so I didn't trouble
you with those :)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When you think to setup the __class__ of a module object to a subclass of ModuleType

2019-04-27 Thread David
On Sat, 27 Apr 2019 at 02:14, Alan Gauld via Tutor  wrote:
> On 26/04/2019 13:48, Arup Rakshit wrote:
>
> > BTW, one thing I would like to know about this list is that, everytime I
> > send an email I see it the in list after 2 hours approx. Is this for me
> > or everybody? I am just curious.
>
> Just for you! ...And every other new poster :-)
>
> It stays on moderation until the volume increases
> to the point where I get to recognise the email address.
> Around which point I get motivated to change the moderation
> setting. I've just done that for you so they should
> come through a little quicker now.

I've been reading here for years, and I take this opportunity
to give my sincere thanks to everyone who shares their
knowledge here.

I very occasionally respond to questions here, if I'm confident
of what I have to say.

I've always wondered why my responses often seemed to be
ignored by other participants. Now I know.

It's no big deal, but I wonder why you wouldn't approve an address
the first time you see that it is being used for legitimate discussion.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] [OT] Problem with auto-complete package installation in Atom [Was: Re: After virtualenv, how to use ide]

2019-03-24 Thread David L Neil

apologize in advance!  But that is okay.  I am not a professional nor
expert programmer myself.  Because of this, I recall agonizing over
the choice of code editor, or, possibly even worse, deciding whether
to use an IDE or editor.  This is a difficult decision about which
many wax poetic and express their opinions with great emotion.


But for professional programmers is a mere detail of very
little import. Its almost as irrelevant as the choice of
programming language. A professional uses the tools [sh]e
is given(or dictated). Sure we all have our favourites
(personally I favour a Unix-like OS using emacs/vim or Netbeans)
but we use what we must.


+1

The last time I had this conversation, in person, we were working on 
some HTML5 training and a colleague wanted to know how/why I edited 
something. I was using PyCharm, which he'd not seen before, and used a 
facility he had never seen, but which was also a little longer than one 
he would have used in his chosen-tool. Accordingly, he sought to 
'educate' me...


Having used many editors over the years, cough, mumble, decades; I 
suggest choosing one AND sticking with it for a long time, eg one year. 
Maybe as part of your new year celebrations you might choose another. In 
the meantime, I find it takes a while to stop trying to make 'this 
editor' look like the last one; and to learn how to best use the powers 
(and avoid the foibles) of this year's tool to actually improve one's 
productivity..


The fact remains, many of 'the big names' today offer many more 
facilities that one person will ever want to use, especially if working 
exclusively in one language! Perhaps the 80/20 rule applies? eg I've 
been using SublimeText for the last six+ months, and if I've more than 
scratched the surface, I'll be surprised. Even in my 
slightly-expanded-upon-the-vanilla installation, there are still 
lint-ing codes and sundry Python helps that bemuse me (and, obviously, 
I've simply ignored).




But in my time I've alo used
- CP/M and ed (or wordstar) {assembler, C, Pascal, Logo}
- OS/9 and scred, (assembler, C, BASIC}
- IBM MVS and ISPF, (COBOL, JCL, SQL}
- Windows and VS (or Borland IDE.) {ASM, VB, Pascal, C++, Java)
- DEC VAX/VMS and Edit/TPU {C, C++, DCL}


How about MP/M? OS/360 etc before MVS? Extra respect for avoiding the 
PC-DOS/MS-DOS fandango.


I find that the older I become, the longer it takes to re-wind all this 
nostalgia.


I can't even remember the name of the editor I used on my slide-rule PC!



Sorry for the rant but I get very depressed by some of
the discussion that happens on programming fora, especially
when there are so many genuinely interesting things to
talk about!


Agreed that it tends to be a newcomer's topic; and that one tends to use 
the same tools as the rest of the team; but it is an important 
consideration - I've never forgotten the first time I was asked (um, 
instructed) to change every instance of "xyz" in each source-code file 
in ... whereas today most professional-grade editors will achieve such 
in a single Find-Replace!
(am not sure if that can be achieved with today's Windows-NotePad, but 
equally, I'd struggle to find a good reason for such an action 'today' 
and in Python!)



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


Re: [Tutor] Merge a dictionary into a string

2019-03-17 Thread David L Neil

On 18/03/19 6:05 AM, Mats Wichmann wrote:

On 3/16/19 11:39 AM, Valerio Pachera wrote:

Consider this:
import collections
d = OrderedDict(a='hallo', b='world')
I wish to get a single string like this:
'a "hallo" b "world"'
Notice I wish the double quote to be part of the string.
In other words I want to wrap the value of a and b.



So the question that comes to mind is "why"?  I don't mean that in the
negative sense as in you don't want to do that, but your use case may
drive the choice of possible solutions.


Reading the OP, I immediately recognised the problem - meantime others 
had responded and the f'string' suggestion seemed most apropos.



Somewhat intrigued, and to answer the use-case question, I went looking 
in my personal collection of RDBMS routines and "snippets" (which have 
hardly been updated since Py2, excepting (IIRC) when MySQL's 
Connector-Python extended into dictionary-cursors).


The Connector will automatically delimit field/colNMs passed within a 
variable collection ('escaping' practice, highly recommended!) - a 
SELECT clause (for example). However, such automation is not applied to 
similar appearing in other clauses.


One of my helper-routines creates a comma-separated string by first 
surrounding columnNMs with back-ticks and then .join()ing. It's not 
rocket-surgery, but has been handy and import-ed many, many times.


YAGNI: me being me [puffs-out chest in a most unattractive fashion], one 
of the function's optional arguments offers a choice of delimiter. Can't 
recall ever using it 'elsewhere' though.



Thanks to the OP, and respondents making me think.
Have added to my >=v3.6 Backlog...
--
Regards =dn
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to get the weeks of a month

2019-03-04 Thread David Rock

> On Mar 4, 2019, at 16:30, Ben Finney  wrote:
> 
> john fabiani  writes:
> 
>> My understanding is - a week starts on Monday and ends on Sunday.
> 
> That's behaviour specific to a timezone. Which one are you using, and
> does your program know to consult the timezone data for when a week
> begins and ends?


That’s why I said "Which I’m sure is just a question of “defining the start of 
the week” properly.”  “Properly” is in the eye of the beholder.  As long as 
it’s performing the way you expect it to perform, you should be fine.  If all I 
saw was the output you had, I’d think something was broken because I think in 
terms of first day being Sunday, so maybe include a note in the output what the 
First day of the week is if that’s appropriate?


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] how to get the weeks of a month

2019-03-04 Thread David Rock

> On Mar 4, 2019, at 15:28, john fabiani  wrote:
> 
> I knew there was a simple why to get it done!  But where is it off my a day?
> 

comparing

$ cal
 March 2019
Su Mo Tu We Th Fr Sa
1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

to

import calendar as cal
cal.monthcalendar(2019,3)
[[0, 0, 0, 0, 1, 2, 3], [4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16,
17], [18, 19, 20, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30, 31]]

I see the first element of the array is
[0, 0, 0, 0, 1, 2, 3]

where I would have expected
[0, 0, 0, 0, 0, 1, 2]

Which I’m sure is just a question of “defining the start of the week” properly, 
but if you just took it as-is, Mar 1 would be Thursday, not Friday if you 
translated literally.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] how to get the weeks of a month

2019-03-04 Thread David Rock

> On Mar 4, 2019, at 13:19, Alan Gauld via Tutor  wrote:
> 
> On 04/03/2019 18:54, john fabiani wrote:
> 
>> I need to print out the weeks of the month - given any month and any year.
> 
> I'm not totally clear how you define a week.
> 
> EDIT: OK I see the comment at the end now.
> 
>> For example this month would have:
>> 
>> 3/1/2019 - 3/3/2019   # notice that this a short week
>> 3/4/2019 - 3/10/2019
>> 3/11/2019 - 3/17/2019
>> 3/18/2019 - 3/24/2019
>> 3/25/2019 - 3/31/2019  # also this can be a short week as in April 2019 
>> last week would be 4/29/2019 - 4/30-2019

What I think he’s shooting for is something similar to cal output

$ cal
 March 2019
Su Mo Tu We Th Fr Sa
1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31


> So what I think you want is to
> 
> start with the first day and print each day up to Sunday.
> Newline
> print the current date up to sunday
> newline
> repeat until you run out of days in the month.
> 
> 
>>>> import calendar as cal
>>>> cal.monthcalendar(2019,3)
> [[0, 0, 0, 0, 1, 2, 3], [4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16,
> 17], [18, 19, 20, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30, 31]]
>>>> 
> 
> That looks close to what you want?


That seems close, but off by a day?


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] systemd

2019-03-03 Thread David Rock

> On Mar 3, 2019, at 08:46, Dave Hill  wrote:
> 
> 
> I would like to take advantage of the 'restart' functionality, but I still 
> wish to have a method of exiting
> 
>   i.e. Restart=always
> 
> Is there a way in which I can have automatic restart but also have a way of 
> exiting?
> 

Maybe “always” is not what you want.  If you use “on-failure" instead, it will 
restart in all cases except when it cleanly exits.

From systemd.service manpage:
https://manpages.debian.org/jessie/systemd/systemd.service.5.en.html

"Setting this to on-failure is the recommended choice for long-running 
services, in order to increase reliability by attempting automatic recovery 
from errors. For services that shall be able to terminate on their own choice 
(and avoid immediate restarting), on-abnormal is an alternative choice.”

You will also see a table of what each setting does, to help you pick the best 
option for your needs.


You might also want to set the RestartSec to something other than zero.  If you 
set it to something like 20 seconds, it would also give you time to manually 
disable the service if you needed to.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] systemd

2019-03-03 Thread David Rock

> On Mar 3, 2019, at 14:59, Cameron Simpson  wrote:
> 
> On 03Mar2019 16:01, Alan Gauld  wrote:
>> On 03/03/2019 14:46, Dave Hill wrote:
>>>python3 /home/pi/Code/TestVideo#6.py CLIP0026.MP4 20 DEBUG
>> 
>> To be honest I'm surprised that works.
>> I'd expected bash to interpret the # as a comment delimiter!
>> But I tried it and it seems ok, you live and learn...
> 
> The octothorpe is only a comment marker at the start of a word.

While it works, it’s usually a bad idea to use non alphanumeric characters for 
filenames.  Naming it TestVideo6.py would be less prone to “weird things” 
happening down the road.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] schedulers

2019-02-28 Thread David Rock

> On Feb 28, 2019, at 17:23, Alan Gauld via Tutor  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
da...@graniteweb.com




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


Re: [Tutor] Recommended Resurce or strategy for beginning students

2019-02-20 Thread David
On Thu, 21 Feb 2019 at 14:35, Matthew Polack
 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.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Recommended Resurce or strategy for beginning students

2019-02-04 Thread David
On Tue, 5 Feb 2019 at 15:03, David  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  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  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@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Recommended Resurce or strategy for beginning students

2019-02-04 Thread David
On Tue, 22 Jan 2019 at 20:30, Matthew Polack
 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@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Implementation of list comparison operators

2019-01-17 Thread David Rock

> On Jan 17, 2019, at 16:13, Peter Otten <__pete...@web.de> wrote:
> 
> David Rock wrote:
> 
>> both a and nan are floats, so why does a == a work, but nan == nan
>> doesn’t?
> 
> It does "work", it's only produces a result you didn't expect ;) 
> Python just follows the standard here
> 
> https://en.wikipedia.org/wiki/IEEE_754
> https://en.wikipedia.org/wiki/NaN#Comparison_with_NaN
> 
> Also:
> 
> https://stackoverflow.com/questions/10034149/why-is-nan-not-equal-to-nan

Touché :-)


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Implementation of list comparison operators

2019-01-17 Thread David Rock

> On Jan 17, 2019, at 13:40, Peter Otten <__pete...@web.de> wrote:
> 
> David Rock wrote:
> 
>> 
>> Isn’t this a bit artificial, though?  The reason this is False is because
>> you explicitly tell it to return False when using equality.  That’s not
>> the same thing as using __eq__ without overriding it’s behavior
>> internally.
> 
> Sorry, I don't understand that argument. My point wasn't whether it's a good 
> idea to write objects that compare unequal to themselves -- such objects 
> already exist:
> 
>>>> nan = float("nan")
>>>> nan == nan
> False
> 
> I only warned that a list containing such an object does not meet the 
> intuitive expectation that list_a == list_b implies that all items in list_a 
> compare equal to the respective items in list_b.

It’s certainly a valid warning.  My confusion came from you using an arbitrary 
example of creating a class that breaks the logic in an override rather than 
one that already exists as a concrete example.  To me, your class example 
looked contrived.

What is it about the float(“nan”) example that makes this break?  

In [5]: nan = float("nan”)

In [6]: type(nan)
Out[6]: float

In [7]: nan == nan
Out[7]: False

In [8]: a = 1.1

In [9]: a ==a
Out[9]: True

In [10]: type(a)
Out[10]: float

both a and nan are floats, so why does a == a work, but nan == nan doesn’t?


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Implementation of list comparison operators

2019-01-17 Thread David Rock

> On Jan 17, 2019, at 12:39, Peter Otten <__pete...@web.de> wrote:
> 
> One obscure detail of the implementation of list equality:
> 
> In Python an object can be unequal to itself:
> 
>>>> class A:
> ... def __eq__(self, other): return False
> ... 
>>>> a = A()
>>>> a == a
> False

Isn’t this a bit artificial, though?  The reason this is False is because you 
explicitly tell it to return False when using equality.  That’s not the same 
thing as using __eq__ without overriding it’s behavior internally.


— 
David Rock
da...@graniteweb.com




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


[Tutor] function question

2019-01-05 Thread David Lynch
Hello,
I'm not sure if this is where I can find this sort of help but I am
struggling understanding functions. I have written a simple math code but I
feel like it could be improved if I were to use it in a function.

>From what I've read about functions I should be able to define a function
with 2 variables? And then I can add all of my code into that function by
indenting it. And then shouldn't I be able to
function(float(input("enter input: ")))
function(float(input("enter input 2: ")))
return(function)
??

Also, since it'll be in a function, when I type return(function) will it
rerun the code from the top?

I'd appreciate any advice!
David Lynch
print("Passive income from incentivised onboarding")
capital = float(input("Amount of capital raised: "))
amount_invested = float(input("Amount invested: "))
revenue = (capital * .75) / .2
total_royalty = (capital / 100) + 300
royalty_blocs_owned = amount_invested / 100
percentage_owned = royalty_blocs_owned / total_royalty
total_percent_owned = royalty_blocs_owned / total_royalty
passive_income = revenue * .1 * total_percent_owned
print("Assuming 75% of the capital raised is used for incentivised onboarding 
and there is no organic growth. Your passive income, by the time the onboarding 
funds are depleted, will be: ")
print(passive_income)
print("")
print("Passive income with estimated revenue")
capital = float(input("Amount of capital raised: "))
total_royalty = (capital / 100) + 300
amount_invested = float(input("Amount invested: "))
royalty_blocs_owned = amount_invested / 100
percentage_owned = royalty_blocs_owned / total_royalty
total_percent_owned = royalty_blocs_owned / total_royalty
revenue = float(input("Companies Revenue: "))
passive_income = revenue * .1 * total_percent_owned
print("Your passive income based on the revenue provided will be: ")
print(passive_income)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Defining variable arguments in a function in python

2018-12-31 Thread David Rock

> On Dec 30, 2018, at 18:39, Alan Gauld via Tutor  wrote:
> 
> On 30/12/2018 22:25, Avi Gross wrote:
> 
>> I admit I have not studied the charter for the group.
> 
> As moderator I feel the need to step in here because the
> charter is extremely apropos to that function and some
> clarification may be helpful.

I would like to add an observation…

The core complaint appears to be the length of the postings.  To my eye, Avi’s 
style of posting is extremely verbose, which is not necessarily a bad thing; 
but perhaps taking some time to distill the thoughts to make a concise, on 
topic, point would be helpful in this case.  When discussions appear to ramble 
at length in odd tangents, the helpfulness to the beginner is diluted and the 
original point of the discussion is lost.


— 
David Rock
da...@graniteweb.com




___
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-04 Thread David Rock

> On Dec 4, 2018, at 13:31, Avi Gross  wrote:
> 
> David,
> 
> What does it mean when someone says they cannot install a module? I can see 
> how a school assignment might require using only some limited set of 
> functionality. I note some installations add more than others or let you 
> designate optional components to include.

In the context of what the OP posted, I don’t think it actually matters if they 
mean “not allowed,” “not internet accessible,” or something else.  The 
statement is enough to move on in the conversation to try and be productive 
rather than belabor the point.

That said, hopefully we will get some feedback on the OS and ssh setup options.

— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] sftp using subprocess

2018-12-04 Thread David Rock

> On Dec 4, 2018, at 15:37, Alan Gauld via Tutor  wrote:
> 
> On 04/12/2018 18:30, David Rock wrote:
>> you MUST stop trying to use batch mode, because it will never work.
> 
> But you could presumably use interactive mode via Popen
> by taking control of the stdin/out pipes.
> 
> But then you are basically re writing expect!

Right.  and what’s worse, sftp doesn’t like here documents (by design, for 
fairly obvious reasons).  The best option (if it’s possible) really is setting 
up ssh key authentication.



— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] sftp using subprocess

2018-12-04 Thread David Rock

> On Dec 4, 2018, at 12:05, Asad  wrote:
> 
> Hi All ,
> 
>   I am not allowed to import pexcept   .Therefore only option I
> have is to implement a solution using the standard libraries in python .

I’m only suggesting it because it’s an easier way to interface with expect.  If 
you aren’t allowed to install it, then we’ll stop talking about it.

>However I am using subprocess.Popen for sftp I am unable to
> pass the password.
> 

You still are not understanding my point.  using sftp in batch mode CAN’T USE a 
password.  If you look at the manpage for sftp, batch mode prohibits it.

 -b batchfile
 Batch mode reads a series of commands from an input batchfile 
instead of stdin.
 Since it lacks user interaction it should be used in conjunction 
with non-inter‐
 active authentication.   <<—

“non-interactive authentication” means you must use an ssh key to authenticate 
instead of a password.  In other words, trying to figure out how to send a 
login to the subprocess is not the issue; even if you can, it won’t work 
because sftp *in batch mode* will not accept it.  If you _can’t_ set up an ssh 
key for this access, then you MUST stop trying to use batch mode, because it 
will never work.

>  Here I am unable to proceed , I am sure someone would have cracked this
> problem earlier if they can share the code

There is no code for this because it is not possible to do within the 
constraints you have proposed up to this point.

1. Can you set up ssh key passwordless authentication?
   if yes, then do it and what you have now will start working
   if no, then you can’t use sftp the way you are currently trying (the -b 
“batch mode”) and find a different solution (expect, here docs, etc).


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] sftp using subprocess

2018-12-04 Thread David Rock

> On Dec 4, 2018, at 02:41, Alan Gauld via Tutor  wrote:
> 
> On 04/12/2018 06:25, Asad wrote:
> 
>> Permission denied (keyboard-interactive,publickey,password).
>> Connection closed
>> 
>> Is there any other way to acheive this because I cannot import pexcept
>> module .
> 
> That looks like the problem that David already highlighted
> with sftp.

Yup.  So, back to my other question regarding ssh key access…

Do you have the ability to ssh to an account on the target system (i.e., use 
ssh to log in, not use sftp to grab a file)?
If you do, then the “easiest” solution is to create an ssh key and set up 
passwordless authentication.  If you do not, then maybe you can upload the key 
through some web service.  What is the actual target system to which you are 
trying to connect?  Is there an admin that can help configure ssh key-based 
access for you?

If you can’t set up key access, then you will need to automate sending the 
login information (hence the pexpect recommendation, since this is a python 
list, after all).  If you can’t install pexpect, you may have expect available 
(on what OS are you running your script?); but writing an expect script is 
starting to drift away from a python tutor list a bit.

If you are on linux, you may want to forego python altogether if you can’t get 
the ssh key access enabled and use a bash here document for automation.  
http://www.tldp.org/LDP/abs/html/here-docs.html

The disadvantage to this (and to using expect, for that matter) is plaintext 
storage of credentials on your system, but it’s pretty simple to use.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] sftp using subprocess

2018-12-03 Thread David Rock

> On Dec 3, 2018, at 16:01, Asad  wrote:
> 
> Hi All ,
> 
>I am looking for a solution to automate downloading file using sftp
> process using :
> 
> batch.txt :contains the following two lines
> cd 12345678
> get 12345678_1.zip
> 
> 
> import subprocess
> host="abc.com"
> user="sa"
> user_host="%s@%s" % (user, host)
> sftp_process = subprocess.Popen(['sftp', '-b', 'batch.txt', user_host],
> shell=False)
> 
> however it gives error even unable to provide password .

batch mode for sftp assumes you don’t need a password.  From the manage:

 -b batchfile
 Batch mode reads a series of commands from an input batchfile 
instead of stdin.
 Since it lacks user interaction it should be used in conjunction 
with non-inter‐
 active authentication.  

You would need to set up an ssh key with a null passphrase, or set up an 
ssh-agent in order for that to work.

Another option would be to use pexpect to automate console input


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Moving a conda environment to an off-line computer

2018-12-01 Thread David Rock

> On Dec 1, 2018, at 05:41, Henrique Castro  wrote:
> 
> Thank you guys, I'll try to contact the Conda community.
> Alan Gauld, good to know. I suggest that you try to spread the news to Fermi 
> Lab, CERN and other research centers.
> Sometimes when you need a specific setting it is just easier to pre-build 
> your distro than to repeat the same configuration hundreds of times.


So it sounds like you have local network connectivity, but do not have external 
internet access?  I ask, because I wonder how you are copying the data to the 
system from your computer that does have an internet connection.

Is there no internet access at all?  By that, I mean is there also no web proxy 
that can be used?

If a proxy exists, it may be possible to do something like define an http_proxy

os.environ['http_proxy’]=‘yourproxy:port'


It looks to me like you have a bigger problem than being able to “install 
conda.”  Even after conda is functioning, errors like :

Traceback (most recent call last):
 File "qm7_ANI.py", line 15, in 
   featurizer='BPSymmetryFunction', split='stratified', move_mean=False)
 File 
"/home/henrique/bin/anaconda3/envs/deepchem/lib/python3.6/site-packages/deepchem/molnet/load_function/qm7_datasets.py",
 line 50, in load_qm7_from_mat
   'http://deepchem.io.s3-website-us-west-1.amazonaws.com/datasets/qm7.mat'


tell me it is always going to want to use the internet to access datasets in 
AWS.  Unless you can use a web proxy, or possibly get a local mirror of the 
deepchem.io data on a university system you _can_ reach, this may not be 
possible to resolve.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] encoder decoder problem

2018-11-27 Thread David Rock

> On Nov 27, 2018, at 16:17, Alan Gauld via Tutor  wrote:
> 
> On 27/11/2018 21:04, Kamina Kamtarin wrote:
>> A De/Coder. Think back to 3rd grade when you passed notes to friends in
>> class. We can't let the teacher see what we're writing so we used a code.
>> A=1, B=2, C=3, etc. Your job is to create a program which does the
>> following:
>> 
>>   1. Presents the user with a menu choice: encode or decode
>>   2. Depending on what they chose you will either encode letters into
>>   numbers (seperated by dashes) or decode a series of numbers (separated by
>>   dashes) into letters.
>>   3. For example:
>>  - "How are you?" would encode as "8-15-23 1-18-5 25-15-21?"
>>  - "8-15-23 1-18-5 25-15-21" would decode as "How are you?"
> 
> Look at the builtin ord() and chr() functions.
> 
> For example ord('A') -> 65 and ord('a') -> 97
> 
> Similarly chr(97) -> 'a' and chr(65) -> ‘A'

I would also try to break up your requirements into smaller pieces.  For 
example, some things to solve:

How would you get input?
How would you break up a string into individual characters?
How would you break up an encoded string into individual numbers?
How would you put the characters/numbers back together for output?



Have you started writing any code? What have you tried so far?


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] A required question

2018-11-23 Thread David Rock

> On Nov 23, 2018, at 09:35, Alan Gauld via Tutor  wrote:
> 
> On 23/11/2018 05:34, Avi Gross wrote:
>> What I was thinking was the ability to do something like this:
>> 
>> import ReChoir as require
>> 
>> require.version(condition, before=True, after=False)
>> require.modules(module list, recursive=True)
>> require.os([“Eunuchs”, “Windblows”])
>> require.functionality(“print3”)
> 
> I can see the logic but suspect discussion of new features is
> probably the preserve of the main Python list. If you can get
> traction there somebody might actually go ahead and write one!

discussion of a “require” library probably isn’t necessary.  It’s pretty 
straightforward to include the logic using existing methods.

For the version of python, test against sys.version_info
For the modules, put your import calls in a try block and handle exceptions
For the OS version, test against os.name or sys.platform
The last one, “functionality,” is a bit vague.  Probably another candidate for 
a try block.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] origins bootstrapped.

2018-11-21 Thread David Rock

> On Nov 21, 2018, at 10:31, Avi Gross  wrote:
> 
> Is there room for a smaller core
> language that remains good for teaching purposes and that is small enough to
> fit in a Rasberry pi, while other versions are of industrial strength? Do we
> already sort of have some of that?

What comes stock on a Pi is more than sufficient (there’s plenty of room for 
“standard” python 2 and python 3).

Micropython (https://micropython.org/) fits that category nicely for micro 
controllers and Adafruit’s version of it, CircuitPython has a strong following 
https://www.adafruit.com/circuitpython

These have been great to allow people learn not only python, but how to 
physically interact with the world outside the computer.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Problem using termcolor and colorama

2018-11-15 Thread David Rock

> On Nov 15, 2018, at 07:18, John Blower  wrote:
> 
> I try to create colour text by using these two  modules , only returns the 
> colour code, no colour text.
> How to solve this problem.
> 
>>>> import termcolor
>>>> import colorama
>>>> colorama.init()
>>>> termcolor.cprint('Hello World','red')
> [31mHello World[0m

I don’t know what those modules are, but based on the output, where you use 
them will matter.
Those are the correct ESC codes to print something in red, but your terminal 
needs to support displaying the colors.

If you are trying this in the python interpreter, try making a basic test 
script and run it instead to see if it works outside the interpreter 
environment.

I assume you are on Windows, too.  What OS and what version of Python are you 
using?

— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] GPA calculator

2018-11-14 Thread David Rock

> On Nov 14, 2018, at 14:50, Cameron Simpson  wrote:
> 
> On 14Nov2018 13:51, Whitney Eichelberger  
> wrote:
>> I need help creating a weighted GPA calculator. I attempted to create one 
>> but I was unable to incorporate different leveled classes (College Prep, 
>> Honors, and AP). How can I incorporate those leveled classes into the 
>> calculator in order to get a final GPA
> 
> Please always include your code, and some sample data and the output, and 
> explain what isn't as you want it.
> 
> Past that into your message - this list does not do attachments.
> 
> Also, please explain terms like "GPA". I imagine it may mean "Grade Point 
> Average", but really it might mean almost anything.

One assumes you are talking about school, but regardless, you need to be able 
to explain your goal before you can code it.

For example, do you know how to manually calculate a weighted GPA?  Do you know 
how your school does the weighting (.5 point, full point, etc)?
This link has a good overview of the process/steps you probably need to work 
through.

https://www.wikihow.com/Calculate-Your-Weighted-GPA

let us know what you have tried so far and where you get stuck, and we will be 
better able to help.

— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Unable to get the gateway IP of wlan interface using python code

2018-11-12 Thread David Rock

> On Nov 12, 2018, at 13:37, srinivasan  wrote:
> 
> Dear Python Experts,
> 
> *First method:*
> 
> I need to get the IP address basically the gateway IP in my setup I get it
> as "192.168.178.1" when I run the below standalone python code.

Is there a requirement to use only what comes in the standard libraries, or can 
you use things from pypi?
Getting interface details is exactly why netifaces was created

https://pypi.org/project/netifaces/

damocles:src drock$ python3
Python 3.7.0 (default, Oct 28 2018, 22:17:08) 
[Clang 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import netifaces
>>> gws = netifaces.gateways()
>>> gws
{'default': {2: ('192.168.69.1', 'en0')}, 2: [('192.168.69.1', 'en0', True)]}
>>> gws['default']
{2: ('192.168.69.1', 'en0’)}

— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Request for help with code

2018-11-06 Thread David Rock
* Mats Wichmann  [2018-11-06 16:54]:
> 
> there must be some solution... guys, do you know of any alternate way to
> send a message to the list if a mail client isn't cooperating? or do we
> have instructions for beating gmail into submission?  Obviously gmail is
> a key part of the modern infrastructure despite its (ahem) misfeatures.

Looking at the mail headers, I'm seeing

Content-Type: text/plain; charset="us-ascii"  

But that is probably just what the final format that gets sent to the list ends
up with.  We might have some suggestions if we know for sure what email client
is being used.  A gmail.com address is not a guarantee that gmail within a
browser is what's being used (I use mutt to send mail through my gmail.com
account all the time).

What's the MUA (mail client)?
If it's in a browser, what browser is being used?

Off the top, I would suggest looking for a "plain text" selection on a dropdown.

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


Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-06 Thread David Rock
> 
> *def get_fstype_of_mounted_partition(self, fs):*
>"""
>Get the filesystem type of the mounted partition.
> 
>:partition_name : Partition path as string (e.g. /dev/mmcblk0p1)
>:return: filesystem type as string or None if not found
>"""
> 
> *cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
>*return self._helper.execute_cmd_output_string(cmd)*
> 
> 
> 
> root:~/qa/test_library# python3 sd.py
>  File "sd.py", line 99
> *cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
> * ^*
> *SyntaxError: can't assign to literal*
> root:~/qa/test_library#
> 

looking at
 cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*

It’s probably because you have “ characters that are inside “ characters and it 
can’t tell where the string ends. It looks like you are trying to do

cmd = "blkid -o export %s | grep 'TYPE' | cut -d”  =  " -f3" % (fs)*

which doesn’t make sense.  Try using triple quotes instead so it’s clear what 
string you are trying to use.

cmd = “""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3”"" % (fs)


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Best solution to modifying code within a distributed library

2018-09-19 Thread David Rock

> On Sep 19, 2018, at 18:51, Mats Wichmann  wrote:
> 
> On 09/19/2018 03:47 PM, Chip Wachob wrote:
>> Hello once again,
>> 
>> I would like to comment out line 340 (self.mpsse_write_gpio()) to
>> prove that this is what is causing glitches that I do not want.
>> 
> 
> You'll want to get the original and work from there. You already know
> where it is - you've included the github link.
> 

There’s another option… Ask Adafruit directly.

They are amazingly helpful and would be more than happy to hear if there’s a 
potential issue with their code.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] [OT] Re: Need help in learning Python

2018-08-13 Thread David Rock

> On Aug 13, 2018, at 13:49, Carlos Monge  wrote:
> 
> Ok, this may have been a fatal error on my part but I decided to start
> fresh and uninstalled my old version of Python. Now when I try to reinstall
> I get these error messages..

Have you tried rebooting?  Maybe you have some lingering cruft in memory.

— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Need help in learning Python

2018-08-12 Thread David Rock

> On Aug 11, 2018, at 20:34, James Gledhill via Tutor  wrote:
> 
> I know this is a python focused mail group, but you asked about Linux so I'll 
> answer. :-)
> I would strongly recommend that you skip Kali Linux for the next little 
> while. Every tool available on Kali can be obtained on Ubuntu. Kali is not 
> beginner friendly, and while the community is great, honestly it's not the 
> most beginner friendly either. If you don't feel comfortable installing the 
> tools you need for your course on Ubuntu, Kali is going to give you a 
> splitting headache. Stick with Ubuntu, learn python, install the tools as you 
> need them and you will learn so much more.
> 

I will second that, and add if you really NEED Kali, it’s possible to run it as 
a Live image (eg, off a USB stick); you don’t need to install it to use it.
https://docs.kali.org/downloading/kali-linux-live-usb-install

Doing it this way, you get better flexibility with having Kali without 
[potentially] destroying what’s currently on your system through trying to set 
up a multi-boot environment.

Bite of smaller chunks instead of trying to learn everything at once and you 
will be a lot happier.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Need help combining elements of a list of lists

2018-07-10 Thread David Rock

> On Jul 10, 2018, at 22:04, David Rock  wrote:
> 
>> On Jul 10, 2018, at 21:46, Jim  wrote:
>> 
>> ltrs = [['A', 'B'], ['C', 'D', 'E'], ['F', 'G', 'H', 'I']]
> 
> A fairly straightforward way is to use nested loops:
> 
>>>> for l in ltrs[0]:
> ...   for j in ltrs[1]:
> ... for k in ltrs[2]:
> ...   print l,j,k
> 

Sorry, let’s try to make that a little cleaner-looking

for x in ltrs[0]:
  for y in ltrs[1]:
for z in ltrs[2]:
  print x,y,z


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Need help combining elements of a list of lists

2018-07-10 Thread David Rock

> On Jul 10, 2018, at 21:46, Jim  wrote:
> 
> ltrs = [['A', 'B'], ['C', 'D', 'E'], ['F', 'G', 'H', 'I']]

A fairly straightforward way is to use nested loops:

>>> for l in ltrs[0]:
...   for j in ltrs[1]:
... for k in ltrs[2]:
...   print l,j,k

A C F
A C G
A C H
A C I
A D F
A D G
A D H
A D I
A E F
A E G
A E H
A E I
B C F
B C G
B C H
B C I
B D F
B D G
B D H
B D I
B E F
B E G
B E H
B E I


Not the most elegant, but probably the easiest to follow.

— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] CSV Read

2018-06-30 Thread David Rock

> On Jun 30, 2018, at 02:01, Peter Otten <__pete...@web.de> wrote:
> 
> 
> Rather than forcing both blocks into the same data structure I would read 
> the header with the "key: value" lines into a separate object.
> 
> If the header and the X,Y pairs are separated by an empty line read until 
> that and then feed the file object to pandas.read_csv() to read those pairs:

Ultimately, everything presented so far is conjecture without getting 
clarification from the original poster on what they actually need and what the 
dataset looks like.  Does every file look the same? is it always a header and 
data separated by empty lines?

Hopefully we will get some feedback.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Question about a python finction

2018-05-11 Thread David Rock

> On May 9, 2018, at 07:14, kevin hulshof  wrote:
> 
> Hello,
> 
> Is there a function that allows you to grab the numbers between two numbers?
> 
> Eg. If you input the numbers 1 and 4
> To make a list like this [1,2,3,4]

One option is range

range(1,5)

>>> range(1,5)
[1, 2, 3, 4]

https://docs.python.org/2/library/functions.html#range

— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Sam Kahraman Campus Middle School Advice

2018-04-27 Thread David Wolfe
Sam;

Were I you, I would look for a local MeetUp that deals with Python, attend
one of their meetings, and talk to one of the folks there.  I've learned a
lot from the MeetUp in my area, and there are Python experts in several
fields usually in attendance.  They'll be able to help you with your
questions and interview, as well as to give you pointers on next steps in
learning and proficiency.

Good Luck,
David

On Thu, Apr 26, 2018 at 4:00 PM, Kahraman, Sam K. <
skahra...@cherrycreekschools.org> wrote:

> Hello,
>
>  I am a 8th grade student at Campus Middle School. We have a project on
> coding and I need a expert to interview. Currently I'm learning Python and
> thought I should ask someone who works their to Interview. To contact me
> and ask any questions my email is skahra...@cherrycreekschools.org.
>
> ___
> 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] Beginner Level Projects

2018-04-19 Thread David Rock

> On Apr 18, 2018, at 20:34, Joshua Nghe  wrote:
> 
> Hi,
> 
> This is Joshua N from Campus Middle School in CO. Our science class is 
> collectively participating in a project that consumes 20% of our classtime 
> every week. For my project, I chose to learn Python, and create something 
> from what I learned. I currently have around 10 hours spent learning Python, 
> and predict to have at least 20 by the time I start my project. According to 
> my level of experience, what would be an interesting project that would 
> exihbit all that I've learned.

Start by thinking about problems you would like to solve.  Is there something 
that you wish you could do easier?

Are you in 6th grade, or 8th?  What other kinds of classes are you in where 
python might help?  For example, have you done any graphing in a Math class?  
making a graph of a function using text is a pretty complete exercise that 
might help you visualize problems (and help with you other classes, too).

Are you interested in making things move or turning stuff on/off?  Using python 
on a Raspberry Pi is a great way to start with using a computer to control the 
“real world.”


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] PLEASE HELP

2018-04-13 Thread David Rock

> On Apr 13, 2018, at 09:24, Neil Cerutti  wrote:
> 
> On 2018-04-12, Scharrer, Brianna  wrote:
>> Applications of basic language syntax
>> 
>> Date/time string parsing
>> 
>> Time stamps on data are often recorded in the standard ISO date
>> and time format as shown below
>> 1999-02-14T21:02:37 > 9:02pm on February 14, 1999
>> 
>> Write code that when given a datetime string and outputs a
>> human readable version exactly in the format specified below.
> 
> I disagree that the first version isn't human readable. It is
> both human readable and stores the date/time in lexicographic
> order, which is extremly useful for both humans and machines.

Don’t nitpick the definition of “human readable;” it isn’t relevant to the 
assignment and just serves to confuse the student.  Using the phrase “human 
readable” is just a poor choice for describing the assignment parameters: 
changing from one format to another (ISO -> “standard English” (for lack of a 
better description of the target format).  That’s the only thing that matters 
in this context.

For the assignment, think about the following:

How to separate the date from the time
How to separate the -MM-DD into discreet variables
How to convert the digit month into a Full name (e.g, convert 2 -> February)
How to convert a 24-hour time into a 12-hour am/pm time
How to print the bits into a specific format

Tackle each part separately, and it should be fairly straightforward.  Look up 
methods for parsing formatted strings as a place to start.

— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Help with a task

2018-04-12 Thread David Rock

> On Apr 12, 2018, at 05:54, Aditya Mukherjee  
> wrote:
> 
> Helping me getting started and just understanding what I actually need to
> do would be vastly helpful, as I've heard from other students that they
> have over 200 lines. :)
> 
> I've attached the premise of what the task is asking for, due in 2 days.

This list does not support attachments, so we can’t see what your requirements 
are.

Also, we won’t do the work for you, so you need to help us help you by telling 
us what you have tried so far.  We can give guidance, but only if we can see 
where you have tried to go.

I would also recommend talking to your classmates that are having more success 
as a first attempt to get some direction.  2 days is not much time for a 
mailing list to help you understand an unknown assignment.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] pythonic

2018-04-02 Thread David Rock

> On Mar 30, 2018, at 04:15, George Fischhof  wrote:
> 
> 2.)
> argparse
> 
> it is good, but you can write more Pythonic code using click
> https://pypi.python.org/pypi/click/
> it is also Pythonic to use / know the Python ecosystem (the packages)

It’s just as (if not more) pythonic to use the standard libraries. It’s very 
common in a professional environment to not have access to outside (i.e., 
internet) resources.  I wouldn’t venture into Pypi unless there’s something you 
can’t do well with what’s already provided by default.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Tutor Digest, Vol 169, Issue 20

2018-03-26 Thread David Brown
Thanks Joel. That got me going in the right direction. I ended up using a
"while true" statement. The code below seems to work now. It will accept
any key and not just "Y". Haven't gotten that far with it yet.

# Fortune Cookie
# Displays Random Fortune
# Allows user to see repeated fortunes up to 5

import random

# Generate one of five fortunes randomly

print("\t\t~~Cyber Fortune Cookie~~")

# Set the initial values
prefix = "Your fortune is: "
count = 0
while True:
input("  \n\tHit ENTER to see your fortune")
number = random.randint (1,6)
if number == 1:
print("\n", prefix,"When much wine goes in very bad things come
out.")
count += 1
elif number == 2:
print("\n", prefix,"You will be hungry in one hour.")
count += 1
elif number == 3:
print("\n", prefix,"Order another egg roll and you will be happy.")
count += 1
elif number == 4:
print("\n", prefix,"You will love the spicy ginger shrimp.")
count += 1
elif number == 5:
print("\n", prefix,"You will meet an old friend soon.")
count += 1
if count > 5:
print("\nNo more fortunes for you")
break
if count <5:
input("\n\nEnter 'Y' if you would like another fortune: ")
continue


On Mon, Mar 26, 2018 at 12:00 PM,  wrote:

> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-requ...@python.org
>
> You can reach the person managing the list at
> tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
> Today's Topics:
>
>1. Problems with Looping (David Brown)
>2. Re: Problems with Looping (Joel Goldstick)
>
>
> -- Forwarded message --
> From: David Brown 
> To: tutor@python.org
> Cc:
> Bcc:
> Date: Mon, 26 Mar 2018 09:45:19 -0400
> Subject: [Tutor] Problems with Looping
> Hello all,
>
> I am trying to teach myself Python by working through a book on Safari
> Books. One of the examples in the chapter on Loops states:
>
> *"Write a program that simulates a fortune cookie. The program should
> display one of five unique fortunes, at random, each time it’s run."*
>
> The program below does that just fine. However, I wanted to take it to the
> next level and allow the user to select another fortune if desired. I've
> tried a variety of "While" loops, but they end up with infinite loops, or
> not generating a fortune. I've tried to add continue, after each "if, elif"
> statement, but I usually get an error stating that it's not in the correct
> place in the loop.
>
> Can any one give me a hint? I'd like to figure it out on my own, but am
> stuck.
>
> This is NOT for a graded assignment. It is purely for self study.
>
> # Fortune Cookie
> # Displays Random Fortune
>
> import random
>
> # Generate one of five fortunes randomly
>
> print("\t\tCyber Fortune Cookie")
> input(" \n\tHit ENTER to see your fortune")
>
> # Set the initial values
> prefix = "Your fortune is: "
> number = random.randrange(5) + 1
>
> if number == 1:
> print("\n", prefix,"When much wine goes in very bad things come out.")
>
> elif number == 2:
> print("\n", prefix,"You will be hungry in one hour.")
>
> elif number == 3:
> print("\n", prefix,"Order another egg roll and you will be happy.")
>
> elif number == 4:
> print("\n", prefix,"You will love the spicy shrimp and garlic.")
>
> elif number == 5:
> print("\n", prefix,"You will meet an old friend soon.")
>
> #input("\n\nPress the enter key to get another fortune.")
> --
> *David*
>
>
>
> -- Forwarded message --
> From: Joel Goldstick 
> To:
> Cc: tutor@python.org
> Bcc:
> Date: Mon, 26 Mar 2018 09:56:30 -0400
> Subject: Re: [Tutor] Problems with Looping
> On Mon, Mar 26, 2018 at 9:45 AM, David Brown 
> wrote:
> > Hello all,
> >
> > I am trying to teach myself Python by working through a book on Safari
> > Books. One of the examples in the chapter on Loops states:
> >
> > *"Write a program that simulates a fortune cookie. The program should

[Tutor] Problems with Looping

2018-03-26 Thread David Brown
Hello all,

I am trying to teach myself Python by working through a book on Safari
Books. One of the examples in the chapter on Loops states:

*"Write a program that simulates a fortune cookie. The program should
display one of five unique fortunes, at random, each time it’s run."*

The program below does that just fine. However, I wanted to take it to the
next level and allow the user to select another fortune if desired. I've
tried a variety of "While" loops, but they end up with infinite loops, or
not generating a fortune. I've tried to add continue, after each "if, elif"
statement, but I usually get an error stating that it's not in the correct
place in the loop.

Can any one give me a hint? I'd like to figure it out on my own, but am
stuck.

This is NOT for a graded assignment. It is purely for self study.

# Fortune Cookie
# Displays Random Fortune

import random

# Generate one of five fortunes randomly

print("\t\tCyber Fortune Cookie")
input(" \n\tHit ENTER to see your fortune")

# Set the initial values
prefix = "Your fortune is: "
number = random.randrange(5) + 1

if number == 1:
print("\n", prefix,"When much wine goes in very bad things come out.")

elif number == 2:
print("\n", prefix,"You will be hungry in one hour.")

elif number == 3:
print("\n", prefix,"Order another egg roll and you will be happy.")

elif number == 4:
print("\n", prefix,"You will love the spicy shrimp and garlic.")

elif number == 5:
print("\n", prefix,"You will meet an old friend soon.")

#input("\n\nPress the enter key to get another fortune.")
-- 
*David*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 169, Issue 17

2018-03-23 Thread David Holland via Tutor
Thank you all for the replies.  I did not make myself clear.I don't want to 
access the database directly as that would be unsupported by Oracle.I mean 
Oracle forms which using in Oracle financials, and something that acts like a 
dumb clerk that takes information from a spreadsheet and puts it in the 
form.Similar to something that you use to put information into a website (I 
don't know how to do that either sadly).
 

On Friday, 23 March 2018, 16:00:13 GMT,  wrote:  
 
 Send Tutor mailing list submissions to
    tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
    https://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
    tutor-requ...@python.org

You can reach the person managing the list at
    tutor-ow...@python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tutor digest..."


Today's Topics:

  1. Matrix help (Connie Callaghan)
  2. Re: Oracle forms (Peter Otten)
  3. Re: Oracle forms (Mats Wichmann)
  4. Re: Oracle forms (Alan Gauld)
  5. Re: Matrix help (Peter Otten)
  6. Re: Matrix help (Alan Gauld)
  7. Matrix Multiplication user entries (Noor Alghanem)


--

Message: 1
Date: Thu, 22 Mar 2018 11:35:05 +
From: Connie Callaghan 
To: "tutor@python.org" 
Subject: [Tutor] Matrix help
Message-ID: <5ab394ed.177c1c0a.ac374.f...@mx.google.com>
Content-Type: text/plain; charset="utf-8"

Hi, 
I was just looking help for a matrix that I am building, it needs to look like 
this 
1, 0, 0, ...,0
A,b,c,0,...,0
0,a,b,c,...,0
0,0,a,b,c,..0
0,0,0,a,b,c,...,0
0,0,0,0...0, 1 

It has n rows and columns and the first and last line has to have 1s at the 
corners as shown, and a,b,c going diagonal and 0?s everywhere else, I am really 
struggling and it would be a great help to even be shown how to begin, 

Thanks 
Connie 




---
This email has been checked for viruses by AVG.
http://www.avg.com


--

Message: 2
Date: Thu, 22 Mar 2018 18:35:17 +0100
From: Peter Otten <__pete...@web.de>
To: tutor@python.org
Subject: Re: [Tutor] Oracle forms
Message-ID: 
Content-Type: text/plain; charset="ISO-8859-1"

David Holland via Tutor wrote:

> Is there anyway I can use Python to fill in an Oracle form rather than
> typing it in myself.I.e take values from a .csv file and put them into an
> Oracle form.Any ideas (I have googled it) what libraries to use?

If I understand you correctly you want to enter data into a database, in 
bulk. For that you typically bypass any GUI, and connect to the database 
directly. With Python and Oracle that would look like

http://www.oracle.com/technetwork/articles/dsl/python-091105.html

As it is possible to do a lot of damage (provided you have the necessary 
credentials) I suggest that you discuss this with your IT department before 
you proceed.



--

Message: 3
Date: Thu, 22 Mar 2018 11:41:37 -0600
From: Mats Wichmann 
To: tutor@python.org
Subject: Re: [Tutor] Oracle forms
Message-ID: <9c47487f-5664-2d7a-b99e-9ad0d581c...@wichmann.us>
Content-Type: text/plain; charset=utf-8

On 03/22/2018 11:35 AM, Peter Otten wrote:
> David Holland via Tutor wrote:
> 
>> Is there anyway I can use Python to fill in an Oracle form rather than
>> typing it in myself.I.e take values from a .csv file and put them into an
>> Oracle form.Any ideas (I have googled it) what libraries to use?
> 
> If I understand you correctly you want to enter data into a database, in 
> bulk. For that you typically bypass any GUI, and connect to the database 
> directly. With Python and Oracle that would look like
> 
> http://www.oracle.com/technetwork/articles/dsl/python-091105.html
> 
> As it is possible to do a lot of damage (provided you have the necessary 
> credentials) I suggest that you discuss this with your IT department before 
> you proceed.

>From the Python viewpoint, no clue.

Oracle Forms has its own API. Naturally, that requires a unique
scripting language to use ("but it's easy to learn!"). Maybe if they
were building it today they would use a known scripting language
instead, who knows. And the API package has, I believe, add-on costs.
It's Oracle, after all.



--

Message: 4
Date: Thu, 22 Mar 2018 18:08:53 +
From: Alan Gauld 
To: tutor@python.org
Subject: Re: [Tutor] Oracle forms
Message-ID: 
Content-Type: text/plain; charset=utf-8

On 22/03/18 15:22, David Holland via Tutor wrote:
> Is there anyway I can use Python to fill in an Oracle form

What kind of Oracle form? There are at least 2 that I'm
aware of.

1) The Oracle Forms thick client app framework which runs
  on a PC and connects to the database server. (I believe
this is now obsolescent and 

[Tutor] Oracle forms

2018-03-22 Thread David Holland via Tutor
Is there anyway I can use Python to fill in an Oracle form rather than typing 
it in myself.I.e take values from a .csv file and put them into an Oracle 
form.Any ideas (I have googled it) what libraries to use?


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


Re: [Tutor] PYTHON HELP

2018-03-15 Thread David Rock

> On Mar 15, 2018, at 08:42, Prashanth Ram  wrote:
> 
> I'm a beginner in Python. I have written a code to open browsers using
> selenium framework. I have purchased a Virtual Private Server (VPS) with
> CentOS 6.9 installed from GoDaddy.
> 
> My code is working well in localhost but when I try to open that in VPS
> server I'm failing in running that code. I'm getting errors. I have
> installed Chrome and it's drivers. Even though I'm facing errors.
> 
> I request your team to help me in this. Please find the attachments
> 

Welcome,

Your attachments did not come through.  This list generally only works with 
in-line text.  If you post your code, what you expect and what the errors are, 
we will have a better chance of helping.

Being a tutor list, help with the selenium framework is not guaranteed, though. 
 Hopefully your issue is something basic.


— 
David Rock
da...@graniteweb.com




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


[Tutor] I have a problem with def

2018-02-23 Thread David Bauer
it doesn't work, you are suppsed to declare a function as def func() and it
comes back as:

File "", line 1
def func()
 ^
SyntaxError: invalid syntax

that is not expected I would also expect def to turn red because it is a
keyword in Python, but that doesn't happen, anyone else having this
problem Anyone know what I should do or look for
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is day of week from either 20180211 or 02112018

2018-02-06 Thread David Rock

> On Feb 6, 2018, at 13:45, Ken Green  wrote:
> Traceback (most recent call last):
>   File "A_Weekday.py", line 20, in 
> answer = datetime.date(year, month, day).weekday()
> NameError: name 'datetime' is not defined

Your error message tells you the problem.  You are importing date _from_ 
datetime, but then try to call datetime.date

> from datetime import date

You have _not_ imported date time, so the program doesn’t know what you mean 
when you say

answer = datetime.date(year, month, day).weekday()

Try just doing 

import datetime 

instead.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] unable to locate python on mac

2018-01-31 Thread David Rock

> On Jan 31, 2018, at 13:44, Alan Gauld via Tutor  wrote:
> 
> If you need more details you will need to ask more specific questions.
> Bear in mind that although some folks here use Macs most of us don't.
> 

Another pertinent question is what python did you actually install (i.e., where 
did you get it from)?  Different bundles install differently, so knowing 
exactly what you downloaded will help identify some of the other questions.


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] How to sort float number from big numbers to small numbers?

2017-09-25 Thread David Rock
> On Sep 24, 2017, at 22:34, edmundo pierre via Tutor  wrote:
> 
> I am trying to sort float numbers input by an user from the bigger to smaller 
> number. I do not know how to compare float numbers. Any ideas? Thank you!
> Edwin

Some basic ideas to think about:

1. inputs are usually strings, so make sure you are storing them as floats
2. put them in a list.  You can then use list built-ins to sort 

What have you tried so far?  Are you trying to start at all, or are you trying 
things that aren’t working?


— 
David Rock
da...@graniteweb.com




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


Re: [Tutor] Python 3 for Beginners was: (Re: intro book for python)

2017-09-03 Thread David Rock

> On Sep 3, 2017, at 08:55, Mats Wichmann  wrote:
> 
> On 09/03/2017 04:02 AM, Leam Hall wrote:
> 
>> Anyone that uses python on Linux has to use Python 2. 
> 
> Every current distro I know of has a python 3 package, plus lots and
> lots of add-ons in python 3 mode.  It's quite easy to use python 3 as a
> result... and if that doesn't work you can install your own to your
> workspace (rather than as a "system package") just as easily.

While a bit anecdotal, the complaint is valid.  Red Hat does not support Python 
3 in their base installation on RHEL and the only way to get it “officially” 
(i.e., directly from Red hat) is through Software Collections, which is a bit 
cumbersome to use and not available in all cases.  There are a lot of places 
(including where I work) that frown heavily on using packages that aren’t from 
the base repositories from the OS maintainers.

Installing into “your own workspace” isn’t so easy when you are talking about 
2000 servers, either.  In order for me to write code that I know will work 
across all the servers, I have to use python 2 because I know it will be there. 
 I can’t say the same thing about python 3, and that’s not something I’m likely 
to be able to fix within the bounds of company procedures.

So while the original statement is obviously false, the heart of why it was 
said is functionally true. 


— 
David Rock
da...@graniteweb.com




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


[Tutor] Installing NUMPY

2017-07-28 Thread David Torres
Hello,
I am having trouble executing a scripty that imports numpy. I have a
feeling its because I had an old version of Numpy when I was using python
2.7. I am now using Pyhton 3X and I am getting the following error when I
execute the program:::


ImportError:
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: DLL load failed: The specified procedure could not be
found.



Please let me know if we can email each other or call. I would appreciate
your help, I am very desperate! Thanks
David A. Torres
GitHub : https://github.com/dav1dt0rres
-Man lives like a robot: mechanically efficient, but with no awareness.
Department of Computer Science



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


Re: [Tutor] Why use main() ?

2017-07-05 Thread David Rock
* Mats Wichmann  [2017-07-05 16:47]:
> > 
> 
> As a vaguely contradictory position to a part of this (which I in the
> main agree with): if your objective is to make a module, and also have
> some code (perhaps including test code) which is run in the non-module
> (aka not-imported) case, then stuffing that code in a function main()
> means you've exposed that not-really-module-code as part of the module,
> and might then want to take steps to hide it from clients so it doesn't
> end up looking like part of the module API.

In most cases, my scripts tend to be pretty self-contained and written
for my own purposes, so that would rarely be an issue.  

How would you hide main() if you _were_ concerned about it?

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


Re: [Tutor] Why use main() ?

2017-07-05 Thread David Rock
* Alan Gauld via Tutor  [2017-07-05 20:36]:
> On 05/07/17 16:37, David Rock wrote:
> 
> > This is a question about the benefits of using a main() function vs not.
> 
> 
> Others have answered for the pros, but I confess that I don't
> always use a main(), but only if all I'm doing is, say,
> instantiating a class and running a method. For anything
> more complex I'd write a main() (or test() or demo() ) to
> go inside the
>if name==main
> clause.

Thank you everyone for the input.

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


[Tutor] Why use main() ?

2017-07-05 Thread David Rock
This is not a question about using if __name__ == '__main__':.  I know
what the difference is between running the script or importing it and
using the value of __name__ to determine behavior.

This is a question about the benefits of using a main() function vs not.
ie,

if __name__ == '__main__':
#code goes here

vs


def main():
#code goes here

if __name__ == '__main__':
main()


I personally find using main() cumbersome, but many examples I come
across use main().  Is there some fundamental benefit to using main()
that I'm missing?


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


Re: [Tutor] Fahrenheit to Celsius Conversion another problem and Programming Paradigm

2017-06-15 Thread David Rock

> On Jun 15, 2017, at 13:16, William Gan  wrote:
> 
> Hi David,
> 
> Very much thanks for taking time to help.
> 
> Your explanation has helped me understand that syntax issue better. I have 
> resolved that error.
> 
> Your counsel on the second issue has given me encouragement. Thank you.

I’m glad it helped.  For completeness, in case you didn’t notice, your elif 
statement has the same issue.

elif unit == 'F' or 'f’:
c = (temp - 32) * 5 / 9
print(str(temp) + ' F is equivalent to ' + "%.2f" % c + ' C.’


—
David Rock
da...@graniteweb.com




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


Re: [Tutor] Fahrenheit to Celsius Conversion another problem and Programming Paradigm

2017-06-14 Thread David Rock

> On Jun 14, 2017, at 09:20, William Gan  wrote:
> 
> However, today I modified only the print instruction a little to try to print 
> out ℃ (in the second print clause). When I subsequently ran the script all 
> the outputs were executed from the if clause, even when I input other letters 
> (Please see below. I have removed the code to print degree C).
> 
> 
> if unit == 'C' or 'c':
> 
>f = temp * 9 / 5 + 32
> 
>print(str(temp) + ' C is equivalent to ' + '%.2f' % f + ' F.')
> 
> elif unit == 'F' or 'f':
> 
>c = (temp - 32) * 5 / 9
> 
>print(str(temp) + ' F is equivalent to ' + "%.2f" % c + ' C.')


The problem is your if statement is flawed.

if unit == 'C' or 'c’:

This is not doing what you think it is.  You are expecting:
if unit == ‘C’ or unit == ‘c’

When doing an ‘or’ statement, each part of the logic on each side of the ‘or’ 
is evaluated, so
if unit == ‘C’ is true, or if ‘c’ is true

is what’s actually being checked.  a bare character, ‘c’ will always evaluate 
to True, so the if is always true.

What you actually want (checking if unit is ‘C’ or ‘c’) can be done a few ways. 
 The most common are:

if unit == ‘C’ or unit ==‘c’:

or

if unit in [‘C’, ‘c’]:



> ISSUE 2:
> 
> The second issue relates to the last statement above “I have looked at it 
> many times today and could not see the error”.
> 
> 
> 
> I was hoping that someone, perhaps one with pedagogical experience and 
> knowledge, could advise the following:
> 
> 1.   Is it possible that I may not have the right aptitude or mental 
> paradigm to do computer programming?

Unlikely.  Programming is not about aptitude, it’s more about spending time 
understanding the rules.  The above is a prime example of getting to understand 
the rules.  Logic rules are notoriously specific; they check exactly what you 
tell them to check, which is not always what you think you are asking.  It just 
takes time.

> 
> 2.   Nevertheless, I intend to keep learning and practicing, but wonder 
> if there is an effective way to get a breakthrough into the programming 
> paradigm? If so, kindly advise how and direct me to a suitable resource to do 
> it.

Really, just keep trying things.  When you run into something like this, the 
most effective way to troubleshoot is narrow it down to the essential issue.  
In this case, “why is the if statement always evaluating to true?”  Look at the 
parts and re-read what each does (eg, reread how the ‘or’ operator works).

You are doing fine. :-)



—
David Rock
da...@graniteweb.com




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


Re: [Tutor] Python - help with something most essential

2017-06-05 Thread David Rock

> On Jun 5, 2017, at 09:36, Schtvveer Schvrveve  wrote:
> 
> 
> And I was rejected. I just wish to understand what I could have done for
> this to be better?
> 
> I am a Python beginner, so I'm sure there are things I don't know, but I
> was a bit surprised at the abruptness of the rejection and I'm worried I'm
> doing something profoundly wrong.

The main thing that jumps out to me is the memory issue they asked you to 
address was not addressed.  

In your readFile, you have 

with open(filename) as f:
   content = f.readlines()

Which reads the entire file into memory. They specifically did not want you to 
do that.  
The implication is they were looking for a solution where you read the file 
maybe one line (or even one word) at a time and look for anagrams in smaller 
groups.

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


Re: [Tutor] Pycharm Edu Lesson 3, Task 7

2017-05-04 Thread David Wolfe
Thanks all for the help.

Pycharm just posted an update to their Pycharm Edu product, and when I
re-ran the script, everything was fine.

Best,
David

On Tue, May 2, 2017 at 4:27 AM, Alan Gauld via Tutor 
wrote:

> On 02/05/17 01:42, David Wolfe wrote:
>
> > I'm working through Pycharm Edu, and I'm stuck on the following:
> >
> > phrase = """
> > It is a really long string
> > triple-quoted strings are used
> > to define multi-line strings
> > """
> > first_half = phrase[:len(phrase)//2]
> > print(first_half)
> >
> >
> > The instructions are:
> > The len() function is used to count how many characters a string
> contains.
> >
> > Get the first half of the string stored in the variable phrase.
> > Note: Remember about type conversion.
>
> I'm assuming this is only part of the story since the instructions don't
> make sense. There is no need for type conversion here.
>
> > and my output is:
> >
> > It is a really long string
> > triple-quoted st
> >
> > which is what I'm supposed to get, but I keep getting the error message
> > "Too short string in the output"
>
> I don't know the PyCharm IDE but is that all it says?
> I'd expect a bit more information about where the error lies.
> It certainly isn't obvious and I don't get any such error when
> I execute your code in IDLE.
>
> --
> 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


[Tutor] Pycharm Edu Lesson 3, Task 7

2017-05-02 Thread David Wolfe
Good Evening;

I'm working through Pycharm Edu, and I'm stuck on the following:

phrase = """
It is a really long string
triple-quoted strings are used
to define multi-line strings
"""
first_half = phrase[:len(phrase)//2]
print(first_half)


The instructions are:

The len() function is used to count how many characters a string contains.

Get the first half of the string stored in the variable phrase.
Note: Remember about type conversion.

and my output is:

It is a really long string
triple-quoted st

which is what I'm supposed to get, but I keep getting the error message
"Too short string in the output"

Any suggestions?

Thanks,
David




<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virus-free.
www.avg.com
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] CSV file Reading in python

2017-03-21 Thread David Rock

> On Mar 20, 2017, at 14:37, Edzard de Vries  wrote:
> 
> I have a CSV which I want to be able to read in Python. I don't know the 
> exact syntax and I get error messages. Where can I find the syntax to do this.
> I juiste starter learning Python.

Edzard,

Please post your code and the errors you are getting so we can see what issue 
you are having.

—
David Rock
da...@graniteweb.com




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


Re: [Tutor] Problem on parsing data

2017-03-13 Thread David Rock

> On Mar 13, 2017, at 16:19, jarod_v6--- via Tutor  wrote:
> 
> 
> What can I do for parse better that file and Have only the  comma outside the 
> string ?
> 

I recommend using the cvs module rather than try to write your own.

https://docs.python.org/2/library/csv.html


—
David Rock
da...@graniteweb.com




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


Re: [Tutor] While until the end of a list

2017-03-13 Thread David Rock

> On Mar 13, 2017, at 10:54, Toni Fuente via Tutor  wrote:
> 
> Hi,
> 
> I've got this script that goes through an httpd conf file, and gets the
> related bits of it for a site, and writes a new config with values that
> I am interested. The problem is that it finds the first chunk and
> returns it, but I need to go to the end of all chunks list, because
> there are also some chunks related to the same site that I need to
> collect (virtualhost *:80 and virtualhost:443). I was
> 
> I was thinking in a while loop in the find_chunk function that will go through
> all chunks and return the chunks that site is on, but I don't know how to
> construct it.

You just need to make a list or a dict to store the information for each site, 
and add the results to it.  If you use a list, it would be list.append(), for 
example.

I don’t really follow what you expect the output to be, though.
What do you want the results of running the script to look like?


—
David Rock
da...@graniteweb.com




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


Re: [Tutor] printing items form list

2017-03-03 Thread David Rock

> On Mar 3, 2017, at 13:42, dirkjso...@gmail.com  wrote:
> 
> On 03/03/2017 12:19 PM, Alan Gauld via Tutor wrote:
>> 
>> That's one reason why join() is a better solution, it
>> handles all of that for you. It's also faster, although
>> in a small application you'd never notice the difference.
>> 
> The ','.join(suitcase) is obviously best of all, but if one doesn't know that 
> method, the below suggestion can be fixed with:
> 
> suitcase = ['book', 'towel', 'shirt', 'pants']
> 
> for i in suitcase:
>st = st + i + ', '
> 
> print('You have a s% in your luggage.' % st)

There are three issues with that statement.
1. not knowing a method is not an excuse.  It’s worth knowing join because it 
has a lot of flexibility (and it _is_ known because of this discussion)
2. Your code as written doesn’t work because st is not defined before you use it

>>> suitcase = ['book', 'towel', 'shirt', 'pants']
>>> for i in suitcase:
... st = st + i + ', '
...
Traceback (most recent call last):
  File "", line 2, in 
NameError: name 'st' is not defined

3. Your [fixed] code (added st = ‘') and join do NOT do the same thing (note 
the extra comma and space at the end of yours)
  join: You have a book, towel, shirt, pants in your luggage.
  yours: You have a book, towel, shirt, pants,  in your luggage.


String concatenation with a loop is notorious for adding extra stuff at the 
end.  To get it right, you have to take into account what to do at the end of 
the list, which adds code complexity.

—
David Rock
da...@graniteweb.com




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


Re: [Tutor] printing items form list

2017-03-03 Thread David Rock

> On Mar 3, 2017, at 12:52, Peter Otten <__pete...@web.de> wrote:
> 
> Antonio Zagheni via Tutor wrote:
> 
>> suitcase = ["book, ", "towel, ", "shirt, ", "pants"]
> 
> Hm, looks like you opened Rafael's suitcase while he wasn't looking, and
> sneaked in some commas and spaces ;)
> 
> That's cheating...

yeah, just a little. :-)

You can use join for this:

suitcase = ["book", "towel", "shirt", "pants"]
output = ', '.join(suitcase)
print ("You have a %s in your luggage.") %output


—
David Rock
da...@graniteweb.com




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


Re: [Tutor] Q about .join() Thanks!

2017-02-13 Thread David Rock

> On Feb 13, 2017, at 12:34, SIJIA CHEN  wrote:
> 
> I find out that the outcome for using .join() on a dictionary is totally 
> different than it using on list or string. for example,
> 
>>>> seq4 = {'hello':1,'good':2,'boy':3,'doiido':4}
>>>> print ':'.join(seq4)
>  boy:good:doiido:hello
> So my question is why the outcome doesn't show sequentially as the same 
> sequence of the original seq4?  What pattern do those "keys" of the 
> dictionary in the outcome show ?

Dictionaries (in particular, their keys) are unordered.  You can not rely on 
them to be in a particular sequence.  The reason for this, from a practical 
perspective, is you are expected to ask for the specific key; you should not 
care about the ordering.

Lists, on the other hand, have a specific order by design so will always be in 
the order they were created.

What are you trying to do with join() on a dictionary in the first place?  Is 
there a specific outcome you are trying to get?  It’s unlikely that using join 
on a dictionary is what you actually want.

—
David Rock
da...@graniteweb.com




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


  1   2   3   4   5   6   7   8   9   10   >