[Tutor] regular expression matching a dot?

2005-10-19 Thread Christian Meesters
Hi

I've got the problem that I need to find a certain group of file names 
within a lot of different file names. Those I want to match with a 
regular expression are a bit peculiar since they all look like:
07SS.INF , 10SE.INF, 13SS.INF, 02BS.INF, 05SS.INF.
Unfortunately there are similar file names that shouldn't be matched, 
like:
01BE.INF, 02BS.INF
Any other extension than 'INF' should also be skipped. (There are names 
like 07SS.E00, wich I don't want to see matched.)
So I tried the following pattern (using re):
\d+[SS|SE]\.INF - as there should be at least one digit, the group 'SE' 
or 'SS' followed by a dot and the extension 'INF'.

Well, this doesn't work, no match. However, if I change the pattern to 
\d+[SS|SE] it somehow works and all all valid names are matched. But if 
there is a different extension than 'INF' it matches too - but it 
shouldn't. (Surrounding the dot with [] doesn't help, though I have no 
idea as for why.)
Any ideas what I could do else?

TIA
Christian

PS Hope that I described the problem well enough ...

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression matching a dot?

2005-10-19 Thread Kent Johnson
Christian Meesters wrote:
> Hi
> 
> I've got the problem that I need to find a certain group of file names 
> within a lot of different file names. Those I want to match with a 
> regular expression are a bit peculiar since they all look like:
> 07SS.INF , 10SE.INF, 13SS.INF, 02BS.INF, 05SS.INF.
> Unfortunately there are similar file names that shouldn't be matched, 
> like:
> 01BE.INF, 02BS.INF
> Any other extension than 'INF' should also be skipped. (There are names 
> like 07SS.E00, wich I don't want to see matched.)
> So I tried the following pattern (using re):
> \d+[SS|SE]\.INF - as there should be at least one digit, the group 'SE' 
> or 'SS' followed by a dot and the extension 'INF'.

Use parentheses () for grouping. Brackets [] define a group of characters. Your 
re says to match
  \d+ one or more digits
  [SS|SE] exactly one of the characters S, |, E
  \.INF literal .INF

Since there are TWO characters S or E, nothing matches. Change the [] to () and 
it works.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression matching a dot?

2005-10-19 Thread Misto .
[ Workaround ]
What about using the glob module?

http://docs.python.org/lib/module-glob.html

you can use something like
glob.glob('./[0-9][0-9]S[E|S].INF')
(Not tested)


Misto
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression matching a dot?

2005-10-19 Thread Christian Meesters
Hi Misto,

Thanks, but this is no option for me - though I use glob a lot in other 
cases (mostly the quick and dirty hacks). But here I'm working on a 
list of names - not the files directly. Besides: REs are a lot more 
powerful (usually ;-), e.g. I'm using \d+ since I don't now that there 
are always only two digits, but there need to be one.

Cheers,
Christian

On 19 Oct 2005, at 12:11, Misto . wrote:

> [ Workaround ]
> What about using the glob module?
>
> http://docs.python.org/lib/module-glob.html
>
> you can use something like
> glob.glob('./[0-9][0-9]S[E|S].INF')
> (Not tested)
>
>
> Misto
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression matching a dot?

2005-10-19 Thread Christian Meesters
Actually, your answer did help to open my eyes. The expression is 
"\d+S[S|E]\.INF": Ouch!

Thanks a lot,
Christian

On 19 Oct 2005, at 12:11, Misto . wrote:

> [ Workaround ]
> What about using the glob module?
>
> http://docs.python.org/lib/module-glob.html
>
> you can use something like
> glob.glob('./[0-9][0-9]S[E|S].INF')
> (Not tested)
>
>
> Misto
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression matching a dot?

2005-10-19 Thread Kent Johnson
Christian Meesters wrote:
> Actually, your answer did help to open my eyes. The expression is 
> "\d+S[S|E]\.INF": Ouch!

That will work, but what you really mean is one of these:
"\d+S[SE]\.INF"
"\d+S(S|E)\.INF"

Your regex will match 0S|.INF

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] setting

2005-10-19 Thread Shi Mu
I have installed Python 2.3 and I type "help()" and then "Keywords".
I get a list of words. And it says that I can enter any of the words
to get more help.  I enter
"and" and I get the following error message:
"Sorry, topic and keyword documentation is not available because the Python
HTML documentation files could not be found.  If you have installed them,
please set the environment variable PYTHONDOCS to indicate their location."

but I have set both the environment variable, with the path to be
C:\Python23\Doc which includes python23.chm
Why I still got the above error message?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression matching a dot?

2005-10-19 Thread Christian Meesters
Thanks, corrected. I was happy now - and then too fast ;-).

Cheers
Christian
On 19 Oct 2005, at 13:50, Kent Johnson wrote:

> Christian Meesters wrote:
>> Actually, your answer did help to open my eyes. The expression is 
>> "\d+S[S|E]\.INF": Ouch!
>
> That will work, but what you really mean is one of these:
> "\d+S[SE]\.INF"
> "\d+S(S|E)\.INF"
>
> Your regex will match 0S|.INF
>
> Kent
>

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python books

2005-10-19 Thread David Holland
The best book I found was python programming for the
absolute beginner by Michael Dawson.  I would strongly
recommend it.
The only annoying thing is that he uses a games
wrapper called livewires, which he modifies from the
original but keeps the same name, which does not seem
very clever to me.  So if you want to have one program
with the original wrapper and one program with his
then you have a slight problem.



___ 
To help you stay safe and secure online, we've developed the all new Yahoo! 
Security Centre. http://uk.security.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python books

2005-10-19 Thread David Holland
The best book I found was python programming for the
absolute beginner by Michael Dawson.  I would strongly
recommend it.
The only annoying thing is that he uses a games
wrapper called livewires, which he modifies from the
original but keeps the same name, which does not seem
very clever to me.  So if you want to have one program
with the original wrapper and one program with his
then you have a slight problem.



___ 
To help you stay safe and secure online, we've developed the all new Yahoo! 
Security Centre. http://uk.security.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] setting

2005-10-19 Thread paul brian
Did you install from the python.org download or from activestate. If
you have a .chm file I am guessing activestate. For some reason the
normal docs that you get with the python.org distributin (the
"official" one) are only found as a chm file.

I suggest you get the python.org installer and carefully install to a
temp directory, and copy across the html files in Doc, or remove
activestate, install python.org and then add in the win32all
extensions. I would suggest the first option for sheer ease. (in fact
on windows i would suggest keeping the .chm and using that, cmd.exe is
quite poor in command line reading and copying so that .chm is my
favourtie way of looking up documentation)

HTH.




On 10/19/05, Shi Mu <[EMAIL PROTECTED]> wrote:
> I have installed Python 2.3 and I type "help()" and then "Keywords".
> I get a list of words. And it says that I can enter any of the words
> to get more help.  I enter
> "and" and I get the following error message:
> "Sorry, topic and keyword documentation is not available because the Python
> HTML documentation files could not be found.  If you have installed them,
> please set the environment variable PYTHONDOCS to indicate their location."
>
> but I have set both the environment variable, with the path to be
> C:\Python23\Doc which includes python23.chm
> Why I still got the above error message?
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>


--
--
Paul Brian
m. 07875 074 534
t. 0208 352 1741
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] define vars by iteration

2005-10-19 Thread Luke Jordan
I've got a bunch of pickled class instances with self.name attributes, and I would like to assign the instances themselves to variables named whatever is stored in 
self.name using a function. "Can't assign to literal", right? Is there a way to do this?
 
Thanks,
 
Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] setting

2005-10-19 Thread Brian van den Broek
Shi Mu said unto the world upon 2005-10-19 07:22:
> I have installed Python 2.3 and I type "help()" and then "Keywords".
> I get a list of words. And it says that I can enter any of the words
> to get more help.  I enter
> "and" and I get the following error message:
> "Sorry, topic and keyword documentation is not available because the Python
> HTML documentation files could not be found.  If you have installed them,
> please set the environment variable PYTHONDOCS to indicate their location."
> 
> but I have set both the environment variable, with the path to be
> C:\Python23\Doc which includes python23.chm
> Why I still got the above error message?
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


Hi Shi Mu,

I solved that problem by downloading the html version of the docs from 
  the python site, and placing them in the same dir as the .chm, 
setting PYTHONDOCS appropriately.

Best,

Brian vdB

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] define vars by iteration

2005-10-19 Thread Danny Yoo


On Wed, 19 Oct 2005, Luke Jordan wrote:

> I've got a bunch of pickled class instances with
> self.nameattributes, and I would like to assign the
> instances themselves to variables
> named whatever is stored in self.name  using a function.
> "Can't assign to literal", right? Is there a way to do this?

Hi Luke,

It's technically possible to do this, but discouraged.  The reason it's
not so safe is because some of those names might collide with your own
program's names, or with the builtins.  So if you start having pickled
instances with names like 'list' or 'open', havoc is bound to ensue.

Furthermore, Python variable names have some physical restrictions that
may interfere with what you're trying to do:

##
>>> 4meUshouldnthave = 42
  File "", line 1
4meUshouldnthave = 42
   ^
SyntaxError: invalid syntax
##

(For the gory details on what's allowed in a name "identifier", see:
http://www.python.org/doc/ref/identifiers.html)


A safer way to do that I think you want is to use a separate dictionary
container for those instances.  As a concrete example:

##
class Person:
def __init__(self, name):
self.name = name

people_names = ['fred', 'barney', 'wilma', 'betty']
people = {}
for name in people_names:
people[name] = Person(name)
##

Rather than using a direct variable name to refer to the person, we can go
an indirect route, and refer to the corresponding entry in the 'people'
dictionary.  Does this make sense?  This is safer because there's no
potential to munge up the toplevel, plus the 'name' keys won't have the
restrictions that Python variable names have.


Hope this helps!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Saving command line keyed input?

2005-10-19 Thread CPIM Ronin
I know that one should use IDLE or a choosen editor for any substantial 
Python coding! However, if one  happens to have written some interesting 
doodlings on the regular command line interface (under Windows XP in my 
case), is there an easy way to save ALL input to date into a selected file?

For example:
>>>class work_center:
 def __init__(self,x_name):
self.name = x_name

>>>x = work_center("machine press")
>>>

  ---  What do I do to save the above work into a file named "mywork.py"

Thanks.

RC

_
On the road to retirement? Check out MSN Life Events for advice on how to 
get there! http://lifeevents.msn.com/category.aspx?cid=Retirement

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Saving command line keyed input?

2005-10-19 Thread bob
At 02:12 PM 10/19/2005, CPIM Ronin wrote:
>I know that one should use IDLE or a choosen editor for any substantial
>Python coding! However, if one  happens to have written some interesting
>doodlings on the regular command line interface (under Windows XP in my
>case), is there an easy way to save ALL input to date into a selected file?

The way I do it is: select the text by dragging with the mouse (a 
recangle), then hit Enter. This puts it on the clipboard. Then go to where 
you want it and paste. As I did here:

Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> "hi"
'hi'
 >>>


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] iteration is overwriting the previous set value

2005-10-19 Thread Jonas Melian
def _pre_save(self):
for field in [self.name, self.native_name]:
if not field.istitle():
#print field.title()
field = field.title()

The change I try to do there (field = field.title()) is not being applied
I changed code so that you do 'self.foo = bar' statements for each 
attribute instead of using a loop and see if data gets saved, and it goes ok

I'm supposed that each iteration is overwriting the previous set value

how solve it? using a dict?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iteration is overwriting the previous set value

2005-10-19 Thread Danny Yoo

On Thu, 20 Oct 2005, Jonas Melian wrote:

> def _pre_save(self):
> for field in [self.name, self.native_name]:
> if not field.istitle():
> #print field.title()
> field = field.title()
>
> The change I try to do there (field = field.title()) is not being
> applied I changed code so that you do 'self.foo = bar' statements for
> each attribute instead of using a loop and see if data gets saved, and
> it goes ok

Hi Jonas,


Do you understand why it isn't working?

The issue is that 'field' is just another variable name, and the
assignment just redirects that particular name to some other value.  So
when we're doing:

field = field.title()

this statement has no effect on any other name, and in particular, doesn't
do any mutation on 'self'.


As a related matter:

##
>>> a = "42"
>>> b = a
>>> b = "17"
##

What do you expect 'a' to be?



> I'm supposed that each iteration is overwriting the previous set value
>
> how solve it? using a dict?

One way to do this is to use getattr() and setattr() so that we can do
mutation on 'self'.  Your example above should work with:

###
def _pre_save(self):
for fieldname in ['name', 'native_name']:
value = getattr(self, fieldname)
if not value.istitle():
setattr(self, fieldname, value.title())
###


Hope this helps!

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iteration is overwriting the previous set value

2005-10-19 Thread bob
At 04:16 PM 10/19/2005, Jonas Melian wrote:
>def _pre_save(self):
> for field in [self.name, self.native_name]:
> if not field.istitle():
> #print field.title()
> field = field.title()
>
>The change I try to do there (field = field.title()) is not being applied

Yes it is. field (a local variable) is being replaced by field.title(). You 
can confirm that by putting
print field after the assignment.

However I guess you want the change to apply to self.name and self.native_name.

Unfortunately you have a list containing the values of self.name and 
self.native_name. Even if you modified the list elements (which assignment 
to field does not do) self.name and self.native_name would not be affected.

Use getattr and setattr to access and assign the attributes, which you 
specify by name.

def _pre_save(self):
 for fieldname in ['name', 'native_name']:
 setattr(self, fieldname) = getattr(self, fieldname).title()

[snip] 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] iteration is overwriting the previous set value

2005-10-19 Thread bob
At 04:16 PM 10/19/2005, Jonas Melian wrote:
>def _pre_save(self):
> for field in [self.name, self.native_name]:
> if not field.istitle():
> #print field.title()
> field = field.title()

And FWIW there is no benefit in using "if not field.istitle():" since it 
calculates the title value anyway you might just as well assign it without 
checking. 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python books: buying advice needed

2005-10-19 Thread Byron
Hi David,

The answer depends.  If you are looking for free resources, I would 
recommend checking out:  http://www.greenteapress.com

However, if you are looking for a professional-grade book, then I would 
recommend "Python Programming for the Absolute Beginner."  I, personally 
speaking, found this book to be an excellent resource -- I would highly 
recommend it.

Byron
---



David Stotijn wrote:
> Hi,
> 
> I'm planning on buying a book to help me learn Python. Some of the books 
> I'm considering are a few years old and based on an older version of 
> Python (e.g. 2.3).
> Is it wise to buy a book based on an older version? Are the principles 
> and methods used in those books outdated by now?
> Ideally, the book I'm looking for has some "best practice" guidelines 
> and alot of example code.
> 
> Do you have any tips?
> 
> Thanks in advance!
> 
> David
> 
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python books

2005-10-19 Thread Byron
David Holland wrote:
> The best book I found was python programming for the
> absolute beginner by Michael Dawson.  I would strongly
> recommend it.


Yes, I would agree 100%.  Michael Dawson does an excellent job teaching 
Python to beginners.  (Most others don't come close to his book, in my 
opinion.)

Byron
---

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python books: buying advice needed

2005-10-19 Thread w chun
On 10/18/05, Kent Johnson <[EMAIL PROTECTED]> wrote:
> David Stotijn wrote:
> > Hi,
> >
> > I'm planning on buying a book to help me learn Python. Some of the books
> > I'm considering are a few years old and based on an older version of
> > Python (e.g. 2.3).
> > Is it wise to buy a book based on an older version? Are the principles
> > and methods used in those books outdated by now?
>
> 2.3 is not that old. The basics of Python change slowly, especially the 
> beginner-level stuff. The later versions introduce refinements, convenience 
> features and new, advanced stuff; they don't generally break much or change 
> the overall 'feel' of Python. I don't know if there are any books out yet 
> that cover 2.4.
>
> > Ideally, the book I'm looking for has some "best practice" guidelines
> > and alot of example code.
> >
> > Do you have any tips?
>
> I like _Learning Python_


david,

as others have said, for beginners, the version of Python that's used
has less impact than for more advanced users.  look for any book that
focuses on teaching you the language rather than just being a tutorial
for the features in the latest releases.

if you are completely new to programming, as many are here, then the
recommendation for Dawson's Python for the Absolute Beginner seems to
be a very popular choice.  i recently picked up the book to evaluate
to use as the textbook for my intro to programming class, but haven't
had a chance to really go through it yet.  it seems to have surpassed
the popular Learn to Program Using Python by Alan Gauld, which is
slightly dated but also a good choice.
there is also the How to Think like a Computer Scientist series, which
aims at teaching programming to high schoolers, and is available for a
number of languages: Python, Java, C++, and Logo... see
http://www.ibiblio.org/obp/thinkCS

Dawson's book targets games.  there are other intro to programming
books on my shelf with alternative targets:  Python Programming by
John Zelle is gearsed towards learning Computer Science as an
undergraduate, and Mark Guzdial's Intro to Computing and Programming
in Python has a graphics/multimedia approach.  and on the side, i'd
recommend Chris Fehily's Python visual quickstart guide because it has
lots of pictures and serves as a good reference for a beginner.

books such as Learning Python and Core Python Programming are geared
towards those who already know how to program.  some have noted that
Learning Python targets C programmers more than others, but Core
Python doesn't assume anything other than knowing at least one other
high-level language.  and i *definitely* use Core Python when teaching
my standard Python courses.  ;-)

i'd suggest taking a look through some of the titles discussed on this
thread in a bookstore if possible to see what you like, and also check
out the reviews on Amazon as well as Python book reviews online.

hope this helps!
--wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2006,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Saving command line keyed input?

2005-10-19 Thread w chun
On 10/19/05, bob <[EMAIL PROTECTED]> wrote:
> At 02:12 PM 10/19/2005, CPIM Ronin wrote:
> >I know that one should use IDLE or a choosen editor for any substantial
> >Python coding! However, if one  happens to have written some interesting
> >doodlings on the regular command line interface (under Windows XP in my
> >case), is there an easy way to save ALL input to date into a selected file?
>
> The way I do it is: select the text by dragging with the mouse (a
> recangle), then hit Enter. This puts it on the clipboard. Then go to where
> you want it and paste. As I did here:


hi ronin,

another alternative you have in IDLE is to just open a source window
by going to the File menu -> New Window, and doodling in there.  then
just click F5 (to save and) run your doodling.  that way your code is
already saved in a file.  i do have to admit that it's not as easy as
just playing in the interpreter and typing Ctrl-A and pasting that
into your text editor, e-mail window, etc.

good luck!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2006,2001
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor