473,468 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

pattern search

Hi,

I wrote a small gtk file manager, which works pretty well. Until
now, I am able to select different file (treeview entries) just by
extension (done with 'endswith'). See the little part below:

self.pathlist1=[ ]
self.patternlist=[ ]
while iter:
# print iter
value = model.get_value(iter, 1)
# if value is what I'm looking for:
if value.endswith("."+ pattern):
selection.select_iter(iter)
selection.select_path(n)
self.pathlist1.append(n)
self.patternlist.append(value)
iter = model.iter_next(iter)
# print value
n=n+1

Now, I would like to improve it by searching for different 'real'
patterns just like using 'ls' in bash. E.g. the entry
'car*.pdf' should select all pdf files with a beginning 'car'.
Does anyone have an idea, how to do it?

Greetings!
Fabian

Mar 27 '07 #1
9 1806
Fabian Braennstroem wrote:
Hi,

I wrote a small gtk file manager, which works pretty well. Until
now, I am able to select different file (treeview entries) just by
extension (done with 'endswith'). See the little part below:

self.pathlist1=[ ]
self.patternlist=[ ]
while iter:
# print iter
value = model.get_value(iter, 1)
# if value is what I'm looking for:
if value.endswith("."+ pattern):
selection.select_iter(iter)
selection.select_path(n)
self.pathlist1.append(n)
self.patternlist.append(value)
iter = model.iter_next(iter)
# print value
n=n+1

Now, I would like to improve it by searching for different 'real'
patterns just like using 'ls' in bash. E.g. the entry
'car*.pdf' should select all pdf files with a beginning 'car'.
Does anyone have an idea, how to do it?
Use regular expressions. They are part of the module "re". And if you use
them, ditch your code above, and make it just search for a pattern all the
time. Because the above is just the case of

*.ext

Diez
Mar 27 '07 #2
Fabian Braennstroem wrote:
Now, I would like to improve it by searching for different 'real'
patterns just like using 'ls' in bash. E.g. the entry
'car*.pdf' should select all pdf files with a beginning 'car'.
Does anyone have an idea, how to do it?
Use module glob.
Mar 27 '07 #3
On Mar 27, 10:18 am, "Diez B. Roggisch" <d...@nospam.web.dewrote:
Fabian Braennstroem wrote:
Hi,
I wrote a small gtk file manager, which works pretty well. Until
now, I am able to select different file (treeview entries) just by
extension (done with 'endswith'). See the little part below:
self.pathlist1=[ ]
self.patternlist=[ ]
while iter:
# print iter
value = model.get_value(iter, 1)
# if value is what I'm looking for:
if value.endswith("."+ pattern):
selection.select_iter(iter)
selection.select_path(n)
self.pathlist1.append(n)
self.patternlist.append(value)
iter = model.iter_next(iter)
# print value
n=n+1
Now, I would like to improve it by searching for different 'real'
patterns just like using 'ls' in bash. E.g. the entry
'car*.pdf' should select all pdf files with a beginning 'car'.
Does anyone have an idea, how to do it?

Use regular expressions. They are part of the module "re". And if you use
them, ditch your code above, and make it just search for a pattern all the
time. Because the above is just the case of

*.ext

Diez- Hide quoted text -

- Show quoted text -
The glob module is a more direct tool based on the OP's example. The
example he gives works directly with glob. To use re, you'd have to
convert to something like "car.*\.pdf", yes?

(Of course, re offers much more power than simple globbing. Not clear
how much more the OP was looking for.)

-- Paul

Mar 27 '07 #4
Hi to all,

Wojciech Mu?a schrieb am 03/27/2007 03:34 PM:
Fabian Braennstroem wrote:
>Now, I would like to improve it by searching for different 'real'
patterns just like using 'ls' in bash. E.g. the entry
'car*.pdf' should select all pdf files with a beginning 'car'.
Does anyone have an idea, how to do it?

