Invoice

2022-05-19 Thread Poppy Thomas
[image: Invoice.jpg]
..
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: strip module bug

2008-10-13 Thread Poppy
Thanks Steven and Tim, I understand the strip module a lot more today. Also 
for some reason I was deciding against using the path functions but now 
decided to try and thus implemented them. My script is reading one file and 
writing a new file with a different extension.

So based on your suggestions I wrote this line.

import sys, os
xmlfile = sys.argv[1]
filout = os.path.splitext(xmlfile)[0] + ".xmlparse"  ### here is the new 
line


"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Mon, 13 Oct 2008 08:50:41 -0400, Poppy wrote:
>
>> I'm using versions 2.5.2 and 2.5.1 of python and have encountered a
>> potential bug. Not sure if I'm misunderstanding the usage of the strip
>> function but here's my example.
>>
>> var = "detail.xml"
>> print var.strip(".xml")   ### expect to see 'detail', but get 'detai'
>> var = "overview.xml"
>> print var.strip(".xml") ### expect and get 'overview'
>
>
> I got bitten by this once too. Most embarrassingly, I already knew the
> right behaviour but when somebody suggested it was a bug I got confused
> and convinced myself it was a bug. It's not.
>
> You have misunderstood what strip() does. It does NOT mean "remove this
> string from the string if it is a suffix or prefix".
>
> Consider:
>
>>>> "abcd123".strip('123')
> 'abc'
>>>> "abcd123".strip('321')
> 'abc'
>>>> "abcd123111".strip('213')
> 'abc'
>
> strip() removes *characters*, not substrings. It doesn't matter what
> order it sees them.
>
> See help(''.strip) in the interactive interpreter for more detail.
>
>
> By the way, the right way to deal with file extensions is:
>
>>>> import os
>>>> os.path.splitext('detail.xml')
> ('detail', '.xml')
>
>
>
>
> -- 
> Steven 


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


strip module bug

2008-10-13 Thread Poppy

I'm using versions 2.5.2 and 2.5.1 of python and have encountered a 
potential bug. Not sure if I'm misunderstanding the usage of the strip 
function but here's my example.

var = "detail.xml"
print var.strip(".xml")   ### expect to see 'detail', but get 'detai'
var = "overview.xml"
print var.strip(".xml") ### expect and get 'overview'

I have a work around using the replace function which happens to be the 
better choice for my script anyhow. But am curious about the strip module. 
Any thoughts? Is it removing the 'l' in detail because the strip function 
text ends in 'l'?


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


Re: convert string containing list to list (or tuple) type

2008-05-30 Thread Poppy
Arrgh. One of those days where I find an answer just after posting. I spend 
hours on the code below only to find I don't know how to use split to it's 
fullest.

>>> b.strip(",").split(",")
['I', 'G', 'AQ', 'ET', 'K', 'BF']

"Poppy" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> I'm reading from a database a column that has a list of codes (comma 
> seperated). When I read in the list I have a single value, see code sample 
> below values for a, b, and c. These represent possible values in my 
> database. I need to loop through each value so I can expand my data from 
> this compressed view.
>
> My code below works and creates my desired output but I believe there must 
> be a better way this is very messy. My messy function that I'd like to 
> replace is lst_codes(codes). Any alternative suggestions?
>
> this is what I begin with
> a = ',P,'
> b = ',I,G,AQ,ET,K,BF,'
> c = ',DZ,'
> this is what I want (lists or tuples are fine)
> ['P']
> ['I', 'G', 'AQ', 'ET', 'K', 'BF']
> ['DZ']
>
>
> def lst_codes(codes):
>""" turn a string of comma seperated codes into a real list object """
>i = 0
>lstD = []
>while i < len(codes):
>a = codes[i]
>b = ","
>if (i + 1) < len(codes):
>b = codes[i + 1]
>i = i + 1
>else:
>b = ","
>
>if b <> ",":
>lstD.append(a + b)
>i = i + 2
>else:
>lstD.append(a)
>i = i + 1
>return lstD
>
>
> a = ',P,'
> b = ',I,G,AQ,ET,K,BF,'
> c = ',DZ,'
>
> for ea in (a,b,c):
>print lst_codes(ea.strip(","))
>
> 


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


