RE: Is there a better way of listing Windows shares other than us ing "os.listdir"

2004-12-31 Thread Doran_Dermot
Hi David,

Thanks for the bit of code on finding shares!  I'd been using something a
bit different (win32com.client stuff) but your code looks better. 

I've found that "win32file.FindFilesIterator" (suggested to me by another
person on this mailing list) allows the gui to remain responsive. Using the
same code to execute the "os.listdir" hangs the gui!

I've been using the wx.PostEvent and Python threading objects to implement
multi-threading. Works very well!  The wxPython demo illustrates the use of
wx.PostEvent and Python multi-threading extremely well.

Thanks again for your help!

Dermot.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
David Bolen
Sent: 30 December 2004 17:39
To: python-list@python.org
Subject: Re: Is there a better way of listing Windows shares other than
using "os.listdir"

[EMAIL PROTECTED] writes:

> I'm currently using "os.listdir" to obtain the contents of some slow
Windows
> shares.  I think I've seen another way of doing this using the win32
library
> but I can't find the example anymore.

Do you want the list of files on the shares or the list of shares
itself?  If the files, you can use something like FindFiles, but I
don't expect it to be that much faster just to obtain directory names
(likely the overhead is on the network).

If you just want a list of shares, you could use NetUseEnum, which
should be pretty speedy.

(FindFiles is wrapped by win32api, and NetUseEnum by win32net, both parts
 of the pywin32 package)

Here's a short example of displaying equivalent output to the "net
use" command:

  - - - - - - - - - - - - - - - - - - - - - - - - -
import win32net

status = {0 : 'Ok',
  1 : 'Paused',
  2 : 'Disconnected',
  3 : 'Network Error',
  4 : 'Connected',
  5 : 'Reconnected'}

resume = 0
while 1:
(results, total, resume) = win32net.NetUseEnum(None, 1, resume)
for use in results:
print '%-15s %-5s %s' % (status.get(use['status'], 'Unknown'),
 use['local'],
 use['remote'])
if not resume:
break
  - - - - - - - - - - - - - - - - - - - - - - - - -

Details on the the arguments to NetUseEnum can be found in MSDN (with
any pywin32 specifics in the pywin32 documentation).

> My main problem with using "os.listdir" is that it hangs my gui
application.
> The tread running the "os.listdir" appears to block all other threads when
> it calls this function.

