Re: Are Python's reserved words reserved in places they dont need to be?

2006-09-13 Thread Antoon Pardon
On 2006-09-13, Carl Banks <[EMAIL PROTECTED]> wrote:
> metaperl wrote:
>> -->  python -i
>> >>> class = "algebra"
>>   File "", line 1
>> class = "algebra"
>>   ^
>> SyntaxError: invalid syntax
>> >>>
>>
>>
>> Why isn' t the parser smart enough to see that class followed by an
>> identifier is used for class definition but class followed by equals is
>> a simple assignment?
>
> Hmm.  Someone called "metaPERL" is asking why Python doesn't have a
> more complicated grammar.  Why does this not surprise me?  :)

Would a solution for this always make the grammer more complicated?

> Seriously, Python is that way deliberately.  The developers consider it
> a good design to reserve keywords.  It is not in any way considered a
> flaw, nor an oversight, nor a case of laziness.
>
> Besides, what you ask is impossible in general.  Consider this code:
>
> return(1,2,3)

This is just an idea of mine, nothing I expect python to adapt.
But just suppose the language allowed for words in bold. A word
in bold would be considered a reserved word, a word in non bold
would be an identifier. 

> Are you returning the tuple (1,2,3), or are you calling the function
> "return" with arguments 1,2,3?  There is no context-free grammar in the
> universe that can divine which one is meant.  It'd have to use context
> to even guess, and in a highly dynamic language like Python, you can
> never be wholly sure of the context.  (Is there an identifier named
> "return" in scope?  Don't know until you run the code...)

With my idea, you would just look whether "return" was written in
bold or not.

>> Also, I had a bug where I tried to set the attributes "user" and "pass"
>> in an object but "pass" would not work because it is a reserved word.
>> Again pass should be reserved in certain contexts but not others.
>>
>> Is Python 3k going to fix this sort of thing?
>
> Nope.  PEP 3099 (which lists changes that won't be made in Python
> 3000), states that the Python grammar will not be more complex than
> LL(1), and says that simple grammars are more desirable than complex
> ones.  There is no hope of this being "fixed".

This idea won't make python more complex than LL(1).

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


RE: Are Python's reserved words reserved in places they dont need tobe?

2006-09-13 Thread Delaney, Timothy (Tim)
Antoon Pardon wrote:

> This is just an idea of mine, nothing I expect python to adapt.
> But just suppose the language allowed for words in bold. A word
> in bold would be considered a reserved word, a word in non bold
> would be an identifier.

Exactly how am I supposed to use my text editor to make words bold? Is
every text editor supposed to understand a "python format" for code?

Besides, I don't like bold for keywords (or anything in code) - I like
my keywords blue (RGB 0, 0, 255). Of course, with a "python format", I
could make *my* keywords blue. But I can pretty much guarantee that my
preferred editor will not ever understand "python format".

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


Re: How to compare to directories?

2006-09-13 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, could.net
wrote:

> I want to compare 2 directories: dir1 and dir2.
> What I want to do is to get these informations:
> 1. does they have the same number of files and sub-directories?
> 2. does each file with the same name have the same size and date
> information?

I think `os.listdir()` and the functions in `os.path` will be the tools
you need.

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to compare to directories?

2006-09-13 Thread Rob Wolfe

[EMAIL PROTECTED] wrote:
> I want to compare 2 directories: dir1 and dir2.
> What I want to do is to get these informations:
> 1. does they have the same number of files and sub-directories?
> 2. does each file with the same name have the same size and date
> information?
>
> So, how can I do it in python?

Here is a nice example:

http://docs.python.org/lib/os-file-dir.html

Look for description of function walk.

HTH,
Rob

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


Python blogging software

2006-09-13 Thread Cliff Wells
There's been a lot of blogs started in Python, but given the recent
spate of web frameworks, I'm surprised that some blogging package hasn't
taken front seat yet.

I'm currently using Frog, and it's decent, but lacks some fundamental
features (tags for one).  Since Irmen is probably going to scrap it
anyway, I'm kind of fishing about for something new.

I've seen a few written in Zope/Plone, but they looked not quite
interesting enough given the resources it would take to run them.  At
least two were started in TurboGears but seem to have vaporized.

Anyone aware of any functional (doesn't need to be complete, beta is
fine) blog software written in Python?  

Regards,
Cliff
-- 

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


Re: Help me use my Dual Core CPU!

2006-09-13 Thread Simon Wittber
Paul Rubin wrote:
> "Simon Wittber" <[EMAIL PROTECTED]> writes:
> > I've just noticed that os.fork is not available on Win32. Ouch.
>
> Use the subprocess module.

I can't see how subprocess.Popen can replace a fork. Using a manually
started process is not really viable, as it does not automatically
share pre-built (read-only) data between the processes. If it can, I'd
really like to know how...

Yikes. This is a bummer. The conclusion seems to be, I cannot use any
common cross platform, true concurrency strategies in my games. On top
of that, I can't really use any form of concurrency on Win32.

Lets hope we get some super fast SMP friendly backends for PyPy sooner
rather than later!

-Sw.

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


Re: Are Python's reserved words reserved in places they dont need to be?

2006-09-13 Thread Paul Rubin
Antoon Pardon <[EMAIL PROTECTED]> writes:
> This is just an idea of mine, nothing I expect python to adapt.
> But just suppose the language allowed for words in bold. A word
> in bold would be considered a reserved word, a word in non bold
> would be an identifier. 

Heh, sounds like ColorForth, in which words meant different things
depending on what color they were written in (www.colorforth.com).
Madness, if you ask me ;-).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python blogging software

2006-09-13 Thread Cliff Wells
On Wed, 2006-09-13 at 00:29 -0700, Cliff Wells wrote:

> Anyone aware of any functional (doesn't need to be complete, beta is
> fine) blog software written in Python?  

Hmph.  And as soon as I hit send I find

 http://wiki.python.org/moin/PythonBlogSoftware

Okay, so is there any *not* on that list that should be considered (and
perhaps added to the list)?

Regards,
Cliff

-- 

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


Re: How can I get the function's caller?

2006-09-13 Thread John Machin

David wrote:
> Inside a function I need to get the function's caller's name. How can I get
> it?
>

Check out the thread "__LINE__ and __FILE__ functionality in Python?"
(messages posted 2006-0813).

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


Re: How to get the "longest possible" match with Python's RE module?

2006-09-13 Thread gatti

Frederic Rentsch wrote:


>If you need regexes, why not just reverse-sort your expressions? This
> seems a lot easier and faster than writing another regex compiler.
> Reverse-sorting places the longer ones ahead of the shorter ones.

Unfortunately, not all regular expressions have a fixed match length.
Which is the longest of, for example, /(abc)?def/ and /(def)?ghi/
depends on the input. 

Lorenzo Gatti

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


Re: Help me use my Dual Core CPU!

2006-09-13 Thread Paul Rubin
"Simon Wittber" <[EMAIL PROTECTED]> writes:
> I can't see how subprocess.Popen can replace a fork. Using a manually
> started process is not really viable, as it does not automatically
> share pre-built (read-only) data between the processes. If it can, I'd
> really like to know how...

Either with sockets or mmap.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are Python's reserved words reserved in places they dont need tobe?

2006-09-13 Thread Antoon Pardon
On 2006-09-13, Delaney, Timothy (Tim) <[EMAIL PROTECTED]> wrote:
> Antoon Pardon wrote:
>
>> This is just an idea of mine, nothing I expect python to adapt.
>> But just suppose the language allowed for words in bold. A word
>> in bold would be considered a reserved word, a word in non bold
>> would be an identifier.
>
> Exactly how am I supposed to use my text editor to make words bold? Is
> every text editor supposed to understand a "python format" for code?

The standard answer here to people complaining about their editor not
working well with python is that they should use a better editor.

> Besides, I don't like bold for keywords (or anything in code)

So? I don't like to append an "_" to make a reserved keyword into
an identifier. What individual people like or not is not a big
concern.

> - I like
> my keywords blue (RGB 0, 0, 255). Of course, with a "python format", I
> could make *my* keywords blue. But I can pretty much guarantee that my
> preferred editor will not ever understand "python format".

, Different options are possible, in a file the keywords
could just be prefixed with a Ctrl-K, and depending on the editor or its
setting, this could be shown bold or blue or whatever. I don't care
about the specifics at this point. I just wanted to make clear there
is the option to make/show the distiction between identifiers and keywords
more explicitly.

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


Re: How to compare to directories?

2006-09-13 Thread Gabriel Genellina

At Wednesday 13/9/2006 03:09, [EMAIL PROTECTED] wrote:


I want to compare 2 directories: dir1 and dir2.
What I want to do is to get these informations:
1. does they have the same number of files and sub-directories?
2. does each file with the same name have the same size and date
information?


Look at filecmp.dircmp in the standard library


Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

RE: Are Python's reserved words reserved in places they dont need tobe?

2006-09-13 Thread Duncan Booth
"Delaney, Timothy (Tim)" <[EMAIL PROTECTED]> wrote:

> Antoon Pardon wrote:
> 
>> This is just an idea of mine, nothing I expect python to adapt.
>> But just suppose the language allowed for words in bold. A word
>> in bold would be considered a reserved word, a word in non bold
>> would be an identifier.
> 
> Exactly how am I supposed to use my text editor to make words bold? Is
> every text editor supposed to understand a "python format" for code?

I guess you would do it the same way other languages have implemented this 
in the past: use bold if your editor supports it and use something else if 
it doesn't.

Algol 68 has the concept that keywords and identifiers with the same 
spelling are distinguished in some way (and if I remember correctly there 
were compiler options that let you specify what sort of stropping you were 
using). There was case stropping: case not otherwise being significant you 
could indicate a reserved word by uppercasing it e.g. BEGIN; or various 
punctuation conventions .begin. 'BEGIN' @begin or your editor might 
indicate reserved words using a different font e.g. bold.

I see wikipedia's entry on stropping says that Atlas Autocode let you strop 
keywords by underlining them using backspace and overstrike. That must have 
been real fun to type.

One of the big advantages of stropping is of course that you don't have to 
print or view source code using the same convention as you used when 
entering the text. So you might use case stropping to type your source code 
in, but then print listings with keywords bolded and lowercased.

So for Python you would have a magic comment similar to how you specify 
encoding to specify the type of stropping in use and your editor would 
recognise the comment and display the file using whichever stropping 
convention you prefer for viewing.

Personally I think a simpler idea to get round clashes of reserved words 
and identifiers would be to adopt something similar to c#'s @ escape. You 
could simply allow the lexer to accept @'something' as an alternative 
spelling for the identifier something, but with no restrictions on the 
characters that such an identifier could contain. so for manipulating html 
you would be able to write:

   element.@'class' = "whatever"

instead of having to call setattr or use some other kludge.

If Python did have a mechanism like this to escape identifiers then you 
could implement stropping completely outside the language: you could have 
an editor which displays keywords in one font and identifiers in another 
(as most editors already do), and then when saving simply escape any 
identifiers which are not otherwise valid. It wouldn't even be a big 
change: the editor could probably guess your intent correctly 99% of the 
time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are Python's reserved words reserved in places they dont need to be?

2006-09-13 Thread Antoon Pardon
On 2006-09-13, Paul Rubin  wrote:
> Antoon Pardon <[EMAIL PROTECTED]> writes:
>> This is just an idea of mine, nothing I expect python to adapt.
>> But just suppose the language allowed for words in bold. A word
>> in bold would be considered a reserved word, a word in non bold
>> would be an identifier. 
>
> Heh, sounds like ColorForth, in which words meant different things
> depending on what color they were written in (www.colorforth.com).
> Madness, if you ask me ;-).

Well I'm sure people would be able the abuse the feature with
madness as a result. However that is nothing new.

One place where I would use such a feature is in a unittest
package.  I think being able to write self.assert or self.raise
looks better than having to append an underscore.

I once experimented with end markers in python, but I dropped
it because end.if wasn't legal python.

If python would make this distinction, one wouldn't need
to be concerned anymore that the introduction of a new
keyword would break code.

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


Extra Unittest Information

2006-09-13 Thread Calvin Spealman
This is something I have been wanting to find for a while, but i
haven't figured out. I really would love to know if there is some way
I can report extra information while running unittests, and have that
information appear along with the tracebacks, so its near the relevent
test's results.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are Python's reserved words reserved in places they dont need to be?

2006-09-13 Thread Fredrik Lundh
Antoon Pardon wrote:

> One place where I would use such a feature is in a unittest
> package.  I think being able to write self.assert or self.raise
> looks better than having to append an underscore.

patch here:

http://mail.python.org/pipermail/python-list/2001-June/047996.html



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


Re: Are Python's reserved words reserved in places they dont need tobe?

