Forum Home
Press F1
 
Thread ID: 108466 2010-03-30 02:19:00 Search Cursor in Python Mike (15) Press F1
Post ID Timestamp Content User
871044 2010-03-30 02:19:00 I have a Python script with a database Search Cursor, which works fine . . . however when I want to output the contents of a field in the database I usually enter something like:


output = row . MyName
row = rows . next()

(where MyName is the name of my field) .

However I want to feed "MyName" to the cursor as a variable, but I can't figure out how to do this:


fieldname = "MyName"
output = row . fieldname
row = rows . next()

Is it possible to do what I'm trying to do? How? :)

Thanks in advance :D

Cheers,
Mike .
Mike (15)
871045 2010-03-30 03:52:00 Nevermind :) got it sorted... seems it was quite module dependant.

Cheers,
Mike.
Mike (15)
871046 2010-04-09 05:59:00 Hi,

Could you post a solution to this problem? I'm having the very same trouble.

Thanks
BenThrossell (15703)
871047 2010-04-09 06:06:00 Could you post a solution to this problem? I'm having the very same trouble. As I said my solution was dependant on the module that produced the search cursor.

The script is at work, so I'll try to remember to look it up when I'm back at work on Monday.

Cheers,
Mike.
Mike (15)
871048 2010-04-11 21:20:00 Its Very hard learning Program language. I need help too! AZ1 (15478)
871049 2010-04-11 21:39:00 Its Very hard learning Program language. I need help too!Might I suggest you a) actually state what your problem is, rather than simply saying you have one, and b) post it in a new thread where it will get more attention, and not clutter up this thread.

You'll get much better assistance that way...
Erayd (23)
871050 2010-04-12 21:11:00 Could you post a solution to this problem? I'm having the very same trouble.
As I said my solution was dependant on the module that produced the search cursor.
Hi BenThrossell,

This is how I did it:
fieldname = "MyName"
output = row.GetValue(fieldname.name)
row = rows.next()where name is the name of the field - there was also type and length.

Hope this helps,
Mike.
Mike (15)
871051 2010-04-26 06:16:00 Hi Mike,

Thanks for the help, sorry for the late reply, asked this just before going on leave . I think my problem is slightly different to yours but hopefully you can tell me what to do to fix it .

What i am trying to do is update a table (so using an update cursor but the principle should be the same) .

This is where i encounter a problem,

code:
MyName = somevariable

row . MyName= somevalue
rows . UpdateRow(row)
row = rows . Next()


I need the "MyName" to be passed as a variable . If I use the code above it looks for the column called MyName which does not exist .

Since this code is part of a loop the column i want it to update changes on each iteration . The column i want to update on each iteration is defined by the "somevariable"

To be honest i feel that I am missing something fairly obvious or are perhaps trying to use the update cursor in the wrong context .

Thanks
BenThrossell (15703)
871052 2010-04-29 23:47:00 Solved!! Just had to use the setvalue function, where MyName is variable (column header)

row.setvalue(MyName,somevalue)
rows.UpdateRow(row)

Thanks
BenThrossell (15703)
1