#๐Ÿ”’ Inserting a section of text in a quite particular spot

21 messages ยท Page 1 of 1 (latest)

low hatchBOT
#

@cold tendon

Python help channel opened

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.

soft ice
#

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.

cold tendon
#

Thanks!

soft ice
#

!paste

low hatchBOT
#
Pasting large amounts of code

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.

soft ice
#

You can use this instead

cold tendon
#

Alright, thank you!

soft ice
#

also please paste the full error message and your code

cold tendon
#

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

soft ice
cold tendon
#

Yep, that's the main issue

soft ice
cold tendon
#

If I can get it to accept slashes I think it'll work

#

Thanks for the pointer, I'll check it out!

cold tendon
#

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?

low hatchBOT
#
Python help channel closed for inactivity

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.