[Tutor] Wrong module name and line number in logging package.

2006-11-05 Thread Noufal Ibrahim
Greetings everyone,
   I'm using the python standard logging package for a personal project
of mine and have initialised it like so.


logger = logging.getLogger("pydagogue")
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter("[%(levelname)s]%(pathname)s:%(lineno)d
%(message)s"))
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

Suppose I have a module called ui as part of this project, I want debug
messages from it to be displayed like (assuming it's called from line 25)

[DEBUG]ui.py:25 Debug message here.

the level displays fine and so does the message. The pathname however
prints the name logging/__init__.py and the lineno 1072 which I assume
are from the logging module itself.

Am I doing something wrong here?

Peace.


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


[Tutor] python, python2 & python2.3 in /usr/bin

2006-11-05 Thread Michael Daly
Greetings everyone
Could someone please explain these links...python2 seems to have resulted
from an installation of python 2.5 (in a specified dir via the --prefix
switch) and is a symbolic link to 'python'

The others - python and python2.3 are just files and predate the python2
file.

I am worried that installing python 2.5 might have upset the 'path' for
python (which I don't understand very well).

When I type 'python -V' I get:
python 2.3.4
which is what i want for centos / asterisk; however asterisk had trouble
starting after a reboot (it is a python 2.3.4 dependent app) 

Does this sound normal?

Thanks to anyone who can help

Regards & remaining, 

Compused
 



 


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


Re: [Tutor] Amazing power of Regular Expressions...

2006-11-05 Thread Kent Johnson
Alan Gauld wrote:
> But I sure agree with it. The problem with Regex is that they can
> be just a bit too powerful. To cite another programming proverb,
> this time by Bjarne Stroustrup I think:
> 
> "C makes it easy to shoot yourself in the foot;
> C++ makes it  harder, but when you do,
> it blows away your whole leg."
> 
> Regex can be like that too.

I guess it's time to trot out the famous quote of Jamie Zawinsky:

> Some people, when confronted with a problem, think
> “I know, I'll use regular expressions.”   Now they have two problems.

In this case I think regex is not the best solution. A better way to 
validate a date is to try to use it as a date. The regex 
'\d\d/\d\d/\d\d\d\d' accepts all kinds of non-dates such as 99/99/, 
not to mention accepting US format dates such as 12/25/2006 when you 
want 25/12/2006. I would use
   import time
   try:
 time.strptime(date, '%d/%m/%Y')
 # it's a valid date
   except ValueError:
 # not a valid date

which at least restricts the input to something that is a valid date, 
though it won't detect that a user typed 11/5/2006 when they mean 5/11/2006.

Regular expressions are an extremely powerful and useful tool that every 
programmer should master and then put away and not use when there is an 
alternative :-)

Kent

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


[Tutor] Help me to debug this script .. I tried but ....

2006-11-05 Thread Asrarahmed Kadri
Hi Folks,
 
I have a function defined in a module.
I am using this module in a script but its giving me error: the traceback is as follows:
 

 
29/2/2003['29', '2', '2003']Traceback (most recent call last):  File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript    exec codeObject in __main__.__dict__
  File "C:\project stuff-programs\Scriptdate.py", line 18, in ?    t1 = my_version_datecheck.dateCheck(dt1,0)  File "my_version_datecheck.py", line 38, in dateCheck    import traceback
NameError: global name 'traceback' is not defined 

 
The module name is : my_version_datecheck.py 
 

 

import stringimport datetimeimport time
 
def dateCheck(date1,num_days):    flag = True    startdate = None    enddate = None        if num_days < 0 or num_days > 31:    flag = False    print "The argument for -n has to be between 0 and 31"
    return (flag,startdate,enddate)        else:    print date1    date_lst = string.split(date1,"/")    print date_lst    ln = len(date_lst)    if ln != 3:
        flag = False    print "The argument for -D option has to be in the format: dd/mm/"    return (flag,startdate,enddate)    else:    date_lst.reverse()
    try:    startdate = datetime.date(int(date_lst[0]),int(date_lst[1]),int(date_lst[2]))    enddate = startdate + datetime.timedelta(days=num_days)        except ValueError:
    import traceback    flag = False    err_msg = traceback.format_exc()    index = string.find(err_msg,'Value')    print err_msg[index:]
    return (flag,startdate,enddate)
    return (flag,startdate,enddate)

 
The code for test script is as follows:
 


import my_version_datecheck
import traceback
dt = '12/3/2005'
dt1 = '29/2/2003'
dt2 = '3/32/5m'
t = my_version_datecheck.dateCheck(dt,0)
print t
t1 = my_version_datecheck.dateCheck(dt1,0)
print t1
t2 = my_version_datecheck.dateCheck(dt2,0)
print t2

 
TIA.
 
Regards,
Asrarahmed-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Encoding and XML troubles

2006-11-05 Thread Kent Johnson
William O'Higgins Witteman wrote:
> I've been struggling with encodings in my XML input to Python programs.
> 
> Here's the situation - my program has no declared encoding, so it
> defaults to ASCII.  It's written in Unicode, but apparently that isn't
> confusing to the parser.  Fine by me.  I import some XML, probably
> encoded in the Windows character set (I don't remember what that's
> called now).  I can read it for the most part - but it throws exceptions
> when it hits accented characters (some data is being input by French
> speakers).  I am using ElementTree for my XML parsing
> 
> What I'm trying to do is figure out what I need to do to get my program
> to not barf when it hits an accented character.  I've tried adding an
> encoding line as suggested here:
> 
> http://www.python.org/dev/peps/pep-0263/
> 
> What these do is make the program fail to parse the XML at all.  Has
> anyone encountered this?  Suggestions?  Thanks.

As Luke says, the encoding of your program has nothing to do with the 
encoding of the XML or the types of data your program will accept. PEP 
263 only affects the encoding of string literals in your program.

It sounds like your XML is not well-formed. XML files can have an 
encoding declaration *in the XML*. If it in not present, the file is 
assumed to be in UTF-8 encoding. If your XML is in Cp1252 but lacks a 
correct encoding declaration, it is not valid XML because the Cp1252 
characters are not valid UTF-8.

Try including the line

or


as the first line of the XML. (windows-1252 is the official 
IANA-registered name for Cp1252; I'm not sure which name will actually 
work correctly.)

Kent

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


Re: [Tutor] Help me to debug this script .. I tried but ....

2006-11-05 Thread Dustin J. Mitchell
Asrarahmed Kadri wrote:
> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
> line 310, in RunScript
> exec codeObject in __main__.__dict__
>   File "C:\project stuff-programs\Scriptdate.py", line 18, in ?
> t1 = my_version_datecheck.dateCheck(dt1,0)
>   File "my_version_datecheck.py", line 38, in dateCheck
> import traceback
> NameError: global name 'traceback' is not defined

This tells you everything you need to know right here.

What version of Python are you using?  I know traceback existed at least in
2.3.  Might be time to consider an upgrade.

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


[Tutor] Two Questions...(i) Checking for None (ii) Making

2006-11-05 Thread Greg Lindstrom
Date: Sat, 4 Nov 2006 10:36:58 +From: "Asrarahmed Kadri" <
[EMAIL PROTECTED]>Hi Folks,I am trying to build a program which takes the following command-line
arguments:   *-s  -D  -n  -t   time>*the first argument which is -s (for source) can be replaced by -d (fordestination) or -o (for observer) or -r (for reporter). Now what I want is
to make sure that the user only supplies one of the options from the 4alternatives.I am using 'optparse' module. It has got a nice feature taht enables you togive the option name, along with the variable-name to store the value of
that option. The syntax is as under:if you import sys you can use sys.argv to look at a list of all the command line arguments (including the programs filename).  You should be able to determine if you have duplicate flags ('-s','-d',etc).
hth--greg
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me to debug this script .. I tried but ....

2006-11-05 Thread Kent Johnson
Dustin J. Mitchell wrote:
> Asrarahmed Kadri wrote:
>> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
>> line 310, in RunScript
>> exec codeObject in __main__.__dict__
>>   File "C:\project stuff-programs\Scriptdate.py", line 18, in ?
>> t1 = my_version_datecheck.dateCheck(dt1,0)
>>   File "my_version_datecheck.py", line 38, in dateCheck
>> import traceback
>> NameError: global name 'traceback' is not defined
> 
> This tells you everything you need to know right here.
> 
> What version of Python are you using?  I know traceback existed at least in
> 2.3.  Might be time to consider an upgrade.

If traceback was not a valid module name the import would raise 
ImportError, not NameError.

Something strange is going on here; have you shown us all the code?

Kent

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


Re: [Tutor] Encoding and XML troubles

2006-11-05 Thread Dustin J. Mitchell
For what it's worth, the vast majority of the XML out there (especially if
you're parsing RSS feeds, etc.) is written by monkeys and is totally
ill-formed.  It seems the days of 'it looked OK in my browser' are still here.

To find out if it's your app or the XML, you could try running the XML through
a validating parser.  There are also various tools out there which might be
able to parse the XML anyway -- xmllint, I believe, can do this.

Dustin (not by *any* stretch an expert on XML *or* Unicode)
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me to debug this script .. I tried but ....

2006-11-05 Thread Dustin J. Mitchell
Kent Johnson wrote:
> Dustin J. Mitchell wrote:
>> Asrarahmed Kadri wrote:
>>> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
>>> line 310, in RunScript
>>> exec codeObject in __main__.__dict__
>>>   File "C:\project stuff-programs\Scriptdate.py", line 18, in ?
>>> t1 = my_version_datecheck.dateCheck(dt1,0)
>>>   File "my_version_datecheck.py", line 38, in dateCheck
>>> import traceback
>>> NameError: global name 'traceback' is not defined
>> This tells you everything you need to know right here.
>>
>> What version of Python are you using?  I know traceback existed at least in
>> 2.3.  Might be time to consider an upgrade.
> 
> If traceback was not a valid module name the import would raise 
> ImportError, not NameError.
> 
> Something strange is going on here; have you shown us all the code?

Python caches the text of programs, and will show that in later tracebacks.
Try restarting your IDE and running the script again, or look on line 38 of
my_version_datecheck.py -- I bet it doesn't say "import traceback".

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


Re: [Tutor] Help me to debug this script .. I tried but ....

2006-11-05 Thread Asrarahmed Kadri
When I am running the script from the command line, its working fine but when I am trying to run from Pythonwin, its giving me error.
 
Can anyone explain the reason?
 
Regards,
Asrarahmed 
On 11/5/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
Dustin J. Mitchell wrote:> Asrarahmed Kadri wrote:>> "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
>> line 310, in RunScript>> exec codeObject in __main__.__dict__>>   File "C:\project stuff-programs\Scriptdate.py", line 18, in ?>> t1 = my_version_datecheck.dateCheck(dt1,0)
>>   File "my_version_datecheck.py", line 38, in dateCheck>> import traceback>> NameError: global name 'traceback' is not defined>> This tells you everything you need to know right here.
>> What version of Python are you using?  I know traceback existed at least in> 2.3.  Might be time to consider an upgrade.If traceback was not a valid module name the import would raiseImportError, not NameError.
Something strange is going on here; have you shown us all the code?Kent___Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor-- To HIM you shall return. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help me to debug this script .. I tried but ....

2006-11-05 Thread Danny Yoo
On Sun, 5 Nov 2006, Asrarahmed Kadri wrote:

> When I am running the script from the command line, its working fine but
> when I am trying to run from Pythonwin, its giving me error.
>
> Can anyone explain the reason?

Hi Asrarahmed,


Did you see Kent's reply?  He mentioned:

>> Something strange is going on here; have you shown us all the code?


I agree with Kent.  I suspect something very funky is going on here, 
especially since the error message says that you're doing an 'import 
traceback' within a function called dateCheck().  That's highly unusual: 
people usually put their imports at the top level.  The error message 
that's coming out has hints of weirdness in it:


>> >>   File "C:\project stuff-programs\Scriptdate.py", line 18, in ?
>> >> t1 = my_version_datecheck.dateCheck(dt1,0)
>> >>   File "my_version_datecheck.py", line 38, in dateCheck
>> >> import traceback
>> >> NameError: global name 'traceback' is not defined

Why would the code try to do an import on line 38?  That's way deep in the 
middle of your program.  Very strange.  The most likely thing that's going 
on, given the information so far, is that the line numbers are wrong, and 
that 'my_version_datecheck' has been changed while the program is running.


We don't have enough information to duplicate your error yet. So please 
show us your 'my_version_datecheck.py'.  Otherwise, we really can't do 
much else except guess at the problem.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Amazing power of Regular Expressions...

2006-11-05 Thread Michael Sparks
On Sunday 05 November 2006 15:02, Kent Johnson wrote:
...
> Regular expressions are an extremely powerful and useful tool that every
> programmer should master and then put away and not use when there is an
> alternative :-)



There's always an alternative to a regular expression, so are you really 
suggesting *never* use a regex? (seriously though, I doubt you are, but taken 
in this context, that's how it looks).

The most pathological example of regex avoidance I've seen in a while
is this:

def isPlain(text):
plaindict = {'-': True, '.': True, '1': True, '0': True, '3': True, 
  '2': True, '5': True, '4': True, '7': True, '6': True, '9': True,
  '8': True, 'A': True, 'C': True, 'B': True, 'E': True, 'D': True,
  'G': True, 'F': True, 'I': True, 'H': True, 'K': True, 'J': True,
  'M': True, 'L': True, 'O': True, 'N': True, 'Q': True, 'P': True,
  'S': True, 'R': True, 'U': True, 'T': True, 'W': True, 'V': True,
  'Y': True, 'X': True, 'Z': True, '_': True, 'a': True, 'c': True,
  'b': True, 'e': True, 'd': True, 'g': True, 'f': True, 'i': True,
  'h': True, 'k': True, 'j': True, 'm': True, 'l': True, 'o': True,
  'n': True, 'q': True, 'p': True, 's': True, 'r': True, 'u': True,
  't': True, 'w': True, 'v': True, 'y': True, 'x': True, 'z': True}

for c in text:
if plaindict.get(c, False) == False:
return False
return True

(sadly this is from real code - in defence of the person
 who wrote it, they weren't even *aware* of regexes)

That's equivalent to the regular expression:
* ^[0-9A-Za-z_.-]*$

Now, which is clearer? If you learn to read & write regular expressions, then 
the short regular expression is the clearest form. It's also quicker.

I'm not someone who advocates coding-by-regex, as happens rather heavily in 
perl (I like perl about as much as python), but to say "don't use them if 
there's an alternative" is a little strong. Aside from the argument that "you 
now have two problems" (which always applies if you think all problems can be 
hit with the same hammer), solving *everything* with regex is often slower. 
(since people then do one after another, after another - the most 
pathological example I've seen applied over 1000 regexes to a piece
of text, one after another, and then the author wondered why their
code was slow...)

JWZ's quote is more aimed at people who think about solving every problem with 
regexes (and where you end up with 10 line monstrosities in perl with 5 
levels of backtracking).

Also, it's worth bearing in mind that there's more than one definition of what 
regex's are (awk, perl, python, and various C libraries all have slightly 
differing rules and syntax, even if they often share a common base). Rather 
than say there's one true way, it's worth bearing in mind that regexes are 
little more than a shorthand for structured parsing, and bearing this in 
mind, then it's worth recasting JWZ's point as:

If your reaction to seeing a problem is "this looks like it can be solved 
using a regex", you should think to yourself: has someone else already hit 
this problem and have they come up with a specialised pattern matcher for it 
already? If not, why not? 

In this case that *should* have led the poster to the discovery of the
specialised parser:
 time.strptime(date, '%d/%m/%Y')

File globs are another good example of a specialised form of pattern matcher.

Using a regex when it's appropriate is good. Finding a more appropriate 
specialised pattern matcher? Even better. Avoiding using regexes in the way 
I've shown above, because it's an alternative to using a regex? Bad, it's 
slow and unclear.

:-)


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


Re: [Tutor] Amazing power of Regular Expressions...

2006-11-05 Thread Kent Johnson
Michael Sparks wrote:
> On Sunday 05 November 2006 15:02, Kent Johnson wrote:
> ...
>> Regular expressions are an extremely powerful and useful tool that every
>> programmer should master and then put away and not use when there is an
>> alternative :-)
> 
> 
> 
> There's always an alternative to a regular expression, so are you really 
> suggesting *never* use a regex? (seriously though, I doubt you are, but taken 
> in this context, that's how it looks).

OK, maybe a bit overstated. I use regexes regularly ;) and as I wrote I 
think every programmer should know how to use them.

Kent

> 
> The most pathological example of regex avoidance I've seen in a while
> is this:
> 
> def isPlain(text):
> plaindict = {'-': True, '.': True, '1': True, '0': True, '3': True, 
>   '2': True, '5': True, '4': True, '7': True, '6': True, '9': True,
>   '8': True, 'A': True, 'C': True, 'B': True, 'E': True, 'D': True,
>   'G': True, 'F': True, 'I': True, 'H': True, 'K': True, 'J': True,
>   'M': True, 'L': True, 'O': True, 'N': True, 'Q': True, 'P': True,
>   'S': True, 'R': True, 'U': True, 'T': True, 'W': True, 'V': True,
>   'Y': True, 'X': True, 'Z': True, '_': True, 'a': True, 'c': True,
>   'b': True, 'e': True, 'd': True, 'g': True, 'f': True, 'i': True,
>   'h': True, 'k': True, 'j': True, 'm': True, 'l': True, 'o': True,
>   'n': True, 'q': True, 'p': True, 's': True, 'r': True, 'u': True,
>   't': True, 'w': True, 'v': True, 'y': True, 'x': True, 'z': True}
> 
> for c in text:
> if plaindict.get(c, False) == False:
> return False
> return True
> 
> (sadly this is from real code - in defence of the person
>  who wrote it, they weren't even *aware* of regexes)
> 
> That's equivalent to the regular expression:
> * ^[0-9A-Za-z_.-]*$
> 
> Now, which is clearer? If you learn to read & write regular expressions, then 
> the short regular expression is the clearest form. It's also quicker.
> 
> I'm not someone who advocates coding-by-regex, as happens rather heavily in 
> perl (I like perl about as much as python), but to say "don't use them if 
> there's an alternative" is a little strong. Aside from the argument that "you 
> now have two problems" (which always applies if you think all problems can be 
> hit with the same hammer), solving *everything* with regex is often slower. 
> (since people then do one after another, after another - the most 
> pathological example I've seen applied over 1000 regexes to a piece
> of text, one after another, and then the author wondered why their
> code was slow...)
> 
> JWZ's quote is more aimed at people who think about solving every problem 
> with 
> regexes (and where you end up with 10 line monstrosities in perl with 5 
> levels of backtracking).
> 
> Also, it's worth bearing in mind that there's more than one definition of 
> what 
> regex's are (awk, perl, python, and various C libraries all have slightly 
> differing rules and syntax, even if they often share a common base). Rather 
> than say there's one true way, it's worth bearing in mind that regexes are 
> little more than a shorthand for structured parsing, and bearing this in 
> mind, then it's worth recasting JWZ's point as:
> 
> If your reaction to seeing a problem is "this looks like it can be solved 
> using a regex", you should think to yourself: has someone else already hit 
> this problem and have they come up with a specialised pattern matcher for it 
> already? If not, why not? 
> 
> In this case that *should* have led the poster to the discovery of the
> specialised parser:
>  time.strptime(date, '%d/%m/%Y')
> 
> File globs are another good example of a specialised form of pattern matcher.
> 
> Using a regex when it's appropriate is good. Finding a more appropriate 
> specialised pattern matcher? Even better. Avoiding using regexes in the way 
> I've shown above, because it's an alternative to using a regex? Bad, it's 
> slow and unclear.
> 
> :-)
> 
> 
> Michael.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> 


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


[Tutor] GUI with Designer

2006-11-05 Thread Jonathon Sisson
Wow...

SPE is in the Gentoo repository as well.  I've been looking for 
something to replace Eric, so thanks for the tip, Chris!  I'll check it out.

Jonathon


Chris Hengge wrote:
> Well, I use SPE which comes with wxGlade and XRC. For the small amount 
> of gui I've done with python I think SPE offers the best IDE coder 
> experience (coming from a VS world). The tools make sense to me.
> 
> wxGlade is a GUI designer written in Python with the popular GUI toolkit 
> wxPython , that helps you create 
> wxWidgets/wxPython user interfaces. At the moment it can generate 
> Python, C++, Perl and XRC (wxWidgets' XML resources) code.
> 
> XRC(wxWidgets' XML resources) is nice because it allows you to abstract 
> your interface design (think of any program that uses XML to format skins).
> 
> Overall, I think everyone using python should give SPE a try, even 
> without gui programming its a great tool for writing code. It's free, 
> and written in python using wxPython.. Stani (the Dev) is a great person 
> for helping out with questions on using his package, he puts out regular 
> updates and fixes. He's got some help from a few other people so its 
> packaged in .exe, .rpm and standalone .zip formats. It's also on the 
> standard repo's for Ubuntu.
> 
> If you like it, be kind and toss the guy a few bucks for his efforts. If 
> you do, you will get your name mentioned on the SPE news page and get a 
> nice copy of his user manual (pdf).
> 
> If you want to know more about SPE, check out:
> http://www.serpia.org/spe
> or video demonstations at:
> http://showmedo.com/videos/series?name=PythonDevelopmentWithSPE 
> 
> 
> On 11/3/06, *Dick Moores* <[EMAIL PROTECTED] > 
> wrote:
> 
> At 02:10 PM 11/3/2006, Chris Hengge wrote:
>> I vouch for the SPE with wxGlade and XRC! (packaged together with IDE)
> 
> I'd be very interested in hearing why you suggest that combination.
> 
> Dick Moores
> 
> 
>> On 11/3/06, *Carlos Daniel Ruvalcaba Valenzuela* <
>> [EMAIL PROTECTED] > wrote:
>>
>> wxPython is good for cross-platform stuff and has a few gui
>> designers
>> (Boa Constructor and others comes to mind), I don't know much
>> about
>> PyQT state in this, but PyGtk + Glade (Gui Designer) is a very
>> good
>> combo.
>>
>> Is about choise, I suggest you to do some simple tests with
>> everything
>> until you find something to be confortable with.
>>
>> * PyGtk + Glade
>> * Boa Contructor
>> * SPE + wxPython
>>
>> On 11/3/06, Todd Dahl <[EMAIL PROTECTED]
>> > wrote:
>> > I am wanting to get into some GUI coding with Python and have
>> heard about
>> > PyQT and wxPython. Now I am definately not looking for some
>> type of holy war
>> > but can anyone give me a good reason to pick one over the other.
>> >
>> > Also I would like to have a designer with it or a seperate
>> designer that
>> > could be used with either. I plan on coding in Windows XP.
>> >
>> > Thanks,
>> >
>> > -Todd
>> >
>> > ___
>> > Tutor maillist  -  Tutor@python.org 
>> > http://mail.python.org/mailman/listinfo/tutor
>> >
>> >
>> >
>> ___
>> Tutor maillist  -  Tutor@python.org 
>> http://mail.python.org/mailman/listinfo/tutor
>> 
>>
>>
>> ___
>> Tutor maillist  -  Tutor@python.org 
>> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 
> 
> 
> ___
> 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] shebang problem

2006-11-05 Thread Brian van den Broek
Alan Gauld said unto the world upon 11/04/2006 06:47 PM:
> [EMAIL PROTECTED]:~/test$ ls -la shebangtest.py
> -rwxr-xr-- 1 brian brian 68 2006-11-04 02:29 shebangtest.py
> 
> so the file is called shebangtest.py...
> 
>> [EMAIL PROTECTED]:~/test$ shebangtest
>> bash: shebangtest: command not found
> 
> but you try to run shebangtest...
> 
> bash can't find the file. you didn't put the .py on the end


Well, shebangtest.py also didn't work as evidenced by one of the lines 
you snipped.

> Also you may not have . in your path. For security reasons it isn't 
> there by default.
> 
> Try
> 
> [EMAIL PROTECTED]:~/test$ ./shebangtest.py

And that would be it.

It didn't occur to me to try ./shebangtest.py in lieu of the bare 
shebangtest.py. My command-line instinct were installed back in the 
days of using DOS on an XT. DOS (at least the version I used) first 
checked the cwd and only then searched the path. The security 
implications that Alan and Rick pointed to make the POSIX/bash 
behaviour make perfect sense on reflection, though.

Thanks to all who replied, both on and off list,

Brian vdB

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


Re: [Tutor] Amazing power of Regular Expressions...

2006-11-05 Thread Alan Gauld

"Michael Sparks" <[EMAIL PROTECTED]> wrote

> The most pathological example of regex avoidance I've seen in a 
> while
> is this:
>
> def isPlain(text):
>plaindict = {'-': True, '.': True, '1': True, '0': True, '3': 
> True,
>  '2': True, '5': True, '4': True, '7': True, '6': True, '9': 
> True,
>  '8': True, 'A': True, 'C': True, 'B': True, 'E': True, 'D': 
> True,
>  'G': True, 'F': True, 'I': True, 'H': True, 'K': True, 'J': 
> True,
>  'M': True, 'L': True, 'O': True, 'N': True, 'Q': True, 'P': 
> True,
>  'S': True, 'R': True, 'U': True, 'T': True, 'W': True, 'V': 
> True,
>  'Y': True, 'X': True, 'Z': True, '_': True, 'a': True, 'c': 
> True,
>  'b': True, 'e': True, 'd': True, 'g': True, 'f': True, 'i': 
> True,
>  'h': True, 'k': True, 'j': True, 'm': True, 'l': True, 'o': 
> True,
>  'n': True, 'q': True, 'p': True, 's': True, 'r': True, 'u': 
> True,
>  't': True, 'w': True, 'v': True, 'y': True, 'x': True, 'z': 
> True}
>
>for c in text:
>if plaindict.get(c, False) == False:
>return False
>return True
>
> (sadly this is from real code - in defence of the person
> who wrote it, they weren't even *aware* of regexes)
>
> That's equivalent to the regular expression:
>* ^[0-9A-Za-z_.-]*$

While using a dictionary is probably overkill, so is a regex.
A simple string holding all characters and an 'in' test would probably
be both easier to read and faster. Which kind of illustrates the
point of the thread I think! :-)

> Now, which is clearer? If you learn to read & write regular 
> expressions, then
> the short regular expression is the clearest form. It's also 
> quicker.

Whether its quicker will depend on several factors including the
implementation of the regex library as well as the length of the 
string.
If its a single char I'd expect the dictionary lookup to be faster 
than
a regex parse or the string inclusion test... In fact this is how the
C standard library usually implements functions like toupper()
and tolower() etc, and for speed reasons.

> to say "don't use them if there's an alternative" is a little 
> strong.
> Aside from the argument that "you now have two problems"
> (which always applies if you think all problems can be hit with
> the same hammer), solving *everything* with regex is often slower.

regex can be faster than a sequential string search. It depends on
the problem.

The thing that we are all trying to say here (I think) is that regex
are powerful tools but dangerously complex. Its nearly always
safer and easier to use alternatives where they exist, but when
used intelligently they can solve difficult problems very elegantly.

> JWZ's quote is more aimed at people who think about solving
> every problem with regexes (and where you end up with 10 line
> monstrosities in perl with 5 levels of backtracking).

Agreed and thats what the message of the thread is about.
Use them ewhen they are the right solution, but look for
altrernatives first.

> Also, it's worth bearing in mind that there's more than one 
> definition of what
> regex's are

To be picky, there is only one definition of what regexd are,
but there are many grammars or dialects.

> If your reaction to seeing a problem is "this looks like it can be 
> solved
> using a regex", you should think to yourself: has someone else 
> already hit
> this problem and have they come up with a specialised pattern 
> matcher for it
> already? If not, why not?

Absolutely agree with this.

> :-)

Likewise :-)

Alan g. 


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