Yes, for a GUI you need to keep your main GUI thread always responsive
(e.g., don't do any blocking operations).

There are a number of alternatives to handling a long processing task
in a GUI application, dependent on both the operation and toolkit in
use.  For wxPython, http://wiki.wxpython.org/index.cgi/LongRunningTasks
covers several of the options (and the theory behind them is generally
portable to other toolkits although implementation will change).

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


RE: Is there a better way of listing Windows shares other than us ing "os.listdir"

2004-12-30 Thread Doran_Dermot
Hi Tim,

That does the trick!  Now my gui remains responsive during the long search
time. 

Thanks!

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Tim Golden
Sent: 30 December 2004 10:54
To: python-list@python.org
Subject: RE: Is there a better way of listing Windows shares other than us
ing "os.listdir"

[EMAIL PROTECTED]

| I'm currently using "os.listdir" to obtain the contents of 
| some slow Windows shares.  I think I've seen another way of 
| doing this using the win32 library but I can't find the 
| example anymore.

It may be FindFilesIterator, recently added to the win32file
module in pywin32. I don't know if it's any more efficient
than an os.listdir (which may use it under the covers, for
all I know) but it certainly works:


import win32file

for file_data in win32file.FindFilesIterator ("c:/temp/*"):
  ( attr, ctime, atime, wtime, 
size_hi, size_lo, r0, r1, 
longname, shortname
  ) = file_data
  print longname


TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Is there a better way of listing Windows shares other than using "os.listdir"

2004-12-30 Thread Doran_Dermot
Hi All,

I'm currently using "os.listdir" to obtain the contents of some slow Windows
shares.  I think I've seen another way of doing this using the win32 library
but I can't find the example anymore.

My main problem with using "os.listdir" is that it hangs my gui application.
The tread running the "os.listdir" appears to block all other threads when
it calls this function.

Any ideas, comments or suggestions?

Thanks in advance,

Dermot.

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


RE: Cool object trick

2004-12-16 Thread Doran_Dermot
I rather like it!  I prefer writing obj.spam to obj["spam"]!  I wonder if
there is a technical downside to this use of Python?

P.S.

Certainly makes writing 'print obj.spam, obj.spam, obj.eggs, obj.bacon,
obj.sausages, "and", obj.spam' a lot easier ;-)

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Jive
Sent: 17 December 2004 06:29
To: [EMAIL PROTECTED]
Subject: Re: Cool object trick

Kinda cool.

It's occured to me that just about everything Pythonic can be done with
dicts and functions.  Your Obj is just a dict with an alternate syntax.  You
don't have to put quotes around the keys.  But that's cool.


class struct(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)

# Indented this way, it looks like a struct:
obj = struct(  saying = "Nee"
   , something = "different"
   , spam = "eggs"
  )

print obj.spam

# Is that really much different from this?

obj2 = { "saying" : "Nee"
, "something" : "different"
, "spam" : "eggs"
   }

print obj2["spam"]


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


RE: KeyError

2004-12-16 Thread Doran_Dermot
If a default value would be acceptable to the application (which is quite
likely), then this would be a much cleaner solution.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Roland Heiber
Sent: 16 December 2004 10:28
To: [EMAIL PROTECTED]
Subject: Re: KeyError

[EMAIL PROTECTED] wrote:
> Hi "R",
> 
> The only explanation I can give is that the environment varialbe
REMOTE_ADDR
> does not exist!  Wrap your high-level code with try and except. Example:
> try:
>  tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']
> except KeyError:
>   # Code to  handle the fact tht REMOT_ADDR does not exist. 

... or just replace os.environ['REMOTE_ADDR'] with 
os.environ.get('REMOTE_ADDR', 'enter_default_here') to use a default in 
case of missing REMOTE_ADDR ...

HtH, Roland
-- 
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: AsmL/Python relationship? Anyone using AsmL? What for?

2004-12-15 Thread Doran_Dermot
Hi Claudio,

If I recall correctly Guido van Rossum (creator/father of Python) did not
mention AsmL as being an influence.  Also AsmL appears to be more recent
(circa .NET epoch) than Python (circa 1991). Hence, I would suggest that the
Foundations of Software Engineering group at Microsoft have borrowed a few
bricks from Guido and maybe even a few rocks from Donald Knuth.

Interesting (AsmL, that is, not my posting).

Cheers!!



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Claudio Grondi
Sent: 15 December 2004 15:53
To: [EMAIL PROTECTED]
Subject: AsmL/Python relationship? Anyone using AsmL? What for?

Hi,

I have just by chance discovered, that Microsoft research
works on a kind of programming language called AsmL,
and I'm just curious if AsmL, which is using same concept
of significant indentation as Python language, was
developed fully independently or is there a kind of
relationship (same person in developer team, etc.)?
Maybe someone can give here some hints?

Is anyone of you using AsmL? What for?

Claudio
P.S. What is AsmL can be checked out at:
http://research.microsoft.com/fse/asml/
or directly in the tutorial:
http://research.microsoft.com/fse/asml/doc/AsmL2_Tutorial.doc

Here an excerpt from online available information:
"AsmL is the Abstract State Machine Language.
It is an executable specification language based on
the theory of Abstract State Machines.
The current version, AsmL 2 (AsmL for Microsoft .NET),
is embedded into Microsoft Word and Microsoft Visual
Studio.NET. It uses XML and Word for
literate specifications. It is fully interoperable with
other .NET languages.
AsmL generates .NET assemblies which can either
be executed from the command line, linked with
other .NET assemblies, or packaged as COM
components.
AsmL is useful in any situation where you need
a precise, non-ambiguous way to specify a computer
system, either software or hardware. AsmL
specifications are an ideal way for teams to
communicate design decisions.
Program managers, developers, and testers can
all use an AsmL specification to achieve a
single, unified understanding. One of the greatest
benefits of an AsmL specification is that you can
execute it. That means it is useful before you commit
yourself to coding the entire system."


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


RE: Import trouble

2004-12-15 Thread Doran_Dermot
Hi Craig,

How about creating your own module that does this in  __init__.py.

You could create a directory (Eg craig_init) and in that directory create
the file __init__.py containing the following code:

try: import libxml
except: 
  # Blah, blah, blah. A clever bit of code goes here!

WARNING: I haven't checked this myself, but it appears to be the way that
the Zope Database python code has been written.  If you have the ZODB
package installed take a look at "Lib\site-packages\Btrees\__init__.py".
I'm sure there must be other examples of this as well. 

Cheers!!

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Craig Ringer
Sent: 15 December 2004 13:45
To: Frans Englich
Cc: Python mailing list
Subject: Re: Import trouble

On Wed, 2004-12-15 at 21:45, Frans Englich wrote:

> 2) I use Python modules which are not usually installed(libxml2/libxslt)
and 
> want to fail gracefully in case the modules aren't available; print an 
> informative message. Since these imports are done in several related 
> programs, I don't want to duplicate the code, but instead centralize it.
The 
> problem is that when I put the module imports/exception code in a
function, 
> it is as if it wasn't imported, even though there was no exceptions. I 
> suspect this is because the import is only done into the current
namespace: 
> the function scope(instead of file scope as I want). Is there any solution
to 
> my problem? Or should I solve it in another way?

def import_xml:
   try:   
   import libxml
   except ImportError,err:
   # handle the error
   return libxml

libxml = import_xml()


--
Craig Ringer

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


RE: KeyError

2004-12-15 Thread Doran_Dermot
Hi "R",

The only explanation I can give is that the environment varialbe REMOTE_ADDR
does not exist!  Wrap your high-level code with try and except. Example:
try:
 tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']
except KeyError:
  # Code to  handle the fact tht REMOT_ADDR does not exist. 

Hope that this helps and is not just another infamous "Dermot Didn't Get It"
posting!

Cheers!!

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: 15 December 2004 13:34
To: [EMAIL PROTECTED]
Subject: KeyError

Hello.
Maybe someone will help me with this KeyError:


Traceback (most recent call last):
  File "C:\Python\tabla.py", line 929, in -toplevel-
tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']
  File "C:\Python23\lib\os.py", line 417, in __getitem__
return self.data[key.upper()]
KeyError: 'REMOTE_ADDR'
.. 


Thanks for reading this.
R.



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


RE: Python IDE

2004-12-14 Thread Doran_Dermot
If you want to spend the $35 I can recommend WingIDE. 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Chris
Sent: 14 December 2004 16:37
To: [EMAIL PROTECTED]
Subject: Python IDE

What IDE's do y'all recommend for Python?  I'm using PythonWin atm, but 
I'd like something with more functionality.

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


RE: Python mascot proposal

2004-12-14 Thread Doran_Dermot
Here are my suggestions:
1. A "larch" (nice play on early Java)
2. Shoebox in middle o' road! (totally meaningless)
3. A Python sitting in a comfy chair (indicating ease-of-use)
4. A "larch"

All very Pythonic and non-controversial (unless you're a member of the
"Prevention of Cruelty to Shoeboxes Society").

P.S.

Anybody know what a larch looks like?

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Andrew Robert
Sent: 14 December 2004 10:37
To: [EMAIL PROTECTED]
Subject: Re: Python mascot proposal


What about a dead camel?
-- 
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: How did you learn Python?

2004-12-03 Thread Doran_Dermot
Hi Shawn,

I would recommend the following for starters:
- The Tutorial (http://www.python.org/dev/doc/devel/tut/tut.html)
- Python "How to Program" by Deitel 

After that it is like any language, natural or computer related!  Use it!

However, I think you'll find that it is a lot easier to use than most other
languages.

Cheers!!

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Shawn Milo
Sent: 03 December 2004 14:55
To: [EMAIL PROTECTED]
Subject: How did you learn Python?

I was just wondering what the best books were for learning Python.

Which books are good for getting started, and which should be saved for
later, or or not useful except as a reference for the learned?

I have a decent programming background in VB, JavaScript, VBScript,
Net.Data (IBM's macro language), regular expressions, and a teensy bit of
Perl. My point is, I don't want something that is going to explain the basic
programming concepts, but does give a good introduction to Python-specific
things. Then, once I know how to get the job done, I would like a good book 
or two at the intermediate to advanced level, to learn how to write really
good code.

I understand that resources such as this list and Google searches have all
the answers,
but it seems like a more structured tool, such as a book or formal class,
would be
of great benefit to me. The other languages I have used were picked up
because of the
need to get a job done. As a result, I am able to get the job done, but any
experienced
coder can show me six more efficient ways to do what I'm doing. I'm new to
Python, and I want to do this one right. I believe that Python will be
around for a good, long time, and it matches my values as an
Open-Source/Linux
supporter, while having relevance in the Windows and Mac world, as well. 
Plus, it looks like it was designed extremely well, and I'm excited about
the 
principles I've read about.

Thanks,
Shawn
-- 
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Regular Expression Problem...

2004-12-01 Thread Doran_Dermot
You could try the following:
regex = re.compile("[\$]\w+", re.IGNORECASE)

I've only done a bit of testing.  Maybe somebody has a better solution.

Cheers!!

Dermot. 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: 01 December 2004 12:23
To: [EMAIL PROTECTED]
Subject: Regular Expression Problem...

Hello NG,

 I am quite new with Python... I'm writing an application that does
also some regexp things on strings, but I'm having problem about
identifying/extracting a substring from another string. What I have to do
is to extract all the strings that begins with a "$" character, but
excluding characters like "." (point) and "'" (single quote) and "\" "/"
(slashes). For example I have:

1) This Is An $EXAMPLE String
2) This Is An $EXAMPLE.String
3) 'This Is An $EXAMPLE'
4) This Is An \$EXAMPLE\String;

I would like to extract only the "keyword" $EXAMPLE and what I'm using at
the moment is:

#CODE BEGIN
import re

mystring = "This Is An \$EXAMPLE\String;"
regex = re.compile("[\$]+\S*",re.IGNORECASE)
keys = regex.findall(mystring)

#CODE END

Obviously this code returns things like $EXAMPLE', $EXAMPLE/, $EXAMPLE. and
so on...
Does anyone have a suggestion?

Thank you a lot.

Andrea.


--

Message for the recipient only, if received in error, please notify the
sender and read http://www.eni.it/disclaimer/

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