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

  • Home
  • SEARCH
  • 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 514191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:29:56+00:00 2026-05-13T07:29:56+00:00

I am using some python to do some variable name generation. For some reason

  • 0

I am using some python to do some variable name generation. For some reason I am only getting part of what I need.

import sys
import csv

params = csv.reader(open('params.csv'), delimiter=',', skipinitialspace=True)

flags_r = []
flags_w = []
numbers_r = []
numbers_w = []
station = ['AC1','DC1','DC1']
drive = ['','Fld','Arm']

for i in range(3):
    for p in params:
        try:
            desc = p[1].split(' ')
            desc = [part.capitalize() for part in desc]
            desc = "".join(desc)
        except IndexError, e:
            print 'IndexError: %s' %(e,)
            continue
        print station[i],drive[i],p[0]
        flags_r.append( 'mod%(station)s_%(drive)sP%(param)04dr_%(desc)s' % \
                          { 'station' : station[i], 'drive' : drive[i], 'param': int(p[0]), 'desc':desc })
        flags_w.append( 'mod%(station)s_%(drive)sP%(param)04dw_%(desc)s' % \
                          { 'station' : station[i], 'drive' : drive[i], 'param': int(p[0]), 'desc':desc })
        numbers_r.append( 'mod%(station)s_%(drive)sP%(param)04drn_%(desc)s' % \
                          { 'station' : station[i], 'drive' : drive[i], 'param': int(p[0]), 'desc':desc })
        numbers_w.append( 'mod%(station)s_%(drive)sP%(param)04dwn_%(desc)s' % \
                          { 'station' : station[i], 'drive' : drive[i], 'param': int(p[0]), 'desc':desc })

    print i

params.csv:

100, Speed Reference
101, Speed Feedback

for some reason it is outputting:

AC1 100
AC1 101
0
1
2

the reason for the try/except is to catch any blank rows or missing second fields in the csv file.

It appears that the inner loop only get executed on the first pass. The only reason I can see for this to happen would be the try/except as I have done an interactive example to test it.

  • 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-05-13T07:29:57+00:00Added an answer on May 13, 2026 at 7:29 am

    In the first iteration of the outer loop you read all lines from params. In the second iteration all the lines from params are already read, so there is nothing left to iterate over in the inner loop.

    To work around this, you could load all the data sets into a list and then iterate over that list:

    reader = csv.reader(open('params.csv'), delimiter=',', skipinitialspace=True)
    params = list(reader)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Got an answer on the padrino mailing list that fixes… May 16, 2026 at 11:51 am
  • Editorial Team
    Editorial Team added an answer Using Custom Query Table Structure: ID insurance_name invested_amount investement_date public… May 16, 2026 at 11:51 am
  • Editorial Team
    Editorial Team added an answer Place the code that runs on page load in a… May 16, 2026 at 11:51 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am using BeautifulSoup in Python and am having trouble replacing some tags. I
I want to do some image processing using Python. Is there a simple way
I have a Python script and I am trying to set a variable so
Using Python (3.1 or 2.6), I'm trying to read data from binary data files
I've just started using Python and I was thinking about which notation I should
Question: Is it possible to use a variable as your table name without having
I am trying to update my changes to some python work onto an SVN
I'm trying to run an Icecast stream using a simple Python script to pick
I have below variables try to make an auto generating SQL statement in python
Is there any way to format a string by name rather than position 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.