Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The file operation program is not updating #23

Open
gopalthakur71 opened this issue Nov 30, 2023 · 1 comment
Open

The file operation program is not updating #23

gopalthakur71 opened this issue Nov 30, 2023 · 1 comment

Comments

@gopalthakur71
Copy link

def update_server_config(file_path, key, value):
# Read the existing content of the server configuration file
with open(file_path, 'r') as file:
lines = file.readlines()

# Update the configuration value for the specified key
with open(file_path, 'w') as file:
    for line in lines:
        # Check if the line starts with the specified key
        if key in line:
            # Update the line with the new value
            file.write(key + "=" + value + "\n")
            print("File update successfully")
        else:
            # Keep the existing line as it is
            file.write(line)
            print("No change done")

Path to the server configuration file

server_config_file = 'server.conf'

Key and new value for updating the server configuration

key_to_update = 'PORT'
new_value = '9000' # New maximum connections allowed

Update the server configuration file

update_server_config(server_config_file, key_to_update, new_value)

This program is running but it is not updating to new value.

@iam-veeramalla
Copy link
Owner

Did you try to debug if the file is read ? try to use some print statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants