trouble using \ to escape %
I'm writing a python script that modifies the smb.conf file, and i need to write the characters '%U' in the file. I tried making a string like so: str1 = "[%s%s]\n\tpath = /mnt/samba/%s%s/\%U" % (list[0], list[1], list[0], list[1]) but i keep getting: "TypeError: not enough arguments for format string". I've also tried making the string: str1 = "[%s%s]\n\tpath = /mnt/samba/%s%s/\%" % (list[0], list[1], list[0], list[1]) but i get: "ValueError: incomplete format". These errors lead me to believe that for some reason it is not escaping the '%' character. There has to be a way to write '%' to a file. Thanks in advance.. Cheers -Lucas Machado -- http://mail.python.org/mailman/listinfo/python-list
Re: Win32 drive mapping... aka "net use"
Roger Upole wrote: > You could use win32api.GetLogicalDriveStrings to list > the drive letters currently in use, and find the next free > letter. net use * probably does something like that under > the covers. I went and took your advice and this is where I am now: >>> import win32api >>> a = win32api.GetLogicalDriveStrings() >>> a 'A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00' >>> print a A:\ C:\ D:\ E:\ Z:\ So I think this function will work great since it gives me a string that i can simply strip away what i don't need and then split it into a list and traverse the list. However, when I try to split it, the following occurs: >>> b = a.strip(r'\\\x00') >>> b 'A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00' >>> b = a.split(r'\\\x00') >>> b ['A:\\\x00C:\\\x00D:\\\x00E:\\\x00Z:\\\x00'] I'm a bit of a novice at python (even more so of the win32 api), but I've used the split and strip functions before (for example to get rid of '\n' from strings) so it is unclear to me why this does not work. Thanks --LM -- http://mail.python.org/mailman/listinfo/python-list
handling pywintypes.error exceptions
I'm using the win32 api to map samba shares, and I'm having trouble handling some exceptions. In my script there are 2 possible exceptions when the script attempts to map a share: >>> win32net.NetUseAdd(None, 1, {'remote':r'\\foo\bar','local':'X Traceback (most recent call last): File "", line 1, in ? pywintypes.error: (53, 'NetUseAdd', 'The network path was not found.') This exception occurs when '\\foo\bar' is not an existing share. Also, when a drive letter is already in use the following occurs: >>> win32net.NetUseAdd(None, 1, {'remote':r'\\some_server\share','local':'Y:'}) Traceback (most recent call last): File "", line 1, in ? pywintypes.error: (85, 'NetUseAdd', 'The local device name is already in use.') I know the exception raised in these cases is "pywintypes.error", but how can i differentiate between the two exceptions? Being able to do this is critical for my script Thanks in advance, --Lucas Machado -- http://mail.python.org/mailman/listinfo/python-list
Re: Win32 drive mapping... aka "net use"
I have already seen the "net help use" and i know how to manage samba shares from a command prompt. What i need help with is using the win32 api for python to manage shares --Lucas -- http://mail.python.org/mailman/listinfo/python-list
Re: Win32 drive mapping... aka "net use"
Alex Martelli wrote: > import win32net > win32net.NetUseAdd(None,1,{'remote':r'\\server\share','local':'K:'}) > > is an example (not all that easy to fathom from the docs, but I > found it out with a little help from the docs, a little from MSDN, > and a little experimentation). I looked through the MSDN and was not able to find much information on how to properly use the NetUseAdd function. I searched for the function and looked through the results but all it showed was some data structure, but i was actually looking for a list of all possible arguments and which arguments were/were not required. my problem with the above NetUseAdd example is that I would rather not have to specify a device. In the script I am writing the user may choose to map multiple shares so I need to be able to map to the next available device: net use * \\some_server\share_name instead of: net use k: \\server\share Thanks for the help in advance. Also, if anyone could provide a link to good windows api docs for python that would be great. Cheers, --Lucas Machado -- http://mail.python.org/mailman/listinfo/python-list