Re: [Tutor] Fwd: Can tempfile.NamedTemporaryFile(delete=False) be used to create *permanent* uniquely named files?

2018-10-23 Thread Avi Gross
Since this topic is not focused on efficiency, why exactly does it matter if your function should check if a file exists and then avoid a collision? What you are describing sounds a bit like a hash function. In many cases, when you perform the computations you may find the slot you hash to is

Re: [Tutor] Installing python

2018-11-03 Thread Avi Gross
Alan, Many people have machines with a single login that is shared with nobody. I install lots of software on multiple machines that only I use and have often wondered what the purpose for me was to install for everyone. On some machines you then need to log in as whatever variant of superuser

Re: [Tutor] TESTING

2018-11-02 Thread Avi Gross
I am not totally up on the exact purposes of this group but have noted how many of the questions asked have been frustrating. I wonder if it would make any sense to provide a template people might fill out to suit their needs. An example might be people who want you to pretty much do their

Re: [Tutor] How to find optimisations for code

2018-10-20 Thread Avi Gross
There are many ways to do some things. I present a fairly straightforward method for consideration. Synopsis. Use two dictionaries to keep track of how many times a letter can be found in the source word and the target word. Loop over the target letters and as soon as you find a letter

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-08 Thread Avi Gross
; % fs"*, Now I dont see the error "SyntaxError: can't assign to literal" This is not returning exactly "*vfat*" instead of this, it is returning as "* /dev/mmcblk1p1: LABEL="efi" UUID="1084-AA42" TYPE="vfat"* " Could you please hel

Re: [Tutor] Displaying Status on the Command Line

2018-11-08 Thread Avi Gross
What Alan wrote makes sense if you just want to put out one mark per second till you stop. But if you want a percentage of progress, you need some way to estimate what percent of the way you are to being done. You need to determine how many marks represent 100% such as 50 periods. You need to

Re: [Tutor] best way to dynamically set class variables?

2018-11-08 Thread Avi Gross
I have been reading the replies and wonder sometimes if we understand the real question as intended. Classes in Python can be changed in all kinds of ways even after they have been defined and the changes take effect on any new instances created afterward. So can instances in multiple ways. If

Re: [Tutor] Require Python assistance

2018-11-09 Thread Avi Gross
As I see others have replied, the question is not easy to understand and seems so broad as to be overwhelming to actually do without further info. It would be easier if someone asked if we could direct him to resources that either explain the algorithms needed or to full-blown packages/modules

Re: [Tutor] Require Python assistance

2018-11-10 Thread Avi Gross
WARNING to any that care: As the following letter is a repeat request without any hint they read the earlier comments here, I did a little searching and see very much the same request on another forum asking how to do this in MATLAB:

[Tutor] Bufferin

2018-11-11 Thread Avi Gross
After my earlier message (snipped out for space savings) focused on choosing among various methods to retain a buffer of recent lines from a file, I realized that for many, the best method is simply to import a solution others have created, often in the form of an object. Many of the methods I

Re: [Tutor] saveLine decked

2018-11-11 Thread Avi Gross
g or debugging overhead. It is even flexible enough, if you choose, to store or display the lines backwards as in showing the last line that showed the error, followed by successively earlier lines. Why use a limited solution when you can play with a full deck? -Original Message

Re: [Tutor] Example for read and readlines() (Asad)

2018-11-13 Thread Avi Gross
Asad, Like many projects, there may be many ways to do things BUT some rules do apply. You can only read an open file ONCE unless you seek back to the beginning or reopen it. string = f3.read() string1 = f3.readlines() The first line reads the entire file into a single buffer. The second

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-07 Thread Avi Gross
I may be missing something but it looks like the embedded double quotes may be a problem in this: cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % ... if you use single quotes as in: cut -d"=" becomes cut -d'=' or escape the double quotes with \" and so on ... The above seems to

[Tutor] python commandos

