Re: Wrapping classes

2005-09-22 Thread Peter Hansen
Jeremy Sanders wrote:
> Is it possible to implement some sort of "lazy" creation of objects only
> when the object is used, but behaving in the same way as the object?
> 
> For instance:
> 
> class Foo:
>   def __init__(self, val):
> """This is really slow."""
> self.num = val
> 
> # this doesn't call Foo.__init__ yet
> a = lazyclass(Foo, 6)
> 
> # Foo is only initalised here
> print a.num
> 
> What I really want to do is make an object which looks like a numarray,
> but only computes its contents the first time it is used.

Almost anything is possible in Python, though whether the underlying 
design idea is sound is a completely different question.  (Translation: 
try the following pseudo-code, but I have my suspicions about whether 
what you're doing is a good idea. :-) )

class lazyclass(object):
 '''should probably be called lazyobject though...'''
 def __init__(self, class_, *args, **kwargs):
 self.class_ = class_
 self.args = args
 self.kwargs = kwargs
 self.obj = None

 def _getnum(self):
 if self.obj is None:
 self.obj = self.class_(*args, **kwargs)
 return self.obj.num
 num = property(_getnum)

Now that "should" do precisely what you've asked for above, though it is 
obviously very limited in supporting only a single attribute name even 
though the __init__ method is somewhat generalized.  I didn't try 
testing the code so there could be typos.

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


Re: in-memory db? gadfly?

2005-09-22 Thread Peter Hansen
chris wrote:
> I'm looking for a completely in-memory sql db.  I have seen gadfly, but
> its startup method seems to require a directory for the on-disk file
> storage.  I have a script and I want to create a database/tables in the
> script, insert some data (not much), and execute some queries, all
> in-memory.  Don't need to persist anything.  Possible, or am I just
> talking crazy here?

I believe SQLite will do this easily, if you use a connection name of 
":memory:" instead of a file name.

Wrapped with either of:

  - Gerhard Häring's pysqlite (http://initd.org/tracker/pysqlite)

  - Roger Binns' APSW (http://www.rogerbinns.com/apsw.html)

I believe the primary distinction is that pysqlite is DB-API 2.0 
compliant, while APSW is a "thin" wrapper that may or may not feel more 
comfortable for you, and which provides access to more of SQLite's 
features.

(Both appear to have been around roughly the same length of time, though 
pysqlite seems better known.)

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


Re: Alternatives to Stackless Python?

2005-09-22 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
>>I found LGT http://lgt.berlios.de/ but it didn't seem as if the
>>NanoThreads module had the same capabilites as stackless.
> 
> What specific capabilities of Stackless are you looking for, that are
> missing from NanoThreads?

While I can't speak for the OP, isn't it the case that the threadlets in 
Stackless (sorry, don't know what they are really called) are true 
threads in the sense of being able to switch contexts no matter how far 
down in a set of nested calls they might be?  And that NanoThreads are 
simply generators, which means you can switch contexts only at the top 
level, with a yield statement?

I don't know what the OP wants, but I could imagine that would be a 
pretty fundamental difference (if I'm right about Stackless).

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


Re: File processing

2005-09-23 Thread Peter Hansen
Gopal wrote:
> Hello,
> 
> I'm Gopal. I'm looking for a solution to the following problem:
> 
> I need to create a text file config.txt having some parameters. I'm
> thinking of going with this format by having "Param Name - value". Note
> that the value is a string/number; something like this:
> 
> PROJECT_ID = "E4208506"
> SW_VERSION = "18d"
> HW_VERSION = "2"
> 
> In my script, I need to parse this config file and extract the Values
> of the parameters.
> 
> I'm very new to python as you can understand from the problem. However,
> I've some project dealines. So I need your help in arriving at a simple
> and ready-made solution.

Luckily, you're already done!  Just make sure the above file has a .py 
extension, say maybe "config.py", and then in code where you need to 
"parse" it and extract the values you can just do this:

import config
print 'Project Id is', config.PROJECT_ID

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


Re: Productivity and economics at software development

2005-09-23 Thread Peter Hansen
Adriano Monteiro wrote:
> I'm making a little research project about programming languages e
> their respective IDEs. The goal is to trace each language silhouettes,
> where it fits better, their goods/bads and the costs of developing in
> this language.

You say this as though each language has and needs an IDE!

We do all our development using a simple text editor (often Scite) and a 
console window (or three), plus assorted other tools developed or 
discovered, as required.  It's not "integrated" like an IDE, but we find 
it a much more effective approach, especially as we are doing 
test-driven development.  An IDE just gets in our way.

If you focus on IDEs, your research will have pre-selected only certain 
kinds of programmers and teams, and will not necessarily include the 
best ones.  (Looking at the VB world, one might even say something more 
extreme than that.)

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


Re: Single type for __builtins__ in Py3.0

2005-09-23 Thread Peter Hansen
Collin Winter wrote:
> On 9/23/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>>__builtins__ is a CPython implementation detail.  why not just let it
>>be an implementation detail, and refrain from using it?  it's not that
>>hard, really.

> Given, but I fail to see why it can't be a consistent implementation
> detail. After my own encounter with __builtins__, I now know that I
> should use __builtin__ instead. However, the docs never mention this.

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

> The only way you'd know that __builtin__ is preferred is by searching
> the list archives, something you're not likely to do unless you're
> already having a problem.
> 
> If it's decided to leave things they way they are, at the very least
> the docs should be amended to indicate that users shouldn't be
> touching __builtins__. If anyone has a suggestion as to where this
> kind of thing might best fit (tutorial, library reference, language
> reference?), I'd be happy to write a patch for the docs.

User are clearly told in various places that names with leading and 
trailing double underscores are *special*, and at least by implication 
they are not to be used without a good understanding of what they are. 
You certainly shouldn't have found any docs telling you to use 
__builtins__ that way.

http://www.google.ca/search?q=site%3Apython.org+__builtin__ is a pretty 
quick way of finding the above docs, and while doing the same search 
with __builtins__ admittedly finds lots of mailing list archives where 
people have the same misconception as you did, it doesn't take one past 
the second page of results before you'll be right back at a post by 
Fredrik pointing out the same mistake. :-)

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


Re: Single type for __builtins__ in Py3.0

2005-09-23 Thread Peter Hansen
Collin Winter wrote:
> The difference between __builtins__ and the other __*__ names is that
> while the others shouldn't be used without understanding their
> purpose, the consensus on __builtins__ seems to be that it shouldn't
> be used at all. 
> 
> ... at the very
> least, users should be explicitly told -- up front, in the official
> documentation --  that they shouldn't ever touch __builtins__. 

(...all of which I understood you to be saying in your previous post on 
the matter.)

My point, which might not have been clear, is that users are *already* 
told that they shouldn't ever touch __anything__ without understanding 
what it is, which is more general advice than and therefore encompasses 
the __builtins__ issue.  For this reason I believe the existing advice 
is sufficient for everyone except those who would probably also end up 
ignoring your above suggestions anyway.

 > Maybe
 > __builtins__ could be removed entirely from Py3.0, thus bringing
 > reality in to sync with policy.

That's a possibility, though given that it's an implementation detail 
there could easily be other implementation details which you would then 
be asking to be removed as well because they might confuse someone.  If 
you really want to avoid having implementation details exposed like 
this, you should probably be participating closely in the development 
process.  ;-)

(I'm also someone who believes we have way too many laws and that a few 
core ones already cover the majority of interesting situations for which 
the politicians are endlessly dreaming up more and more specific laws. 
So far this thread seems to me a parallel sort of situation...)

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


Re: Can I compile Python for the web?

2005-09-23 Thread Peter Hansen
Charles wrote:
> I'm doing some investigations on the Python language.
> I'd like to know if it is possible to compile Python code made for the 
> web  (an online database for instance), and to run it using mod_python. 
> How is  it possible? I think it would be very fast to execute the code 
> if it were  compiled.

Python code is already compiled, specifically to .pyc files, though this 
is clearly not what you meant by the above.  (The .pyc files contain 
"bytecode" which is executed by the Python virtual machine, much like a 
CPU executes its native opcodes, or like Java executes its own bytecode 
instructions.)

What you appear to be asking is if it's possible to create *native 
machine code* from Python source in order to achieve a significant 
increase in performance.  The short answer is "no, not really", and 
longer answers include "yes, sort of, using something like Psyco", and 
"who cares because it wouldn't give you much better performance for a 
web-based application where you're probably either I/O-bound or limited 
by the speed of the non-Python database solution you are using in the 
first place?".

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


Re: Productivity and economics at software development

2005-09-23 Thread Peter Hansen
Paul Rubin wrote:
> Peter Hansen <[EMAIL PROTECTED]> writes:
>>If you focus on IDEs, your research will have pre-selected only
>>certain kinds of programmers and teams, and will not necessarily
>>include the best ones.
> 
> It wouldn't have occurred to me to say that Ken Iverson (APL), Peter
> Deutsch (PARC Smalltalk), or Dave Moon (MIT Lisp machine) were any of
> them slouches.  Some of the best programming ever done has gone into
> IDE's.  It would be great if Python had anything of the caliber of
> those old systems.

Then we're on the same page, Paul, since I would never say that any of 
those people, nor many others who use or create IDEs, were slouches.

If you thought I said that, I believe you're parsing my statement 
incorrectly, or using incorrect logic.

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


Re: parsing a date

2005-09-24 Thread Peter Hansen
Kalle Anke wrote:
> On Fri, 23 Sep 2005 23:01:18 +0200, Larry Bates wrote:
> 
>>but I'm not sure it is "better".  I guess it depends
>>on what you want to do with them after parsing.
> 
> Sorry, I should have been clearer. I want to parse the date and create a 
> 'date object' that is a part of larger object (I'm parsing a text file that 
> represents the larger object and the date is a part of it).
> 
> So my question should probably be: is there a better way to parse the date 
> and generate the 'date object' than the two step 
> 
>  w = strptime(d,'%Y-%m-%d')
>  datetime.date( w[0], w[1], w[2] )
> 
> Since I'm new to many things in Python I'm trying to learn if there is a 
> "better" way of doing things.

You're still not defining what "better" means to you, so who can say?

Perhaps you think a single line would be "better"?

datetime.date(*time.strptime(d, '%Y-%m-%d')[:3])

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


Re: parsing a date

2005-09-24 Thread Peter Hansen
Kalle Anke wrote:
> Better (in this case) =
> 
>   + Being "pythonic"
> 
>   + Avoiding going through a second representation (the tuple)
> if there is some way to create a date object directly.

I think the plainest and simplest approach would be to create a 
well-named function which does the necessary steps (_not_ in a single 
line of code but with nice readable temporary variables) and call that 
whenever you need it.

Simple utility functions that call a few standard library functions to 
do a job like this are very "pythonic", and trying to avoid a second 
representation when (as in this case) there's no obvious way to do it is 
not pythonic. :-)

I'd say if you've checked datetime.date() and not found a factory 
function or whatever which knows how to parse a string (as many of us 
have), and if you don't want to download, install, and depend on a 
third-party extension such as mxDateTime which do this already, then a 
function to wrap the ugly details is a very nice way to proceed.

If you need to do this often, then you've got the beginnings of your own 
utility module or package, and having those around is pretty "pythonic" too.

(An alternative would be to contribute a patch to add something like 
this to the datetime module.  I don't know if it would be accepted, but 
at least it would be the true arbiters of "pythonicism" who would be 
judging the matter, not you or I. :-) )

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


Re: Determine type of a socket

2005-09-26 Thread Peter Hansen
Tor Erik Sønvisen wrote:
> How can I determine the type of a socket (TCP or UDP) object?

In what context?  Do you have some code that gets passed a socket object 
but it could have been created with either SOCK_STREAM or SOCK_DGRAM? 
And you want a way of determining by looking just at the object passed 
in which type it is?  (I could make other guesses, but let's start with 
that... ;-)  )

How about this:

 >>> import socket
 >>> t = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 >>> u = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 >>> dir(t)
['__class__',  '_sock', 'accept', 'bind', 'close'
, 'connect', 'connect_ex', 'dup', 'fileno', 'getpeername',
...'setblocking', 'setsockopt', 'settimeout', 'shutdown']

Let's see... what looks good here?

 >>> u._sock

 >>> t._sock


Maybe that type field?

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


Re: Determine type of a socket

2005-09-26 Thread Peter Hansen
Reinhold Birkenfeld wrote:
> Peter Hansen wrote:
>>Tor Erik Sønvisen wrote:
>>>How can I determine the type of a socket (TCP or UDP) object?

>>Let's see... what looks good here?
>>
>> >>> u._sock
>>
>> >>> t._sock
>>
>>
>>Maybe that type field?
> 
> Heh. The type field isn't publicly accessible (yet). There is a
> patch on SF for this, in the meanwhile you'll have to parse the
> __repr__ output.

And he might not have to do either, depending on what his situation 
really is.  For example, if his socket is always going to be connected 
(in the case of a TCP socket) I expect checking something about the peer 
would be a quick way to tell the difference, since UDP sockets don't 
shouldn't have peers.  (I'm assuming, not having tested... but I think 
there are probably such approaches that don't involve either _sock or 
repr().  Let's see what the OP reveals.)

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


Re: The ^ operator

2005-09-26 Thread Peter Hansen
Tuvas wrote:
> What exactly does the ^ operator do? I've seen, for example, that
> 3^4=7, 3^5=8. but 3^3=0. Is it just adding them together if they are
> not equal, and if they are equal, outputs 0, or what? Thanks!

It performs an "exclusive-OR" (XOR) operation on the binary data 
corresponding to those values.  Where the boolean AND operation returns 
a 1 where both inputs are 1 and a 0 otherwise, and boolean OR returns a 
1 if either input is 1 but 0 otherwise, the XOR operator returns a 1 if 
the two inputs are different (i.e. one is 0 and the other is 1) but a 0 
if they are the same.

When done on the binary value, each corresponding bit is compared using 
the above logic.  For example, 3 is 0011 in binary, and 4 is 0100, so:

   011 binary for 3
^ 100 binary for 4
   ---
= 111 (which is binary for 7).

(match up the binary digits vertically, so the first digit in the result 
comes from the 0 and the 1 above it, in the two input values).

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


Re: @staticmethod, backward compatibility?

2005-09-27 Thread Peter Hansen
Neal Becker wrote:
> How can I write code to take advantage of new decorator syntax, while
> allowing backward compatibility?
> 
> I almost want a preprocessor.
> 
> #if PYTHON_VERSION >= 2.4
> @staticmethod
> ...
> 
> Since python < 2.4 will just choke on @staticmethod, how can I do this?

It seems to me that no matter what you do, if it's not done with an 
external processing tool which requires no changes in the source code, 
the result will be much uglier than if you just used the pre-2.4 
decorator syntax:

def meth():
   pass
meth = staticmethod(meth)


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


Re: Python 2.4 under WinXP, free VC71 toolkit and VC6 libraries

2005-09-27 Thread Peter Hansen
Berthold Höllmann wrote:
> As I understand it, ctypes is not really a solution. The code is about
> data handling and FE analysis. It has not GUI component. I'm not sure
> how well ctypes works with Numeric arrays, but I'm sure ctypes does
> not work on Linux and Solaris, but my code has to.

Neither of those comments makes sense, so you probably _don't_ 
understand what ctypes is.  Not only does it definitely work on Linux, 
but it has nothing to do per se with GUI components, and should work 
fine for "data handling" of just about any kind that is done by a DLL.

I'm not sure what you were thinking of, but it probably wasn't ctypes.

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

Re: Overhead of individual python apps

2005-09-28 Thread Peter Hansen
Fredrik Lundh wrote:
> (for python, the "private" memory use is usually ~1.5 megabytes for a "empty" 
> 2.4
> process, and some of that will only occupy space in the paging file...  for 
> firefox with
> a simple page loaded into a single tab, the private space is ~10 megabytes)

I believe a relatively simple, if crude, way of measuring this sort of 
thing (at least for console programs) is to open a handful of command 
prompts, check the Physical Memory Available measurement in the Task 
Manager, and then load one instance of the program in each console, 
checking the drop in physical memory available at each step.  After 
three or four instances are loaded, the approximate real memory usage 
for each should be readily apparent.

Obviously there are a dozen issues that can screw with this, including 
having too little memory free at all, and having other programs open 
which are very actively allocating or freeing memory.

It does seem to back up the "~1.5MB" number above, and certainly shows 
that the total is nowhere near 4MB per Python interpreter.

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


Re: import problems in packages

2005-09-28 Thread Peter Hansen
Stéphane Ninin wrote:
> Traceback (most recent call last):
>   File "main.py", line 8, in ?
> main()
>   File "main.py", line 5, in main
> handler = HandlerFactory().makeHandler(command)
>   File "c:\ROOT\Handlers\HandlerFactory.py", line 6, in HandlerFactory
> import Handlers.Default.HandlerFactory
> ImportError: No module named Default.HandlerFactory

Are you sure that's right?  You asked it to import 
Handlers.Default.HandlerFactory but it is apparently importing just 
Default.HandlerFactory instead?  This seems unexpected to me, though 
perhaps it can happen in certain situations.  It's a hint, anyway.

Are the earlier four lines which you did show us relevant?  (i.e. if 
that's line six, what was on lines one, two, three, and four?)

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


Re: Rollover/wraparound time of time.clock() under win32?

2005-09-28 Thread Peter Hansen
Russell Warren wrote:
> Does anyone know how long it takes for time.clock() to roll over under
> win32?
> 
> I'm aware that it uses QueryPerformanceCounter under win32... when I've
> used this in the past (other languages) it is a great high-res 64-bit
> performance counter that doesn't roll-over for many (many) years, but
> I'm worried about how many bits Python uses for it and when it will
> roll over.  

Check the source for yourself:

http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Modules/timemodule.c?rev=2.144&view=auto

(It takes the full 64-bit value and divides by the frequency, returning 
a double.  Whether or not that works for you only you can say.)

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


Re: A quick c.l.p netiquette question

2005-09-29 Thread Peter Hansen
Peter Corbett wrote:
> I've written a program to illustrate a few... syntactic issues with
> Python. It's 158 <80 character lines long.
> 
> About how short should a program be to be postable to this newsgroup -
> in other words, at what length should you stick it on a web page and
> post a link?

Does it really have to be 158 lines to demonstrate these few issues?  I 
for one almost never take the time to dig through 158 lines of someone 
else's code, partly on the assumption that almost any interesting issue 
can be covered (using Python, specifically) in about a dozen lines of 
code.  YMMV

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


Re: converting Word to MediaWiki

2005-09-29 Thread Peter Hansen
Jeff Schwab wrote:
> ChiTownBob wrote:
> 
>> Perl just sucks, as all good Python hackers know!
> 
> 
> I disagree.  Perl has saved my butt more times than I care to count. 
> Python certainly has its advantages, but I won't be giving up Perl any 
> time soon.

Are the two necessarily in conflict?  Perl can save your butt and 
_still_ suck!

;-) ;-)

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


Re: A quick c.l.p netiquette question

2005-09-29 Thread Peter Hansen
Fredrik Lundh wrote:
> Peter Hansen wrote:
>>Does it really have to be 158 lines to demonstrate these few issues?  I
>>for one almost never take the time to dig through 158 lines of someone
>>else's code, partly on the assumption that almost any interesting issue
>>can be covered (using Python, specifically) in about a dozen lines of
>>code.

> did you click on the link he posted a little later?

What link?  I see only two posts from him in this thread, one at 5:09 
and the other at 6:14, and neither contains links.  I suppose I should 
start to distrust my ISP's news feed, because that was how it was this 
morning and how it still is now.  There are a grand total of 10 posts to 
that thread as I'm about to post this reply.

Sorry, but I can't click on links that don't exist.

>>YMMV
> 
> no, YVFC.

??  you've lost me there too.  Your Very Fucked Computer?  I'll agree 
that some computer around here is fucked if I can't see a post that 
everyone else can see.

-Peter

(Well now... I just realized that it wasn't in the same thread after 
all, and yes, I did see the post, then noticed a reply from someone 
talking about Greenspun's law, quickly hit "k" to move on to more 
interesting topics, and never gave it a second thought.  Certainly 
didn't notice it was also Peter who had posted that one, nor realized 
the connection (probably because I'd already sent my reply and thus 
flushed the whole affair from my memory).  So, in summary, yes I did 
click on the link he posted, but that was after I'd already replied so I 
don't think it's particularly useful for us to be discussing it.  YMMV 
again. :-)  )

(And I do see the YVFC part now... what was really bizarre was trying to 
do a search on the web for what that acronym means.  Try it... strange 
stuff.  I was thinking there was some weird conspiracy to make people 
think there was this acronym that was well known but had no online 
definition.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where to find python c-sources

2005-09-29 Thread Peter Hansen
Dave Benjamin wrote:
> Tor Erik Sønvisen wrote:
>> I need to browse the socket-module source-code. I believe it's 
>> contained in the file socketmodule.c, but I can't locate this file... 
>> Where should I look?
> 
> You can browse the Python CVS tree here:
> http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/
> 
> For example, the file you asked for is viewable here:
> http://cvs.sourceforge.net/viewcvs.py/python/python/dist/src/Modules/socketmodule.c?rev=1.314&view=auto
>  

And only three hits down in this Google search:

   http://www.google.com/search?q=python+socketmodule.c

plus one additional click on "view" once you're there...

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


Re: Help with syntax warnings

2005-09-29 Thread Peter Hansen
Ivan Shevanski wrote:
> Here's a noob question for everyone (I'm not sure if my first message 
> got through, is had a "suspicious header" so sorry for double post is 
> so), is there a way to turn off syntax warnings or just make them not 
> visible?

Not sure... what's a "syntax warning"?

Python has SyntaxError exceptions, which are raised during compilation 
when a program can't even be compiled.  They're definitely not warnings, 
and making them invisible would generally be pointless, yet even so all 
you would have to do is catch them and ignore them if that's what you 
wanted to do.  But did you mean SyntaxError, or something else?

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


Re: Help with syntax warnings

2005-09-30 Thread Peter Hansen
Robert Kern wrote:
> Peter Hansen wrote:
>>Not sure... what's a "syntax warning"?
> 
> In [1]: SyntaxWarning?
> Type:   classobj
> String Form:exceptions.SyntaxWarning
> Namespace:  Python builtin
> Docstring:
> Base class for warnings about dubious syntax.

Wow... Python detects "dubious syntax"?  And here I thought programming 
was rather black and white, it's right or it's wrong.

(He notes examples such as assigning to None and "unqualified exec is 
not allowed in function" etc.)

I guess I've never accidentally hit one of those.  Seems like, if I had, 
I'd probably want to fix the problem rather than hide it, as with most 
warnings from C compilers.

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


Re: RELEASED Python 2.4.2 (final)

2005-09-30 Thread Peter Hansen
Martin v. Löwis wrote:
> Trent Mick wrote:
> 
>>It is possible that the python.org installer didn't overwrite the
>>"python24.dll" in the system directory (C:\WINDOWS\system32). Try doing
>>this:
> 
> 
> Even though this is apparently what happened, I'm puzzled as to why it
> happened: shouldn't the version number of python24.dll in the pydotorg
> installer be higher than the one in the ActivePython installer, and
> shouldn't then Windows Installer overwrite the DLL?

Couldn't it also happen if the first time someone did an "admin" install 
which (I believe) puts the DLLs in the system folder, and the next time 
did just a non-admin install which doesn't do that?  (Or am I 
misunderstanding the conditions under which c:\windows\system32 has 
files written to it?)

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


Re: A Moronicity of Guido van Rossum

2005-09-30 Thread Peter Hansen
Gerrit Holl wrote:
> True. However, most mail to this mailinglist has less than 0.001 spam
> probability. As you can see, this one had 0.048 - a vast score, almost
> enough to put it in my unsure box. It seems to be just not hammy enough.
> It's interesting to see that no none of the foul language words used by
> Xah Lee ever occurs in any spam I receive - spam is not that stupid.

"Xah Lee: stupider than spam." (?)

-neologism-intentional-ly y'rs,
  Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Moronicity Xha Lee, Jargonizer

2005-09-30 Thread Peter Hansen
Kay Schluehr wrote:
> By the way I noticed also a few reasonable non-troll postings of Xah
> without any response in the forum. Not even Xahs posting strategy is
> coherent.

Really?  Every one I've noticed has actually had a response, and a 
reasonably civil one at that.  Usually from Steve Holden, too, which 
makes the civility doubly surprising. ;-)

-revenge-is-sweet-ly y'rs,
  Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what does 0 mean in MyApp(0)

2005-10-02 Thread Peter Hansen
Alex wrote:
> Thanks for the replies. It seems that I have three options
> 1. app=MyApp()
> 2. app=MyApp(0)
> 3. app=MyApp('myfile.txt')

I just want to emphasize the part of vincent's reply in which he points 
out that using the keyword arguments makes this more readable.

If more examples and actual code would just use the darned "redirect=" 
keyword argument, you probably wouldn't have had to ask the question.

I remember when I had the same question and spent more time than I 
should have had to digging out the answer.  Now I try to make sure that 
all my wx.Apps are initialized with redirect=False or whatever else I 
need to make clear to a reader what I'm doing.  For some widely used and 
understood methods and constructors, using positional arguments might be 
adequate.  For ones like wx.App where everyone initializes them but 
nobody seems to know what the arguments are doing (sometimes they seem 
to be handed down from earlier generations), keyword arguments are a 
real blessing.

The world needs more keyword arguments.  Use them everywhere!  ;-)

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


Re: Where to find python c-sources

2005-10-03 Thread Peter Hansen
Michael wrote:
> John J. Lee wrote:
>>You believe that Tor is dumb enough not to think of searching for
>>"socketmodule.c" when, um, searching for socketmodule.c?
> 
> He said he had tried google - OK, not in the first post but early in this
> thread -  I don't equate that with being dumb - just dumb luck :-)
> 
> Message-ID: <[EMAIL PROTECTED]>
> 
> After all Peter Hansen suggested the search terms "python socketmodule.c"
> rather than just "socketmodule.c"
> 
> Message-ID: <[EMAIL PROTECTED]>
> 
> To you the obvious search term was "socketmodule.c" which to me simply means
> you're more aligned with Google than Tor :-)

Sorry, but this defense is less than weak.  Using "python 
socketmodule.c" you actually get the right answer as the third result, 
while with the even-more-obvious-to-a-rookie "socketmodule.c" you get it 
as the *first* result.  It would perhaps be fun to experiment to see 
just how hard it would be to use "socketmodule.c" plus anything else and 
*not* get the result one was looking for. ;-)  (note the wink...)

Clearly "Tor" did not try searching Google with two of the most obvious 
results, but I think at this point he should be considered to be soundly 
thrashed over the matter and we can all move on.  This isn't getting any 
more interesting...

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


Re: how do you pronounce wxpython

2005-10-10 Thread Peter Hansen
Peter wrote:
> Although the wxPyWiki seems to be pronounced wix-pee-wi-kee (as it says 
> on the front page) so maybe it is pronounced wix-Python... you never 
> know...

That's _definitely_ how it's pronounced.

Here.

Where I am.

When I'm speaking.

If, however, we're near Mike Fletcher and he's the one speaking, it's 
pronounced differently than any of the suggestions made so far, but I'd 
have to defer to him for the spelling describing his pronunciation.

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


Re: Python's Performance

2005-10-10 Thread Peter Hansen
Harald Armin Massa wrote:
> """
> What is Python?
> 
> Python is an interpreted, interactive, object-oriented programming
> language. It is often compared to Tcl, Perl, Scheme or Java.
> """
> taken from
> http://www.python.org/doc/Summary.html
> 
> maybe someone could update that???

Maybe we should add '''...for some definitions of "interpreted", 
"object-oriented", and perhaps even "interactive". '''

I've seen at least the first two debated endlessly here.

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


Re: Python reliability

2005-10-10 Thread Peter Hansen
Ville Voipio wrote:
> I am not building a redundant system with independent
> instruments voting. At this point I am trying to minimize
> the false alarms. This is why I want to know if Python
> is reliable enough to be used in this application.
> 
> By the postings I have seen in this thread it seems that
> the answer is positive. At least if I do not try 
> apply any adventorous programming techniques.

We built a system with similar requirements using an older version of 
Python (either 2.0 or 2.1 I believe).  A number of systems were shipped 
and operate without problems.  We did have a memory leak issue in an 
early version and spent ages debugging it (and actually implemented the 
suggested "reboot when necessary feature" as a stop-gap measure at one 
point), before finally discovering it.  (Then, knowing what to search 
for, we quickly found that the problem had been fixed in CVS for the 
Python version we were using, and actually released in the subsequent 
major revision.  (The leak involved extending empty lists, or extending 
lists with empty lists, as I recall.)

Other than that, we had no real issues and definitely felt the choice of 
Python was completely justified.  I have no hesitation recommending it, 
other than to caution (as I believe Paul R did) that use of new features 
is "dangerous" in that they won't have as wide usage and shouldn't 
always be considered "proven" in long-term field use, by definition.

Another suggestion would be to carefully avoid cyclic references (if the 
app is simple enough for this to be feasible), allowing you to rely on 
reference-counting for garbage collection and the resultant "more 
deterministic" behaviour.

Also test heavily.  We were using test-driven development and had 
effectively thousands of hours of run-time by the time the first system 
shipped, so we had great confidence in it.

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


Re: Send password over TCP connection

2005-10-10 Thread Peter Hansen
dcrespo wrote:
> Two copies of the password: one on the client, the other on the server.
[snip]
> I think it is a very good solution, Isn't it?

Ignoring all the other issues, any solution which actually requires the 
password to be stored on the server is a bad solution.  Administrators 
should not have access to user passwords, and in addition users should 
not be put in the position of having to trust your server-side security 
to keep their passwords (which they might have used on other systems) 
from being grabbed by hackers.

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


Re: Library functions

2005-10-10 Thread Peter Hansen
Tuvas wrote:
> How exactly do you do that? Just to get some kind of an idea, perhaps
> you could share bits of code? Thanks!

Did you check out the ctypes web site before asking?  See 
http://starship.python.net/crew/theller/ctypes/ and at least read 
through the helpful tutorial before asking questions which are almost 
certainly covered there.  For example, right there near the top of the 
first screen in the tutorial is an example of opening a Linux .so file...

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


Re: Why asci-only symbols?

2005-10-10 Thread Peter Hansen
Mike Meyer wrote:
> Out of random curiosity, is there a PEP/thread/? that explains why
> Python symbols are restricted to 7-bit ascii?

And of equally random curiosity :-), what alternative(s) can you suggest 
would have been appropriate?  (I note that Unicode, for example, dates 
from around the time Python was first released.  And I can't really 
imagine a non-ugly alternative, which probably reveals something bad 
about my imagination.)

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


Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-10 Thread Peter Hansen
Sebastian Bassi wrote:
> I don't understand why there is a new expression, if this could be
> accomplished with:
> 
> if C:
>  X
> else:
>  Y
> 
> What is the advantage with the new expression?

It actually is an expression, whereas your example shows a statement (so 
"this" could _not_ be accomplished with what you showed).

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


Re: Python's Performance

2005-10-11 Thread Peter Hansen
Steve Holden wrote:
> And we definitely need "agile" in there. Bugger, I'll go out and come in 
> again ...

Used in the same breath as the word "bugger", I'm not sure the phrase 
"go out and come in again" is entirely appropriate for a family forum. ;-)

But I'm also not sure I ought to post that to the group, so I'll spare 
them and just inflict the thought on you!

Cheers,
-Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Send password over TCP connection

2005-10-11 Thread Peter Hansen
Laszlo Zsolt Nagy wrote:
 > Peter Hansen wrote:
>> Ignoring all the other issues, any solution which actually requires 
>> the password to be stored on the server is a bad solution.  
>> Administrators should not have access to user passwords, and in 
>> addition users should not be put in the position of having to trust 
>> your server-side security to keep their passwords (which they might 
>> have used on other systems) from being grabbed by hackers.
>>
> Users will always need to trust in the server. The authentication 
> process ensures that the
> client is really talking with the desired server and vice versa. But 
> even if you know that you
> are talking to the right server, you need to trust in the server. The 
> administrator of the server
> has access to all data. Possibly other persons and softwares too. 
> Passwords are not different from this point of view.

If you're saying that people have no choice but to trust that their 
passwords, stored in the clear on the server of some idiot who didn't 
know better, are safe from casual administrator observation and safe 
from hackers stealing the password file, then you shouldn't be allowed 
anywhere near a supposedly secure system...

If you're just saying that one has to trust that the server you are 
talking to at this instant in time is really the one you thought it was, 
then that's an entirely different issue and I agree.

But storing passwords in the clear, thus allowing administrators full 
access to users' passwords, is absolutely *not* necessary.  That's my 
point, regardless of what other issues this thread spawns.  If the OP 
implements strictly the sequence he mentioned in the posting to which I 
was replying, he'll be the aforementioned idiot...

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


Re: Python's Performance

2005-10-11 Thread Peter Hansen
Peter Hansen wrote:
> But I'm also not sure I ought to post that to the group, so I'll spare 
> them and just inflict the thought on you!

Or, maybe I'll just fail to trim the newsgroup line and accidentally 
post to the group anyway.  Yes, that's just what I'll do.

Sorry folks. :-)

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


Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-12 Thread Peter Hansen
Dave Hansen wrote:
> So lose the "if."
> 
>R = C then A else B

It would be nice (in my opinion) if this were the way it was going to 
be.  Having one of the two results come first makes that result seem 
somehow of primary importance, while the conditional (which in my mind 
is far more important than either result) comes hidden in the middle:

"C then A else B"   makes the conditional stand out

"A if C else B" suggests that A is more important than B and hides C

But I can live with whichever it is... not that I have any choice. :)

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


Re: Python reliability

2005-10-12 Thread Peter Hansen
John Waycott wrote:
> I wrote a simple Python program that acts as a buffer between a 
> transaction network and a database server, writing the transaction logs 
> to a file that the database reads the next day for billing. The simple 
> design decoupled the database from network so it wasn't stresed during 
> high-volume times. The two systems (one for redundancy) that run the 
> Python program have been running for six years.

Six years?  With no downtime at all for the server?  That's a lot of 
"9s" of reliability...

Must still be using Python 1.5.2 as well...

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


Re: Send password over TCP connection

2005-10-12 Thread Peter Hansen
dcrespo wrote:
> then, what you proppose?

I'll assume that question was for me, in response to my comment that one 
should never store passwords in the clear.

Do you know how any other system manages to do this?  Linux, for example 
(assuming a properly configured system)?  The passwords aren't stored: 
hashes of the passwords are stored (with additional things thrown in to 
prevent certain kinds of attacks even if someone nabs the password 
(/etc/shadow) file).  If you store the password or even encrypt it (i.e. 
something that can be reversed if someone knows the key), it's a risk.

If you don't know about this stuff yet, I strongly suggest lots of 
additional research and reading prior to implementing a serious system. 
  There are _many_ web pages to be found which discuss this sort of 
thing, probably including lots of tutorials for people starting on the 
ground floor.

I bet Paul R or others more experienced in this area can point us to 
some excellent ones, but a little googling with "passwords store clear 
text" or "encrypted passwords" would get you started.  I expect that 
would quickly lead to the term "hashing", since you really don't want to 
just encrypt the password: that can easily be reversed if anyone has the 
key, and certainly an administrator could access the key used by some 
random application that encrypts its passwords.  The first few hits for 
that last search seem to include pages that introduce the concept of 
"salt", one of the "additional things" I mentioned above.

I'm not going to try to give a tutorial: I'm not nearly expert enough to 
be trusted for that. :-)  I just wanted to warn against one of the most 
basic and easily avoidable problems.

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


Re: slots? SLOTS?

2005-10-12 Thread Peter Hansen
tin gherdanarra wrote:
> what is a "slot" in python? 

Google for "site:docs.python.org slots":

http://www.google.ca/search?q=site%3Adocs.python.org+slots

First hit...

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


Re: Bad magic no. in python zipfile

2005-10-12 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
\> I'm able to create a new zipfile with the module's ZipFile class and
> add files to it.  After closing the file, I'm able to view the contents
> of it with WinZip.  I can also confirm that it is a python zip file by
> using the is_zipfile() method.  All good so far.  However, under some
> circumstances, I am unable to later read the file and extract its
> contents.  As soon as a I attempt to instantiate a new ZipFile
> instance, I receive an error regarding Bad Magic number.   In the past,
> I've seen that when trying to use a .pyc module, created with one
> Python version, using another Python version.  But in this case, I
> created the zip file under Python 2.4.2 and tried to open it under
> Python 2.4.2 as well.  Any ideas on what to do?  

Maybe try posting the full traceback so we can see the "Bad Magic 
Number" error you are getting...

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


Re: Well written open source Python apps

2005-10-13 Thread Peter Hansen
Ben wrote:
> Could anyone suggest an open source project that has particularly well
> written Python?  I am especially looking for code that people would
> describe as "very Python-ic".  (Not trying to start any kind of war -
> just wanted some good examples of a well written Python app to read.)

I'm sorry I can't speak on its "pythonicity" (my memory sucks), but I 
did find Roger Binns' BitPim program (http://bitpim.sourceforge.net/) to 
be an excellent source of ideas (steal steal steal) for wxPython code, 
and I do remember it struck me as being exceptionally well commented and 
well structured.  I suspect it's pretty Pythonic, too, since Roger seems 
pretty brilliant from where I sit. :-)

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


Re: 1-liner to iterate over infinite sequence of integers?

2005-10-13 Thread Peter Hansen
Erik Max Francis wrote:
> The negative integers are being descriminated against!  I demand justice!
> 
> def integers():
> yield 0
> x = 1
> while True:
> yield x
> yield -x
> x += 1
> 
> ... which is also not a bad demonstration of how the integers are 
> countably infinite.

