#πŸ”’ Need help with running a .py file

23 messages Β· Page 1 of 1 (latest)

indigo wagon
#

Hi, so i dont really use python to do anything, but i decided to get chatgpt to write something for me today.

So i have to type AI=fixed Under RESTRICTOR=0 but only if the MODEL=name contains traffic (as shown below)

[CAR_63]
MODEL=traffic_dodge_challenger_srt
SKIN=00_sepang_blue_pearl_effect_br
SPECTATOR_MODE=0
DRIVERNAME=
TEAM=
GUID=
BALLAST=0
RESTRICTOR=0
AI=fixed

with the following script, it doesnt run it correctly. It opens the script for under half a second than dissapeers without even modifying the entry_list.cfg file. How may i fix this

`# Define the file path
file_path = 'entry_list.cfg'

Open the file and read its contents

with open(file_path, 'r') as file:
lines = file.readlines()

Iterate through the lines and modify as needed

modified_lines = []
for line in lines:
# Check if the line contains "MODEL=traffic"
if 'MODEL=traffic' in line:
# Add "AI=fixed" under "RESTRICTOR=0"
if line.strip().startswith('RESTRICTOR=0'):
modified_lines.append(line)
modified_lines.append('AI=fixed\n')
else:
modified_lines.append(line)
else:
modified_lines.append(line)

Write the modified content back to the file

with open(file_path, 'w') as file:
file.writelines(modified_lines)`

vapid pantherBOT
#

@indigo wagon

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.

hearty vessel
#

Unless you're very firm with ChatGPT it tends to produce nonsensical code for things that aren't super basic.

#

What's the problem you're having?

indigo wagon
#

i was really descriptive with what i needed it to produce. So i assume that what it made was going to work right

hearty vessel
#

ChatGPT is not logically consistent so I would never assume that.

indigo wagon
hearty vessel
#

And of course a problem with asking ChatGPT to produce code for something you don't understand is that if it doesn't work you have no idea what went wrong.

#

How are you running it?

hearty vessel
#

You should run it from a cmd window

#

That way you can see any errors it produces.

indigo wagon
#

i pasted the code into a notepad file and saved it as new.py than placed it in the directory containing the file i needed it to modify and then ran it

#

i wasnt sure how to run it in cmd

hearty vessel
#

win+r, type cmd, enter, then cd to the directory that the file is in.

#

Then py script.py

indigo wagon
#

ok, so if im understanding correctly i type in

cd H:\SteamLibrary\assettocorsa\server\presets\SRP PUBLIC 1 SWRVN (this is where my script is placed in)

Then py new.py (since new.py is the script name)

hearty vessel
#

In cmd you can usually tab-complete stuff. If the file path has spaces in it you'll need to surround the entire thing in quotes

#

e.g. if you type cd \Ste then hit tab it might autocomplete that for you

#

just a tip

#

make sure you're not violating the TOS of the game.

vapid pantherBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.