2018-11-15 Thread Avi Gross
Dev, There are many ways to learn a programming language but a list of all commands is not necessarily a good way. I suspect your real question is how do you learn Python as either a beginner at this language or with little knowledge of computers in general. There are tons of books and classes

Re: [Tutor] best way to dynamically set class variables?

2018-11-09 Thread Avi Gross
An interesting discussion that is outside the scope of a group like this is HOW malicious things can be done and perhaps how to avoid them. Obviously some contexts are totally uncontrolled. If you write a "calculator" that asks the user to type in an arbitrary string like "2*(3+5)" or "sin(30)"

Re: [Tutor] (no subject)

2018-11-12 Thread Avi Gross
In replying to what "Stealth Fleet" asked, I have too many comments, starting with a suggestion to put a SUBECT on the Subject: line. Your first error was not converting the text input to an integer or floating point number. tokenAmount = input( "How many tokens would you like to buy or

[Tutor] saveLine

2018-11-11 Thread Avi Gross
Alan and others have answered the questions posed and what I am asking now is to look at the function he proposed to keep track of the last five lines. There is nothing wrong with it but I wonder what alternatives people would prefer. His code is made for exactly 5 lines to be buffered and is

[Tutor] look back comprehensively

2018-11-14 Thread Avi Gross
I have been thinking about the thread we have had where the job seemed to be to read in a log file and if some string was found, process the line before it and generate some report. Is that generally correct? The questioner suggested they needed both the entire file as one string but also as a

Re: [Tutor] Regarding "IDLE Subprocess Didn't Make Connection" Error

2018-11-16 Thread Avi Gross
BREAK fast , You certainly haven't been idle! Until you get IDLE working ideally, you can still use one of many text editors and programming environments and perhaps run python on the files manually. Have you verified that the rest of your installation worked? Sent from AOL Mobile Mail On

Re: [Tutor] decomposing a problem

2018-12-29 Thread Avi Gross
a problem On Fri, Dec 28, 2018 at 10:39:53PM -0500, Avi Gross wrote: > I will answer this question then head off on vacation. You wrote about 140 or more lines, but didn't come close to answering the question: how to randomly split data from a dictionary into training data and reserved data. -- St

Re: [Tutor] decomposing a problem

2018-12-29 Thread Avi Gross
percentages to partition by or other ways. Sent from AOL Mobile Mail On Saturday, December 29, 2018 Avi Gross wrote: Steven, As I head out the door, I will sketch it. Given a data.frame populated with N rows and columns you want to break it into training and test data sets. In a data.frame, you

Re: [Tutor] decomposing a problem

2018-12-27 Thread Avi Gross
Re: [Tutor] decomposing a problem On Wed, Dec 26, 2018 at 11:02:07AM -0500, Avi Gross wrote: > I often find that I try to make a main point ad people then focus on > something else, like an example. I can't speak for others, but for me, that could be because of a number of reasons: - I agree w

Re: [Tutor] dangerous class neighborhood

2018-12-27 Thread Avi Gross
My apologies. This reply went to the wrong forum. Hopefully it contains little to be debated. An even shorter version would be: If at first you don't succeed ... -Original Message- From: Tutor On Behalf Of Avi Gross Sent: Thursday, December 27, 2018 9:48 PM To: tutor@python.org Subject

[Tutor] Interpreter pasting Question

2018-12-27 Thread Avi Gross
This is a serious question. I have tried things and searched and remain stumped. It is about python and perhaps just the interpreter. Copying and pasting multiple lines into the interpreter fails in mysterious ways, unless they are a logical single entity. Is there a way to change this

Re: [Tutor] Re Module

2018-12-27 Thread Avi Gross
Asad, After reading replies to you by Alan and Steven I want to ask you if you can first tell us in normal words what the exact outline of the program does. If you only want help on one small part, tell us about that. I was first fooled into thinking you wanted to show us how you solve the

Re: [Tutor] dangerous class neighborhood

2018-12-27 Thread Avi Gross
the problem does not really need to be solved by me and I move on. -Original Message- From: Python-list On Behalf Of Chris Angelico Sent: Thursday, December 27, 2018 5:11 PM To: Python Subject: Re: dangerous class neighborhood On Fri, Dec 28, 2018 at 8:47 AM Avi Gross wrote: > Quest

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

2018-12-29 Thread Avi Gross
I have my usual off the wall answer. OK, seriously. Not exactly an answer but perhaps an experiment. The question was how to have a non-named first argument to a function with some form of default. As was pointed out, this does not fit well with being able to have python gather all positional

Re: [Tutor] Python

2018-12-20 Thread Avi Gross
Mary, Mary, It is often best to develop and test small parts of the project where you can easily play with it, then move it into more complex configurations like a function body Here is your code: def read_words(words_file): return [word.upper() for line in open(words_file, 'r') for word

Re: [Tutor] decomposing a problem

2018-12-25 Thread Avi Gross
al Message- From: Mike Mossey Sent: Tuesday, December 25, 2018 9:49 PM To: Avi Gross Subject: Re: [Tutor] decomposing a problem > On Dec 25, 2018, at 4:00 PM, Avi Gross wrote: > > [Long enough that some should neither read nor comment on.] > > Mats raised an issue that

[Tutor] decomposing a problem

2018-12-25 Thread Avi Gross
e might see: lines.sort(show=True).reverse(show=True).pop() Or some other similar stratagem. Then we could write a fairly complex sequence in a pipelined mode. -Original Message- From: Tutor On Behalf Of Mats Wichmann Sent: Tuesday, December 25, 2018 11:04 AM To: tutor@python.or

Re: [Tutor] decomposing a problem

2018-12-25 Thread Avi Gross
method like pop() to suddenly return the list with a member dropped but it would be nice to fix some like this one: >>> testink.remove('7') >>> testink ['1', '3', '15'] Meanwhile, I hear Beethoven is decomp..., well never mind! It was probably Liszt! -Orig

Re: [Tutor] decomposing a problem

2018-12-25 Thread Avi Gross
-0500, Avi Gross wrote: > class chainable_list(list): > """Same as list but sort() can now be chained""" > def chainsort(this, *args, **kwargs): > this.sort(*args, **kwargs) > return this In Python, it is traditional to use "

Re: [Tutor] Increase performance of the script

2018-12-12 Thread Avi Gross
Asad, I wonder if an import from __future__ happened, perhaps in the version of collections you used. Later versions of 2.x allow optional use of the 3.x style of print. When you redefine print, the old statement style is hidden or worse. -Original Message- From: Tutor On Behalf Of

Re: [Tutor] Long Lines techniques

2018-12-13 Thread Avi Gross
ould allow tricks like this in a pre-processor. From: Bob Gailer Sent: Thursday, December 13, 2018 2:33 PM To: Avi Gross Cc: tutor@python.org Subject: Re: [Tutor] Long Lines techniques On Dec 13, 2018 1:51 PM, "Avi Gross" mailto:avigr...@verizon.net> > wrote: > > S

Re: [Tutor] Long Lines techniques

2018-12-14 Thread Avi Gross
anded to much more. -Original Message- From: Tutor On Behalf Of Steven D'Aprano Sent: Thursday, December 13, 2018 7:27 PM To: tutor@python.org Subject: Re: [Tutor] Long Lines techniques On Thu, Dec 13, 2018 at 12:36:27PM -0500, Avi Gross wrote: > Simple question: > > When line

Re: [Tutor] Python function

2018-12-14 Thread Avi Gross
If you know what a CommaSeparatedValues file looks like, then reading ONE LINE gives you enough info to answer the question about how many columns of data it describes. -Original Message- From: Tutor On Behalf Of Alan Gauld via Tutor Sent: Thursday, December 13, 2018 7:47 PM To:

Re: [Tutor] Obfuscated Python [was Long Lines techniques]

2018-12-14 Thread Avi Gross
To: tutor@python.org Subject: [Tutor] Obfuscated Python [was Long Lines techniques] On Thu, Dec 13, 2018 at 11:07:59PM -0500, Avi Gross wrote: > Python may claim to be straightforward but I can easily see ways to > fool people in python too with dunder methods or function closures

Re: [Tutor] Long Lines techniques

2018-12-14 Thread Avi Gross
:59PM -0500, Avi Gross wrote: [...] > There are cases where it may make sense to have a long like connected > by AND or OR given how python does short-circuiting while returning > the last thing or two it touched instead of an actual True/False. For > example, you may want to ta

Re: [Tutor] look back comprehensively

2018-12-24 Thread Avi Gross
There is linear thinking and then there is more linear thinking. As Alan, Mats and others said, there are often choices we can make and many approaches. If your goal is to solve a problem NOW and right where you are, any method you can find is great. If your goal is to solve it repeatedly or in

[Tutor] Long Lines techniques

2018-12-13 Thread Avi Gross
Simple question: When lines get long, what points does splitting them make sense and what methods are preferred? Details. I am used to many languages where you can continue a statement across multiple lines. What they share in common is the fact they do not use indenting for the use

Re: [Tutor] PEP 572 -- Assignment Expressions

2018-11-28 Thread Avi Gross
Ivo, One thing you could have done is explore with simpler code to see if you can deduce what is happening. If you opened your Python interpreter and tried to see what happens with a simplified variant like this, what do you get? if (match = 5) is not None: pass That might answer your

Re: [Tutor] writer overloaded

2018-11-29 Thread Avi Gross
ences but then you might have said I was too broad and showed no reasons or examples. As I said, life is short. -Original Message- From: Tutor On Behalf Of Steven D'Aprano Sent: Wednesday, November 28, 2018 6:15 PM To: tutor@python.org Subject: Re: [Tutor] user overloaded On Wed,

Re: [Tutor] online interactive Py resource?

2018-11-29 Thread Avi Gross
Mats, This may not be a direct answer to your question but I have used more generic tools in a way that might make some sense. You can use a videoconference tool such as SKYPE to connect and have one of you share your screen with the otgher so you can see whatever is open such as an editor they

[Tutor] Copyleft

2018-12-05 Thread Avi Gross
d be asked to limit their code to the standard distribution. -Original Message- From: Tutor On Behalf Of Alan Gauld via Tutor Sent: Tuesday, December 4, 2018 6:43 PM To: tutor@python.org Subject: Re: [Tutor] Borrowing free code On 04/12/2018 19:31, Avi Gross wrote: > But some packag

Re: [Tutor] Regarding Python api script

2018-12-07 Thread Avi Gross
[[ Real SUBJECT: emulating decorators ]] Steven, I am not suggesting that a particular way of reusing a name is a good idea. I am asking if some ways are encouraged and others are discouraged in the python community. Just to clarify one point you asked about: # > I have often seen something

Re: [Tutor] Regarding Python api script

2018-12-07 Thread Avi Gross
I left the "subject" above to be the same, as requested. The actual subject might have been "Pythonic variable name use" Alan says he had a challenge evaluating code (below) because the same variable names were reused and it made me wonder if the python community has general ideas about name

[Tutor] Borrowing free code

2018-12-04 Thread Avi Gross
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. Some companies may have

Re: [Tutor] Borrowing restricted code

2018-12-05 Thread Avi Gross
I don't want to start (and continue) another sideways discussion. Alan and Steven (not Stephen) both made very good points and helped clarify my understanding. I am NOT advocating copying code. Not even "free" code. I am saying there may be times you want to package the code for special

[Tutor] Born to be free

2018-11-23 Thread Avi Gross
Alan, Yes, I meant that many things are effectively free these days. Some things are required to be distributed free by CopyLeft. But you can pay a nominal fee for say a CD of the software. You can pay for a bundle like you describe, perhaps including some consulting or warranties to keep you

[Tutor] A required question

2018-11-23 Thread Avi Gross
Just to be different, and perhaps return to the purpose of this group, I have a question. Is there some functionality available in Python that you could put in the beginning of a program so it aborts with a message if the version of R being run is not acceptable? Let me elaborate. There

Re: [Tutor] A required question

2018-11-24 Thread Avi Gross
) import os os.system("python -m pip install " + modulosity) exec(f"import {modulosity}") I am sure something is doable and can be made into a proper function. Yes, I cheated by using exec. But it is now after Spanksgiving. -Original Message- From: Tutor

Re: [Tutor] A required question

2018-11-24 Thread Avi Gross
Python Subject: Re: [Tutor] A required question > 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 >> >>

[Tutor] Pythonic way

2018-11-20 Thread Avi Gross
This is not a question or reply. Nor is it short. If not interested, feel free to delete. It is an observation based on recent experiences. We have had quite a few messages that pointed out how some people approach solving a problem using subconscious paradigms inherited from their

Re: [Tutor] how to print lines which contain matching words or strings

2018-11-20 Thread Avi Gross
at least three times on that line, no matter what the word is. You may need to tell it whether a match should be greedy and many other considerations such as ignoring case. Have fun. Avi -Original Message- From: Tutor On Behalf Of Asad Sent: Monday, November 19, 2018 10:15 PM

Re: [Tutor] how to print lines which contain matching words or strings

2018-11-19 Thread Avi Gross
Asad, As others have already pointed out, your request is far from clear. Ignoring the strange use of words, and trying to get the gist of the request, would this be close to what you wanted to say? You have a file you want to open and process a line at a time. You want to select just lines

[Tutor] the fivefold path

2018-11-21 Thread Avi Gross
sage- From: Tutor On Behalf Of Mark Lawrence Sent: Tuesday, November 20, 2018 3:45 PM To: tutor@python.org Subject: Re: [Tutor] Pythonic way On 20/11/2018 18:08, Avi Gross wrote: > > We have two completely separate ways to format strings that end up > with fairly similar func

[Tutor] evolutionary drift

2018-11-21 Thread Avi Gross
Steve, You may be right. It often happens that someone has a (small) idea, perhaps very focused, and others chime in and try to apply it more widely, perhaps by making it more general, and it grows. Over the years, the earlier adopters may be seen almost as co-creators or even become the lead

Re: [Tutor] Writing the right code rite

2018-11-27 Thread Avi Gross
. Avi -Original Message- From: Tutor On Behalf Of Steven D'Aprano Sent: Tuesday, November 27, 2018 5:40 AM To: tutor@python.org Subject: Re: [Tutor] Writing the right code rite On Mon, Nov 26, 2018 at 07:18:46PM -0500, Avi Gross wrote: > What kind of answers have people provi

[Tutor] origins bootstrapped.

2018-11-21 Thread Avi Gross
Alan has been involved with Python for a long time so he has more to offer historically. I don't see some things as either/or. You can start with one major motivation and it morphs from a one-celled creature like an Amoeba to a complex vertebrate like a Python which needs modules added so it can

[Tutor] seniority

2018-11-22 Thread Avi Gross
: Tutor On Behalf Of Steven D'Aprano Sent: Thursday, November 22, 2018 1:06 AM To: tutor@python.org Subject: Re: [Tutor] origins bootstrapped. On Wed, Nov 21, 2018 at 11:31:59AM -0500, Avi Gross wrote: > Alan has been involved with Python for a long time so he has more to > offer historically.

[Tutor] learning languages

2018-11-22 Thread Avi Gross
.org Subject: Re: [Tutor] origins bootstrapped. On Wed, Nov 21, 2018 at 11:31:59AM -0500, Avi Gross wrote: ... > Can I ask a question that I really want an opinion on? As a preface, I see > some think python as a formal language is being pushed by industry in > directions that may not

Re: [Tutor] A retired question

2018-11-26 Thread Avi Gross
- From: Tutor On Behalf Of Mats Wichmann Sent: Monday, November 26, 2018 10:23 AM To: paso...@gmail.com Cc: tutor@python.org Subject: Re: [Tutor] A required question On 11/25/18 8:54 PM, Asokan Pichai wrote: > On Sat, Nov 24, 2018, 14:33 Avi Gross >> David, >> >> As I suspe

[Tutor] Writing the right code rite

2018-11-27 Thread Avi Gross
I am here to learn but also to help out when I already know something that is asked. What has been of some concern to me is how to reply when the asked has not shared with us lots of info. If I see them using "print" without parentheses, I can assume they are not using 3.x and perhaps

[Tutor] user overloaded

2018-11-28 Thread Avi Gross
inding this colon in a wrong context? I conclude by saying life is complicated and then you die. I mean there are many places where similar but not identical things happen in languages as well as life. -Original Message- From: Tutor On Behalf Of Steven D'Aprano Sent: Wednesday, November 28, 201

Re: [Tutor] I need help with my project

2018-11-28 Thread Avi Gross
I suggest starting at the beginning when asking a question to people who have no way of knowing what you have not told them. Your sentence is completely in middle or even near the end of something that has to be larger: " If the user selected a sandwich, french fries, and a beverage, reduce the

Re: [Tutor] Regarding "IDLE Subprocess Didn't Make Connection" Error

2018-11-17 Thread Avi Gross
I was wondering if I was the only one who felt the urge to apply a tad of humor and suppressed most of the thoughts about idol/IDLE worship and other puns so I am glad to see Steve do just a little of the same. It seems that despite how portable Python is touted to be, quite a few people

Re: [Tutor] Finding the largest gap in tuple between two lists.

2018-11-18 Thread Avi Gross
Harry, Your code may not have come through as intended as the formatting often combined lines. It may help to think about the question before giving deeper answers. You have two places and two sets of goods with prices. You want the intersection of those two to focus on what goods are in both.

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

2018-12-30 Thread Avi Gross
not handle any form. Can you save a value of Inf that is meaningful even to read back in? I don't mean from using something like pickle, but from some storage formal like CSV or EXCEL. I see Steve wrote a bit more and will just say I agree. God programming style tries to avoid surprises when it can

Re: [Tutor] Interpreter pasting Question

2018-12-28 Thread Avi Gross
on On Fri, Dec 28, 2018 at 12:58:00AM -0500, Avi Gross wrote: [...] > Copying and pasting multiple lines into the interpreter fails in > mysterious ways, unless they are a logical single entity. > > Is there a way to change this behavior, or perhaps an > editor/environ

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

2018-12-30 Thread Avi Gross
nction in python On Sun, Dec 30, 2018 at 12:07:20AM -0500, Avi Gross wrote: [...] > Or on a more practical level, say a function wants an input from 1 to 10. > The if statement above can be something like: > > >>> def hello(a, *n, **m) : > if not (1 <= a <=

Re: [Tutor] decomposing a problem

2018-12-28 Thread Avi Gross
python consistently enough has everything being object-oriented. R started off without and has grafted on at least a dozen variations which can be a tad annoying. -Original Message- From: Tutor On Behalf Of Steven D'Aprano Sent: Friday, December 28, 2018 8:04 PM To: tutor@python.org Subj

Re: [Tutor] decomposing a problem

2018-12-28 Thread Avi Gross
Steve, I am going to just respond to one part of your message and will snip the rest. I am not is disagreement with most of what you say and may simply stress different aspects. I will say that unless I have reason to, I don't feel a need to test speeds for an academic discussion. Had this been a

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

2018-12-30 Thread Avi Gross
variable arguments in a function in python On 30/12/2018 17:26, Avi Gross wrote: > Replying to Steve's points. Again, it was not a serious design and > said so but was an ACADEMIC exploration of what could be done. I fully > agree with Steve that it is probably not a great i

[Tutor] Wrap a pipe to get text mode

2018-12-02 Thread Avi Gross
Brief(er) message on topic: Someone was having a problem that was traced to their use of a pipe to communicate between tasks that normally passes data in binary mode. They were offered solutions on how to convert the data that should work fine. I am offering a different solution from the