convert string containing list to list (or tuple) type

2008-05-30 Thread Poppy
I'm reading from a database a column that has a list of codes (comma 
seperated). When I read in the list I have a single value, see code sample 
below values for a, b, and c. These represent possible values in my 
database. I need to loop through each value so I can expand my data from 
this compressed view.

My code below works and creates my desired output but I believe there must 
be a better way this is very messy. My messy function that I'd like to 
replace is lst_codes(codes). Any alternative suggestions?

this is what I begin with
a = ',P,'
b = ',I,G,AQ,ET,K,BF,'
c = ',DZ,'
this is what I want (lists or tuples are fine)
['P']
['I', 'G', 'AQ', 'ET', 'K', 'BF']
['DZ']


def lst_codes(codes):
""" turn a string of comma seperated codes into a real list object """
i = 0
lstD = []
while i < len(codes):
a = codes[i]
b = ","
if (i + 1) < len(codes):
b = codes[i + 1]
i = i + 1
else:
b = ","

if b <> ",":
lstD.append(a + b)
i = i + 2
else:
lstD.append(a)
i = i + 1
return lstD


a = ',P,'
b = ',I,G,AQ,ET,K,BF,'
c = ',DZ,'

for ea in (a,b,c):
print lst_codes(ea.strip(","))


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


Re: addendum Re: working with images (PIL ?)

2008-05-20 Thread Poppy
Thank you and the other responders have given me something to consider, I 
understand the concept of the posterize idea and will be experimenting with 
that.

I wanted to respond to this statement below which is true, however I believe 
the histogram sums the values so both colors would be in bin 229.  I say 
that because all white is in histogram element 767, while black is in 
element 0. Anyone on this list know how to interpret the histogram list? 
Your point is still valid regardless of my interpretation.

> So, for example, colours (2, 27, 200) and (200, 27, 2) are both in
> the bin for G=27. But they are very different colours.

I will be checking out the SIG for PIL thanks for that pointer.



"Ken Starks" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>I would still be concerned that you are checking against the percentage
> of the 768 bins returned by the histogram method. Two pixels of
> widely different colour end up in the same bin, so long as just ONE
> of the Red, Green, or Blue components is equal.
>
> So, for example, colours (2, 27, 200) and (200, 27, 2) are both in
> the bin for G=27. But they are very different colours.
>
> There are actualy 256 * 256 * 256 colours, but I don't suppose
> you want that many bins!
>
> What you want is a much smaller number of bins, with pixels
> of 'close' colours (whatever that means) put into the same bin.
>
> What 'close' means for colours, is quite a difficult thing, and
> the consensus is that using the three RGB coordinates is not
> as good as certain other colour spaces.
>
> You could use the ImageOps.posterize method to reduce the number of 
> colours in the image, but whether 'close' colours end up together,
> I don't know.
>
> You might try the PIL special interest group (SIG) 'image-sig'
>
> http://mail.python.org/mailman/listinfo/image-sig
>
> (If you want to know exactly how many unique colours an image actually
> has, load the image into the 'GIMP' assuming you have it,
> and go to :
>
> Menubar --> Filters --> Colours --> Colourcube analysis...
>
> )
>
>
>
>
>
>
>
>
>
>
> Poppy wrote:
>> Thanks, since posting I  figured out how to interpret the histogram 
>> results, which seems to be the consensus in responses. I wrote a check 
>> image program and have been periodically calling it against a folder 
>> where I make a copy of our images used for production. My method right 
>> now is to check what we send for errors, but is not preventive.
>>
>> Also I determined whitespace is not the only issue, any color that 
>> dominates. I'm considering rewriting this code below to setup bins, so if 
>> combined neighboring colors exceeds the threshold then reject the image. 
>> I have examples where half the image appears black, but actually varies 
>> throughout.
>>
>> Since my image is RGB I'm looping through a 768 element list.
>>
>> Zach-
>>
>> import Image, os
>>
>>
>> def check_image(file):
>>
>> try:
>> im = Image.open(file)
>> except:
>> return "Can't open file %s " % file
>>
>> imData = im.histogram()
>> i = 0
>> for ea in imData:
>> if ea > ((im.size[0] * im.size[1]) / 4): ## 25% of image size
>> return "bad image %s - %s element num is %s " % (file, ea, 
>> str(i))
>> i = i + 1
>>
>> return "good image %s, image size is %s" % (file, im.size)
>>
>>
>> def main(dir):
>> data = ""
>> try:
>> files = os.listdir(dir)
>> for ea in files:
>> data = data + str(check_image(os.path.join(dir,ea))) + "\n"
>> except:
>> return "Can't get files in %s" % dir
>> return data
>>
>> print main("host\\path\\to\\image_folder\\")
>> 

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


Re: addendum Re: working with images (PIL ?)

2008-05-19 Thread Poppy
Thanks, since posting I  figured out how to interpret the histogram results, 
which seems to be the consensus in responses. I wrote a check image program 
and have been periodically calling it against a folder where I make a copy 
of our images used for production. My method right now is to check what we 
send for errors, but is not preventive.

Also I determined whitespace is not the only issue, any color that 
dominates. I'm considering rewriting this code below to setup bins, so if 
combined neighboring colors exceeds the threshold then reject the image. I 
have examples where half the image appears black, but actually varies 
throughout.

Since my image is RGB I'm looping through a 768 element list.

Zach-

import Image, os


def check_image(file):

try:
im = Image.open(file)
except:
return "Can't open file %s " % file

imData = im.histogram()
i = 0
for ea in imData:
if ea > ((im.size[0] * im.size[1]) / 4): ## 25% of image size
return "bad image %s - %s element num is %s " % (file, ea, 
str(i))
i = i + 1

return "good image %s, image size is %s" % (file, im.size)


def main(dir):
data = ""
try:
files = os.listdir(dir)
for ea in files:
data = data + str(check_image(os.path.join(dir,ea))) + "\n"
except:
return "Can't get files in %s" % dir
return data

print main("host\\path\\to\\image_folder\\")


"Ken Starks" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> As others have said, PIL has the 'histogram' method to do most of the 
> work. However, as histogram works on each band separately, you have
> a bit of preliminary programming first to combine them.
>
> The ImageChops darker method is one easy-to-understand way (done twice),
> but there are lots of alternatives, I am sure.
>
>
> # 
>
> import Image
> import ImageChops
>
> Im = Image.open("server\\vol\\temp\\image.jpg")
> R,G,B = Im.split()
>
> Result=ImageChops.darker(R,G)
> Result=ImageChops.darker(Result,B)
>
> WhiteArea=Result.histogram()[0]
> TotalArea=Im.size[0] * Im.size[1]
> PercentageWhite = (WhiteArea * 100.0)/TotalArea
>
>
>
>
>
> Poppy wrote:
>> I've put together some code to demonstrate what my goal is though looping 
>> pixel by pixel it's rather slow.
>>
>> import Image
>>
>> def check_whitespace():
>> im = Image.open("server\\vol\\temp\\image.jpg")
>>
>> size = im.size
>>
>> i = 0
>> whitePixCount = 0
>> while i in range(size[1]):
>> j = 0
>> while j in range(size[0]):
>> p1 = im.getpixel((j,i))
>> if p1 == (255, 255, 255):
>>     whitePixCount = whitePixCount + 1
>> if whitePixCount >= 492804:  ## ((image dimensions 1404 x 
>> 1404) / 4) 25%
>> return "image no good"
>> j = j + 1
>> i = i + 1
>>
>> print whitePixCount
>>
>> return "image is good"
>>
>> print check_whitespace()
>>
>>
>> "Poppy" <[EMAIL PROTECTED]> wrote in message news:...
>>> I need to write a program to examine images (JPG) and determine how much 
>>> area is whitespace. We need to throw a returned image out if too much of 
>>> it is whitespace from the dataset we're working with. I've been 
>>> examining the Python Image Library and can not determine if it offers 
>>> the needed functionality. Does anyone have suggestions of other image 
>>> libraries I should be looking at it, or if PIL can do what I need?
>>>
>> 

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


addendum Re: working with images (PIL ?)

2008-05-16 Thread Poppy
I've put together some code to demonstrate what my goal is though looping 
pixel by pixel it's rather slow.

import Image

def check_whitespace():
im = Image.open("server\\vol\\temp\\image.jpg")

size = im.size

i = 0
whitePixCount = 0
while i in range(size[1]):
j = 0
while j in range(size[0]):
p1 = im.getpixel((j,i))
if p1 == (255, 255, 255):
whitePixCount = whitePixCount + 1
if whitePixCount >= 492804:  ## ((image dimensions 1404 x 
1404) / 4) 25%
return "image no good"
j = j + 1
i = i + 1

print whitePixCount

return "image is good"

print check_whitespace()


"Poppy" <[EMAIL PROTECTED]> wrote in message news:...
>I need to write a program to examine images (JPG) and determine how much 
>area is whitespace. We need to throw a returned image out if too much of it 
>is whitespace from the dataset we're working with. I've been examining the 
>Python Image Library and can not determine if it offers the needed 
>functionality. Does anyone have suggestions of other image libraries I 
>should be looking at it, or if PIL can do what I need?
> 


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


working with images (PIL ?)

2008-05-16 Thread Poppy
I need to write a program to examine images (JPG) and determine how much 
area is whitespace. We need to throw a returned image out if too much of it 
is whitespace from the dataset we're working with. I've been examining the 
Python Image Library and can not determine if it offers the needed 
functionality. Does anyone have suggestions of other image libraries I 
should be looking at it, or if PIL can do what I need? 


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


Re: cx_Oracle execute procedure

2008-03-19 Thread Poppy
Thanks Jerry and Diez. The first two replies I found answered my noob 
question.


"Jerry Hill" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Wed, Mar 19, 2008 at 11:03 AM, Poppy <[EMAIL PROTECTED]> 
> wrote:
>> I've been working on the code below and and executes silently, no
>>  complaints, however the end result should be a record in my table and 
>> it's
>>  not added. The procedure works with the passed credentials using SQLPlus 
>> or
>>  SQL Developer clients. However I'm not sure if I'm constructing my 
>> python
>>  code correctly to interact with Oracle.
> ...
>>  connection.commit
>>  cur.close
>>  connection.close
>
> You have to actually call these methods:
> connection.commit()
> cur.close()
> connection.close()
>
> Without the parentheses, you're just getting a reference to the
> methods and immediately discarding them.
>
> -- 
> Jerry 


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


cx_Oracle execute procedure

2008-03-19 Thread Poppy
I've been working on the code below and and executes silently, no 
complaints, however the end result should be a record in my table and it's 
not added. The procedure works with the passed credentials using SQLPlus or 
SQL Developer clients. However I'm not sure if I'm constructing my python 
code correctly to interact with Oracle.

I've been basing the code below on what I found in this thread 
http://www.thescripts.com/forum/thread33728.html .

Zach-

import cx_Oracle

connection = cx_Oracle.connect("user/[EMAIL PROTECTED]")

## PROCEDURE rptmgr.rep_utils.CLONE_REPORT( p_ordernum varchar2,p_repnum 
varchar2, p_prefix number)

cur = connection.cursor()

repParams = {}
repParams['arg1'] = "555"
repParams['arg2'] = "2"
repParams['arg3'] = "999"

sqlStr = """BEGIN rptmgr.rep_utils.CLONE_REPORT( :arg1, :arg2, :arg3); 
end;"""

cur.execute(sqlStr, repParams)

connection.commit

cur.close

connection.close


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


Re: understaning "self"

2008-02-21 Thread Poppy
Thanks for your explanation and pointer.

"Mike Driscoll" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Feb 21, 7:34 am, "Poppy" <[EMAIL PROTECTED]> wrote:
>> I've been searching online to try get a better understanding of what 
>> "self"
>> does when I define this parameter in my class functions. All I'm finding 
>> is
>> debates on whether  "self" has any value to the language but that doesn't
>> help me in my newbie question. So the code excerpt below is from 
>> "Beginning
>> Python" Norton, Samuel, Aitel, Foster-Johnson, Richardson, Diamon, 
>> Parker,
>> and Roberts.
>>
>> What I think "self" is doing is limiting the function call to only 
>> function
>> in "this" class. So in the function below "has" calls self.has_various(), 
>> if
>> I had a function called "has_various" in my program or another included
>> class using "self" insures that the "has_various" below is the one used. 
>> Am
>> I correct in my understanding?
>>
>> thanks,
>>
>> Zach-
>>
>> def has(self, food_name, quantity=1):
>> """
>> has(food_name, [quantity]) - checks if the string food_name is in the
>> fridge. quantity defaults to 1
>> returns True if there is enough, false otherwise.
>> """
>>
>> return self.has_various({food_name:quantity})
>>
>> def has_various(self, foods):
>> """
>> has various(foods) determines if the dictionary food_name
>> has enough of every element to satisfy a request.
>> returns true if there's enough, Fasle if there's not or if an element 
>> does
>> not exist.
>> """
>> try:
>> for food in foods.keys():
>> if self.items[food] < foods[food]:
>> return False
>> return True
>> except KeyError:
>> return False
>
> I think you are correct. The term "self" is a convention more than
> anything. You can use another name, but it's not recommended as 99% of
> developers expect it to be called "self".
>
> You can read up on it here: 
> http://www.diveintopython.org/object_oriented_framework/defining_classes.html
>
> In there, they define it this way and I quote:
>
> "The first argument of every class method, including __init__, is
> always a reference to the current instance of the class. By
> convention, this argument is always named self. In the __init__
> method, self refers to the newly created object; in other class
> methods, it refers to the instance whose method was called. Although
> you need to specify self explicitly when defining the method, you do
> not specify it when calling the method; Python will add it for you
> automatically."
>
> Hope that helps.
>
> Mike 


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


understaning "self"

2008-02-21 Thread Poppy
I've been searching online to try get a better understanding of what "self" 
does when I define this parameter in my class functions. All I'm finding is 
debates on whether  "self" has any value to the language but that doesn't 
help me in my newbie question. So the code excerpt below is from "Beginning 
Python" Norton, Samuel, Aitel, Foster-Johnson, Richardson, Diamon, Parker, 
and Roberts.

What I think "self" is doing is limiting the function call to only function 
in "this" class. So in the function below "has" calls self.has_various(), if 
I had a function called "has_various" in my program or another included 
class using "self" insures that the "has_various" below is the one used. Am 
I correct in my understanding?

thanks,

Zach-




def has(self, food_name, quantity=1):
"""
has(food_name, [quantity]) - checks if the string food_name is in the
fridge. quantity defaults to 1
returns True if there is enough, false otherwise.
"""

return self.has_various({food_name:quantity})

def has_various(self, foods):
"""
has various(foods) determines if the dictionary food_name
has enough of every element to satisfy a request.
returns true if there's enough, Fasle if there's not or if an element does
not exist.
"""
try:
for food in foods.keys():
if self.items[food] < foods[food]:
return False
return True
except KeyError:
return False 


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