473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

getting the last index of an array

14
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',
Oct 6 '08 #1
6 2251
bvdet
2,851 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. >>> import os
  2. >>> os.path.basename(r'D:\Miscellaneous\FEMA-350.pdf')
  3. 'FEMA-350.pdf'
  4. >>> 
Oct 6 '08 #2
klia
14
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.
Oct 6 '08 #3
bvdet
2,851 Expert Mod 2GB
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. ...     
Oct 6 '08 #4
klia
14
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
Oct 7 '08 #5
bvdet
2,851 Expert Mod 2GB
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
Oct 7 '08 #6
klia
14
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
Oct 8 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Vani Murarka | last post by:
Hi Everyone, Does .NET offer any collection class which will give me objects last *accessed* such that I may build a least-recently-used cache that kills off objects that haven't been used for...
6
by: pg | last post by:
Is there any simple way to query the most recent time of "changes" made to a table? I'm accessing my database with ODBC to a remote site thru internet. I want to eliminate some DUPLICATE long...
3
by: John Yatla | last post by:
Here is how I've done it. intMAX = Math.Max(Math.Max(Math.Max(dr("NAQty"), dr("CurrentNotRequiredYetQty")), Math.Max(dr("OutstandingQty"), dr("SavedQty"))), Math.Max(dr("UnapprovedQty"),...
4
by: Tad Marshall | last post by:
Hi, I'm reading about arrays in VB.NET and I seem to have a few options for my data structure. I need a multi-dimensional array of structures, and my first thought was Public Structure myStr...
12
by: Jared Carr | last post by:
First I wish I knew how this was caused but here is our problem. Sometime in the recent past we got a duplicate table. Here is the result of a pg_dump with a pg_restore for just that table. ...
5
by: JonH | last post by:
Ok, I have this dynamically created table in my one of my php forms that shows the names of the people the user has entered into a text field. When they hit add a row displays, showing the name...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
7
by: Aaron Gray | last post by:
I put together the following code to get the href's parameters :- function GetParameters() { var arg = new Object(); var href = document.location.href; if ( href.indexOf( "?") != -1) { var...
8
by: sherifffruitfly | last post by:
Hi, I've been searching as best I can for this - coming up with little. I have a file that is full of lines fitting this pattern: (?<year>\d{4}),(?<amount>\d{6,7}) I'm likely to get a...
6
by: sgottenyc | last post by:
Hello, If you could assist me with the following situation, I would be very grateful. I have a table of data retrieved from database displayed on screen. To each row of data, I have added...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.