Roel,
In order for the code to provide different error messages, it needs a way to
differentiate between circumstances.
As far as the int() function is concerned, it sees a string of characters and
has no clue where they came from. In Python, int(input()) just runs input()
first and creates a
It may be a matter of taste and policies, Dave.
I am talking about whether to write your code so it looks good to you, and
dealing with issues like error messages only when needed, or whether to
first do all kinds of things to catch errors or make it easier if they pop
up.
Python can be written f
I would suggest thinking carefully about ramifications as well as any benefits
of adding some or .=operator.
It sounds substantially different than the whole slew of +=, *= and so on
types of operators. The goal some would say of those is to either allow the
interpreter optimize by not evaluat
As others have mentioned features added like this need careful examination
not only at effects but costs.
As I see it, several somewhat different ideas were raised and one of them
strikes me oddly. The whole point of an iterable is to AVOID calculating the
next item till needed. Otherwise, you can
I get a tad suspicious when someone keeps telling us every offered solution
does not feel right. Perhaps they are not using the right programming
language as clearly they are not willing to work with it as it is not as it
should be.
After all the back and forth, there are several choices includin
I think you got that right, Rob. A method created in a class is normally
expected to care about the class in the sense that it often wants to access
internal aspects and is given a "this" or "self" or whatever name you choose as
a first argument. As noted, it is sometimes possible to create a
Dennis,
Before I reply, let me reiterate I am NOT making a concrete suggestion, just
having a somewhat abstract discussion.
The general topic is a sort of polymorphism I envisioned where a select group
of classes/objects that can be seen as different aspects of an elephant can be
handled to pr
Yes, Dave, there are many data structures that can be used to maintain a
list of output types the class claims to support. Dictionaries have the
interesting property that you can presumably have a value that holds a
member function to access the way the key specifies.
Ideally, the order is not imp
Alan,
Your guess is not quite what I intended.
Something like a C union is just a piece of memory large enough to hold one of
several kinds of content and some way to figure out which is currently in place.
I am looking at a data structure that is an object of some class and stores the
data in
Can I bring a part of this discussion a bit closer to Python?
I stipulate that quite a few languages, including fairly early ones, treated
text often as numbers. Ultimately, much of programming is about taking in
text and often segregating parts into various buckets either explicitly or
by checkin
This reminds me a bit of complaints that the parser does not do what you
want when you do not supply parentheses in an expression like:
5 * 4 + 3
In many and maybe most languages it is seen as (5*4)+3 UNLESS you tell it
you want 5*(4+3). There are precedence and associativity rules.
Of course th
[THIS CLAIMER: a bit off a bit off a bit off topic, imagine that]
Chris,
You have a gift of taking things I think about but censor myself from
including in my post and then blurting it out! LOL!
The original question in this thread now seems a dim memory but we are now
discussing not how to add
Chris, I was not suggesting it for Python as one of many possible
implementations.
I do see perfectly valid uses in other contexts. For example, if I have a
program that displays my text as pixels in some font and size, I may indeed
want the text clipped at 2 1/2 repetitions. But as always, when t
Given the significant number of languages other than Python that have some
version of a feature that allows implicit conversion of unlike operands to
concatenate something like a "number" and a string into a string, the
question may not be silly as to how or why Python chose as it chose.
As I see
On closer reading, the OP may be asking how to make a function doing what
they want, albeit without a plus.
Here is a python function as a one-liner that takes exactly two arguments of
any kind (including string and integer) and concatenates them into one
string without anything between and prints
As originally written, the question posed has way too many possible answers
but the subject line may give a hint. Forget printing.
The Python statement
1 + "a"
SHOULD fail. The first is an integer and the second is string. These two
are native Python objects that neither define what to do if the
Sadly, between Daylight Savings time and a newer irrational PI π Day, I am
afraid some April Foolers got thrown off albeit some may shower us with
nonsense in May I.
-Original Message-
From: Python-list On
Behalf Of Barry Warsaw
Sent: Monday, April 3, 2023 8:31 PM
To: Skip Montanaro
Some questions are more reasonable than others.
If the version of a function used in a package were IDENTICAL to the
built-in, then why have it?
There are many possible reasons a package may tune a function for their own
preferences or re-use a name that ends up blocking the view of another name.
There seem to be a fundamental disconnect here based on people not
understanding what can happen when spaces are optional. Yes, I have had my
share of times I found what I programmed was not quite right and been unhappy
but the result was mostly learning how to not not not not do that next time
Morten,
Suggesting something is UNPYTHONIC is really not an argument I take
seriously.
You wrote VALID code by the rules of the game and it is not a requirement
that it guesses at what you are trying to do and calls you an idiot!
More seriously, python lets you do some completely obscure things
Hi,
This seems again to be a topic wandering. Was the original question whether
Python could be used for dealing with Seismic data of some unspecified sort
as in PROCESSING it and now we are debating how to clean various aspects of
data and make things like data.frames and extract subsets for anal
I have used GNU Octave as a sort of replacement for MATLAB as a free
resource. I have no idea if it might meet your needs.
Although Python is a good environment for many things, if you have no
knowledge of it yet, it can take a while to know enough and if you just need
it for one project, ...
--
A a,
Consider asking a more specific question. Many things can be done in many
different programming languages.
Are you asking if there are helpers you can use such as modules that
implement parts of the algorithms you need? Are you asking about speed or
efficiency?
Have you considered how few p
Greg,
Yes, it is very possible from other sources. I doubt it hurts if a popular
language, albeit not compiled the same way, uses a feature.
I see it a bit as more an impact on things like compiler/interpreter design
in that once you see it can reasonably be implemented, some features look
doable
This may be of interest to a few and is only partially about Python.
In a recent discussion, I mentioned some new Python features (match) seemed
related to a very common feature that has been in a language like SCALA for
a long time. I suggested it might catch on and be used as widely as in SCALA
Some of the discussions here leave me confused as the info we think we got
early does not last long intact and often morphs into something else and we
find much of the discussion is misdirected or wasted.
Wouldn't it have been nice if this discussion had not started with a mention
of a package/mod
Ah, thanks Dino. Autocomplete within a web page can be an interesting
scenario but also a daunting one.
Now, do you mean you have a web page with a text field, initially I suppose
empty, and the user types a single character and rapidly a drop-down list or
something is created and shown? And as th
Thomas,
I may have missed any discussion where the OP explained more about proposed
usage. If the program is designed to load the full data once, never get updates
except by re-reading some file, and then handles multiple requests, then some
things may be worth doing.
It looked to me, and I ma
Gerard,
I was politely pointing out how it was more than the minimum necessary and
might gets repeated multiple times as people replied. The storage space is a
resource someone else provides and I prefer not abusing it.
However, since the OP seems to be asking a question focused on how long it
ta
I am not commenting on the technique or why it is chosen just the part where
the last search looks for a non-existent period:
s = 'alpha.beta.gamma'
...
s[ 11: s.find( '.', 11 )]
What should "find" do if it hits the end of a string without finding the
period you claim is a divider?
Could that be
Dino, Sending lots of data to an archived forum is not a great idea. I
snipped most of it out below as not to replicate it.
Your question does not look difficult unless your real question is about
speed. Realistically, much of the time spent generally is in reading in a
file and the actual search
>>> I think you are over-thinking this, Avi :)
Is overthinking the pythonic way or did I develop such a habit from some
other language?
More seriously, I find in myself that I generally do not overthink. I
overtalk and sort of overwrite, so for now, I think I will drop out of this
possibly non-py
Alan,
I got divorced from the C++ crowd decades ago when I left Bell Labs. You are
making me glad I did!
I do accept your suggestion that you can be idiomatic if you follow the common
methods of whatever language you use. That will take you quite far as long as
you are not a total slave to it.
Great idea, DN!
A whole series of books can be written such as:
- Python for virgin dummies who never programmed before.
- Python for former BASIC programmers
- Python for former LISP programmers with a forked tongue
- Python for former Ada Programmers
- Python for ...
- Python for those who find
I don't know, Thomas. For some simple programs, there is some evolutionary
benefit by starting with what you know and gradually growing from there. He
first time you need to do something that seems to need a loop in python,
there are loops to choose from.
But as noted in a recent discussion, thin
Peter,
Of course each language has commonly used idioms as C with pointer
arithmetic and code like *p++=*q++ but my point is that although I live near
a seaway and from where C originated, I am not aware of words like "c-way"
or "scenic" as compared to the way people keep saying "pythonic".
Yes,
Thomas is correct that this is a bit of an odd request unless explained
better.
There are a number of implicit assumptions that need to be revisited here.
Python Lists are what they are. They are not in any way tagged. They are not
linked lists or binary trees or dictionaries or whatever you are l
Alan,
I do not buy into any concept about something being pythonic or not.
Python has grown too vast and innovated quite a bit, but also borrowed from
others and vice versa.
There generally is no universally pythonic way nor should there be. Is there
a C way and then a C++ way and an R way or
It is a well-known fact, Jose, that GIGO.
The letters "n" and "m" are not interchangeable. Your pattern fails because you
have "pn" in one place and "pm" in the other.
>>> s = "pn=jose pn=2017"
...
>>> s0 = r0.match(s)
>>> s0
-Original Message-
From: Python-list On
Behalf Of jose
My understanding is that python created functions like type() and len() as a
general purpose way to get information and ALSO set up a protocol that
classes can follow by creating dunder methods. I think the most pythonic
things is to avoid directly calling the dunder methods with a few exceptions
t
Thanks, Peter. Excellent advice, even if only for any of us using Microsoft
Outlook as our mailer. I made the changes and we will see but they should
mainly impact what I see. I did tweak another parameter.
The problem for me was finding where they hid the options menu I needed.
Then, I started tr
José,
Matching can be greedy. Did it match to the last space?
What you want is a pattern that matches anything except a space (or whitespace)
followed b matching a space or something similar.
Or use a construct that makes matching non-greedy.
Avi
-Original Message-
From: Python-list
Cameron,
The topic is now Regular Expressions and the sin tax. This is not
exclusively a Python issue as everybody and even their grandmother uses it
in various forms.
I remember early versions of RE were fairly simple and readable. It was a
terse minilanguage that allowed fairly complex things t
If a workaround like itertools.count.__next__() is used because it will not
be interrupted as it is implemented in C, then I have to ask if it would
make sense for Python to supply something similar in the standard library
for the sole purpose of a use in locks.
But realistically, this is one plac
This discussion has veered a bit, as it often does, but does raise
interesting points about programming in general and also in python.
We seem to be able to easily cite examples where a group of things is lumped
for convenience and people end up using them but then tweaking them.
S an example, th
Peter,
Nobody here would appreciate it if I tested it by sending out multiple
copies of each email to see if the same message wraps differently.
I am using a fairly standard mailer in Outlook that interfaces with gmail
and I could try mailing directly from gmail but apparently there are
systemic
Karsten,
Would it be OK if we paused this discussion a day till February is History?
Sarcasm aside, I repeat, the word black has many unrelated meanings as
presumably this case includes. And for those who do not keep close track of
the local US nonsense, February has for some reason been dedicate
David,
Your results suggest we need to be reminded that lots depends on other
factors. There are multiple versions/implementations of python out there
including some written in C but also other underpinnings. Each can often
have sections of pure python code replaced carefully with libraries of
com
Dave,
Is it rude to name something "black" to make it hard for some of us to remind
them of the rules or claim that our personal style is so often the opposite
that it should be called "white" or at least shade of gray?
The usual kidding aside, I have no idea what it was called black but in al
This message is more for Thomas than Jen,
You made me think of what happens in fairly large cases. What happens if I ask
you to search a thousand pages looking for your name?
One solution might be to break the problem into parts that can be run in
independent threads or processes and perhaps a
exact text that
matched or even show some characters before and/or after for context.
-Original Message-
From: Python-list mailto:python-list-bounces+avi.e.gross=gmail@python.org> > On Behalf Of
Jen Kris via Python-list
Sent: Monday, February 27, 2023 8:36 PM
To: Camer
Roel,
You make some good points. One to consider is that when you ask a regular
expression matcher to search using something that uses NO regular expression
features, much of the complexity disappears and what it creates is probably
similar enough to what you get with a string search except tha
I think by now we have given all that is needed by the OP but Dave's answer
strikes me as being able to be a tad faster as a while loop if you are
searching larger corpus such as an entire ebook or all books as you can do
on books.google.com
I think I mentioned earlier that some assumptions need
Michael,
Although I appreciate much of what you say, I ask humbly and politely that
we change the Subject line for messages like this one. HH is out of range
for now, albeit I think he can still read what we say.
But keeping the name Michael Torrie in the subject line, should be sort of
XXX rated
Jen,
Can you see what SOME OF US see as ASCII text? We can help you better if we get
code that can be copied and run as-is.
What you sent is not terse. It is wrong. It will not run on any python
interpreter because you somehow lost a carriage return and indent.
This is what you sent:
example
Jen,
What you just described is why that tool is not the right tool for the job,
albeit it may help you confirm if whatever method you choose does work
correctly and finds the same number of matches.
Sometimes you simply do some searching and roll your own.
Consider this code using a sort of l
Just FYI, Jen, there are times a sledgehammer works but perhaps is not the only
way. These days people worry less about efficiency and more about programmer
time and education and that can be fine.
But it you looked at methods available in strings or in some other modules,
your situation is qui
Yes, Greg, you are correct. After I posted, I encountered a later message
that suggested it was list comprehensions that had accidentally left a
variable behind in a context when theoretically you got ALL you asked for in
the resulting list, so it fixed eventually.
You live and learn till you don'
MRAB makes a valid point. The regular expression compiled is only done on the
pattern you are looking for and it it contains anything that might be a
command, such as an ^ at the start or [12] in middle, you want that converted
so NONE OF THAT is one. It will be compiled to something that looks
Karsten,
There are limits to the disruption a group should tolerate even from people
who may need some leeway.
I wonder if Hen Hanna has any idea that some of the people he is saying this
to lost most of their family in the Holocaust and had parents who barely
survived passing through multiple co
I am not a big fan of religions or philosophies that say a road to salvation is
for the "I" to disappear.
But on a more serious note, as Roel said, there is NO RULE being violated
unless the documentation of the language says it is supposed to do something
different.
There are many excellent r
Only sometimes.
Is it an insult to suggest the question about what quotes to use is quite
basic? Python has a wide variety of ways to make a string and if you have text
that contains one kind of quote, you can nest it in the other kind. Otherwise,
it really does not matter.
And, yes, there are
I so rarely need to save a list in python in a form acceptable to LISP but here
is a go with no visible recursion needed.
>>> nested = [1, 2, [3, 4, [5, 6, 7], 8], 9]
>>> print(nested)
[1, 2, [3, 4, [5, 6, 7], 8], 9]
# Just converting to a tuple does not change nested lists
>>> print(tuple(nest
Alan,
Good tack. By not welcoming someone who is paranoid about being welcomed you
are clearly the right kind of welcoming!
Kidding aside, you have a point about one of the barrage of messages
probably not getting a great answer on your tutor forum. It is the MANY
messages often about fairly simp
Greg,
Yes, the forum should be open. The first requests from the person were
replied to politely.
At some point a pattern was emerging of lots of fairly irreverent posts by
someone who is having trouble shifting programming paradigms. The suggestion
was then made as a SUGGESTION by several people
Mark,
I was very interested in the point you made and have never thought much about
string concatenation this way but adjacency is an operator worth using.
This message has a new subject line as it is not about line continuation or
comments.
From what you say, concatenation between visibly adj
Greg,
I do not advocate for writing extremely concise python as mentioned in that
book although I was quite interested and do use some of the methods.
But I worry about what you focused in on. Everyone says a picture is worth a
thousand words. So when writing about python one-liners, you might s
We have been supplying many possible reasons or consequences for why the
implementation of python does not do what the OP wants and even DEMANDS.
I am satisfied with knowing it was because they CHOSE NOT TO in some places
and maybe not in others. It is nice to see some possible reasons, but
someth
Many "warnings" can safely be ignored.
The function as shown does not look right. I assume it is just an example, but
a function that ignores the argument supplied is already a tad suspect.
Since it is SUGGESTED that the variable name "self" normally is used in a
method for a class/instance, it
Good example, Rob, of how some people make what I consider RELIGIOUS edicts
that one can easily violate if one wishes and it makes lots of sense in your
example.
Let me extend that. The goal was to store a character string consisting of
multiple lines when printed that are all left-aligned. Had
Rob,
There are lots of nifty features each of us might like and insist make much
more sense than what others say they want.
Sometimes the answer is to not satisfy most of those demands but provide
TOOLS they can use to do things for themselves.
As you agree, many of us have found all kinds of to
Rob,
It depends. Some purists say python abhors one liners. Well, I politely
disagree and I enjoyed this book which shows how to write some quite compressed
one-liners or nearly so.
Python One-Liners: Write Concise, Eloquent Python Like a Professional
Illustrated Edition
by Christian Mayer (Au
Grant,
I am not sure it is fair to blame JSON for a design choice.
Use of commas can be done many ways in many contexts.
One context is a sort of placeholder. Can you have a language where a
function has multiple arguments and you can skip some as in:
Func(a,b,c)
Func(a, b,)
Func(a,,)
Or even
That is a reasonable use, Rob, albeit I would refactor that example in quite a
few ways so the need for a semicolon disappears even for lining things up.
So to extrapolate, perhaps a related example might be as simple as wanting to
initialialize multiple variables together might suffice as in:
Greg,
How did you know that was the method I used to indicate I had properly
debugged and tested a line of code?
a = 5; pass
b = 7; pass
c = a * b; pass
Then I switched to using comments:
a = 5 # pass
b = 7 # pass
c = a * b # fail
And would you believe it still worked!
OK, I am just kidding
That seems like a reasonable if limited use of a semi-colon, Thomas.
Of course, most shells will allow a multi-line argument too like some AWK
scripts I have written with a quote on the first line followed by multiple
lines of properly formatted code and a closing quote.
Python though can get to
Thomas,
This is one of many little twists I see between languages where one feature
impacts use or even the need for another feature.
So can anyone point to places in Python where a semicolon is part of a best
or even good way to do anything?
Some older languages had simple parsers/compilers tha
Hen or Hanna,
You keep asking WHY which may be reasonable but hard or irrelevant in many
cases.
I find the traceback perfectly informative.
It says you asked it to print NOT just "a" but "a + 12" and the error is
coming not from PRINT but from trying to invoke addition between two objects
that h
HH,
Just FYI, as a seeming newcomer to Python, there is a forum that may fit
some of your questions better as it is for sort of tutoring and related
purposes:
https://mail.python.org/mailman/listinfo/tutor
I am not discouraging you from posting here, just maybe not to overwhelm
this group with m
Axy,
Nobody denies some of the many ways you can make a good design. But people
have different priorities that include not just conflicts between elements
of a design but also equally important factors like efficiency and deadlines
and not breaking too badly with the past.
You can easily enough d
There are limits to anyone arguing for designs to be the way they want or
expect and Roel has explained this one below.
When it comes to designing a function, lots of rules people expect are beyond
irrelevant. Many functions can be implemented truly hundreds of ways with
varying numbers of argu
There is a very common misunderstanding by people learning python that a
tuple has something to do with parentheses. It confused me too at first.
A tuple is made by the use of one or more commas and no parentheses are
needed except when, like everything else, they are used for grouping as in
the a
Tuples are immutable and sort of have to be created all at once. This does
not jive well wth being made incrementally in a comprehension. And, as
noted, the use of parentheses I too many contexts means that what looks like
a comprehension in parentheses is used instead as a generator.
If you reall
MRAB,
I made it very clear I was using the translation provided by Google Translate.
I copied exactly what it said and as I speak the languages involved, they
seemed reasonable. I often find it provides somewhat different translations
than I expect and sometimes I need to supply a longer sente
It is not an unusual pattern, Thomas, to do something selective to some object
rather than do all parts just one way.
The history of computing has often been one where you had to deal with scarcity
of expensive resources.
Consider the Python "list" as a rather wasteful container that is best us
David,
This conversation strikes me as getting antagonistic and as such, I will not
continue it here after this message.
I can nitpick at least as well as you but have no interest. It is also
wandering away from the original point.
The analogy I gave remains VALID no matter if you do not accept
Peter,
Analogies I am sharing are mainly for me to wrap my head around an idea by
seeing if it matches any existing ideas or templates and is not meant to be
exact. Fair enough?
But in this case, from my reading, the analogy is rather reasonable. The
implementation of Roaring Bitmaps seems to log
Stephen,
What response do you expect from whatever people in the IEEE you want?
The specific IEEE standards were designed and agreed upon by groups working
in caveman times when the memory and CPU time were not so plentiful. The
design of many types, including floating point, had to work decently
I am less interested in the choice of names than the pro and con of when these
Roaring bitmaps are worth using and when they are not.
It is a bit like discussing whether various compression techniques are worth
using as the storage or memory costs can be weighed against the CPU or
transient mem
Chris,
That is a nice decorator solution with some extra features.
We don't know if the OP needed a cache that was more general purpose and
could be accessed from multiple points, and shared across multiple
functions.
-Original Message-
From: Python-list On
Behalf Of Chris Angelico
Se
Dino,
If your question is understood, you want to treat a dictionary as a sort of
queue with a maximum number of entries. And, you want to remove some kind of
least useful item to make room for any new one.
Most dictionaries now have entries in the order they were entered. There may
already be so
Weatherby,
Of course you are right and people can, and do, discuss whatever they feel like.
My question is a bit more about asking if I am missing something here as my
personal view is that we are not really exploring in more depth or breadth and
are getting fairly repetitive as if in a typical
There are no doubt many situations someone wants to know how long something
will be when printed but often at lower levels.
In variable-width fonts, for example, the number of characters does not
really line up precisely with how many characters. Some encodings use a
varying number of bytes and, a
Bart,
Some really decent cron jobs can be written without using anything complex.
I get it now that perhaps your motivation is more about finding an excuse
to learn python better. The reality is there is not much that python cannot
do if other programming languages and environments can do them s
Bart, you may want to narrow down your request to something quite specific.
For example, try to do whatever parts you know how to do and when some part
fails or is missing, ask.
I might have replied to you directly if your email email address did not
look like you want no SPAM, LOL!
The cron stuf
I think its has been discussed here that many functions are DELIBERATELY
designed to return without returning anything. Earlier languages like Pascal
had explicit ideas that a function that did not return a value was declared
as a "procedure" but many other languages like python make no real
differ
Cameron,
You are technically correct but perhaps off the mark.
Yes, a python program only sees what is handed to it by some shell if invoked a
certain way.
The issue here is what you tell people using your program about what they need
to type to get it to work. That means if their shell is goi
Although today you could say POSIX is the reason for many things including
the use of "--" I hesitate to mention I and many others used that convention
long before as a standard part of many UNIX utilities. Like many other such
things, you build things first and by the time you standardize, ...
-
Jack,
I get uneasy when someone thinks a jackhammer is a handy dandy tool for pushing
in a thumbtack that is sitting on my expensive table.
I agree it is quite easy to grab some code that does lot of things and also
does something truly minor, and use it for that purpose. Sometimes the cost is
; or "F" then perhaps
they would allow Booleans to be treated as characters and let them be
concatenated to strings and so on.
-Original Message-
From: Python-list mailto:python-list-bounces+avi.e.gross=gmail@python.org> > On Behalf Of
Grant Edwards
Sent: Sat
1 - 100 of 169 matches
Mail list logo