On Wed, Nov 2, 2016 at 7:36 AM, wrote:
> Send Tutor mailing list submissions to
> tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
> tutor-requ...@python.org
>
> You can reach the person managing the list at
> tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
> Today's Topics:
>
>1. Re: Python code (Danny Yoo)
>2. Re: implementing sed - termination error (c...@zip.com.au)
>3. Module webbrowser.os (Palanikumar Gopalakrishnan)
>4. Re: implementing sed - termination error (Peter Otten)
>5. Re: Module webbrowser.os (Alan Gauld)
>6. Re: Module webbrowser.os (Steven D'Aprano)
>
>
> -- Forwarded message --
> From: Danny Yoo
> To: Haley Sandherr
> Cc: Tutor@python.org
> Date: Tue, 1 Nov 2016 21:58:08 -0700
> Subject: Re: [Tutor] Python code
> On Nov 1, 2016 4:57 PM, "Haley Sandherr" wrote:
> >
> > Hello, I am new to python and need help with this question:
> >
> > Compose a function odd ( ) that takes three bool arguments and returns
> True if an odd number of arguments are True and False otherwise.
>
> Do you understand all of the terms in the question? Are there terms in the
> question that you don't know?
>
> Try a simpler, related problem if you are getting stuck: it may help point
> the way forward.
>
> For example, your original question has three arguments. Can you do the
> problem variation that just has one boolean argument? Call this odd1().
> You can see that it's like the original problem.
>
> If you can do this, try writing odd2(): a function that can deal with two
> arguments. Can you do this?
>
> What other similar functions have you seen so far?
>
> These questions are intended to help us calibrate our mental model of what
> you currently understand. Please tell us more do we can give you
> appropriate answers.
>
>
>
> -- Forwarded message --
> From: c...@zip.com.au
> To: bruce
> Cc: Python Tutor Mailing List
> Date: Wed, 2 Nov 2016 16:22:21 +1100
> Subject: Re: [Tutor] implementing sed - termination error
> On 01Nov2016 20:18, bruce wrote:
>
>> Running a test on a linux box, with python.
>> Trying to do a search/replace over a file, for a given string, and
>> replacing the string with a chunk of text that has multiple lines.
>>
>> From the cmdline, using sed, no prob. however, implementing sed, runs
>> into issues, that result in a "termination error"
>>
>
> Just terminology: you're not "implementing sed", which is a nontrivial
> task that would involve writing a python program that could do everything
> sed does. You're writing a small python program to call sed to do the work.
>
> Further discussion below.
>
> The error gets thrown, due to the "\" of the newline. SO, and other
>> sites have plenty to say about this, but haven't run across any soln.
>>
>> The test file contains 6K lines, but, the process requires doing lots
>> of search/replace operations, so I'm interested in testing this method
>> to see how "fast" the overall process is.
>>
>> The following psuedo code is what I've used to test. The key point
>> being changing the "\n" portion to try to resolved the termination
>> error.
>>
>> import subprocess
>>
>> ll_="ffdfdfdfg"
>> ll2_="12112121212121212"
>> hash="a"
>>
>> data_=ll_+"\n"+ll2_+"\n"+qq22_
>> print data_
>>
>
> Presuming qq22_ is not shown.
>
> cc='sed -i "s/'+hash+'/'+data_+'/g" '+dname
>> print cc
>> proc=subprocess.Popen(cc, shell=True,stdout=subprocess.PIPE)
>> res=proc.communicate()[0].strip()
>>
>
> There are two fairly large problems with this program. The first is your
> need to embed newlines in the replacement pattern. You have genuine
> newlines in your string, but a sed command would look like this:
>
> sed 's/a/ffdfdfdfg\
> 12112121212121212\
> q/g'
>
> so you need to replace the newlines with "backslash and newline".
>
> Fortunately strings have a .replace() method which you can use for this
> purpose. Look it up:
>
> https://docs.python.org/3/library/stdtypes.html#str.replace
>
> You can use it to make data_ h