Re: [SOLVED] Re: Compare zip lists where order is important
will find the added pairs, but ignore the removed ones. Is that what you want? Yes, I think. I want to find the changed pairs. The people that moved team numbers. Sayth -- https://mail.python.org/mailman/listinfo/python-list
Re: [SOLVED] Re: Compare zip lists where order is important
Sayth Renshaw wrote: > will find the added > pairs, but ignore the removed ones. Is that what you want? > > Yes, I think. I want to find the changed pairs. The people that moved team > numbers. To find the people that moved team numbers I would tear the pairs apart. Like: >>> people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"] >>> team_number = [1,1,2,2,3,3] >>> shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"] >>> shuffle_team_number = [1,1,2,2,3,3] >>> old = dict(zip(people, team_number)) >>> new = dict(zip(shuffle_people, shuffle_team_number)) >>> for name in old.keys() & new.keys(): ... old_team = old[name] ... new_team = new[name] ... if old_team != new_team: ... print(name, "went from", old_team, "to", new_team) ... Tim went from 1 to 2 Fredricka went from 3 to 1 Ally went from 2 to 3 -- https://mail.python.org/mailman/listinfo/python-list
Re: unable to to install paython
On Thu, Aug 29, 2019 at 12:51 AM Alemu Geletew via Python-list wrote: > Hmm - - - - somehow you think that other members of this list can somehow understand what you did do - - - - without you even telling them. As my crystal ball (for future readings and such) hasn't ever worked it would be far more likely that you would get assistance if you would describe what you 'have' done and then it might be possible to guide you to what you could do to achieve what you wish. Regards -- https://mail.python.org/mailman/listinfo/python-list
Re: if STREAM.isatty():
On 29/08/2019 04:40, Hongyi Zhao wrote: Hi, I read the following code: https://github.com/shichao-an/homura/blob/master/homura.py On the line 265-266, it said: if STREAM.isatty(): p = (self.progress_template + '\r') % params What's mean by using the above two lines? Can I not use them? If you don't understand them, you definitely shouldn't use them. So let's fix that :-) "isatty()" is a method of the io.IOBase class that checks to see if the stream is connected to a tty, or to use less jargon, if it is interactive. "tty" was I think originally an abbreviation for "teletype", but nowadays it refers to any terminal, anywhere you get a command line prompt. See https://docs.python.org/3/library/io.html#io.IOBase.isatty The next line gives you a cheap and cheerful progress message. I haven't looked at the rest of the code, but I imagine "self.progress_template" gets set somewhere with a string rather like "%d%% complete". What the expression does is add a carriage return character to the end of the string (but *not* a line feed -- remember that, it will be important in a minute), then the % operator formats the string (see https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting) using the information in "params". This is easiest to show by example. Suppose "self.progress_template" is "%d%% complete" as I suggested, and "params" is 1. Then "p" becomes the string "1% complete\r" (where \r is the carriage return character). Presumably a little later the code does STREAM.write(p) which will write "1% complete" to the terminal and then put the cursor (the "writing point") back to the start of the line. Since there is no carriage return character, it does *not* move on to a new line. The next time we call this code, say with params = 2, we write out "2% complete" over the top of the previous message, obliterating the old text. The cursor is once again at the start of the line, so we can carry on with "3% complete", "4% complete" and so on. TLDR: these two lines set up (but don't output) a progress message for an interactive stream. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list
Re: if STREAM.isatty():
On Thu, 29 Aug 2019 13:23:07 +0100, Rhodri James wrote: > TLDR: these two lines set up (but don't output) a progress message for > an interactive stream. Thanks a lot for your deeply notes on this. But, if so, when will the ``else ...'' be executed in the original code: if STREAM.isatty(): p = (self.progress_template + '\r') % params else: current_time = time.time() if self._last_time == 0.0: self._last_time = current_time else: interval = current_time - self._last_time if interval < 0.5: return self._last_time = current_time p = (self.progress_template + '\n') % params STREAM.write(p) STREAM.flush() Regards -- https://mail.python.org/mailman/listinfo/python-list
Re: if STREAM.isatty():
On 29/08/2019 14:37, Hongyi Zhao wrote: On Thu, 29 Aug 2019 13:23:07 +0100, Rhodri James wrote: TLDR: these two lines set up (but don't output) a progress message for an interactive stream. Thanks a lot for your deeply notes on this. But, if so, when will the ``else ...'' be executed in the original code: When the stream isn't connected to an interactive terminal, obviously. For example, when it's writing to file. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list
Re: if STREAM.isatty():
On 8/29/19, Rhodri James wrote: > > "isatty()" is a method of the io.IOBase class that checks to see > if the stream is connected to a tty, or to use less jargon, if it is > interactive. "tty" was I think originally an abbreviation for > "teletype", but nowadays it refers to any terminal, anywhere you > get a command line prompt. In Windows, isatty() is true for any character-type file. This does not necessarily mean an interactive stream. In particular, NUL is a character device: C:\>python -c "import sys;print(sys.stderr.isatty())" 2>NUL True But a pipe is not: C:\>python -c "import sys;print(sys.stderr.isatty())" 2>&1 | more False -- https://mail.python.org/mailman/listinfo/python-list
Re: pandas loc on str lower for column comparison
Sayth Renshaw writes:
> Hi
>
> I am importing 4 columns into a dataframe from a spreadsheet.
>
> My goal is to create a 5th column with TRUE or False if column 4 (str)
> matches column 3.
>
> Trying to leverage this answer https://stackoverflow.com/a/35940955/461887
>
> This is my code
>
> import pandas as pd
>
> xls = pd.ExcelFile("Melbourne.xlsx")
> df = xls.parse('Sheet1', skiprows= 4)
> df1 = df[['UID','Name','New Leader','Current Team', 'New Team']]
> df1['Difference'] = df1['Current
> Team'].str.lower().str.replace('s/+',"") == df1['New
> Team'].str.lower().str.replace('s/+',"")
>
> Which gives this error
>
> C:\Users\u369811\AppData\Local\Continuum\anaconda3\lib\site-packages\ipykernel_launcher.py:6:
> SettingWithCopyWarning:
> A value is trying to be set on a copy of a slice from a DataFrame.
I think what happens is that df1 is not a copy of the subset of df that you
want, but it is a VIEW on df instead. This means that df1 shares memory with df
(for memory savings reasons). But if you would change this view by adding a
column, where should it be put? In df? If so, where?
So the correct way to do this is to make df1 a copy rather than a view.
df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')]
And than it should work.
Except that the str.replace is wrong for what you want. It just replaces the
literal string "s/+" with an empty string instead of white space. This was
wrong in the stackoverflow post.
To replace whitespace it should be str.replace('\\s+',"", regex=True). But
simpler is to use str.strip():
df1['Difference'] = df1['Current Team'].str.lower().str.strip() == df1['New
Team'].str.lower().str.strip()
--
Piet van Oostrum
WWW: http://piet.vanoostrum.org/
PGP key: [8DAE142BE17999C4]
--
https://mail.python.org/mailman/listinfo/python-list
Re: pandas loc on str lower for column comparison
Piet van Oostrum writes:
> So the correct way to do this is to make df1 a copy rather than a view.
>
> df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')]
Or maybe even make an explicit copy:
df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy()
--
Piet van Oostrum
WWW: http://piet.vanoostrum.org/
PGP key: [8DAE142BE17999C4]
--
https://mail.python.org/mailman/listinfo/python-list
Re: if STREAM.isatty():
On Thu, 29 Aug 2019 14:51:43 +0100, Rhodri James wrote: > When the stream isn't connected to an interactive terminal, obviously. > For example, when it's writing to file. But I cannot see any thing like this in the code. Regards -- https://mail.python.org/mailman/listinfo/python-list
Re: if STREAM.isatty():
On 29/08/2019 16:29, Hongyi Zhao wrote: On Thu, 29 Aug 2019 14:51:43 +0100, Rhodri James wrote: When the stream isn't connected to an interactive terminal, obviously. For example, when it's writing to file. But I cannot see any thing like this in the code. I don't understand what's to not to understand. if condition: do_something_because_condition_is_true() else: do_something_because_condition_is_false() is a perfectly normal construction. If you mean something else, please be explicit. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list
Re: An "Object" class?
Thank you! For some reason I didn't think of using issubclass and isinstance in my Python types investigation. As you may have already noticed, I am a Python beginner. I also happen to have a Logic and Foundations of Mathematics background, hence I am tempted to investigate Python's type taxonomy from a basic mathematical angle, with an eye to "recovering" basic mathematical notions such as set membership, set inclusion etc. So far, I have been living under the impression that type() is akin to set membership (in a meta-Python approach), hence it should ideally match the results of isinstance(), but that does not happen: >>> type(print) >>> isinstance(print, builtin_function_or_method) Traceback (most recent call last): File "", line 1, in NameError: name 'builtin_function_or_method' is not defined Just curious why builtin_function_or_method doesn't work as an argument of isinstance(). After all, builtin_function_or_method is a type, right? The bottom line is that I am trying to figure out where exactly the world of Python types _diverges from_ what I would expect as a mathematician. It makes it easier for me to learn Python this way. Many thanks, C On Wed, Aug 28, 2019 at 11:56 PM Alan Bawden wrote: > Cristian Cocos writes: > > > Thank you! I can see that the taxonomy of built-in classes (i.e. the > > subclass/superclass relations) is not very developed. At the very least I > > would have loved to see stuff such as int declared as a subClass/subType > > of float and the like--that is, a class taxonomy in tune with standard > > mathematical practice, but I am guessing that mathematical kosher-ness > had > > to take a back seat to implementational concerns. > > Except that numbers of type `int' are _not_ a subset of numbers of > type `float'! Some ints are much larger that the largest float. > > In fact, both `int' and `float' are subclasses of `numbers.Real'. While it > is true that `numbers.Real' does not appear in the list returned by > `type.mro(int)', nevertheless `issubclass(int, numbers.Real)' and > `isinstance(2, numbers.Real)' are true. `type.mro' tells you something > about the _implementation_ of `int' and `float' that you _usually_ > shouldn't > concern yourself with. Stick to `isinstance' and `issubclass' and > everthing looks pretty kosher. > > -- > Alan Bawden > -- > https://mail.python.org/mailman/listinfo/python-list > -- "People think that I must be a very strange person. This is not correct. I have the heart of a small boy. It is in a glass jar on my desk." -- Stephen King -- https://mail.python.org/mailman/listinfo/python-list
Re: Python unit test framework to fire 1000 unique concurrent requests (rmlibre)
If you want to try out some libraries to build your own tests, you could try aiohttp, aiodns, and asyncio. The requests using these libraries are made asynchronously, not completely in parallel, but produce a similar effect at lower cost. Some examples and docs on these can be found here: https://docs.aiohttp.org/en/v2.3.5/ I also recently came across this talk where the author created a server to resolve 100 million requests to a server using asyncio. You can find the talk here: https://www.youtube.com/watch?v=Mj-Pyg4gsPs Also, Raymond Hettinger gave a talk on useful testing modules, which could be helpful in deciding how to create your tests: https://www.youtube.com/watch?v=ARKbfWk4Xyw On 2019-08-29 16:00, [email protected] wrote: > Send Python-list mailing list submissions to > [email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > [email protected] > > You can reach the person managing the list at > [email protected] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > >1. Re: Python unit test framework to fire 1000 unique concurrent > requests (Pankaj Jangid) >2. Re: How do I decouple these two modules? (Andrea D'Amore) >3. Re: An "Object" class? (Cristian Cocos) >4. Re: An "Object" class? (Chris Angelico) >5. Fwd: installation problem (fateme jbr) >6. Re: Fwd: installation problem (DL Neil) >7. Re: How to use regex to search string between {}? (Jason Friedman) >8. Compare zip lists where order is important (Sayth Renshaw) >9. Re: How to use regex to search string between {}? (Sayth Renshaw) > 10. if STREAM.isatty(): (Hongyi Zhao) > 11. Re: An "Object" class? (Alan Bawden) > 12. Re: Compare zip lists where order is important (Sayth Renshaw) > 13. Re: Compare zip lists where order is important (Sayth Renshaw) > 14. [SOLVED] Re: Compare zip lists where order is important > (Sayth Renshaw) > 15. pandas loc on str lower for column comparison (Sayth Renshaw) > 16. unable to to install paython (Alemu Geletew) > 17. Re: [SOLVED] Re: Compare zip lists where order is important > (Peter Otten) > 18. Re: Compare zip lists where order is important (Frank Millman) > 19. Re: Compare zip lists where order is important (Frank Millman) > 20. Re: [SOLVED] Re: Compare zip lists where order is important > (Sayth Renshaw) > 21. Re: [SOLVED] Re: Compare zip lists where order is important > (Peter Otten) > 22. Re: unable to to install paython (o1bigtenor) > 23. Re: if STREAM.isatty(): (Rhodri James) > 24. Re: if STREAM.isatty(): (Hongyi Zhao) > 25. Re: if STREAM.isatty(): (Rhodri James) > 26. Re: if STREAM.isatty(): (Eryk Sun) > 27. Re: pandas loc on str lower for column comparison > (Piet van Oostrum) > 28. Re: pandas loc on str lower for column comparison > (Piet van Oostrum) > 29. Re: if STREAM.isatty(): (Hongyi Zhao) > 30. Re: if STREAM.isatty(): (Rhodri James) > 31. Re: unable to to install paython (Dennis Lee Bieber) -- https://mail.python.org/mailman/listinfo/python-list
Re: if STREAM.isatty():
On Thu, 29 Aug 2019 16:42:44 +0100, Rhodri James wrote: > I don't understand what's to not to understand. > >if condition: > do_something_because_condition_is_true() >else: > do_something_because_condition_is_false() > > is a perfectly normal construction. If you mean something else, please > be explicit. Let me say it more explicitly: The original code snippet's logic is as follows: if STREAM.isatty(): p = (self.progress_template + '\r') % params else: [do something to reset the new value of p] p = (self.progress_template + '\n') % params STREAM.write(p) STREAM.flush() In order to refresh the tty, the if and else must be run alternatively. i.e., the isatty() must return 0 and 1 periodically. I still understand how the above code will let the isatty() return 0 and 1 in turn? Regards -- https://mail.python.org/mailman/listinfo/python-list
Re: if STREAM.isatty():
On 8/29/2019 8:23 AM, Rhodri James wrote: On 29/08/2019 04:40, Hongyi Zhao wrote: Hi, I read the following code: https://github.com/shichao-an/homura/blob/master/homura.py On the line 265-266, it said: if STREAM.isatty(): p = (self.progress_template + '\r') % params What's mean by using the above two lines? Can I not use them? If you don't understand them, you definitely shouldn't use them. So let's fix that :-) "isatty()" is a method of the io.IOBase class that checks to see if the stream is connected to a tty, or to use less jargon, if it is interactive. "tty" was I think originally an abbreviation for "teletype", but nowadays it refers to any terminal, anywhere you get a command line prompt. See https://docs.python.org/3/library/io.html#io.IOBase.isatty That says "Return True if the stream is interactive (i.e., connected to a terminal/tty device)." AFAIK, the docs do not define 'interactive' or 'terminal/tty device'. The Linux 'isatty(fildes)' man page says "return 1 if fildes is associated with a terminal". I don't know it 'terminal' is defined anywhere. I take 'interactive' as meaning that the stream is one of at least two streams associated with one device such that if the program writes a prompt to an output stream, a response might be received on the corresponding input stream. In python, 'input(prompt)' writes 'prompt' to sys.stdout, reads sys.stdin until '\n' is received, and returns the preceding string. Note that devices differ on whether type-ahead works, and that input calls might never return. When a 'terminal' receives \r, it can ignore it, display something, or act on it by putting the cursor at the beginning of the line if . After moving to the beginning of the line, subsequent chars can overwrite, replace, or be inserted before existing characters, except that \t and \n may get special treatment. The code above assumes 'return' followed by replacement. If that assumption is wrong, as with the original ttys, '\r' instead of '\n' is the wrong choice of terminator. [snip] which will write "1% complete" to the terminal and then put the cursor (the "writing point") back to the start of the line. Since there is no carriage return character, it does *not* move on to a new line. I presume you meant either 'no newline' or 'just a carriage return' -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: pandas loc on str lower for column comparison
On Friday, 30 August 2019 00:49:32 UTC+10, Piet van Oostrum wrote:
> Piet van Oostrum
>
> > So the correct way to do this is to make df1 a copy rather than a view.
> >
> > df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')]
>
> Or maybe even make an explicit copy:
>
> df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy()
Thank you so much.
Sayth
--
https://mail.python.org/mailman/listinfo/python-list
Re: if STREAM.isatty():
On 2019-08-29 23:38, Hongyi Zhao wrote: On Thu, 29 Aug 2019 16:42:44 +0100, Rhodri James wrote: I don't understand what's to not to understand. if condition: do_something_because_condition_is_true() else: do_something_because_condition_is_false() is a perfectly normal construction. If you mean something else, please be explicit. Let me say it more explicitly: The original code snippet's logic is as follows: if STREAM.isatty(): p = (self.progress_template + '\r') % params else: [do something to reset the new value of p] p = (self.progress_template + '\n') % params STREAM.write(p) STREAM.flush() In order to refresh the tty, the if and else must be run alternatively. i.e., the isatty() must return 0 and 1 periodically. I still understand how the above code will let the isatty() return 0 and 1 in turn? No. Either it's outputting to a TTY, or it isn't. If it detects that it's outputting to a TTY, it'll make the progress messages overwrite each other on the same line. This looks better on an interactive terminal than printing many lines and scrolling the display. If it detects that it's _not_ outputting to a TTY (probably a file), it'll write the progress messages one after another. This makes more sense in, say, a log file. -- https://mail.python.org/mailman/listinfo/python-list
Re: if STREAM.isatty():
On 29Aug2019 22:38, Hongyi Zhao wrote: On Thu, 29 Aug 2019 16:42:44 +0100, Rhodri James wrote: The original code snippet's logic is as follows: if STREAM.isatty(): p = (self.progress_template + '\r') % params else: [do something to reset the new value of p] p = (self.progress_template + '\n') % params STREAM.write(p) STREAM.flush() In order to refresh the tty, the if and else must be run alternatively. i.e., the isatty() must return 0 and 1 periodically. I still understand how the above code will let the isatty() return 0 and 1 in turn? No, merely that the test is done every time this code runs. It will normally always return the same value. What you describe above is two distinct implementations of progress reporting, chosen accordin to the nature of the output stream. If the output stream is a terminal, it always writes a progress string and a carriage return, which will return the cursor to the start of the line. Notably, this never scrolls the display. The next call will overwrite what happened before. Otherwise, it writes the progress string and a newline on the premise that the output is a normal text file, such as a log file. So it just wants to write normal lines of text. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: if STREAM.isatty():
On 8/29/2019 10:16 AM, Eryk Sun wrote:
On 8/29/19, Rhodri James wrote:
"isatty()" is a method of the io.IOBase class that checks to see
if the stream is connected to a tty, or to use less jargon, if it is
interactive. "tty" was I think originally an abbreviation for
"teletype", but nowadays it refers to any terminal, anywhere you
get a command line prompt.
In Windows, isatty() is true for any character-type file.
Does that mean one that can either send or receive data a character at a
time, as opposed to a block at a time?
This does
not necessarily mean an interactive stream. In particular, NUL is a
character device:
C:\>python -c "import sys;print(sys.stderr.isatty())" 2>NUL
True
Aha. So this is why
https://pubs.opengroup.org/onlinepubs/009695399/functions/isatty.html
follows the doc for isatty, which says 'associated with a terminal
device', with an information section that contradicts that with
"The isatty() function does not necessarily indicate that a human being
is available for interaction via fildes. It is quite possible that
non-terminal devices are connected to the communications line."
But a pipe is not:
C:\>python -c "import sys;print(sys.stderr.isatty())" 2>&1 | more
False
What makes a pipe on Windows not a character file? Is data sent between
processes a block at a time? Are posix pipes different?
https://stackoverflow.com/questions/1312922/detect-if-stdin-is-a-terminal-or-pipe
notes that 'cat | python' does not launch the REPL' and asks how to
detect if connected to a pipe (or not a terminal). I presume the system
in not Windows. The answers include both isatty and a stat call. For
CPython, the answer is in the code. On Windows, I got the following
with one 'Enter' after 'NUL'
---
C:\Users\Terry>python 0Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916
64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
---
It appears that Python sees NUL as a tty, as you said, and the first
read indicated EndOfFile, nearly the same as entering ^Z.
I don't understand the following.
---
C:\Users\Terry>python -c "print('hello\n') | python
hello
Traceback (most recent call last):
File "", line 1, in
NameError: name 'python' is not defined
---
This illustrates that pipe input is not seen as a tty as python exits
without a prompt.
---
C:\Users\Terry>py -c "print('''print('alpha')''')" | py
alpha
C:\Users\Terry>
---
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list
Re: [SOLVED] Re: Compare zip lists where order is important
On Thursday, 29 August 2019 20:33:46 UTC+10, Peter Otten wrote:
> Sayth Renshaw wrote:
>
> > will find the added
> > pairs, but ignore the removed ones. Is that what you want?
> >
> > Yes, I think. I want to find the changed pairs. The people that moved team
> > numbers.
>
> To find the people that moved team numbers I would tear the pairs apart.
> Like:
>
> >>> people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"]
> >>> team_number = [1,1,2,2,3,3]
> >>> shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"]
> >>> shuffle_team_number = [1,1,2,2,3,3]
> >>> old = dict(zip(people, team_number))
> >>> new = dict(zip(shuffle_people, shuffle_team_number))
> >>> for name in old.keys() & new.keys():
> ... old_team = old[name]
> ... new_team = new[name]
> ... if old_team != new_team:
> ... print(name, "went from", old_team, "to", new_team)
> ...
> Tim went from 1 to 2
> Fredricka went from 3 to 1
> Ally went from 2 to 3
The reason I opted away from Dictionaries is if there was a team with people
with same name. Then the keys would be the same.
So if Sally left and team 2 had one Tim move in and a new Tim start.
shuffle_people = ["Fredricka","Bill","Tim","Tim","Ally","Fred"]
shuffle_team_number = [1,1,2,2,3,3]
becomes
{'Fredricka': 1, 'Bill': 1, 'Tim': 2, 'Ally': 3, 'Fred': 3}
This still appears to work but is wrong.
for name in old.keys()& new.keys():
old_team = old[name]
new_team = new[name]
if old_team != new_team:
print(name, "went from", old_team, "to", new_team)
Ally went from 2 to 3
Tim went from 1 to 2
Fredricka went from 3 to 1
But I guess in reality I would use a UID and then look up the UID in a list or
database.
Cheers
Sayth
--
https://mail.python.org/mailman/listinfo/python-list
Re: if STREAM.isatty():
Hongyi Zhao wrote: > On Thu, 29 Aug 2019 16:42:44 +0100, Rhodri James wrote: > >> I don't understand what's to not to understand. >> >>if condition: >> do_something_because_condition_is_true() >>else: >> do_something_because_condition_is_false() >> >> is a perfectly normal construction. If you mean something else, please >> be explicit. > > Let me say it more explicitly: > > The original code snippet's logic is as follows: > > if STREAM.isatty(): > p = (self.progress_template + '\r') % params > else: >[do something to reset the new value of p] >p = (self.progress_template + '\n') % params > STREAM.write(p) > STREAM.flush() > > > In order to refresh the tty, the if and else must be run alternatively. > i.e., the isatty() must return 0 and 1 periodically. > > I still understand how the above code will let the isatty() return 0 and > 1 in turn? Perhaps a simple example can help? $ cat checktty.py import sys stream = sys.stdout if stream.isatty(): message = "tty" else: message = "no tty" print(message, file=stream) When you run the script it prints to the terminal: $ python3 checktty.py tty But when you redirect to a pipe or into a file: $ python3 checktty.py | cat no tty $ python3 checktty.py > tmp.txt $ cat tmp.txt no tty -- https://mail.python.org/mailman/listinfo/python-list
Re: [SOLVED] Re: Compare zip lists where order is important
Sayth Renshaw wrote:
> On Thursday, 29 August 2019 20:33:46 UTC+10, Peter Otten wrote:
>> Sayth Renshaw wrote:
>>
>> > will find the added
>> > pairs, but ignore the removed ones. Is that what you want?
>> >
>> > Yes, I think. I want to find the changed pairs. The people that moved
>> > team numbers.
>>
>> To find the people that moved team numbers I would tear the pairs apart.
>> Like:
>>
>> >>> people = ["Tim","Bill","Sally","Ally","Fred","Fredricka"]
>> >>> team_number = [1,1,2,2,3,3]
>> >>> shuffle_people = ["Fredricka","Bill","Sally","Tim","Ally","Fred"]
>> >>> shuffle_team_number = [1,1,2,2,3,3]
>> >>> old = dict(zip(people, team_number))
>> >>> new = dict(zip(shuffle_people, shuffle_team_number))
>> >>> for name in old.keys() & new.keys():
>> ... old_team = old[name]
>> ... new_team = new[name]
>> ... if old_team != new_team:
>> ... print(name, "went from", old_team, "to", new_team)
>> ...
>> Tim went from 1 to 2
>> Fredricka went from 3 to 1
>> Ally went from 2 to 3
>
> The reason I opted away from Dictionaries is if there was a team with
> people with same name. Then the keys would be the same.
>
> So if Sally left and team 2 had one Tim move in and a new Tim start.
> shuffle_people = ["Fredricka","Bill","Tim","Tim","Ally","Fred"]
> shuffle_team_number = [1,1,2,2,3,3]
>
> becomes
> {'Fredricka': 1, 'Bill': 1, 'Tim': 2, 'Ally': 3, 'Fred': 3}
>
> This still appears to work but is wrong.
>
> for name in old.keys()& new.keys():
> old_team = old[name]
> new_team = new[name]
> if old_team != new_team:
> print(name, "went from", old_team, "to", new_team)
> Ally went from 2 to 3
> Tim went from 1 to 2
> Fredricka went from 3 to 1
>
> But I guess in reality I would use a UID and then look up the UID in a
> list or database.
It doesn't matter how you calculate the team changes; you always have to
ensure unique players.
--
https://mail.python.org/mailman/listinfo/python-list
Re: pandas loc on str lower for column comparison
On Friday, 30 August 2019 00:49:32 UTC+10, Piet van Oostrum wrote:
> Piet van Oostrum writes:
>
> > So the correct way to do this is to make df1 a copy rather than a view.
> >
> > df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')]
>
> Or maybe even make an explicit copy:
>
> df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy()
> --
> Piet van Oostrum
> WWW: http://piet.vanoostrum.org/
> PGP key: [8DAE142BE17999C4]
I have tried both
df1 = df.loc[:, ('UID','Name','New Leader','Current Team', 'New Team')]
df1['Difference'] = df1.loc['Current Team'].str.lower().str.strip() ==
df1.loc['New Team'].str.lower().str.strip()
and
df1 = df[['UID','Name','New Leader','Current Team', 'New Team']].copy()
df1['Difference'] = df1.loc['Current Team'].str.lower().str.strip() ==
df1.loc['New Team'].str.lower().str.strip()
But on both occasions I receive this error.
# KeyError: 'the label [Current Team] is not in the [index]'
if I test df1 before trying to create the new column it works just fine.
Sayth
--
https://mail.python.org/mailman/listinfo/python-list
