jborean93 / smbprotocol

Python SMBv2 and v3 Client
MIT License
318 stars 73 forks source link

Include path in __init__.py #157

Closed swedchef closed 2 years ago

swedchef commented 2 years ago

TBH I am early in the programmer learning curve, so I might have completely missed the most obvious thing, but here goes..

When I want to use the .path submodule, I have to import it explicitly (i.e. from smbclient import path as smbclient_path) - instead of just importing the main module and accessing it though dot-notation as path is not included in the __init__.py file.

Perhaps it would be an improvement to add from smbclient import path as a line in the __init__.py file?

jborean93 commented 2 years ago

It makes sense, it's mostly meant to mirror os and os.path as it contains similar functions. In the past I believe you would have had to import os.path to access those functions but since Python 3 that is no longer the case. Being able to do both import smbclient; smbclient.path.func or import smbclient.path; smbclient.path.func makes sense to me.

swedchef commented 2 years ago

Just to indicate what difference it might make, my specific usecase is to use an alias and then import from either OS or from smbclient, now that you went to all that effort (thanks for that!) to make the path module similar. ie:

if localpath:
  from os import path as path_in
else:
  from smbclient import path as path_in

Then I can just use path_in, and not continuously compare or write separate code depending on local or remote path.

jborean93 commented 2 years ago

Sorry for the delay https://github.com/jborean93/smbprotocol/pull/163 implements this change, it allows you to do the following

import smbclient

smbclient.path.isfile(r"\\server\share\path")

This will be included in the upcoming release.