2006-09-13 Thread Steve Holden
Delaney, Timothy (Tim) wrote:
> Antoon Pardon wrote:
> 
> 
>>This is just an idea of mine, nothing I expect python to adapt.
>>But just suppose the language allowed for words in bold. A word
>>in bold would be considered a reserved word, a word in non bold
>>would be an identifier.
> 
> 
> Exactly how am I supposed to use my text editor to make words bold? Is
> every text editor supposed to understand a "python format" for code?
> 
> Besides, I don't like bold for keywords (or anything in code) - I like
> my keywords blue (RGB 0, 0, 255). Of course, with a "python format", I
> could make *my* keywords blue. But I can pretty much guarantee that my
> preferred editor will not ever understand "python format".
> 
This would take us back to the days of Algol 60, where keywords could 
either be "stropped" (with single quotes, IIRC) or in some 
implementations underlined. I believe that Flexowriters had an underline 
key that didn't move the carriage, but it's all a long time ago now.

But I guess we could use the dollar sign to indicate keywords without 
requiring too much of people's editors.

$class$ sample1
$def$ __init__(self, a, b):
self.a = a
self.b = b
$def$ __cmp__(self, other):
$return$ self.a.__cmp__(other.a)

Don't see *that* catching on, though ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Inter process signalling

2006-09-13 Thread Dale Strickland-Clark
Dennis Lee Bieber wrote:

> Unfortunately... You are on Windows...
> 
> I think your choices become: Block, or Poll
> 
> Check the Win32Api modules...
> 
> win32event may be a candidate...
> CreateEvent()
> OpenEvent()
> PulseEvent()
> SetEvent()
> ResetEvent()
> WaitForSingleObject() or WaitForMultipleObjects()

Thanks. We'll look into those.
-- 
Dale Strickland-Clark
Riverhall Systems - www.riverhall.co.uk

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


How to write UNIX daemons in Python?

2006-09-13 Thread gnewsg
Hi all. I've just finished to write an FTP daemon in Python.
To do things well I'd like to write an 'insteller' to permit the end
user to 'deeply' install the package inside the system. In details I
would like that installer is able to do the following operations:

- copy ftpd.py in /usr/bin.
- depending on the system, it should be able to determinate where
service startup directory is located (for example /etc/init.d)  and
copy a script able to automatically run /usr/ftpd.py at startup.
- optionally install a manual callable with "man ftpd".
- many other operations about the installation of a package.

What should I use to do something like that? Do I have to use
distutils? Do I have to use third party packages? Do I have to write a
"setup.py" and solve the problem manually?
This last solution is problematic becouse, for (dumb) example, Debian
wants executable/programs to be located in /usr/bin while Fedora uses
another path (for example /usr/sbin).

Another question: what about .deb, .rpm, [...] packages?
Does it possible to use them with Python programs?
Resolving third party dependancies by using them could be a nice thing.


Best regards

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


Re: Help me use my Dual Core CPU!

2006-09-13 Thread Paul Boddie
Simon Wittber wrote:
> Michael wrote:
> > Also, Paul Boddie posted a module for parallel systems a while back as well
> > which might be useful (at least for ideas):
> >* http://cheeseshop.python.org/pypi/parallel
> >
>
> I've checked this out, it looks like a good idea which I could build
> further on.

Feel free to expand on what I've done. The tricky part was making some
kind of communications mechanism with asynchronous properties, and
although I suppose I could have used asyncore, Medusa or Twisted, I was
interested in the exercise of learning more about the poll system call
(and without adding dependencies which dwarf the pprocess module
itself).

> I've just noticed that os.fork is not available on Win32. Ouch.

Sorry! My motivation was to support operating systems that I personally
care about and which also have solutions for transparent process
migration, which I believe could be used in conjunction with the
pprocess module for better-than-thread parallelisation. In other words,
you get processes running independently on potentially many CPUs with
only the communications as overhead, and with access to shared data
either through the communications channels or via global variables
which are read only due to the nature of the fork semantics. This
doesn't necessarily play well with threaded-style programs wanting to
modify huge numbers of shared objects, but I'd argue that the benefits
of parallelisation (for performance) are somewhat reduced in such
programs anyway.

> Does that mean there is _no_ way for a single Python program to use
> multiple CPU/core systems on Windows? (other than writing an extension
> module in C (which is completely unacceptable for me!))

Rumour has it that recent versions of Windows provide fork-like
semantics through a system call. Your mission is to integrate this
transparently into the standard library's os.fork function. ;-)

Paul

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


Re: Is it just me, or is Sqlite3 goofy?

2006-09-13 Thread Hendrik van Rooyen
 "Tim Chase" <[EMAIL PROTECTED]> wrote:

To: "Steve Holden" <[EMAIL PROTECTED]>


> >> "But honestly, boss, I didn't write this code!  It was my
> >> evil alter-ego that puts VARCHAR values containing Gilbert &
> >> Sullivan lyrics into the Amount_Due CURRENCY fields!"
> >> 
> > Hence the phrase "Going for a song"?
> 
> I am the very model of a modern major database,
> For gigabytes of information gathered out in userspace.
> For banking applications to a website crackers will deface,
> You access me from console or spiffy user interface.
> 
> My multi-threaded architecture offers you concurrency,
> And loads of RAM for caching things reduces query latency.
> The data is correctly typed, a fact that I will guarantee,
> Each datum has a data type, it's specified explicitly.
> 
> is-it-friday-yet'ly yers,
> 
> -tkc

I love this group - thanks for that - it made my day ...

- Hendrik

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


Re: Is it just me, or is Sqlite3 goofy?

2006-09-13 Thread Hendrik van Rooyen
From: "Steve Holden" <[EMAIL PROTECTED]> wrote:


> These kids wi' their Oracle databases didn't know they were born. I can
> remember 'avin' to optimise programs by making sure that the next
> instruction were comin' under the heads of t' drum just as the last
> instruction were finishing.
>
> But yer tell these young folk nowadays and they just don't believe yer.


Too true - one of my contemporaries made NCR CRAM units sing - one card
dropping, one on the drum, and one flying back up into the stack

- Hendrik

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


Re: table (ascii text) lin ayout recognition

2006-09-13 Thread James Stroud
[EMAIL PROTECTED] wrote:
> Hello,
> 
> I am looking for python code useful to process
> tables that are in ASCII text. The code must
> determine where are the columns (fields).
> Concerned tables for my application are various,
> but their columns are not very complicated
> to locate for a human, because even
> when ignoring the semantic of  words,
> our eyes see vertical alignments
> 
> Here is a sample table (must be viewed
> with fixed-width font to see alignments):
> =
> 
> 44544  ipod  apple black 102
> GFGFHHF-12 unknown thing bizar brick mortar  tbc
> 45fjk  do not know   + is less   biac
>disk  seagate   250GB 130
> 5G_gff   tbd   tbd
> gjgh88hgg  media record  a and b 12
> hjjfoo   bar   hop   zip
> hg uy oi   hj uuu ii a   qqq ccc v ZZZ Ughj
> qdsd   zertnope  nope
> 
> =
> 
> I want the python code that builds a representation
> of this table (for exemple a list of lists, where each list
> represents a table line, each element of the list
> being a field value).
> 
> Any hints?
> thanks
> 

As promised. I call this the "cast a shadow" algorithm for table 
discovery. This is about as obfuscated as I could make it. It will be up 
to you to explain it to your teacher ;-)

Assuming the lines are all equal width (padded right with space) e.g.:

def rpadd(lines):
   """
   Pass in the lines as a list of lines.
   """
   lines = [line.rstrip() for line in lines]
   maxlen = max([len(line) for line in lines])
   return [line + ' ' * (maxlen - len(line)) for line in lines]


In which case, you can:


binary = [[((s==' ' and 2) or 1) for s in line] for line in lines]
shadow = [1 in c for c in zip(*binary)]

isit = False
indices = []
for i,v in enumerate(shadow):
   if v is not isit:
 indices.append(i)
 isit = not isit

indices.append(i+1)

indices = [t for t in zip(indices[::2],indices[1::2])]

columns = [[line[t[0]:t[1]].strip() for line in lines] for t in indices]


In case you want rows:

rows = zip(*columns)


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


Re: Inter process signalling

2006-09-13 Thread Duncan Booth
Dale Strickland-Clark <[EMAIL PROTECTED]> wrote:

> In Linux this is easy with 'signal' and 'kill' but how can I get one
> Python process to signal another (possibly running as a service)? 
> 
> All I need is a simple prod with no other data being sent and none
> being returned - except that the signal was delivered.
> 
> Receiving a signal should generate an interrupt. I'm not looking for a
> solution the involves polling.
> 
Lots of ways. Basically all involving creating a thread which waits on an 
event and then calls your code when the event is generated.

You can use semaphores, named pipes &c.; you could create a windows message 
queue and simply send the process a message when you want to alert it; you 
could create a COM server and call a method on it; you could use 
asynchronous procedure calls (APCs) (but you still need to ensure that 
there is a thread in an alertable wait state).

If the code you want to signal is running as a service then the easiest way 
to signal it is to call win32service.ControlService with a user defined 
service code. That gives you 127 signals to play with, and Python's win32 
library will simply call the SvcOther method within your service code 
(although not of course using the same thread as the actual service is 
running on).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: table (ascii text) lin ayout recognition

2006-09-13 Thread James Stroud
James Stroud wrote:
> indices = [t for t in zip(indices[::2],indices[1::2])]

(Artefact of cut-and-paste.)

Make that:

indices = zip(indices[::2],indices[1::2])



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


Re: Inter process signalling

2006-09-13 Thread Dale Strickland-Clark
Duncan Booth wrote:

> Dale Strickland-Clark <[EMAIL PROTECTED]> wrote:
> 
>> In Linux this is easy with 'signal' and 'kill' but how can I get one
>> Python process to signal another (possibly running as a service)?
>> 
>> All I need is a simple prod with no other data being sent and none
>> being returned - except that the signal was delivered.
>> 
>> Receiving a signal should generate an interrupt. I'm not looking for a
>> solution the involves polling.
>> 
> Lots of ways. Basically all involving creating a thread which waits on an
> event and then calls your code when the event is generated.
> 
> You can use semaphores, named pipes &c.; you could create a windows
> message queue and simply send the process a message when you want to alert
> it; you could create a COM server and call a method on it; you could use
> asynchronous procedure calls (APCs) (but you still need to ensure that
> there is a thread in an alertable wait state).
> 
> If the code you want to signal is running as a service then the easiest
> way to signal it is to call win32service.ControlService with a user
> defined service code. That gives you 127 signals to play with, and
> Python's win32 library will simply call the SvcOther method within your
> service code (although not of course using the same thread as the actual
> service is running on).

Thanks Duncan.
-- 
Dale Strickland-Clark
Riverhall Systems - www.riverhall.co.uk

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


os.access(file, os.R_OK) on UNIX and WINDOWS

2006-09-13 Thread kai rosenthal
Hello,

on UNIX I changed the permission of a file "myfile" with chmod 000
myfile. Then I got 0 from os.access(myfile, os.R_OK). This is ok.

Then I checked the same file on WINDOWS (with samba):
I got "True" from os.access(myfile, os.R_OK). I think it is not ok?!

In my python script I check the return value of os.access(myfile,
os.R_OK) and when it is "True" I copy the file with shutil.copy(myfile,
newfile).
But on WINDOWS I get the error: IOError: [Errno 13] Permission denied.

How can I check the right file access with python on WINDOWS before
copying the file?
Is it a samba configuration?

Thank' for your hints, Kai

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


Re: egg and modpython

2006-09-13 Thread Paul Boddie
Bruno Desthuilliers wrote:
>
> AFAIK, jar files don't include native dynamic libs... But I'm not a Java
> expert (happily forgot most of what I used to know about this language).

I can't be bothered to read the specification to say what is allowed in
.jar files, but .war files frequently get unpacked by various
application servers either for efficiency reasons or in order to access
resources that have to be processed. Whether such software is badly
designed or not (eg. the horror of Oracle Containers for Java), there's
a precedent for such behaviour that needs to be reviewed continuously.

[...]

> Yes, true. But I'd still say that it's more a problem of proper
> packaging (ie, an egg with dynamic libs inside should better not be
> packaged as 'zip-safe') than a bug in the eggs system itself.

There's always going to be an issue of how much you need to know in
order to be able to package stuff effectively. With Debian packaging,
there's a culture around this with a moderately steep learning curve;
with distutils, a simple script is often enough for a Python-only
package, but various strangely defined options for installing scripts,
data and programs cause the learning curve to point more steeply
upwards. I imagine that providing native code libraries can be even
more of a hassle, but at such a point setuptools should really start to
help out and detect the situations where compressed .egg files have to
be unpacked.

But returning briefly to my point about what setuptools and its
associates should be used for, I think the following message sums up
one side of the conflicting demands made upon it:

