Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8569643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:23:01+00:00 2026-06-11T18:23:01+00:00

Here is a problem which is annoying me during these last two hours. I

  • 0

Here is a problem which is annoying me during these last two hours.
I have a template file with multiple lines and in some lines some words have to be changed by some others. Here is how my template looks like:

subnet {{ MY_SUBNET }} netmask {{ MY_NETMASK }} {}

subnet {{ MY_SUBNET }} netmask {{ MY_NETMASK }}
{
option domain-name-servers {{ MY_DOMAIN_IP }}; 
option domain-name {{ MY_DOMAIN_NAME }}; 
option routers {{ MY_GATEWAY }}; 
option broadcast-address {{ MY_BROADCAST }};

Here is the code I am using:

f = open(DHCPD_PATH, 'w')
g = open(TEMPLATE_PATH, 'r')
patterns = { 
   '{{ MAC_ADDRESS }}'     : mac,
   '{{ IP_ADDRESS }}'      : ip, 
   '{{ MY_IP }}'           : MY_IP,
   '{{ MY_DOMAIN_IP }}'    : MY_DOMAIN_IP,
   '{{ MY_DOMAIN_NAME }}'  : MY_DOMAIN_NAME,
   '{{ MY_NETMASK }}'      : MY_NETMASK,
   '{{ MY_GATEWAY }}'      : MY_GATEWAY,
   '{{ MY_SUBNET }}'       : MY_SUBNET,
   '{{ MY_BROADCAST }}'    : MY_BROADCAST,
}   
content = g.read()
for i,j in patterns.iteritems():
   content = content.replace(i,j)
f.write(content)
f.close()
g.close()

Here is the file I get:

subnet 192.168.10.0 netmask {{ MY_NETMASK }} {}

subnet 192.168.10.0 netmask 255.255.255.0
{
  option domain-name-servers 192.168.10.10;
  option domain-name "localnet.lan";
  option routers 192.168.10.1;
  option broadcast-address 192.168.10.255;
  default-lease-time 600;
  max-lease-time 7200;
  filename "pxelinux.0";
  next-server 192.168.10.3;

I can’t understand why is this {{ MY_NETMASK }} remaining whereas one of it has been correctly replaced and every others template-patterns get also correctly replaced.

Can anyone give me a hint on this one? Or at least explain me how to correct it?

Many thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:23:03+00:00Added an answer on June 11, 2026 at 6:23 pm

    @eumiro guessed right: one of your spaces isn’t a space.

    >>> repr('subnet {{ MY_SUBNET }} netmask {{ MY_NETMASK }} {}')
    "'subnet {{ MY_SUBNET }} netmask {{ MY_NETMASK\\xc2\\xa0}} {}'"
                                                  ^^^^^^^^^^
    

    Looks like a non-breaking space.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a small problem here which i cannot fix,This post goes through but
Got a problem which to me make no sense. So here goes: I have
I'm developing an Eclipse plug-in and I have a problem which is reproduced here:
Here's the problem: I have couple of pages which gets its content from a
Here is my problem : I have a list of messages which I can
Here's my problem: I have do create a menu/list of actions (which would be
Here is my problem, I have a class which have a object who throw
Probably everyone ran into this problem at least once during development: while(/*some condition here
I'm facing a very annoying problem. Here's the context : I have a rectangle
Related to a question I asked earlier here , I've found a problem which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.