Re: Line continuation and comments

2023-02-27 Thread Robert Latest via Python-list
Robert Latest wrote: > Paul Bryan wrote: >> Adding to this, there should be no reason now in recent versions of >> Python to ever use line continuation. Black goes so far as to state >> "backslashes are bad and should never be used": >> >> https://black.readthedocs.io/en/stable/the_black_code_style

Re: Line continuation and comments

2023-02-27 Thread Robert Latest via Python-list
Paul Bryan wrote: > Adding to this, there should be no reason now in recent versions of > Python to ever use line continuation. Black goes so far as to state > "backslashes are bad and should never be used": > > https://black.readthedocs.io/en/stable/the_black_code_style/ future_style.html#using-

Re: Line continuation and comments

2023-02-27 Thread Robert Latest via Python-list
Edmondo Giovannozzi wrote: > Il giorno mercoledì 22 febbraio 2023 alle 09:50:14 UTC+1 Robert Latest ha > scritto: >> I found myself building a complicated logical condition with many ands and >> ors which I made more manageable by putting the various terms on individual >> lines and breaking them w

Re: Line continuation and comments

2023-02-24 Thread dn via Python-list
On 25/02/2023 10.04, Mark Bourne wrote: Personally, I don't particularly like the way you have to put multiline strings on the far left (rather than aligned with the rest of the scope) to avoid getting spaces at the beginning of each line.  I find it makes it more difficult to see where the sco

Re: Line continuation and comments

2023-02-24 Thread Roel Schroeven
Mark Bourne schreef op 24/02/2023 om 22:04: Personally, I don't particularly like the way you have to put multiline strings on the far left (rather than aligned with the rest of the scope) to avoid getting spaces at the beginning of each line. I find it makes it more difficult to see where the s

Re: Line continuation and comments

2023-02-24 Thread Mark Bourne
Open spam\n" HelpText += " Shift + Left click: Cook spam\n" ... Or perhaps just dumping the multi-line text into a file beforehand and reading that into a string! def someFunc(): The backslash is not looking like such a bad idea! LOL! -Original Message- From

Re: Line continuation and comments

2023-02-23 Thread Cameron Simpson
On 24/02/2023 12.45, Weatherby,Gerard wrote: NB my PyCharm-settings grumble whenever I create an identifier which is only used once (and perhaps, soon after it was established). I understand the (space) optimisation, but prefer to trade that for 'readability'. It isn't "space". Got an example

RE: Line continuation and comments

2023-02-23 Thread avi.e.gross
ld react if you used: self.LEGAL_AGE_US = 21 -Original Message- From: Python-list On Behalf Of dn via Python-list Sent: Thursday, February 23, 2023 9:01 PM To: [email protected] Subject: Re: Line continuation and comments On 24/02/2023 12.45, Weatherby,Gerard wrote: > “ > NB my PyCharm-s

Re: Line continuation and comments

2023-02-23 Thread dn via Python-list
On 24/02/2023 12.45, Weatherby,Gerard wrote: “ NB my PyCharm-settings grumble whenever I create an identifier which is only used once (and perhaps, soon after it was established). I understand the (space) optimisation, but prefer to trade that for 'readability'. “ I haven’t seen that one. What I

Re: Line continuation and comments

2023-02-23 Thread Weatherby,Gerard
dult( self )->bool: LEGAL_AGE_US = 21 return LEGAL_AGE It doesn’t like LEGAL_AGE_US being all caps if declared in a function. From: Python-list on behalf of dn via Python-list Date: Thursday, February 23, 2023 at 5:46 PM To: [email protected] Subject: Re: Line continuation

Re: Line continuation and comments

2023-02-23 Thread dn via Python-list
On 22/02/2023 21.49, Robert Latest via Python-list wrote: I found myself building a complicated logical condition with many ands and ors which I made more manageable by putting the various terms on individual lines and breaking them with the "\" line continuation character. In this context it wou

RE: Line continuation and comments

2023-02-23 Thread avi.e.gross
ps just dumping the multi-line text into a file beforehand and reading that into a string! def someFunc(): The backslash is not looking like such a bad idea! LOL! -Original Message- From: Python-list On Behalf Of Rob Cliffe via Python-list Sent: Wednesday, February 22, 2023 2:08 PM To:

Re: Line continuation and comments

2023-02-23 Thread Rob Cliffe via Python-list
On 22/02/2023 15:23, Paul Bryan wrote: Adding to this, there should be no reason now in recent versions of Python to ever use line continuation. Black goes so far as to state "backslashes are bad and should never be used": https://black.readthedocs.io/en/stable/the_black_code_style/future_styl

Re: Line continuation and comments

2023-02-22 Thread Cameron Simpson
On 22Feb2023 11:27, Thomas Passin wrote: On 2/22/2023 10:02 AM, Weatherby,Gerard wrote: That’s a neat tip. End of line comments work, too x = (3 > 4 #never and 7 == 7 # hopefully or datetime.datetime.now().day > 15 # sometimes ) print(x) I find myself doing this more and mor

Re: Line continuation and comments

2023-02-22 Thread Thomas Passin
vannozzi Date: Wednesday, February 22, 2023 at 9:40 AM To: [email protected] Subject: Re: Line continuation and comments *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Il giorno mercoledì 22 febbraio 2023 alle 09:50:14 UTC+1

Re: Line continuation and comments

2023-02-22 Thread Weatherby,Gerard
on.org Subject: Re: Line continuation and comments *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Il giorno mercoledì 22 febbraio 2023 alle 09:50:14 UTC+1 Robert Latest ha scritto: > I found myself building a complicated logical

Re: Line continuation and comments

2023-02-22 Thread Paul Bryan
Adding to this, there should be no reason now in recent versions of Python to ever use line continuation. Black goes so far as to state "backslashes are bad and should never be used": https://black.readthedocs.io/en/stable/the_black_code_style/future_style.html#using-backslashes-for-with-statement

Re: Line continuation and comments

2023-02-22 Thread Edmondo Giovannozzi
Il giorno mercoledì 22 febbraio 2023 alle 09:50:14 UTC+1 Robert Latest ha scritto: > I found myself building a complicated logical condition with many ands and > ors > which I made more manageable by putting the various terms on individual lines > and breaking them with the "\" line continuatio

Re: Line terminators in Python?

2017-09-30 Thread Pavol Lisy
On 9/29/17, Rob Gaddi wrote: > On 09/29/2017 10:54 AM, Stefan Ram wrote: >>In some languages, printing »'\n'«, the Unicode code point 10, >>will have the effect of printing a line terminator, which might >>mean that the output device actually receives »\r\n«. >> >>The line terminat

Re: Line terminators in Python?

2017-09-29 Thread Rob Gaddi
On 09/29/2017 10:54 AM, Stefan Ram wrote: In some languages, printing »'\n'«, the Unicode code point 10, will have the effect of printing a line terminator, which might mean that the output device actually receives »\r\n«. The line terminator ostensibly depends on the operating sy

Re: Line terminators in Python?

2017-09-29 Thread Chris Warrick
On 29 September 2017 at 19:54, Stefan Ram wrote: > In some languages, printing »'\n'«, the Unicode code point 10, > will have the effect of printing a line terminator, which might > mean that the output device actually receives »\r\n«. > > The line terminator ostensibly depends on the oper

Re: Line terminators in Python?

2017-09-29 Thread Chris Angelico
On Sat, Sep 30, 2017 at 3:54 AM, Stefan Ram wrote: > In some languages, printing »'\n'«, the Unicode code point 10, > will have the effect of printing a line terminator, which might > mean that the output device actually receives »\r\n«. > > The line terminator ostensibly depends on the op

Re: Line terminators in Python?

2017-09-29 Thread Thomas Jollans
On 29/09/17 19:54, Stefan Ram wrote: > In some languages, printing »'\n'«, the Unicode code point 10, > will have the effect of printing a line terminator, which might > mean that the output device actually receives »\r\n«. > > The line terminator ostensibly depends on the operating > sys

Re: line error on no. 7

2015-07-29 Thread Jean-Michel Pichavant
- Original Message - > From: "ltc hotspot" > To: "[email protected]" > Sent: Tuesday, 28 July, 2015 10:21:59 PM > Subject: line error on no. 7 > Hi Everyone, > I'm writing python code to read a data text file, split the file into > a list of words using the split(function) and to pr

Re: line to argv transformation

2014-06-17 Thread Antoon Pardon
On 16-06-14 13:09, Chris Angelico wrote: > On Mon, Jun 16, 2014 at 8:51 PM, Tim Chase > wrote: >> On 2014-06-16 20:41, Chris Angelico wrote: >>> Oops! I made the cardinal error of trying in one and assuming it'd >>> work in both. Just needs a b prefix on the split string: >>> >>> def shell_split(c

Re: line to argv transformation

2014-06-16 Thread Tim Chase
On 2014-06-16 13:51, Antoon Pardon wrote: > >>> shlex.split("ls *.py") > ['ls', '*.py'] > >>> shlex.split("ls '*.py'") > ['ls', '*.py'] To accommodate this, I'd probably just clone the shlib.py to my local project under a new name and then tweak the source to emit whether a token was quoted or

Re: line to argv transformation

2014-06-16 Thread Antoon Pardon
On 16-06-14 13:01, Peter Otten wrote: > Antoon Pardon wrote: > >> I am looking for an interface that takes a string as argument. The >> string is to be treated as if it is a command line and transformed into >> an argv list. >> >> "ls file" -> ['ls', 'file'] >> "ls *.py" -> ['ls', 'file1.py', '

Re: line to argv transformation

2014-06-16 Thread Chris Angelico
On Mon, Jun 16, 2014 at 8:59 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> def shell_split(cmd): >> return subprocess.check_output("""python -c 'import sys; >> print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split(b"\0") >> >> You'll get back a list of byte strings, in any case.

Re: line to argv transformation

2014-06-16 Thread Tim Chase
On 2014-06-16 20:41, Chris Angelico wrote: > Oops! I made the cardinal error of trying in one and assuming it'd > work in both. Just needs a b prefix on the split string: > > def shell_split(cmd): > return subprocess.check_output("""python -c 'import sys; > print("\\0".join(sys.argv[1:]))' > "

Re: line to argv transformation

2014-06-16 Thread Chris Angelico
On Mon, Jun 16, 2014 at 8:51 PM, Tim Chase wrote: > On 2014-06-16 20:41, Chris Angelico wrote: >> Oops! I made the cardinal error of trying in one and assuming it'd >> work in both. Just needs a b prefix on the split string: >> >> def shell_split(cmd): >> return subprocess.check_output("""pyth

Re: line to argv transformation

2014-06-16 Thread Peter Otten
Antoon Pardon wrote: > I am looking for an interface that takes a string as argument. The > string is to be treated as if it is a command line and transformed into > an argv list. > > "ls file" -> ['ls', 'file'] > "ls *.py" -> ['ls', 'file1.py', 'file2.py', ...] > "ls '*.py'" -> ['ls', '*.py'

Re: line to argv transformation

2014-06-16 Thread Marko Rauhamaa
Chris Angelico : > def shell_split(cmd): > return subprocess.check_output("""python -c 'import sys; > print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split(b"\0") > > You'll get back a list of byte strings, in any case. Feel free to pass > them through a decode operation, or to incor

Re: line to argv transformation

2014-06-16 Thread Chris Angelico
On Mon, Jun 16, 2014 at 8:24 PM, Antoon Pardon wrote: > On 16-06-14 12:06, Chris Angelico wrote: > >> def shell_split(cmd): >> return subprocess.check_output("""python -c 'import sys; >> print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split("\0") > > Nice idea, unfortunatly it doesn'

Re: line to argv transformation

2014-06-16 Thread Antoon Pardon
On 16-06-14 12:06, Chris Angelico wrote: > def shell_split(cmd): > return subprocess.check_output("""python -c 'import sys; > print("\\0".join(sys.argv[1:]))' """+cmd,shell=True)[:-1].split("\0") Nice idea, unfortunatly it doesn't work in python3.3 >>> shell_split("ls *.py") Traceback (most

Re: line to argv transformation

2014-06-16 Thread Chris Angelico
On Mon, Jun 16, 2014 at 7:56 PM, Antoon Pardon wrote: > I am looking for an interface that takes a string as argument. The > string is to be treated as if it is a command line and transformed into > an argv list. > > "ls file" -> ['ls', 'file'] > "ls *.py" -> ['ls', 'file1.py', 'file2.py', ...

Re: Line of best fit

2014-03-31 Thread Steven D'Aprano
On Mon, 31 Mar 2014 04:29:15 -0700, Jamie Mitchell wrote: > I am new to python so apologies for the ignorance with this question. > > How would I apply a line of best fit to a plot? That depends on what software you are using to generate the plot. I see you have this line of code: > plt.plot(h

Re: Line of best fit

2014-03-31 Thread Sturla Molden
Roy Smith wrote: > Please tell us more about the environment you're working in. I'm > guessing from the fact that you're calling plt.plot(), that you've > already got some add-on modules loaded. Pandas, maybe? Probably matplotlib.pyplot -- https://mail.python.org/mailman/listinfo/python-li

Re: Line of best fit

2014-03-31 Thread Moritz Beber
None of these are in the standard library but why re-invent the wheel? Using numpy: http://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html scipy: http://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.stats.linregress.html statsmodels: http://statsmodels.sourceforge.net

Re: Line of best fit

2014-03-31 Thread Roy Smith
In article <[email protected]>, Jamie Mitchell wrote: > I am new to python so apologies for the ignorance with this question. > > How would I apply a line of best fit to a plot? Python has nothing built-in which does that, but there are plenty of add-on mod

Re: Line based graphic in canvas (vectorgraphic?) scale incorrectly on HDMI monitor.

2013-12-21 Thread jonas . thornvall
Den lördagen den 21:e december 2013 kl. 20:56:54 UTC+1 skrev Ned Batchelder: > On 12/21/13 2:12 PM, [email protected] wrote: > > > Den l�rdagen den 21:e december 2013 kl. 20:03:17 UTC+1 skrev Ned > > Batchelder: > > >> On 12/21/13 1:30 PM, [email protected] wrote: > > >> > >

Re: Line based graphic in canvas (vectorgraphic?) scale incorrectly on HDMI monitor.

2013-12-21 Thread Ned Batchelder
On 12/21/13 2:12 PM, [email protected] wrote: Den lördagen den 21:e december 2013 kl. 20:03:17 UTC+1 skrev Ned Batchelder: On 12/21/13 1:30 PM, [email protected] wrote: Is there a way to make linebased graphic used in canvas scale correct on any monitor? I run in 1920*1

Re: Line based graphic in canvas (vectorgraphic?) scale incorrectly on HDMI monitor.

2013-12-21 Thread jonas . thornvall
Den lördagen den 21:e december 2013 kl. 20:03:17 UTC+1 skrev Ned Batchelder: > On 12/21/13 1:30 PM, [email protected] wrote: > > > Is there a way to make linebased graphic used in canvas scale correct on > > any monitor? > > > > > > I run in 1920*1080 on a Philips TV used as monitor doe

Re: Line based graphic in canvas (vectorgraphic?) scale incorrectly on HDMI monitor.

2013-12-21 Thread Ned Batchelder
On 12/21/13 1:30 PM, [email protected] wrote: Is there a way to make linebased graphic used in canvas scale correct on any monitor? I run in 1920*1080 on a Philips TV used as monitor does it matter, lines tend to get longer vertical then horizontal? Strange is i really do not see it w

Re: #line in python (dirty tricks)

2012-02-20 Thread Duncan Booth
Ross Boylan wrote: >> No [easy] way to go from bytecodes back to AST, but I see no reason >> why you can't create a new code object with your filename and line >> numbers and then create a new function using your modified code >> object. > Could you elaborate? I don't understand what you are su

Re: #line in python (dirty tricks)

2012-02-20 Thread Ross Boylan
Duncan Booth wrote > Ross Boylan wrote: > > > As an extension or alternate, could there be a decorator like > > @source_line(lineno, filename) > > for classes and methods that could do the conversion on the fly? I > > don'

Re: #line in python

2012-02-20 Thread Duncan Booth
Ross Boylan wrote: > As an extension or alternate, could there be a decorator like > @source_line(lineno, filename) > for classes and methods that could do the conversion on the fly? I > don't know if there's a way to go from the function (or class) object > the decorator receives to the AST. >

Re: Line continuation issue\

2011-11-08 Thread Westley Martínez
On Fri, Nov 04, 2011 at 11:10:58AM -0400, Steven Lehar wrote: > Is this the right place to propose language extensions? > > My Python code keeps expanding rightwards, it is difficult to keep it > contained within reasonable limits. But the standard line continuation \ > is positively anti-Pythonic

Re: Line continuation issue\

2011-11-04 Thread Terry Reedy
On 11/4/2011 11:10 AM, Steven Lehar wrote: Is this the right place to propose language extensions? Yes, especially for beginners not familiar with previous discussions. My Python code keeps expanding rightwards, it is difficult to keep it contained within reasonable limits. But the standard l

Re: Line continuation issue\

2011-11-04 Thread Chris Angelico
On Sat, Nov 5, 2011 at 2:53 AM, Steven Lehar wrote: > > > > How's it anti-Pythonic for invisible whitespace differences to be significant? > A central idea of Python was to replace {curly;braces{and;parentheses;}}, > which are easily overlooked by the programmer, and use WHITESPACE instead, > so

Re: Line continuation issue\

2011-11-04 Thread Steven Lehar
> How's it anti-Pythonic for invisible whitespace differences to be significant? A central idea of Python was to replace {curly;braces{and;parentheses;}}, which are easily overlooked by the programmer, and use WHITESPACE instead, something that is clearly visible to the programmer, as the defining

Re: Line continuation issue\

2011-11-04 Thread Chris Angelico
On Sat, Nov 5, 2011 at 2:10 AM, Steven Lehar wrote: > But the standard line continuation \ > is positively anti-Pythonic because an *invisible* white space between \ and > [CR] will render it useless. How's it anti-Pythonic for invisible whitespace differences to be significant? ChrisA *grinni

Re: Line continuation issue\

2011-11-04 Thread Peter Otten
Steven Lehar wrote: > Is this the right place to propose language extensions? > > My Python code keeps expanding rightwards, it is difficult to keep it > contained within reasonable limits. You should attack this by breaking large expressions into smaller ones and factoring out some of your co

Re: Line breaks in list causing a small formatting problem while joining the list

2011-01-21 Thread GrayShark
On Fri, 21 Jan 2011 07:39:26 -0800, Oltmans wrote: > Hi Python gurus, hope you're doing well. I've a small problem. > > When I run the following code > ___ names = ['oltmans','abramhovic','\n','sal','lee'] print '| ' + ' | '.join(names) >

Re: Line breaks in list causing a small formatting problem while joining the list

2011-01-21 Thread MRAB
On 21/01/2011 16:25, Peter Otten wrote: Oltmans wrote: Hi Python gurus, hope you're doing well. I've a small problem. When I run the following code ___ names = ['oltmans','abramhovic','\n','sal','lee'] print '| ' + ' | '.join(names) | oltmans |

Re: Line breaks in list causing a small formatting problem while joining the list

2011-01-21 Thread Peter Otten
Oltmans wrote: > Hi Python gurus, hope you're doing well. I've a small problem. > > When I run the following code > ___ names = ['oltmans','abramhovic','\n','sal','lee'] print '| ' + ' | '.join(names) > | oltmans | abramhovic | > | sal |

Re: Line-by-line processing when stdin is not a tty

2010-08-12 Thread Nobody
On Wed, 11 Aug 2010 18:49:26 -0700, RG wrote: > This doesn't explain why "cat | cat" when run interactively outputs > line-by-line (which it does). STDIN to the first cat is a TTY, but the > second one isn't. GNU cat doesn't use stdio, it uses read() and write(), so there isn't any buffering.

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
In article , Nobody wrote: > On Wed, 11 Aug 2010 10:32:41 +, Tim Harig wrote: > > >>> Usually you either > >>> need an option on the upstream program to tell it to line > >>> buffer explicitly > >> > >> once cat had an option -u doing exactly that but nowadays > >> -u seems to be ignored >

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Nobody
On Wed, 11 Aug 2010 10:32:41 +, Tim Harig wrote: >>> Usually you either >>> need an option on the upstream program to tell it to line >>> buffer explicitly >> >> once cat had an option -u doing exactly that but nowadays >> -u seems to be ignored >> >> http://www.opengroup.org/onlinepubs/009695

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Cameron Simpson
On 11Aug2010 12:35, Tim Harig wrote: | > The buffering is a performance choice. Every write requires a context | > switch from userspace to kernel space, and availability of data in the | > pipe will wake up a downstream process blocked trying to read. | > It is far more efficient to do as few suc

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
In article , RG wrote: > In article , > Tim Harig wrote: > > > On 2010-08-11, RG wrote: > > > In article , > > > Tim Harig wrote: > > > > > >> On 2010-08-11, RG wrote: > > >> > I'm writing a system in a different language but want to use a Python > > >> > library. I know of lots of ways

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
In article , Tim Harig wrote: > On 2010-08-11, RG wrote: > > In article , > > Tim Harig wrote: > > > >> On 2010-08-11, RG wrote: > >> > I'm writing a system in a different language but want to use a Python > >> > library. I know of lots of ways to do this (embed a Python interpreter, > >>

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Tim Harig
On 2010-08-11, RG wrote: > In article , > Tim Harig wrote: > >> On 2010-08-11, RG wrote: >> > I'm writing a system in a different language but want to use a Python >> > library. I know of lots of ways to do this (embed a Python interpreter, >> > fire up a python server) but by far the easies

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
In article , Tim Harig wrote: > On 2010-08-11, RG wrote: > > I'm writing a system in a different language but want to use a Python > > library. I know of lots of ways to do this (embed a Python interpreter, > > fire up a python server) but by far the easiest to implement is to have > > the

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Tim Harig
On 2010-08-11, RG wrote: > I'm writing a system in a different language but want to use a Python > library. I know of lots of ways to do this (embed a Python interpreter, > fire up a python server) but by far the easiest to implement is to have > the main program spawn a Python interpreter and

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
In article , Peter Otten <[email protected]> wrote: > Grant Edwards wrote: > > > On 2010-08-11, Tim Harig wrote: > >> On 2010-08-11, RG wrote: > >>> When stdin is not a tty, Python seems to buffer all the input through > >>> EOF before processing any of it: > >>> > >>> [...@mickey:~]$ cat | pyt

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread RG
In article , Cameron Simpson wrote: > On 11Aug2010 00:11, RG wrote: > | When stdin is not a tty, Python seems to buffer all the input through > | EOF before processing any of it: > | > | [...@mickey:~]$ cat | python > | print 123 > | print 456 > | 123 > | 456 > | > | Is there a way to get P

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Grant Edwards
On 2010-08-11, Peter Otten <[email protected]> wrote: > Grant Edwards wrote: >>> If you want to handle stdin a single line at a time from inside of >>> your program, you can access it using sys.stdin.readline(). >> >> That doesn't have any effect on stdin buffering. > > "for line in stream"-styl

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Peter Otten
Grant Edwards wrote: > On 2010-08-11, Tim Harig wrote: >> On 2010-08-11, RG wrote: >>> When stdin is not a tty, Python seems to buffer all the input through >>> EOF before processing any of it: >>> >>> [...@mickey:~]$ cat | python >>> print 123 >>> print 456 >>> 123 >>> 456 >>> >>> Is there a w

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Grant Edwards
On 2010-08-11, Tim Harig wrote: > On 2010-08-11, RG wrote: >> When stdin is not a tty, Python seems to buffer all the input through >> EOF before processing any of it: >> >> [...@mickey:~]$ cat | python >> print 123 >> print 456 >> 123 >> 456 >> >> Is there a way to get Python to process input

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Tim Harig
On 2010-08-11, Cameron Simpson wrote: > On 11Aug2010 10:32, Tim Harig wrote: >| On 2010-08-11, Wolfgang Rohdewald wrote: >| > On Mittwoch 11 August 2010, Cameron Simpson wrote: >| >> Usually you either >| >> need an option on the upstream program to tell it to line >| >> buffer explicitly >| > >

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Cameron Simpson
On 11Aug2010 10:32, Tim Harig wrote: | On 2010-08-11, Wolfgang Rohdewald wrote: | > On Mittwoch 11 August 2010, Cameron Simpson wrote: | >> Usually you either | >> need an option on the upstream program to tell it to line | >> buffer explicitly | > | > once cat had an option -u doing exactly that

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Tim Harig
On 2010-08-11, Wolfgang Rohdewald wrote: > On Mittwoch 11 August 2010, Cameron Simpson wrote: >> Usually you either >> need an option on the upstream program to tell it to line >> buffer explicitly > > once cat had an option -u doing exactly that but nowadays > -u seems to be ignored > > http://ww

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Wolfgang Rohdewald
On Mittwoch 11 August 2010, Cameron Simpson wrote: > Usually you either > need an option on the upstream program to tell it to line > buffer explicitly once cat had an option -u doing exactly that but nowadays -u seems to be ignored http://www.opengroup.org/onlinepubs/009695399/utilities/cat.html

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Cameron Simpson
On 11Aug2010 00:11, RG wrote: | When stdin is not a tty, Python seems to buffer all the input through | EOF before processing any of it: | | [...@mickey:~]$ cat | python | print 123 | print 456 | 123 | 456 | | Is there a way to get Python to process input line-by-line the way it | does when s

Re: Line-by-line processing when stdin is not a tty

2010-08-11 Thread Tim Harig
On 2010-08-11, RG wrote: > When stdin is not a tty, Python seems to buffer all the input through > EOF before processing any of it: > > [...@mickey:~]$ cat | python > print 123 > print 456 > 123 > 456 > > Is there a way to get Python to process input line-by-line the way it > does when stdin is

Re: Line indexing in Python

2009-12-22 Thread MRAB
Lie Ryan wrote: On 12/22/2009 11:25 PM, Steve Holden wrote: > > If you want to extract an index number from the first part of of a given > line use split( split_character, maximum_splits_to_do ) and then angle > brackets to reference the first part (index 0)... > > a = "20 GOTO 10"

Re: Line indexing in Python

2009-12-22 Thread r0g
Steve Holden wrote: > r0g wrote: >> seafoid wrote: >>> Hi Guys, >>> >>> When python reads in a file, can lines be referred to via an index? >>> >>> Example: >>> >>> for line in file: >>> if line[0] == '0': >>> a.write(line) >>> >>> This works, however, I am unsure if line[0] refers on

Re: Line indexing in Python

2009-12-22 Thread Lie Ryan
On 12/22/2009 11:25 PM, Steve Holden wrote: > > If you want to extract an index number from the first part of of a given > line use split( split_character, maximum_splits_to_do ) and then angle > brackets to reference the first part (index 0)... > > a = "20 GOTO 10" int( a.split('

Re: Line indexing in Python

2009-12-22 Thread Steve Holden
r0g wrote: > seafoid wrote: >> Hi Guys, >> >> When python reads in a file, can lines be referred to via an index? >> >> Example: >> >> for line in file: >> if line[0] == '0': >> a.write(line) >> >> This works, however, I am unsure if line[0] refers only to the first line or >> the fir

Re: Line indexing in Python

2009-12-21 Thread r0g
seafoid wrote: > Hi Guys, > > When python reads in a file, can lines be referred to via an index? > > Example: > > for line in file: > if line[0] == '0': > a.write(line) > > This works, however, I am unsure if line[0] refers only to the first line or > the first character in all l

Re: Line indexing in Python

2009-12-18 Thread seafoid
Rory, You are a gentleman! Thank you very much for your suggestion! Kind Regards, Seafoid. Rory Campbell-Lange wrote: > > On 18/12/09, seafoid ([email protected]) wrote: >> http://old.nabble.com/Parsing-file-format-to-ensure-file-meets-criteria-to26837682.html > > Your specification is confus

Re: Line indexing in Python

2009-12-18 Thread seafoid
Hey folks, Is it possible to assign a list within a nested list to a variable? Example: l = [['1', '2', '3'], ['4', '5', '6']] for i in l: if i[0][1] == '1': m = i Indeed, I generally do not understand how to assign variables within a loop! Is there an easy way to 'flatten' a nes

Re: Line indexing in Python

2009-12-18 Thread Rory Campbell-Lange
On 18/12/09, seafoid ([email protected]) wrote: > http://old.nabble.com/Parsing-file-format-to-ensure-file-meets-criteria-to26837682.html Your specification is confusing. However I suggest you break it down the code so that the steps in your programme are logical. Good luck. # example psuedocode he

Re: Line indexing in Python

2009-12-18 Thread Rory Campbell-Lange
On 18/12/09, seafoid ([email protected]) wrote: > Have you any suggestions how I may render this code undead or should I scrap > it and create something new? It might be easier for us to help you if you give us an example of your input file and a clearer description of what you are trying to do with

Re: Line indexing in Python

2009-12-18 Thread seafoid
Hi Guys, It has been point out that it is difficult for anyone to provide suggestions if I do not outline more clearly my input file and an example of what I wish to do with it (Thanks Rory!). I mentioned it in this thread (Is creating different threads bad etiquette? If so, lesson learned!): h

Re: Line indexing in Python

2009-12-18 Thread Lie Ryan
On 12/19/2009 4:33 AM, seafoid wrote: Thanks for that Lie. I had to have a think about what you meant when you referred to control going to a.write(line). and if-elif-elif-... chain is executed sequentially and when a match is found, the rest of the chain is skipped. Your code: if line.sta

Re: Line indexing in Python

2009-12-18 Thread seafoid
Thanks for that Lie. I had to have a think about what you meant when you referred to control going to a.write(line). Have you any suggestions how I may render this code undead or should I scrap it and create something new? My confusion and ineptitude is perhaps explained by my being a biologist

Re: Line indexing in Python

2009-12-18 Thread Lie Ryan
On 12/19/2009 3:27 AM, seafoid wrote: Thanks for that Richard and Steve. I have another question. What's the question? fname = raw_input('Please enter the name of the file: ') # create file objects blah = open(fname, 'r') a = open('rubbish', 'w') for line in blah: if line.startswith

Re: Line indexing in Python

2009-12-18 Thread seafoid
Thanks for that Richard and Steve! Below is my full code so far: for line in file: if line.startswith("1"): a.write(line) elif line.endswith("0"): lists_a = line.strip().split() print lists_a elif line.startswith("2"): lists_b = line.strip().split()

Re: Line indexing in Python

2009-12-18 Thread seafoid
Thanks for that Richard and Steve. I have another question. fname = raw_input('Please enter the name of the file: ') # create file objects blah = open(fname, 'r') a = open('rubbish', 'w') for line in blah: if line.startswith("0"): a.write(line) elif line.endswith("0"):

Re: Line indexing in Python

2009-12-18 Thread Steve Holden
seafoid wrote: > Hi Guys, > > When python reads in a file, can lines be referred to via an index? > > Example: > > for line in file: > if line[0] == '0': > a.write(line) > > This works, however, I am unsure if line[0] refers only to the first line or > the first character in all l

Re: Line indexing in Python

2009-12-18 Thread Richard Thomas
On Dec 18, 3:42 pm, seafoid wrote: > Hi Guys, > > When python reads in a file, can lines be referred to via an index? > > Example: > > for line in file: >      if line[0] == '0': >          a.write(line) > > This works, however, I am unsure if line[0] refers only to the first line or > the first c

Re: Line-continuation "Anti-Idiom" and with statement

2009-11-24 Thread Neil Cerutti
On 2009-11-23, Terry Reedy wrote: > Neil Cerutti wrote: >> Unfortunately, the new "nested" with statement (which I also read >> about today) forces me into this anti-idiom. When replacing an >> appearance of contextlib.nested with the 3K with statement, I >> ended up with an unexpected syntax erro

Re: Line Breaks

2009-11-23 Thread Gary Herron
Susan Day wrote: On Mon, Nov 23, 2009 at 2:26 PM, Gary Herron mailto:[email protected]>> wrote: >>> print 'A Message From %s:\n\n %s' % ('someone','some message') A Message From someone: some message So... *Exactly* what are you doing with msg, and *exactly* what

Re: Line Breaks

2009-11-23 Thread Lie Ryan
D'Arcy J.M. Cain wrote: On Mon, 23 Nov 2009 14:46:23 -0500 Susan Day wrote: First, it does in fact ignore all line breaks, not just double line breaks. Here's what I'm doing: session.sendmail(clientEmail, ourEmail2, header+msg) The email sent out has the message sans breaks. You should really

Re: Line-continuation "Anti-Idiom" and with statement

2009-11-23 Thread Terry Reedy
MRAB wrote: Neil Cerutti wrote: > I installed Python 3.1 today, and I've been porting my small > library of programs to the new system. > > I happened to read the interesting "Idioms and Anti-Idioms" > HOWTO, and saw the '\' continuation character labeled an > anti-idiom. I already generall

Re: Line-continuation "Anti-Idiom" and with statement

2009-11-23 Thread Terry Reedy
Neil Cerutti wrote: I installed Python 3.1 today, and I've been porting my small library of programs to the new system. I happened to read the interesting "Idioms and Anti-Idioms" HOWTO, and saw the '\' continuation character labeled an anti-idiom. I already generally avoided it, so I just nodde

Re: Line Breaks

2009-11-23 Thread D'Arcy J.M. Cain
On Mon, 23 Nov 2009 14:46:23 -0500 Susan Day wrote: > First, it does in fact ignore all line breaks, not just double line breaks. > Here's what I'm doing: > session.sendmail(clientEmail, ourEmail2, header+msg) > The email sent out has the message sans breaks. You should really post an entire scri

Re: Line-continuation "Anti-Idiom" and with statement

2009-11-23 Thread MRAB
Neil Cerutti wrote: > I installed Python 3.1 today, and I've been porting my small > library of programs to the new system. > > I happened to read the interesting "Idioms and Anti-Idioms" > HOWTO, and saw the '\' continuation character labeled an > anti-idiom. I already generally avoided it, so I

Re: Line Breaks

2009-11-23 Thread Susan Day
On Mon, Nov 23, 2009 at 2:26 PM, Gary Herron wrote: > >>> print 'A Message From %s:\n\n %s' % ('someone','some message') > A Message From someone: > > some message > > > So... *Exactly* what are you doing with msg, and *exactly* what is your > evidence that line breaks are being ignored. With th

  1   2   >