Re: First two bytes of 'stdout' are lost

2024-04-11 Thread Cameron Simpson via Python-list
On 11Apr2024 14:42, Olivier B. wrote: I am trying to use StringIO to capture stdout, in code that looks like this: import sys from io import StringIO old_stdout = sys.stdout sys.stdout = mystdout = StringIO() print( "patate") mystdout.seek(0) sys.stdout = old_stdout print(mys

Re: First two bytes of 'stdout' are lost

2024-04-11 Thread Thomas Passin via Python-list
On 4/11/2024 8:42 AM, Olivier B. via Python-list wrote: I am trying to use StringIO to capture stdout, in code that looks like this: import sys from io import StringIO old_stdout = sys.stdout sys.stdout = mystdout = StringIO() print( "patate") mystdout.seek(0) sys.stdout = old_st

Re: First two bytes of 'stdout' are lost

2024-04-11 Thread Olivier B. via Python-list
Partly answering myself: For some reason, right after mystdout has been created, i now have to do mystdout.seek(0) and this solves the issue. No idea why though.. Le jeu. 11 avr. 2024 à 14:42, Olivier B. a écrit : > > I am trying to use StringIO to capture stdout, in code that looks lik

First two bytes of 'stdout' are lost

2024-04-11 Thread Olivier B. via Python-list
I am trying to use StringIO to capture stdout, in code that looks like this: import sys from io import StringIO old_stdout = sys.stdout sys.stdout = mystdout = StringIO() print( "patate") mystdout.seek(0) sys.stdout = old_stdout print(mystdout.read()) Well, it is not exactly like t

Python logging (was Re: What should go to stdout/stderr and why Python logging write everything to stderr?)

2023-01-06 Thread Weatherby,Gerard
FWIW, it wasn’t too difficult to build a logging handler to send messages to Slack. https://pypi.org/project/slack-webclient-logger/ -- https://mail.python.org/mailman/listinfo/python-list

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-06 Thread Peter J. Holzer
On 2023-01-05 12:29:33 -0800, Grant Edwards wrote: > On 2023-01-05, Thomas Passin wrote: > > > The logging system is so configurable that... > > I find it almost impossible to use unless I copy a working example I > find somewhere. ;) I usually copy the working example from my previous project

Re: asyncio and tkinter (was: What should go to stdout/stderr and why Python logging write everything to stderr?)

2023-01-05 Thread Thomas Passin
On 1/5/2023 7:52 PM, Stefan Ram wrote: Thomas Passin writes: On 1/5/2023 4:24 PM, Stefan Ram wrote: You often can replace threads in tkinter by coroutines using asyncio when you write a replacement for the mainloop of tkinter that uses asyncio. Now, try to read only the official documentation

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-05 Thread Thomas Passin
On 1/5/2023 4:24 PM, Stefan Ram wrote: You often can replace threads in tkinter by coroutines using asyncio when you write a replacement for the mainloop of tkinter that uses asyncio. Now, try to read only the official documentation of asyncio and tkinter and figure out only from this

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-05 Thread Thomas Passin
owto: >>> logging.basicConfig(level=logging.DEBUG) >>> logging.info('So should this') INFO:root:So should this : Finally! Not quite straightforward, though it is in the Howto. Now about those handlers ... From: Python-list on behalf of Grant Edwards Date: Thurs

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-05 Thread Grant Edwards
On 2023-01-05, Weatherby,Gerard wrote: > logging.basicConfig() > logging.info(“Nice to know”) > logging.debug(“Details for when things are funky”) > logging.warn(“Trouble is brewing”) I always seem to need something slightly more complex. Usually something like: * Specify a log level on the com

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-05 Thread Weatherby,Gerard
logging.basicConfig() logging.info(“Nice to know”) logging.debug(“Details for when things are funky”) logging.warn(“Trouble is brewing”) From: Python-list on behalf of Grant Edwards Date: Thursday, January 5, 2023 at 3:31 PM To: python-list@python.org Subject: Re: What should go to stdout

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-05 Thread Thomas Passin
On 1/5/2023 3:29 PM, Grant Edwards wrote: On 2023-01-05, Thomas Passin wrote: The logging system is so configurable that... I find it almost impossible to use unless I copy a working example I find somewhere. ;) I'm not at all surprised that the OP didn't understand how it works. I've been

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-05 Thread Grant Edwards
On 2023-01-05, Thomas Passin wrote: > The logging system is so configurable that... I find it almost impossible to use unless I copy a working example I find somewhere. ;) I'm not at all surprised that the OP didn't understand how it works. I've been writing Python programs for over 20 years, a

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-05 Thread Thomas Passin
On 1/5/2023 2:18 PM, Peter J. Holzer wrote: On 2023-01-05 08:31:40 -0500, Thomas Passin wrote: The logging system is so configurable that a user could set a different destination for each level of logging. So it seems that the O.P.'s original question about why the package's developers choose s

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-05 Thread Peter J. Holzer
On 2023-01-05 08:31:40 -0500, Thomas Passin wrote: > The logging system is so configurable that a user could set a different > destination for each level of logging. So it seems that the O.P.'s original > question about why the package's developers choose stderr for all levels can > be answered: "

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-05 Thread Thomas Passin
it is - sort of. That is all log messages go to stderr, but not all log levels are logged. Actually, I misread something else that made me think that non-warning messages would go to stdout, but I was mistaken. As it happens, the page in the Python docs only mention stderr twice, both in the

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-05 Thread Peter J. Holzer
On 2023-01-04 12:32:40 -0500, Thomas Passin wrote: > On 1/3/2023 10:35 AM, c.bu...@posteo.jp wrote: > > The logging module write everything to stderr no matter which logging > > level is used. > > The OP wrote this, but it's not so by default. By default it is - sort of. That is all log message

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-04 Thread Chris Angelico
On Thu, 5 Jan 2023 at 05:06, Barry Scott wrote: > > > On 03/01/2023 21:24, c.bu...@posteo.jp wrote: > > Am 03.01.2023 17:51 schrieb r...@zedat.fu-berlin.de: > >> logging.getLogger().addHandler( logging.StreamHandler( sys.stdout )) > > > > But I don't want

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-04 Thread Barry Scott
On 03/01/2023 21:24, c.bu...@posteo.jp wrote: Am 03.01.2023 17:51 schrieb r...@zedat.fu-berlin.de: logging.getLogger().addHandler( logging.StreamHandler( sys.stdout )) But I don't want to make all log levels go to stdout. Just DEBUG and INFO. But this would be a workaround. The

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-04 Thread Barry Scott
On 03/01/2023 21:24, c.bu...@posteo.jp wrote: Am 03.01.2023 17:51 schrieb r...@zedat.fu-berlin.de: logging.getLogger().addHandler( logging.StreamHandler( sys.stdout )) But I don't want to make all log levels go to stdout. Just DEBUG and INFO. But this would be a workaround. The

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-04 Thread Thomas Passin
On 1/3/2023 10:35 AM, c.bu...@posteo.jp wrote: The logging module write everything to stderr no matter which logging level is used. The OP wrote this, but it's not so by default. There is a HOW-TO page that explains this and how to get the logging package to log everything to a file, along w

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-04 Thread Peter J. Holzer
On 2023-01-03 21:24:20 +, c.bu...@posteo.jp wrote: > The main question here is why does Python deciecded to make all logs go to > stderr? It doesn't. The Python logging system provides a plethora of handlers to log to lots of different places. Only the StreamHandler defaults to writing to std

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-04 Thread Peter J. Holzer
On 2023-01-04 16:46:37 +1100, Chris Angelico wrote: > On Wed, 4 Jan 2023 at 15:11, Eryk Sun wrote: > > On 1/3/23, Chris Angelico wrote: > > > writing the FD is the same as using stdout > > > > Except stdout may be buffered. Maybe I'm overly lax in my termino

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-04 Thread Barry Scott
On 04/01/2023 06:46, Chris Angelico wrote: I've known some systems to have a trigger of "reading on FD 0 flushes FD 1" C++ has this feature: Quote from https://en.cppreference.com/w/cpp/io/cin "Once |std::cin| is constructed, std::cin.tie() returns &std::cout

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-04 Thread Barry Scott
On 04/01/2023 02:26, Chris Angelico wrote: Reading/writing the FD is the same as using stdout (technically you'd write to fd 1 and read from fd 0), but yes, can use /dev/tty to reach for the console directly. I think the logic is more like checking that stdin is a tty then using the t

Re: No solution for "--verbose" (on stdout) output in Pythonds standard library?

2023-01-04 Thread Richard Damon
> On Jan 4, 2023, at 8:56 AM, c.bu...@posteo.jp wrote: > > Hello, > > first I have to say that in my current and fresh humble opinion the > often seen "--verbose" switch in command line applications should > affect only the messages given to the users. This mea

Re: No solution for "--verbose" (on stdout) output in Pythonds standard library?

2023-01-04 Thread Eryk Sun
On 1/4/23, c.bu...@posteo.jp wrote: > > often seen "--verbose" switch in command line applications should > affect only the messages given to the users. This means messages on > "stdout". That is what this question is about. Is this additional context information

Re: No solution for "--verbose" (on stdout) output in Pythonds standard library?

2023-01-04 Thread Weatherby,Gerard
ser.parse_args() logger = logging.getLogger(__name__) logger.setLevel(getattr(logging,args.loglevel)) From: Python-list on behalf of c.bu...@posteo.jp Date: Wednesday, January 4, 2023 at 8:55 AM To: python-list@python.org Subject: No solution for "--verbose" (on stdout) output in Pythonds sta

Re: No solution for "--verbose" (on stdout) output in Pythonds standard library?

2023-01-04 Thread Chris Angelico
On Thu, 5 Jan 2023 at 00:54, wrote: > > Hello, > > first I have to say that in my current and fresh humble opinion the > often seen "--verbose" switch in command line applications should > affect only the messages given to the users. This means messages on > "

No solution for "--verbose" (on stdout) output in Pythonds standard library?

2023-01-04 Thread c.buhtz
Hello, first I have to say that in my current and fresh humble opinion the often seen "--verbose" switch in command line applications should affect only the messages given to the users. This means messages on "stdout". That is what this question is about. The logging mod

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-04 Thread 2QdxY4RzWzUUiLuE
On 2023-01-04 at 12:02:55 +, "Weatherby,Gerard" wrote: > Dealing with stdout / stderr is bash is just syntax. I don’t always > remember it off the top of my head but … stackoverflow.com. https://tldp.org/LDP/abs/html/io-redirection.html > On Linux at least it’s

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-04 Thread Weatherby,Gerard
Dealing with stdout / stderr is bash is just syntax. I don’t always remember it off the top of my head but … stackoverflow.com. On Linux at least it’s possible to pipe to arbitrary streams, it seems. The following uses bash to write “Hi” to the file “third” opened by Python. I determined the

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Chris Angelico
tines (ISTR readline was one of the few things that *didn't* have that problem, but I may be misremembering), so the general strategy was: print your prompt, flush stdout, THEN request input. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Eryk Sun
On 1/3/23, Chris Angelico wrote: > > FDs can also be buffered. If it's buffering you want to avoid, don't > mess around with exactly which one you're writing to, just flush. I meant to flush a C FILE stream or Python file before writing directly to the file descriptor, in order to avoid out-of-se

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Eryk Sun
engroup.org/onlinepubs/95399/basedefs/xbd_chap10.html > No, the whole point is _not_ to write to stdout (which would corrupt > the program's output). The way I remember it was that you wrote the > prompt to fd 0, and then read the password from fd 0. That way it > worked even when

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Chris Angelico
; of a program while at the same time interacting with a prompt on stderr. > >>> A rare thing, though. > >> > >> Programs that ask for passwords often do it by reading/writing to > >> fd 0 or /dev/tty so that stdout is unaffected. > > > > Reading/wri

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Chris Angelico
On Wed, 4 Jan 2023 at 15:11, Eryk Sun wrote: > > On 1/3/23, Chris Angelico wrote: > > > > writing the FD is the same as using stdout > > Except stdout may be buffered. One should probably flush the buffer > before each raw write to the file descriptor. FDs ca

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Grant Edwards
re thing, though. >> >> Programs that ask for passwords often do it by reading/writing to >> fd 0 or /dev/tty so that stdout is unaffected. > > Reading/writing the FD is the same as using stdout. No, stdout is fd 1. > (technically you'd write to fd 1 and read from fd

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Eryk Sun
On 1/3/23, Chris Angelico wrote: > > writing the FD is the same as using stdout Except stdout may be buffered. One should probably flush the buffer before each raw write to the file descriptor. > use /dev/tty to reach for the console directly. On Windows, open "CON" (rea

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Chris Angelico
On Wed, 4 Jan 2023 at 10:28, Stefan Ram wrote: > > c.bu...@posteo.jp writes: > >But I don't want to make all log levels go to stdout. Just DEBUG and > >INFO. > > The following was stripped down from something some guy > posted on a web site, maybe it was

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Chris Angelico
;> messages, even user prompts, and not mess up the program's actual > >>> output. This is important on a *nix system where you might be piping > >>> the output of one program into the input of another. > >> > >> I would expect user prompts to be

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Grant Edwards
> output. This is important on a *nix system where you might be piping >>> the output of one program into the input of another. >> >> I would expect user prompts to be written to stdout, or perhaps to some >> system-specific stream like the current tty, not to stderr.

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Chris Angelico
rogram's actual > >> output. This is important on a *nix system where you might be piping > >> the output of one program into the input of another. > > > > I would expect user prompts to be written to stdout, or perhaps to some > > system-specific stream like th

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread 2QdxY4RzWzUUiLuE
On 2023-01-03 at 21:24:20 +, c.bu...@posteo.jp wrote: > The main question here is why does Python deciecded to make all logs > go to stderr? It makes sense to send all logging to one destination, and stderr is that place. > Maybe I totally misunderstood the intention of logging.info()?! Isn'

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Michael Torrie
ht be piping >> the output of one program into the input of another. > > I would expect user prompts to be written to stdout, or perhaps to some > system-specific stream like the current tty, not to stderr. If a > program has user prompts, it probably doesn't make sense to

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Chris Angelico
On Wed, 4 Jan 2023 at 08:25, wrote: > > Am 03.01.2023 17:51 schrieb r...@zedat.fu-berlin.de: > > logging.getLogger().addHandler( logging.StreamHandler( sys.stdout )) > > But I don't want to make all log levels go to stdout. Just DEBUG and > INFO. But this would be a work

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Cameron Simpson
ging level is used. Sure. They're logs. The argparse module does it more differentiated. If arguments are mandatory but none are given then argparse produce a short version of the usage info; on stderr. If the user request the usage info via "-h" it goes to stdout. This is th

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread c . buhtz
Am 03.01.2023 17:51 schrieb r...@zedat.fu-berlin.de: logging.getLogger().addHandler( logging.StreamHandler( sys.stdout )) But I don't want to make all log levels go to stdout. Just DEBUG and INFO. But this would be a workaround. The main question here is why does Python deciecded to

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Eryk Sun
On 1/3/23, Weatherby,Gerard wrote: > If sys.stdout is a tty, it typically flushes on newline. e. g. Sorry if I wasn't clear. Yes, a tty file will be buffered, but it's line buffering, which isn't an issue as long as lines are written to stdout. I was referring to full bufferin

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Weatherby,Gerard
pt ends From: Python-list on behalf of Eryk Sun Date: Tuesday, January 3, 2023 at 1:33 PM To: c.bu...@posteo.jp Cc: python-list@python.org Subject: Re: What should go to stdout/stderr and why Python logging write everything to stderr? *** Attention: This is an external email. Use caution respo

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Thomas Passin
On 1/3/2023 11:51 AM, Stefan Ram wrote: Thomas Passin writes: On 1/3/2023 10:35 AM, c.bu...@posteo.jp wrote: Also, I think it would be confusing to sometimes have logging output go to stdout and other times go to stderr. In UNIX, the output of a program can be redirected, so error

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Keith Thompson
another. I would expect user prompts to be written to stdout, or perhaps to some system-specific stream like the current tty, not to stderr. If a program has user prompts, it probably doesn't make sense to pipe its output to the input of another. -- Keith Thompson (The_Other_Keith) keith.

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Eryk Sun
On 1/3/23, c.bu...@posteo.jp wrote: > > If the user request the usage info via "-h" it goes to stdout. The standard file for application output is sys.stdout. Note that sys.stdout may be buffered, particularly if it isn't a tty. When a file is buffered, writes are aggregate

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Weatherby,Gerard
print that and exit, regardless of any other arguments that are passed. So its behavior is consistent with the concept of standard out. From: Python-list on behalf of MRAB Date: Tuesday, January 3, 2023 at 11:41 AM To: python-list@python.org Subject: Re: What should go to stdout/stderr and

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Richard Damon
dule write everything to stderr no matter which logging > level is used. > > The argparse module does it more differentiated. If arguments are > mandatory but none are given then argparse produce a short version of > the usage info; on stderr. If the user request the usage info via

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread MRAB
ging level is used. The argparse module does it more differentiated. If arguments are mandatory but none are given then argparse produce a short version of the usage info; on stderr. If the user request the usage info via "-h" it goes to stdout. This is the behavior I would expect. Why

Re: What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread Thomas Passin
ging level is used. The argparse module does it more differentiated. If arguments are mandatory but none are given then argparse produce a short version of the usage info; on stderr. If the user request the usage info via "-h" it goes to stdout. This is the behavior I would expect. Why

What should go to stdout/stderr and why Python logging write everything to stderr?

2023-01-03 Thread c.buhtz
es it more differentiated. If arguments are mandatory but none are given then argparse produce a short version of the usage info; on stderr. If the user request the usage info via "-h" it goes to stdout. This is the behavior I would expect. Why does logging behave different? DEBUG and INFO imho

Re: empty stdout (subprocess.run)

2022-01-20 Thread James Smith
On Wednesday, January 19, 2022 at 11:14:28 PM UTC-5, cameron...@gmail.com wrote: > But I recommend you use shell=False and make: > > cmd = ["/usr/bin/transmission-remote", "--torrent", str(torrentno), "--info"] I like that. :-) -- https://mail.python.org/mailman/listinfo/python-list

Re: empty stdout (subprocess.run)

2022-01-20 Thread James Smith
On Wednesday, January 19, 2022 at 11:08:58 PM UTC-5, Dennis Lee Bieber wrote: > Don't you need to provide for that %s? Perhaps > > cmd="/usr/bin/transmission-remote --torrent %s --info" % torrentno That works, thanks. -- https://mail.python.org/mailman/listinfo/python-list

Re: empty stdout (subprocess.run)

2022-01-19 Thread Cameron Simpson
On 19Jan2022 19:16, James Smith wrote: >I'm trying to run a shell command but the stdout is empty: > >import subprocess > >torrentno=8 >cmd="/usr/bin/transmission-remote --torrent %s --info", str(torrentno) >res=subprocess.run(cmd, shell=True, check=True, unive

Re: empty stdout (subprocess.run)

2022-01-19 Thread Dennis Lee Bieber
On Wed, 19 Jan 2022 19:16:19 -0800 (PST), James Smith declaimed the following: >I'm trying to run a shell command but the stdout is empty: > >import subprocess > >torrentno=8 >cmd="/usr/bin/transmission-remote --torrent %s --info", str(torrentno) Don&

empty stdout (subprocess.run)

2022-01-19 Thread James Smith
I'm trying to run a shell command but the stdout is empty: import subprocess torrentno=8 cmd="/usr/bin/transmission-remote --torrent %s --info", str(torrentno) res=subprocess.run(cmd, shell=True, check=True, universal_newlines=True, capture_output=True) print(res) CompletedProc

Re: How to flush 's stdout stream?

2021-01-15 Thread Grant Edwards
On 2021-01-15, Eryk Sun wrote: > On 1/15/21, Grant Edwards wrote: >> In Python 3.7+, how does one flush the stdout FILE stream? I mean the >> FILE *declared as 'stdio' in . I'm _not_ asking how to flush the >> Python file object sys.stdio. > > You can

Re: How to flush 's stdout stream?

2021-01-15 Thread Eryk Sun
On 1/15/21, Grant Edwards wrote: > In Python 3.7+, how does one flush the stdout FILE stream? I mean the > FILE *declared as 'stdio' in . I'm _not_ asking how to flush the > Python file object sys.stdio. You can flush all output streams via C fflush(NULL). If it has to

How to flush 's stdout stream?

2021-01-15 Thread Grant Edwards
In Python 3.7+, how does one flush the stdout FILE stream? I mean the FILE *declared as 'stdio' in . I'm _not_ asking how to flush the Python file object sys.stdio. The problem is that some Python modules write to FILE *stdio, but don't flush the stream so that the data

Re: stderr writting before stdout

2020-05-25 Thread Rhodri James
On 24/05/2020 05:27, Souvik Dutta wrote: Is there any precedence or priority order by which sys.stderr.write() and sys.stdout.write() works. No. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list

Re: stderr writting before stdout

2020-05-24 Thread Dylan Evans
Hi, This data is being line buffered, so either a newline or flush is required to get it to actually write to the terminal / file. On Sun, May 24, 2020 at 2:34 PM Souvik Dutta wrote: > Also this code maintains order i.e. writting is displayed before no errors. > Why is that? > > import sys > sys

stderr writting before stdout

2020-05-24 Thread Souvik Dutta
Hi, Is there any precedence or priority order by which sys.stderr.write() and sys.stdout.write() works. Because when running the below code... import sys sys.stdout.write("Writting") sys.stderr.write("No errors \n") No errors is written (displayed) first and writting is written later. Why does th

Re: stderr writting before stdout

2020-05-23 Thread Souvik Dutta
Thank you I understood. Sorry for top posting... 😛 On Sun, 24 May, 2020, 11:34 am Cameron Simpson, wrote: > Please don't top post; I have rearranged your message so that the > discussion reads from top to bottom. Reponse below. > > On 24May2020 10:04, Souvik Dutta wrote: > >On Sun, 24 May, 202

Re: stderr writting before stdout

2020-05-23 Thread Cameron Simpson
Please don't top post; I have rearranged your message so that the discussion reads from top to bottom. Reponse below. On 24May2020 10:04, Souvik Dutta wrote: On Sun, 24 May, 2020, 9:57 am Souvik Dutta, wrote: Is there any precedence or priority order by which sys.stderr.write() and sys.stdo

Re: stderr writting before stdout

2020-05-23 Thread Souvik Dutta
Also this code maintains order i.e. writting is displayed before no errors. Why is that? import sys sys.stdout.write("Writting \n") sys.stderr.write("No errors \n") On Sun, 24 May, 2020, 9:57 am Souvik Dutta, wrote: > Hi, > Is there any precedence or priority order by which sys.stderr.write() a

Re: print small DataFrame to STDOUT and read it back into dataframe

2020-04-07 Thread Luca
On 4/6/2020 11:05 PM, Luca wrote: On 4/6/2020 8:51 PM, Reto wrote: out = df.to_csv(None) new = pd.read_csv(io.StringIO(out), index_col=0) Thank you, brother. It works BTW, a little gotcha (I write this in case someone gets here in the future through Google or something) """ import pandas

Re: print small DataFrame to STDOUT and read it back into dataframe

2020-04-06 Thread Luca
On 4/6/2020 8:51 PM, Reto wrote: out = df.to_csv(None) new = pd.read_csv(io.StringIO(out), index_col=0) Thank you, brother. It works -- https://mail.python.org/mailman/listinfo/python-list

Re: print small DataFrame to STDOUT and read it back into dataframe

2020-04-06 Thread Reto
On Mon, Apr 06, 2020 at 06:29:01PM -0400, Luca wrote: > so, given a dataframe, how do I make it print itself out as CSV? read the docs of to_csv... > And given CSV data in my clipboard, how do I paste it into a Jupiter cell > (possibly along with a line or two of code) that will create a datafram

Re: print small DataFrame to STDOUT and read it back into dataframe

2020-04-06 Thread Luca
On 4/6/2020 3:03 PM, Christian Gollwitzer wrote: CSV is the most sensible option here. It is widely supported by spreadsheets etc. and easily copy/pasteable. Thank you Christian. so, given a dataframe, how do I make it print itself out as CSV? And given CSV data in my clipboard, how do I

Re: print small DataFrame to STDOUT and read it back into dataframe

2020-04-06 Thread Christian Gollwitzer
Am 06.04.20 um 17:17 schrieb Luca: On 4/6/2020 4:08 AM, Reto wrote: Does this help? Thank you, but not really. What I am trying to achieve is to have a way to copy and paste small yet complete dataframes (which may be the result of previous calculations) between a document (TXT, Word, Google

Re: print small DataFrame to STDOUT and read it back into dataframe

2020-04-06 Thread Luca
On 4/6/2020 4:08 AM, Reto wrote: Does this help? Thank you, but not really. What I am trying to achieve is to have a way to copy and paste small yet complete dataframes (which may be the result of previous calculations) between a document (TXT, Word, GoogleDoc) and Jupiter/IPython. Did I m

Re: print small DataFrame to STDOUT and read it back into dataframe

2020-04-06 Thread Reto
On Sat, Apr 04, 2020 at 07:00:23PM -0400, Luca wrote: > dframe.to_string > > gives: > > 0 a0 b0 c0 d0 > 1 a1 b1 c1 d1 > 2 a2 b2 c2 d2 > 3 a3 b3 c3 d3> That's not the output of to_string. to_string is a method, not an attribute which is apparent by the > comment in your output

print small DataFrame to STDOUT and read it back into dataframe

2020-04-04 Thread Luca
possibly a stupid question. Let's say I have a (small) dataframe: import pandas as pd dframe = pd.DataFrame({'A': ['a0','a1','a2','a3'], 'B': ['b0','b1','b2','b3'], 'C': ['c0','c1','c2','c3'], 'D': ['d0','d1','d2','d3']}, i

Re: printing to stdout

2018-08-23 Thread richard lucassen
On Mon, 20 Aug 2018 08:19:12 +1000 Cameron Simpson wrote: [sorry for late reply] > Someone else has descibed zip tersely: it pairs it the elements of 2 > lists. In fact it joins up matching elements of an arbitrary number > of iterables. Here is a 3 iterable example: > > >>> zip( (1,2,3), (

Re: Writing bytes to stdout reverses the bytes

2018-08-20 Thread Thomas Jollans
On 2018-08-20 17:07, Akkana Peck wrote: >> Thomas Jollans : >>> Wonderful. Now why don't we all forget about hexdump and use xxd? ;-) > > Marko Rauhamaa writes: >> Fedora: >> >>$ xxd >>bash: xxd: command not found >>$ hd >>bash: hd: command not found >>$ od -Ax -tx1z -v <<>

Re: Writing bytes to stdout reverses the bytes

2018-08-20 Thread Akkana Peck
> Thomas Jollans : > > Wonderful. Now why don't we all forget about hexdump and use xxd? ;-) Marko Rauhamaa writes: > Fedora: > >$ xxd >bash: xxd: command not found >$ hd >bash: hd: command not found >$ od -Ax -tx1z -v <<00 68 65 6c 6c 6f 0a

Re: Writing bytes to stdout reverses the bytes

2018-08-20 Thread Grant Edwards
On 2018-08-20, Chris Angelico wrote: > On Mon, Aug 20, 2018 at 12:01 PM, Grant Edwards >> What do you mean "run it as hd"? >> [... Calling via 'hd' alias makes no difference ...] > Your system is different from mine, then. No doubt. :) > rosuav@sikorsky:~$ ls -l $(which hd) > lrwxrwxrwx 1 root

Re: Writing bytes to stdout reverses the bytes

2018-08-20 Thread Marko Rauhamaa
Thomas Jollans : > On 2018-08-20 04:22, Chris Angelico wrote: >> On Mon, Aug 20, 2018 at 12:01 PM, Grant Edwards >> wrote: >>> On 2018-08-20, Ben Bacarisse wrote: It is if you run it as hd. >>> What do you mean "run it as hd"? >>> I don't have an "hd" in my path. >> Your system is different

Re: Writing bytes to stdout reverses the bytes

2018-08-20 Thread Thomas Jollans
On 2018-08-20 04:22, Chris Angelico wrote: > On Mon, Aug 20, 2018 at 12:01 PM, Grant Edwards > wrote: >> On 2018-08-20, Ben Bacarisse wrote: >>> It is if you run it as hd. >> >> What do you mean "run it as hd"? >> >> I don't have an "hd" in my path. > > Your system is different from mine, then.

Re: Writing bytes to stdout reverses the bytes

2018-08-19 Thread Chris Angelico
On Mon, Aug 20, 2018 at 12:01 PM, Grant Edwards wrote: > On 2018-08-20, Ben Bacarisse wrote: >> Grant Edwards writes: >> >>> On 2018-08-20, Steven D'Aprano wrote: >>>> On Mon, 20 Aug 2018 00:31:35 +, Steven D'Aprano wrote: >>>>

Re: Writing bytes to stdout reverses the bytes

2018-08-19 Thread Grant Edwards
On 2018-08-20, Ben Bacarisse wrote: > Grant Edwards writes: > >> On 2018-08-20, Steven D'Aprano wrote: >>> On Mon, 20 Aug 2018 00:31:35 +, Steven D'Aprano wrote: >>> >>>> When I write bytes to stdout, why are they reversed? >>> &

Re: Writing bytes to stdout reverses the bytes

2018-08-19 Thread Chris Angelico
Aprano wrote: >>>> >>>>> When I write bytes to stdout, why are they reversed? >>>> >>>> Answer: they aren't, use hexdump -C. >>> >>> One might think that dumping out bytes in the correct order ought to >>> be the

Re: Writing bytes to stdout reverses the bytes

2018-08-19 Thread Ben Bacarisse
Grant Edwards writes: > On 2018-08-20, Steven D'Aprano wrote: >> On Mon, 20 Aug 2018 00:31:35 +, Steven D'Aprano wrote: >> >>> When I write bytes to stdout, why are they reversed? >> >> Answer: they aren't, use hexdump -C. > > On

Re: Writing bytes to stdout reverses the bytes

2018-08-19 Thread Grant Edwards
On 2018-08-20, Chris Angelico wrote: > On Mon, Aug 20, 2018 at 11:12 AM, Grant Edwards > wrote: >> On 2018-08-20, Steven D'Aprano wrote: >>> On Mon, 20 Aug 2018 00:31:35 +, Steven D'Aprano wrote: >>> >>>> When I write bytes to stdout, why

Re: Writing bytes to stdout reverses the bytes

2018-08-19 Thread Chris Angelico
On Mon, Aug 20, 2018 at 11:12 AM, Grant Edwards wrote: > On 2018-08-20, Steven D'Aprano wrote: >> On Mon, 20 Aug 2018 00:31:35 +, Steven D'Aprano wrote: >> >>> When I write bytes to stdout, why are they reversed? >> >> Answer: they aren't, u

Re: Writing bytes to stdout reverses the bytes

2018-08-19 Thread Grant Edwards
On 2018-08-20, Steven D'Aprano wrote: > On Mon, 20 Aug 2018 00:31:35 +, Steven D'Aprano wrote: > >> When I write bytes to stdout, why are they reversed? > > Answer: they aren't, use hexdump -C. One might think that dumping out bytes in the correct order o

Re: Writing bytes to stdout reverses the bytes

2018-08-19 Thread Steven D'Aprano
On Mon, 20 Aug 2018 00:31:35 +, Steven D'Aprano wrote: > When I write bytes to stdout, why are they reversed? Answer: they aren't, use hexdump -C. Thanks to all replies! -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing i

Re: Writing bytes to stdout reverses the bytes

2018-08-19 Thread Cameron Simpson
On 20Aug2018 00:31, Steven D'Aprano wrote: When I write bytes to stdout, why are they reversed? [steve@ando ~]$ python2.7 -c "print('\xfd\x84\x04\x08')" | hexdump 000 84fd 0804 000a 005 [steve@ando ~]$ python3.5 -c "import sys; sys.stdout.buff

Re: Writing bytes to stdout reverses the bytes

2018-08-19 Thread Chris Angelico
On Mon, Aug 20, 2018 at 10:31 AM, Steven D'Aprano wrote: > When I write bytes to stdout, why are they reversed? > > [steve@ando ~]$ python2.7 -c "print('\xfd\x84\x04\x08')" | hexdump > 000 84fd 0804 000a > 005 > > [steve@ando ~]$ python3.5

Re: Writing bytes to stdout reverses the bytes

2018-08-19 Thread Grant Edwards
On 2018-08-20, Steven D'Aprano wrote: > When I write bytes to stdout, why are they reversed? > > [steve@ando ~]$ python2.7 -c "print('\xfd\x84\x04\x08')" | hexdump > 000 84fd 0804 000a > 005 They aren't. You're being fooled by the

Writing bytes to stdout reverses the bytes

2018-08-19 Thread Steven D'Aprano
When I write bytes to stdout, why are they reversed? [steve@ando ~]$ python2.7 -c "print('\xfd\x84\x04\x08')" | hexdump 000 84fd 0804 000a 005 [steve@ando ~]$ python3.5 -c "import sys; sys.stdout.buffer.write(b'\xfd \x84\x04\x08\n')"

Re: printing to stdout

2018-08-19 Thread Cameron Simpson
On 19Aug2018 15:09, richard lucassen wrote: On Sun, 19 Aug 2018 19:53:04 +1000 Cameron Simpson wrote: Although I do not understand what zip is doing exactly here (I presume I switch to use pointers instead of the values), Someone else has descibed zip tersely: it pairs it the elements of 2 li

Re: printing to stdout

2018-08-19 Thread Chris Angelico
On Mon, Aug 20, 2018 at 7:55 AM, Cameron Simpson wrote: > Draw little boxes with arrows. It helps. - Michael J. Eager Draw good boxes. - DeviCat ChrisA -- https://mail.python.org/mailman/listinfo/python-list

  1   2   3   4   5   6   7   8   9   >