For some reason I was unable to avoid seeing that one can save a yield 
there (not that they're a scarce resource, mind you):

def integers():
   x = 0
   while True:
 yield -x
 x += 1
 yield x

I know that shouldn't win any readability awards...

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


Re: Yes, this is a python question, and a serious one at that (moving to Win XP)

2005-10-14 Thread Peter Hansen
Christian Stapfer wrote:
> 0.0. ... and add an item to your SendTo folder that allows
> you to have Windows Explorer open a terminal window with its
> current directory set to the currently displayed folder
> (= "Open terminal here").

Or install the "Command Prompt Here" gadget that MS produces, which has 
a massive installer and a click-through license thing and everything, 
just to open a freakin' prompt at a given directory.  I'm continually 
amazed by how these little bits of knowledge (like the one Christian 
provides above and which I never knew before) have to be disseminated 
through the grass roots, so to speak.  Definitely like the MS world is 
not set up for real developers easily to be productive.

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


Re: Accessing Parallel Port in Python Error : Priviledged Instruction

2005-10-15 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> When I use Pyparallel to access the parallel port in WinXP with Python
> I get an error saying that this is a priviledged instruction
> 
> Any clue ?

Here's a clue: please always cut and paste the *entire actual* traceback 
when you report a Python error.

If it's not a Python traceback, spend the time to retype -- carefully -- 
the exact text from the dialog where the error was reported.  If it's 
one of those awful Windows crash dialogs with reams of useless 
information, spend some time thinking about what portion of that would 
be most likely to be of help to us, if you can't retype all of it.

Also consider reporting on version numbers of things: Python, 
Pyparallel, WinXP (SP2 for example?), just in case that matters.

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


Re: How to get a raised exception from other thread

2005-10-15 Thread Peter Hansen
dcrespo wrote:
> How can I get a raised exception from other thread that is in an
> imported module?

Define what "get" means for your purposes.  It appears that you mean you 
want to catch the exception, but in the thread which launched the other 
thread in the first place.  If that's true, please show where you would 
expect to catch this exception, given that when you start the thread, 
the main thread continues running and might even finish before the other 
thread finishes.

> thread = programB.MakeThread()
> thread.start()
...
# later code which might have completed by the time the thread finishes
...

Are you looking, for example, for some kind of
thread.waitUntilCompletionAndReRaiseExceptions() method?

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


Re: How to get a raised exception from other thread

2005-10-15 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> I also need an answer to this problem.  

What _is_ the problem?  We're still waiting for a clear description from 
the OP as to what the problem really is.  How would you describe what 
_your_ problem is?

 > I'm using windows.  Throwing an
> exception in thread B from thread A using a callback function.
> 
> The function runs, but the thread never actually catches the exception.
>  The try/except block is in the run() method (over-riden from the
> Thread class)

Rather than force us all to guess what you are doing wrong, maybe it 
would be better if you posted a small amount of code that shows the problem.

Exceptions raised in threads can definitely be caught in the run() 
method if the code is written correctly, so that is not in itself an issue.

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


Re: How to get a raised exception from other thread

2005-10-16 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> Nevermind.  I found a better solution.  I used shared memory to create
> a keep-alive flag.  I then use the select function with a specified
> timeout, and recheck the keep-alive flag after each timeout.

As Dennis points out, your original attempt was destined to fail because 
you were calling the method from the main thread, not the one you wanted 
to kill.  Threads don't magically execute any methods that are attached 
to the Thread instance just because they're attached.  You have to 
actually call those methods *from* the thread, which means from the 
run() method or from any of the routines it calls (whether they are 
methods on that Thread or not), but it must be done in the context of 
the thread you want to raise exceptions in or it won't work.

More importantly, you've now described your use case (and I hope that of 
the OP as well, since he hasn't replied yet): killing threads.

This is an oft-discussed topic here, and searching the archives will 
probably give you lots more answers, but the short answer is you cannot 
kill a thread in Python (except by exiting the entire process). Instead, 
as you've discovered, you must ask it nicely to exit.  The nearly 
canonical approach to doing that is as follows:

class MyThread(threading.Thread):
 def __init__(self, *args, **kwargs):
 threading.Thread.__init__(self, *args, **kwargs)
 self._keepRunning = True

 def stop(self, timeout=None):
 self._keepRunning = False
 # optional: wait for thread to exit
 self.join(timeout=timeout)

 def run(self):
 while self._keepRunning:
 # do stuff here

Now you can do things like this:

thread = MyThread()
thread.start()
# other stuff...
thread.stop()# block here until the thread exits

I hope that clarifies things a little more...

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


Re: How to get a raised exception from other thread

2005-10-17 Thread Peter Hansen
dcrespo wrote:
>>Define what "get" means for your purposes.  It appears that you mean you
>>want to catch the exception, but in the thread which launched the other
>>thread in the first place.  If that's true, please show where you would
>>expect to catch this exception, given that when you start the thread,
>>the main thread continues running and might even finish before the other
>>thread finishes.
> 
> In my above example, I want to catch in ProgramA the raised exception
> in ProgramB. 

Better not to call them "programs" since they're not separate programs, 
just separate modules, one of which starts a thread using methods in the 
other module.

And you haven't really answered the questions I asked.  Please show 
exactly where you expect to catch the exception, given the points I note 
above.  Before, after, or during the .start() call, or somewhere else?

> Please, look at my example one more time.

Done.  It didn't really help looking at it a third time.  It's still 
unclear what you want.

Maybe explaining the use case would help you help us help you. :-)

Your example seems contrived.  In the real code you want to write, why 
do you expect an exception to occur?  Will it be raised deliberately, as 
you show in the example, or is it unexpected (and unhandled by any 
try/except at the top level of the thread's run() method)?  Or do you 
really need to use an exception here?

I'm quite sure the problem you are trying to solve can be solved, but 
you are still describing part of the solution you believe you need, 
rather than explaining why you want to do this (which may let us show 
you other, simpler or cleaner ways to accomplish your goals).

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


Re: unittest of file-reading function

2005-10-18 Thread Peter Hansen
Helge Stenstroem wrote:
> Say I have a function
> 
> def f(filename):
> result = openFileAndProcessContents(filename)
> return result
> 
> Can that function be unit tested without having a real file as input?
> Something along the lines of
> 
> import unittest
> class tests(unittest.TestCase):
> def test1(self):
> fileContents = "bla bla bla\nmore bla bla bla"
> ???   # make f read this string instead of opening a file
> expected = expectedResult
> result = f(filename)
> self.assertEqual(result, expected)
> 
> One possibility would be to make the unit test write to a temporary
> file. Are there better alternatives?

The simplest approach is to use a StringIO.  Often that will require 
passing a "file" object to the routine instead of a file *name*, but 
often that's better anyway (decouples file management and parsing).

Another approach is to create a "mock file" object.  Depending on your 
needs, this can be a very simple or a very complex thing to do.  I can 
offer more detail/suggestions here if you need.

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


Re: Dealing with Excel

2005-10-18 Thread Peter Hansen
Robert Hicks wrote:
> No, I have to format fields and everything sad to say. Another poster
> up the chain of this posting gave me the nudge in the direction I
> needed.

Doesn't Excel also support (in addition to binary .xls and simple text 
.csv files) an XML format, which allows full access to formatting and 
all other such features?  I would assume it's reasonably well documented 
and you could just generate that output directly.

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


Re: write a loopin one line; process file paths

2005-10-18 Thread Peter Hansen
Xah Lee wrote:
> If you think i have a point, ...

You have neither that, nor a clue.

(Newsgroups line trimmed to reduce the effects of cross-posting trolls.)

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


Re: How to get a raised exception from other thread

2005-10-18 Thread Peter Hansen
dcrespo wrote:
>>Before, after, or during the .start() call, or somewhere else?
> I'd like to catch *just after* the .start() call.

Excellent.  That makes it pretty easy then, since even though you are 
spawning a thread to do the work, your main thread isn't expected to 
continue processing in parallel.  See my draft solution below.  If it 
doesn't seem to suit, explain where it fails you and we can try to 
evolve it (assuming we're on the same page at all here).

> When you specify the case number 2, the IP must be valid for the
> computer where the program runs, otherwise, it raises an exception
> saying that "Can't assign requested address".
> 
> MainProgram.py
> ...
> SrvrTCP = module.ThreadedTCPServer(ip,port)
> SrvrTCP.start()
 > #Here, I want to know if the TCPServer started well.

Leave that part as it is.  We'll override the start() method in your 
subclass to solve your problem.

> module.py
> ...
> class ThreadedTCPServer(threading.Thread):
> 
> def __init__(self, ip,port):
> threading.Thread.__init__(self)
> self.ip= ip
> self.port= port
   self.startError = None
   self.startedEvent = threading.Event()


   def start(self):
   '''start thread and wait for successful start'''
   threading.Thread.start(self)
   self.startedEvent.wait()
   if self.startError:
   raise self.startError


> def run(self):
> TCPServer((self.ip,self.port)) #Here, if the self.ip is
> invalid, it raises an exception.
> ...

We have to change the run() method slightly now:

   def run(self):
   try:
   try:
   TCPServer((self.ip, self.port))
   except Exception, ex:
   self.startError = ex
   return
   finally:
   self.startedEvent.set()

   # do the rest of the existing run() code here


Now that may not be perfect, since I'm not familiar with the TCPServer() 
call.  I've sort of assumed it does something quickly and returns, or 
raises an exception if the input is bad.  If it doesn't actually return 
if it starts successfully, you would need a little different approach. 
Probably adding a simple timeout to the self.startEvent.wait() call 
would work.

Note also that you don't get the full original traceback with this 
technique.  I'm not sure you can, actually (though I can imagine that 
with Python one could "stitch together" a traceback from a previous 
exception as one raises a new exception).  From what you describe, 
however, it sounds like you just need to know that the exception 
occurred, not the precise line of code down in TCPServer() where it was 
originally raised.

I hope that helps and/or gives you some leads on a better solution.

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


Re: How to get a raised exception from other thread

2005-10-21 Thread Peter Hansen
dcrespo wrote:
> Ok, sorry about the above question. I solved it adding this to the main
> thread:
> 
> try:
> SrvrTCP = module.ThreadedTCPServer(ip,port)
> SrvrTCP.start()
> except Exception, description:
> MsgBox(self,"TCPServer
> Error:\n\n"+str(description),title="TCPServer",style=wx.OK |
> wx.ICON_ERROR)
> return
> 
> Peter, thank you very much.

You're quite welcome.  It's nice to be able to provide a "perfect" 
answer, for a change. :-)

One suggestion about the above: "description" is actually the exception 
instance (the object), not just the description.  The except statement 
can take two items after: the exception type(s) to catch and, 
optionally, a name to bind to the exception instance.  But since 
exception objects know how to represent themselves as strings, calling 
str() on it gives you the description you wanted.  Therefore it would be 
more readable/correct to say this:

except Exception, ex:
 MsgBox(. str(ex) ... )

But I'm happy it works either way!

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


Re: Converting 2bit hex representation to integer ?

2005-10-21 Thread Peter Hansen
Madhusudan Singh wrote:
> I just tried 
> 
> n=str(x)
> print struct.unpack("b",n)
> 
> I get (51,)
> 
> What is the deal with the parenthesis
> and the comma ?

If you really don't know what the parentheses and comma mean in the 
above output, I would suggest that you need to go back a step and walk 
through the Python tutorial before you try to continue on with what you 
are attempting to do.  (Section 5.3 specifically covers your question.) 
  Either that, or read the documentation on struct.unpack() since that 
describes what it returns fairly clearly.

Assuming your input represents a C-style integer (i.e. fixed size) 
rather than a Python long integer (of arbitrary length), you should be 
able to use just struct.unpack('i', mybinarydata)[0] to get the result 
you need...

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


Re: Python vs Ruby

2005-10-21 Thread Peter Hansen
Bryan wrote:
> Dave Cook wrote:
>> Cale?  You mean Python has more ruffage?
> 
> i think you mean "kale" not "cale".  nothing like a hot bowl of tofu 
> kale soup while reading the recipes in the "python cookbook".

Well, if he's going to talk about "ruffage" instead of "roughage", 
perhaps he really did mean "cale" and not "kale". ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C replacement for Queue module

2005-10-22 Thread Peter Hansen
Jonathan Ellis wrote:
> I'm working on an application that makes heavy use of Queue objects in
> a multithreaded environment.
> 
> By "heavy" I mean "millions of calls to put and get, constituting ~20%
> of the app's run time."  The profiler thinks that a significant amount
> of time is spent in this code -- not just a consumer waiting for a
> producer, but actual _empty, notify calls, etc.

I wonder if the use case would support hand-crafting an alternative. 
Queues appear fairly heavy weight (when you look at the implementation), 
and while they are very robust, if your own needs allow putting many 
items in at the same time, or getting many items out, for example, then 
perhaps you could come up with a much faster alternative based on the 
primitives (e.g. Event, Condition, etc) and perhaps some wrapped data 
structure other than the list that Queues use.

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


Re: Listening for keypress in the background

2005-10-22 Thread Peter Hansen
Mathias Dahl wrote:
> I have created a small Python program that is running on my desktop.
> 
> How can I make it listen for a certain keypress (say, Windows-key +
> space) in a controlled fashion even when it is not the program having
> focus?
> 
> I need to do this running under GNOME in Mandrake GN/Linux 10.

Search Google for "python keylogger".

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


Re: Listening for keypress in the background

2005-10-23 Thread Peter Hansen
Mathias Dahl wrote:
> Peter Hansen <[EMAIL PROTECTED]> writes:
>>>How can I make it listen for a certain keypress (say, Windows-key +
>>>space) in a controlled fashion even when it is not the program having
>>>focus?
>>>
>>>I need to do this running under GNOME in Mandrake GN/Linux 10.
>>
>>Search Google for "python keylogger".
> 
> Thanks, good idea! The relevant pages I found only link to
> Windows-specific keyloggers though.

Oops, you're quite right.  Sorry!  I didn't even read the second 
sentence in your post.  Stupid me...

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


Re: C replacement for Queue module

2005-10-23 Thread Peter Hansen
Jason Lai wrote:
> As far as Queues go, the adding/popping is apparently done with deque
> which are implemented in C. The Queue class pretty much just provides
> blocking operations and is otherwise a very thin layer around deque. As
> far as primitives go, only threading.Lock is written in C and the
> others are pure Python, so they're not that fast, which might be a
> reason for Queue's slowness.

BTW, I didn't mean (or expect) that one could improve significantly on 
Queue's performance in general just by re-writing it.

I meant that if the OP took into account _his own unique situation_, he 
might see opportunities for improvement which Queue couldn't possibly 
provide, given that it's a general purpose tool.  If his own situation 
simply involves a massive number of discrete put/get operations which 
cannot be bundled in any fashion, rewriting the entire Queue in C just 
to avoid the Python method calls (which have high setup overhead) might 
be the only real option.

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


Re: Missing modules '_ssl', 'ext.IsDOMString', 'ext.SplitQName'

2005-10-23 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> i get the following error message when i use py2exe on my application:
> 
> The following modules appear to be missing
> ['_ssl', 'ext.IsDOMString', 'ext.SplitQName']
> 
> I've installed PyXML-0.8.4.win32-py2.4.exe. My version of python is 2.4
> I've checked in the pyxml directories and these modules are not there.
> 
> Anybody have an idea what I'm doing wrong?

Maybe nothing.  Often py2exe will complain about modules which are not 
actually required by the application.

If your code runs and you've tested all areas of it, then you can chalk 
the above up to a "py2exe feature".

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


Re: wxpython - passing arg to wx.app OnInit

2005-10-23 Thread Peter Hansen
Stuart McGraw wrote:
> I have a wxPython app, conventionally structured
> with a Application class derived from wx.App.
> My problem is that the app accepts a command
> line argument that must be acted upon within the
> OnInit() method of the Application class.  How do
> I pass it cleanly from main() into app.OnInit()?  In 
> the simplified example below, dbfn is the piece of 
> info that is in main() that OnInit() needs to use.
> Is a global variable is the only way?  :-(

There are various ways, but the simplest is to accept that sys.argv is
*already* a "global" and just to access it directly from the
Application's OnInit() method.

This wiki page demonstrates:
http://wiki.wxpython.org/index.cgi/UsingCommandLineArguments

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


Re: How to separate directory list and file list?

2005-10-23 Thread Peter Hansen
Gonnasi wrote:
> With
>>glob.glob("*")
> or
>>os.listdir(cwd)
> 
> I can get a combined file list with directory list, but I just wanna a
> bare file list, no directory list. How to get it?

Using Jason Orendorff's path module, it's just this:

 >>> from path import path
 >>> path('.').files()  # returns list of files in current dir


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


Re: bsddb version?

2005-10-23 Thread Peter Hansen
leasun wrote:
> Anybody knows which version bsddb is released with py2.3 and py2.4?

Is this what you wanted?

Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
win32
>>> import bsddb
>>> bsddb.__version__
'4.3.0'

I'll leave it up to you to do the work to find out what it is on
Python2.3...  I hope you can manage the effort. ;-)

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

Re: wxpython - passing arg to wx.app OnInit

2005-10-23 Thread Peter Hansen
Stuart McGraw wrote:
> I simplied the my code for posting.  In my real program, the
> thing being passed is not a command line argument per se,
> but the result of signifigant processing dependent on the 
> command line argument.  I do not want to repeat that 
> processing in the wx.App method.
> Would you elaborate on the other ways?

In that case, override __init__ something like this:

class Application(wx.App):
def __init__(self, *pargs, clargs=None, **kwargs):
self.clargs = clargs or []   # store reference to args

# call parent class initializer
wx.App.__init__(self, *pargs, **kwargs)

   def OnInit(self):
   # use self.clargs here


app = Application(redirect=0, clargs=[dbfn])

or whatever... I just guessed at what you meant to do with dbfn though,
but I think the basic idea is clear enough.

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


Re: testing '192.168.1.4' is in '192.168.1.0/24' ?

2005-10-23 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> Is there standard library modules handling this ? currently I need to
> turn it into a long integer and do the shift and compare.

A little Googling turned up this:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440560

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


Re: testing '192.168.1.4' is in '192.168.1.0/24' ?

2005-10-24 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> thanks, that is basically what I am doing and since it is a recipe, I
> would assume there is no standard library module for it.

Well, since a Google search for "site:docs.python.org subnet" turns up 
nothing, one would assume not, but it would be hard to prove it without 
an exhaustive review of the source code. ;-)

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


Re: output from external commands

2005-10-24 Thread Peter Hansen
Mike Meyer wrote:
> darren kirby <[EMAIL PROTECTED]> writes:
> 
>>If all you want is filenames this will work:
>>
>import glob
>files = ["%s" % f for f in glob.glob("*")]
> 
> 
> What's the point of doing "%s" % f? How is this different from just
> file = [f for f in glob.glob("*")]?

Answering narrowly, the difference is that using "%s" calls str() on the 
items in the result list, while your suggestion does not.  ("Why not 
just use str(f) instead of the less clear '%s' % f?" would be a valid 
question too though.)

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


Re: Tricky Areas in Python

