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 7730347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:12:11+00:00 2026-06-01T06:12:11+00:00

i read data from my config file like this: ip_vlan1 = 10.10.($id+100).5 ip_vlan2 =

  • 0

i read data from my config file like this:

ip_vlan1 = "10.10.($id+100).5"
ip_vlan2 = "10.11.($id*2+1).6"
v.v...

And for each vlan, I want calculate vlan address for it, based on ID and vlan-expression:

def calculate_vlan_id(id, vlan_exp):
    ...
    return ip_addr   # string

Example:

def(3, ip_vlan1) --> result: "10.10.103.5"
def(5, ip_vlan2) --> result: "10.11.11.6"

Do you have a solution for this?

Thanks in advance, folks!

  • 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-01T06:12:12+00:00Added an answer on June 1, 2026 at 6:12 am

    You could use a text templating engine. (Which is safer than using eval based tricks).

    Here’s an example using genshi

    from genshi.template import TextTemplate
    ip_vlan1 = TextTemplate("10.10.${id+100}.5")
    ip_vlan2 = TextTemplate("10.11.${2*id+1}.6")
    print( ip_vlan1.generate(id=3) ) # prints 10.10.103.5
    print( ip_vlan2.generate(id=5) ) # prints 10.11.11.6
    

    If you really need the calculate_vlan_id function it would look something like this:

    def calculate_vlan_id(id,ip_vlan):
      return ip_vlan.generate(id=id)
    

    Edit:

    As requested here’s an example using jinja2: This may not be the best way to do this, the jinja2 docs are large and confusing.

    ip_vlan1 = jinja2.Template('10.10.{{id+100}}.5')
    ip_vlan2 = jinja2.Template('10.11.{{2*id+1}}.6')
    ip_vlan1.render(id=3)
    ip_vlan2.render(id=5)
    

    Both these methods are untested

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

Sidebar

Related Questions

Puppy meta data gets read in from config file using (General::Config) and creates this
I want to read data from XML file but it showing the following errors:
I am trying to read data from a file stream as shown below: fileStream.Read(byteArray,
I'm trying to read data from a binary file and put it into a
I need to read data from a legacy database file produced by Visual Basic
So here is a snippet from the config file I'd like to parse (It
I would like to store log4net config data in my application.config file. Based on
I can read the connection strings from the config file, however I need to
I want put all configuration data from WPF projects to one file for whole
I am trying to read data from properties file.I have specified the path in

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.