Glob returning an empty list when passed a variable

2007-02-09 Thread Neil Webster
Hi,

I was wondering whether anybody could help me out.

I have a program, for part of it I am trying to pass a variable to a
glob function, this returns an empty list.  The strange thing is when
I hard code in the variable the glob section works.

Does anybody have any ideas as why it is not working?

The section of code that is not working is:

# The variable to be passed to the glob function
area_name_string = '"*% s*"' % (Area_name)

os.chdir(Input)

filename = glob.glob(area_name_string)

Thanks in advance

Neil

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


Re: Glob returning an empty list when passed a variable

2007-02-09 Thread Neil Webster
On 9 Feb, 14:15, Steve Holden <[EMAIL PROTECTED]> wrote:
> Neil Webster wrote:
> > Hi,
>
> > I was wondering whether anybody could help me out.
>
> > I have a program, for part of it I am trying to pass a variable to a
> > glob function, this returns an empty list.  The strange thing is when
> > I hard code in the variable the glob section works.
>
> > Does anybody have any ideas as why it is not working?
>
> > The section of code that is not working is:
>
> > # The variable to be passed to the glob function
> > area_name_string = '"*% s*"' % (Area_name)
>
> > os.chdir(Input)
>
> > filename = glob.glob(area_name_string)
>
> > Thanks in advance
>
> Because you are trying to match filenames that have a double-quote
> character at the start and end? Try
>
> area_name_string = '*% s*' % (Area_name)
>
> Interesting, I never realised until now that you can have spaces between
> the percent sign and th format effector.
>
> regards
>   Steve
> --
> Steve Holden   +44 150 684 7255  +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenwebhttp://del.icio.us/steve.holden
> Blog of Note:  http://holdenweb.blogspot.com
> See you at PyCon?http://us.pycon.org/TX2007- Hide quoted text -
>
> - Show quoted text -

Steve and Philipp,

Thanks very much for the promptness of the reply and providing the
answer.

Steve, it appears to work so I left it, should it not be possible?

Regards

Neil

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


Problems with if/elif statement syntax

2007-11-22 Thread Neil Webster
Hi all,

I'm sure I'm doing something wrong but after lots of searching and
reading I can't work it out and was wondering if anybody can help?

I've got the following block of code:
if a >= 20 and a < 100:
if c == "c":
radius = 500
else:
radius = 250
elif (a >= 100) and (a < 500):
radius = 500
elif (a >= 500) and (a < 1000):
radius = 1000
elif (a >= 1000) and (a < 3000):
radius = 1500
elif (a >= 3000) and (a < 5000):
radius = 2000
else:
radius = 4000

No matter what value goes in for 'a' the radius always comes out as
4000.

What am I doing wrong?

Cheers

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


Hexadecimal list conversion

2007-12-20 Thread Neil Webster
Hi All.

I have a list which is a line from a file:
['\x003\x008\x001\x004\x007\x005\x00.\x005\x000\x002\x005\x009\x009\x00',
'\x002\x001\x003\x006\x002\x002\x00.\x001\x007\x004\x002\x008\x002\x00']

This should be in the format:
['381475.502599', '213622.174282']

I've tried a few options using replace (replacing "\x00" with "") and
trying to convert from hexademical to decimal.

But nothing has worked.  Can anybody give any tips to help?

Thanks.

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


Simple list problem that's defeating me!

2010-06-22 Thread Neil Webster
Hi all,

I've got a simple problem but it's defeated me and I was wondering if
somebody could point out where I'm going wrong or offer an alternative
solution to the problem?

I have a list of lists such as [[a,2,3,4],[b,10,11,12], [a,2,3,4]].  I
need to combine the two lists that have the same first character in
this example 'a'.  In reality there are 656 lists within the list.

My attempt so far is:
L = [[a,2,3,4],[b,10,11,12], [a,2,3,4]]
d = []
z = 1
while z <= len(L):
for a in L:
if L.count(a[0]) > 1:
d.append(a[2:])

summed = [sum(pair) for pair in zip(d[0], d[1])]
z = z+1
print summed

Any pointers more than welcome.

Thanks all.

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


Re: Simple list problem that's defeating me!

2010-06-24 Thread Neil Webster
Thanks for the help so far.

The background to the problem is that the lists come from reading a
dbf file.  The code that I am trying to write is to merge lines of the
dbf based on the first column.  So in my example there would be three
lines:
a 2 3 4
b 10 11 12
a 2 3 4

The expected output from the above example lines would be:
a 4 6 8
b 10 11 12

 ... and the lines are read as: [[a,2,3,4],[b,10,11,12], [a,2,3,4]]

In response to not posting working code or actual inputs, ummm, that's
why I am asking the question here.








On Jun 22, 4:38 pm, Bruno Desthuilliers  wrote:
> Neil Webster a crit :
>
> > Hi all,
>
> > I've got a simple problem but it's defeated me and I was wondering if
> > somebody could point out where I'm going wrong
>
> 1/ not posting working code (got a NameError)
> 2/ not posting the expected output
> 3/ not posting the actual output
>
> > or offer an alternative
> > solution to the problem?
>
> When you'll have fixed the 3 problems listed above !-)
>
> (snip broken code)

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