http://mail.python.org/pipermail/python-dev/2004-October/049572.html

Because one platform has no package manager, people reach for the
closest solution, inflicting a (meta)package format on everyone else.
Attempts to make distutils work with .deb files seem to have stalled,
and I don't buy the "awkward Debian" argument that some suggest is the
reason for this. It's more likely that the metapackage format in
question isn't expressive enough to get the job done.

Paul

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


Re: Help me use my Dual Core CPU!

2006-09-13 Thread Robin Becker
Simon Wittber wrote:
> Paul Rubin wrote:
>> "Simon Wittber" <[EMAIL PROTECTED]> writes:
>>> I've just noticed that os.fork is not available on Win32. Ouch.
>> Use the subprocess module.
> 
> I can't see how subprocess.Popen can replace a fork. Using a manually
> started process is not really viable, as it does not automatically
> share pre-built (read-only) data between the processes. If it can, I'd
> really like to know how...
> 
> Yikes. This is a bummer. The conclusion seems to be, I cannot use any
> common cross platform, true concurrency strategies in my games. On top
> of that, I can't really use any form of concurrency on Win32.
> 
> Lets hope we get some super fast SMP friendly backends for PyPy sooner
> rather than later!
> 
> -Sw.
> 
Nobody seems to have mentioned POSH http://poshmodule.sourceforge.net
which used almost to work. I assume it's busted for later pythons and the 
author 
says it's just a demonstration.

Anandtech demoed an 8 core mac pro machine and were unable to "max out the 
cpus". Python needs some kind of multi cpu magic pretty quickly or we'll all 
end 
up using erlang :)

As for subprocess I don't see it as much use unless we can at least determine 
the number of cpu's and also set the cpu affinity easy with occam maybe not in 
python.
-- 
Robin Becker

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


Re: Newbie - ? get IDLE going on cygwin

2006-09-13 Thread David J. Braden
Thorsten Kampe wrote:
> * David J. Braden (2006-09-12 18:35 +0100)
>> I can run Python in command-line mode fine from the cygwin shell; the 
>> cygwin distribution also includes IDLE, which is apparently completely 
>> installed, yet I am unable to get IDLE running. When I double-click 
>> idle.bat (or idle.pyw) I am prompted to locate the program's creator. 
>> Darn if I know what it is. If I try to invoke IDLE from cygwen bash, I 
>> get "unable to remap c:\cygwin\bin\tk84.dll to same address as parent".
> 
> rebaseall
>  
>> Also - could someone plz recommend some useful environment variables for 
>> Python on Windows? If I were to specify PYTHONDOC, should I use Unix or 
>> Windows notation (e.g., "/" or "\").
> 
> You can set them under Windows in Windows notation or in your shell
> startup file in Unix notation.
> 
> Thorsten

Thanks, Thorsten. I assume you mean type in "idle rebaseall" (?) - seems 
to bring up a window for a split second, then come back with same error 
messages I had before. I cannot find in the IDLE doc any reference on 
how to get it going under cygwin; could you please point me towards a 
less-than-terse set of instructions?

Regards,
Dave B
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me use my Dual Core CPU!

2006-09-13 Thread Paul Rubin
Robin Becker <[EMAIL PROTECTED]> writes:
> Nobody seems to have mentioned POSH http://poshmodule.sourceforge.net
> which used almost to work. I assume it's busted for later pythons and
> the author says it's just a demonstration.

Yeah, it's been mentioned.

> Anandtech demoed an 8 core mac pro machine and were unable to "max out
> the cpus".

You mean with POSH??!  And I see a 4 core machine on Apple's site but
not an 8 core.  

> Python needs some kind of multi cpu magic pretty quickly or we'll
> all end up using erlang :)

Heh, yeah ;).  

> As for subprocess I don't see it as much use unless we can at least
> determine the number of cpu's and also set the cpu affinity easy with
> occam maybe not in python.

I haven't looked at Occam.  I've been sort of interested in Alice
(concurrent ML dialect), though apparently the current version is
interpreted.  Erlang is of less somewhat interest to me because it's
dynamically typed like Python.  Not that dynamic typing is bad, but
I'm already familiar with Python (and previously Lisp) so I'd like to
try out one of the type-inferenced languages in order to get a feel
for the difference.  I'd also like to start using something with a
serious optimizing compiler (MLton, Ocaml) but right now none of these
support concurrency.

I guess I should check into GHC:

  http://www.haskell.org/haskellwiki/GHC/Concurrency
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it just me, or is Sqlite3 goofy?

2006-09-13 Thread Magnus Lycka
First of all, anyone with extensive experience in database systems
understand that validating and cleaning input is an unavoidable task.

Static typing can help identify some of the problems, but far from
all, and there is often data processing done before the data enters
the database, so it's often too late to do the cleaning at that time
anyway.

Once you are dealing with data within your system, it's a bug in the
software if data doesn't fulfill the intended constraints. Such
problems should be identified by unit tests.

Mike Owens wrote:
> Next, as far as transferring you data, you most likely have to resort
> to some delimited format, or INSERT statements, which is no different
> than any other database.

You can always write a Python script which reads from one
database, cleans up the data and inserts into another, one
row at a time. This isn't just a porting activity. I've written
a Python app that moved data from a DB2 mainframe production
database to DB2 testing database on Windows. It moved data
from a hierarchy of tables, starting in a given table, and
reading foreign keys from system tables (very slow in mainframe
DB2!) to figure out what data to bring from which tables.

Since the system used abstract keys and moved data to a populated
database, it had to generate new keys and adjust the foreign keys
in the dependent tables. It also had to work around bugs and
quirks in Windows NT, DB2 and ADODBAPI etc. These things are
relatively easy, but it's never trivial. There are always a lot
of details to deal with.

For big volumes, you typically need to use some kind of bulk
loading facility. Inserts are generally much too slow. (I'm
talking about general data porting woes here--in the case of
SQLite it's not likely that you have many million rows of data.)

Efficient bulk loading means that you have different data format
for different database systems, and also that you need to validate
your data before insertion, so the problems directly related to
SQLite doesn't seem very odd.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to write UNIX daemons in Python?

2006-09-13 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

> Hi all. I've just finished to write an FTP daemon in Python.
> To do things well I'd like to write an 'insteller' to permit the end
> user to 'deeply' install the package inside the system. In details I
> would like that installer is able to do the following operations:
> 
> - copy ftpd.py in /usr/bin.
> - depending on the system, it should be able to determinate where
> service startup directory is located (for example /etc/init.d)  and
> copy a script able to automatically run /usr/ftpd.py at startup.
> - optionally install a manual callable with "man ftpd".
> - many other operations about the installation of a package.
> 
> What should I use to do something like that? Do I have to use
> distutils? Do I have to use third party packages? Do I have to write a
> "setup.py" and solve the problem manually?
> This last solution is problematic becouse, for (dumb) example, Debian
> wants executable/programs to be located in /usr/bin while Fedora uses
> another path (for example /usr/sbin).
> 
> Another question: what about .deb, .rpm, [...] packages?
> Does it possible to use them with Python programs?
> Resolving third party dependancies by using them could be a nice thing.

You can use setuptools to generate scripts in the various bin-directories.
And of course you could try and make setup.py detect the system & adapt the
necessary paths accordingly.

But the best thing to do would certainly be a package - however, I'm not
aware that there is any support for that. But a look here might be a start:

http://wiki.debian.org/DebianPythonFAQ

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


Re: os.name under Win32

2006-09-13 Thread Igor Kravtchenko
Hi again,

I get back to this old "thread".

sys.platform returns indeed "win32" under Windows.

os.name should return "posix" even under Windows if we are under Cygwin 
as Martin suggested.

Recently, someone advised me to use instead:
platform.system()

that returns only 3 different strings: Java, Linux or Windows.  End of 
story.

Is this not supposed to work better than sys.platform?
Indeed I'm pretty worried about having "win64" returned on further os 
like Windows Vista
and having our tests failing again.

Igor.



Fredrik Lundh wrote:

>Igor Kravtchenko wrote:
>
>  
>
>>We have an application using Python that is intended to work both under 
>>Win32 and Linux.
>>Since some parts of the code need to be different depending whether we 
>>are under Win32
>>or Linux, we use the traditional:
>>
>>if os.name == "posix":
>>  some Linux code
>>else:
>>  some Win32 code
>>
>>
>
>the usual thing to test for is sys.platform, not os.name.
>
>if sys.platform == "win32":
>some win32 code (or win64 code)
>else:
>some linux code
>
>  
>
>>However, we have noticed that under some circumstances, in some cases, 
>>in some computers under Windows XP Family that the "posix" code was
>>
>>
> > executed causing of course a crash.
>
>sounds weird.  have you checked your code so you don't assign to os.name 
>somewhere, by accident?
>
>
>
>  
>

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


Re: Are Python's reserved words reserved in places they dont need tobe?

2006-09-13 Thread Diez B. Roggisch
>> Exactly how am I supposed to use my text editor to make words bold? Is
>> every text editor supposed to understand a "python format" for code?
> 
> The standard answer here to people complaining about their editor not
> working well with python is that they should use a better editor.

In general, that is true for the 21st century. But under certain
circumstances, one might be forced to use a vi over a limited b/w terminal
to fix that goddamn bug on the live system.

Even though you don't care about the pesky details, it boils down to
introducing an escape mechanism that will surround whatever identifiers
there are. Which looks crap in anything except and python-aware editor. 

But I bet you don't work with e.g. subversion to display diffs and the
like...

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


Re: best small database?

2006-09-13 Thread Pierre Quentel
Buzhug (like Karrigell and Strakell) is a Breton word ; Breton is the
language spoken in Brittany, the westernmost part of France. Less and
less spoken, actually, but I do, like all my ancestors. It is a close
cousin of Welsh, and has common roots with Irish and Gaelic

Buzhug means "earthworm", the big long brown worms that you find when
you dig ; the shape is the same as a python, only smaller and less
dangerous...

You pronounce it "buzuk", with the French "u" or German "ü"

Karrigell means "cart" and strakell, any sort of engine that you don't
know its name. Bot rhyme with "hell" ; a and r like in French, g like
in goat

Now you know 3 words of Breton !

Regards,
Pierre

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


RE: pyLinda?

2006-09-13 Thread Tim Golden
(Caveat Lector: I've dabbled with this, but a while ago)

[Gardner Pomper]
| It sounds like pyLinda runs a server process and stores 
| tuples in it. 

That's about. From the "Beginner's Guide" page:
http://www-users.cs.york.ac.uk/aw/pylinda/beginner.html

"""
First a server must be started - linda_server.py
.
.
If you want to add a new computer to the linda network simply 
run 'linda_server.p -c' where the 
computer you supply is already running a linda server.
"""

| How does this work with multiple machines? One 
| server per machine? 

Yes. As above. I suppose one could build some sort
of directory or discovery service if one wanted.
(Haven't tried it; no idea what the pitfalls might be).

| Do you connect to your local server and then that server 
| has some sort of directory that tells it which server 
| holds the object you are looking for? Or are the servers 
| synchronized somehow? 

What you're doing here is matching a tuple, not finding
named objects as such (which is what your "directory"
suggested to me). That said, there is a well-known
("universe") tuplespace which everyone can get hold
of -- don't know what the underlying mechanism is, 
and I don't have the source code to hand. The idea
is that if you create your own tuplespace, you put
*that* tuplespace in the universal one so that 
other processes can pick it up. eg,

http://www-users.cs.york.ac.uk/aw/pylinda/doc/tutorial.html

NB This uses a non-destructive read (_rd) so that any
other process can look for the well-known tuple or
tuple-pattern. (eg you could specify that a new tuplespace
will be published as ("TUPLESPACE", linda.TupleSpace) where 
the second item in the tuple is the tuplespace in question.

| That should get me started. As many others here, I don't have 
| an immediate project for pyLinda, but I would like to 
| understand what it offers better so that I can identity an 
| appropriate project if one appears.

I think the thing it's best suited for is distributed
computing, rather like a sort of networked Python Queue
object (vague hand-waving...).

TJG


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

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


Re: Are Python's reserved words reserved in places they dont need tobe?

2006-09-13 Thread Antoon Pardon
On 2006-09-13, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
>>> Exactly how am I supposed to use my text editor to make words bold? Is
>>> every text editor supposed to understand a "python format" for code?
>> 
>> The standard answer here to people complaining about their editor not
>> working well with python is that they should use a better editor.
>
> In general, that is true for the 21st century. But under certain
> circumstances, one might be forced to use a vi over a limited b/w terminal
> to fix that goddamn bug on the live system.

AFAIR, even those terminals had a form of highlighting. And personnaly
I would think PEP 0263 would be potentially more annoying than this
idea in those circumstances.

> Even though you don't care about the pesky details, it boils down to
> introducing an escape mechanism that will surround whatever identifiers
> there are. Which looks crap in anything except and python-aware editor. 
>
> But I bet you don't work with e.g. subversion to display diffs and the
> like...

I wouldn't be surprised that looking at diffs from files that use
PEP 0263 could look like crap too. Yes some decisions can cause 
some tools to be less usefull. I would say that the right cause
of action is then to adapt those tools. Not to let something like
that stop your decision.

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


Re: Help me use my Dual Core CPU!

2006-09-13 Thread Robin Becker
Paul Rubin wrote:
> Robin Becker <[EMAIL PROTECTED]> writes:
>> Nobody seems to have mentioned POSH http://poshmodule.sourceforge.net
>> which used almost to work. I assume it's busted for later pythons and
>> the author says it's just a demonstration.
> 
> Yeah, it's been mentioned.
> 
>> Anandtech demoed an 8 core mac pro machine and were unable to "max out
>> the cpus".
> 
> You mean with POSH??!  And I see a 4 core machine on Apple's site but
> not an 8 core.  
> 

No I think they tried to just run a lot of processes at once and they got the 8 
core by just substituting the two dual cores with two quads.

>> Python needs some kind of multi cpu magic pretty quickly or we'll
>> all end up using erlang :)
> 
> Heh, yeah ;).  
> 
>> As for subprocess I don't see it as much use unless we can at least
>> determine the number of cpu's and also set the cpu affinity easy with
>> occam maybe not in python.
> 
> I haven't looked at Occam.  I've been sort of interested in Alice

I used occam back in the eighties with ibm pcs and these 4 transputer plugin 
cards. One of my bosses was Scottish MP and heavily into macro economic 
modelling (also an inmos supporter). I seem to remember doing chaotic 
gauss-seidel with parallel equation block solving, completely pointless as the 
politicos just ignored any apparent results. Back of the envelope is good 
enough 
for war and peace it seems.

Is suppose Alice isn't related to the "Alice Machine" which was a tagged pool 
processor of some kind. I recall it being delivered just when prolog and the 
like were going out of fashion and it never got faster than a z80 on a hot day.

> (concurrent ML dialect), though apparently the current version is
> interpreted.  Erlang is of less somewhat interest to me because it's
> dynamically typed like Python.  Not that dynamic typing is bad, but
> I'm already familiar with Python (and previously Lisp) so I'd like to
> try out one of the type-inferenced languages in order to get a feel
> for the difference.  I'd also like to start using something with a
> serious optimizing compiler (MLton, Ocaml) but right now none of these
> support concurrency.
> 
> I guess I should check into GHC:
> 
>   http://www.haskell.org/haskellwiki/GHC/Concurrency


-- 
Robin Becker

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


Re: Help me use my Dual Core CPU!

2006-09-13 Thread Simon Wittber
Paul Boddie wrote:
> Simon Wittber wrote:
> > Michael wrote:
> > > Also, Paul Boddie posted a module for parallel systems a while back as 
> > > well
> > > which might be useful (at least for ideas):
> > >* http://cheeseshop.python.org/pypi/parallel
> > >
> > I've just noticed that os.fork is not available on Win32. Ouch.
>
> Sorry! My motivation was to support operating systems that I personally
> care about and which also have solutions for transparent process
> migration, which I believe could be used in conjunction with the
> pprocess module for better-than-thread parallelisation.

Ah don't be sorry! I don't care about Win32 a whole lot either, its
just that most of my target market use Win32...

> Rumour has it that recent versions of Windows provide fork-like
> semantics through a system call. Your mission is to integrate this
> transparently into the standard library's os.fork function. ;-)

I'm not sure I'm up to this kind of low level stuff, though if the itch
really starts to _itch_, I might have a crack at scratching it. :-)


-Sw

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


Re: Is it just me, or is Sqlite3 goofy?

2006-09-13 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
> What was Richard Hipp's justification for slandering the
> writers of the SQL Language Specification?

First of all, if you read the text you quoted and understand
English, you should be able to see that the author of the
text is clearly expressing an opinion, not stating a fact.

Calling this lies or slander is just absurd.

"the authors of SQLite feel very strongly that this is a
feature"

"The authors argue that static typing is a bug in the SQL
specification"

If you think that these sentences imply some kind objective
truth that could be claimed to be a lie, then you are confused
about English or logic or both.

 > Is there anything more rude than describling the SQL Language
 > Specification as a bug that needs to be fixed?

Using "waterheadretard" in a posting subject perhaps?

Seriously, this is the first time I ever heard anyone
being religious about the SQL standard in that way.

Also, while I actually find your statement about SQL being
a bug rather funny and fitting, it's not what Hipp is saying.
He's talking about static typing, which is really only a
detail in SQL and has no bearing on the relational theories.
Equality and inequality can certainly be defined in a strict
way regardless on whether it is columns or values that have a
distinct type. The use of NULL as a permitted value for all
types mean that SQL has already relaxed the traditional type
mechanism a bit. Python, Tcl, SQLite etc goes one step further.

To cleanse you from this affliction, I suggest that you
read Date and Darwen's "A Guide to the SQL Standard".
After all, these guys are seriously involved in the SQL
standard development, and they are certainly not very
religious about it. Among their claims you can find these
pearls: "SQL in particular is very far from ideal as a
relational language", "although there are well-established
principles for the design of formal languages, there is
little evidence that SQL was ever designed in accordance
with any such principles", "Standard SQL especially is
additionally deficient in a number of respects".

Many people have claimed through the years that SQL is
broken, and that Quel was a much better language, and the
only reason that SQL killed Quel and not vice versa was the
IBM backing. Richard Hipp is hardly being controversial
in this respect...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Are Python's reserved words reserved in places they dont need tobe?

2006-09-13 Thread Diez B. Roggisch
>> In general, that is true for the 21st century. But under certain
>> circumstances, one might be forced to use a vi over a limited b/w
>> terminal to fix that goddamn bug on the live system.
> 
> AFAIR, even those terminals had a form of highlighting. And personnaly
> I would think PEP 0263 would be potentially more annoying than this
> idea in those circumstances.

How so? Because some less important string literals  might be fucked up?
Certainly can that cause trouble, but having the trouble for each and every
keyword is a huge difference.

>> Even though you don't care about the pesky details, it boils down to
>> introducing an escape mechanism that will surround whatever identifiers
>> there are. Which looks crap in anything except and python-aware editor.
>>
>> But I bet you don't work with e.g. subversion to display diffs and the
>> like...
> 
> I wouldn't be surprised that looking at diffs from files that use
> PEP 0263 could look like crap too. Yes some decisions can cause
> some tools to be less usefull. I would say that the right cause
> of action is then to adapt those tools. Not to let something like
> that stop your decision.

The same reasoning as above applies. 

And sure you would say that - the day you admit to have suggested a stupid
thing won't be in my hopefully long-standing life span. 

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


Re: Help me use my Dual Core CPU!

2006-09-13 Thread Paul Rubin
Robin Becker <[EMAIL PROTECTED]> writes:
> No I think they tried to just run a lot of processes at once and they
> got the 8 core by just substituting the two dual cores with two quads.

Huh?!  There are no quad core x86 cpu's as far as I know ;).

> I used occam back in the eighties with ibm pcs and these 4 transputer
> plugin cards. One of my bosses was Scottish MP and heavily into macro
> economic modelling (also an inmos supporter). I seem to remember doing
> chaotic gauss-seidel with parallel equation block solving, completely
> pointless as the politicos just ignored any apparent results. Back of
> the envelope is good enough for war and peace it seems.

Heh :).  OK, yeah, I remember Occam now, it used CSP (communicating
sequential processes) for concurrency if I remember, sort of like
Erlang?

> Is suppose Alice isn't related to the "Alice Machine" which was a
> tagged pool processor of some kind. I recall it being delivered just
> when prolog and the like were going out of fashion and it never got
> faster than a z80 on a hot day.

No I don't think so.  It's Standard ML with some concurrency extensions
and a really nice toolkit: 

   http://www.ps.uni-sb.de/alice/ 

Actually I'm not sure now whether it supports real multiprocessor
concurrency.  It looks cool anyway.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python reference counting and exceptions

2006-09-13 Thread Andreas Huesgen


Delaney, Timothy (Tim) wrote:
> RIIA - Resource Initialisation is Acquisition
> 
> Python is adding an RIIA mechanism in 2.5 - look at the "with"
> statement.
> 

Ah, thanks, thats exactly what I was looking for.


Gabriel Genellina wrote:
> Yes: the try/finally construct, which is *not* the same as a try/except. The 
> finally clause is always executed, whether or not an exception is raised.

Yes, of course it must be the try finally construct and not try/except. 
Shame on me ;)

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


Re: Is it just me, or is Sqlite3 goofy?

2006-09-13 Thread Magnus Lycka
Paul Boddie wrote:
> To be fair, that text originates in section 12.3, referring to input
> parameters to procedures. Meanwhile, the following text (subclause
> 13.8, "") appears to be more pertinent:
> 
> "If the data type of the target identified by the i-th  is
> an exact numeric type, then the data type of the i-th item of the
>  shall be an exact numeric type."

And SQLite behaves as expected if you provide a numeric value
to a numeric column, right? In other words, it complies to that
clause.

Does the spec state how the database engine should behave if the
client breaks the requirements for insert? I guess that this is
implementation dependent.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help me use my Dual Core CPU!

2006-09-13 Thread Paul Boddie
Simon Wittber wrote:
> Paul Boddie wrote:
> > Rumour has it that recent versions of Windows provide fork-like
> > semantics through a system call. Your mission is to integrate this
> > transparently into the standard library's os.fork function. ;-)
>
> I'm not sure I'm up to this kind of low level stuff, though if the itch
> really starts to _itch_, I might have a crack at scratching it. :-)

Here's a message which might provide a decent starting point:

http://groups.google.com/group/comp.lang.python/msg/fdadd7b615e7824b

Paul

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


RELEASED Python 2.5 (release candidate 2)

2006-09-13 Thread Anthony Baxter
On behalf of the Python development team and the Python
community, I'm happy to announce the second RELEASE
CANDIDATE of Python 2.5.

After the first release candidate a number of new bugfixes
have been applied to the Python 2.5 code. In the interests
of making 2.5 the best release possible, we've decided to
put out a second (and hopefully last) release candidate. We
plan for a 2.5 final in a week's time.

This is not yet the final release - it is not suitable for
production use. It is being released to solicit feedback
and hopefully expose bugs, as well as allowing you to
determine how changes in 2.5 might impact you. As a release
candidate, this is one of your last chances to test the new
code in 2.5 before the final release. *Please* try this
release out and let us know about any problems you find.

In particular, note that changes to improve Python's support
of 64 bit systems might require authors of C extensions
to change their code. More information (as well as source
distributions and Windows and Universal Mac OSX installers)
are available from the 2.5 website:

http://www.python.org/2.5/

As of this release, Python 2.5 is now in *feature freeze*.
Unless absolutely necessary, no functionality changes will
be made between now and the final release of Python 2.5.

The new features in Python 2.5 are described in Andrew
Kuchling's What's New In Python 2.5. It's available from the
2.5 web page.

Amongst the language features added include conditional
expressions, the with statement, the merge of try/except
and try/finally into try/except/finally, enhancements to
generators to produce a coroutine kind of functionality, and
a brand new AST-based compiler implementation.

New modules added include hashlib, ElementTree, sqlite3,
wsgiref, uuid and ctypes. In addition, a new profiling
module "cProfile" was added.

Enjoy this new release,
Anthony

Anthony Baxter
[EMAIL PROTECTED]
Python Release Manager
(on behalf of the entire python-dev team)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie - ? get IDLE going on cygwin

2006-09-13 Thread Jason Tishler
Dave,

On Wed, Sep 13, 2006 at 09:42:48AM +, David J. Braden wrote:
> Thorsten Kampe wrote:
> > * David J. Braden (2006-09-12 18:35 +0100)
> >> I can run Python in command-line mode fine from the cygwin shell;
> >> the cygwin distribution also includes IDLE, which is apparently
> >> completely installed, yet I am unable to get IDLE running. When I
> >> double-click idle.bat (or idle.pyw) I am prompted to locate the
> >> program's creator.  Darn if I know what it is. If I try to invoke
> >> IDLE from cygwen bash, I get "unable to remap
> >> c:\cygwin\bin\tk84.dll to same address as parent".
> > 
> > rebaseall
> >  
> [snip]
> 
> Thanks, Thorsten. I assume you mean type in "idle rebaseall" (?) -
> seems to bring up a window for a split second, then come back with
> same error messages I had before. I cannot find in the IDLE doc any
> reference on how to get it going under cygwin; could you please point
> me towards a less-than-terse set of instructions?

Here's another terse response:


http://www.google.com/search?hl=en&q=unable+remap+same+address+parent&btnG=Google+Search

:,)

The following are excerpts from the rebase README:

The rebaseall utility is a convenient way for users that suffer from
the Cygwin rebase problem to rebase their entire system (i.e., all
of their DLLs).  The following is a list of known Cygwin
applications that are affected by the rebase problem:

Apache
Perl
Python

The rebase problem is due to fork() failing when it is unable to
load DLLs in the child at the same address as in the parent.  This
is caused by DLLs which have conflicting base addresses.  An error
message like the following will be displayed when the problem is
triggered:

C:\cygwin\bin\python.exe: *** unable to remap C:\cygwin\bin\cygssl.dll
to same address as parent(0xDF) != 0xE0

Use the following procedure to rebase your entire system:

1. shutdown all Cygwin processes and services
2. start ash (do not use bash or rxvt)
3. execute /bin/rebaseall (in the ash window)

BTW, idle has problems running under Cygwin Python:

http://sf.net/tracker/?func=detail&atid=105470&aid=786827&group_id=5470

Jason

-- 
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: auto upgrade scripts?

2006-09-13 Thread Larry Bates
[EMAIL PROTECTED] wrote:
>> Auto-upgrade from what to what?
>> -Larry Bates
> 
> Interesting question.
> 
> In my case I want my program to check for (e.g.) bug-fix releases on
> some location (network drive or ftp), and if available, allow to
> automatically download and install them.
> Kind of like the AutoUpgrade functionality in .net (*shudder*) ;)
> 
> Best regards,
> Stefaan.
> 

Since you mention .NET and didn't state otherwise, I'm assuming
Windows platform?  You should probably take a look at Inno Installer
with web update wizard:

http://www.powerprogrammer.co.uk/web-update-download/web-update-download.html

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


Re: Is it just me, or is Sqlite3 goofy?

2006-09-13 Thread Paul Boddie
Magnus Lycka wrote:
> Paul Boddie wrote:
> > To be fair, that text originates in section 12.3, referring to input
> > parameters to procedures. Meanwhile, the following text (subclause
> > 13.8, "") appears to be more pertinent:
> >
> > "If the data type of the target identified by the i-th  is
> > an exact numeric type, then the data type of the i-th item of the
> >  shall be an exact numeric type."
>
> And SQLite behaves as expected if you provide a numeric value
> to a numeric column, right? In other words, it complies to that
> clause.

My 30 seconds' worth of consideration suggests that you have to
consider the matter the other way round: if the data type of some
column is an exact numeric type, then you should be providing a value
of such a type, not a string, for example.

> Does the spec state how the database engine should behave if the
> client breaks the requirements for insert? I guess that this is
> implementation dependent.

Well, if the client is free not to bother signalling anything about
erroneous value types, one has to wonder why there's so much of a
specification.

Paul

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


Re: table (ascii text) lin ayout recognition

2006-09-13 Thread bearophileHUGS
My version, not much tested. It probably doesn't work well for tables
with few rows. It finds the most frequent word beginnings, and then
splits the data according to them.

data = """\
44544  ipod  apple black 102
GFGFHHF-12 unknown thing bizar brick mortar  tbc
45fjk  do not know   + is less   biac
   disk  seagate   250GB 130
5G_gff   tbd   tbd
gjgh88hgg  media record  a and b 12
hjjfoo   bar   hop   zip
hg uy oi   hj uuu ii a   qqq ccc v ZZZ Ughj
qdsd   zertnope  nope
"""

import re, pprint
# import collections # For Python 2.5

# RE to find the beginning of words
tpatt = re.compile(r"\b[^ ]")

# Remove empty lines
lines = filter(None, data.splitlines())

# Find the positions of all word beginnings
# This finds:  treshs = [0, 11, 25, 35, 49, ...
# 44544  ipod  apple black 102
# ^  ^ ^ ^ ^
treshs = [ob.start() for li in lines for ob in tpatt.finditer(li)]

# Find treshs frequences
freqs = {}
for el in treshs:
freqs[el] = freqs.get(el, 0) + 1

# Find treshs frequences, alternative for Python V.2.5
# freqs = collections.defaultdict(int)
# for el in treshs:
# freqs[el] += 1

# Find a big enough frequence
bigf = max(freqs.itervalues()) * 0.6

# Find the most common column beginnings
cols = sorted(k for k,v in freqs.iteritems() if v>bigf)

def xpairs(alist):
"xpairs(xrange(n)) ==> (0,1), (1,2), (2,3), ..., (n-2, n-1)"
for i in xrange(len(alist)-1):
yield alist[i:i+2]

result = [[li[x:y].strip() for x,y in xpairs(cols+[None])] for li in
lines]

print data
pprint.pprint(result)


"""
Output:

44544  ipod  apple black 102
GFGFHHF-12 unknown thing bizar brick mortar  tbc
45fjk  do not know   + is less   biac
   disk  seagate   250GB 130
5G_gff   tbd   tbd
gjgh88hgg  media record  a and b 12
hjjfoo   bar   hop   zip
hg uy oi   hj uuu ii a   qqq ccc v ZZZ Ughj
qdsd   zertnope  nope

[['44544', 'ipod', 'apple', 'black', '102'],
 ['GFGFHHF-12', 'unknown thing', 'bizar', 'brick mortar', 'tbc'],
 ['45fjk', 'do not know', '+ is less', '', 'biac'],
 ['', 'disk', 'seagate', '250GB', '130'],
 ['5G_gff', '', 'tbd', 'tbd', ''],
 ['gjgh88hgg', 'media record', 'a and b', '', '12'],
 ['hjj', 'foo', 'bar', 'hop', 'zip'],
 ['hg uy oi', 'hj uuu ii a', 'qqq ccc v', 'ZZZ Ughj', ''],
 ['qdsd', 'zert', '', 'nope', 'nope']]
"""

Bye,
bearophile

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


Re: Are Python's reserved words reserved in places they dont need tobe?

2006-09-13 Thread Antoon Pardon
On 2006-09-13, Diez B. Roggisch <[EMAIL PROTECTED]> wrote:
>>> In general, that is true for the 21st century. But under certain
>>> circumstances, one might be forced to use a vi over a limited b/w
>>> terminal to fix that goddamn bug on the live system.
>> 
>> AFAIR, even those terminals had a form of highlighting. And personnaly
>> I would think PEP 0263 would be potentially more annoying than this
>> idea in those circumstances.
>
> How so? Because some less important string literals  might be fucked up?
> Certainly can that cause trouble, but having the trouble for each and every
> keyword is a huge difference.

Viewing such an unimportant string literal might lockup your terminal,
because your terminal interprets it as somekind of control sequence.
Your keyword trouble would probably be less than looking at html code
in those circumstances.

>>> Even though you don't care about the pesky details, it boils down to
>>> introducing an escape mechanism that will surround whatever identifiers
>>> there are. Which looks crap in anything except and python-aware editor.
>>>
>>> But I bet you don't work with e.g. subversion to display diffs and the
>>> like...
>> 
>> I wouldn't be surprised that looking at diffs from files that use
>> PEP 0263 could look like crap too. Yes some decisions can cause
>> some tools to be less usefull. I would say that the right cause
>> of action is then to adapt those tools. Not to let something like
>> that stop your decision.
>
> The same reasoning as above applies. 
>
> And sure you would say that - the day you admit to have suggested a stupid
> thing won't be in my hopefully long-standing life span. 

That you don't like it, is not the same as stupid. Your two arguments
against, have nothing to do with the quality of the suggestion within
the langauge but only with problems of the envinronment.

You know, if I want, I can probably turn up some old terminal where
you can only type uppercase letters. What if under certain circumstance
I would be forced, to use this old thing. Would I then have a rightfull
complaint against python because it is case significant?

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


Re: Extra Unittest Information

2006-09-13 Thread Robert Kern
Calvin Spealman wrote:
> This is something I have been wanting to find for a while, but i
> haven't figured out. I really would love to know if there is some way
> I can report extra information while running unittests, and have that
> information appear along with the tracebacks, so its near the relevent
> test's results.

Several test runners (py.test, testoob, nose) will trap stdout and stderr and 
only display them if that test fails. Then you can simply use print statements 
in your test methods.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

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


Re: Gadfly server startup error

2006-09-13 Thread Ralf Muschall
Steve Holden wrote:

> You're already doing better than I am. On Cygwin 2.5rc2 and Windows 
> 2.4.2 I can't even get it to runs its tests properly:

I don't remember whether I looked into that at all.

...
> NameError: global name 'Server' is not defined

...
> Time to report a bug, methinks? Makes SQLite look good  ...

Carl Waldbieser reported this bug (and a few others, including
fixes) in April 04 (entry 94049[35]).  It seems the project
fell asleep four years ago (but in "News" on SF is a more recent
message from the author pointing to xsdb).

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


socket question

2006-09-13 Thread hg
Hi,

I am not sure whether this is a python-related question.

If I have device A than sends XX bytes to device B, and device B does a
recv(XX) using the default timeout, what could make device B wake-up
with less than XX bytes received ?

Regards,

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


Re: Scientific computing and data visualization.

2006-09-13 Thread Paul F. Kunz
"Fie Pye" <[EMAIL PROTECTED]> writes:

> Hallo
>   
>   I would like to have a high class open source tools for scientific 
> computing and powerful 2D and 3D data visualisation. Therefore I chose 
> python, numpy and scipy as a base. Now I am in search for a visualisation 
> tool. I tried matplotlib and py_opendx with OpenDx. OpenDx seems to me very 
> good but the project py_opendx looks like closed. After py_opendx instalation 
> and subsequent testing I got an error that needs discussion with author or an 
> experienced user. Unfortunately a mail to author returned as undeliverable.
>   
>   Does anybody now about suitable visualisation tool?
>   
Have you looked at HippoDraw?

http://www.slac.stanford.edu/grk/ek/hippodraw
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: os.access(file, os.R_OK) on UNIX and WINDOWS

2006-09-13 Thread Tim Golden
[kai rosenthal]

| on UNIX I changed the permission of a file "myfile" with chmod 000
| myfile. Then I got 0 from os.access(myfile, os.R_OK). This is ok.
| 
| Then I checked the same file on WINDOWS (with samba):
| I got "True" from os.access(myfile, os.R_OK). I think it is not ok?!

Ummm. This is a touch similar to a parallel thread about
os.X_OK on Win32. At the risk of being grilled by better-informed
types, the fact is that while the Win32 CRT (used for non-Unicode
operations by the Python os module) does expose chmod and
access functions, they don't seem guaranteed to do more than overlap
more-or-less with the corresponding Unix functions.

>From what appears to be the MSDN page for chmod [1]:
"""
The permission setting controls read and write access to the file. 
The integer expression pmode contains one or both of the following 
manifest constants, defined in SYS\STAT.H:

_S_IWRITE - Writing permitted
_S_IREAD - Reading permitted
_S_IREAD | _S_IWRITE - Reading and writing permitted

Any other values for pmode are ignored. 
"""

Note that last sentence: I take this to mean that passing
zero to mean "can't read or write" is having no effect.

The latest Python source source [2] uses the Win32 API
SetFileAttributesW [3] where a Unicode filename is passed, 
but this doesn't seem to allow for a neither-read-nor-write
situation either.

| In my python script I check the return value of os.access(myfile,
| os.R_OK) and when it is "True" I copy the file with 
| shutil.copy(myfile, newfile).
| But on WINDOWS I get the error: IOError: [Errno 13] Permission denied.

I suspect you're going to have to put the copy in a
try... except block, which is not bad advice in any
case. If you check access and then copy, you're at
the mercy of a change to the file's permissions (or
even existence) between the calls, so you'd have to
cope with a potential exception in any case. Better
perhaps to do it that way in the first place. This
point of view is supported by, among others, GvR
in a thread on python-dev. [4]

[1]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore9
8/html/_crt__chmod.2c_._wchmod.asp[2]
http://svn.python.org/view/python/trunk/Modules/posixmodule.c?rev=51762&;
view=auto
[3]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/
fs/setfileattributes.asp
[4]
http://mail.python.org/pipermail/python-dev/2004-November/049931.html

In short, do something like this:


try:
  shutil.copy (myfile, newfile)
except IOError:
  print "Couldn't copy; do useful things or ignore"
else:
  print "Copied ok"


TJG


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

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


Re: socket question

2006-09-13 Thread Diez B. Roggisch
hg wrote:

> Hi,
> 
> I am not sure whether this is a python-related question.
> 
> If I have device A than sends XX bytes to device B, and device B does a
> recv(XX) using the default timeout, what could make device B wake-up
> with less than XX bytes received ?

There exist higher abstractions for sockets in python for IPC - are you sure
you want to reinvent the wheel?

If you absolutely must: the select-call allows for specification of a
timeout. Use it with the socket file-descriptor.

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


Re: socket question

2006-09-13 Thread Jean-Paul Calderone
On Wed, 13 Sep 2006 08:13:43 -0500, hg <[EMAIL PROTECTED]> wrote:
>Hi,
>
>I am not sure whether this is a python-related question.
>
>If I have device A than sends XX bytes to device B, and device B does a
>recv(XX) using the default timeout, what could make device B wake-up
>with less than XX bytes received ?

Assuming the sends take place over a TCP connection, any number of things.
In generally, you cannot rely on anything about the length of the string
returned from recv(N) except that:

  it will not be greater than N
  it will not be less than 1 unless the connection has been lost

If you expect a particular number of bytes, you need to call recv()
multiple times and collect the returned strings until you have as many
bytes as you wanted.

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


Re: Random Drawing Simulation -- performance issue

2006-09-13 Thread Brendon Towle

On 12 Sep 2006, at 6:33 PM, [EMAIL PROTECTED] wrote:

> Date: 12 Sep 2006 15:23:51 -0700
> From: "Simon Forman" <[EMAIL PROTECTED]>
> Subject: Re: Random Drawing Simulation -- performance issue
>
> Brendon Towle wrote:
>> I need to simulate scenarios like the following: "You have a deck of
>> 3 orange cards, 5 yellow cards, and 2 blue cards. You draw a card,
>> replace it, and repeat N times."
>>  [my original code snipped]
>
> I got nearly a 2x speed up with this variant:
>
> def randomDrawing3(count, population):
> res = [[0, item[1]] for item in population]
> mapping = []
> for i in xrange(len(population)):
> mapping.extend([i]*population[i][0])
>
> n = len(mapping)
> for i in xrange(count):
> index = int(n * random.random())
> res[mapping[index]][0] += 1
>
> return res

Excellent! For some reason, the speedup I get is only ~1.5x, but  
that's still non-trivial.

Thanks much for the pointer-

B.


-- 
Brendon Towle, PhD
Cognitive Scientist
+1-412-690-2442x127
Carnegie Learning, Inc.
The Cognitive Tutor Company ®
Helping over 375,000 students in 1000 school districts succeed in math.


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


Re: Help me use my Dual Core CPU!

2006-09-13 Thread Robin Becker
Paul Rubin wrote:
> Robin Becker <[EMAIL PROTECTED]> writes:
>> No I think they tried to just run a lot of processes at once and they
>> got the 8 core by just substituting the two dual cores with two quads.
> 
> Huh?!  There are no quad core x86 cpu's as far as I know ;).
> 

well these guys seem to think there are, perhaps it's a joke

http://anandtech.com/mac/showdoc.aspx?i=2832&p=6

>> I used occam back in the eighties with ibm pcs and these 4 transputer
>> plugin cards. One of my bosses was Scottish MP and heavily into macro
>> economic modelling (also an inmos supporter). I seem to remember doing
>> chaotic gauss-seidel with parallel equation block solving, completely
>> pointless as the politicos just ignored any apparent results. Back of
>> the envelope is good enough for war and peace it seems.
> 
> Heh :).  OK, yeah, I remember Occam now, it used CSP (communicating
> sequential processes) for concurrency if I remember, sort of like
> Erlang?
> 
>> Is suppose Alice isn't related to the "Alice Machine" which was a
>> tagged pool processor of some kind. I recall it being delivered just
>> when prolog and the like were going out of fashion and it never got
>> faster than a z80 on a hot day.
> 
> No I don't think so.  It's Standard ML with some concurrency extensions
> and a really nice toolkit: 
> 
>http://www.ps.uni-sb.de/alice/ 
> 
> Actually I'm not sure now whether it supports real multiprocessor
> concurrency.  It looks cool anyway.


-- 
Robin Becker

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


Re: Random Drawing Simulation -- performance issue

2006-09-13 Thread Brendon Towle
On 13 Sep 2006, at 1:01 AM, [EMAIL PROTECTED] wrote:

> Date: 12 Sep 2006 20:17:47 -0700
> From: Paul Rubin 
> Subject: Re: Random Drawing Simulation -- performance issue
> To: [email protected]
>
> "Travis E. Oliphant" <[EMAIL PROTECTED]> writes:
>>> I need to simulate scenarios like the following: "You have a deck of
>>> 3 orange cards, 5 yellow cards, and 2 blue cards. You draw a card,
>>> replace it, and repeat N times."
>>>
>> Thinking about the problem as drawing sample froms a discrete
>> distribution defined by the population might help.
>
> Is there some important reason you want to do this as a simulation?
> And is the real problem more complicated?  If you draw from the
> distribution 100,000 times with replacement and sum the results, per
> the Central Limit Theorem you'll get something very close to a normal
> distribution whose parameters you can determine analytically.  There
> is probably also some statistics formula to find the precise error.
> So you can replace the 100,000 draws with a single draw.

The real problem is not substantially more complicated. (The real  
code is, because it's embedded in a bunch of other stuff, but that's  
not the point.)

I guess the essential reason that I want to do it as a simulation,  
and not as a statistics formula, is that I'd like the code to be  
readable (and modifiable) by a programmer who doesn't have a  
statistics background. I could dredge up enough of my college stats  
to do as you suggest (although I might not enjoy it), but I don't  
think I want to make that a requirement.

On the other hand (quote somewhat snipped):

> Date: Tue, 12 Sep 2006 22:46:04 -0500
> From: Robert Kern <[EMAIL PROTECTED]>
> Subject: Re: Random Drawing Simulation -- performance issue
> To: [email protected]
>
> Along the lines of what you're trying to get at, the problem that  
> the OP is
> describing is one of sampling from a multinomial distribution.
>
> numpy has a function that will do the sampling for you:
>
> In [4]: numpy.random.multinomial?
> Docstring:
>  Multinomial distribution.
>
>  multinomial(n, pvals, size=None) -> random values
>
>  pvals is a sequence of probabilities that should sum to 1  
> (however, the
>  last element is always assumed to account for the remaining  
> probability
>  as long as sum(pvals[:-1]) <= 1).

Here, I'm torn. I do want the code to be accessible to non-stats  
people, but this just might do the trick. Must ponder.

Thanks, everyone, for your helpful suggestions!

B.

-- 
Brendon Towle, PhD
Cognitive Scientist
+1-412-690-2442x127
Carnegie Learning, Inc.
The Cognitive Tutor Company ®
Helping over 375,000 students in 1000 school districts succeed in math.


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


Re: Help me use my Dual Core CPU!

2006-09-13 Thread Paul Rubin
Robin Becker <[EMAIL PROTECTED]> writes:
> well these guys seem to think there are, perhaps it's a joke
> http://anandtech.com/mac/showdoc.aspx?i=2832&p=6

Wow!  Yes, it seems to be real ("Clovertown" 4-core cpu).  See:

http://www.tgdaily.com/2006/03/07/idf_keynotes_welcome_to_intel_3-point-0/

There's even a version that goes out to 32 cores ("Dunnington") on the
drawing boards.

We better get rid of that GIL soon ;-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket question

2006-09-13 Thread hg
Jean-Paul Calderone wrote:
> On Wed, 13 Sep 2006 08:13:43 -0500, hg <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I am not sure whether this is a python-related question.
>>
>> If I have device A than sends XX bytes to device B, and device B does a
>> recv(XX) using the default timeout, what could make device B wake-up
>> with less than XX bytes received ?
> 
> Assuming the sends take place over a TCP connection, any number of things.
> In generally, you cannot rely on anything about the length of the string
> returned from recv(N) except that:
> 
>  it will not be greater than N
>  it will not be less than 1 unless the connection has been lost
> 
> If you expect a particular number of bytes, you need to call recv()
> multiple times and collect the returned strings until you have as many
> bytes as you wanted.
> 
> Jean-Paul
Many thanks,

hg


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


Re: socket question

2006-09-13 Thread hg
Diez B. Roggisch wrote:
> hg wrote:
> 
>> Hi,
>>
>> I am not sure whether this is a python-related question.
>>
>> If I have device A than sends XX bytes to device B, and device B does a
>> recv(XX) using the default timeout, what could make device B wake-up
>> with less than XX bytes received ?
> 
> There exist higher abstractions for sockets in python for IPC - are you sure
> you want to reinvent the wheel?
> 
> If you absolutely must: the select-call allows for specification of a
> timeout. Use it with the socket file-descriptor.
> 
> Diez
Thanks I'll look, with the retry-wrapper around recv, it seem to work now.

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


xinclude and pathnames

2006-09-13 Thread Tim Arnold
I'm using ElementTree to access some xml configuration files, and using the 
module's xinclude capability. I've got lines like this in the parent xml 
file (which lives in the same directory as the included xml file):


When I started the project it was Unix-only; this worked fine. Now I have 
users who want to use the system on Windows and of course that directory 
path doesn't exist on Windows, but it is available on the network using a 
name like \\ladida\current\en\xml\asdf\asdf_syntaxterms.xml

if relative paths worked, I could imagine
 would work.
Also,the file can be read via an http server.

My question: is there a way to make xinclude work with relative paths or 
perhaps urls?
Any ideas welcome--to me it looks like I'll have to restructure this part of 
the system since I've basically programmed myself into a corner.

thanks,
--Tim Arnold


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


eval(repr(object)) hardly ever works

2006-09-13 Thread Matthew Wilson

I understand that idea of an object's __repr__ method is to return a
string representation that can then be eval()'d back to life, but it
seems to me that it doesn't always work. 

For example it doesn't work for instances of the object class:

In [478]: eval(repr(object()))

   File "", line 1
 
 ^
SyntaxError: invalid syntax

It seems to work for types like integers and dictionaries and lists,
but not for much else.

Any thoughts?


-- 
A better way of running series of SAS programs:
http://overlook.homelinux.net/wilsonwiki/SasAndMakefiles
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best small database?

2006-09-13 Thread Kay Schluehr

Pierre Quentel wrote:
> Buzhug (like Karrigell and Strakell) is a Breton word ; Breton is the
> language spoken in Brittany, the westernmost part of France. Less and
> less spoken, actually, but I do, like all my ancestors. It is a close
> cousin of Welsh, and has common roots with Irish and Gaelic
>
> Buzhug means "earthworm", the big long brown worms that you find when
> you dig ; the shape is the same as a python, only smaller and less
> dangerous...
>
> You pronounce it "buzuk", with the French "u" or German "ü"
>
> Karrigell means "cart" and strakell, any sort of engine that you don't
> know its name. Bot rhyme with "hell" ; a and r like in French, g like
> in goat
> 
> Now you know 3 words of Breton !
> 
> Regards,
> Pierre

Thanks !!!

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


Re: eval(repr(object)) hardly ever works

2006-09-13 Thread Hardcoded Software

Matthew Wilson wrote:
> I understand that idea of an object's __repr__ method is to return a
> string representation that can then be eval()'d back to life, but it
> seems to me that it doesn't always work.
>
> For example it doesn't work for instances of the object class:
>
> In [478]: eval(repr(object()))
> 
>File "", line 1
>  
>  ^
> SyntaxError: invalid syntax
>
> It seems to work for types like integers and dictionaries and lists,
> but not for much else.
>
> Any thoughts?
>
>
> --
> A better way of running series of SAS programs:
> http://overlook.homelinux.net/wilsonwiki/SasAndMakefiles

I don't think that repr() is for eval(). repr() is for outputting a
string that represent the object and is not ambiguous. Example: print
'foo' == print u'foo' but print repr('foo') != print repr(u'foo')

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


Re: eval(repr(object)) hardly ever works

2006-09-13 Thread skip

Matthew> I understand that idea of an object's __repr__ method is to
Matthew> return a string representation that can then be eval()'d back
Matthew> to life, but it seems to me that it doesn't always work.

No, where it's convenient that property is desirable.  It's not a
hard-and-fast rule though.  Some objects (think open files) it would be
impossible (or nearly so) to generate a representation which captured the
state of the object.  For others (basic types or containers of them), it's
pretty easy.

Matthew> It seems to work for types like integers and dictionaries and
Matthew> lists, but not for much else.

Matthew> Any thoughts?

Sure, if you want to save and restore objects, pickle or marshal them.
Don't rely on repr().

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


Re: table (ascii text) lin ayout recognition

