UPDATE: 2019-06-25
Test your paths
def check_path(out_fc):
"""Check for a filegeodatabase and a filename"""
msg = dedent(check_path.__doc__)
_punc_ = '!"#$%&\'()*+,-;<=>?@[]^`~}{ '
flotsam = " ".join([i for i in _punc_]) # " ... plus the `space`"
fail = False
if (".gdb" not in fc) or np.any([i in fc for i in flotsam]):
fail = True
pth = fc.replace("\\", "/").split("/")
name = pth[-1]
if (len(pth) == 1) or (name[-4:] == ".gdb"):
fail = True
if fail:
tweet(msg)
return (None, None)
gdb = "/".join(pth[:-1])
return gdb, name
What 'flotsam' in the _punc_ list do you use?
Is it a work restriction?
Did you work institute 'dot' user names than have to backtrack and replace them with underscores?
Would love to hear the stories.
-------------------------------------------------------------------------------------------
Warnings
People still continue to be confused about file path naming conventions when using python. Please take the time to read. Python 3.x is used in ArcGIS Pro so you may encounter a new problem...
pth = "C:\Users\dan_p\AppData\Local\ESRI\ArcGISPro"
File "<ipython-input-66-5b37dd76b72d>", line 1
pth = "C:\Users\dan_p\AppData\Local\ESRI\ArcGISPro"
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
# ---- the fix is still raw encoding
pth = r"C:\Users\dan_p\AppData\Local\ESRI\ArcGISPro"
pth
'C:\\Users\\dan_p\\AppData\\Local\\ESRI\\ArcGISPro'
-------------------------------------------------------------------------------------------
READINGS: String and bytes literals
Still not allowed
pth = r"C:\Users\dan_p\AppData\Local\ESRI\ArcGISPro\" # ---- note the \ at the end
File "<ipython-input-86-70ede0dfa3fe>", line 1
pth = r"C:\Users\dan_p\AppData\Local\ESRI\ArcGISPro\"
^
SyntaxError: EOL while scanning string literal # ---- which means you 'escaped' the "
-------------------------------------------------------------------------------------------
HISTORY: take the poll first before you read on
I am sure everyone is sick of hearing ... check your filenames and paths and make sure there is no X or Y. Well, this is going to be a work in progress which demonstrates where things go wrong while maintaining the identity of the guilty.
Think about it |
---|
|
Examples... Rules broken and potential fixes |
---|
Total garbage... as well as way too long. Time to buy an extra drive.
-------------------------------------------------------------------------------------------------------------------------- Solution 1... raw format
-------------------------------------------------------------------------------------------------------------------------- Solution 2... double backslashes
-------------------------------------------------------------------------------------------------------------------------- Solution 3... forward slashes
-------------------------------------------------------------------------------------------------------------------------- Solution 4... os.path functions There are very useful functions and properties in os.path. The reader is recommended to examine the contents after importing the os module (ie dir(os.path) and help(os.path)
ad nauseum -------------------------------------------------------------------------------------------------------------------------- Gotcha's Fixes often suggest the following ... what can go wrong, if you failed to check. (1)
(2)
(3)
(4)
(5) This isn't going to happen again!
(6) Last try
Well this isn't good! Lesson? Get it right the first time. Remember the next time someone says... Have you checked your file paths...????? Remember these examples. Curtis pointed out this helpful link...I will include it here as well Paths explained: Absolute, relative, UNC, and URL—Help | ArcGIS for Desktop That's all for now. I will deal with spaces in filenames in an update. I am not even to go to UNC paths. |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.