Re: How to remove a string from a txt file?

2019-09-04 Thread Tobiah

On 9/4/19 8:08 AM, Spencer Du wrote:

Hi

I want to remove a string from a txt file and then print out what I have 
removed. How do I do this.

The txt file is in this format and should be kept in this format.

txt.txt:
laser,cameras,

Thanks



Do you want to remove one of the fields by using an argument?  Like:

my_py_solution txt.txt cameras

Its not clear what you are trying to achieve.



--
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove a string from a txt file?

2019-09-04 Thread DL Neil via Python-list

On 5/09/19 3:08 AM, Spencer Du wrote:

Hi

I want to remove a string from a txt file and then print out what I have 
removed. How do I do this.

The txt file is in this format and should be kept in this format.

txt.txt:
laser,cameras,


Is this a homework assignment?

What code do you have so far?

How to identify the beginning of the sub-string to be removed?

How to identify the end of the sub-string?

How does one "remove a string" AND "kept in this format"?

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove a string from a txt file?

2019-09-04 Thread Joel Goldstick
On Wed, Sep 4, 2019 at 11:11 AM Spencer Du  wrote:
>
> Hi
>
> I want to remove a string from a txt file and then print out what I have 
> removed. How do I do this.
>
> The txt file is in this format and should be kept in this format.
>
> txt.txt:
> laser,cameras,
>
> Thanks
> --
> https://mail.python.org/mailman/listinfo/python-list

read the file line by line.  if it doesn't contain your string, write
it to a new file.  for each line, use string functions to find the
string you want to remove.  One way is to split on ',' or use
csvreader to get a list of words between comma.  Print the one you
like and join the values on each side of the text you are looking for.
Write that to a file

Lather, rinse and repeat

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


How to remove a string from a txt file?

2019-09-04 Thread Spencer Du
Hi

I want to remove a string from a txt file and then print out what I have 
removed. How do I do this.

The txt file is in this format and should be kept in this format.

txt.txt:
laser,cameras,

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list