Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old October 6th, 2008, 06:07 AM
Newbie
 
Join Date: Oct 2008
Posts: 6
Default getting the last index of an array

Hi folks
i am totally novice to python, that's why i have to learn it for my final year project.

Any way i have been using a python module for extracting exif data from pictures taken by digital camera. one of the data is extracting the file name of the picture but the file name is stored on an array so, once i call the extraction the whole file name directory will be printed on the terminal which is /home/waseem/my pictures/1.jpg. home can i be able to print only the FILE NAME of the photo which is 1.jpg.

Thanks in advance

here's the code

Expand|Select|Wrap|Line Numbers
  1. l=filename.split("")
  2.     print 'Name',
Reply
  #2  
Old October 6th, 2008, 02:15 PM
bvdet's Avatar
Expert
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,221
Default

Expand|Select|Wrap|Line Numbers
  1. >>> import os
  2. >>> os.path.basename(r'D:\Miscellaneous\FEMA-350.pdf')
  3. 'FEMA-350.pdf'
  4. >>> 
Reply
  #3  
Old October 6th, 2008, 05:10 PM
Newbie
 
Join Date: Oct 2008
Posts: 6
Default

thanks bvdet for you replay

your example gave me an idea but there you specified the path of the file and the file name but how can i get that without any user input which means the function will know that i am now in this directory and this is file name so, it will extract the file name from the directory and print it out because if i change my module to other directory i have to change in the code you gave me. i hope you got the idea and sorry for the hassle.


thanks in advance.
Reply
  #4  
Old October 6th, 2008, 05:55 PM
bvdet's Avatar
Expert
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,221
Default

I don't understand the question. This will print all the file and directory names in the current working directory:
Expand|Select|Wrap|Line Numbers
  1. >> for fn in os.listdir(os.getcwd()):
  2. ...     print fn
  3. ...     
Reply
  #5  
Old October 7th, 2008, 09:22 AM
Newbie
 
Join Date: Oct 2008
Posts: 6
Default

hey man,

your code above printed the files in my working directory which i don't need.

my module works like this
waseem@Linux:~/Study Related/project1/python modules/EXIFpy_1.0.7$
this is my directory
waseem@Linux:~/Study Related/project1/python modules/EXIFpy_1.0.7$python myexif.py -q '/home/waseem/My Pictures/Malaysia 28sep 2008/100MEDIA/IMAG0044.jpg' what i need is how to get the picture name which is IMAG0044.jpg from '/home/waseem/My Pictures/Malaysia 28sep 2008/100MEDIA/'. this is the directory of my pictures. your first example did the job for a specific picture but i got thousands of pictures i need to extract their names, i can't do that with your first code because it only applicable for one picture.
i hope you get my point....
i think my English ain't helping me much here.
thank you
Reply
  #6  
Old October 7th, 2008, 01:53 PM
bvdet's Avatar
Expert
 
Join Date: Oct 2006
Location: Nashville, TN
Posts: 1,221
Default

Quote:
Originally Posted by klia
hey man,

your code above printed the files in my working directory which i don't need.

my module works like this
waseem@Linux:~/Study Related/project1/python modules/EXIFpy_1.0.7$
this is my directory
waseem@Linux:~/Study Related/project1/python modules/EXIFpy_1.0.7$python myexif.py -q '/home/waseem/My Pictures/Malaysia 28sep 2008/100MEDIA/IMAG0044.jpg' what i need is how to get the picture name which is IMAG0044.jpg from '/home/waseem/My Pictures/Malaysia 28sep 2008/100MEDIA/'. this is the directory of my pictures. your first example did the job for a specific picture but i got thousands of pictures i need to extract their names, i can't do that with your first code because it only applicable for one picture.
i hope you get my point....
i think my English ain't helping me much here.
thank you
This will list all the file and subdirectory names in your directory:
Expand|Select|Wrap|Line Numbers
  1. import os
  2. for fn in os.listdir('/home/waseem/My Pictures/Malaysia 28sep 2008/100MEDIA'):
  3.     print fn
Reply
  #7  
Old October 8th, 2008, 04:15 AM
Newbie
 
Join Date: Oct 2008
Posts: 6
Default

unfourtently, still not the fulfillment i might be extracting many photos at the time and i also might be extracting only and only one photo at the time so,i need the function that will cop with that which will only print the name of the photo that i specify after calling the module python myexif -q '/home/waseem/......./filename.jg without any concern of hom many the photos are(one, two, three, ....)in the terminal, besides if i changed to another photos directory, the above directory in the code need to be changed which i can't do every time i wanna extract the names, date and camera model from photos....in the module aim using, my file name is held up an an array once i call print filename the whole file name directory will be printed out which i don't need if i want to store all that string into a database but i need only to cut out the file name of the directory. my module already know the directory of the file and the file name.


thank you
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles