Re: [perl-python] 20050113 looking up syntax

2005-01-14 Thread Erik Max Francis
Peter Hansen wrote:
So why duplicate the posts by posting them to the newsgroups?
Because he's a well-known pest.
--
Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
  Yes I'm / Learning from falling / Hard lessons
  -- Lamya
--
http://mail.python.org/mailman/listinfo/python-list


Re: XPath and XQuery in Python?

2005-01-14 Thread Uche Ogbuji
Interesting discussion.  My own thoughts:

http://www.oreillynet.com/pub/wlg/6224
http://www.oreillynet.com/pub/wlg/6225

Meanwhile, please don't make the mistake of bothering with XQuery.
It's despicable crap.  And a huge impedance mismatch with Python.
--Uche

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


Re: porting C code

2005-01-14 Thread Peter Hansen
Lucas Raab wrote:
Sorry, the third "byte" is what I meant. 
Fair enough.  Note, however, that as someone pointed out,
it's actually the *fourth* of something, and it would not
necessarily be a byte.  In fact, in your case, it's not:
typedef   unsigned long int  word32 ;
void mu(word32 *a)
{
int i ;
word32 b[3] ;
This defines an array of *3* long (32-bit) integers.
b[0] = b[1] = b[2] = 0 ;
Each of these is just indexing into that array, starting
as Python does with an index origin of zero.
The "a[#]" and "b[#]" are the parts that are giving me trouble.
Between the clarifications you've got and Duncan's post,
you shouldn't have much more trouble now. :-)
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: finding/replacing a long binary pattern in a .bin file

2005-01-14 Thread John Lenton
On Wed, Jan 12, 2005 at 10:36:54PM -0800, yaipa wrote:
> What would be the common sense way of finding a binary pattern in a
> .bin file, say some 200 bytes, and replacing it with an updated pattern
> of the same length at the same offset?
> 
> Also, the pattern can occur on any byte boundary in the file, so
> chunking through the code at 16 bytes a frame maybe a problem.  The
> file itself isn't so large, maybe 32 kbytes is all and the need for
> speed is not so great, but the need for accuracy in the
> search/replacement is very important.

ok, after having read the answers, I feel I must, once again, bring
mmap into the discussion. It's not that I'm any kind of mmap expert,
that I twirl mmaps for a living; in fact I barely have cause to use it
in my work, but give me a break!  this is the kind of thing mmap
*shines* at!

Let's say m is your mmap handle, a is the pattern you want to find,
b is the pattern you want to replace, and n is the size of both a and
b.

You do this:

  p = m.find(a)
  m[p:p+n] = b

and that is *it*. Ok, so getting m to be a mmap handle takes more work
than open() (*) A *lot* more work, in fact, so maybe you're justified
in not using it; some people can't afford the extra

  s = os.stat(fn).st_size
  m = mmap.mmap(f.fileno(), s)

and now I'm all out of single-letter variables.

*) why isn't mmap easier to use? I've never used it with something
other than the file size as its second argument, and with its access
argument in sync with open()'s second arg.

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
If the aborigine drafted an IQ test, all of Western civilization would
presumably flunk it.
-- Stanley Garn


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Com port interrupts again

2005-01-14 Thread Peter Hansen
engsol wrote:
I didn't fully think through my application before posting my
question. Async com port routines to handle com port interrups
only work well if one has access to the low level operating
system. In that case the receive buffer interrupt would cause
a jump to an interrupt service routine.. I don't believe that
Python provides that capabilty directly. The solution then would
be to write a C extention?
Maybe, but I doubt that you can or would really want to do this
with modern operating systems anyway.  With DOS, and similar
primitive things, glomming onto an interrupt or hooking yourself
into the interrupt table was pretty easy.  I don't think either
Windows or Linux is structured such that you just "write a
C extension" to intercept interrupts.  Instead, you must write
relatively complicated drivers which have to be loaded at
system startup (more or less) and be tied into the kernel at
a relatively low level.  Think "rocket science", at least in
comparison to writing a simple C extension. :-)
The suggestions offered by respondents to my original post
were almost all of a "Use threads, and poll as needed" flavor.
You're right...I need to learn threads as applied to com ports.
At least on Windows, I'm fairly sure you can configure the
read timeouts so that you get behaviour on reads that for
all intents and purposes is about as good as an interrupt,
without the difficulties inherent in that approach, but
provided you are willing to dedicate a thread to the task.
On Linux, it's possible the read timeouts capabilities are
a little less flexible (but I've only just barely glanced
at this area), but as I recall you were on Windows anyway.
BTW, another post pointed you to USPP.  As far as I know,
it hasn't been updated recently and, while I can't say how
it compares to PySerial, I believe it's fair to say at
this point in time that PySerial is the _de facto_ standard
way to do serial port stuff in Python.  If it doesn't do
what you need, it's probably a good idea to at least point
that out in its mailing list so that it can be improved.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python.org, Website of Satan

2005-01-14 Thread Stephen Waterbury
Michael Hoffman wrote:
Denis S. Otkidach wrote:
Certainly, it can be done more efficient:
Yes, of course. I should have thought about the logic of my code before 
posting. But I didn't want to spend any more time on it than I had to. ;-)
Bah, you satanic types are so lazy.
--
http://mail.python.org/mailman/listinfo/python-list


Re: finding/replacing a long binary pattern in a .bin file

2005-01-14 Thread Bengt Richter
On 14 Jan 2005 15:40:27 -0800, "yaipa" <[EMAIL PROTECTED]> wrote:

>Bengt, and all,
>
>Thanks for all the good input.   The problems seems to be that .find()
>is good for text files on Windows, but is not much use when it is
>binary data.  The script is for a Assy Language build tool, so I know
Did you try it? Why shouldn't find work for binary data?? At the end of
this, I showed an example of opening and modding a text file _in binary_.

 >>> s= ''.join(chr(i) for i in xrange(256))
 >>> s
 
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\
 x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>[EMAIL PROTECTED]
 
cdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f
 
\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7
 
\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf
 
\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7
 
\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef
 \xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'
 >>> for i in xrange(256):
 ... assert i == s.find(chr(i))
 ...
 >>>

I.e., all the finds succeded for all 256 possible bytes. Why wouldn't you think 
that would work fine
for data from a binary file? Of course, find is case sensitive and fixed, not a 
regex, so it's
not very flexible. It wouldn't be that hard to expand to a list of old,new 
pairs as a change spec
though. Of course that would slow it down some.


>the exact seek address  of the binary data that I need to replace, so
>maybe I'll just go that way.  It just seemed a little more general to
>do a search and replace rather than having to type in a seek address.
Except you run the risk of not having a unique search result, unless you
have a really guaranteed unique pattern.
>
>Of course I could use a Lib function to convert the binary data to
>ascii and back, but seems a little over the top in this case.
I think you misunderstand Python strings. There is no need to "convert" the 
result
of open(filename, 'rb').read(chunksize). Re-read the example below ;-)
[...]
>>
>> If you wanted to change a binary file, you'd use it something like
 ^^^
>(although probably let
>> the default buffer size be at 4096, not 20, which is pretty silly
>other than demoing.
>> At least the input chunks are 512 ;-)
>>
>>  >>> from sreplace import sreplace
>>  >>> fw = open('sreplace.py.txt','wb')
opens a binary output file

>>  >>> for buf in sreplace(iter(lambda
>f=open('sreplace.py','rb'):f.read(512), ''),'out','OUT',20):
iter(f, sentinel) is the format above. I creates an iterator that
keeps calling f() until f()==sentinel, which it doesn't return, and 
that ends the sequence
f in this case is lambda f=open(inputfilename):f.read(inputchunksize) 
and the sentinel is '' -- which is what is returned at EOF.
The old thing to find was 'out', to be changed to 'OUT', and the 20 was 
a silly small
return chunks size for the sreplace(...) iterator. Alll these chunks 
were simply passed
to
>>  ... fw.write(buf)
>>  ...
>>  >>> fw.close()
and closing the file explicitly wrapped it up.
>>  >>> ^Z

I just typed that in interactively to demo the file change process with the 
source itself,  so the diff
could show the changes. I guess I should have made sreplace.py runnable as a 
binary file updater, rather
than a cute demo using command line text. The files are no worry, but what is 
the source of your old
and new binary patterns that you want use for find and replace? You can't enter 
them in unescaped format
on a command line, so you may want to specify them in separate binary files, or 
you could specify them
as Python strings in a module that could be imported. E.g.,

---< old2new.py >--
# example of various ways to specify binary bytes in strings
from binascii import unhexlify as hex2chr
old = (
'This is plain text.'
+ ''.join(map(chr,[33,44,55, 0xaa])) + '<<-- arbitrary list of binary bytes 
specified in numerically if desired'
+ chr(33)+chr(44)+chr(55)+ '<<-- though this is plainer for a short sequence'
+ hex2chr('4142433031320001ff') + r'<<-- should be ABC012\x00\x01\xff'
)

new = '\x00'*len(old) # replace with zero bytes
---

BTW: Note: changing binaries can be dangerous! Do so at your own risk!!
And this has not been tested worth a darn, so caveat**n.

---< binfupd.py >--
from sreplace import sreplace
def main(infnam, outfnam, old, new):
infile = open(infnam, 'rb')
inseq = iter(lambda: infile.read(4096), '')
outfile = open(outfnam, 'wb')
try:
try:
for buf in sreplace(inseq, old, new):
outfile.write(buf)
finally:
infile.close()
outfile.clo

Re: import keyword behaviour - performance impact if used multiple times?

2005-01-14 Thread Nick Coghlan
neophyte wrote:
Nick Coghlan wrote:
> Is
> this something to do with system modules being singletons?
They aren't singletons in the GoF design pattern sense. However,
Python's import
machinery operates in such a way that it takes effort to get multiple
version of
the same module into memory at the same time (it *can* be done, but
you have to
work at it).
Given that this is exactly what I want, how can you do it?
If you just want to reload an existing module, use the builtin "reload" 
function.
Getting multiple versions of a module into sys.modules at the same time isn't 
something I've ever actually wanted to do, but the following will do it:

Py> import sys
Py> sys.modules["sys1"] = sys
Py> del sys.modules["sys"]
Py> import sys
Py> import sys1
Py> sys is sys1
False
However:
1. Doing this at all is probably a bad idea (since you may end up duplicating 
objects that are meant to be unique within the process, and any C-extension code 
will still be shared between the multiple versions of the module)
2. Doing it to 'sys' like I just did is an even worse idea, since you 
*definitely* end up doing 1 :)

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


[perl-python] 20050114 if statement

2005-01-14 Thread Xah Lee
. # here's an example of if statement in python.
.
. x=-1
. if x<0:
.  print 'neg'
. elif x==0:
.  print 'zero'
. elif x==1:
.  print 'one'
. else:
.  print 'other'
.
. # the elif can be omitted.
. --
. # here's an example of if statement in perl
.
. $x=31;
. if ($x<0) {
. print 'neg'
. } elsif ($x==0) {
. print 'zero'
. } elsif ($x==1) {
. print 'one'
. } else {
. print 'other'
. }
.
.
. ---
.
. Note: this post is from the Perl-Python a-day mailing list at
. http://groups.yahoo.com/group/perl-python/
. to subscribe, send an email to [EMAIL PROTECTED]
. if you are reading it on a web page, program examples may not run
. because html conversion often breaks the code.
.
.   Xah
.   [EMAIL PROTECTED]
.   http://xahlee.org/PageTwo_dir/more.html

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


Re: Python Operating System???

2005-01-14 Thread JanC
jtauber schreef:

> see http://cleese.sourceforge.net/

There is not much to see there, most of the wiki is filled with spam...

-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threading Or Other Suggestions?!?

2005-01-14 Thread chrisg
You could also use os.spawnl to launch it in a separate process.

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


Re: Python.org, Website of Satan

2005-01-14 Thread Michael Hoffman
Denis S. Otkidach wrote:
Certainly, it can be done more efficient:
Yes, of course. I should have thought about the logic of my code before 
posting. But I didn't want to spend any more time on it than I had to. ;-)
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Re: query python env

2005-01-14 Thread Michael Hoffman
Steve Holden wrote:
I suspect rather that the OP is looking for os.environ, as in:
He was using the examples of PYTHONHOME and PYTHONPATH which have 
specific meanings. Using sys.prefix is better than 
os.environ["PYTHONHOME"], which is unlikely to be set.
--
Michael Hoffman
--
http://mail.python.org/mailman/listinfo/python-list


Looking for a few badass Python coders (Chicago).

2005-01-14 Thread Wendell III
Hello everyone,
I am currently involved with a project involving instant messengers and 
social networks. We really need some talented individuals to help our 
team out with some Python code. Your work would be open sourced, and 
you would be credited in the application itself. Compensation is 
negotiable. Feel free to send a CV, but (to be fair) I am primarily 
interested/most enthralled in/by the idea of taking a look at your best 
work.

Individuals in the Chicagoland area greatly preferred. ;-)
Looking forward,
-Wendell
--
ph: 773.880.1282 fx: 866.805.2744  icq: 12107743 aim: zephyrwendell
gg: 7116285  y!: zephyrwendell  web: http://www.zephyrsyndicate.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python.org, Website of Satan

2005-01-14 Thread Brian Eable
"mr_little" <[EMAIL PROTECTED]> writes:

> Brian Eable wrote:
> > perl -e '$a="194.109.137.226"; @a = reverse split /\./, $a; for $i
> (0..3) { $sum += $a[$i]*(256**$i) } print "sum = $sum\n"'
> >
> > 226 + 35072 + 7143424 + 3254779904 = 3261958626
> >
> > http://3261958626/
> >
> > Which is NOT 666.
>
> Comrade, why perl here? :)

Huh? Alt.prophecies.nostradamus is ALL ABOUT PERL!

   And at the end of the age
   There shall be a mysterious language
   Filled with punctuation
   It will connect many things.

> Are you afraid python? :)

I asked you to stop calling me python.

Feel free to write a python version if you want to.


-- 
   It's explained on my website.. but you have to have a bona fide degree
in science to understand it Mr. Ruken Dukin Kookin. -- George Hammond
  http://beable.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Handling fractions of seconds in strftime/strptime

2005-01-14 Thread skip
I'm looking for a solution (or ideas about a solution) to the problem
that strftime(3) and strptime(3) don't understand time increments of
less than one second.  Most operating systems can provide times with
subsecond resolution and like Python I'm pretty sure Ruby, Perl and
Tcl have objects or packages that can manipulate such times in a sane
manner.  I'm casting my net to a broader community than just Python
(where I generally hang out) to see if/how others have addressed this
problem.

Here's my typical use case.  I generate log files with subsecond
resolution using Python's datetime module.  By default it generates
printable timestamps in an ISO format that includes fractions of
seconds, e.g., "2005-01-14 18:56:54.546607".  I often need to parse
such times, and therein lies the rub.  Python's date parsing is based
on strptime(3) which can't handle fractions of seconds.  I wind up
worming around the problem with a little hackery, but it bothers me
that given an otherwise complete solution to formatting and parsing
times I can't handle this common (for me) case.

I realize that other languages may not base their current time
formatting and parsing on strftime(3) and strptime(3), but I suspect
those two functions were at least the root of what is commonly used by
most languages.  In my investigation I came across a DateTime module
in Perl that uses "%N" (or optionally "%nN" where n is a digit) to
identify integers as nanoseconds or some other subsecond time.  I
belive "%3N" would cause "123" to be interpreted as 123 milliseconds,
for instance.  I've considered extending "%S" to accept fractional
seconds or adding a new format specifier like "%F" to handle this
case.

I'm interested to know what solutions have been devised or considered
for other languages.  (Has this been addressed in some more recent
version of the C or C++ standards I'm unaware of?) Rather than
reinventing the wheel I'd like to adopt an existing solution if
possible. At the very least I'd like to know how others have
approached the problem.  I think there's an opportunity to add some
value that everyone can take advantage of.
Thanks for your time,

Skip Montanaro
[EMAIL PROTECTED]

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


Re: Why 'r' mode anyway?

2005-01-14 Thread Tim Peters
[Tim Peters]
>> That differences may exist is reflected in the C
>> standard, and the rules for text-mode files are more restrictive
>> than most people would believe.

[Irmen de Jong]
> Apparently. Because I know only about the Unix <-> Windows
> difference (windows converts \r\n <--> \n when using 'r' mode,
> right).  So it's in the line endings.

That's one difference.  The worse difference is that, in text mode on
Windows, the first instance of chr(26) in a file is taken as meaning
"that's the end of the file", no matter how many bytes may follow it. 
That's fine by the C standard, because everything about a text-mode
file containing a chr(26) character is undefined.

> Is there more obscure stuff going on on the other systems you
> mentioned (Mac OS, VAX) ?

I think on Mac Classic it was *just* line end differences.  Native VAX
has many file formats.  "Record-based" file formats used to be very
popular.  There the OS saves meta-information in the file, such as
each record contains an offset to the start of the next record, and
may even contain an index structure to support random access to
records quickly (for example, "a line" may be a record, and "read the
last line" may go quickly).  Read that in binary mode, and you'll be
reading up the bits in the index and offsets too, etc.  IIRC, Unix was
actually quite novel at the time in insisting that all files were just
raw byte streams to the OS.

> (That means that the bug in Simplehttpserver that my patch
> 839496 addressed, also occured on those systems? Or that
> the patch may be incorrect after all??)

Don't know, and (sorry) no time to dig.

> While your argument about why Python doesn't use its own
> platform- independent file format is sound of course, I find it often
> a nuisance that platform specific things tricle trough into Python
> itself and ultimately in the programs you write. I sometimes feel
> that some parts of Python expose the underlying C/os
> implementation a bit too much. Python never claimed write once
> run anywhere (as that other language does) but it would have
> been nice nevertheless ;-)
> In practice it's just not possible I guess.

It would be difficult at best.  Python hides a lot of platform crap,
but generally where it's reasonably easy to hide.  It's not easy to
hide native file conventions, partly because Python wouldn't play well
with *other* platform software if it did.

Remember that Guido worked on ABC before Python, and Python is in
(small) part a reaction against the extremes of ABC.  ABC was 100%
platform-independent.  You could read and write files from ABC.
However, the only files you could read from ABC were files that were
written by ABC -- and files written by ABC were essentially unusable
by other software.  Socket semantics were also 100% portable in ABC: 
it didn't have sockets, nor any way to extend the language to add
them.  Etc -- ABC was a self-contained universe.  "Plays well with
others" was a strong motivator for Python's design, and that often
means playing by others' rules.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: finding/replacing a long binary pattern in a .bin file

2005-01-14 Thread yaipa
Bengt, and all,

Thanks for all the good input.   The problems seems to be that .find()
is good for text files on Windows, but is not much use when it is
binary data.  The script is for a Assy Language build tool, so I know
the exact seek address  of the binary data that I need to replace, so
maybe I'll just go that way.  It just seemed a little more general to
do a search and replace rather than having to type in a seek address.

Of course I could use a Lib function to convert the binary data to
ascii and back, but seems a little over the top in this case.

Cheers,

--Alan


Bengt Richter wrote:
> On Thu, 13 Jan 2005 11:40:52 -0800, Jeff Shannon <[EMAIL PROTECTED]>
wrote:
>
> >Bengt Richter wrote:
> >
> >> BTW, I'm sure you could write a generator that would take a file
name
> >> and oldbinstring and newbinstring as arguments, and read and yield
nice
> >> os-file-system-friendly disk-sector-multiple chunks, so you could
write
> >>
> >> fout = open('mynewbinfile', 'wb')
> >> for buf in updated_file_stream('myoldbinfile','rb',
oldbinstring, newbinstring):
> >> fout.write(buf)
> >> fout.close()
> >
> >What happens when the bytes to be replaced are broken across a block

> >boundary?  ISTM that neither half would be recognized
> >
> >I believe that this requires either reading the entire file into
> >memory, to scan all at once, or else conditionally matching an
> >arbitrary fragment of the end of a block against the beginning of
the
> >oldbinstring...  Given that the file in question is only a few tens
of
> >kbytes, I'd think that doing it in one gulp is simpler.  (For a
large
> >file, chunking it might be necessary, though...)
> >
> Might as well post this, in case you're interested... warning, not
very tested.
> You want to write a proper test? ;-)
>
> < sreplace.py >-
> def sreplace(sseq, old, new, retsize=4096):
> """
> iterate through sseq input string chunk sequence treating it
> as a continuous stream, replacing each substring old with new,
> and generating a sequence of retsize returned strings, except
> that the last may be shorter depedning on available input.
> """
> inbuf = ''
> endsseq = False
> out = []
> start = 0
> lenold = len(old)
> lennew = len(new)
> while not endsseq:
> start, endprev = old and inbuf.find(old, start) or -1, start
> if start<0:
> start = endprev  # restore find start pos
> for chunk in sseq: inbuf+= chunk; break
> else:
> out.append(inbuf[start:])
> endsseq = True
> else:
> out.append(inbuf[endprev:start])
> start += lenold
> out.append(new)
> if endsseq or sum(map(len, out))>=retsize:
> s = ''.join(out)
> while len(s)>= retsize:
> yield s[:retsize]
> s = s[retsize:]
> if endsseq:
> if s: yield s
> else:
> out = [s]
>
> if __name__ == '__main__':
> import sys
> args = sys.argv[:]
> usage = """
> Test usage: [python] sreplace.py old new retsize [rest of
args is string chunks for test]
> where old is old string to find in chunked stream and new
is replacement
> and retsize is returned buffer size, except that last may
be shorter"""
> if not args[1:]: raise SystemExit, usage
> try:
> args[3] =  int(args[3])
> args[0] = iter(sys.argv[4:])
> print '%r\n---\n%s\n' %(sys.argv[1:],
'\n'.join(sreplace(*args[:4])))
> except Exception, e:
> print '%s: %s' %(e.__class__.__name__, e)
> raise SystemExit, usage
> 
>
> As mentioned, not tested very much beyond what you see:
>
> [ 2:43] C:\pywk\ut>py24 sreplace.py x _XX_  20 This is x and abcxdef
012x345 zzxx zzz x
> ['x', '_XX_', '20', 'This', 'is', 'x', 'and', 'abcxdef', '012x345',
'zzxx', 'zzz', 'x']
> ---
> Thisis_XX_andabc_XX_
> def012_XX_345zz_XX__
> XX_zzz_XX_
> 
>
> [ 2:43] C:\pywk\ut>py24 sreplace.py x _XX_  80 This is x and abcxdef
012x345 zzxx zzz x
> ['x', '_XX_', '80', 'This', 'is', 'x', 'and', 'abcxdef', '012x345',
'zzxx', 'zzz', 'x']
> ---
> Thisis_XX_andabc_XX_def012_XX_345zz_XX__XX_zzz_XX_
> 
>
> [ 2:43] C:\pywk\ut>py24 sreplace.py x _XX_  4  This is x and abcxdef
012x345 zzxx zzz x
> ['x', '_XX_', '4', 'This', 'is', 'x', 'and', 'abcxdef', '012x345',
'zzxx', 'zzz', 'x']
> ---
> This
> is_X
> X_an
> dabc
> _XX_
> def0
> 12_X
> X_34
> 5zz_
> XX__
> XX_z
> zz_X
> X_
> 
>
> [ 2:44] C:\pywk\ut>py24 sreplace.py def DEF 80 This is x and abcxdef
012x345 zzxx zzz x
> ['def', 'DEF', '80', 'This', 'is', 'x', 'and', 'abcxdef', '012x345',
'zzxx', 'zzz', 'x']
> ---
> ThisisxandabcxDEF012x345zzxxzzzx
> 
>
> I

Re: What strategy for random accession of records in massive FASTA file?

2005-01-14 Thread Roy Smith
In article <[EMAIL PROTECTED]>,
 "Chris Lasher" <[EMAIL PROTECTED]> wrote:

> Hello,
> I have a rather large (100+ MB) FASTA file from which I need to
> access records in a random order. The FASTA format is a standard format
> for storing molecular biological sequences. Each record contains a
> header line for describing the sequence that begins with a '>'
> (right-angle bracket) followed by lines that contain the actual
> sequence data. Three example FASTA records are below:
> 
> >CW127_A01
> TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAGTGGCGGACGGGTGAGTAATG
> TATAGTTAATCTGCCCTTTAGAGATAACAGTTGGAAACGACTGCTAATAATA
> GCATTAAACAT
> >CW127_A02
> TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAGTGGCGGACGGGTGAGTAATG
> TATAGTTAATCTGCCCTTTAGAGATAACAGTTGGAAACGACTGCTAATAATA
> GCATTAAACATTCCGCCTAGTACGGTCGCAAGATTCTCAAAGGAATAGACGG
> >CW127_A03
> TGCAGTCGAACGAGAACGGTCCTTCGGGATGTCAGCTAAGTGGCGGACGGGTGAGTAATG
> TATAGTTAATCTGCCCTTTAGAGATAACAGTTGGAAACGACTGCTAATAATA
> GCATTAAACATTCCGCCTGGG
> ...
> 
> Since the file I'm working with contains tens of thousands of these
> records, I believe I need to find a way to hash this file such that I
> can retrieve the respective sequence more quickly than I could by
> parsing through the file request-by-request.

First, before embarking on any major project, take a look at 
http://www.biopython.org/ to at least familiarize yourself with what 
other people have done in the field.

The easiest thing I think would be to use the gdbm module.  You can 
write a simple parser to parse the FASTA file (or, I would imagine, find 
one already written on biopython), and then store the data in a gdbm 
map, using the tag lines as the keys and the sequences as the values.  

Even for a Python neophyte, this should be a pretty simple project.  The 
most complex part might getting the gdbm module built if your copy of 
Python doesn't already have it, but gdbm is so convenient, it's worth 
the effort.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class initialization from a dictionary, how best?

2005-01-14 Thread Bengt Richter
On 14 Jan 2005 07:32:06 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

>Yes, my examle here is a tiny part of a larger more complex issue. My
>application is an DOM XML parser that is reading attributes one at a
you mean like blah blah and you are
grabbing things of interest out of a stream of info you are getting
from call-backs? Or the equivalent?
>time. My class that I am creating is used elsewhere and must have
>certain arguments for those uses to continue working. So, I seem to be
>left with creating an intermediate object. Before, I was simply
Unless the "intermediate object" accumulates information for multiple
Test() instances, why couldn't t= Test() be its own "intermediate object"?

If you are accumulating info for multiple instances before creating them
it is not clear from your description.

>creating an object:
>
>t = Test()
>for attr_name in mapping.keys():
>setattr(t, attr_name, value_from_source)
>
>This I feel was ellegant, efficient and clear. However, what I have now
>works but is not clear.
>BTW, t1 is just for example and was just being printed

What about giving Test some methods to do what you'd like? E.g., a micro-step
in that direction from the above would let you write

t = Test()
...
t.load_info(infosource)

Then the question becomes what infosource should be, or whether you really
need it at all. IOW, if you are doing infosource.add_info(info_id, info_value)
why couldn't you do t.add_info(info_id, info_value), unless you have to
do t2.add_info(...) alternately with t.add_info(...), and if that's the case,
what is the criterion for choosing t vs t2? Maybe that could be done by 
something
that automatically manufactures t's as needed in a pool of partially complete 
t's.

But your real requirements are not clear enough here, so you may get help 
crossing
a stream, but no one will be able to say you are already on the side of the 
stream
you want to be later, and there's an easy path without need of crossing twice 
;-)

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: (objects as) mutable dictionary keys

2005-01-14 Thread Steven Bethard
Peter Maas wrote:
I have summarized the discussion about the usability of lists (and
and other mutable types) as dictionary keys and put it into the
Python wiki.URL: http://www.python.org/moin/DictionaryKeys.
Antoon Pardon wrote:
> I had a look and I think you should correct the followingr:
>
>   Dictionary lookup with mutable types like lists is a source of
>   unpleasant surprises for the programmer and therefore impossible in
>   Python.
>
> It is not impossible in Python. It may be discouraged but it is not
> impossible since I have already done so.
John Roth wrote:
> The last piece has an incorrect conclusion. Lists are not safe
> _because_ the cmp function is NOT a compare of id(list), but
> is based on list contents, which can change at any time.
>
> It should also be emphasized that the default instance hash
> and cmp functions quoted make it impossible for two different
> instances to compare equal, thus there is no reason to store them
> as dictionary keys: it's simpler to make the value an attribute of
> the instance and bypass the additional complexity of the dictionary.
Note that Peter Maas has put this up on the Python wiki, so if you find 
things that are wrong or inaccurate, don't hesitate to correct them 
yourselves. =)

That said, I just made a few substantial edits that may have at least 
partially resolved your concerns.

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


Re: oddities in the datetime module

2005-01-14 Thread Tim Peters
[Max M]
> ...
> First of, it should be possible to easily convert between the
> datetime objects.

Why?  All the conversions people asked for when the module was being
designed were implemented.

> And eg. the date object doesn't have a datetime() method. Which
> it could easily have.

But not a *sensible* one.  If you only have a date (or time), what's a
conversion to datetime supposed to do about the "missing values"? 
Guess?  No good.

> Neither does time. They could have. But I don't think that
> is the way to solve it.

datetime.datetime objects have .date() and .time() methods, returning
the obvious datetime.date and datetime.time slices of the
datetime.datetime.  The class constructor datetime.combine() goes in
the other direction, building a datetime.datetime object by combining
a datetime.date and a datetime.time.

> It is a problem if you make a subclass of datetime. Often you
> will ned to make datetime arithmetics with the new class.
>
> Like: datetime_subclass_1 + datetime_subclass_2
>
> The result of that is a plain datetime

If your subclass doesn't override __add__, yes.

> In that case you will rather want your own subclass returned.

While possible, that's not necessarily so of all subclasses.

> But subclasses of datetime returns datetime objects.  Not the
> subclass.

That depends on whether the subclass overrides __add__, and if so, the
code in its __add__ method.

> So to do an add of your own objects you must convert the output
> to your own class "manually"
>
> class my_datetime(datetime):
> 
> def __add__(self, other):
> result = datetime.__add__(self, other)
> return my_datetime(result.timetuple()[:6])
> 
> datetime(), time() etc. methods will not help with this.

Well, it's unclear where you think you need help there.  If that's
what you want your subclass __add__ to do, you've already done it,
right?  It could save tedium to give your subclass a class
constructor, e.g., from_datetime(), and then code __add__ as

def __add__(self, other):
return my_datetime.from_datetime(datetime.__add__(self, other))

Whether the implementation wants to use timetuple() depends on what
the subclass wants to do; for example, a subclass that intends to
support a notion of time zone needs more than just that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Producer/consumer Queue "trick"

2005-01-14 Thread John Lenton
On Fri, Jan 14, 2005 at 04:26:02PM -0600, Evan Simpson wrote:
> WEBoggle needs a new game board every three minutes.  Boards take an 
> unpredictable (much less than 3min, but non-trivial) amount of time to 
> generate. The system is driven by web requests, and I don't want the 
> request that happens to trigger the need for the new board to have to 
> pay the time cost of generating it.
> 
> I set up a producer thread that does nothing but generate boards and put 
> them into a length-two Queue (blocking).  At the rate that boards are 
> pulled from the Queue, it's almost always full, but my poor consumer 
> thread was still being blocked for "a long time" each time it fetched a 
> board.
> 
> At this point I realized that q.get() on a full Queue immediately wakes 
> up the producer, which has been blocked waiting to add a board to the 
> Queue.  It sets about generating the next board, and the consumer 
> doesn't get to run again until the producer blocks again or is preempted.
> 
> The solution was simple: have the producer time.sleep(0.001) when 
> q.put(board) returns.

If I had had that problem, I would probably have set up different
server processes (consumer(s), producer(s), and queue(s)), coordinated
by somthing like pyro's event server. But I don't really know the
problem, so it's probably just bad guesswork on my part---you probably
don't need to scale at all.

-- 
John Lenton ([EMAIL PROTECTED]) -- Random fortune:
Tonight's the night: Sleep in a eucalyptus tree.


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: What strategy for random accession of records in massive FASTA file?

2005-01-14 Thread Steve Holden
Jeff Shannon wrote:
Chris Lasher wrote:
And besides, for long-term archiving purposes, I'd expect that zip et
al on a character-stream would provide significantly better
compression than a 4:1 packed format, and that zipping the packed
format wouldn't be all that much more efficient than zipping the
character stream.

This 105MB FASTA file is 8.3 MB gzip-ed.

And a 4:1 packed-format file would be ~26MB.  It'd be interesting to see 
how that packed-format file would compress, but I don't care enough to 
write a script to convert the FASTA file into a packed-format file to 
experiment with... ;)

If your compression algorithm's any good then both, when compressed, 
should be approximately equal in size, since the size should be 
determined by the information content rather than the representation.

Short version, then, is that yes, size concerns (such as they may be) 
are outweighed by speed and conceptual simplicity (i.e. avoiding a huge 
mess of bit-masking every time a single base needs to be examined, or a 
human-(semi-)readable display is needed).

(Plus, if this format might be used for RNA sequences as well as DNA 
sequences, you've got at least a fifth base to represent, which means 
you need at least three bits per base, which means only two bases per 
byte (or else base-encodings split across byte-boundaries) That gets 
ugly real fast.)

Right!
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: What strategy for random accession of records in massive FASTA file?

2005-01-14 Thread Steve Holden
Bengt Richter wrote:
On 12 Jan 2005 14:46:07 -0800, "Chris Lasher" <[EMAIL PROTECTED]> wrote:
[...]
Others have probably solved your basic problem, or pointed
the way. I'm just curious.
Given that the information content is 2 bits per character
that is taking up 8 bits of storage, there must be a good reason
for storing and/or transmitting them this way? I.e., it it easy
to think up a count-prefixed compressed format packing 4:1 in
subsequent data bytes (except for the last byte which have
less than 4 2-bit codes).
I'm wondering how the data is actually used once records are
retrieved. (but I'm too lazy to explore the biopython.org link).
Revealingly honest.
Of course, adopting an encoding that only used two bits per base would 
make it impossible to use the re module to search for patterns in them, 
for example. So the work of continuously translating between 
representations might militate against more efficient representations. 
Or, of course, it might not :-)

it's-only-storage-ly y'rs  - steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: oddities in the datetime module

2005-01-14 Thread Serge Orlov
Max M wrote:
> Serge Orlov wrote:
>> Max M wrote:
>
>> Yes, you did. datetime.timetuple is those who want *time module*
>> format, you should use datetime.data, datetime.time, datetime.year
>> and so on... As they say, if the only tool you have is timetuple, everything
>> looks like tuple  Try this:
>>
> dt = datetime(2005, 1, 1, 12, 0, 0)
> dt.date()
>>
>> datetime.date(2005, 1, 1)
>
> This doesn't solve it. I don't think you understand my issue.

I understand, but I don't think it's something that should be solved. Especially
date(*dt.timetuple()[:3])


> class my_datetime(datetime):
>
> def __add__(self, other):
> result = datetime.__add__(self, other)
> return my_datetime(result.timetuple()[:6])
>

What about:

def __add__(self, other):
result = datetime.__add__(self, other)
return my_datetime.fromdatetime(result)

  Serge. 


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


Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-14 Thread Steve Holden
Paul Rubin wrote:
"Fredrik Lundh" <[EMAIL PROTECTED]> writes:
Huh?  Expressions are not statements except when they're "expression
statements"?  What kind of expression is not an expression statement?
any expression that is used in a content that is not an expression 
statement,
of course.

Come on, that is vacuous.  The claim was "expressions are not
statements".  But it turns out that expressions ARE statements.  The
explanation is "well, that's because they're expression statements".
And there is no obvious case of an expression that can't be used as a
statement.  So it's not inherently obvious that there needs to be any
kind of statement that can't be used as an expression.  It's just an
artifact.  Whether the artifact is a desirable one is a matter of
discussion.
Excuse me, coould we get back to discussing how many angels can dance on 
the head of a pin?

or-something-interesting-like-that-sly y'rs  - steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: (objects as) mutable dictionary keys

2005-01-14 Thread Steve Holden
Antoon Pardon wrote:
Op 2005-01-14, Peter Maas schreef <[EMAIL PROTECTED]>:
I have summarized the discussion about the usability of lists (and
and other mutable types) as dictionary keys and put it into the
Python wiki.URL: http://www.python.org/moin/DictionaryKeys.
This summary might be used as a reference should the 'mutable
dictionary keys' issue come up again in c.l.py.
I had a look and I think you should correct the followingr:
  Dictionary lookup with mutable types like lists is a source of
  unpleasant surprises for the programmer and therefore impossible in
  Python.
Better, perhaps, to say:
  Dictionary lookup with mutable types like lists can be a
  source of unpleasant surprises for the programmer and
  therefore not recommended in Python.
It is not impossible in Python. It may be discouraged but it is not
impossible since I have already done so.
If I discouraged you from shooting yourself in the foot would you do 
that too?

some-people-just-won't-be-told-ly y'rs  - steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Index server

2005-01-14 Thread Marcel van den Dungen
[EMAIL PROTECTED] wrote:
Is there an Index server available in Python? For example:
I have large intranet with several servers and I would like to index
documents like  search engines do. Users then can search for a domument
in ALL intranet servers like I do on Google.
Thanks for answers
L.A.
Take a look at the following URLs:
http://www.methods.co.nz/docindexer/
http://www.divmod.org/Home/Projects/Lupy/index.html
http://www.divmod.org/Home/Projects/Pyndex/index.html
HTH,
-- Marcel
--
http://mail.python.org/mailman/listinfo/python-list


Re: Octal notation: severe deprecation

2005-01-14 Thread Bengt Richter
On Fri, 14 Jan 2005 20:13:48 +0100, Reinhold Birkenfeld <[EMAIL PROTECTED]> 
wrote:

>Bengt Richter wrote:
>> On Thu, 13 Jan 2005 08:18:25 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote:
>> 
>>>[EMAIL PROTECTED] wrote:
 In Mythical Future Python I would like to be able to use any base in
 integer literals, which would be better. Example random syntax:
 
 flags= 2x00011010101001
 umask= 8x664
 answer= 10x42
 addr= 16x0E84  # 16x == 0x
 gunk= 36x8H6Z9A0X
>>>
>>>I think I kinda like this idea.  Allowing arbitrary values,
>>>however, would probably be pointless, as there are very
>>>few bases in common enough use that a language should make
>>>it easy to write literals in any of them.  So I think "36x"
>>>is silly, and would suggest limiting this to 2, 8, 10, and
>>>16.  At the very least, a range of 2-16 should be used.
>>>(It would be cute but pointless to allow 1x0. :-)
>>>
>> My concern is negative numbers when you are interested in the
>> bits of a typical twos-complement number. (BTW, please don't tell me
>> that's platform-specific hardware oriented stuff: Two's complement is
>> a fine abstraction for interpreting a bit vector, which is another
>> fine abstraction ;-)
>> 
>> One way to do it consistently is to have a sign digit as the first
>> digit after the x, which is either 0 or base-1 -- e.g., +3 and -3 would be
>> 
>> 2x011 2x101
>> 8x03  8x75
>> 16x03 16xfd
>> 10x03 10x97
>
>Why not just -2x11? IMHO, Py2.4 does not produce negative values out of
>hex or oct literals any longer, so your proposal would be inconsistent.
>
Inconsistent with what? This is a new based-literal representation, not
the old hex or octal representation. It is separate and self-consistent,
and can live along side the old.

The fact that there is no longer a way to represent negative numbers
with traditional octal or hex is due to getting away from the
platform-dependent assumptions that bit 31 was a sign bit of a 32-bit
two-s complement machine represenentation. That was a good thing to get
away from.

But it means you now have to write a unary minus expression for negative 
numbers,
not a self-contained literal.

Re your question, -2x11 is the same as -(2x11) so you have to decide what
you want 2x11 to mean. If it means +3, we are back to the original problem
of having no way to see any of the 101 or fd of a -3 ;-)
(Except of course by '%02x'%(-0x3&0xff) -- ick)

I am not proposing a change to the new Py2.4 positive-only hex and octal 
literals.
I just want to be able to write literals for both positive and negative numbers
as self-contained literals (not expressions) without a '-' sign, and have the
representation be a readable representation of typical twos-complement 
representation.
You can't do that with -0x3, because (though the expression equals -3) it 
doesn't show
the information about the bits that you get with 16xfd or 2x101. Note that 
-16xfd == 16x03
and -2x101 == 2x011 and -16x03 == 16xfd and -2x011 == 2x101.

The '-' sign is not part of the literal.

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python.org, Website of Satan

2005-01-14 Thread Steve Holden
Lucas Saab wrote:
Arich Chanachai wrote:
Jane wrote:
"Lucas Raab" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
 

Jane wrote:
 

<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
   

python.org = 194.109.137.226
194 + 109 + 137 + 226 = 666
What is this website with such a demonic name and IP address?  What
evils are the programmers who use this language up to?
  

Some people have too much time on their hands...
Jane


Better get some ointment for that burn!!
  

Huh???
Jane
 

You said that people have too much "time" on their "hands", so he 
suggested ointment to prevent the irritation etc...  He was probably 
also getting at the topic of this thread (hint: Satan = Hell = Fire), 
so the ointment puts out the burn.
Have fun folks!

- Arich

I'd also like to add that the term "burn" means to be made look stupid 
or be insulted.
And here was me just thinking that the burn would result from the 
inevitable flames. Newsgroups really re a continual surprise.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Producer/consumer Queue "trick"

2005-01-14 Thread Evan Simpson
WEBoggle needs a new game board every three minutes.  Boards take an 
unpredictable (much less than 3min, but non-trivial) amount of time to 
generate. The system is driven by web requests, and I don't want the 
request that happens to trigger the need for the new board to have to 
pay the time cost of generating it.

I set up a producer thread that does nothing but generate boards and put 
them into a length-two Queue (blocking).  At the rate that boards are 
pulled from the Queue, it's almost always full, but my poor consumer 
thread was still being blocked for "a long time" each time it fetched a 
board.

At this point I realized that q.get() on a full Queue immediately wakes 
up the producer, which has been blocked waiting to add a board to the 
Queue.  It sets about generating the next board, and the consumer 
doesn't get to run again until the producer blocks again or is preempted.

The solution was simple: have the producer time.sleep(0.001) when 
q.put(board) returns.

Cheers,
Evan @ 4-am
--
http://mail.python.org/mailman/listinfo/python-list


Re: win32net help

2005-01-14 Thread [EMAIL PROTECTED]
Have you tried using UDP instead of TCP? Also, it is common practice to
choose a random port over 1024 for opening a connection to a remote
server.

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


Re: query python env

2005-01-14 Thread Steve Holden
Michael Hoffman wrote:
David Bear wrote:
How does one query the python environment, ie pythonhome

sys.prefix
 > pythonpath
sys.path
etc.

[...]
I suspect rather that the OP is looking for os.environ, as in:
[EMAIL PROTECTED] sholden]$ ENVAR=value
[EMAIL PROTECTED] sholden]$ export ENVAR
[EMAIL PROTECTED] sholden]$ python
Python 2.2.1 (#1, Aug 30 2002, 12:15:30)
[GCC 3.2 20020822 (Red Hat Linux Rawhide 3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ["ENVAR"]
'value'
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: query python env

2005-01-14 Thread Scott David Daniels
David Bear wrote:
How does one query the python environment, ie pythonhome, pythonpath,
etc.
also, are there any HOWTO's on keeping multiple versions of python
happy? 
In general, (and in this case) the answer is system-specific.
You need to explain (A) what operating system, and (B) what you
mean by multiple Python versions.
For example, for Windows 2K/XP, As long as you try for only
distinct major versions (2.2.x, 2.3.x, 2.4.x).  There should
not be a problem.  The primary issues are where (and how) does
your system get to the python files.
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: why are people still using classic classes?

2005-01-14 Thread Steve Holden
Michael Hobbs wrote:
Simon Wittber <[EMAIL PROTECTED]> wrote:
I've noticed that a few ASPN cookbook recipes, which are recent
additions, use classic classes.
I've also noticed classic classes are used in many places in the
standard library.
I've been using new-style classes since Python 2.2, and am suprised
people are still using the classic classes.
Is there a legitimate use for classic classes that I am not aware of?
Is there a project to specifically migrate standard library classes to
new-style classes?

I'm guessing that the biggest contributor to the continued prevalence
of classic classes is the official Python Tutorial:
http://docs.python.org/tut/node11.html#SECTION001130
I came into Python around the 2.2 timeframe and used the tutorial as
my starting point. I had often read people referring to "classic
classes" but assumed that it was some old pre-2.2 thing that I need
not worry about. For the longest time, I had assumed that I was using
new style classes because I created them exactly as prescribed in the
2.2 tutorial (which still hasn't changed for 2.3 or 2.4).
Now, classic classes are my habit and I see no compelling reason to
put in the effort to change my habits.
Since the only effort is the addition of
__meta class__ = type
at the head of your modules you could probably automate this without 
breaking too much code.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Com port interrupts again

2005-01-14 Thread engsol
Thanks much..:)

On 14 Jan 2005 12:25:43 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:

>A search on google gave me this library, I haven't tested it though:
>http://groups-beta.google.com/group/comp.lang.python.announce/browse_frm/thread/6d3263250ed65816/291074d7bd94be63?q=com+port+python&_done=%2Fgroups%3Fhl%3Den%26lr%3D%26safe%3Doff%26q%3Dcom+port+python%26qt_s%3DSearch+Groups%26&_doneTitle=Back+to+Search&&d#291074d7bd94be63

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


Re: Why would I get a TypeEror?

2005-01-14 Thread Reinhold Birkenfeld
Steven Bethard wrote:
> It's me wrote:
>> Say again???
> 
> Please stop top-posting -- it makes it hard to reply in context.
> 
>> "Reinhold Birkenfeld" wrote...
>>>It's me wrote:
If this is true, I would run into trouble real quick if I do a:

(1/x,1.0e99)[x==0]
>>>
>>>Lazy evaluation: use the (x==0 and 1e99 or 1/x) form!
> 
> If you want short-circuting behavior, where only one of the two branches 
> gets executed, you should use Python's short-circuiting boolean 
> operators.  For example,
> 
>  (x == 0 and 1.0e99 or 1/x)
> 
> says something like:
> 
>  Check if x == 0.
>  If so, check if 1.0e99 is non-zero.  It is, so return it.
>  If x != 0, see if 1/x is non-zero.  It is, so return it.
> 
> Note that if you're not comfortable with short-circuiting behavior, you 
> can also code this using lazy evaluation:
> 
>  (lambda: 1/x, lambda: 1.0e99)[x==0]()

Or even

(x==0 and lambda: 1e99 or lambda: 1/x)()

Or ...


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


Re: oddities in the datetime module

2005-01-14 Thread Max M
Serge Orlov wrote:
Max M wrote:

Yes, you did. datetime.timetuple is those who want *time module* format, you should use datetime.data, datetime.time, datetime.year 
and so on...

As they say, if the only tool you have is timetuple, everything looks like tuple 

Try this:
dt = datetime(2005, 1, 1, 12, 0, 0)
dt.date()
datetime.date(2005, 1, 1)
This doesn't solve it. I don't think you understand my issue.
First of, it should be possible to easily convert between the datetime 
objects.

And eg. the date object doesn't have a datetime() method. Which it could 
easily have. Neither does time. They could have. But I don't think that 
is the way to solve it.


It is a problem if you make a subclass of datetime. Often you will ned 
to make datetime arithmetics with the new class.

Like: datetime_subclass_1 + datetime_subclass_2
The result of that is a plain datetime
In that case you will rather want your own subclass returned. But 
subclasses of datetime returns datetime objects. Not the subclass.

So to do an add of your own objects you must convert the output to your 
own class "manually"

class my_datetime(datetime):
def __add__(self, other):
result = datetime.__add__(self, other)
return my_datetime(result.timetuple()[:6])
datetime(), time() etc. methods will not help with this.
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list


Re: Refactoring; arbitrary expression in lists

2005-01-14 Thread Steve Holden
Peter Maas wrote:
Steven Bethard schrieb:
BJörn Lindqvist wrote:
[...]
I believe this can be nicelier written as:
if "Makefile" in basename:
+1 for "nicelier" as VOTW (Vocabulation of the week) =)

Me too, because nicelier is nicer than more nicely. :)
Is that really the niceliest way to express that thought?
regards-li-er y'rs  - steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why would I get a TypeEror?

2005-01-14 Thread Steven Bethard
It's me wrote:
Say again???
Please stop top-posting -- it makes it hard to reply in context.
"Reinhold Birkenfeld" wrote...
It's me wrote:
If this is true, I would run into trouble real quick if I do a:
(1/x,1.0e99)[x==0]
Lazy evaluation: use the (x==0 and 1e99 or 1/x) form!
If you want short-circuting behavior, where only one of the two branches 
gets executed, you should use Python's short-circuiting boolean 
operators.  For example,

(x == 0 and 1.0e99 or 1/x)
says something like:
Check if x == 0.
If so, check if 1.0e99 is non-zero.  It is, so return it.
If x != 0, see if 1/x is non-zero.  It is, so return it.
Note that if you're not comfortable with short-circuiting behavior, you 
can also code this using lazy evaluation:

(lambda: 1/x, lambda: 1.0e99)[x==0]()
This says something like:
Create two functions, one to produce 1/x and one to produce 1.0e99.
Select one of these functions depending on whether or not x==0
Invoke the chosen function.
HTH,
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: why are people still using classic classes?

2005-01-14 Thread Steve Holden
Peter Hansen wrote:
Paul Rubin wrote:
Simon Wittber <[EMAIL PROTECTED]> writes:
Is there a reason NOT to use them?  If a classic class works fine, what
incentive is there to switch to new style classes?  

Perhaps classic classes will eventually disappear?

It just means that the formerly "classic" syntax will define a
new-style class.  Try to write code that works either way.

Unfortunately, if we should follow the recent advice about
always using "super()" in the __init__ method, it's hard
to do what you suggest (though it sounds like good advice)
without resorting to extreme ugliness:
 >>> class Classic:
   def __init__(self):
 super(Classic, self).__init__()

 >>> c = Classic()
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 3, in __init__
TypeError: super() argument 1 must be type, not classobj
Could classic classes ever be removed without us having manually
to fix all __init__ calls to the superclass?
That's not really an issue unless there's a diamond-shaped inheritance 
graph and linearisation of the the super classes is required to ensure 
that things stay sane. Remembering that the MO for classic classes and 
types are rather different, how many cases do you think it will matter?

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python.org, Website of Satan

2005-01-14 Thread mr_little
Brian Eable wrote:
> perl -e '$a="194.109.137.226"; @a = reverse split /\./, $a; for $i
(0..3) { $sum += $a[$i]*(256**$i) } print "sum = $sum\n"'
>
> 226 + 35072 + 7143424 + 3254779904 = 3261958626
>
> http://3261958626/
>
> Which is NOT 666.
Comrade, why perl here? :)
Are you afraid python? :)

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


Re: Threading Or Other Suggestions?!?

2005-01-14 Thread Aahz
In article <[EMAIL PROTECTED]>,
 <[EMAIL PROTECTED]> wrote:
>
>  I have a wxPython application that does a lot of things. One of them,
>in particular, I have doubts on how to implement it. Essentially, this part
>of my application calls an external executable (an oil reservoir
>simulator). What I would like to do, is to give the user the possibility to
>run more than 1 simulation at the same time. This means:
>
>1) Writing the executable "data file" needed by the simulator
>2) Run the executable file (and wait until completion)
>3) Examine the simulation results
>
>For this, I was thinking about threads... does anyone have other/better
>suggestion(s)? Does anyone see any difficulty/memory problems in using
>threads?

If you're not on Windows, this will be much easier with multiple
processes.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why would I get a TypeEror?

2005-01-14 Thread Reinhold Birkenfeld
It's me wrote:
> Say again???
> 
> "Reinhold Birkenfeld" <[EMAIL PROTECTED]> wrote in
> message news:[EMAIL PROTECTED]
>> It's me wrote:
>> > Sorry if my question was a little "lazy" and yes, I was asking about the
>> > "lazy evaluation".  :=)
>> >
>> > I am surprised about this (and this can be dangerous, I guess).
>> >
>> > If this is true, I would run into trouble real quick if I do a:
>> >
>> > (1/x,1.0e99)[x==0]
>> >
>> > and that's not good.
>> >
>> > Something to keep in mind.  :-(
>>
>> Lazy evaluation: use the (x==0 and 1e99 or 1/x) form!
>>
>> Reinhold

Say what again?

Reinhold

PS: Please do not produce top-posting!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why would I get a TypeEror?

2005-01-14 Thread It's me
Say again???

"Reinhold Birkenfeld" <[EMAIL PROTECTED]> wrote in
message news:[EMAIL PROTECTED]
> It's me wrote:
> > Sorry if my question was a little "lazy" and yes, I was asking about the
> > "lazy evaluation".  :=)
> >
> > I am surprised about this (and this can be dangerous, I guess).
> >
> > If this is true, I would run into trouble real quick if I do a:
> >
> > (1/x,1.0e99)[x==0]
> >
> > and that's not good.
> >
> > Something to keep in mind.  :-(
>
> Lazy evaluation: use the (x==0 and 1e99 or 1/x) form!
>
> Reinhold


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


Re: oddities in the datetime module

2005-01-14 Thread Serge Orlov
Max M wrote:
> # -*- coding: latin-1 -*-
>
> """
>
> I am currently using the datetime package, but I find that the design
> is oddly
> asymmetric. I would like to know why. Or perhaps I have misunderstood
> how it should be used?

Yes, you did. datetime.timetuple is those who want *time module* format, you 
should use datetime.data, datetime.time, datetime.year 
and so on...

[snip a lot of timetuple wrestling]
> The other way around is also easy.
>
 dt = datetime(2005, 1, 1, 12, 0, 0)
 date(*dt.timetuple()[:3])
> datetime.date(2005, 1, 1)

As they say, if the only tool you have is timetuple, everything looks like 
tuple 

Try this:

>>> dt = datetime(2005, 1, 1, 12, 0, 0)
>>> dt.date()
datetime.date(2005, 1, 1)

  Serge.


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


Re: Pickled text file causing ValueError (dos/unix issue)

2005-01-14 Thread Tim Peters
[Tim Peters]
>>Yes:  regardless of platform, always open files used for pickles
>> in binary mode. ...

[John Machin]
> Tim, the manual as of version 2.4 does _not_ mention the need
> to use 'b' on OSes where it makes a difference, not even in the
> examples at the end of the chapter. Further, it still refers to
> protocol 0 as 'text' in several places. There is also a reference to
> protocol 0 files being viewable in a text editor.
>
> In other words, enough to lead even the most careful Reader of
> TFM up the garden path :-)

Take the next step:  submit a patch with corrected text.  I'm not paid
to work on the Python docs either <0.5 wink>.  (BTW, protocol 0 files
are viewable in a text editor regardless, although the line ends may
"look funny")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python connect to db2

2005-01-14 Thread Jarek Zgoda
yuzx wrote:
>>> conn = DB2.connect(dsn='sample', uid='db2inst1', pwd='ibmdb2')
but i don't know about dsn,
If the database is DB2/400 and you try to connect from iSeries, dsn 
would be '*local' for local database, or its name (not hostname or IP 
address!) as returned by dsprdbdire command for remote databases.

--
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/
--
http://mail.python.org/mailman/listinfo/python-list


Index server

2005-01-14 Thread python
Is there an Index server available in Python? For example:
I have large intranet with several servers and I would like to index
documents like  search engines do. Users then can search for a domument
in ALL intranet servers like I do on Google.
Thanks for answers
L.A.

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


Re: Pickled text file causing ValueError (dos/unix issue)

2005-01-14 Thread John Machin
On Fri, 14 Jan 2005 09:12:49 -0500, Tim Peters <[EMAIL PROTECTED]>
wrote:

>[Aki Niimura]
>> I started to use pickle to store the latest user settings for the tool
>> I wrote. It writes out a pickled text file when it terminates and it
>> restores the settings when it starts.
>...
>> I guess DOS text format is creating this problem.
>
>Yes.
>
>> My question is "Is there any elegant way to deal with this?".
>
>Yes:  regardless of platform, always open files used for pickles in
>binary mode.  That is, pass "rb" to open() when reading a pickle file,
>and "wb" to open() when writing a pickle file.  Then your pickle files
>will work unchanged on all platforms.  The same is true of files
>containing binary data of any kind (and despite that pickle protocol 0
>was called "text mode" for years, it's still binary data).

Tim, the manual as of version 2.4 does _not_ mention the need to use
'b' on OSes where it makes a difference, not even in the examples at
the end of the chapter. Further, it still refers to protocol 0 as
'text' in several places. There is also a reference to protocol 0
files being viewable in a text editor.

In other words, enough to lead even the most careful Reader of TFM up
the garden path :-)

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


Re: What strategy for random accession of records in massive FASTA file?

2005-01-14 Thread Paul Rubin
"Chris Lasher" <[EMAIL PROTECTED]> writes:
> Forgive my ignorance, but what does using mmap do for the script? My
> guess is that it improves performance, but I'm not sure how. I read the
> module documentation and the module appears to be a way to read out
> information from memory (RAM maybe?).

Mmap lets you treat a disk file as an array, so you can randomly
access the bytes in the file without having to do seek operations.
Just say a[234]='x' and you've changed byte 234 of the file to the
letter x.  It works through the OS's virtual memory system and the
computer's MMU hardware, and so it has lower overhead than doing
system calls for every access.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python to mssql

2005-01-14 Thread Richards Noah (IFR LIT MET)
"Robert Brewer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Brane wrote:
> can someone please give me some info regarding subject
>
>http://sourceforge.net/projects/mysql-python
>
>Ask a broad question...
>
>
>Robert Brewer

Robert, the question was about 'mssql', not 'mysql'.  As for mssql, a search
on google will give you the following as the first result:
http://pymssql.sourceforge.net/

with others on the page that include:
http://www.object-craft.com.au/projects/mssql/
http://www.egenix.com/files/python/eGenix-mx-Extensions.html


Don't be lazy, Brane.  Your first point of reference should _always_ be
google.  The fact that "I'm Feeling Lucky" points you to pymssql shows that
you didn't do any research before posting here.

-Noah


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


Re: Using Sqlite with Python under Windows

2005-01-14 Thread Michel Claveau - abstraction méta-galactique non triviale en fuite perpétuelle.
Thanks, for the link


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


reusing Tkinter Canvases

2005-01-14 Thread Sean McIlroy
I'd like to save one Tkinter Canvas in order to use it on another
Canvas later. The problem is that it gets saved as EPS but it needs to
be GIF to be reuseable. How can I convert that format?

Peace,
STM
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What strategy for random accession of records in massive FASTA file?

2005-01-14 Thread Chris Lasher
Forgive my ignorance, but what does using mmap do for the script? My
guess is that it improves performance, but I'm not sure how. I read the
module documentation and the module appears to be a way to read out
information from memory (RAM maybe?).

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


Re: python to mssql

2005-01-14 Thread Jarek Zgoda
Brane wrote:
can someone please give me some info regarding subject
From Windows machine: http://adodbapi.sourceforge.net/
From elsewhere: FreeTDS + unixODBC + mxODBC is one of possible solutions.
--
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Com port interrupts again

2005-01-14 Thread [EMAIL PROTECTED]
A search on google gave me this library, I haven't tested it though:
http://groups-beta.google.com/group/comp.lang.python.announce/browse_frm/thread/6d3263250ed65816/291074d7bd94be63?q=com+port+python&_done=%2Fgroups%3Fhl%3Den%26lr%3D%26safe%3Doff%26q%3Dcom+port+python%26qt_s%3DSearch+Groups%26&_doneTitle=Back+to+Search&&d#291074d7bd94be63

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


Re: Why 'r' mode anyway?

2005-01-14 Thread Irmen de Jong
Tim Peters wrote:
That differences may exist is reflected in the C
standard, and the rules for text-mode files are more restrictive than
most people would believe.
Apparently. Because I know only about the Unix <-> Windows difference
(windows converts \r\n <--> \n when using 'r' mode, right).
So it's in the line endings.
Is there more obscure stuff going on on the other systems you
mentioned (Mac OS, VAX) ?
(That means that the bug in Simplehttpserver that my patch
839496 addressed, also occured on those systems? Or that
the patch may be incorrect after all??)
While your argument about why Python doesn't use its own platform-
independent file format is sound ofcourse, I find it often a nuisance
that platform specific things tricle trough into Python itself and
ultimately in the programs you write. I sometimes feel that some
parts of Python expose the underlying C/os implementation
a bit too much. Python never claimed write once run anywhere (as
that other language does) but it would have been nice nevertheless ;-)
In practice it's just not possible I guess.
Thanks,
--Irmen
--
http://mail.python.org/mailman/listinfo/python-list


Re: Octal notation: severe deprecation

2005-01-14 Thread JCM
[EMAIL PROTECTED] wrote:
...
> In Mythical Future Python I would like to be able to use any base in
> integer literals, which would be better. Example random syntax:

> flags= 2x00011010101001
> umask= 8x664
> answer= 10x42
> addr= 16x0E84  # 16x == 0x
> gunk= 36x8H6Z9A0X

I'd prefer using the leftmost character as a two's complement
extension bit.

0x1  : 1 in hex notation
1xf  : -1 in hex notation, or conceptually an infinitely long string of 1s
0c12 : 10 in octal noataion
1c12 : -54 in octal (I think)
0d12 : 12 in decimal
0b10 : 2 in binary
etc

I leave it to the reader to decide whether I'm joking.
-- 
http://mail.python.org/mailman/listinfo/python-list


Free NNTP (was Re: how to stop google from messing Python code)

2005-01-14 Thread Aahz
In article <[EMAIL PROTECTED]>,
Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>Fuzzyman wrote:
>>
>> I guess that most people use google to post to newsgroups is that they
>> don't have nntp access. Telling htem to use a newsreader is facetious
>> and unhelpful.

Most people use Gooja to post because they're lazy.

>if you have internet access, you have NNTP access. gmane.org provides
>access to more than 6,500 mailing lists via NNTP, including all
>relevant Python forums.

You also have access to the free netnews server http://news.cis.dfn.de/
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why 'r' mode anyway? (was: Re: Pickled text file causing ValueError (dos/unix issue))

2005-01-14 Thread Serge Orlov
Irmen de Jong wrote:
> Tim Peters wrote:
>
> > Yes:  regardless of platform, always open files used for pickles in
> > binary mode.  That is, pass "rb" to open() when reading a pickle
file,
> > and "wb" to open() when writing a pickle file.  Then your pickle
files
> > will work unchanged on all platforms.  The same is true of files
> > containing binary data of any kind (and despite that pickle
protocol 0
> > was called "text mode" for years, it's still binary data).
>
> I've been wondering why there even is the choice between binary mode
> and text mode. Why can't we just do away with the 'text mode' ?

We can't because characters and bytes are not the same things. But I
believe what you're really complaining about is that "t" mode sometimes
mysteriously corrupts data if processed by the code that expects binary
files. In Python 3.0 it will be fixed because file.read will have to
return different objects: bytes for "b" mode, str for "t" mode. It
would be great if file type was split into binfile and textfile,
removing need for cryptic "b" and "t" modes but I'm afraid that's too
much of a change even for Python 3.0

  Serge.

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


Re: Why would I get a TypeEror?

2005-01-14 Thread Reinhold Birkenfeld
It's me wrote:
> Sorry if my question was a little "lazy" and yes, I was asking about the
> "lazy evaluation".  :=)
> 
> I am surprised about this (and this can be dangerous, I guess).
> 
> If this is true, I would run into trouble real quick if I do a:
> 
> (1/x,1.0e99)[x==0]
> 
> and that's not good.
> 
> Something to keep in mind.  :-(

Lazy evaluation: use the (x==0 and 1e99 or 1/x) form!

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


Re: [perl-python] 20050113 looking up syntax

2005-01-14 Thread Istvan Albert
Jürgen Exner wrote:
Why don't you just stop posting this nonsense?
He will, fairly soon. I'm suspecting that the original
intent behind these posts was to stir up a perl vs python
flamewar. That is unlikely to materialize since the
poster does not seem to understand neither of these
languages.
I.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Octal notation: severe deprecation

2005-01-14 Thread Reinhold Birkenfeld
Bengt Richter wrote:
> On Thu, 13 Jan 2005 08:18:25 -0500, Peter Hansen <[EMAIL PROTECTED]> wrote:
> 
>>[EMAIL PROTECTED] wrote:
>>> In Mythical Future Python I would like to be able to use any base in
>>> integer literals, which would be better. Example random syntax:
>>> 
>>> flags= 2x00011010101001
>>> umask= 8x664
>>> answer= 10x42
>>> addr= 16x0E84  # 16x == 0x
>>> gunk= 36x8H6Z9A0X
>>
>>I think I kinda like this idea.  Allowing arbitrary values,
>>however, would probably be pointless, as there are very
>>few bases in common enough use that a language should make
>>it easy to write literals in any of them.  So I think "36x"
>>is silly, and would suggest limiting this to 2, 8, 10, and
>>16.  At the very least, a range of 2-16 should be used.
>>(It would be cute but pointless to allow 1x0. :-)
>>
> My concern is negative numbers when you are interested in the
> bits of a typical twos-complement number. (BTW, please don't tell me
> that's platform-specific hardware oriented stuff: Two's complement is
> a fine abstraction for interpreting a bit vector, which is another
> fine abstraction ;-)
> 
> One way to do it consistently is to have a sign digit as the first
> digit after the x, which is either 0 or base-1 -- e.g., +3 and -3 would be
> 
> 2x011 2x101
> 8x03  8x75
> 16x03 16xfd
> 10x03 10x97

Why not just -2x11? IMHO, Py2.4 does not produce negative values out of
hex or oct literals any longer, so your proposal would be inconsistent.

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


Re: Octal notation: severe deprecation

2005-01-14 Thread Reinhold Birkenfeld
Simon Brunning wrote:
> On Thu, 13 Jan 2005 16:50:56 -0500, Leif K-Brooks <[EMAIL PROTECTED]> wrote:
>> Tim Roberts wrote:
>> > Stephen Thorne <[EMAIL PROTECTED]> wrote:
>> >
>> >>I would actually like to see pychecker pick up conceptual errors like this:
>> >>
>> >>import datetime
>> >>datetime.datetime(2005, 04,04)
>> >
>> >
>> > Why is that a conceptual error?  Syntactically, this could be a valid call
>> > to a function.  Even if you have parsed and executed datetime, so that you
>> > know datetime.datetime is a class, it's quite possible that the creation
>> > and destruction of an object might have useful side effects.
>> 
>> I'm guessing that Stephen is saying that PyChecker should have special
>> knowledge of the datetime module and of the fact that dates are often
>> specified with a leading zero, and therefor complain that they shouldn't
>> be used that way in Python source code.
> 
> It would be useful if PyChecker warned you when you specify an octal
> literal and where the value would differ from what you might expect if
> you didn't realise that you were specifying an octal literal.
> 
> x = 04 # This doesn't need a warning: 04 == 4
> #x = 09 # This doesn't need a warning: it will fail to compile
> x= 012 # This *does* need a warning: 012 == 10

Well, this would generate warnings for all octal literals except
01, 02, 03, 04, 05, 06 and 07.

However, I would vote +1 for adding such an option to PyChecker. For
code that explicitly uses octals, it can be turned off and it is _very_
confusing to newbies...

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


Re: Integration with java

2005-01-14 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Istvan Albert  <[EMAIL PROTECTED]> wrote:
>Joachim Boomberschloss wrote:
>
>>  the code is already written in Python, using the
>>  standard libraries and several extension modules
>
>One thing to keep in mind is that Jython does not
>integrate CPython, instead it "understands" python code
>directly. So if you have a C extension that works with python
>it won't work with Jython.
>
>My feeling is that if you had a lot of Java code written and
>wanted to build on that with python Jython would be a better
>fit than vice versa.
>
>Istvan.

There are other possibilities, though, including JPE
http://jpe.sourceforge.net >.  I recommend the
original poster consider the latter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python connect to db2

2005-01-14 Thread Jacek
yuzx wrote:
anyone can help me ?
this might help:
http://www6.software.ibm.com/reg/devworks/dw-db2pylnx-i?S_TACT=104AHW03&S_CMP=EDU
jacek
--
http://mail.python.org/mailman/listinfo/python-list


Com port interrupts again

2005-01-14 Thread engsol
I didn't fully think through my application before posting my
question. Async com port routines to handle com port interrups
only work well if one has access to the low level operating
system. In that case the receive buffer interrupt would cause
a jump to an interrupt service routine.. I don't believe that
Python provides that capabilty directly. The solution then would
be to write a C extention?

The suggestions offered by respondents to my original post
were almost all of a "Use threads, and poll as needed" flavor.
You're right...I need to learn threads as applied to com ports.
Norm B
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-14 Thread Roel Schroeven
Antoon Pardon wrote:
Op 2005-01-14, Roel Schroeven schreef <[EMAIL PROTECTED]>:
Antoon Pardon wrote:
IMO we have a: dogs are mamals kind of relationship in Python.
I see what you mean, but I don't think it's true.

Every expression can be used where a statement is expected.
(And this can be worded as: every expression is a statement.)
Not really. An expression statement is a statement that looks like an 
expression, but actually it's more than that: not only does it calculate 
the value of the expression, it also prints the value.

1) Only in an interactive environment.
True, I wanted to add that but forgot it. Doesn't change what I'm saying 
though.

2) That the semantics differ according to where the expression is
   used doesn't make a difference. That an expression decides which
   branch of an if statement is executed or what object is pass
   as an argument in a call are also semantic difference, yet 
   we still have an expression in both cases.
In both cases we have an expression, in both cases we have a statement, 
in both cases the expression is a part of the statement. In one case the 
expression is the only statement, in the other case the statement has 
other parts too.


Note that it would be perfectly possible to modify the syntax into
expression_stmt ::= "exprstmt" expression_list
...
If you change the syntax, of course you will change the strings
that will be accepted. I could change the syntax to:
  if_stmt ::= "if" "ifexpr" expression ...
Have I now proved that expressions after an if are not normal
expressions?
No, you still have a statement with one or more parts, one of which is 
an expression.

In OOP terms: I think that an expression statement 'has an' expression 
(I agree that is a very thin wrapper though), not that an expression 
statement 'is an' expression.

Not every statement can be used where an expression is expected. 
AFAIK *no* statement can be used where an expression is expected.

But that was not the implication of what Guido supposedly had said.
So that this is not the case doesn't counter what I said.
Whether statements can be used in the place of expressions is indeed not 
relevant to the discussion.

Regarding what Guido apparently said:
Op 2005-01-12, Steve Holden schreef <[EMAIL PROTECTED]>:
>> Given that Guido is on record as saying that expressions aren't
>> statements because he wants those things to be separate
Antoon Pardon wrote:
> Well, it seems that Guido is wrong then. The documentation clearly
> states that an expression is a statement.
I don't think it says that at all.
> More specifically, everywhere you can use a statement, you can
> simply use an expression according to the python syntax.
 If you use an expression where a statement is expected, you really 
write an expression statement that contains the expression (and nothing 
else, but that doesn't matter).

--
"Codito ergo sum"
Roel Schroeven
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to stop google from messing Python code

2005-01-14 Thread Fredrik Lundh
Fuzzyman wrote:

> I guess that most people use google to post to newsgroups is that they
> don't have nntp access. Telling htem to use a newsreader is facetious
> and unhelpful.

if you have internet access, you have NNTP access.  gmane.org provides access
to more than 6,500 mailing lists via NNTP, including all relevant Python forums.

 



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


Re: Why 'r' mode anyway? (was: Re: Pickled text file causing ValueError (dos/unix issue))

2005-01-14 Thread Tim Peters
[Irmen de Jong]
> I've been wondering why there even is the choice between binary mode
> and text mode. Why can't we just do away with the 'text mode' ?
> What does it do, anyways? At least, if it does something, I'm sure
> that it isn't something that can be done in Python itself if
> really required to do so...

It's not Python's decision, it's the operating system's.  Whether
there's an actual difference between text mode and binary mode is up
to the operating system, and, if there is an actual difference, every
detail about what the difference(s) consists of is also up to the
operating system.  That differences may exist is reflected in the C
standard, and the rules for text-mode files are more restrictive than
most people would believe.

On Unixish systems, there's no difference.  On Windows boxes, there
are conceptually small differences with huge consequences, and the
distinction appears to be kept just for backward-compatibility
reasons.  On some other systems, text and binary files are entirely
different kinds of beasts.

If Python didn't offer text mode then it would be clumsy at best to
use Python to write ordinary human-readable text files in the format
that native software on Windows, and Mac Classic, and VAX (and ...)
expects (and the native format for text mode differs across all of
them).  If Python didn't offer binary mode then it wouldn't be
possible to use Python to process data in binary files on Windows and
Mac Classic and VAX (and ...).  If Python used its own
platform-independent file format, then it would end up creating files
that other programs wouldn't be able to deal with.

Live with it .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie: module structure and import question

2005-01-14 Thread Ziong
Thx Rob.

yes i know it's related to search path, but i don't know how to set it in a
practical way (beside hard coding).
my concern is, if i want to create a custom module/library, i don't know
what py file will import it and where the working directory should be.
sometime like my example, even i don't know where the root directory of my
module will place, and i expect it can place in anywhere, how should i set
the sys.path?
i know that maybe a stupid  question, please forgive me, i'm just a newbie.
i have read all online documents in python.org. but i wouldn't find the
answer.

yes,  i'm asking is it normally only put one class in one py file.
thanks for your advice.
But if i put a set of classes in a py file as a module,  will it increase
the dependency of each class?
back to my example, of course, i can put BaseA and ClassA together in one py
file. what should i do when i need to add one more class later, "ClassB",
which also extend BaseA. Put it into the same file or in a new file? if put
in in the same file, i think it should difficult to maintain versioning. i'm
quite confuse in this, maybe because i learn Java before.

Thx again, Rob.

"Rob Emmons" <[EMAIL PROTECTED]> ???
news:[EMAIL PROTECTED] ???...
> > hi all,
> > i have question on how to design a module structure.
> > for example, i have 3 files.
> > [somewhere]/main.py
> > [somewhere]/myLib/Base/BaseA.py
> > [somewhere]/myLib/ClassA.py
> > 
> > .
> > It's fine when i run main.py.
> > however when i run ClassA.py individually, it would fail in import
> > statment since the import path is incorrect.
> > I would like to know is something wrong in my design, or something i
> > missed.
>
> I think your issue is your module search path.  Take a look at the doc for
> sys.path in the library reference.  These are the directories that python
> searchies for modules.  Usually the "." directory is included in this
> which makes python search the current working directory.  Your example
> fails because your working directories are probably different when you ran
> the two modules.  In any case always consider how you've setup sys.path
> and your libraries and modules.
>
> > Also, in practical usage, is that one class in one py file?
>
> I'm not exactly clear what your asking -- but I think yor asking if you'd
> normally only put one class in one py file.  My answer is no -- generally
> you'd put many functions and classes in each py file.  Modules are high
> level and should be used to create libraries essentailly -- this means
> many fucntions and classes per module.
>
> Rob
>
>


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


Re: Integration with java

2005-01-14 Thread andybak
How about this?
http://jpype.sourceforge.net/

(I haven't used it myself)

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


Why 'r' mode anyway? (was: Re: Pickled text file causing ValueError (dos/unix issue))

2005-01-14 Thread Irmen de Jong
Tim Peters wrote:
Yes:  regardless of platform, always open files used for pickles in
binary mode.  That is, pass "rb" to open() when reading a pickle file,
and "wb" to open() when writing a pickle file.  Then your pickle files
will work unchanged on all platforms.  The same is true of files
containing binary data of any kind (and despite that pickle protocol 0
was called "text mode" for years, it's still binary data).
I've been wondering why there even is the choice between binary mode
and text mode. Why can't we just do away with the 'text mode' ?
What does it do, anyways? At least, if it does something, I'm sure
that it isn't something that can be done in Python itself if
really required to do so...
--Irmen
--
http://mail.python.org/mailman/listinfo/python-list


Re: Free python server.

2005-01-14 Thread Robin Becker
[EMAIL PROTECTED] wrote:
Your file probably need to (a) be in the cgi-bin, not public_html,
(b)
be flagged executable ("chmod a+x file.py"), and (c) begin with the
line: '#!/usr/bin/env python'
If the server doesn't provide you with CGI (or, strongly preferable,
SCGI or mod_python), you're probably out of luck.

You're probably right, this machine doesn't provide with CGI, I'll send
an e-mail to administrator of arbornet.org and make sure.
So, I ask once again: does anyone know where I can put my *.py files?
Greetings.
Rootshell.
Hi, I just made a cgi script on rht earbornet machine.
Process as follows
mkdir public_html
chmod 0755 public_html
cd public_html
mkdir cgi-bin
chmod 0755 cgi-bin
echo hello world > index.html
cd cgi-bin
echo '#!/bin/sh
> echo content-type: text/html
> echo
> echo "Hello 
World!"
> ' > hw.cgi

chmod a+x hw.cgi
then
http://m-net.arbornet.org/~rgbecker/cgi-bin/hw.cgi
gives a nice red hello world ie acts as a cgi script
I also created the standard echo script
pytestcgi.cgi
as
#!/usr/local/bin/python
import cgi
cgi.test()
chmodded as before. See
http://m-net.arbornet.org/~rgbecker/cgi-bin/pytestcgi.cgi
Please don't misuse it's free and I'm no longer an American :)
--
Robin Becker
--
http://mail.python.org/mailman/listinfo/python-list


RE: python to mssql

2005-01-14 Thread Robert Brewer
Brane wrote:
> can someone please give me some info regarding subject

http://sourceforge.net/projects/mysql-python

Ask a broad question...


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


python to mssql

2005-01-14 Thread Brane
can someone please give me some info regarding subject
please advice
regards
brane
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Static executable with shared modules

2005-01-14 Thread "Martin v. Löwis"
Rickard Lind wrote:
Is there any way to build the python executable statically and
still be able to load modules built as shared libraries?
I'm not what "build statically" means; if you talking about
building a statically linked interpreter binary - then no,
this is not possible. At a minimum, you need to link with -ldl,
or else you cannot perform dlopen(3).
I'm trying to run python scripts on a stripped down FreeBSD (4.9)
machine which has no shared system libraries so I want to link it
statically against libc et al, but it would be nice to still be
able to load modules which were built as shared libraries.
Does that system support shared libraries? What is the API for
loading shared libraries, and finding a symbol in a dynamically-loaded
shared library, on that system?
In
particular I have a library for which I've generated a wrapper
with swig which I'd like to import.
If shared libraries are not supported, you could link the swig
module statically as well.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode conversion in 'print'

2005-01-14 Thread "Martin v. LÃwis"
Ricardo Bugalho wrote:
 thanks for the information. But what I was really looking for was
informaion on when and why Python started doing it (previously, it always
used sys.getdefaultencoding())) and why it was done only for 'print' when
stdout is a terminal instead of always.
It does that since 2.2, in response to many complains that you cannot
print a Unicode string in interactive mode, unless the Unicode string
contains only ASCII characters. It does that only if sys.stdout is
a real terminal, because otherwise it is not possible to determine
what the encoding of sys.stdout is.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Integration with java

2005-01-14 Thread Christopher De Vries
It is possible, though possibly painful, to call java modules from
CPython using JNI. This is more difficult than Jython integration, but
probably required if you want to keep using your extension modules.

The JNI tutorial is available at
http://java.sun.com/docs/books/tutorial/native1.1/index.html .

I probably would not take this approach unless java offered some
incredibly substantial benefit or I was integrating a complex python
system with a complex java sytem. I would also probably start by
creating a good C API to access the required java modules via JNI and
then use SWIG (http://www.swig.org/) to generate the python wrapper.

Of course if you can drop the extension modules you have already
written, accessing Java from Jython is just an import statement away.
Good luck,

Chris

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


Re: (objects as) mutable dictionary keys

2005-01-14 Thread John Roth
"Peter Maas" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
I have summarized the discussion about the usability of lists (and
and other mutable types) as dictionary keys and put it into the
Python wiki.URL: http://www.python.org/moin/DictionaryKeys.
This summary might be used as a reference should the 'mutable
dictionary keys' issue come up again in c.l.py.
The last piece has an incorrect conclusion. Lists are not safe
_because_ the cmp function is NOT a compare of id(list), but
is based on list contents, which can change at any time.
It should also be emphasized that the default instance hash
and cmp functions quoted make it impossible for two different
instances to compare equal, thus there is no reason to store them
as dictionary keys: it's simpler to make the value an attribute of
the instance and bypass the additional complexity of the dictionary.
John Roth
--
---
Peter Maas,  M+R Infosysteme,  D-52070 Aachen,  Tel +49-241-93878-0
E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64')
---
--
http://mail.python.org/mailman/listinfo/python-list


Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-14 Thread Fredrik Lundh
Antoon Pardon wrote:

> Well IMO I have explained clearly that I understood this in a set
> logical sense in my first response.

what does "first" mean on your planet?

 



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


Re: how to stop google from messing Python code

2005-01-14 Thread Terry Reedy

"Fuzzyman" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
>
> Xah Lee wrote:
>> gmane is great!

> I guess that most people use google to post to newsgroups is that they
> don't have nntp access.

Anyone with a normal internet connection has nntp access.  What some do not 
get from their ISP is 'free' access to a full newsite, and they may not 
feel like paying extra $$ to one when they can get free access to 
non-binary groups via Google that is better in regards to retention and 
search, Google just happens to not work well for posting Python code.  What 
most of those people may not know is that there is free access to a 
restricted news site (gmane) which mirrors a large number of mailing lists, 
one of which is the Python mailing list, which mirrors the Python 
newsgroup.  So I help them by giving them this  information.  Xah Lee used 
the information I shared, as have many other people, and even, in effect, 
thanked me for doing so.  Gmane also gives a Pythoneer easy access to about 
50 specialized Python-related mailing lists (and 1000s not related to 
Python).

> Telling htem to use a newsreader is facetious  and unhelpful.

Telling someone to stop sharing sharing useful information is nasty and 
unhelpful.  You owe me an apology.

Terry J. Reedy



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


Re: Free python server.

2005-01-14 Thread rootshell
> Your file probably need to (a) be in the cgi-bin, not public_html,
(b)
> be flagged executable ("chmod a+x file.py"), and (c) begin with the
> line: '#!/usr/bin/env python'
>
> If the server doesn't provide you with CGI (or, strongly preferable,
> SCGI or mod_python), you're probably out of luck.

You're probably right, this machine doesn't provide with CGI, I'll send
an e-mail to administrator of arbornet.org and make sure.

So, I ask once again: does anyone know where I can put my *.py files?
Greetings.
Rootshell.

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


Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-14 Thread Antoon Pardon
Op 2005-01-14, Roel Schroeven schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> IMO we have a: dogs are mamals kind of relationship in Python.
>
> I see what you mean, but I don't think it's true.
>
>> Every expression can be used where a statement is expected.
>> (And this can be worded as: every expression is a statement.)
>
> Not really. An expression statement is a statement that looks like an 
> expression, but actually it's more than that: not only does it calculate 
> the value of the expression, it also prints the value.

1) Only in an interactive environment.

2) That the semantics differ according to where the expression is
   used doesn't make a difference. That an expression decides which
   branch of an if statement is executed or what object is pass
   as an argument in a call are also semantic difference, yet 
   we still have an expression in both cases.

> Note that it would be perfectly possible to modify the syntax into
>
> expression_stmt ::= "exprstmt" expression_list
>
> so that you would have to write
>
> exprstmt 6*9
>
> instead of just
>
> 6*9
>
> That makes it clearer to see the distinction: 6*9 is an expression,
>
> exprstmt 6*9
>
> is a statement. An expression statement, more precisely.

If you change the syntax, of course you will change the strings
that will be accepted. I could change the syntax to:

  if_stmt ::= "if" "ifexpr" expression ...

Have I now proved that expressions after an if are not normal
expressions?

>
>> Not every statement can be used where an expression is expected. 
>
> AFAIK *no* statement can be used where an expression is expected.

But that was not the implication of what Guido supposedly had said.
So that this is not the case doesn't counter what I said.

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


Re: newbie q

2005-01-14 Thread Steve Holden
Bengt Richter wrote:
On Thu, 13 Jan 2005 09:16:40 -0500, Steve Holden <[EMAIL PROTECTED]> wrote:
[...]
Any statement of the form
   for i in [x for x in something]:
can be rewritten as
   for i in something:
Note that this doesn't mean you never want to iterate over a list 
comprehension. It's the easiest way, for example, to iterate over the 
first item of each list in a list of lists:

   for i in [x[0] for x in something]:
As I'm sure you know, with 2.4's generator expressions you
don't have to build the temporary list.
Which could be important if 'something'
is (or generates) a huge sequence.
  for i in (x[0] for x in something):
Yes. While I haven't yet done any more than play with generator 
sequences I do really feel that more of "the best of Icon" has arrived 
in Python with this new addition.

 >>> something = ([x] for x in xrange(10,20))
 >>> something
 
 >>> list(something)
 [[10], [11], [12], [13], [14], [15], [16], [17], [18], [19]]
 >>> for i in (x[0] for x in something): print i,
 ...
oops, that list() used it up ;-)
 >>> something = [[x] for x in xrange(10,20)]
 >>> for i in (x[0] for x in something): print i,
 ...
 10 11 12 13 14 15 16 17 18 19
Really nice.
I quite agree. It's particularly useful for infinite sequences :-)
regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: import keyword behaviour - performance impact if used multiple times?

2005-01-14 Thread neophyte
Nick Coghlan wrote:
>  > Is
>  > this something to do with system modules being singletons?
>
> They aren't singletons in the GoF design pattern sense. However,
Python's import
> machinery operates in such a way that it takes effort to get multiple
version of
> the same module into memory at the same time (it *can* be done, but
you have to
> work at it).
Given that this is exactly what I want, how can you do it?

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


Re: newbie ?s

2005-01-14 Thread Steve Holden
Venkat B wrote:
Hi folks,
I'm looking build a CGI-capable SSL-enabled web-server around Python 2.4 on
Linux.
It is to handle ~25 hits possibly arriving "at once". Content is non-static
and built by the execution of py cgi-scripts talking to a few backend
processes.
1) I was wondering if anyone has opinions on the ability of CGIHTTPServer (a
forking variant) to be able to handle this.
I wouldn't even consider it. The *HTTPServer modules aren't really 
intended to be much beyond a proof-of-concept, IMHO. Certainly you'd be 
likely to stress the system having 25 requests arrive in a bunch, though 
a modern computer would probably handle it.

2) If so, would something like pyOpenSSL be useful to make such a webserver
SSL-enabled.
There is a *lot* to do to SSL-enable a server. Since you advertise 
yourself as a newbie, I'd suggest there were better places to focus your 
efforts.

I checked out John Goerzen's book: Foundations of Python Network Programming
(ISBN 1590593715) and searched around. While I found how one can write py
scripts that could communicate with SSL-enabled webservers, tips on building
SSL-enabled webservers isn't obvious.
I was hoping to build a cleaner solution around the CGIHTTPServer variant
instead of say something like mini-httpd/OpenSSL/Python. I'd appreciate any
pointers.
I believe the Twisted package may be your best alternative, though this 
is at best hearsay since I am not (yet) an active user.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-14 Thread Roel Schroeven
Antoon Pardon wrote:
IMO we have a: dogs are mamals kind of relationship in Python.
I see what you mean, but I don't think it's true.
Every expression can be used where a statement is expected.
(And this can be worded as: every expression is a statement.)
Not really. An expression statement is a statement that looks like an 
expression, but actually it's more than that: not only does it calculate 
the value of the expression, it also prints the value.

Note that it would be perfectly possible to modify the syntax into
expression_stmt ::= "exprstmt" expression_list
so that you would have to write
exprstmt 6*9
instead of just
6*9
That makes it clearer to see the distinction: 6*9 is an expression,
exprstmt 6*9
is a statement. An expression statement, more precisely.
Not every statement can be used where an expression is expected. 
AFAIK *no* statement can be used where an expression is expected.
--
"Codito ergo sum"
Roel Schroeven
--
http://mail.python.org/mailman/listinfo/python-list


Re: lambda

2005-01-14 Thread Steve Holden
Antoon Pardon wrote:
Op 2005-01-13, hanz schreef <[EMAIL PROTECTED]>:
Antoon Pardon wrote:
So if I have a call with an expression that takes more than
one line, I should assign the expression to a variable and
use the variable in the call?
Yes, that's sometimes a good practice and can clarify
the call.

But wait if I do that, people will tell me how bad that it
is, because it will keep a reference to the value which
will prevent the garbage collector from harvesting this
memory.

Of course, unless that reference is in the global scope of the __main__ 
module its lifetime will be transient anyway. If the reference is stored 
in a function's local variable then unless its value is returned from 
the function it will become available for garbage collection when the 
function returns.

Nobody will tell you that it's bad.

Sorry, someone already did. If I recall correctly it
was Alex Martelli.
"A foolish consistency is the hobgoblin of little minds". Rules are made 
to be broken. Besides which, if you don't understand the language 
environment, rules alone will do you very little good. Try to focus a 
little more on principles and a little less on minutiae.

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-14 Thread Roel Schroeven
Skip Montanaro wrote:
Fredrik> no, expressions CAN BE USED as statements.  that doesn't mean
Fredrik> that they ARE statements, unless you're applying belgian logic.
Hmmm...  I'd never heard the term "belgian logic" before.  Googling provided
a few uses, but no formal definition (maybe it's a European phrase so
searching for it in English is futile).
I'm from Belgium, and I've never heard it before either. Probably a 
public secret, very carefully being kept hidden from us Belgians ;)

--
"Codito ergo sum"
Roel Schroeven
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-14 Thread Martin MOKREJÅ
Tim Peters wrote:
[Martin MOKREJÅ]
This comm(1) approach doesn't work for me. It somehow fails to
detect common entries when the offset is too big.
[...]
I'll repeat:

As I mentioned before, if you store keys in sorted text files ...

Those files aren't in sorted order, so of course `comm` can't do
anything useful with them.  Do `man sort`; sorting is not optional
here.
I did read the manpage, but somehow it seems I did not execute sort(1)
from within my python code, so it was unsorted and did did not realize
it yet. Thanks!
m.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [perl-python] 20050113 looking up syntax

2005-01-14 Thread Jürgen Exner
Xah Lee wrote:
> -
>
> for perl syntax lookup, use perldoc in the command line. For example:
> perldoc perl

Wrong. That command will give you a high-level overview of Perl but tell you 
nothing about the syntax.
To lookup the Perl syntax you would have to use

perldoc perlsyn

> use 'perldoc -f functionName' for specific function. example:
> perldoc -f qq

BS. That will tell you what a function does, it doesn't tell you anything at 
all about the syntax of Perl.
BTW: Why on earth are you using qq() as an example? That doc page just 
points you to 'perldoc perlop'.

> note that keywords cannot be looked up with -f. For basic keywords
> like
>
> if, while..., use
> perldoc perlop

BS. What gave you the idea that keywords were operators? Of course keywords 
can be found where they belong, in the syntax definition of the language, 
but not in the operator section of the documentation.

Why don't you just stop posting this nonsense?

jue



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


Re: Writing huge Sets() to disk

2005-01-14 Thread Tim Peters
[Martin MOKREJÅ]
> This comm(1) approach doesn't work for me. It somehow fails to
> detect common entries when the offset is too big.
>
> file 1:
>
> A
> F
> G
> I
> K
> M
> N
> R
> V
> AA
> AI
> FG
> FR
> GF
> GI
> GR
> IG
> IK
> IN
> IV
> KI
> MA
> NG
> RA
> RI
> VF
> AIK
> FGR
> FRA
> GFG
> GIN
> GRI
> IGI
> IGR
> IKI
> ING
> IVF
> KIG
> MAI
> NGF
> RAA
> RIG
> 
> file 2:
> 
> W
> W
> W
> W
> W
> W
> W
> W
> W
> W
> AA
> AI
> FG
> FR
> GF
> GI
> GR
> IG
> IK
> IN
> IV
> KI
> MA
> NG
> RA
> RI
> VF
> A
> A
> A
> A
> A
> A
> A
> A
> A
> A
> A
> A

I'll repeat:

>> As I mentioned before, if you store keys in sorted text files ...

Those files aren't in sorted order, so of course `comm` can't do
anything useful with them.  Do `man sort`; sorting is not optional
here.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing huge Sets() to disk

2005-01-14 Thread Martin MOKREJÅ
Tim Peters wrote:
[Martin MOKREJÅ]
...
I gave up the theoretical approach. Practically, I might need up
to store maybe those 1E15 keys.

We should work on our multiplication skills here .  You don't
have enough disk space to store 1E15 keys.  If your keys were just one
byte each, you would need to have 4 thousand disks of 250GB each to
store 1E15 keys.  How much disk space do you actually have?  I'm
betting you have no more than one 250GB disk.
...
[Istvan Albert]
On my system storing 1 million words of length 15
as keys of a python dictionary is around 75MB.

Fine, that's what I wanted to hear. How do you improve the algorithm?
Do you delay indexing to the very latest moment or do you let your
computer index 999 999 times just for fun?

It remains wholly unclear to me what "the algorithm" you want might
be.  As I mentioned before, if you store keys in sorted text files,
you can do intersection and difference very efficiently just by using
the Unix `comm` utiltity.
This comm(1) approach doesn't work for me. It somehow fails to detect
common entries when the offset is too big.
file 1:
A
F
G
I
K
M
N
R
V
AA
AI
FG
FR
GF
GI
GR
IG
IK
IN
IV
KI
MA
NG
RA
RI
VF
AIK
FGR
FRA
GFG
GIN
GRI
IGI
IGR
IKI
ING
IVF
KIG
MAI
NGF
RAA
RIG
file 2:
W
W
W
W
W
W
W
W
W
W
AA
AI
FG
FR
GF
GI
GR
IG
IK
IN
IV
KI
MA
NG
RA
RI
VF
A
A
A
A
A
A
A
A
A
A
A
A
--
http://mail.python.org/mailman/listinfo/python-list


Re: Integration with java

2005-01-14 Thread Istvan Albert
Joachim Boomberschloss wrote:
 the code is already written in Python, using the
 standard libraries and several extension modules
One thing to keep in mind is that Jython does not
integrate CPython, instead it "understands" python code
directly. So if you have a C extension that works with python
it won't work with Jython.
My feeling is that if you had a lot of Java code written and
wanted to build on that with python Jython would be a better
fit than vice versa.
Istvan.
--
http://mail.python.org/mailman/listinfo/python-list


Re: import problems *newbie*

2005-01-14 Thread Steve Holden
F. Petitjean wrote:
Le 13 Jan 2005 21:58:36 -0800, mike kreiner a écrit :
I am having trouble importing a module I created. I'm running PythonWin
on Windows XP if that helps. I saved my module in a folder called
my_scripts in the site-packages directory. I edited the python path to
include the my_scripts folder (it now reads
C:\Python23\Lib;C:\Python23\DLLs;C:\Python23\Lib\lib-tk;C:\Python23\Lib\site-packages\my_scripts).
Not a very godd idea to mess with the python path
Furthermore it should not be necessary!
When I try to import the module, I get this error:

from PolyDraw import *
Traceback (most recent call last):
File "", line 1, in ?
ImportError: No module named PolyDraw
OK, have your modifications to the path worked?
Try adding
  import sys
  print sys.path
before the import statement to verify what Python is actually using as 
the path.

When I select Browse PythonPath from the tools menu, I'm able to locate
my module, PolyDraw.py.
The problem goes away if I open PolyDraw.py from PythonWin, which I'm
assuming is because opening the module makes my_scripts the current
working directory. This is just a quick workaround, but I'd like to
know how to fix the problem. Thanks.
A quick fix is to promote your my_scripts folder to be a python package,
by creating a python module (file) named __init__.py right in the
package directory. The content of __init__.py can be for instance
The __init__.py can actually be completely empty, but surely then you'd 
have to import the module by

  from my_scripts import PolyDraw
which is a little less convenient. It would be easier (and also easier 
than modifying the PYTHONPATH) just to create a .pth file (say 
C:\Python23\Lib\site-packages\my.pth) containing the single line

my_scripts
and that should ensure that the directory really *is* on your path.
The *name* of the .pth file is irrelevant, and you can actually have 
several lines naming different directories (whose paths can be absolute, 
or relative to the directory containing the .pth file).

Obviously you should check that the path's setting is correct using the 
technique allowed above.


#!/usr/bin/env python
# -*- coding: Latin-1 -*-
"""
my_scripts package containing miscellaneous modules 
  PolyDraw
  
"""
__author__ = 'mike kreiner'

To import from this package the syntax is
from my_scripts import PolyDraw
Let's not recommend this as a way around the problem - let's find out 
what the problem actually *is* and fix it ;-)

regards
 Steve
--
Steve Holden   http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/
Holden Web LLC  +1 703 861 4237  +1 800 494 3119
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to list the global functions from a C program

2005-01-14 Thread Jack Diederich
On Fri, Jan 14, 2005 at 04:01:13PM +0100, Francesco Montorsi wrote:

> PyObject *list = PyObject_Dir(m_pGlobals);
> if (!list || PyList_Check(list) == FALSE)
>  return;
> 
> for (int i=0,max=PyList_Size(list); i 
>  PyObject *elem = PyList_GetItem(list, i);
>  if (PyCallable_Check(elem) != 0) {
> 
>   /* this should be a function..  */
>/* HERE IS THE PROBLEM: this code is never reached */
>   PyObject *str = PyObject_GetAttrString(elem, "func_name");
>  }
> }
> ==
> 
> Everything seems to work but then when scanning the list returned
> by PyObject_Dir() I never find any callable object
> what am I doing wrong ?

You are checking the list of strings returned from the dir() to
see if any of them are callable (they aren't).  You mean to check
the thing that the string is a name for, so instead of

# callable(name)
PyCallable_Check(elem)

use

# callable(globals()[name])
PyCallable_Check(PyDict_GetItem(m_pGlobals, elem))

-Jack

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


Re: python and macros (again) [Was: python3: 'where' keyword]

2005-01-14 Thread Carl Banks

Tim Jarman wrote:
> IANA French person, but I believe that Belgians are traditionally
> regarded as stupid in French culture, so "Belgian logic" would be
> similar to "Irish logic" for an English person. (Feel free to insert
> your own cultural stereotypes as required. :)

Ok.

http://www.urbandictionary.com/define.php?term=belgian&r=f
-- 
CARL BANKS

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


  1   2   >