On Feb 24, 2:11 am, monkeys paw wrote:
> if I have a string such as '01/12/2011' and i want
> to reformat it as '20110112', how do i pull out the components
> of the string and reformat them into a DDMM format?
>
> I have:
>
> import re
>
> test = re.compile('\d\d\/')
> f = open('test.html')
On Feb 23, 9:11 pm, monkeys paw wrote:
> if I have a string such as '01/12/2011' and i want
> to reformat it as '20110112', how do i pull out the components
> of the string and reformat them into a DDMM format?
>
> I have:
>
> import re
>
> test = re.compile('\d\d\/')
> f = open('test.html')
if I have a string such as '01/12/2011' and i want
to reformat it as '20110112', how do i pull out the components
of the string and reformat them into a DDMM format?
I have:
import re
test = re.compile('dd/')
f = open('test.html') # This file contains the html dates
for line in f:
if
In article ,
Chris Rebert wrote:
> regex = compile("(\d\d)/(\d\d)/(\d{4})")
I would probably write that as either
r"(\d{2})/(\d{2})/(\d{4})"
or (somewhat less likely)
r"(\d\d)/(\d\d)/(\d\d\d\d)"
Keeping to one consistent style makes it a little easier to read. Also,
don't forget the leadi
On Wed, Feb 23, 2011 at 6:37 PM, Steven D'Aprano
wrote:
> On Wed, 23 Feb 2011 21:11:53 -0500, monkeys paw wrote:
>> if I have a string such as '01/12/2011' and i want to reformat
>> it as '20110112', how do i pull out the components of the string and
>> reformat them into a DDMM format?
>
> da
On Wed, 23 Feb 2011 21:11:53 -0500, monkeys paw wrote:
> if I have a string such as '01/12/2011' and i want to reformat
> it as '20110112', how do i pull out the components of the string and
> reformat them into a DDMM format?
data = '01/12/2011'
# Throw away tags.
data = data[4:-5]
# Separat
In article ,
monkeys paw wrote:
> if I have a string such as '01/12/2011' and i want
> to reformat it as '20110112', how do i pull out the components
> of the string and reformat them into a DDMM format?
>
> I have:
>
> import re
>
> test = re.compile('\d\d\/')
> f = open('test.html') #
On 07/16/2010 02:20 PM, Chad Kellerman wrote:
Greetings,
I have some code that I wrote and know there is a better way to
write it. I wonder if anyone could point me in the right direction
on making this 'cleaner'.
I have two lists: liveHostList = [ app11, app12, web11, web12, hos
Chad Kellerman wrote:
Greetings,
I have some code that I wrote and know there is a better way to
write it. I wonder if anyone could point me in the right direction
on making this 'cleaner'.
I have two lists: liveHostList = [ app11, app12, web11, web12, host11 ]
> Fair enough. To help you understand the method I used, I'll give you
> this hint. It's true that regex on works on strings. However, is there
> any way to convert arbitrarily complex data structures to string
> representations? You don't need to be an experienced Python user to
> answer to this ;
On Jun 19, 9:03 pm, John Machin <[EMAIL PROTECTED]> wrote:
> On Jun 20, 10:45 am, Chris <[EMAIL PROTECTED]> wrote:
>
> > On Jun 17, 1:09 pm, [EMAIL PROTECTED] wrote:
>
> > > Kirk Strauser:
>
> > > > Hint: recursion. Your general algorithm will be something like:
>
> > > Another solution is to use
On Jun 20, 1:45 am, Chris <[EMAIL PROTECTED]> wrote:
> On Jun 17, 1:09 pm, [EMAIL PROTECTED] wrote:
>
> > Kirk Strauser:
>
> > > Hint: recursion. Your general algorithm will be something like:
>
> > Another solution is to use a better (different) language, that has
> > built-in pattern matching, o
On Jun 20, 1:44 am, Chris <[EMAIL PROTECTED]> wrote:
> Thanks for your help. Those weren't quite what I was looking for, but
> I ended up figuring it out on my own. Turns out you can actually
> search nested Python lists using simple regular expressions.
Strange?
How do you match nested '[' ... ']
On Jun 20, 10:45 am, Chris <[EMAIL PROTECTED]> wrote:
> On Jun 17, 1:09 pm, [EMAIL PROTECTED] wrote:
>
> > Kirk Strauser:
>
> > > Hint: recursion. Your general algorithm will be something like:
>
> > Another solution is to use a better (different) language, that has
> > built-in pattern matching,
On Jun 17, 1:09 pm, [EMAIL PROTECTED] wrote:
> Kirk Strauser:
>
> > Hint: recursion. Your general algorithm will be something like:
>
> Another solution is to use a better (different) language, that has
> built-in pattern matching, or allows to create one.
>
> Bye,
> bearophile
Btw, Python's stdl
Thanks for your help. Those weren't quite what I was looking for, but
I ended up figuring it out on my own. Turns out you can actually
search nested Python lists using simple regular expressions.
--
http://mail.python.org/mailman/listinfo/python-list
Kirk Strauser:
> Hint: recursion. Your general algorithm will be something like:
Another solution is to use a better (different) language, that has
built-in pattern matching, or allows to create one.
Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list
At 2008-06-17T05:55:52Z, Chris <[EMAIL PROTECTED]> writes:
> Is anyone aware of any prior work done with searching or matching a
> pattern over nested Python lists? I have this problem where I have a
> list like:
>
> [1, 2, [1, 2, [1, 7], 9, 9], 10]
>
> and I'd like to search for the pattern [1, 2
Hello,
> I have a large text file (1GB or so) with structure similar to the
> html example below.
>
> I have to extract content (text between div and tr tags) from this
> file and put it into a spreadsheet or a database - given my limited
> python knowledge I was going to try to do this with regex
Hello Python Community,
I have a large text file (1GB or so) with structure similar to the
html example below.
I have to extract content (text between div and tr tags) from this
file and put it into a spreadsheet or a database - given my limited
python knowledge I was going to try to do this with
azrael wrote:
> can someone give me good links for pattern matching in images using
> python
There is a python-binding available for the OpenCV library, a collection of
state-of-the-art CV algorithms.
And it comes with a free manual
Diez
--
http://mail.python.org/mailman/listinfo/python-li
BartlebyScrivener wrote:
> Even without the marker, can't you do:
>
> sentence = "the fabric is red"
> colors = ["red", "white", "blue"]
>
> for color in colors:
> if (sentence.find(color) > 0):
> print color, sentence.find(color)
>
That depends on whether you're only looking for who
Even without the marker, can't you do:
sentence = "the fabric is red"
colors = ["red", "white", "blue"]
for color in colors:
if (sentence.find(color) > 0):
print color, sentence.find(color)
--
http://mail.python.org/mailman/listinfo/python-list
Taking you literally, I'm not sure you need regex. If you know or can
find position n, then can't you just:
sentence = "the color is $red"
patterns = ["blue","red","yellow"]
pos = sentence.find("$")
for x in patterns:
if x==sentence[pos+1:]:
print x, pos+1
But maybe I'm oversimplifyin
On Mon, 12 Dec 2005 [EMAIL PROTECTED] wrote:
> I'd need to perform simple pattern matching within a string using a list
> of possible patterns. For example, I want to know if the substring
> starting at position n matches any of the string I have a list, as
> below:
>
> sentence = "the color is
[EMAIL PROTECTED] wrote:
> Hi,
>
> I'd need to perform simple pattern matching within a string using a
> list of possible patterns. For example, I want to know if the substring
> starting at position n matches any of the string I have a list, as
> below:
>
> sentence = "the color is $red"
> patte
Hello!
I was trying to create a program to search for the largest common
subsetstring among filenames in a directory, them move the filenames
to the substring's name. I have succeeded, with help, in doing so and
here is the code.
Thanks for your help!
--- Code ---
#This program was created wit
tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Synonymous wrote:
> > tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> >
> >>tiissa wrote:
> >>
> >>>If you know the number of characters to match can't you just compare
> >>>slices?
> >>
> >>If you
John Machin <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> On 17 Apr 2005 18:12:19 -0700, [EMAIL PROTECTED] (Synonymous)
> wrote:
>
> >
> >I will look for a Left$(str) function that looks at the first X
> >characters for python :)).
> >
>
> Wild goose chase alert! AFAIK there
Synonymous wrote:
tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
tiissa wrote:
If you know the number of characters to match can't you just compare
slices?
If you don't, you can still do it by hand:
In [7]: def cmp(s1,s2):
: diff_map=[chr(s1[i]!=s2[i]) for i in r
On 17 Apr 2005 18:12:19 -0700, [EMAIL PROTECTED] (Synonymous)
wrote:
>
>I will look for a Left$(str) function that looks at the first X
>characters for python :)).
>
Wild goose chase alert! AFAIK there isn't one. Python uses slice
notation instead of left/mid/right/substr/whatever functions. I do
tiissa <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> tiissa wrote:
> > If you know the number of characters to match can't you just compare
> > slices?
> If you don't, you can still do it by hand:
>
> In [7]: def cmp(s1,s2):
>: diff_map=[chr(s1[i]!=s2[i]) for i in
tiissa wrote:
Synonymous wrote:
Can regular expressions compare file names to one another. It seems RE
can only compare with input i give it, while I want it to compare
amongst itself and give me matches if the first x characters are
similiar.
Do you have to use regular expressions?
If you know the
tiissa wrote:
If you know the number of characters to match can't you just compare
slices?
If you don't, you can still do it by hand:
In [7]: def cmp(s1,s2):
: diff_map=[chr(s1[i]!=s2[i]) for i in range(min(len(s1),
len(s2)))]
: diff_index=''.join(diff_map).find(chr(True))
.
Synonymous wrote:
Can regular expressions compare file names to one another. It seems RE
can only compare with input i give it, while I want it to compare
amongst itself and give me matches if the first x characters are
similiar.
Do you have to use regular expressions?
If you know the number of cha
Le 24 Mar 2005 06:16:12 -0800, Ben a écrit :
>
> Below is a few sample lines. There is the name followed by the class
> (not important) followed by 5 digits each of which can range 1-9 and
> each detail a different ability, such as fitness, attacking ability
> etc. Finally the preferred foot is st
George Sakkis wrote:
> B
> "Ben" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > I'm currently trying to develop a demonstrator in python for an
> > ontology of a football team. At present all the fit players are
> > exported to a text document.
> >
> > The program reads the docu
Ben,
Others have answered your specific questions, but I thought
I'd use this opportunity to make a general statement. Unlike
other programming languages, Python doesn't make its built-in
functions keywords. You should never, ever, ever name a
variable 'list' (the same is true of dict, tuple, st
First, if you're going to loop over each line, do it like this:
for line in file('playerlist.txt'):
#do stuff here
Second, this statement is referencing the *second* item in the list,
not the first:
match = ph.match(list[1])
Third, a simple splitting of the lines by some delimiter character
B
"Ben" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm currently trying to develop a demonstrator in python for an
> ontology of a football team. At present all the fit players are
> exported to a text document.
>
> The program reads the document in and splits each line into a st
40 matches
Mail list logo