I'm fairly new to Python but had to start using it and for reasons I have to use 2.7, which is why I am using that syntax. I have this function which gets data from a file, if it exists, and then gets passed onto other functions to perform SQL queries etc. The script is only intended to work for the directory it is running in, hence the os.getcwd()
This static data is the only data that gets looked up then returned and referenced by other functions. It works as it is but would you say for professionalism and understanding python better that a class would be better here or a restructure in someway? I am of course only posting a snippet.
currentdirectory = os.getcwd() versionf = "version.ini" verfile = os.path.join(currentdirectory, versionf) def main(): get_local_details() push_app(application, version) do_something(app_name_version) def get_local_details(): if os.path.isfile(verfile): def get_app_name(): try: global application application = subprocess.check_output(['grep', 'application', verfile]).strip('\n') application = application.rsplit('=') return application except: print "Application missing from version.ini" def version_number(): try: global version version = subprocess.check_output(['grep', 'version', verfile]).strip('\n') version = version.rsplit('=') return version except: print "version missing from version.ini" get_app_name() version_number() def app_name_version(application, version) try: global applicationver applicationver = application + "." + version return applicationver except: print "error here" app_name_version(application, version) else: print "File does not exist." main()
contents of ini file are
do_something is a function that contains a SQL query that uses the app_name_version as the WHERE statement.
Is it even possible to use a function within a class to define the attributes?