2006-09-13 Thread Paul McGuire
"James Stroud" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> [EMAIL PROTECTED] wrote:
>> Hello,
>>
>> I am looking for python code useful to process
>> tables that are in ASCII text. The code must
>> determine where are the columns (fields).
>> Concerned tables for my application are various,
>> but their columns are not very complicated
>> to locate for a human, because even
>> when ignoring the semantic of  words,
>> our eyes see vertical alignments
>>
>> Here is a sample table (must be viewed
>> with fixed-width font to see alignments):
>> =
>>
>> 44544  ipod  apple black 102
>> GFGFHHF-12 unknown thing bizar brick mortar  tbc
>> 45fjk  do not know   + is less   biac
>>disk  seagate   250GB 130
>> 5G_gff   tbd   tbd
>> gjgh88hgg  media record  a and b 12
>> hjjfoo   bar   hop   zip
>> hg uy oi   hj uuu ii a   qqq ccc v ZZZ Ughj
>> qdsd   zertnope  nope
>>
>> =
>>
>> I want the python code that builds a representation
>> of this table (for exemple a list of lists, where each list
>> represents a table line, each element of the list
>> being a field value).
>>
>> Any hints?
>> thanks
>>
>
> As promised. I call this the "cast a shadow" algorithm for table 
> discovery. This is about as obfuscated as I could make it. It will be up 
> to you to explain it to your teacher ;-)
>

James -

I used your same algorithm, but I guess I used more brute force (and didn't 
use pyparsing, either!).

-- Paul


data = """\
44544  ipod  apple black 102
GFGFHHF-12 unknown thing bizar brick mortar  tbc
45fjk  do not know   + is less   biac
   disk  seagate   250GB 130
5G_gff   tbd   tbd
gjgh88hgg  media record  a and b 12
hjjfoo   bar   hop   zip
hg uy oi   hj uuu ii a   qqq ccc v ZZZ Ughj
qdsd   zertnope  nope""".split('\n')

