Configparser. Parsing Error File Contains Parsing Errors
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business python configparser example Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation configparser parsingerror Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like file contains parsing errors configparser you, helping each other. Join them; it only takes a minute: Sign up Python configparser will not accept keys without values up vote 13 down vote favorite So I'm writing a script that reads from a config python argparse file, and I want to use it exactly how configparser is designed to be used as outlined here: http://docs.python.org/release/3.2.1/library/configparser.html I am using Python 3.2.1. The script, when complete, will run on a Windows 2008 R2 machine using the same version of Python, or assuming compatibility, the latest version at the time. #!/user/bin/env python import configparser config = configparser.ConfigParser() config.read('c:\exclude.ini') config.sections() That works fine to read the exclude.ini file - unless I have a value without a key. Thinking I might be doing something wrong tried parsing the example listed here: http://docs.python.org/release/3.2.1/library/configparser.html#supported-ini-file-structure It still throws the following every time: File "C:\Python32\lib\configparser.py", line 1081, in _read raise e configparser.ParsingError: Source contains parsing errors: c:\exclude.ini [line 20]: 'key_without_value\n' I'm at a loss... I'm literally copy/pasting the example code from the documentation for the exact python version I'm using and it's not working as it should. I can only assume I'm missing something as I also can't really find anyone with a similar issue. python python-3.x configparser share|improve this question edited Jun 22 '13 at 0:48 Isxek 695615 asked Feb 28 '12 at 23:39 Sparc 9727 add a comment| 2 Answers 2 active oldest votes up vote 11 down vote accepted The ConfigParser constructor has a keyword argument allow_no_value with a default value of False. Try setting that to true, and I'm betting it'll work for you. share|improve this answer answered Feb 29 '12 at 0:07 Karl Barker 4,9773922 Excellent, thankyou Karl. Perhaps I should send them a note suggesting changing their example .ini to put a comment above that section noting that part only works if the constructor is changed. I suppose I should have read the entire documentation, but the way things were set out it looked to me like it should have worked like this by default. –Sparc Fe
Format Reading Configuration Files Unicode Configuration Data Accessing Configuration Settings Testing whether values are present Value Types Options as Flags Modifying Settings Saving Configuration Files Option Search Path Combining Values with Interpolation Using Defaults Substitution Errors Navigation Table of Contents Previous: csv - Comma-separated value files Next: robotparser - Internet spider access control This Page Show Source Examples The output from all the example programs from PyMOTW has been generated with Python 2.7.8, unless otherwise noted. Some of http://stackoverflow.com/questions/9491521/python-configparser-will-not-accept-keys-without-values the features described here may not be available in earlier versions of Python. If you are looking for examples that work under Python 3, please refer to the PyMOTW-3 section of the site. Navigation index modules | next | previous | PyMOTW » File Formats » ConfigParser - Work with configuration filesĀ¶ Purpose:Read/write configuration files similar to Windows https://pymotw.com/2/ConfigParser/ INI files Available In:1.5 Use the ConfigParser module to manage user-editable configuration files for an application. The configuration files are organized into sections, and each section can contain name-value pairs for configuration data. Value interpolation using Python formatting strings is also supported, to build values that depend on one another (this is especially handy for URLs and message strings). Configuration File FormatĀ¶ The file format used by ConfigParser is similar to the format used by older versions of Microsoft Windows. It consists of one or more named sections, each of which can contain individual options with names and values. Config file sections are identified by looking for lines starting with [ and ending with ]. The value between the square brackets is the section name, and can contain any characters except square brackets. Options are listed one per line within a section. The line starts with the name of the option, which is separated from the value by a colon (:) or equal sign (=). Whitespace around the separator is i
Support Search GitHub This repository Watch 10 https://github.com/vterron/lemon/issues/65 Star 26 Fork 6 vterron/lemon Code Issues 32 Pull requests 0 Projects 0 Pulse Graphs New issue ConfigParser.ParsingError: File contains parsing errors: /home/usc/oa/jgc/.lemonrc #65 Open jorgegocre opened this Issue Jul 29, 2015 · 4 comments Projects None yet Labels None yet Milestone No milestone parsing error Assignees No one assigned 2 participants jorgegocre commented Jul 29, 2015 [uscoajgc@compute-4-2 ~]$ lemon photometry -vvv LEM1/LEMmosaic.fits LEM1/LEM/*.fits LEMphot.LEMONdB Traceback (most recent call last): File "/opt/cesga//lemon-0.2.0/lemon", line 135, in