Pergunta

Does anyone know how Python deals with ConfigParser line endings in the different OSes? Because it follows the Windows INI format. But what about Linux?

(As you know, Windows text line endings are typically CRLF, and Unix's are CR.)

I want users of my app to take their config files (.INI files) easily from Windows to Linux and I'd like to know if that's going to be problematic. If it does use different line endings for Unix and Windows, what do you recommend?

Foi útil?

Solução

You're fine, ConfigParser will still work.

The reason is that is uses fp.readline, which reads up to and including the next LF (\n). The value is then stripped of whitespace, which removes the CR (\r).

I'd say just use LF (\n) as your line separator - it will work on both systems, but using both won't cause any harm either.

Edit: In fact, if you generate a file using ConfigParser.RawConfigParser it will use \n as the line separator.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top