# find rightmost space characters delimiting text columns
spaceCols = set(range(max(map(len, data - \
set( [col for line in data
  for col,c in enumerate(line.expandtabs())
  if not c.isspace() ] )
spaceCols -= set( [c for c in spaceCols if c+1 in spaceCols ] )

# convert to sorted list of leading col characters
spaceCols = map(lambda x:x+1, sorted(list(spaceCols)))

# get and pretty-print data fields
dataFields = \
[ [line.expandtabs()[start:stop] for (start,stop) in
zip([0]+spaceCols,spaceCols+[None])] for line in data ]
import pprint
pprint.pprint( dataFields )

Gives:

[['44544  ', 'ipod  ', 'apple ', 'black ', '102'],
 ['GFGFHHF-12 ', 'unknown thing ', 'bizar ', 'brick mortar  ', 'tbc'],
 ['45fjk  ', 'do not know   ', '+ is less ', '  ', 'biac'],
 ['   ', 'disk  ', 'seagate   ', '250GB ', '130'],
 ['5G_gff ', '  ', 'tbd   ', 'tbd', ''],
 ['gjgh88hgg  ', 'media record  ', 'a and b   ', '  ', '12'],
 ['hjj', 'foo   ', 'bar   ', 'hop   ', 'zip'],
 ['hg uy oi   ', 'hj uuu ii a   ', 'qqq ccc v ', 'ZZZ Ughj', ''],
 ['qdsd   ', 'zert  ', '  ', 'nope  ', 'nope']]


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


Re: Gadfly server startup error

2006-09-13 Thread Steve Holden
Ralf Muschall wrote:
> Steve Holden wrote:
> 
> 
>>You're already doing better than I am. On Cygwin 2.5rc2 and Windows 
>>2.4.2 I can't even get it to runs its tests properly:
> 
> 
> I don't remember whether I looked into that at all.
> 
> 
> 
>>NameError: global name 'Server' is not defined
> 
> 
> 
> 
>>Time to report a bug, methinks? Makes SQLite look good  ...
> 
> 
> Carl Waldbieser reported this bug (and a few others, including
> fixes) in April 04 (entry 94049[35]).  It seems the project
> fell asleep four years ago (but in "News" on SF is a more recent
> message from the author pointing to xsdb).
> 
Yes, the whole Gadfly SF web seems to be a bit of a mess.

That news page talks about a "new release", but nothing has actually 
been released, so I presume that code is in SVN now. Frankly I'm not 
encouraged to use it, though it's a pity: I discussed Gadfly somewhat in 
"Python Web Programming", and it would have been nice to see it survive.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: eval(repr(object)) hardly ever works

2006-09-13 Thread Steve Holden
Matthew Wilson wrote:
> I understand that idea of an object's __repr__ method is to return a
> string representation that can then be eval()'d back to life, but it
> seems to me that it doesn't always work. 
> 
> For example it doesn't work for instances of the object class:
> 
> In [478]: eval(repr(object()))
> 
>File "", line 1
>  
>  ^
> SyntaxError: invalid syntax
> 
> It seems to work for types like integers and dictionaries and lists,
> but not for much else.
> 
That's intentional. Would you have it return the code of all the methods 
when you take the repr() of a class?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: How to get the "longest possible" match with Python's RE module?

2006-09-13 Thread Frederic Rentsch
[EMAIL PROTECTED] wrote:
> Frederic Rentsch wrote:
>
>
>   
>>If you need regexes, why not just reverse-sort your expressions? This
>> seems a lot easier and faster than writing another regex compiler.
>> Reverse-sorting places the longer ones ahead of the shorter ones.
>> 
>
> Unfortunately, not all regular expressions have a fixed match length.
> Which is the longest of, for example, /(abc)?def/ and /(def)?ghi/
> depends on the input. 
>
> Lorenzo Gatti
>
>   
Very true! Funny you should remind me, considering that I spent quite 
some time upgrading SE to allow regular expressions. Version 1 didn't 
and could resolve precedence at compile time. Version 2 resolves 
precedence at runtime by length of the matches and should function 
correctly in this respect, although it might not function fast enough 
for speed-critical applications. But then there is in general a 
trade-off between convenience and speed.


Frederic

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


Re: RELEASED Python 2.5 (release candidate 2)

2006-09-13 Thread Ant

Anthony Baxter wrote:
...
> code in 2.5 before the final release. *Please* try this
> release out and let us know about any problems you find.

Not a problem with the release, but with the docs. I've just ported a
module using the ElementTree package to 2.5, and the Module Index
(http://docs.python.org/dev/modindex.html) lists the package as
elementtree, where it should be xml.etree.

Not a major problem, but threw me for a while, since the only reference
to the actual name of the module is in the title of
http://docs.python.org/dev/lib/module-elementtree.html (8.13
elementtree -- The xml.etree.ElementTree Module).

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


Re: How to get the "longest possible" match with Python's RE module?

2006-09-13 Thread Frederic Rentsch
[EMAIL PROTECTED] wrote:
> Frederic Rentsch wrote:
>
>
>   
>>If you need regexes, why not just reverse-sort your expressions? This
>> seems a lot easier and faster than writing another regex compiler.
>> Reverse-sorting places the longer ones ahead of the shorter ones.
>> 
>
> Unfortunately, not all regular expressions have a fixed match length.
> Which is the longest of, for example, /(abc)?def/ and /(def)?ghi/
> depends on the input. 
>
> Lorenzo Gatti
>
>   
Oh yes, and my proposal to reverse-sort the targets was in response to 
the OP who wanted to generate a regex from a bunch of strings. It should 
work for that.


Frederic

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


Unit balancing

2006-09-13 Thread AbrahamLincolnIllinois
Greetings!

I am working with a researcher who would be very happy if he could
include units in his calculations.  Then, if his complicated expression
didn't result in "kg/yr" the program would stop and point out his
error.

Does Python (or SciPy or ..) offer this feature?

Thanks for your help.  


   Abraham

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


python threading

2006-09-13 Thread daniel
can someone give me a good threading tutorial
thx

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


Re: Are Python's reserved words reserved in places they dont need to be?

2006-09-13 Thread John Roth

metaperl wrote:
> -->  python -i
> >>> class = "algebra"
>   File "", line 1
> class = "algebra"
>   ^
> SyntaxError: invalid syntax
> >>>
>
>
> Why isn' t the parser smart enough to see that class followed by an
> identifier is used for class definition but class followed by equals is
> a simple assignment?
>
> Also, I had a bug where I tried to set the attributes "user" and "pass"
> in an object but "pass" would not work because it is a reserved word.
> Again pass should be reserved in certain contexts but not others.
>
> Is Python 3k going to fix this sort of thing?

I can give you a categorical NO to that one. Unless
Guido changes his mind, and it's very unlikely, the
answer is in PEP 3099: "Things that will not change
in Python 3000". It says: "The parser won't be more
complex than LL(1)." He does not want to start down
the slippery slope that leads to certain unnamed
languages such as Perl.

John Roth

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


Re: eval(repr(object)) hardly ever works

2006-09-13 Thread Matthew Wilson
On Wed 13 Sep 2006 10:38:03 AM EDT, Steve Holden wrote:
> That's intentional. Would you have it return the code of all the methods 
> when you take the repr() of a class?

I don't think that would be required.  Couldn't you return a string with
a call to the constructor inside?  That's what sets.Set seems to do:

In [510]: from sets import Set

In [511]: s = Set()

In [512]: s.add('baloney')

In [513]: repr(s)
Out[513]: "Set(['baloney'])"

In [514]: eval(repr(s))
Out[514]: Set(['baloney'])

> regards
>   Steve

PS: I read your python web programming book a few years ago.



-- 
A better way of running series of SAS programs:
http://overlook.homelinux.net/wilsonwiki/SasAndMakefiles
-- 
http://mail.python.org/mailman/listinfo/python-list


pickle and instancemethod objects

2006-09-13 Thread Steven Bethard
I'd like to be able to pickle instancemethod objects mainly because I 
want to be able to delay a call like ``foo(spam, badger)`` by dumping 
``foo``, ``spam`` and ``badger`` to disk and loading them again later. 
Sometimes the callable ``foo`` is actually a bound method, e.g. 
``bar.baz``, but in such cases, pickle doesn't work by default because 
it doesn't know how to pickle/unpickle instancemethod objects.

I was thinking of doing something like::

 >>> def pickle_instancemethod(method):
... func_name = method.im_func.__name__
... cls = method.im_class
... obj = method.im_self
... return unpickle_instancemethod, (func_name, cls, obj)
...
 >>> def unpickle_instancemethod(func_name, cls, obj):
... if obj is None:
... return getattr(cls, func_name)
... else:
... return getattr(obj, func_name)
...
 >>> class C(object):
... def __init__(self, foo, bar):
... self.foo = foo
... self.bar = bar
... def baz(self):
... return self.foo, self.bar
...
 >>> copy_reg.pickle(type(C.baz),
... pickle_instancemethod,
... unpickle_instancemethod)

This seems to basically do the right thing on the few simple things I've 
tried::

 >>> c = C(42, 'badger')
 >>> new_c_baz = pickle.loads(pickle.dumps(c.baz))
 >>> new_c_baz()
(42, 'badger')
 >>> new_C_baz = pickle.loads(pickle.dumps(C.baz))
 >>> new_C_baz(C('eki', 'fekang'))
('eki', 'fekang')

Does this approach seem sound?  Am I going to run into some weird 
problems doing it this way?

Thanks,

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


Windows bandwidth monitor

2006-09-13 Thread RunLevelZero
Hey guys, I've done some searching but can't seem to find anything that
helps me out. I want to write a simple bandwidth monitor that will sit
in the taskbar of windows and tell me my upload and download speeds. I
intend to use wxpython for the little taskbar icon. If anyone can give
me a helping hand I would be more than appreciative.

Thanks

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


Re: Unit balancing

2006-09-13 Thread Tim Chase
> I am working with a researcher who would be very happy if he
> could include units in his calculations.  Then, if his
> complicated expression didn't result in "kg/yr" the program
> would stop and point out his error.
> 
> Does Python (or SciPy or ..) offer this feature?


Well, it's a bit of a hack, but you could try something like

###
class InvalidUnits(Exception): pass

class Unit(object):
def __init__(self, value, units = ''):
self.value = value
self.units = units
def __sub__(self, other):
if isinstance(other, Unit):
if self.units <> other.units:
raise InvalidUnits
return Unit(self.value - other.value, self.units)
return Unit(self.value - other, self.units)
def __add__(self, other):
if isinstance(other, Unit):
if self.units <> other.units:
raise InvalidUnits
return Unit(self.value + other.value, self.units)
return Unit(self.value + other, self.units)
def __mul__(self, other):
if isinstance(other, Unit):
return Unit(self.value * other.value,
"(%s)%s" % (self.units, other.units))
else:
return Unit(self.value * other, self.units)
def __div__(self, other):
if isinstance(other, Unit):
return Unit(self.value / other.value,
"%s/%s" % (self.units, other.units))
else:
return Unit(self.value / other, self.units)
def __radd__(self, other): return self.__add__(other)
def __rsub__(self, other): return self.__sub__(other)
def __rmul__(self, other): return self.__mul__(other)
def __rdiv__(self, other): return self.__div__(other)
def __repr__(self):
return '%i %s' % (self.value, self.units)
def __str__(self): return repr(self)


which allows you to do things like

distance = Unit(80, 'm')
print "Distance: %s" % distance
time = Unit(2, 'h')
print "Time: %s" % time
speed = distance/time
print "Speed: %s" % speed
speed = 3 * speed
print "Speed: %s" % speed
print "Error:",
# can't add dissimilar units
print distance + time



I'm sure there are loads of other edge cases one would want to 
consider, such as analyzing and trimming redundant units, but 
that should give a pretaste of what could be done.

-tkc



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


Re: eval(repr(object)) hardly ever works

2006-09-13 Thread Fredrik Lundh
Matthew Wilson wrote:

> I understand that idea of an object's __repr__ method is to return a
> string representation that can then be eval()'d back to life, but it
> seems to me that it doesn't always work. 

when in doubt, read the language reference:

 "If at all possible, this should look like a valid Python
 expression that could be used to recreate an object with
 the same value (given an appropriate environment). If this
 is not possible, a string of the form "<...some useful
 description...>" should be returned.

 http://pyref.infogami.com/__repr__



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


Re: Python blogging software

2006-09-13 Thread Fuzzyman

Cliff Wells wrote:
> On Wed, 2006-09-13 at 00:29 -0700, Cliff Wells wrote:
>
> > Anyone aware of any functional (doesn't need to be complete, beta is
> > fine) blog software written in Python?
>
> Hmph.  And as soon as I hit send I find
>
>  http://wiki.python.org/moin/PythonBlogSoftware
>
> Okay, so is there any *not* on that list that should be considered (and
> perhaps added to the list)?

Firedrop2 is a client-side blog program (generates static HTML to be
uploaded to your webserver).

The link on that page is out of date. It is now :

http://www.voidspace.org.uk/python/firedrop2/

You can see a feed of some blogs created with Firedrop2 at :

   http://www.voidspace.org.uk/planetfiredrop/

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml


> 
> Regards,
> Cliff
> 
> --

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


Re: Unit balancing

2006-09-13 Thread Jean-Paul Calderone
On 13 Sep 2006 07:47:41 -0700, [EMAIL PROTECTED] wrote:
>Greetings!
>
>I am working with a researcher who would be very happy if he could
>include units in his calculations.  Then, if his complicated expression
>didn't result in "kg/yr" the program would stop and point out his
>error.
>
>Does Python (or SciPy or ..) offer this feature?
>
>Thanks for your help.
>
>
>   Abraham
>

You might be interested in Unum.

http://home.tiscali.be/be052320/Unum.html

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


Re: Unit balancing

2006-09-13 Thread Simon Brunning
On 13 Sep 2006 07:47:41 -0700, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> I am working with a researcher who would be very happy if he could
> include units in his calculations.  Then, if his complicated expression
> didn't result in "kg/yr" the program would stop and point out his
> error.

This what you were looking for?



-- 
Cheers,
Simon B,
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows bandwidth monitor

2006-09-13 Thread Tor Erik
RunLevelZero wrote:
> Hey guys, I've done some searching but can't seem to find anything that
> helps me out. I want to write a simple bandwidth monitor that will sit
> in the taskbar of windows and tell me my upload and download speeds. I
> intend to use wxpython for the little taskbar icon. If anyone can give
> me a helping hand I would be more than appreciative.
> 
> Thanks
> 

For the monitoring part, google "win32pdh"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unit balancing

2006-09-13 Thread Claudio Grondi
[EMAIL PROTECTED] wrote:
> Greetings!
> 
> I am working with a researcher who would be very happy if he could
> include units in his calculations.  Then, if his complicated expression
> didn't result in "kg/yr" the program would stop and point out his
> error.
> 
> Does Python (or SciPy or ..) offer this feature?
> 
> Thanks for your help.  
> 
> 
>Abraham
> 
I mean I run one time already into a Python library or a class which was 
designed to handle such things as this request is common to many 
researcher.
Sorry, don't have any link at my fingertips or even an idea where to 
look after it, so Googling or waiting until someone else using such a 
tool posts here is all I can offer.

Inbetween Frink is maybe an option?
   http://futureboy.homeip.net/frinkdocs/

Claudio Grondi


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


Re: Newbie - ? get IDLE going on cygwin

2006-09-13 Thread David J. Braden
Jason Tishler wrote:
> Dave,
> 
> On Wed, Sep 13, 2006 at 09:42:48AM +, David J. Braden wrote:
>> Thorsten Kampe wrote:
>>> * David J. Braden (2006-09-12 18:35 +0100)
 I can run Python in command-line mode fine from the cygwin shell;
 the cygwin distribution also includes IDLE, which is apparently
 completely installed, yet I am unable to get IDLE running. When I
 double-click idle.bat (or idle.pyw) I am prompted to locate the
 program's creator.  Darn if I know what it is. If I try to invoke
 IDLE from cygwen bash, I get "unable to remap
 c:\cygwin\bin\tk84.dll to same address as parent".
>>> rebaseall
>>>  
>> [snip]
>>
>> Thanks, Thorsten. I assume you mean type in "idle rebaseall" (?) -
>> seems to bring up a window for a split second, then come back with
>> same error messages I had before. I cannot find in the IDLE doc any
>> reference on how to get it going under cygwin; could you please point
>> me towards a less-than-terse set of instructions?
> 
> Here's another terse response:
> 
> 
> http://www.google.com/search?hl=en&q=unable+remap+same+address+parent&btnG=Google+Search
> 
> :,)
> 
> The following are excerpts from the rebase README:
> 
> The rebaseall utility is a convenient way for users that suffer from
> the Cygwin rebase problem to rebase their entire system (i.e., all
> of their DLLs).  The following is a list of known Cygwin
> applications that are affected by the rebase problem:
> 
> Apache
> Perl
> Python
> 
> The rebase problem is due to fork() failing when it is unable to
> load DLLs in the child at the same address as in the parent.  This
> is caused by DLLs which have conflicting base addresses.  An error
> message like the following will be displayed when the problem is
> triggered:
> 
> C:\cygwin\bin\python.exe: *** unable to remap C:\cygwin\bin\cygssl.dll
> to same address as parent(0xDF) != 0xE0
> 
> Use the following procedure to rebase your entire system:
> 
> 1. shutdown all Cygwin processes and services
> 2. start ash (do not use bash or rxvt)
> 3. execute /bin/rebaseall (in the ash window)
> 
> BTW, idle has problems running under Cygwin Python:
> 
> http://sf.net/tracker/?func=detail&atid=105470&aid=786827&group_id=5470
> 
> Jason
> 

Thanks, Jason. Your first cite cracked me up. I can now confirm that, 
yes, IDLE pops up w/o menus under cygwin. Sheesh. Onward...

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


Re: How to write UNIX daemons in Python?

2006-09-13 Thread Martin v. Löwis
[EMAIL PROTECTED] schrieb:
> What should I use to do something like that? Do I have to use
> distutils? Do I have to use third party packages? Do I have to write a
> "setup.py" and solve the problem manually?
> This last solution is problematic becouse, for (dumb) example, Debian
> wants executable/programs to be located in /usr/bin while Fedora uses
> another path (for example /usr/sbin).
> 
> Another question: what about .deb, .rpm, [...] packages?
> Does it possible to use them with Python programs?
> Resolving third party dependancies by using them could be a nice thing.

I would create packages, and therefore restrict attention to the
systems that are to be supported.

For RPM, there is a distutils bdist_rpm command which can help in
generating the RPM. OTOH, it might be actually easier to write a .spec
file and build the RPM "manually".

For .deb, there is also a bdist_deb distutils command (although not
part of the standard Python distribution), again, it is likely easier
to use the standard Debian packaging tool chain (i.e. with an
explicit debian/ subdirectory, initially populated with dh_make).

In either case, it is probably a good idea to look at source packages
to get started quickly.

FWIW, Debian does *not* put daemon programs in /usr/bin. Debian
follows the FHS, which specifies that system binaries go into
/usr/sbin. /usr/bin is limited to user programs.

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


Re: [Twisted-Python] twisted.web2 and blank values in POST

2006-09-13 Thread Jean-Paul Calderone
On Wed, 13 Sep 2006 17:28:04 +0200, Sylvain Thénault <[EMAIL PROTECTED]> wrote:
>Hi there,
>
>I've found a strange behaviour in twisted web2'server : the behaviour with 
>blank values
>in form parameters is not consistent between GET and POST: on GET blank values 
>are kept while
>this is not the case on POST. I'ld have expected blank values to be kept on 
>POST as well. Is this
>a bug or an expected behavour ?
>
>
>PS: if this is a bug, an easy fix is to add keep_blank_values=True to the
>fileupload.parse_urlencoded call in server.py line 91.

Hi.  You might want to post this to the twisted-web mailing list, instead.

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

Re: auto upgrade scripts?

2006-09-13 Thread stefaan . himpe
> Since you mention .NET and didn't state otherwise, I'm assuming
> Windows platform?

No, I need both linux and windows. I guess this means
I'll have to make something myself ...

Thanks, and best regards,
Stefaan.

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


Re: [Twisted-Python] twisted.web2 and blank values in POST

2006-09-13 Thread Jean-Paul Calderone
Ugg, wrong list obviously.  Please disregard.  Sorry.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: os.name under Win32

2006-09-13 Thread Martin v. Löwis
Igor Kravtchenko schrieb:
> Recently, someone advised me to use instead:
> platform.system()
> 
> that returns only 3 different strings: Java, Linux or Windows.  End of
> story.

That's not true:

ActivePython 2.4.1 Build 247 (ActiveState Corp.) based on
Python 2.4.1 (#1, Jun 20 2005, 17:18:51) [C] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.system()
'SunOS'

In any case, the platform module is a more recent addition to Python;
so code using it may not work on older installations (unless you
ship the platform module with your application).

> Is this not supposed to work better than sys.platform?
> Indeed I'm pretty worried about having "win64" returned on further os
> like Windows Vista and having our tests failing again.

It won't. On Win64, sys.platform is still win32.

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


Re: How to build extensions on Windows?

2006-09-13 Thread Kevin D.Smith
On 2006-09-07 13:20:13 -0400, "Jason" <[EMAIL PROTECTED]> said:
> I don't know about MinGW, but you can get the Microsoft compilers by
> installing Visual C++ 2005 Express.  I'm guessing the old toolkit is
> deprecated.  While you must register each Visual Studio Express module
> that you download, I don't think the actual command-line tools are
> encumbered.
> 
> Why not try it out and let us know how it goes?
> 
> (Visual Studio 2005 Express:
> http://msdn.microsoft.com/vstudio/express/)

This almost worked (at least, it appears to).  I got the module to 
build and install using VS 2005.  It works fine if I run python from 
the directory where I built the extension.  However, if you go to any 
other directory, run python, and try to import the module, I get the 
following error:

ImportError: dynamic module does not define init function (initsasSQL)

Why would it work from one directory, but not another?

-- 
Kevin D. Smith

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


Re: Scientific computing and data visualization.

2006-09-13 Thread Claudio Grondi
Paul F. Kunz wrote:
> "Fie Pye" <[EMAIL PROTECTED]> writes:
> 
> 
>>Hallo
>>  
>>  I would like to have a high class open source tools for scientific 
>> computing and powerful 2D and 3D data visualisation. Therefore I chose 
>> python, numpy and scipy as a base. Now I am in search for a visualisation 
>> tool. I tried matplotlib and py_opendx with OpenDx. OpenDx seems to me very 
>> good but the project py_opendx looks like closed. After py_opendx 
>> instalation and subsequent testing I got an error that needs discussion with 
>> author or an experienced user. Unfortunately a mail to author returned as 
>> undeliverable.
>>  
>>  Does anybody now about suitable visualisation tool?
>>  
> 
> Have you looked at HippoDraw?
> 
> http://www.slac.stanford.edu/grk/ek/hippodraw
   http://www.slac.stanford.edu/grp/ek/hippodraw/

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


Is there a way to find IP address?

2006-09-13 Thread Lad
Normaly I can log user's IP address using os.environ["REMOTE_ADDR"] .
If a user  is behind a proxy, I will log  proxy's IP address only.
Is there a way how to find a real IP user's address?
Thank you for help.
LL.

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


Re: How to build extensions on Windows?

2006-09-13 Thread Fredrik Lundh
Kevin D.Smith wrote:

> This almost worked (at least, it appears to).  I got the module to 
> build and install using VS 2005.  It works fine if I run python from 
> the directory where I built the extension.  However, if you go to any 
> other directory, run python, and try to import the module, I get the 
> following error:
> 
> ImportError: dynamic module does not define init function (initsasSQL)
> 
> Why would it work from one directory, but not another?

do you perhaps have a different "sassql.dll" file in your Python path?

(Python's standard import mechanism looks for PYD, DLL, PY, PYW, and 
PYC, in that order.)



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


  1   2   3   >