[Tutor] unzip and connect to Oracle database
Alan Gauld
alan.gauld at yahoo.co.uk
Fri Dec 7 13:12:01 EST 2018
On 07/12/2018 14:00, Asad wrote:
> Hi All ,
>
> I would like to unzip a file using python and then execute the sql
> scripts in the file on Oracle database .
Are you absolutely sure?
That's a very dangerous thing to do from a
security point of view. Potentially similar
to using exec() on user input...
You will need to ensure that the files inside
the zip file are very secure and from trusted
sources.
> >>> from zipfile import ZipFile
>>>> file_name = 'file.zip'
>>>> z = ZipFile(file_name)
>>>> print(z.namelist())
> []
What did you expect to see? What does zip file contain?
Recall that zip files are not simply compressed files
they are also archives of files.
>>>> z.extractall()
> Doesnot unzip the zip file
Are you sure you are looking in the right folder?
Can you use os.listdir() to print the file list
and verify that file.zip is where you expect and
after extracting that the extracted files don't exist?
Also recall that zip files may have absolute paths
so the extracted files may be in some completely
different location.
> Also share some code or documentation to connect to Oracle DB and execute
> sql scripts.
Lets deal with that separately.
There are several tutorials on YouTube and
assorted web pages showing how to do that.
If you don't understand them come back with
specific questions. Lets focus on ZipFile for now!
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list