0
def export_csv_standard_units(name):
    cursor.execute("select distinct(standard_units) from activities where standard_type='IC50' ")
    result_standard_units_distinct = cursor.fetchall()

    cursor.execute("select standard_units from activities where standard_type='IC50' ")
    result_standard_units = cursor.fetchall()

    field_standard_units = ()
    cnt = []

    for result in result_standard_units_distinct:
        field_standard_units = field_standard_units + (result_standard_units_distinct,)

    length = int(len(field_standard_units))

    for i in result_standard_units:
        for j in length:
            if field_standard_units(j) == result_standard_units(9):
                cnt[j] = cnt[j] + 1
    field = (field_standard_units, cnt)

    export_field = open('%s_standard_units.csv' %name, 'wb')
    export_csv_field = csv.writer(export_field)
    export_csv_field.writerows([field])

    export_field.close()

I have some problem to run my python file. I want to make the csv.file for data counting like this..

standard_units count standard_unit1 123 standard_unit2 234

but, It has error like this.

   File "manage.py", line 42
     for j in length:
   TypeError: 'int' object is not iterable

What does it mean iterable?

1
  • Something like Array? Commented Feb 11, 2015 at 8:58

1 Answer 1

2

Like your error message said: ints are not iterable. Use a range

for j in range(length):
    ...

If length is 10, range(length) will give you the values 0..9.

You don't have to actually calculate the length in advance - instead you can enumerate the field_standard_units:

for j, unit in enumerate(field_standard_units):
    if unit == result_standard_units(9):  # What's 9?
        ...

Note: Use xrange if your range is very large since range creates a list, and thus all of its members occupy the memory, whilst xrange creates a generator just like enumerate.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.