2005-10-24 Thread Peter Hansen
beza1e1 wrote:
> well, list comprehension is Python 2.4 and 2.3 is the standard in many
> OSes, so it is possibly not the most portable solution

You're probably remembering "generator expressions", which were added in 
Python 2.4 and aren't available in earlier versions.  They fit in a 
similar place in one's mind, anyway

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


Re: python cgi script not understood as html

2005-10-24 Thread Peter Hansen
Philippe C. Martin wrote:
> The following code outputs the actual HTML text to the browser, not the
> interpreted text.
> 
> html_ok = """
> Content-Type: text/html\n
>  "http://www.w3.org/TR/html4/loose.dtd";>\n

HTTP header lines must end with \r\n, not just with \n.  Not sure this 
is the solution to your specific problem though...

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


Re: Tricky Areas in Python

2005-10-25 Thread Peter Hansen
Tim Roberts wrote:
> "PyPK" <[EMAIL PROTECTED]> wrote:
>>What possible tricky areas/questions could be asked in Python based
>>Technical Interviews?
> 
> What's the point of asking "tricky" questions?  Aren't you really more
> interested in what applications they have worked on and whether they were
> successful?
> 
> I don't know.  I'm not sure I need a job with a company that insists on
> playing "Programming Jeopardy" during the interview.

That's okay.  Those companies don't need you either. ;-)

Seriously though, the point of asking such questions is that with 
minimal effort they _can_ (not "definitely will") quickly qualify a 
candidate's level of expertise in a language.  Novices, and those who 
while they might have programmed in a language for several years still 
don't really understand it deeply enough to be considered entirely safe 
on their own, will generally trip up on all or most such questions 
(where "trip up" means anything from giving wrong answers to giving you 
the "deer in the headlights" look).  _Anyone_ could trip up on one or 
two of them, especially given the pressure of an interview situation. 
(And even seeing an expert trip up under pressure tells you something 
useful about the candidate.)

In short, a true senior programmer will provide good correct answers to 
most such questions, while those less senior generally will not.

Asking such questions in isolation, without also delving deeply into 
other background such as what applications you've worked on, is just as 
dangerous as asking _only_ about such applications.  I've made the 
mistake of hiring people who had lengthy involvement -- apparently at a 
senior level -- in significant projects, only to discover that they 
clearly didn't understand some basic concepts of the languages 
supposedly used.  My conclusion was that they were in that class of 
people who manage to interview well yet contribute little, but have 
lucked out repeatedly by working for companies who were incompetent at 
terminating for cause (and there are _many_ such companies).  (We didn't 
make the same mistake and fired them reasonably quickly.)

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


Re: more than 100 capturing groups in a regex

2005-10-25 Thread Peter Hansen
Joerg Schuster wrote:
> I just want to use more than 100 capturing groups. If someone told me
> that it is very unlikely for Python to get rid of the said limitation,
> I would recode part of my program in C++ using pcre. 

It is very unlikely for Python to get rid of the said limitation.

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


Re: Missing modules '_ssl', 'ext.IsDOMString', 'ext.SplitQName'

2005-10-25 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> unfortunately the result from py2exe won't run eventhough the original
> script runs without problems. The trouble is I'm at a loss as to where
> to start looking!

Is there no exception traceback printed?  Or some other error when you 
run the .exe?  It would be very unusual to receive no error message of 
any kind.  If you are getting a message, please post the entire 
traceback/message here, as we can only guess what's happening.

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


Re: Execute C code through Python

2005-10-25 Thread Peter Hansen
Ernesto wrote:
> So i generated the .exe file "myFile.exe"
> 
> This is a Windows - text based application.  Right now, when I run:
> 
> import subprocess
> subprocess.call("myFile")
> 
> the application starts in its own console window.  Is there a way for
> it to run inside the python interface?

Google found the following (after I read the docs for subprocess and 
learned about the "startupinfo" flag, and searched for "subprocess 
startupinfo").  Does this help?

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409002

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


Re: more than 100 capturing groups in a regex

2005-10-26 Thread Peter Hansen
Joerg Schuster wrote:
> So what?

Search in http://docs.python.org/lib/re-syntax.html for "99" and read 
the following sentence carefully.

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


Re: Missing modules '_ssl', 'ext.IsDOMString', 'ext.SplitQName'

2005-10-26 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> Hi,
> 
> yes of course the traceback could be helpfull so here it is...
> 
> Traceback (most recent call last):
>   File "App1.py", line 6, in ?
>   File "Frame1.pyc", line 16, in ?
>   File "brain.pyc", line 4, in ?
>   File "xml\dom\ext\reader\__init__.pyc", line 20, in ?
> LookupError: unknown encoding: utf-8

Which version of py2exe are you using?

Does this page help? 
http://starship.python.net/crew/theller/moin.cgi/EncodingsAgain

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


Re: help with sending data out the parallel port

2005-10-27 Thread Peter Hansen
David wrote:
> I'm wondering if python is capable of fairly precise timing and also sending
> data out the parallel port.
> 
> For example ; making a 7.5 KHz square wave come out of one of the data pins
> on the printer port.
> 
> I've tried to help myself with this one but searching in the "Python Library
> Reference" that installed with my version, [ Python 2.4.1. ]  yielded
> nothing on the subject of either timing or parallel port.

What are you trying to use this for?  What kind of jitter does your 
specification allow?  (That is, since you can't get the edge transitions 
exactly 66.6 microseconds apart all the time, how much variation are you 
able to handle?)  What will happen if, say, once every five or ten 
seconds the OS hiccups and prevents your task from running for a full 
second?

Doing this kind of high-speed realtime control on a non-realtime 
operating system is generally difficult or impossible, but it does 
depend on how precise you need to be, and how "soft" your realtime 
requirements are.  My gut feeling is that you cannot achieve what you 
want using Python on Windows (or Linux!), but it depends on your needs, 
not my gut. :-)

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


Re: Counting Threads

2005-10-27 Thread Peter Hansen
David Poundall wrote:
> Just sorted (its always the way when you post isn't it)
> 
> But the count isn't doint what I expected.  I was after a increment
> after every time the class was used ireespective of instance.  

I have no idea what that last sentence above means...

> Instead
> I get a count based on the instance usage.

> Idea's anyone?

Several, interspersed below:

> 
> class ServerThreads:
> """
> Wrapper for thread handling.
> Thread ID 0 = Controller
> Thread ID 1 = Plant Object 1
> Thread ID 2 = Plant Object 2
> """
> 
> GlobalThreadCount = 0

Style note: using MixedCaps for variable names doesn't fit conventional 
Python style.  To be conventional you would use "globalThreadCount" 
here, or just "threadCount" since it's no more "global" than any other 
class attribute.

> def __init__(self):
> global GlobalThreadCount

And here you definitely don't want "global" since your GlobalThreadCount 
above is *not* a Python "global".  It's a class attribute, and you 
should reference it as such:

> self.Threads = {}
> GlobalThreadCount = 0
Change to:
   ServerThreads.GlobalThreadCount = 0

and access it as such in all other places inside the class.

> def launch(self, SubToLaunch, SubsArgs=(), SubsKwargs={},
> AsDeamon=True):
> t = Thread(target=SubToLaunch, args = SubsArgs, kwargs =
> SubsKwargs)
> t.setDaemon(AsDeamon)

You appear to know there is a difference in spelling between these two 
"demons"... but only "daemon" is correct.  "Deamon" is a misspelling.

> t.start()
> self.Threads[len(self.Threads)] = t   # Stash the
> thread in an instance local
> 
> global GlobalThreadCount
> GlobalThreadCount += 1
> print  GlobalThreadCount

Caution: if you can't guarantee that launch() will be called from only 
one thread, you have a race condition here since the count could be 
increased "simultaneously" from multiple threads and you won't get 
reliable results.  You would want to wrap it with a threading.Lock() to 
protect it in that case.

> def globalusagecount(self):
> """
> Returns a count figure for how many threads are running in
> total
> usnig this class.
> """
> global GlobalThreadCount
> return GlobalThreadCount

Style/usage note: although as I mentioned you don't want to use "global" 
  variables anyway, even if you did the above line is unnecessary.  You 
only need to use "global" if you are going to *rebind* the global name 
(i.e. assign a new value to it), not if you are merely reading the value 
and returning it, as above.  What you wrote would work, it's just not 
needed or usual.  (But, again, using a global at all is wrong anyway.)


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


Re: Automatic binding of **kwargs to variables

2005-10-29 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> if name not in expected_form1_kwargs:
> raise ValueError, "Unrecognized keyword" + name
> elif name in expected_form1_kwargs not in kwargs.keys():
> kwargs.update(name=None)

Do you mean this instead?

  elif name in expected_form1_kwargs and name not in kwargs:

What you wrote doesn't do what you think it does...  it actually tests 
for whether True or False is a key in kwargs, depending on whether "name 
in expected_form1_kwargs" returns True or False.

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


Re: Message about not deleted folders using Inno Setup

2005-10-30 Thread Peter Hansen
Martin wrote:
>I would like to place a message in an uninstaller window which will
> inform the user that some folders haven't been deleted. Is that possible 
> using
> Inno Setup?

Probably, but this newsgroup is for discussion of Python.  Unless you 
have some kind of Python angle to your question, a mailing list or 
something for InnoSetup would be a more appropriate place to ask.

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


Re: Xah's edu corner: the Journey of Foreign Characters thru Internet

2005-11-02 Thread Peter Hansen
Mike Meyer wrote:
> Xah Leh is incompetent, but
> apparently well-intentioned. 

In your view is that ("well-intentioned") an established fact at this 
point?  I was still waiting for conclusive evidence.  So far the 
evidence appears rather strongly in favour of a verdict of true 
trollism, which is anything but well-intentioned.

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


Re: Flat file, Python accessible database?

2005-11-02 Thread Peter Hansen
Karlo Lozovina wrote:
> [EMAIL PROTECTED] (=?utf-8?Q?Bj=C3=B6rn_Lindstr=C3=B6m?=) wrote in 
> news:[EMAIL PROTECTED]:
> 
>>If you need it to be SQL-like, SQLite seems to be the right thing.
> 
> Tried that one, but had some problems setting things up. On the other 
> hand, BerkeleyDB + Pybsddb worked like a charm, with no setting up (under 
> Cygwin).

I'm very curious what problems you had.  In my experience SQLite 
requires *nothing* I'd call "setup".  You install Pysqlite or APSW, 
write your code, and it runs and works.  There are no configuration 
steps required, nothing but creating tables (and that's a standard step 
with any SQL-like database).  What environment were you using, and what 
kind of issues did you encounter?  (I ask because I often recommend 
SQLite, but would like to temper that advice if in some cases these 
setup problems would cause someone trouble.)

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


Re: callback for ctypes

2005-11-02 Thread Peter Hansen
David Wahler wrote:
> Also, I can't find any references for this "QImage Camera". Could you
> post some additional information?

Trying "Qimaging" instead.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Importing Modules

2005-11-02 Thread Peter Hansen
Walter Brunswick wrote:
> What is the best way to import all modules in a directory 
 > (and possibly a subdirectory/subdirectories), possibly including
> conditionals, such as regexes? 

The "best" was, as always, depends on what your use case is.  Why do you 
want to do this?  What will you do with the modules once they are imported?

Also: the second part of the question doesn't mean anything to me.  What 
do you mean by "conditionals, such as regexes", in the context of 
importing modules?

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


Re: Importing Modules

2005-11-02 Thread Peter Hansen
Walter Brunswick wrote:
> The purpose is rather irrelevant. 

The purpose of something is not only relevant but essential when someone 
asks for the "best" way to do it.

For example, without knowing anything of your purpose, I could simply 
say that writing a module with a series of import statements, one per 
module in the target subdirectory, is the "best" way, and I could easily 
defend that as "best" against all other possible approaches until we 
knew what the real reason for doing this was.

(Your extra detail on the regex thing makes it clear that the above 
approach would not be "best", but I think that just goes to show that 
until we know why you want this, we cannot possibly answer your question 
properly.)

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


Re: Py2Exe produced "binary" shows terminal screen on execution

2005-11-02 Thread Peter Hansen
Thomas W wrote:
> I've produced a "binary" version of a python-script using Py2Exe and
> when run on WinXP it shows a terminal window for a brief moment then
> the window disappears. How can I avoid this? I want the script to run
> without being visible at all.

You probably used the "console" option?  See this page 
(http://www.py2exe.org/) for information about the alternate "windows" 
option where it says:

'''The above setup script creates a console program, if you want a GUI 
program without the console window, simply replace 
console=["myscript.py"] with windows=["myscript.py"].'''

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


Re: Flat file, Python accessible database?

2005-11-02 Thread Peter Hansen
Steve Holden wrote:
> My experience on Cygwin was that I had to install sqlite before pySqlite 
>  worked. 

So although the Windows install of Pysqlite bundles a .pyd that includes 
the statically linked sqlite library, other platforms do not?  I agree 
that would represent a potentially annoying extra setup step.

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


Re: reading internet data to generate random numbers.

2005-11-02 Thread Peter Hansen
Levi Campbell wrote:
> Hi, I'm working on a random number generator using the internet as a
> way to gather entropy, I have two questions.
> 
> 1. is there a way to capture the internet stream?

What specifically do you mean by the term "internet stream" here? 
Generally speaking, the internet is not "streamed" at all, but perhaps 
you have some special meaning in mind that isn't in general use.

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


Re: Hexadecimal Conversion in Python

2005-11-02 Thread Peter Hansen
DaBeef wrote:
> I have been coding for 5 years.  This is a proprietary protocol, so it
> is difficult converting.  I did this in java but was just able to
> convert a stream.  

What exactly did you do in Java to get the results you want?

Python's library is certainly *not* "limited" in this area, so if you 
can describe clearly enough what you want we can certainly help. 
Showing an example of Java code that does the job might be a more 
successful way of communicating your goals to us.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to write a blog system with Python

2005-11-02 Thread Peter Hansen
ice wrote:
> I am a fresh here , and I have no idea of it.
> Do you have any comments?

Why do you want to write your own system?  There are already lots of
blog programs written in Python which you could just use, or customize.

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

Re: reading internet data to generate random numbers.

2005-11-03 Thread Peter Hansen
Steven D'Aprano wrote:
> On Thu, 03 Nov 2005 15:51:30 +, Grant Edwards wrote:
>>
>>I've never heard of anybody using the data as source of
>>entropy.  
> 
> Me neither, but the original poster did ask how to read every nth byte
> of "the Internet stream", so I assumed he had something like that in mind.

And to think that if you'd just waited for the OP to explain what the 
heck he meant by "the Internet stream", you'd have saved ever so much 
time.  ;-)

(But then, if we always did that Usenet wouldn't be any fun.)

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


Re: Can Anyone Help me on this

2005-11-03 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> i m trying to reverse the order in which the
> strings are stored in list
> 
> then pop it into another list
> 
> what m i doin worng??
> 
> here's the code:
> 
> list1 = []
> list2 = []
> list1.extend('123456789')

How about this instead (Python 2.4 or later):

list2 = list(reversed('123456789'))

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


Re: reading internet data to generate random numbers.

2005-11-03 Thread Peter Hansen
Steven D'Aprano wrote:
> On Thu, 03 Nov 2005 16:40:43 -0500, Peter Hansen wrote:
>>Steven D'Aprano wrote:
>>
>>>On Thu, 03 Nov 2005 15:51:30 +, Grant Edwards wrote:
>>>
>>>>I've never heard of anybody using the data as source of
>>>>entropy.  
>>>
>>>Me neither, but the original poster did ask how to read every nth byte
>>>of "the Internet stream", so I assumed he had something like that in mind.
>>
>>And to think that if you'd just waited for the OP to explain what the 
>>heck he meant by "the Internet stream", you'd have saved ever so much 
>>time.  ;-)
> 
> Has he done so yet? I can't see it anywhere.

He hasn't, so you'd _still_ be saving time. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: putting an Icon in "My Computer"

2005-11-03 Thread Peter Hansen
yaipa wrote:
> I've been asked by my boss to put an Icon in WinXP's "My Computer" for
> a utility we use around the shop.  My tool of choice is of course
> Python and therefore what I am using to attempt my given task.  I have
> no trouble putting Icons in the WinXP Toolbar using Python, but have
> totally failed to get an Icon to appear in My Computer.  Any Idea on
> why and maybe how to get around this using Python? 

How would you do this if you were not using Python?

(Hint, if the answer is "I have no idea", then it's usually an 
indication that this is not a Python issue, and that you should be 
seeking your answer in a Windows-specific forum, or maybe in the 
documentation on Microsoft's web site.  Then, once you know what API or 
registry settings are required to set this up, you can generally map 
that easily to the pywin32 stuff or maybe ctypes using Python.)

(Of course, you might also luck out, as people often do, since there are 
real Windows expert types hanging out here and they might help you out 
anyway.)

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


Re: how to call basic browser functions?

2005-11-04 Thread Peter Hansen
BLElliott wrote:
> I think this is a very basic question, so feel free to direct me to a 
> FAQ or other resource to go and get myself educated, if that's the best 
> answer.
> 
> Can I perform web browser functions from a script, for example, doing 
> file downloads, if I can construct the file URL within my script?  As an 
> example, suppose there's a file I download periodically, but its URL 
> changes with the current date.  If I can write a script that will 
> automatically generate the URL, can it then go and fetch the file for me?

Yes, you can definitely do that.  Look for examples of using "urllib" or 
"urllib2".  There should be many that are close to the sort of thing you 
want.  Or you could simply use a command line utility such as "wget" to 
accomplish much the same thing and avoid almost any programming.

(Note that if in addition to downloading the actual contents of the 
page, you will require more sophisticated features of a real browser, 
such as Javascript or Java execution, you'll need capabilities far 
beyond what urllib2 can provide.  And you probably don't want to go 
there right now.)

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


Re: Python doc problem example: gzip module (reprise)

2005-11-05 Thread Peter Hansen
Jeffrey Schwab wrote:
> Xah Lee wrote:
> 
>> i've read the official Python tutorial 8 months ago, have spent 30
>> minutes with Python 3 times a week since, have 14 years of computing
>> experience, 8 years in mathematical computing and 4 years in unix admin
>> and perl
> 
> I can wiggle my ears.

Which is almost as good as having spent, um, let's see... a grand total 
of 52 hours attempting to code in Python!  Which is to say roughly one 
week with a little overtime.

I've had a large number of co-op students and junior programmers come on 
board in a Python/agile group.  I've said here before that most of them 
were able to code reasonably in Python after only about one week, at 
least enough to contribute and participate.  Several took a few weeks to 
completely abandon their bad habits from other languages (e.g. coding 
"C"-style iterate-over-chars-in-a-string loops in Python).

Of course, most of them had a basic competence and ability to learn, so 
maybe for them 52 hours was much more effective than it is for others. 
Still, 52 hours is "nothing"... and doing it as "30 minutes, 3 times a 
week, for 8 months" vastly decreases the value of those 52 hours, even 
if it makes it sound much more impressive.  I'm not surprised now at 
what we keeping seeing here...

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


  1   2   3   4   5   6   7   8   9   10   >