Open a file with Python with given name in a folder that change name -


I am using Python 2.7.8

I want to open a file named 'data.html' In a folder / file structure like this,

  'C: \ SVN \ DIR1 \ DIR2 \ DIR3 \ {54F35-586-4AC-895B-52B5CB5} \ data.html'  / Code>  

My problem is that the folder:

  \ {54F35-586-4AC-895B-52B5CB5}  

Changing the name of the rest of the file / folder structure between the execution of my Python script is stable.

My Pyro script for the moment looks like this:

  linkToHtmlReport = 'C: \ SVN \ DIR1 \ DIR2 \ DIR3 \ 54F35-586-4AC-895B -52B5CB5} \ data.html 'soup = beautiful (open (linkToHtmlReport))  

My question is how to open the file, when the data.html folder "{54F35-586-4AC- 895B-52B5CB5} "Changing name between running script? Can I use OS Walkle for this?

Thank you for helping!

i Glob to glob!

  Import glob path = glob.glob ("C: \ SVN \ DIR1 \ DIR2 \ DIR3 \ * \ data.html") [0]  

I always used it with Linux ... but should work on windows too. You will return a list of matching paths for that query. You can reach position 0 if you are sure that there is only one of them.

Anyway it is better if you check that the list is empty as empty:

  import path path = glob.glob ("C: \ SVN \ DIR1" \ DIR2 \ DIR3 \ * \ data.html ") If path list: path = path list [0]  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -