Re: Behaviour of os.path.join

2020-05-27 Thread Beverly Pope
I wasn’t going to say anything because I haven’t used MS Windows for years.  
The OP wants to add a path separator at the end of a path.  Why the OP wants to 
do that doesn’t concern me.

OTOH, as others have already mentioned, the documentation explicitly says, "If 
a component is an absolute path, all previous components are thrown away and 
joining continues from the absolute path component.”  While I may not 
understand WHY anyone would want that to occur, this was the way it was 
designed; it is not a bug.

The documentation also says, “The return value is the concatenation of path and 
any members of *paths with exactly one directory separator (os.sep) following 
each non-empty part except the last, meaning that the result will only end in a 
separator if the last part is empty.”  So, the module does allow one to add a 
path separator at the end of the path by simply adding an empty string as the 
last part of the path.  The following is on macOS (I don’t have a MS Windows 
machine):

>>> import os.path
>>> os.path.join('/Users/myID/a', 'b','c')
'/Users/myID/a/b/c'
>>> os.path.join('/Users/myID/a', 'b','c', '')
'/Users/myID/a/b/c/‘

So, it does work as advertised on Python 3.8 and all the OP should need to do 
is add that empty string to get the OP’s desired result.

Bev in TX




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to copy paragraphs (with number formatting) and images from Words (.docx) and paste into Excel (.xlsx) using Python

2020-03-23 Thread Beverly Pope
On Mar 22, 2020, at 11:12 PM, A S  wrote:
> 
> On Monday, 23 March 2020 01:58:38 UTC+8, Beverly Pope  wrote:
>>> On Mar 22, 2020, at 9:47 AM, A S >> <mailto:aishan0...@gmail.com>> wrote:
>>> 
>>> I can't seem to paste pictures into this discussion so please see both my 
>>> current and desired Excel output here:
>>> 
>>> https://stackoverflow.com/questions/60800494/how-to-copy-paragraphs-with-number-formatting-and-images-from-words-docx-an
>>>  
>>> <https://stackoverflow.com/questions/60800494/how-to-copy-paragraphs-with-number-formatting-and-images-from-words-docx-an><https://stackoverflow.com/questions/60800494/how-to-copy-paragraphs-with-number-formatting-and-images-from-words-docx-an
>>>  
>>> <https://stackoverflow.com/questions/60800494/how-to-copy-paragraphs-with-number-formatting-and-images-from-words-docx-an>>
>> Did you try using the 2 part answer on the stackoverflow webpage?
>> 
>> Bev in TX
> 
> I'm able to get the paragraphs copied correctly now! But i'm trying to figure 
> out if there's a way to copy and paste the images into the Excel, along with 
> the paragraphs as well. Do you have an idea? :)

I’m glad to hear that solution worked for you.  With that said, I only went to 
stackoverflow out of curiosity and happened ro see the posted solution. I 
probably know less about using Python to copy data from Word to Excel than you 
do, given that yesterday was the first time that I had heard about it.  

I did read that MS docx files are zip files, which can be unzipped in Python.
https://gist.github.com/another-junior-dev/990a4e622868627cb93be3d8fa2eff04 
<https://gist.github.com/another-junior-dev/990a4e622868627cb93be3d8fa2eff04>
That could provide access to the pictures contained in the document, but it 
doesn’t explain how to determine where you want to place the pictures with 
relation to text in your Excel spreadsheet.  If you could determine that, then 
you could use XlsxWriter module’s worksheet.insert_image() to insert the image. 
 See n”the Worksheet Class” in the XlsxWriter docs:
https://xlsxwriter.readthedocs.io <https://xlsxwriter.readthedocs.io/>
The rest is beyond the realm of my knowledge.

If it were me, I would go back to stackoveflow and open a new question, as this 
is different than your original post.

Bev in TX
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to copy paragraphs (with number formatting) and images from Words (.docx) and paste into Excel (.xlsx) using Python

2020-03-22 Thread Beverly Pope



> On Mar 22, 2020, at 9:47 AM, A S  wrote:
> 
> I can't seem to paste pictures into this discussion so please see both my 
> current and desired Excel output here:
> 
> https://stackoverflow.com/questions/60800494/how-to-copy-paragraphs-with-number-formatting-and-images-from-words-docx-an
>  
> 
Did you try using the 2 part answer on the stackoverflow webpage?

Bev in TX
-- 
https://mail.python.org/mailman/listinfo/python-list