Thursday 15 January 2015

Python for items list, to indivdual string? -


Just wondering if someone can tell me what I'm doing wrong. Working with a little code with experimentation with my cherry project

  import glob import os def get_html (apath): print (apt) fhtml = open (apt, 'r') data = FHATL data return data article_path = OSGCWD () + '/ articles / *. Html 'myArticles = [glob.glob (article_path)] for MyArticles: get_html (items)   

Results for:

  ['/ Home / sd / documents / projects / cherryweb / articles / module 5-exploitation techniques and exercises.pdf.html'] traceback (most recent call final): file "fntest.py", line 22, & lt; Module & gt; The string or buffer is required to get   

, I accept it because the file name I am passing ['and'] from the list on the string, I can trim these parts I can write a function, but this is the only option, or I'm stupid.

Thanks

  myArticles = [glob.glob (article_path)]   

should be:

  myArticles = glob.glob (article_path)   

glob.glob < Returns a list by adding / code> [] , so that you make it a list of lists.

Then, in this loop:

  items in my articles: get_html (item)   

The error has been raised to get_html and .

Demo:

  & gt; & Gt; & Gt; Open ([]) traceback (most recent call final): File "& lt; ipython-input-242-013dc85bc958"; Line 1, & lt; Module & gt; Open ([]) Type error: Unicode effect: String or buffer is required, list found    

No comments:

Post a Comment