Python fileDialog2 command help


#1

Hello,

new to coding here and I’m stuck trying to get the right file path.

cmds.fileDialog2(fileMode=2, caption="filepath", rf= True)

when I run that code, choose the right folder and print it,
I get the file path

[u'E:/xxxx/xxxx']

my question is, how do I remove the “[u” at the start and “]” at the end?
I intend to change directory with that path so i’m putting into a variable however due to it’s state, i end up with invalid mode (‘r’) or filename: “[u’E:/xxxx/xxxx’]/xxxx.txt” # error

hopefully I’ve explained it well enough,
many thanks in advance!


#2

The [] indicates that the result is an array. You can get a value by index:

filename = result[0]

#3

Managed to figure it out but couldn’t see this post(had to wait for approval) to edit it.
Thanks though! :slight_smile: I still appreciate the help ^^