Use module glob.
Thanks for your help! glob works pretty good, except that I just
deleted all my lastet pdf files :-(

Greetings!
Fabian

Mar 27 '07 #5
On Mar 27, 3:13 pm, Fabian Braennstroem <f.braennstr...@gmx.dewrote:
Hi to all,

Wojciech Mu?a schrieb am 03/27/2007 03:34 PM:
Fabian Braennstroem wrote:
Now, I would like to improve it by searching for different 'real'
patterns just like using 'ls' in bash. E.g. the entry
'car*.pdf' should select all pdf files with a beginning 'car'.
Does anyone have an idea, how to do it?
Use module glob.

Thanks for your help! glob works pretty good, except that I just
deleted all my lastet pdf files :-(

Greetings!
Fabian
Then I shudder to think what might have happened if you had used
re's! :)

-- Paul

Mar 27 '07 #6
Paul McGuire schrieb:
On Mar 27, 10:18 am, "Diez B. Roggisch" <d...@nospam.web.dewrote:
>Fabian Braennstroem wrote:
>>Hi,
I wrote a small gtk file manager, which works pretty well. Until
now, I am able to select different file (treeview entries) just by
extension (done with 'endswith'). See the little part below:
self.pathlist1=[ ]
self.patternlist=[ ]
while iter:
# print iter
value = model.get_value(iter, 1)
# if value is what I'm looking for:
if value.endswith("."+ pattern):
selection.select_iter(iter)
selection.select_path(n)
self.pathlist1.append(n)
self.patternlist.append(value)
iter = model.iter_next(iter)
# print value
n=n+1
Now, I would like to improve it by searching for different 'real'
patterns just like using 'ls' in bash. E.g. the entry
'car*.pdf' should select all pdf files with a beginning 'car'.
Does anyone have an idea, how to do it?
Use regular expressions. They are part of the module "re". And if you use
them, ditch your code above, and make it just search for a pattern all the
time. Because the above is just the case of

*.ext

Diez- Hide quoted text -

- Show quoted text -

The glob module is a more direct tool based on the OP's example. The
example he gives works directly with glob. To use re, you'd have to
convert to something like "car.*\.pdf", yes?

(Of course, re offers much more power than simple globbing. Not clear
how much more the OP was looking for.)
I'm aware of the glob-module. But it only works on files. I was under
the impression that he already has a list of files he wants to filter
instead of getting it fresh from the filesystem.

Diez
Mar 27 '07 #7
En Tue, 27 Mar 2007 18:42:15 -0300, Diez B. Roggisch <de***@nospam.web.de>
escribió:
Paul McGuire schrieb:
>On Mar 27, 10:18 am, "Diez B. Roggisch" <d...@nospam.web.dewrote:
>>Fabian Braennstroem wrote:
while iter:
value = model.get_value(iter, 1)
if value.endswith("."+ pattern): [...]

Now, I would like to improve it by searching for different 'real'
patterns just like using 'ls' in bash. E.g. the entry
'car*.pdf' should select all pdf files with a beginning 'car'.
Does anyone have an idea, how to do it?
>>Use regular expressions. They are part of the module "re". And if you
use them, ditch your code above, and make it just search for a pattern
all the time. Because the above is just the case of
*.ext
>The glob module is a more direct tool based on the OP's example. The
example he gives works directly with glob. To use re, you'd have to
convert to something like "car.*\.pdf", yes?
I'm aware of the glob-module. But it only works on files. I was under
the impression that he already has a list of files he wants to filter
instead of getting it fresh from the filesystem.
In that case the best way would be to use the fnmatch module - it already
knows how to translate from car*.pdf into the right regexp. (The glob
module is like a combo os.listdir+fnmatch.filter)

--
Gabriel Genellina

Mar 27 '07 #8
Hi,

Gabriel Genellina schrieb am 03/27/2007 10:09 PM:
En Tue, 27 Mar 2007 18:42:15 -0300, Diez B. Roggisch <de***@nospam.web.de>
escribió:
>Paul McGuire schrieb:
>>On Mar 27, 10:18 am, "Diez B. Roggisch" <d...@nospam.web.dewrote:
Fabian Braennstroem wrote:
while iter:
value = model.get_value(iter, 1)
if value.endswith("."+ pattern): [...]
>
Now, I would like to improve it by searching for different 'real'
patterns just like using 'ls' in bash. E.g. the entry
'car*.pdf' should select all pdf files with a beginning 'car'.
Does anyone have an idea, how to do it?
>>>Use regular expressions. They are part of the module "re". And if you
use them, ditch your code above, and make it just search for a pattern
all the time. Because the above is just the case of
*.ext
>>The glob module is a more direct tool based on the OP's example. The
example he gives works directly with glob. To use re, you'd have to
convert to something like "car.*\.pdf", yes?
>I'm aware of the glob-module. But it only works on files. I was under
the impression that he already has a list of files he wants to filter
instead of getting it fresh from the filesystem.

In that case the best way would be to use the fnmatch module - it already
knows how to translate from car*.pdf into the right regexp. (The glob
module is like a combo os.listdir+fnmatch.filter)
I have a already a list, but I 'glob' looked so easy ... maybe it is
faster to use fnmatch. When I have time I try it out...

Thanks!
Fabian

Mar 28 '07 #9
Hi Paul,

Paul McGuire schrieb am 03/27/2007 07:19 PM:
On Mar 27, 3:13 pm, Fabian Braennstroem <f.braennstr...@gmx.dewrote:
>Hi to all,

Wojciech Mu?a schrieb am 03/27/2007 03:34 PM:
>>Fabian Braennstroem wrote:
Now, I would like to improve it by searching for different 'real'
patterns just like using 'ls' in bash. E.g. the entry
'car*.pdf' should select all pdf files with a beginning 'car'.
Does anyone have an idea, how to do it?
Use module glob.
Thanks for your help! glob works pretty good, except that I just
deleted all my lastet pdf files :-(

Greetings!
Fabian

Then I shudder to think what might have happened if you had used
re's! :)
A different feature it had was to copy the whole home-partition
(about 19G) into one of its own directories ... the strange thing:
it just needed seconds to do that and I did not have the permission
to all files and directories! It was pretty strange! Hopefully it
was no security bug in python...

Greetings!
Fabian

Mar 29 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dariusz | last post by:
Despite looking at a number of tutorials in books and online examples on pattern matching - I can't quite get my head around it to work... so need some help. What I have now is a variable that...
2
by: BalyanM | last post by:
Hi, I am new to python.I am using it on redhat linux 9. I am interested to run python on a sun machine(SunE420R,os=solaris) with 4 cpu's for a pattern discovery/search program on biological...
9
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images...
1
by: Henry | last post by:
I have a table that stores a list of zip codes using a varchar column type, and I need to perform some string prefix pattern matching search. Let's say that I have the columns: 94000-1235 94001...
2
by: ALI-R | last post by:
I am using the follwoing code to get all files which have txt as an extension but I get an error that your search pattern is not correct.it seems this fuction dosn't accept "*.txt" as search...
2
by: Alphonse Giambrone | last post by:
Is there a way to use multiple search patterns when calling Directory.GetFiles. For instance Directory.GetFiles("C:\MyFolder", "*.aspx") will return all files with the aspx extension. But what if...
5
by: olaufr | last post by:
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...
1
by: Eric | last post by:
I use RegEx to search pattern. Script works fine in the situation when there is a colon after each word and it fetch the rest of the word from that line. Now the pattern is in square bracket and i...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
3
by: mercuryshipzz | last post by:
#!/usr/bin/perl #use strict; use warnings; sub search_pattern { my $file_name = $_;
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.