#๐ Inserting a section of text in a quite particular spot
21 messages ยท Page 1 of 1 (latest)
@cold tendon
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Hi @cold tendon, looks like the bot zapped your message
Hi, here again, last little bit of this program that's giving me a headache. For Prepar3D aircraft liveries, there needs to be an entry in the aircraft.cfg. I have that file as well as the section that needs to go in, but can't figure out a way to get it there.
The file seemed to be structured well for configparser, but it throws an error at the slashes used for comments/decoration. The file is attached here, the entry I need to add is another one of those [fltsim.x] near di beninging along with all the keys within. It needs to go in as the last of the fltsim entries, with the index to match.
Thanks!
!paste
So that everyone can easily read your code, you can paste it in this website:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
You can use this instead
Alright, thank you!
also please paste the full error message and your code
https://paste.pythondiscord.com/LWEQ
File "PMDG Livery Installer.py", line 102, in <module>
File "configparser.py", line 761, in read
File "configparser.py", line 1077, in _read
File "configparser.py", line 1105, in _read_inner
File "configparser.py", line 1129, in _handle_rest
configparser.MissingSectionHeaderError: File contains no section headers.
file: 'C:\\Program Files\\Lockheed Martin\\Prepar3D v5\\SimObjects\\Airplanes\\PMDG 747-400\\aircraft.cfg', line: 1
'/////////////////////////////////////////////////////////\n'
[PYI-12244:ERROR] Failed to execute script 'PMDG Livery Installer' due to unhandled exception!```
I don't have the full code at the moment since I tried to figure out some other way avoiding configparser but it didn't work out
https://docs.python.org/3/library/configparser.html#supported-ini-file-structure
Configuration files may include comments, prefixed by specific characters (# and ; by default [1]). Comments may appear on their own on an otherwise empty line, possibly indented.
Looks like//is not supported for comment syntax
Yep, that's the main issue
https://docs.python.org/3/library/configparser.html#configparser.ConfigParser looks like there's a comment_prefixes parameter here
If I can get it to accept slashes I think it'll work
Thanks for the pointer, I'll check it out!
Best possible thing happened, it crashed while trying to print a success message :D
It's inserting it at the end, doing it like this
ac_cfg['fltsim.'+str(ind)] = config_reg['fltsim.x']```
where ```ac_cfg``` is the configparser from the full aircraft.cfg and ```config_reg``` is the section that goes in
ind is just the next number in line for the fltsim entries
Is there any way to choose where a new section goes?
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.