|
POST
|
I am trying to attach a txt file to my email I am creating in python. Anyone know how I can attach a txt file to the email? #....snip
outFile = open(r"C:\Users\\TestFile.text", "w")
# return all rows
with arcpy.da.SearchCursor(fc, ['*'], where_clause=expression) as cursor:
# return specific rows
#with arcpy.da.SearchCursor(fc, [class_field, name_field], where_clause=expression) as cursor:
for row in cursor:
## Print the name of the residential road
#print('{0}, {1}'.format(row[0], row[1]))
print(row)
zval = str('{0}, {1}'.format(row[0], row[1]))
outFile.write(zval + "\n")
outFile.close()
#===SET EMAIL To AND From==============================
FROMADDR = "[email protected]"
TOADDRS = ["[email protected]"]
#===BUILD EMAIL========================================
def msgEmail():
msg = "Test"
server = smtplib.SMTP('smtp0.sitevision.com',25)
server.set_debuglevel(1)
server.ehlo()
server.sendmail(FROMADDR, TOADDRS, msg)
server.quit()
return "Email Sent but Import Aborted"
#===PROCESS EMAIL======================================
getMsgP = msgEmail()
print getMsgP
... View more
11-21-2016
01:10 PM
|
0
|
5
|
3949
|
|
POST
|
I swear last one.......there is a 'u' in front of all the returns when I do *....thoughts? 3, u'{C8339E75-38A8-4D36-B4CF-F837B32C9BBC}', u'2', u'Amherst', u'Mill Creek',
... View more
11-18-2016
01:43 PM
|
0
|
1
|
1252
|
|
POST
|
Had to modify the print...good to go...THANK YOU ALL print(row)
... View more
11-18-2016
01:41 PM
|
1
|
2
|
1252
|
|
POST
|
Thanks...I forgot the ' ' but it only shows me 2 fields in the python shell... with arcpy.da.SearchCursor(fc, ['*'],
... View more
11-18-2016
01:40 PM
|
0
|
3
|
1253
|
|
POST
|
One last thought....how do I push all fields in the FC to output instead of listing all individually?
... View more
11-18-2016
01:32 PM
|
0
|
5
|
1253
|
|
POST
|
Think this is working... yea......thank you all for your patience and help...greatly appreciated....now onto figuring out how to write this to a text file. import arcpy
arcpy.env.workspace = "C:\\Users\\xx\\AppData\\Roaming\ESRI\\Desktop10.4\\ArcCatalog\\[email protected]"
fc = "Inspection_2"
class_field = 'regulations'
name_field = 'region_1'
# Create an expression with proper delimiters
#expression = u'{} = No'.format(arcpy.AddFieldDelimiters(fc, class_field))
expression = "regulations = 'No' OR region_1 = '2'"
# Create a search cursor using an SQL expression
with arcpy.da.SearchCursor(fc, [class_field, name_field],
where_clause=expression) as cursor:
for row in cursor:
# Print the name of the residential road
print('{0}, {1}'.format(row[0], row[1]))
... View more
11-18-2016
01:31 PM
|
0
|
0
|
1252
|
|
POST
|
Yes I am using SQL and hitting SDE...just need to build the sql_clause then I guess...getting to syntax to work right for something like this is where I am having issues: safteysign = Yes OR regulations = No The below works but there is no WHERE clause or sql Clause import arcpy
arcpy.env.workspace = "C:\\Users\\xxk\\AppData\\Roaming\ESRI\\Desktop10.4\\ArcCatalog\\[email protected]"
fc = "Inspection_2"
fields = ['safteysign', 'regulations', 'region_1']
## Use ORDER BY sql clause to sort field values
for row in arcpy.da.SearchCursor(
fc, fields, sql_clause=(None, 'ORDER BY regulations')):
print('{0}, {1}, {2}'.format(row[0], row[1], row[2]))
... View more
11-18-2016
01:21 PM
|
0
|
0
|
1240
|
|
POST
|
Trying this import arcpy
arcpy.env.workspace = "C:\\Users\\xx\\AppData\\Roaming\ESRI\\Desktop10.4\\ArcCatalog\\[email protected]"
fc = "Inspection_2"
class_field = 'regulations'
name_field = 'region_1'
# Create an expression with proper delimiters
expression = u'{} = No'.format(arcpy.AddFieldDelimiters(fc, class_field))
# Create a search cursor using an SQL expression
with arcpy.da.SearchCursor(fc, [class_field, name_field],
where_clause=expression) as cursor:
for row in cursor:
# Print the name of the residential road
print('{0}, {1}'.format(row[0], row[1])) Get this error: Traceback (most recent call last): File "C:\Users\adminjk\Desktop\PythonSync\Python Scripts\SearchCursor2.py", line 16, in <module> for row in cursor: RuntimeError: Attribute column not found [42S22:[Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name 'No'.] [DGIF_TEST.DBO.Inspection_2]
... View more
11-18-2016
01:14 PM
|
0
|
9
|
1253
|
|
POST
|
Thank you all very much for the help... getting confused....Blake saying to use Where Clause in ex 4? and you saying use 5b with sql_clause...
... View more
11-18-2016
01:10 PM
|
0
|
2
|
1240
|
|
POST
|
I now started using this example: not sure if I use a WHERE clause or sql_clause....very new to this so please forgive my ignorance. But need to insert a WHERE clause : safteysign = Yes OR regulations = No import arcpy
arcpy.env.workspace = "C:\\Users\\xxx\\AppData\\Roaming\ESRI\\Desktop10.4\\ArcCatalog\\[email protected]"
fc = "Inspection"
fields = ['safteysign', 'regulations']
# Use ORDER BY sql clause to sort field values
for row in arcpy.da.SearchCursor(
fc, fields, sql_clause=(None, 'regulations')):
print('{0}, {1}'.format(row[0], row[1]))
... View more
11-18-2016
12:42 PM
|
0
|
5
|
1240
|
|
POST
|
That was just the example I was referencing....I am trying to build a query that will search at a SDE FC Where Field1 = No or FIeld2 = Yes
... View more
11-18-2016
12:33 PM
|
0
|
11
|
1241
|
|
POST
|
this example right from ESRI examples Example 4 here: SearchCursor—Data Access module | ArcGIS for Desktop
... View more
11-18-2016
12:24 PM
|
0
|
7
|
1240
|
|
POST
|
But what If I wanted classfield=Yes and name_field=No
... View more
11-18-2016
12:12 PM
|
0
|
1
|
3498
|
|
POST
|
ooooh....I think its looking at 2 fields and not 1 is that right?
... View more
11-18-2016
12:10 PM
|
0
|
3
|
3498
|
|
POST
|
yea thats where I got to example from...what the heck is class_field varaible?
... View more
11-18-2016
12:09 PM
|
0
|
0
|
3498
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 09-20-2018 11:09 AM | |
| 1 | 09-10-2018 06:26 AM | |
| 1 | 09-15-2022 11:02 AM | |
| 1 | 05-21-2021 07:35 AM | |
| 1 | 08-09-2022 12:39 PM |
| Online Status |
Offline
|
| Date Last Visited |
09-19-2022
09:23 PM
|