Nati,
I know you think you are communicating.
שטרן >> I want to swap indexes of dict
When you say SWAP, do you mean replace the index with something else, or swap
the key and value or something entirely else?
You have not shared an example of what is in your dictionary, but say it is:
That is more detailed, Nati, albeit I may not still understand.
You are working on a detailed project you may have some understanding of and
getting stuck. But the people you ask for help do not have your info and,
worse, your code seems full of blunders based on making assumptions, so readin
Dennis,
I see Nati sent some more code without explaining again what he wants. Yes,
somewhere in this stack of messages he may have said things (that we generally
failed to understand) but it would be helpful to summarize WHY he sent us what
he did or which lines to look at.
If your suggestio
Nati,
You ask what the problem is in that code. I say there I absolutely NO PROBLEM
for me in that code.
Do you know why?
Because even if I want to copy it and make sure I have all the modules it
needs, I have no access to the files it opens, and no idea what the output of
the images pumped i
I guess Dan, that he may not be seeing what he is working on as a list of
lists of lists with each terminal sublist being of cardinality 4. Maybe
Zhao could look up what methods a list object has that allow you to place
additional items, such as a list of 4 numbers, at the beginning or end or in
m
Dennis, I am replying to the group but mainly you as I doubt Nati really
reads much of what we write.
The use of list() is needed as what comes out of the function may be an
object of type dict_keys which is iterable but if you want it in a list form
all at once, the idiom he uses is common. In th
Do you know of a library that resolves schedules like every Wednesday
at 3:00pm to absolute time, that is return the datetime of the next
occurrence?
It may be as simple, as this to add seven days, assuming a slip of a second
is not important or even a hour when things change.
Enddate = Beg
Albert-Jan,
Unless there is something special in your scenario, aren't there many ways
within python proper to create functions that effectively call another
function or more as needed? Think decorators as one example.
Of course if the caller expects some specific result when it calls your
functi
To be clear, the discussion strikes me oddly.
You can learn python without a computer. Of course to actually have people
write code and try it out is another story.
Python by itself is simply a program that can be typed into an interpreter
or given a file to process and works just as well on LINU
Benchmarking aside, Lori, there are some ideas about such things.
You are describing a case, in abstract terms, where an algorithm grinds away
and produces results that may include an occasional or a common unwanted
result. The question is when to eliminate the unwanted. Do you eliminate
them imme
I wonder if someone is pulling our leg as they are sending from an invalid
email address of "GB " which is a bit sick.
I have trouble imagining ANYONE learning a language like python without
rapidly being told that python uses indentation instead of various ways to
detect when a body of text is co
I had considered that, Dave. Albeit others did at least put in some
three-dot markers to show there was other code between the three lines
shown.
But the same silly argument they used applies elsewhere. Consider nested
calls like:
Delta(Gamma(Beta(Alpha)))
Now say one of those functions takes an
This reminds me a bit of how routine spelling checkers and often especially
grammar checkers, generate so many suggestions about mistakes as to become
ignored. If you are writing using lots of names and jargon that keep getting
flagged as errors and they are spelled or used exactly as you want, the
Stefan,
You are correct that the goal of a lock is to do something rather quickly
and atomically, so your design should not do something complex or long
before releasing the lock.
In your example, you have a producer adding data as regularly as every
second and another that wakes up rarely and pr
There are many possible discussions we can have here and some are not really
about whether and how to use Python.
The user asked how to do what is a fairly standard task for some people and
arguably is not necessarily best done using a single application running
things in parallel.
So, yes, if y
How long?
Not fibbing but infinite is infinite and I simply so not have the time.
This is so such an EASY question that you need to show some work to interest
us.
You can do this in ANY programming language so explain if there is a reason
you ask here or ...
The real question is what you want.
Subject: searching for books by an author you like on rather unrelated
topics.
I am curious if you normally look or books by a writer of Mysteries you like
to see if they also wrote Science Fiction or Cookbooks and so on?
Having said that, there are plenty of people in the Computer Science field
Maybe we should ask WHY the person asking the question about how to learn a
computer language called Python is pairing it with the idea of whether to
also learn C.
What are they preparing for? Most people using Python have absolutely no
reason to learn C, or C++ or C# or JAVA or one of a bewilder
Chris,
I started with BASIC in high school and kept shifting my focus from one
computer language to another long before I even looked at Python.
Arguably each language had a REASON for existing so it supported some ideas
or paradigms or ways of looking at things. Many at first were rather focuse
Nati,
If you thought a bit first, you might remember this mailing list does not
forward attachments so we are not seeing the image you called image.png and
you neglected to also give us some text telling us what exception you saw or
lots of additional details that might help.
And, just FYI. Using
>From your description, Chris, it sounds like the functional programming
technique often called currying. A factory function is created where one (or
more) parameters are sort of frozen in so the user never sees or cares about
them, and a modified or wrapped function is returned. In this case, th
[This is an answer for Peter and can easily be skipped by those who know or
have no wish to.]
Strictly speaking Peter, the word "pipe" may not mean quite something in
Python but other concepts like chaining may be better.
The original use of the word I am used to was at the UNIX shell level where
I won't reply to everything Dave says and especially not the parts I fully
agree with.
I think in many situations in life there is no ONE way to do things so most
advice is heuristic at best and many exceptions may exist depending on your
chosen approach. As such, I do not really think in PYTHO
>>>Which is more disparaging: "I couldn't find anyone suggesting this" or
"The only place I could find it was a PHP style guide"?
>>>ChrisA
Chris,
If someone says they heard something from their own personal guru, people
often do not feel threatened or argue. I often am told nutrition or medical
Cameron,
Your suggestion makes me shudder!
Removing all earlier lines of code is often guaranteed to generate errors as
variables you are using are not declared or initiated, modules are not
imported and so on.
Removing just the line or three where the previous error happened would also
have a g
Chris, a short(er) answer to your addition below.
I did not at first share your perception but maybe do now. If the argument
was that ELSE and other constructs like FINALLY or CATCH are horrible
because they follow other code and important things should be first, that is
a silly argument. Many are
I just want to get clear on what may be a side issue
The suggestion is that a loop with an ELSE clause only makes sense if the
user can BREAK out without finishing, right?
My first question is whether a warning or even error makes sense if there is
no BREAK statement anywhere in the loop but ther
Michael,
A reasonable question. Python lets you initialize variables but has no
explicit declarations. Languages differ and I juggle attributes of many in
my mind and am reacting to the original question NOT about whether and how
Python should report many possible errors all at once but how ANY la
Cameron, or OP if you prefer,
I think by now you have seen a suggestion that languages make choices and
highly structured ones can be easier to "recover" from errors and try to
continue than some with way more complex possibilities that look rather
unstructured.
What is the error in code like thi
I stand corrected Chris, and others, as I pay the sin tax.
Yes, there are many kinds of errors that logically fall into different
categories or phases of evaluation of a program and some can be determined
by a more static analysis almost on a line by line (or "statement" or
"expression", ...) bas
I think we are in agreement here, Chris. My point is that the error
detection and correction is now done at levels where there is not much need
to use earlier and inefficient methods like parity bits set aside. We use
protocols like TCP and IP and layers above them and above those to maintain
the i
Thanks for a rather detailed explanation of some of what we have been
discussing, Chris. The overall outline is about what I assumed was there but
some of the details were, to put it politely, fuzzy.
I see resemblances to something like how a web page is loaded and operated.
I mean very different
Anton,
Your example overlaps with the use of generators in Python to do variants of
the same pipeline ideas.
But is that native python or some extension where "|" has been modified to
mean something other than a form of OR in some places? What module do you
need to load to make that happen?
I t
This has been discussed so often precisely because I swear NO CHOICE of keyword
would satisfy everybody! Most languages start with designated keywords and some
reserve a few for later use. But then things can get frozen in place to avoid
breaking existing programs or break older compilers/interp
Realistically an idea about something new is easier to consider than
changing what you have.
Some newer languages may well be designed from the start in new ways and
Julia is an example of a language that allows a wide swath of UNICODE
characters to be used in identifiers. They also let you type t
My point Chris was that you can have a conversation where you are exploring
and not proposing. Brainstorming, perhaps.
I was saying that there are many ways to signal things and in some
hypothetical new language, it may be implemented in novel ways that do not
break anything.
I note languages lik
Cameron,
What would be the meaning of an ordering relation determining what is MORE
VALID?
As has been pointed out, not only are some uses that look odd sometimes
valid, but perhaps even can be used in ways you simply may not see, such as
side effects. Some examples ranging from poor to horrible
That is clear, Cameron, but on my python interpreter values evaluated on the
command line ARE saved:
>>> numb = 5
>>> 5 + numb
10
>>> numb
5
>>> _ + _ + 1
11
>>> _ * 2
22
>>>
The point is that a dummy variable of _ is assigned and re-assigned at each
step and there can be a valid, if not very us
Yes, Chris, that is a REPL feature and one that people may use
interactively.
As you note, it does not work inside something like a function which the
REPL is not trying to evaluate and print. So clearly my supposed use would
not make much sense in such code.
-Original Message-
From: Pyt
Unless someone is counting lines of code for some purpose, like number of
error found per thousand lines of code, many short one-liners strike me as
more readable and especially if followed by a blank line so it is a bit
obvious.
Consider a similar issue in many languages that use curly braces and
Multiple returns is not always a problem as it depends on the nature of a
task whether it has complex enough cases.
I have seen code that instead sets Boolean variables when it is ready to
return and everything else keeps checking the variables to skip further
processing so the program then slide
As often seems to happen, someone asks something that may not be fully clear
and others chime in and extend the question.
Was the original question how to read in a ingle column of numbers from a file
that are all numeric and NOT integers and be able to use them?
If so, the answer was quite tri
I happen to be of two schools here.
Is something sort of taboo when using something like a computer language to
write a program? What if another language tells you to do it a different way or
sort of the opposite? Is it based on the details of the language and
implementation or the prejudices o
Ian,
Do you have some examples of things you can put in a set that you consider
equal but want to store in the set INSTEAD of any current element?
What follows is some thoughts on some methods you could build yourself.
Others re possible and someone else may present you with a module that does
wh
It depends on what people consider too complicated.
I find it a tad complicated when someone posts using two different ID, and
then wonders ...
The question related to taking a list and extending it and using the result
in an assignment statement.
There were several inter-related questions peopl
Agreed, there are lots of pro/con arguments and the feature is what it is
historically and not trivial to change. Inline changes to an object make
sense to just be done "silently" and if there are errors, they propagate the
usual way.
As Guido was a major influence at that time, one view was see
Chris,
There is much to say about consistent behavior as compared to flexibility
and convenience.
I have seen other languages provide functions for example, where the result
can vary and often cause confusion. R had a function that would sometimes
notice the result could be simplified and return
Several of you have mentioned the role of history in the development of
languages and what the founders of a language were trying to improve.
As noted with PASCAL, some earlier languages strived to be different things
and in a certain sense, their procedures were perhaps seen as a safer and
better
Thomas,
I used PASCAL before C and I felt like I was wearing a straitjacket at times
in PASCAL when I was trying to write encryption/decryption functions and had
to find ways to fiddle with bits. Similar things were easy in C, and are
even easier in many more recent languages such as Python.
The
Not to wax poetic about our pasts, Thomas, but I do did not start with
PASCAL and used quite a few languages before and plenty after. At the time
it had interesting contrasts to languages like BASIC, FORTRAN and LISP and I
tended to use whatever was available on the machines I was using. My first
c
Well explained, Roger.
Your explanation reminds me why some languages very deliberately do not want
the C operators of pre/post increment/decrement.
Similar to your argument, code in C like:
Y = X++
Or
Y = ++X
And similarly the -- versions, have a sort of side effect of changing X
either before
Alan,
I stand corrected as my path never led me back to any form of PASCAL. And,
frankly, my path rarely led me again to having to do what we describe as
twiddling bits with the minor exception when doing something like setting the
bits needed to specify what permissions should be associated wi
Jen,
It is dangerous territory you are treading as there are times all or parts of
objects are copied, or changed in place or the method you use to make a view is
not doing quite what you want.
As an example, you can create a named slice such as:
middle_by_two = slice(5, 10, 2)
The above is
Jen,
This may not be on target but I was wondering about your needs in this
category. Are all your data in a form where all in a cluster are the same
object type, such as floating point?
Python has features designed to allow you to get multiple views on such objects
such as memoryview that can
ject holding indices to a series such as
integers or Booleans and then later try using it after the number of items or
rows or columns have changed. Your indices no longer match.
Avi
-Original Message-
From: Python-list mailto:python-list-bounces+avi.e.gross=gmail@python.org
Axel and others,
I can appreciate the comparison to a partially applied function but not in
this case. Not that it matters, but this example is more like creating an
object in something like machine learning and initializing parameters
without adding data. Only when you ad data and call upon some
I can appreciate a beautiful piece of code but I can also appreciate another
piece of code that does things in another pleasing way so there is quite a
bit of subjectivity here.
And, in yet another computer language, the implementation of what seems to
be the same algorithm is somewhat jarring as
<<< Frank Millman>>> My 'aha' moment came when I understood that a python
object has only three properties - a type, an id, and a value. It does *not*
have a name.
Yes, Frank, it is a bit like how some people need to wrap their minds around a
concept like an anonymous function. It has no name a
Just FYI, the example Dave supplied was not using python code and using a
rather strange re-definition in the R language package he was using. Or
maybe not.
Anyone not interested, skip the rest.
First, R does not use indentation for almost anything. So you can break one
long line up into many lin
I stand corrected. Thomas is (mostly) writing valid Python if you use the
module that looks (deliberately) like the R implementation. The use of "+"
in two contexts such as when not needed to concatenate strings, reminded me
too much of R.
Either way, this thread has moved on from any original que
If I understood the issue, the problem is the unary minus at the start of the
expression.
So if you know the expression is in that argument, would it make sense to pad
it in one of many ways that are otherwise harmless?
Could you put parens on both sides of "-4^2+5.3*abs(-2-1)/2":
"(-4^2+5.3*
Python yet again is being asked why something is the way it is and not as
someone insists it should be. It is a tool to be used the way it SAYS it
works so the bug is perhaps in the user and their expectations.
It is what it is and would break lots of things if changed without much
thought. Every
Thomas,
I changed the subject line as we are not talking about bool and int anymore.
For me, there are several sides to JAVA that go beyond the "language" to the
JVM, or Java Virtual Machine. What you are describing is an example of
interoperability you can get if your language also is built on
Dino,
There is no such things as a "principle of least surprise" or if you insist
there is, I can nominate many more such "rules" such as "the principle of
get out of my way and let me do what I want!"
Computer languages with too many rules are sometimes next to unusable in
practical situations.
Chris,
We generally agree albeit I have a question in python with the concept of
being truthy that results in either a Boolean value that boils down to 0 and
1 but in some cases may boil down to the last evaluated argument which
remains in a form that may not be either a Boolean or an integer. I t
Like Chris, I appreciate precision when it matters but since I am not
writing a textbook here, I often talk more informally.
There are many variations on now variables or objects are treated
differently in certain languages and when I said "STRONG" I simply meant a
sort of opposite to "WEAK". I co
Gerard,
I am sure there is. I have been on many forums that discuss programming
languages and since nothing is perfect and people differ in many ways, there
is always grumbling and comparison.
If we all agreed and there was only one of something, I suspect we still
would complain and that is prec
[Dino has a deliberately invalid email address so sending him anything
privately is not an option.]
Dino,
I would agree with you that for some purposes, you do NOT need to dig deep
into a language to get fairly routine things done. You can often borrow
ideas and code from an online search and hop
May I point out that some dynamic situations can in a sense be normalized?
The example below posits a dynamically allocated dictionary during run time.
But why can't you have a placeholder variable name in place and make your
placeholder a link to the dictionary (or other item) before invoking the
; 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
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
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, ...
-
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 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:
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
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
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
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
1 - 100 of 169 matches
Mail list logo