Re: [Tutor] Sum files' size

2011-07-29 Thread Susana Iraiis Delgado Rodriguez
Thank you to all of you!

After I read your mails I started to modify my code, I applied Ramit
suggestion and got the result I wanted:

mport os
file_list = []
folders = None
for root, folders, files in os.walk('C:\\'):
file_list.extend(os.path.join(
root,fi) for fi in files if (fi.endswith.shp))
for row, filepath in enumerate(file_list, start=1):
n = os.path.splitext(filepath)
p = n[0]+'.prj'
shx = n[0]+'.shx'


#Function to get size in humam readable terms:
def sizeof_fmt(num):
 for x in ['bytes','KB','MB','GB','TB']:
  if num < 1024.0:
   return "%3.1f%s" % (num, x)
  num /= 1024.0
s = os.path.getsize(filepath)
shx1 = os.path.getsize(shx)
p1 = s = os.path.getsize(p)
total = sizeof_fmt(s+shx1+p1)



2011/7/28 Prasad, Ramit 

> >kb = sizeof_fmt(s)
> >shx1 = os.path.getsize(shx)
> >kb2 = sizeof_fmt(shx1)
> > total = kb+kb2+kb3
>
> Instead only retrieve the formatted output at the end. That way you will
> not have to worry about converting back from strings, nor have to worry
> about adding number with different units (e.g. 10KB + 10MB).
>
> kb = s
> kb2 = os.path.getsize(shx)
> total = sizeof_fmt(kb+kb2+kb3)
>
> Ramit
>
>
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
>
>
>
> This communication is for informational purposes only. It is not
> intended as an offer or solicitation for the purchase or sale of
> any financial instrument or as an official confirmation of any
> transaction. All market prices, data and other information are not
> warranted as to completeness or accuracy and are subject to change
> without notice. Any comments or statements made herein do not
> necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
> and affiliates.
>
> This transmission may contain information that is privileged,
> confidential, legally privileged, and/or exempt from disclosure
> under applicable law. If you are not the intended recipient, you
> are hereby notified that any disclosure, copying, distribution, or
> use of the information contained herein (including any reliance
> thereon) is STRICTLY PROHIBITED. Although this transmission and any
> attachments are believed to be free of any virus or other defect
> that might affect any computer system into which it is received and
> opened, it is the responsibility of the recipient to ensure that it
> is virus free and no responsibility is accepted by JPMorgan Chase &
> Co., its subsidiaries and affiliates, as applicable, for any loss
> or damage arising in any way from its use. If you received this
> transmission in error, please immediately contact the sender and
> destroy the material in its entirety, whether in electronic or hard
> copy format. Thank you.
>
> Please refer to http://www.jpmorgan.com/pages/disclosures for
> disclosures relating to European legal entities.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sum files' size

2011-07-28 Thread Steven D'Aprano

Susana Iraiis Delgado Rodriguez wrote:

I want to get the size of  3 files. I already completed this step. Then I
need to sum the 3 results I got. In order to do it I have the next code:

[...]

#Finally I want to sum the 3 terms:
total = kb+kb2+kb3
But the output I got is : 15.5KB108.0bytes169.0bytes

Does anyone have an idea how to fix it?



Sum the three terms while they are still numbers, before you convert 
them into strings with units.





--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sum files' size

2011-07-28 Thread Prasad, Ramit
>kb = sizeof_fmt(s)
>shx1 = os.path.getsize(shx)
>kb2 = sizeof_fmt(shx1)
> total = kb+kb2+kb3

Instead only retrieve the formatted output at the end. That way you will not 
have to worry about converting back from strings, nor have to worry about 
adding number with different units (e.g. 10KB + 10MB).

kb = s
kb2 = os.path.getsize(shx)
total = sizeof_fmt(kb+kb2+kb3)

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase &
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to European legal entities.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Sum files' size

2011-07-28 Thread Alan Gauld

Susana Iraiis Delgado Rodriguez wrote:

I want to get the size of  3 files. I already completed this step. Then I
need to sum the 3 results I got. In order to do it I have the next code:

import os
file_list = []
folders = None
for root, folders, files in os.walk('C:\\'):
file_list.extend(os.path.join(root,fi) for fi in files if
(fi.endswith.shp))
for row, filepath in enumerate(file_list, start=1):
n = os.path.splitext(filepath)
p = n[0]+'.prj'
shx = n[0]+'.shx'
s = os.path.getsize(filepath)

#Function to get size in humam readable terms:
def sizeof_fmt(num):
 for x in ['bytes','KB','MB','GB','TB']:
  if num < 1024.0:
   return "%3.1f%s" % (num, x)


This returns a string value


  num /= 1024.0

kb = sizeof_fmt(s)


So kb1 will be astring


shx1 = os.path.getsize(shx)
kb2 = sizeof_fmt(shx1)


And so will kb2


#Finally I want to sum the 3 terms:
total = kb+kb2+kb3


Where does kb3 come from?


But the output I got is : 15.5KB108.0bytes169.0bytes

Does anyone have an idea how to fix it?
Thank you!!


Looks like you are adding the strings. You need to get the
sum then call your format function on the total.

HTH,

Alan G.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Sum files' size

2011-07-28 Thread Susana Iraiis Delgado Rodriguez
I want to get the size of  3 files. I already completed this step. Then I
need to sum the 3 results I got. In order to do it I have the next code:

import os
file_list = []
folders = None
for root, folders, files in os.walk('C:\\'):
file_list.extend(os.path.join(root,fi) for fi in files if
(fi.endswith.shp))
for row, filepath in enumerate(file_list, start=1):
n = os.path.splitext(filepath)
p = n[0]+'.prj'
shx = n[0]+'.shx'
s = os.path.getsize(filepath)

#Function to get size in humam readable terms:
def sizeof_fmt(num):
 for x in ['bytes','KB','MB','GB','TB']:
  if num < 1024.0:
   return "%3.1f%s" % (num, x)
  num /= 1024.0

kb = sizeof_fmt(s)
shx1 = os.path.getsize(shx)
kb2 = sizeof_fmt(shx1)

#Finally I want to sum the 3 terms:
total = kb+kb2+kb3
But the output I got is : 15.5KB108.0bytes169.0bytes

Does anyone have an idea how to fix it?
Thank you!!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor