Python lower string?

1873
11
Jump to solution
10-22-2014 05:16 AM
JohannesBierer
Occasional Contributor III

After insert lower() there's nothing written in the field? What's wrong?

# Process: Feld berechnen

arcpy.CalculateField_management(FeldHinzugefuegt, "Pfad", "\"U:\\rips\\images\\tk50\\tk\" & ([BLATT_NR].lower()) & \"co\" & \"*.*\"", "VB", "")

0 Kudos
1 Solution

Accepted Solutions
curtvprice
MVP Esteemed Contributor

The VBScript function is LCase, as in

LCase("STRING")

I really like splitting long Python statements on multiple lines;  the interpreter ignores the newline if you are inside ( 😞

# VB Parser

arcpy.CalculateField_management(FeldHinzugefuegt, "Pfad", 

    ("\"U:\\rips\\images\\tk50\\tk\" & LCASE([BLATT_NR])"

     "& \"co\" &  \"*.*\"",

    "VB")'

# Python Parser (better, and will run in arcpy 64)!

arcpy.CalculateField_management(FeldHinzugefuegt, "Pfad", 

    ("\"U:\\rips\\images\\tk50\\tk"

    "{}\\co\\*.*\".format(!BLATT_NR!).lower()"),

    "PYTHON")

View solution in original post

0 Kudos
11 Replies
Zeke
by
Regular Contributor III

I'd put the calculation expression in a variable and check that. It kind of looks like your quotation marks are off, but honestly it's a bit hard to follow all that.

0 Kudos
JohannesBierer
Occasional Contributor III

Thanks for the answer. The field calculation work without lower() function, so don't care about all the funny text around.

This must be the problem. Or can`t you lower the expression of a field string in this manner?

0 Kudos
JamesCrandall
MVP Frequent Contributor

I don't believe ".lower()" can be used with the VB parser.  That is Python.

curtvprice
MVP Esteemed Contributor

The VBScript function is LCase, as in

LCase("STRING")

I really like splitting long Python statements on multiple lines;  the interpreter ignores the newline if you are inside ( 😞

# VB Parser

arcpy.CalculateField_management(FeldHinzugefuegt, "Pfad", 

    ("\"U:\\rips\\images\\tk50\\tk\" & LCASE([BLATT_NR])"

     "& \"co\" &  \"*.*\"",

    "VB")'

# Python Parser (better, and will run in arcpy 64)!

arcpy.CalculateField_management(FeldHinzugefuegt, "Pfad", 

    ("\"U:\\rips\\images\\tk50\\tk"

    "{}\\co\\*.*\".format(!BLATT_NR!).lower()"),

    "PYTHON")

0 Kudos
JamesCrandall
MVP Frequent Contributor

Untested:

Likely what will work:

arcpy.CalculateField_management(FeldHinzugefuegt, "Pfad", r"U:\rips\images\tk50\tk\\" + ([BLATT_NR].lower()) + "co\\" + "*.*", "PYTHON_9.3", "")

Or from your original code:

arcpy.CalculateField_management(FeldHinzugefuegt, "Pfad", "\"U:\\rips\\images\\tk50\\tk\" + ([BLATT_NR].lower()) + \"co\" + \"*.*\"", "PYTHON_9.3", "")
0 Kudos
DanPatterson_Retired
MVP Emeritus

do it manually first then copy the syntax from the field calculator expression, fields in python are enclosed in ! ! marks, if that makes a difference

0 Kudos
JohannesBierer
Occasional Contributor III

Thanks for your answers, but I can't follow them or they don't work.

I try now to get a model to work and then export to python.

!BLATT_NR!.lower()

This works in the model

"U:\\rips\\images\\tk50\\" & !BLATT_NR!.lower() & "co.*"

For this I get a error message?

ERROR 000539: Error running expression: "U:\\rips\\images\\tk50\\" & "L6518".lower() & "co.*"

Traceback (most recent call last):

  File "<expression>", line 1, in <module>

TypeError: unsupported operand type(s) for &: 'str' and 'str'

What's the problem?

0 Kudos
JohannesBierer
Occasional Contributor III

What I need:

"U:\\rips\\images\\tk50\\l6518co.*"

0 Kudos
JohannesBierer
Occasional Contributor III

This is for the model ok:

"U:\\rips\\images\\tk50\\" + !BLATT_NR!.lower() + "co*.*"

Result export to python:

# Process: Feld berechnen

arcpy.CalculateField_management(Orthos_Nummern_Layer, "Pfad", "\"U:\\\\rips\\\\images\\\\tk50\\\\\"

+ !BLATT_NR!.lower() + \"co*.* \"", "PYTHON", "")

No field calculate?

Tried this:

arcpy.CalculateField_management(Orthos_Nummern_Layer, "Pfad", "\"U:\\rips\\images\\tk50\\\"

+ !BLATT_NR!.lower() + \"co*.* \"", "PYTHON", "")

No field calculate?

0 Kudos