Re: ConfigParser: use newline in INI file
On Saturday, October 1, 2016 at 7:41:40 PM UTC-5, Ned Batchelder wrote: > On Saturday, October 1, 2016 at 6:25:16 PM UTC-4, Thorsten Kampe wrote: > > * Ben Finney (Sun, 02 Oct 2016 07:12:46 +1100) > > > > > > Thorsten Kampe writes: > > > > > > > ConfigParser escapes `\n` in ini values as `\\n`. > > > > Indenting solves the problem. I'd rather keep it one line per value > > but it solves the problem. > > If you want to have \n mean a newline in your config file, you can > do the conversion after you read the value: > > >>> "a\\nb".decode("string-escape") > 'a\nb' > > --Ned. Wow! Thanks so much Ned. I've been looking for the solution to this issue for several days and had nearly given up. Jim -- https://mail.python.org/mailman/listinfo/python-list
Re: ConfigParser: use newline in INI file
On Thursday, March 7, 2019 at 8:55:31 AM UTC-6, tony wrote: > On 07/03/2019 14:16, jim.womeld...@gmail.com wrote: > > On Saturday, October 1, 2016 at 7:41:40 PM UTC-5, Ned Batchelder wrote: > >> On Saturday, October 1, 2016 at 6:25:16 PM UTC-4, Thorsten Kampe wrote: > >>> * Ben Finney (Sun, 02 Oct 2016 07:12:46 +1100) > > Thorsten Kampe writes: > > > ConfigParser escapes `\n` in ini values as `\\n`. > >>> > >>> Indenting solves the problem. I'd rather keep it one line per value > >>> but it solves the problem. > >> > >> If you want to have \n mean a newline in your config file, you can > >> do the conversion after you read the value: > >> > >> >>> "a\\nb".decode("string-escape") > >> 'a\nb' > >> > >> --Ned. > > > > Wow! Thanks so much Ned. I've been looking for the solution to this issue > > for several days and had nearly given up. > > Jim > > > How does that translate to Python3? I have no idea. I'm on 2.7.3 I'd be interested in knowing if someone would try it on 3. I do very little Python programming. I've written a messaging system for Linuxcnc and could not get it to work using bash, so I tried Python and now, thanks to you, I have it working. I can provide you with the code if you want to play with it. When it is run with an integer as a parameter it displays a message from an INI file. Jim -- https://mail.python.org/mailman/listinfo/python-list
Re: ConfigParser: use newline in INI file
On Saturday, October 1, 2016 at 9:57:24 AM UTC-5, Thorsten Kampe wrote: > Hi, > > ConfigParser escapes `\n` in ini values as `\\n`. Is there a way to > signal to ConfigParser that there is a line break? > > Thorsten And now we know! I think they should have named Python 3 something else -- https://mail.python.org/mailman/listinfo/python-list
Re: ConfigParser: use newline in INI file
On Thursday, March 7, 2019 at 10:38:03 AM UTC-6, jim.wo...@gmail.com wrote: > On Saturday, October 1, 2016 at 9:57:24 AM UTC-5, Thorsten Kampe wrote: > > Hi, > > > > ConfigParser escapes `\n` in ini values as `\\n`. Is there a way to > > signal to ConfigParser that there is a line break? > > > > Thorsten > > And now we know! > I think they should have named Python 3 something else I just tried "unicode_decode" in place of "string-decode" and it works. My impression is that it will also work in Python 3 -- https://mail.python.org/mailman/listinfo/python-list