Inheritance and recursion problem

2006-11-25 Thread Spiro
Hi all,
i'm trying to make some user interface objects in python.

I have classes XWindow and XMainWindow(XWindow) (XMainWindow inherited 
from XWindow)

XWindow have all drawing functionality and Windows[] object which holds 
all child windows.
Function Draw looks like this:
def Draw(self):
self.Back.blit
for wnd in self.Windows:
wnd.Draw(OffsetX, OffsetY)

Now in main module i make objects:
RootWindow=XWindow()
MW=XMainWindow()
RootWindow.Widnows.append(MW)

Now the problem:
When i call RootWindow.Draw() he calls wnd.Draw where wnd is XMainWindow 
from RootWindow's Windows[] collection.
Now, we are in MW's Draw and MW's Windows[] collection should be empty 
but somehow he has itself (well, new instance of XMainWindow) in this 
collection and i got unlimited reference.

...
While writing this post i tried something:
instead of using RootWindow.Windows.append(MW)
i used RootWindow.Windows=[MW] and now it's OK.

I'm happy now, my code works, but i don't know what was happening there: 
why append made new instance of object instead of passing existing object.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Python Papers Edition One

2006-11-25 Thread Fredrik Lundh
Tennessee Leeuwenburg wrote:

> If anyone has any good ideas for how to cope as a publisher with these
> difficulties, I'm all ears.

has any of the format zealots posting to this thread actually 
volunteered to produce any material for your publication?  if not, I 
suggest ignoring them.  any bozo with a keyboard can contribute stop 
energy to a project, but at the end, it's always the people *doing* 
things that matters.



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


Re: Ruby/Python/REXX as a MUCK scripting language

2006-11-25 Thread Stephan Kuhagen
Tony Belding wrote:

> Is this practical?  I'm thinking of Ruby or Python for this, if they
> can meet the requirements.

Python had a sandbox module, but is was discarded because of security
problems.

If you want it working on MacOS, you may also have a look at Tcl, which has
a long tradition on MacOS and it comes with a very good implemented and
fully customizable sandbox. For a starting point, if Tcl sandbox meets your
requirements, have a look here:

Safe Tcl Overview: http://www.tcl.tk/software/plugin/safetcl.html
Docs about the specific Tcl commands, to create safe interpreters:
http://www.tcl.tk/man/tcl8.4/TclCmd/interp.htm (See in the lower third of
the page at "Safe Interpreters")
http://www.tcl.tk/man/tcl8.4/TclCmd/safe.htm

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


Re: Inheritance and recursion problem

2006-11-25 Thread Fredrik Lundh
Spiro wrote:

> XWindow have all drawing functionality and Windows[] object which holds 
> all child windows.
 >
> Function Draw looks like this:
> def Draw(self):
>   self.Back.blit
>   for wnd in self.Windows:
>   wnd.Draw(OffsetX, OffsetY)
> 
> Now in main module i make objects:
> RootWindow=XWindow()
> MW=XMainWindow()
> RootWindow.Widnows.append(MW)

just a guess: you've written

 class XWindow:
 Windows = [] # class attribute, shared by all instances

instead of

 class XWindow:
 def __init__(self, ...):
 self.Windows = [] # create new instance attribute



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


Re: reading id3 tags with python

2006-11-25 Thread Rabin Vincent
On 24 Nov 2006 08:42:02 -0800, jeff <[EMAIL PROTECTED]> wrote:
>   File "/home/jeffrey/Documents/Music/.rename/id3reader.py", line 341,
> in _interpretFlags
> self._readExtHeader = _readExtHeader_rev3
> NameError: global name '_readExtHeader_rev3' is not defined

Add a "self." in front of _readExtHeader_rev3 on line 341 of id3reader.py,
and also in front of _readExtHeader_rev4 on line 343 and it should
probably work.

   self._readExtHeader = self._readExtHeader_rev3

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


Re: The Python Papers Edition One

2006-11-25 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> Your email indicates a possible concern that we are doing something
> untoward -- this was not at all intended, nor is it true.

Although you might not have intended it, I feel it is still true.  You
are misappropriating terminology ("free as in freedom") from the free
software movement that means a work is licensed in a way that meets
some specific criteria, that the license you're using does not meet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Python Papers Edition One

2006-11-25 Thread Paul Rubin
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> I thought I just had. In what way does the statement "Yes, it's true
> that you can't resell copies of The Python Papers for personal profits,
> but you may derive from it, reproduce and propagate it" not provide
> such a revision and clarification? Seriously, let me know what exact
> statement you feel needs to be made, and I will endorse it accordingly
> if it is accurate.

You should not use the phrase "free as in freedom".  "Free as in beer"
is more accurate for the NC licenses.  

> For my part, I don't see that there are ethically serious restrictions
> on the freedom of use of the information contained within The Python
> Papers.

There is a big rant against the CC-NC licenses on Kuro5hin:

http://www.kuro5hin.org/story/2005/9/11/16331/0655

> Call it "mostly free" if you like. 

That is reasonable and if you're going to stick with the NC license,
it would be cool if you also were to descibe TPP as "mostly free", or
maybe "gratis" (as opposed to "libre") in your descriptions.  "Gratis"
is sometimes translated "free as in beer", in contrast with "free
as in speech" or "free as in freedom".

> There's no such thing as complete
> freedom of information anyway, and we have done the best we can.

Well, others including the Wikimedia projects (which use GFDL) and the
PLoS journals (www.plos.org) (which use CC-BY) go further than you do,
so "we have done the best we can" sounds like an apology that "the
best you can" wasn't up to the level that those other, much more
significant projects have managed to do.  Should you expect a response
other than "oh well, nice try"?

One of my desires as a free software user, for example, is to be able
to buy a new computer with a complete suite of software preinstalled
on the hard disk, including all the needed apps, development tools,
and documentation and source code for everything, and the freedom to
propagate it all in the same way.  All the GNU/Linux stuff and all the
Python.org stuff, plus more general reference works like Wikipedia,
educational materials like Wikibooks, and scientific journals like
PLOS, are licensed in ways that would permit including it with such a
computer.  It even includes some entertainment media like various
music downloads from Jamendo and the non-NC CC movies.  But your
journal would have to be omitted.

> We considered releasing under the GPL, but felt that we wanted to
> preserve two things which don't seem to be provided by it:
>   * Rights of the author to attribution as may be expected and desired
> of an academic publication. The GPL doesn't seem appropriate for
> disseminating the work of a single author.
>   * Rights of the author to have their words presented

I would have suggested the GNU Free Documentation License (GFDL) that
Wikipedia uses, but that's just me.

>   * Opportunity for the author to commercially license their works to
> other vendors. By choosing the Share Alike restriction, we have
> encouraged the free dissemination of research information without
> affecting its commercial use. 

Right, the effect on commercial use comes from the NC restriction,
not the SA restriction.

>   * Rights of the author to have their words presented

I'm not sure what you're getting at but if you mean no modified
versions, you need -ND for that.  

> It seemed to be the best middle ground between taking a strong
> ideological position on either side that would be bound to put
> people off side. It preserves some rights for the author while still
> allowing a substantial amount of free re-use.  

"Middle grounds" often combine the disadvantages of both "endpoints".
And failing to take a strong position can leave you in a weak one.

> * Reputation as an
> unbiased, financially disinterested group. 

The NC licenses withhold some rights for exclusive use by the initial
publisher, releasing only a subset to users.  That is usually not a
sign of disinterest.  For example, Cory Doctorow's novels are
published under NC licenses, which he says is working for him as a
marketing tool.  But he has a clear and undisguised financial interest
in choosing the NC license.

> By distributing under the
> license we chose, we hoped to establish our credentials.

Well, it seems to me that you're putting out yet another non-libre
publication, it's nice that it's gratis but I don't think it helps
establish credentials with FOSS users and the confusion so far may
actually be hurting.

> Your email indicates a possible concern that we are doing something
> untoward -- this was not at all intended, nor is it true.

As mentioned in another post, I feel that you're (perhaps
unintentionally) trying to attach to your publication the good
associations created by the licensing practices of the FOSS movement,
while not actually following those practices.  "Untoward" might be a
slightly overstrong term, however, you are creating confusion and
maybe suffering from it yourself.  

Here is the issue: people who write 

Re: Ruby/Python/REXX as a MUCK scripting language

2006-11-25 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Dennis Lee Bieber  <[EMAIL PROTECTED]> wrote:
>On Fri, 24 Nov 2006 18:11:21 -0600, Tony Belding <[EMAIL PROTECTED]>
>declaimed the following in comp.lang.python:
>
>> the security issue that really worries me. . .  I have to be able to 
>> limit what the interpreter can execute.  I can't have my users running 
>
>   That is going to be the killer... Python no-longer ships with a
>"secure sandbox" module, because there were always ways to work around
>it.
.
.
.
Tcl's the one language in this area that has gone the farthest
with its "safe interpreter" http://wiki.tcl.tk/4204 >,
and Tcl is well-supported under Mac OS.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Invoking Python from Cygwin problem.

2006-11-25 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Ant wrote:

> --
> #!/usr/bin/python
> print "Testing",
> 
> Running the bash script, I get the following output:
> 
> OKt var: Testing
> Test var2: Test2 OK
> 
> Does anyone have any idea why the script would mess up the first echo?
> Are there some kind of control characters being appended to the python
> output in Windows? Looks like a CR character, but why?

It's a feature.  The `sys.stdout` object remembers if the last ``print``
ended in a comma (see the `sys.stdout.softspace` attribute) and when the
interpreter executes its shutdown code and that `softspace` attribute is
set, an extra '\n' is printed.

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


Try to stop thread Using flag

2006-11-25 Thread many_years_after
Hi,pythoners:

I countered some problems when I try to stop threads using flag.
These are my some important codes:

#  mythread.py
def run(self):
while self.addr != '':### text waiting for processing
if not self.CONTINUE:   ### flag for thread ,means to exit
the RUN func or not
break
print self.name
post(self.params, self.addr)  ### func to process the text
self.addr = furl.readline().strip()


##  myapp.py
 def OnEndProcess(self, event):
   if self.threadList:
for thread in self.threadList:
thread.CONTINUE = False
#   this func is an EVENT processor. When I press the END BUTTON ,
it will be caused.

def OnBeginProcess(self, event):
for i in range(num):
if lines[i]!= '':
thread =
mythread.mythread('Thread'+str(i),lines[i], params)
self.threadList.append(thread)

print '\n Starting Threads'

for i in self.threadList:
i.start()


##  this func is an EVENT processor. When I press the BEGIN BUTTON
, it will be caused.

By test I found this truely acts as supposed:thread exited the *run()*
func. But when I press the BEGIN BUTTON again, an Error was caused:
thread already started.
It's said that if the *run()* func is finished, the thread will become
dead. So how to interprete this?
Any solution?

Thanks.

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

Re: Try to stop thread Using flag

2006-11-25 Thread MC

http://candygram.sourceforge.net/

-- 
@-salutations

Michel Claveau


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


Capture file descriptors while running an external program

2006-11-25 Thread jfigueiras
>I have a problem with the module subprocess!
>The problem is that the external software that I am running under
>subprocess.Popen opens stdin, stdout, stderr, and other file descriptors to
>write and read in the hard drive.

As many other programs...

>I know how to capture stdin, stdout and stderr, what I cannot do is to capture
>the other file-descriptors. Is there any way to wrap those non-standard file
>descriptors and make them write and read from a specific object that I define?
>I know that I can use tmp files to do that, but i would like something running
>without tmp files.

I'm not sure what you mean by "non-standard file descriptors". The
other program is free to open, read, write, etc any file he wants -
are you trying to trap any file operation it may want to do?
You *could* do such things -google for "code injection" and "API
hooking"- but I doubt it's what you really want.

--
Gabriel Genellina
Softlab SRL

Hi Gabriel!

When I wrote "non-standard file descriptors", I meant the file descriptior which
are pointed to files in the hardrive.
What I would like to do is not to trap any file operation, but instead intercept
that file operation, i.e. I would like the output of the external program to
don't be writen in a file (its normal behavior), but instead be sent to any
variable in my program.
I know the name of the file where the external program will write the output. I
pass its name along the command line.

Joao Figueiras

___

O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt

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


Re: Invoking Python from Cygwin problem.

2006-11-25 Thread Ant

Marc 'BlackJack' Rintsch wrote:
...
> It's a feature.  The `sys.stdout` object remembers if the last ``print``
> ended in a comma (see the `sys.stdout.softspace` attribute) and when the
> interpreter executes its shutdown code and that `softspace` attribute is
> set, an extra '\n' is printed.

So the workaround is to directly write to sys.stdout I guess. Or set
sys.stdout.softspace to 0?

Cheers.

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


Graph Data Structures

2006-11-25 Thread Nathan Harmston
Hi All,

Currently I am working on a generic graph library  so I can do various
graph based analysis for various projects I have ideas for. Currently
I am implementing Graph as a wrapper around a dictionary. Currently my
implementation works like this:

t = Graph()
n1 = Node("Node1")
n2 = Node("Test2")
edge1 = Edge("Test3")
t += n1{ n1:{}}
t[n1][n2] = edge1{ n1:{n2:edge1}

However this isnt actually ending up with the structure I want. I want
it to finally end up as ..{ n1:{n2:edge1}, n2:{}}. Is
there anyway I can do this simply

Also I am looking at having a large graph and was wondering if anyone
knew of anyway I could reduce the memory requirements of this
structure and improve the speed of queries on it. I m thinking writing
a C extension for itis this a good idea and where would I start?
Or does Python have some kind of transparent memory access module I
can implement.

Many Thanks in advance,

Nathan

PS.Please find my code below:

class Graph(object):
def __init__(self, g= { } ):
self.graph = g
def __iadd__(self, p):
if p not in self.graph:
self.graph[p] = PathsDict()
return self
def __getitem__(self, p):
try:
return self.graph[p]
except KeyError:
raise KeyError( "%s not in graph" %(repr(p)) )
def __str__(self):
return str(self.graph)
def filter(self, filter):
pass

class PathsDict(object):
def __init__(self):
self.paths = { }
def __setitem__(self, p, val):
if p not in self.paths:
self.paths[p] = val
def __getitem__(self, p):
return self.paths[p]
# catch exception here
def paths(self):
for k, v in self.paths:
yield (k, v)
def edges(self):
return self.paths.values()
def __str__(self):
return str(self.paths)
def __len__(self):
return len(self.paths)

class Node(object):
def __init__(self, name):
self.name = name
def __str__(self):
return self.name

class Edge(dict):
def __init__(self, name, weight = 1):
self["name"] = name
self["weight"] = weight
def __str__(self):
return self["name"]
-- 
http://mail.python.org/mailman/listinfo/python-list


problem with global variable in a module

2006-11-25 Thread hollowspook
def aa():
global b
b=b+1
print b

b=1
aa()

The above code runs well in python shell.

However I  have a problem as follows.

new a file named test.py


def aa():
global b
b=b+1
print b
-

Then in python shell,

from test import *
b=1
aa()

The error message is :
Traceback (most recent call last):
  File "", line 1, in ?
  File "test.py", line 3, in aa
b=b+1
NameError: global name 'b' is not defined

Why this happens? Please do me a favor. 
Thanks in advance

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

Re: The Python Papers Edition One

2006-11-25 Thread Jerry Hill
On 11/25/06, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> And how do you think this is different from any other publication? That
> Python Papers is under a CC licence is a red-herring.

Well, the CC license is viral.  According to the CC explanation of the
Attribution-NonCommercial-ShareAlike license I am free to create a
derivative work, but only if I then release that work under an
identical license.  When I look at the Python Cookbook, it doesn't
seem to encumber derived works the same way.  Instead, the Python
Cookbook page says "Except where otherwise noted, recipes in the
Python Cookbook are published under the Python license."  The Python
license is extraordinarily broad in what I'm allowed to do with it,
including reusing code in a commercial project.

> Again, how is this different from any other publication? Unless you only
> read public domain publications, anything you read is copyrighted, and
> your arguments apply just as much -- perhaps more so -- depending on the
> licence of that publication.

Yes, of course.  Thus, I have to avoid using code out of any
publication with a viral non-commercial license if there's any chance
my code will be sold commercially. For the same reason, I won't take
code from a GPL'd product and reuse it in a commercial project without
getting a commercial license from the copyright holder.

By the way, I wasn't really trying to complain about the Python
Paper's choice of license.  I just wanted to give my perspective on
why the licensing terms make it unsuitable for me.  The copyright
holders are welcome to release their work under any terms they are
comfortable with.

-- 
Jerry

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


Importing module of data dicts and constants

2006-11-25 Thread Nathan Harmston
Hi All,

I ve got a single module which I m using to contain a lot of
dictionaries, constants, general information, which are used by
various other modules. However I can't seem to access them:

in data.py
_SEQTYPE_DNA = 0
_SEQTYPE_RNA = 1
_SEQTYPE_PROT = 2
_seqType = { "DNA":_SEQTYPE_DNA, "RNA":_SEQTYPE_RNA, "PROTEIN":_SEQTYPE_PROT }

but in test.py
from data import *

class Test(object):
def __init__(self, type):
  self.type = _seqType[type]
def test(self):
 return self.type

t = Test("DNA")
print t.test()

File "test.py", line 24, in __init__
self.type = _seqType[type]
NameError: global name '_seqType' is not defined

I think I m doing something incredibly wrong/stupid here
Can anyone help?

Many Thanks

Nathan

PS. I was wondering if the use of a data module to store constants and
dictionaries is good design??? or not?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Python Papers Edition One

2006-11-25 Thread Fuzzyman

Fredrik Lundh wrote:
> Tennessee Leeuwenburg wrote:
>
> > If anyone has any good ideas for how to cope as a publisher with these
> > difficulties, I'm all ears.
>
> has any of the format zealots posting to this thread actually
> volunteered to produce any material for your publication?  if not, I
> suggest ignoring them.  any bozo with a keyboard can contribute stop
> energy to a project, but at the end, it's always the people *doing*
> things that matters.
>

+1

You guys are doing a great job and the CC license is fine for free
works like the Python Journal

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

> 

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


Re: Simple threading

2006-11-25 Thread Grant Edwards
On 2006-11-25, Gabriel Genellina <[EMAIL PROTECTED]> wrote:

>>I'm just getting started on threading and was wondering why the
>>following code does not work (i know globals is bad style - I'll
>>eliminate them eventually).  All I get is a blank cursor flashing.
>
> You've got your example already working. Globals are bad
> style, but worse, threads and globals don't mix very well: you
> need some sort of syncronization for accessing globals 
> (specially for writing them).

That depends on the type of the global and how they're used.
Re-binding a name is always an atomic operation.  Modifying
many mutable objects is atomic.

>>class ImapThread(threading.Thread):
>> def run(self):
>> global g_currenttick
>> if time.time() > (g_datum + (g_secondspertick *
>>g_currenttick)):
>> print "Ticked %s" % g_currenttick
>> g_currenttick=g_currenttick+1
>> print g_currenttick
>
> Having more than one thread, g_currenttick could have been modified 
> *after* you read its value and *before* you write it back, so you 
> lose the count.

Right. Reading an integer object in one statement and writing
it in a subsequent statement is not an atomic opteration unless
protected by some synchronization mechanism.

-- 
Grant Edwards
[EMAIL PROTECTED]

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


Re: The Python Papers Edition One

2006-11-25 Thread Fuzzyman

Maurice LING wrote:
[snip..]
> As Steven mentioned -- anything you can read is copyrighted. The
> difference is whether is the copyright effective or enforceable. What do
> I mean by this? Without copyright, there will not be plagarism. Ask
> yourself this question, can you copy William Shakespeare's MacBeth and
> submit it as a literary work for a Master of Literary Arts degree? I
> believe the candidate will be expelled from university. William
> Shakespeare's MacBeth is still copyrighted work but not "enforceable"
> because it is pre-1900's work and the author had been dead for more than
> 50 years. Similarly, works in public domain are still copyrighted --
> academically, using work in public domain without attribution (giving
> credits in the form of citations) is still plagarism.
>

This is very, very incorrect. :-)

You're mixing your own moral ethics with an incorrect understanding of
what copyright means...

Fuzzyman
http://www.voidspace.org.uk/index2.shtml

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


Re: Importing module of data dicts and constants

2006-11-25 Thread Fuzzyman

Nathan Harmston wrote:
> Hi All,
>
> I ve got a single module which I m using to contain a lot of
> dictionaries, constants, general information, which are used by
> various other modules. However I can't seem to access them:
>
> in data.py
> _SEQTYPE_DNA = 0
> _SEQTYPE_RNA = 1
> _SEQTYPE_PROT = 2
> _seqType = { "DNA":_SEQTYPE_DNA, "RNA":_SEQTYPE_RNA, "PROTEIN":_SEQTYPE_PROT }
>
> but in test.py
> from data import *
>
> class Test(object):
> def __init__(self, type):
>   self.type = _seqType[type]
> def test(self):
>  return self.type
>
> t = Test("DNA")
> print t.test()
>
> File "test.py", line 24, in __init__
> self.type = _seqType[type]
> NameError: global name '_seqType' is not defined
>
> I think I m doing something incredibly wrong/stupid here
> Can anyone help?
>

This looks fine to me. Perhaps when you import from data you are not
getting the module you expect.

How about adding the following lines to your code and seeing if you get
the results you think   you should :

import data
print data.__file__

In general it is better to use the following import form. This way you
can explicitly see where your names are coming from :

from data import _seqType

Storing constants in a data module is fine if you don't expect end
users to edit the file. 'import' executes code, so it can be a security
hole to store configuration data in Python modules.

All the best,

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


> Many Thanks
>
> Nathan
>
> PS. I was wondering if the use of a data module to store constants and
> dictionaries is good design??? or not?

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


Re: Importing module of data dicts and constants

2006-11-25 Thread Fredrik Lundh
Nathan Harmston wrote:

  > I ve got a single module which I m using to contain a lot of
> dictionaries, constants, general information, which are used by
> various other modules. However I can't seem to access them:
> 
> in data.py
> _SEQTYPE_DNA = 0
> _SEQTYPE_RNA = 1
> _SEQTYPE_PROT = 2
> _seqType = { "DNA":_SEQTYPE_DNA, "RNA":_SEQTYPE_RNA, "PROTEIN":_SEQTYPE_PROT }

why do they all start with an underscore?

> but in test.py

> from data import *

as clearly stated in the documentation, "from import *" consider names 
that start with an underscore to be private.

also see:

 http://effbot.org/pyref/reserved-identifier-classes.htm

> I think I m doing something incredibly wrong/stupid here

well, you're only supposed to be using "from import *" if you know
what you're doing, so if you need to ask, you've obviously broken
the rules ;-)



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


Re: Graph Data Structures

2006-11-25 Thread Szabolcs Nagy
i haven't read your code, but there are many graph implementations in
python.
in case you haven't found these yet:
http://wiki.python.org/moin/PythonGraphApi

if you only want to do some analysis i think you need this one (as it's
pretty complete and simple):
https://networkx.lanl.gov/

i also recommend Guido's essay to read:
http://www.python.org/doc/essays/graphs.html

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


Re: Ruby/Python/REXX as a MUCK scripting language

2006-11-25 Thread Fred Bayer

Tony Belding wrote:
> I'm interested in using an off-the-shelf interpreted language as a 
> user-accessible scripting language for a MUCK.  I'm just not sure if I 
> can find one that does everything I need.  The MUCK must be able to call 
> the interpreter and execute scripts with it, but the interpreter must 
> also be able to call functions in the MUCK code.  And then there's the 
> security issue that really worries me. . .  I have to be able to limit 
> what the interpreter can execute.  I can't have my users running scripts 
> that access the console, access the filesystem or sockets directly, or 
> call libraries or other binaries outside the MUCK.
> 
> Is this practical?  I'm thinking of Ruby or Python for this, if they can 
> meet the requirements.
> 

Don't forget Lua: www.lua.org
It fulfills your requirements and is easily embedable.

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


Re: Graph Data Structures

2006-11-25 Thread Steven D'Aprano
On Sat, 25 Nov 2006 14:05:27 +, Nathan Harmston wrote:

> Hi All,
> 
> Currently I am working on a generic graph library  so I can do various
> graph based analysis for various projects I have ideas for. Currently
> I am implementing Graph as a wrapper around a dictionary. Currently my
> implementation works like this:

[snip]

http://www.python.org/doc/essays/graphs.html

http://mail.python.org/pipermail/python-list/2002-April/137593.html


Hope this helps.


-- 
Steven.

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


Re: Ruby/Python/REXX as a MUCK scripting language

2006-11-25 Thread rony
Hi Tony,

Tony Belding wrote:
> I'm interested in using an off-the-shelf interpreted language as a
> user-accessible scripting language for a MUCK.  I'm just not sure if I
> can find one that does everything I need.  The MUCK must be able to call
> the interpreter and execute scripts with it, but the interpreter must
> also be able to call functions in the MUCK code.  And then there's the
> security issue that really worries me. . .  I have to be able to limit
> what the interpreter can execute.  I can't have my users running scripts
> that access the console, access the filesystem or sockets directly, or
> call libraries or other binaries outside the MUCK.
> 
> Is this practical?  I'm thinking of Ruby or Python for this, if they can
> meet the requirements.
> 
> I might even consider REXX. . .  I remember ARexx from my Amiga days,
> and how great it was for string manipulation and application scripting.
> However. . .  My immediate target platform, Mac OS X, comes with Ruby
> and Python but not REXX, so that's a disadvantage.
> 
> My final option would be to create my own language interpeter where I
> have control over everything that happens.  That is what MUCKs have
> always done in the past.  But the result was always quirky, limited
> languages like MUF (Multi-User Forth) which really turn off a lot of
> coders.  Furthermore, I've never created a language before, and it would
> be a lot of extra work for me.

Well, a few remarks here ad the REXX options that would be available to you:

- REXX (there was its 25th anniversary celebrated in 2004) has an 
object-oriented successor that
still can execute plain REXX code, but is realized as an object-oriented 
language: Object REXX. It
got originally developed by IBM, after their big customers indicated that they 
would be interested
in it. In 1997 Object REXX became part of OS/2 Warp 4. IBM sold Object REXX for 
AIX and Windows.

- In 2004 after negotiations took place with the non-profit Rexx Language 
Association (RexxLA,
http://www.RexxLA.org), IBM handed the source code of Object REXX over to the 
RexxLA which created a
free and open source version and distributed it in April 2005 for the first 
time as Open Object Rexx
(ooRexx) 3.0, cf. ).

- The ooRexx source-code is hosted on Sourceforge and uses the Common Public 
License (CPL) 1.0 (cf.
). This means that you can 
freely use the code, edit
it your way and make it even part of your own (even commercial) product.

- This week a new drop of ooRexx, version 3.1.1, has been released, with 
binaries built for AIX
(first time that an official ooRexx binary got build for it!), Linux, MacOSX 
(first time that an
official ooRexx binyry got build for it PPC, Intel), Solaris (Intel, Sparc), 
and Windows.
[Additional binaries for additional environments can be built using the 
autoconf tools.]
So ooRexx has been made available for your main target platform for your MUCK 
application.

- Ad your needs w.r.t. calling functions of your MUCK applicaiton: yes, that is 
possible (and not
difficult at all).

- Ad your needs w.r.t. security needs of your MUCK application: yes, that is 
possible (and not
difficult at all):
Because of the history of ooRexx (it was a commercial product to be deployed at 
large sites,
security was a paramount issue), there is a Security Manager built into ooRexx.
The ooRexx security architecture is quite interesting, easy to use, very 
flexible as it allows you
to create as many differenct security policy rules as you may wish. The ooRexx 
security manager will
monitor all potential insecure actions from REXX and ooRexx programs (like 
accessing the
environment, accessing streams, accessing functions etc.) and inform the policy 
program about such
intended, possibly secure-threatening operations. The policy program then is 
able to decide to let
the action through, to execute a secure operation instead without the 
supervised REXX or ooRexx
program noticing this (!), or stop the execution of the supervised program 
alltogether.
If you are interested in this and need ideas, help for your MUCK needs, then 
please post, such that
people over here (ie. the ) can help you out.

- Ad ooRexx in general: it is an easy to learn and easy to use (follows still 
the original REXX
philosophy to be a "human centric" language!!), fully object-oriented language 
(influenced by
Smalltalk). There is a small, tutorial-like paper (written for this year's 
European Conference of
Object-Oriented Programming, ECOOP, workshop named "Revival of Dynamic 
Languages (RDL)
", which really gives a brief overview 
of the history and
the (interesting) features of the ooRexx langauge, entitled "Resurrecting REXX, 
Introducing Object
Rexx", to enable reflection and discussion of the language and its interesting 
concepts, cf.:
. At the end of

Re: problem with global variable in a module

2006-11-25 Thread Duncan Booth
"hollowspook" <[EMAIL PROTECTED]> wrote:

> from test import *
> b=1
> aa()
> 
> The error message is :
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "test.py", line 3, in aa
> b=b+1
> NameError: global name 'b' is not defined
> 
> Why this happens? Please do me a favor. 

The global statement makes a name global to a module, it doesn't make it 
global to the entire program. The function aa is in module test, the 
statements you entered in the shell are in a different module called 
__main__.

The particular form of import you used may also be confusing you: just 
because you imported '*' doesn't change the function: 'aa' was defined in 
the module 'test' and that is where it still looks for its global 
variables, all the import did was define a new name 'aa' in the __main__ 
module which refers to the same function object as 'aa' in 'test'.

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


How to Restart a thread

2006-11-25 Thread many_years_after
class mythread(threading.Thread):
def __init__(self, threadname):
threading.Thread.__init__(self, name = threadname)

def run(self):
print 'i am running'
print 'i quit run()'

thread  = mythread('1')
thread.start()
print threading.activeCount()  ## 1 , this means the thread is active
if not thread.isAlive():
print 'i am dead,you can restart'   ### OK, this is executed. this
means the thread is no alive
thread.start()  " thread already started "

This program presentes that the thread quit the *run()* func and is
active but not alive.   How to understand this? It is said if the
thread quit the *run()* func , it's dead.
how to restart it ?

Thanks

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

Return float problem.

2006-11-25 Thread YunBin Lee
Hi, all.
I have a problem of float return error in python c binding module.
Below is my c sources, compile commands and result of program.

== wrap.c =
#include 

PyObject *wrap_fact(PyObject *self, PyObject *args)
{
double n=0.0,result=0.0;
if (!PyArg_ParseTuple (args,"d:fact",&n))
return NULL;
result = fact(n);
result = fact(result);
return Py_BuildValue("d",result);
}

PyObject *wrap_test(PyObject *self, PyObject *args)
{
double value = 0.124;
return Py_BuildValue ("d", value);
}

static PyMethodDef exampleMethods[] =
{
{"fact", wrap_fact, METH_VARARGS, "Simple return a float"},
{"test", wrap_test, METH_VARARGS, "Test"},
{NULL,NULL}
};

void initexample()
{
PyObject *m;
m = Py_InitModule ("example", exampleMethods);
}
== end wrap.c =

== example.c =
#include 

double fact(double n)
{
printf ("n=%f\n",n);
return n;
}

int main(int argc,char *argv[])
{
printf ("%f\n",fact(0.1234));
}
== end example.c =

complied with commands:
[EMAIL PROTECTED]:~$ gcc -fpic -c -I. -I.. -I/usr/include/python2.4/ example.c
wrap.c
[EMAIL PROTECTED]:~$ gcc -shared -o example.so example.o wrap.o

then i used the example.so with command:
[EMAIL PROTECTED]:~$ python -c "import example; print example.fact(0.444)"
n=0.444000
n=-103079215.00 <-- Why not is 0.444?
-1140850688.0 <--- Why not is 0.444?

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

Re: The Python Papers Edition One

2006-11-25 Thread Carl Banks

Paul Rubin wrote:
> "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes:
> > Your email indicates a possible concern that we are doing something
> > untoward -- this was not at all intended, nor is it true.
>
> Although you might not have intended it, I feel it is still true.  You
> are misappropriating terminology ("free as in freedom") from the free
> software movement that means a work is licensed in a way that meets
> some specific criteria, that the license you're using does not meet.

"Free as in freedom" is not terminology; it's a way to differentiate
one of two different senses of the word "free".  "Specific criteria" is
some people's idea of what freedom is, but they're not the last word on
it.


Carl Banks

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


Re: problem with global variable in a module

2006-11-25 Thread Diez B. Roggisch
hollowspook schrieb:
> def aa():
> global b
> b=b+1
> print b
> 
> b=1
> aa()
> 
> The above code runs well in python shell.
> 
> However I  have a problem as follows.
> 
> new a file named test.py
> 
> 
> def aa():
> global b
> b=b+1
> print b
> -
> 
> Then in python shell,
> 
> from test import *
> b=1
> aa()
> 
> The error message is :
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "test.py", line 3, in aa
> b=b+1
> NameError: global name 'b' is not defined
> 
> Why this happens? Please do me a favor. 

Because python does not know "real" globals - globals are always only
global on a module level. Now using the "from module import *"-syntax
asks for trouble. Because your global b above is global to the
__main__-module, not to the module test. But the aa-function expects it
to live in tests.

To make your example work, do it as this:

import test

test.b = 1
test.aa()


See
http://effbot.org/pyfaq/tutor-whats-the-difference-between-import-foo-and-from-foo-import.htm

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

Dynamic function execution

2006-11-25 Thread Andy Wu
Hi guys,

There's a function I want to use which looks like this:

def func(seconds = None, minutes = None, hours = None):
...

In my program I can get a string object('seconds', 'minutes', 'hours')
to specify which parameter to use, the problem is I don't know how to
call the function.

Say I have a string 'minutes' and a integer 30, now I need to call the
func this way: func(minutes = 30), how do I do this?

I'm sure this is a simple question, but I can't google it out since I
don't know how to describe it in a short term.

Thanks,

Andy Wu

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

Re: The Python Papers Edition One

2006-11-25 Thread Paul Boddie
Jerry Hill wrote:
> > MontyLingua is GPL software and thus has its own licensing issues for
> > commercial software.

MontyLingua might appear to be GPL-licensed, but then the author puts
some kind of non-commercial clause on top, either thinking that's what
the GPL is all about (out of confusion, perhaps), or believing that he
can limit the rights of the those who license his code. The effect is
that the code is not actually GPL-licensed at all, given the stated
conditions on distribution. See here for more discussion:

http://lists.debian.org/debian-legal/2004/08/msg00622.html

Paul

P.S. This obsession in academia for non-commercial licences is quite a
destructive force: everyone "protects" their own work yet steers clear
of other people's work, redoing what they need themselves, mostly
because they've got an eye on "monetizing" that work later on.
Consequently, the cult of the almighty dollar gets more out of it than
scientific progress does.

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


Re: Dynamic function execution

2006-11-25 Thread Fredrik Lundh
Andy Wu wrote:

> def func(seconds = None, minutes = None, hours = None):
> ...
> 
> In my program I can get a string object('seconds', 'minutes', 'hours')
> to specify which parameter to use, the problem is I don't know how to
> call the function.
> 
> Say I have a string 'minutes' and a integer 30, now I need to call the
> func this way: func(minutes = 30), how do I do this?

func(**{"minutes": 30})



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

Re: Dynamic function execution

2006-11-25 Thread Irmen de Jong
Andy Wu wrote:
> Say I have a string 'minutes' and a integer 30, now I need to call the
> func this way: func(minutes = 30), how do I do this?

d={"minutes": 30}
func(**d)

This is "extended call syntax". You can read more about this when
you look up the (deprecated) "apply" function in the manual.

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

Re: combining the path and fileinput modules

2006-11-25 Thread wo_shi_big_stomach
Gabriel Genellina wrote:
> At Saturday 25/11/2006 00:14, wo_shi_big_stomach wrote:
> 
>> > The filter should be applied to walkfiles. Something like this:
>> >
>> > dir = path(/home/wsbs/Maildir)
>> > for f in filter(os.path.isfile, dir.walkfiles('*')):
>> > #
>> > # test:
>> > # print f
>>
>> Thanks, this way f will print the full pathname/filename. But f already
>> does that using Jason Orendorff's path module:
>>
>> dir = path('/home/wsbs/Maildir')
>> for f in dir.walkfiles('*'):
>> print f
> 
> The filter is used to exclude directories. fileinput can't handle
> directories.

???

Both routines above produce identical output -- full path/filenames.
Neither prints just a directory name.

> 
>> At this point I believe the error has to do with fileinput, not the path
>> or os.path modules.
>>
>> If I give fileinput.input() a hardcoded path/filename in place of 'f'
>> the program runs. However the program will not accept either f or 'f' as
>> an argument to fileinput.input().
> 
> Tried with (f,) ?
> Notice that *this* error is not the same as your previous error.

  File "p2.py", line 23, in ?
for line in fileinput.input(f,):
  File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/fileinput.py",
line 231, in next
line = self.readline()
  File
"/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/fileinput.py",
line 320, in readline
self._file = open(self._filename, "r")

This looks similar to before -- fileinput.input() still isn't operating
on the input.

Again, I'm looking 1) walk through all files in a directory tree and 2)
using fileinput, evaluate and possibly edit the files.

The current version of the program is below.

thanks!

/wsbs

# start of program
import fileinput
import os
import re
import string
import sys
from path import path

# p2.py - fix broken SMTP headers in email files
#
# recurses from dir and searches all subdirs
# for each file, evaluates whether 1st line starts with "From "
# for each match, program deletes line

# recurse dirs
dir = path('/home/wsbs/Maildir')
#for f in dir.walkfiles('*'):
for f in filter(os.path.isfile, dir.walkfiles('*')):
#
# test: this will print the full path/filename of each file
# print f
#
# open file, search, change if necessary, write backup
for line in fileinput.input(f,):
# just print 2nd and subsequent lines
if not fileinput.isfirstline():
print line.rstrip('\n')
# check first line only
elif fileinput.isfirstline():
if not re.search('^From ',line):
print line.rstrip('\n')
fileinput.close()

# end of program
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Python Papers Edition One

2006-11-25 Thread Noah Slater

On Nov 22, 12:41 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Thanks for the comments. PDF is, to some extent, a requirement. To
> preserve the entire journal as a single "entity" with a reasonably high
> production quality, there seems to be no way around it. I could not
> find a sufficiently simple way to do multi-format publishing with an
> attractive layout and good typesetting.

Which is more important to the Python comunity...

Good typesetting or good, searchable, copyable, usable information?

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


Re: Simple threading

2006-11-25 Thread Aahz
In article <[EMAIL PROTECTED]>,
Grant Edwards  <[EMAIL PROTECTED]> wrote:
>
>Re-binding a name is always an atomic operation.  Modifying
>many mutable objects is atomic.

You know this, but just to make clear: rebinding attributes of an object
(which are also sometimes called names) is not necessarily an atomic
operation.  Moreover, only a plain rebinding operation is atomic;
augmented assignment is frequently not atomic.
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"In many ways, it's a dull language, borrowing solid old concepts from
many other languages & styles:  boring syntax, unsurprising semantics,
few automatic coercions, etc etc.  But that's one of the things I like
about it."  --Tim Peters on Python, 16 Sep 1993
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Invoking Python from Cygwin problem.

2006-11-25 Thread Cousin Stanley


> Hi all,
>
> Using cygwin and Python 2.5, I have the following scripts, 
> one bash script and the other a python script:
> --

Ant  

  Using Cygwin and Python 2.4 under Win2K the following version 
  of your code seems to work OK here with no extraneous CR 

  I only changed the variable names & messages just a bit 
  for clarity 

  I don't see any real differences in this version
  and what you originally posted, so I can't explain
  the reason for the semingly extraneous carriage return
  that you are seeing 
  
  #  

  #!/bin/bash

  TEST_1=`./test.py`
  TEST_2="Testing Bash  Value"

  echo " "
  echo "TEST_1 :  $TEST_1  OK"
  echo "TEST_2 :  $TEST_2  OK"


  # 

  #!/usr/bin/python
  print "Testing Python Code",


  # 

  $ ./test_vars

  TEST_1 :  Testing Python Code  OK
  TEST_2 :  Testing Bash  Value  OK
  

-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona


== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About alternatives to Matlab

2006-11-25 Thread Brian Blais
Phil Schmidt wrote:
> 
> I'd love to use Python, but I'm not comfortable with the hardware side
> of that. I'm certain that most, if not all data acquisition hardware
> comes with DLL drivers, which I could interface with using ctypes. I'm
> concerned though about spending more time messing around with the
> hardware interface than it's worth.
> 
> Do you have any experience with this side of the Matlab replacement
> question? How about anyone else? Any recommendations?
> 

Unfortunately, no I don't have experience with the hardware end of things.  One 
can,
both with c-types and with pyrex, very easily use existing C libraries so if 
there is
a C-API, that shouldn't be a problem.

Sorry for not being much help!


bb

-- 
-

  [EMAIL PROTECTED]
  http://web.bryant.edu/~bblais

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


Re: Try to stop thread Using flag

2006-11-25 Thread ger <[EMAIL PROTECTED]>
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

The Python documentation states:

[quote]
start(  )
Start the thread's activity.

This must be called at most once per thread object. It arranges for
the object's run() method to be invoked in a separate thread of control.
[/quote]

So you cannot start() one Thread object a second time, you have to
create a new one. But as you don't move any thread out of your list in
the OnEndProcess function all stopped Thread objects are indeed
restarted by your OnBeginProcess as they are still in self.threadlist.

Furthermore: you should wait in our OnEndProcess function and check
whether all thread have ended indeed by calling Thread.join().
Otherwise some threads mights still be running indeed.

Hope I could make it clear.

Greetings

Nils
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFFaHbrRQeuB6ws8wERAr4+AJ0UOTCPZoJLK8F4AfnfKyPInwQLVQCcC3a6
6aBP+POkMkKCym6JRaP87yw=
=AgnH
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to Restart a thread

2006-11-25 Thread Rob Williscroft
many_years_after wrote in news:1164467660.760671.145440
@j44g2000cwa.googlegroups.com in comp.lang.python:

> class mythread(threading.Thread):
> def __init__(self, threadname):
> threading.Thread.__init__(self, name = threadname)
> 
> def run(self):
> print 'i am running'
> print 'i quit run()'
> 
> thread  = mythread('1')
> thread.start()
> print threading.activeCount()  ## 1 , this means the thread is active
> if not thread.isAlive():
> print 'i am dead,you can restart'   ### OK, this is executed. this
> means the thread is no alive
> thread.start()  " thread already started "
> 
> This program presentes that the thread quit the *run()* func and is
> active but not alive.   How to understand this? It is said if the
> thread quit the *run()* func , it's dead.
> how to restart it ?
> 
> Thanks
> 

Form the manual [1] (you must have missed this):

start( ) 

Start the thread's activity. 
This must be called at most once per thread object. 
It arranges for the object's run() method to be invoked 
in a separate thread of control. 

Note the 2nd line:

This must be called at most once per thread object. 

so you simply can't restart a Thread object.

[1] http://docs.python.org/lib/thread-objects.html

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Graph Data Structures

2006-11-25 Thread Robin Becker
Szabolcs Nagy wrote:

> if you only want to do some analysis i think you need this one (as it's
> pretty complete and simple):
> https://networkx.lanl.gov/


seems to be broken at present with a python traceback coming out; not a 
good advert for python and/or trac
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Return float problem.

2006-11-25 Thread John Machin
YunBin Lee wrote:
> Hi, all.
> I have a problem of float return error in python c binding module.
> Below is my c sources, compile commands and result of program.

There seems to be a missing file: example.h. If that hint isn't
sufficient, please continue reading.

>
> == wrap.c =
> #include 
>
> PyObject *wrap_fact(PyObject *self, PyObject *args)
> {
> double n=0.0,result=0.0;
> if (!PyArg_ParseTuple (args,"d:fact",&n))
> return NULL;
> result = fact(n);
> result = fact(result);
> return Py_BuildValue("d",result);
> }
>
> PyObject *wrap_test(PyObject *self, PyObject *args)
> {
> double value = 0.124;
> return Py_BuildValue ("d", value);
> }
>
> static PyMethodDef exampleMethods[] =
> {
> {"fact", wrap_fact, METH_VARARGS, "Simple return a float"},
> {"test", wrap_test, METH_VARARGS, "Test"},
> {NULL,NULL}
> };
>
> void initexample()
> {
> PyObject *m;
> m = Py_InitModule ("example", exampleMethods);
> }
> == end wrap.c =
>
> == example.c =
> #include 
>
> double fact(double n)
> {
> printf ("n=%f\n",n);
> return n;
> }
>
> int main(int argc,char *argv[])
> {
> printf ("%f\n",fact(0.1234));
> }
> == end example.c =
>
> complied with commands:
> [EMAIL PROTECTED]:~$ gcc -fpic -c -I. -I.. -I/usr/include/python2.4/ example.c
> wrap.c

Didn't this produce any warning messages, like:

wrap.c:8: warning: implicit declaration of function `fact'

?

> [EMAIL PROTECTED]:~$ gcc -shared -o example.so example.o wrap.o
>
> then i used the example.so with command:
> [EMAIL PROTECTED]:~$ python -c "import example; print example.fact(0.444)"
> n=0.444000
> n=-103079215.00 <-- Why not is 0.444?
> -1140850688.0 <--- Why not is 0.444?

Did you notice that the garbage is a whole number? Why? Because you
have been (more or less) plucking ints out of some arbitrary place on
the stack, floating them, and printing them.

HTH,
John

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


Re: Graph Data Structures

2006-11-25 Thread bearophileHUGS
Szabolcs Nagy:
> i haven't read your code, but there are many graph implementations in
> python.
> in case you haven't found these yet:
> http://wiki.python.org/moin/PythonGraphApi
>
> if you only want to do some analysis i think you need this one (as it's
> pretty complete and simple):
> https://networkx.lanl.gov/
>
> i also recommend Guido's essay to read:
> http://www.python.org/doc/essays/graphs.html

I can also suggest my one:
http://sourceforge.net/projects/pynetwork/

And boost graph bindings for Python, quite fast:
http://www.osl.iu.edu/~dgregor/bgl-python/

Bye,
bearophile

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


Re: Invoking Python from Cygwin problem.

2006-11-25 Thread Ant

Cousin Stanley wrote:
...
>   Using Cygwin and Python 2.4 under Win2K the following version
>   of your code seems to work OK here with no extraneous CR 

Hmm. Just tried it here at home (Python 2.5) and it works fine as
well... Cygwin was pre-installed on my machine when I started work at
the new job a couple of weeks ago. I wonder if it's an old version they
had installed. I'll try updating Cygwin at work and see what happens...

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


my small hashlib - using pythons hash-functions

2006-11-25 Thread Mathias Panzenboeck
Hi.

I wrote a small hashlib for C. Because I'm new to hashes I looked at pythons 
implementation and 
reused *some* of the code... or more the mathematical "hash-function", not 
really the code.

In particular I looked at pythons hash and lookup functions, so I came up with 
this (see the code 
underneath).

So, can this code be considered as derived and do I have to put my code under 
the GPL? I'd like to 
publish it under something less restrictive, like a BSD style license. But if 
GPL is the only way, 
then GPL it is. :)

-panzi


#define PERTURB_SHIFT 5

static ENTRY_T * lookup(CONTAINER_T * table, hash_const_str_t key,
  int (*loop_cond)(ENTRY_T * ptr, hash_const_str_t key)) {
register ENTRY_T *   entries = table->entries;
register hash_size_t size= table->size;
register hash_size_t pos = hash(key) % size;
register hash_size_t perturb = pos;

register ENTRY_T * ptr = entries + pos;

while(loop_cond(ptr,key)) {
pos   = ((pos << 2) + pos + perturb + 1) % size;
perturb >>= PERTURB_SHIFT;

ptr = entries + pos;

#ifdef HASH_COUNT_COLLISIONS
++ table->collisions;
#endif
}

return ptr;
}

hash_t hash(register hash_const_str_t str) {
/* python 2.5's hash function: */
register hash_size_t len;
register hash_t  h;

assert(str);

len = strlen(str);
h   = *str << 7;

while (*str)
h = (103 * h) ^ *str ++;
h ^= len;

return h;
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: my small hashlib - using pythons hash-functions

2006-11-25 Thread Paul Rubin
Mathias Panzenboeck <[EMAIL PROTECTED]> writes:
> So, can this code be considered as derived and do I have to put my
> code under the GPL? I'd like to publish it under something less
> restrictive, like a BSD style license. But if GPL is the only way,
> then GPL it is. :)

Python is not GPL'd but has its own license.  You can make the derived
work GPL if you want, but it is not required.  You'll have to check
its terms to see whether you can specifically use the BSD license.
Simplest might be to just stay with the Python license.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Python Papers Edition One

2006-11-25 Thread Fredrik Lundh
Noah Slater wrote:

> Which is more important to the Python comunity...

the community definitely don't need more random usenet posters who's 
only contribution is to complain whenever someone tries to do some-
thing.  this thread is an embarrassment for the Python community; you 
should all be ashamed of yourself.



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


Re: my small hashlib - using pythons hash-functions

2006-11-25 Thread Mathias Panzenboeck
Paul Rubin wrote:
> Mathias Panzenboeck <[EMAIL PROTECTED]> writes:
>> So, can this code be considered as derived and do I have to put my
>> code under the GPL? I'd like to publish it under something less
>> restrictive, like a BSD style license. But if GPL is the only way,
>> then GPL it is. :)
> 
> Python is not GPL'd but has its own license.  You can make the derived
> work GPL if you want, but it is not required.  You'll have to check
> its terms to see whether you can specifically use the BSD license.
> Simplest might be to just stay with the Python license.

Yes, right. It's PSF.

But the question is: *IS* this derived work? I mean, it's not copied code.
It's the same hashing-logic, which I learned by watching pythons code.

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


Re: The Python Papers Edition One

2006-11-25 Thread Steven D'Aprano
On Sat, 25 Nov 2006 08:13:58 -0800, Noah Slater wrote:

> 
> On Nov 22, 12:41 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>> Thanks for the comments. PDF is, to some extent, a requirement. To
>> preserve the entire journal as a single "entity" with a reasonably high
>> production quality, there seems to be no way around it. I could not
>> find a sufficiently simple way to do multi-format publishing with an
>> attractive layout and good typesetting.
> 
> Which is more important to the Python comunity...
> 
> Good typesetting or good, searchable, copyable, usable information?

Such a sweeping generalization, as if "the Python community" only wanted
one thing.

In any case:

(1) Whether the Python Papers is "good" depends on what content it
includes, not the file format it is published in.

(2) Google can index PDF files. If the Python Papers aren't reachable by
Google's spiders, well, I consider that the Kiss of Death for them.

(3) Code in the Python Papers are certainly legally copyable, and if your
PDF viewer doesn't let you copy text from PDFs, use another PDF viewer:

[quote from page 4 of the Python Papers]
def process(self):
  '''
  Processes the payment into the financial system
  '''
  self._recordPayment()
  self._despatchOrder()
  self._sendConfirmation()
  self._concludePayment()
def _recordPayment():
  '''
  Make a permanent record of the payment in the database
  '''
  pass

Works fine for me, although I would question the choice of TWO spaces for
indents.

(4) The Python Papers are certainly legally usable, for non-commercial
use. For commercial use, you have at least two legal options:

- treat the work the same as you would any piece of code with an
unacceptable licence, and develop your own NON-derivative version. It's
only copyrighted, not patented: you are still allowed to write your own
independent version. Merely having read a work doesn't necessarily
contaminate whatever you write next.

- contact the author of the work and ask for a commercial licence. You may
have to pay a licence fee, or perhaps not.

Instead of bitching and moaning about it, how about you submit your own
work to the Python Papers under a dual licence? It can be both CC
Non-commercial, and GPL (or whatever licence you like).

I assume the purpose of the Non-commercial licence is to prevent somebody
taking up the Python Papers in full and charging for it. (Personally, I
think that is a very low risk -- who cares if somebody tries to charge
for it? They can't compete with the gratis version being given away for
nothing.) Dual licences for the contributed articles will still protect
the over-all integrity of the magazine from being sold for profit, while
still allowing coders to duplicate useful code and use it in whatever they
choose.

That way, the Python Papers themselves continue to be free as in beer, and
individual articles can, according to their authors wishes, be *at least*
gratis and possibly free as in speech as well.



-- 
Steven.

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


Re: my small hashlib - using pythons hash-functions

2006-11-25 Thread Fredrik Lundh
Mathias Panzenboeck wrote:

> But the question is: *IS* this derived work? I mean, it's not copied code.
> It's the same hashing-logic, which I learned by watching pythons code.

given that it's only a few lines of code, and there's hardly any other 
way to write those lines if you want to implement the same algorithm, 
I'd say it falls under "fair use".  crediting the Python developers in 
the source code should be good enough.



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


Re: Simple threading

2006-11-25 Thread Fredrik Lundh
Grant Edwards wrote:

> That depends on the type of the global and how they're used.
> Re-binding a name is always an atomic operation.  Modifying
> many mutable objects is atomic.

footnote: for more on this topic, see this FAQ entry:

http://effbot.org/pyfaq/what-kinds-of-global-value-mutation-are-thread-safe.htm

and this recent python-dev thread that discusses that entry:

http://mail.python.org/pipermail/python-dev/2006-November/thread.html#69981



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


a -very- case sensitive search

2006-11-25 Thread Ola K
Hi,
I am pretty new to Python and I want to make a script that will search
for the following options:
1) words made of uppercase characters -only- (like "YES")
2) words made of lowercase character -only- (like "yes")
3) and words with only the first letter capitalized (like "Yes")
* and I need to do all these considering the fact that not all letters
are indeed English letters.

I went through different documention section but couldn't find a right
condition, function or method for it.
Suggestions will be very much appriciated...
--Ola

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


Re: a -very- case sensitive search

2006-11-25 Thread Goofy666
Hi

 > * and I need to do all these considering the fact that not all letters
 > are indeed English letters.

You mean letters from the English alphabet (derived from the Latin/Roman 
alphabet, fyi)? I'm sorry for the nitpicking, but 'English letters' 
sounds a bit too 'ackward' to me.

 > I went through different documention section but couldn't find a right
 > condition, function or method for it.
 > Suggestions will be very much appriciated...

I'm still (trying to) learn(ing) it myself, but you can try looking into 
using regular expressions. There's a standard module for it (re), see 
the PyLib Reference for details; http://docs.python.org/lib/module-re.html.

--Laurens

Ola K wrote:
> Hi,
> I am pretty new to Python and I want to make a script that will search
> for the following options:
> 1) words made of uppercase characters -only- (like "YES")
> 2) words made of lowercase character -only- (like "yes")
> 3) and words with only the first letter capitalized (like "Yes")
> * and I need to do all these considering the fact that not all letters
> are indeed English letters.
> 
> I went through different documention section but couldn't find a right
> condition, function or method for it.
> Suggestions will be very much appriciated...
> --Ola
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: my small hashlib - using pythons hash-functions

2006-11-25 Thread Mathias Panzenboeck
Fredrik Lundh wrote:
> Mathias Panzenboeck wrote:
> 
>> But the question is: *IS* this derived work? I mean, it's not copied 
>> code.
>> It's the same hashing-logic, which I learned by watching pythons code.
> 
> given that it's only a few lines of code, and there's hardly any other 
> way to write those lines if you want to implement the same algorithm, 
> I'd say it falls under "fair use".  crediting the Python developers in 
> the source code should be good enough.
> 
> 
> 

ic. I'll write a mail to the python developers then.

The code in python looks like this (see code underneath), just if someone 
what's to know.
I only used the logic of the parts I understand. ;)

Objects/stringobject.c:

static long
string_hash(PyStringObject *a)
{
register Py_ssize_t len;
register unsigned char *p;
register long x;

if (a->ob_shash != -1)
return a->ob_shash;
len = a->ob_size;
p = (unsigned char *) a->ob_sval;
x = *p << 7;
while (--len >= 0)
x = (103*x) ^ *p++;
x ^= a->ob_size;
if (x == -1)
x = -2;
a->ob_shash = x;
return x;
}

Objects/dictobject.c:

static dictentry *
lookdict_string(dictobject *mp, PyObject *key, register long hash)
{
register size_t i;
register size_t perturb;
register dictentry *freeslot;
register size_t mask = (size_t)mp->ma_mask;
dictentry *ep0 = mp->ma_table;
register dictentry *ep;

/* Make sure this function doesn't have to handle non-string keys,
   including subclasses of str; e.g., one reason to subclass
   strings is to override __eq__, and for speed we don't cater to
   that here. */
if (!PyString_CheckExact(key)) {
#ifdef SHOW_CONVERSION_COUNTS
++converted;
#endif
mp->ma_lookup = lookdict;
return lookdict(mp, key, hash);
}
i = hash & mask;
ep = &ep0[i];
if (ep->me_key == NULL || ep->me_key == key)
return ep;
if (ep->me_key == dummy)
freeslot = ep;
else {
if (ep->me_hash == hash && _PyString_Eq(ep->me_key, key))
return ep;
freeslot = NULL;
}

/* In the loop, me_key == dummy is by far (factor of 100s) the
   least likely outcome, so test for that last. */
for (perturb = hash; ; perturb >>= PERTURB_SHIFT) {
i = (i << 2) + i + perturb + 1;
ep = &ep0[i & mask];
if (ep->me_key == NULL)
return freeslot == NULL ? ep : freeslot;
if (ep->me_key == key
|| (ep->me_hash == hash
&& ep->me_key != dummy
&& _PyString_Eq(ep->me_key, key)))
return ep;
if (ep->me_key == dummy && freeslot == NULL)
freeslot = ep;
}
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Graph Data Structures

2006-11-25 Thread Nathan Harmston
> > https://networkx.lanl.gov/

This was working for me earlier, I managed to get everything from
there earlier. It seems a very good package. It seems theres more out
there than what I had thought, which unfortunately makes it harder for
me to decide what to use (pynetwork and bgl look useful aswell). I m
going to do some testing on it later and see what happens with it.
Thanks a lot for your help.

Has anyone got an idea how I could split the contents of a node and
its representation (to save memory in my graph). ie the nodes
contain the start and end coordinates and id and the actual
representation contains the string. I was going to have :

class Node(object):
pass

class Section(Node):
pass

class Item(object):
   pass

Where section contains a slice of the Item which im interested. I m
just not sure how I can access the contents of item without storing
it. ---> If u get what I mean???

Many Thanks in advance

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


case insensitive dictionary

2006-11-25 Thread John Henry
I believe the standard dictionary should be amened to allow the use of
case insensitive keys - as an option.  I found some work done by others
to do that at:

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

but the problem with that approach is that they lowercase the keys
immediately when you create the dictionary and so the true identity of
the key is lost.

Of course, I can subclass it and save a copy of the "real" key but
that's kind of messcy.

In other words:

If I have:

pets=caselessDict()

pets["Cat"] = 3
pets["Dog"] = 2

I would like to see:

   pets["cat"]  prints 3
   pets["DOG"] prints 2

but

   print pets.keys()

should print:

"Cat", "Dog"

not:

"cat", "dog"

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


Re: a -very- case sensitive search

2006-11-25 Thread Dustan

Ola K wrote:
> Hi,
> I am pretty new to Python and I want to make a script that will search
> for the following options:
> 1) words made of uppercase characters -only- (like "YES")
> 2) words made of lowercase character -only- (like "yes")
> 3) and words with only the first letter capitalized (like "Yes")
> * and I need to do all these considering the fact that not all letters
> are indeed English letters.
>
> I went through different documention section but couldn't find a right
> condition, function or method for it.
> Suggestions will be very much appriciated...
> --Ola

I'm not sure exactly what you mean by "considering the fact that not
all letters are indeed English letters"; you could mean you don't care
about the non-english characters, or you could mean you don't want any
non-english characters at all (so the function should return False in
that case). If the case is the former, there's a simple test for each:

>>> word = 'hi'
>>> word.upper() == word # evaluates to True if the word is all caps
False
>>> word.lower() == word # evaluates to True if the word is all lowercase
True
>>> word.title() == word # evaluates to True if the word is in a title format
False
>>>

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


Re: Graph Data Structures

2006-11-25 Thread John Machin

Nathan Harmston wrote:
> > > https://networkx.lanl.gov/
>
> This was working for me earlier, I managed to get everything from
> there earlier. It seems a very good package. It seems theres more out
> there than what I had thought, which unfortunately makes it harder for
> me to decide what to use (pynetwork and bgl look useful aswell). I m
> going to do some testing on it later and see what happens with it.
> Thanks a lot for your help.
>
> Has anyone got an idea how I could split the contents of a node and
> its representation (to save memory in my graph). ie the nodes
> contain the start and end coordinates and id and the actual
> representation contains the string. I was going to have :
>
> class Node(object):
> pass
>
> class Section(Node):
> pass
>
> class Item(object):
>pass
>
> Where section contains a slice of the Item which im interested. I m
> just not sure how I can access the contents of item without storing
> it. ---> If u get what I mean???

No. Not at all. "pass" is not very informative. Neither are
"representation" and "the string". Please tell us what you mean by
"slice". What is an "item", if it's not a "node"? Try listing out the
attributes of a node, with a couple of sample values for each, and then
we might get a clue.

What makes you think that you need to save memory?

What makes you think that you could save memory by splitting whatever
it is?

HTH,
John

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


Re: a -very- case sensitive search

2006-11-25 Thread Steven D'Aprano
On Sat, 25 Nov 2006 13:39:55 -0800, Ola K wrote:

> Hi,
> I am pretty new to Python and I want to make a script that will search
> for the following options:
> 1) words made of uppercase characters -only- (like "YES")
> 2) words made of lowercase character -only- (like "yes")
> 3) and words with only the first letter capitalized (like "Yes")
> * and I need to do all these considering the fact that not all letters
> are indeed English letters.
> 
> I went through different documention section but couldn't find a right
> condition, function or method for it.

At the command prompt:


>>> dir('')
# result edited for clarity
[ ... 'isalnum', 'isalpha', 'isdigit', 'islower',
'isspace', 'istitle', 'isupper',  ... ]

Then do this:

>>> help(''.islower)

and read the text it provides. Then experiment on the command line:

>>> 'abcd1234'.islower()
True
>>> 'aBcd1234'.islower()
False

Then come back to us if they aren't suitable, and tell us WHY they aren't
suitable.


-- 
Steven.

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


Re: a -very- case sensitive search

2006-11-25 Thread Dustan

Dustan wrote:
> Ola K wrote:
> > Hi,
> > I am pretty new to Python and I want to make a script that will search
> > for the following options:
> > 1) words made of uppercase characters -only- (like "YES")
> > 2) words made of lowercase character -only- (like "yes")
> > 3) and words with only the first letter capitalized (like "Yes")
> > * and I need to do all these considering the fact that not all letters
> > are indeed English letters.
> >
> > I went through different documention section but couldn't find a right
> > condition, function or method for it.
> > Suggestions will be very much appriciated...
> > --Ola
>
> I'm not sure exactly what you mean by "considering the fact that not
> all letters are indeed English letters"; you could mean you don't care
> about the non-english characters, or you could mean you don't want any
> non-english characters at all (so the function should return False in
> that case). If the case is the former, there's a simple test for each:
>
> >>> word = 'hi'
> >>> word.upper() == word # evaluates to True if the word is all caps
> False
> >>> word.lower() == word # evaluates to True if the word is all lowercase
> True
> >>> word.title() == word # evaluates to True if the word is in a title format
> False
> >>>

If you're using google groups, it for some reason thought my example
code was 'quoted text', which it certainly isn't, seeing as it's not
found anywhere prior to my message.

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


Re: a -very- case sensitive search

2006-11-25 Thread Dustan

Steven D'Aprano wrote:
> On Sat, 25 Nov 2006 13:39:55 -0800, Ola K wrote:
>
> > Hi,
> > I am pretty new to Python and I want to make a script that will search
> > for the following options:
> > 1) words made of uppercase characters -only- (like "YES")
> > 2) words made of lowercase character -only- (like "yes")
> > 3) and words with only the first letter capitalized (like "Yes")
> > * and I need to do all these considering the fact that not all letters
> > are indeed English letters.
> >
> > I went through different documention section but couldn't find a right
> > condition, function or method for it.
>
> At the command prompt:
>
>
> >>> dir('')
> # result edited for clarity
> [ ... 'isalnum', 'isalpha', 'isdigit', 'islower',
> 'isspace', 'istitle', 'isupper',  ... ]
>
> Then do this:
>
> >>> help(''.islower)
>
> and read the text it provides. Then experiment on the command line:
>
> >>> 'abcd1234'.islower()
> True
> >>> 'aBcd1234'.islower()
> False

Forget what I said; I didn't know about the str.is* methods.

> Then come back to us if they aren't suitable, and tell us WHY they aren't
> suitable.
> 
> 
> -- 
> Steven.

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


Re: a -very- case sensitive search

2006-11-25 Thread John Machin
Dustan wrote:
> Steven D'Aprano wrote:
> > On Sat, 25 Nov 2006 13:39:55 -0800, Ola K wrote:
> >
> > > Hi,
> > > I am pretty new to Python and I want to make a script that will search
> > > for the following options:
> > > 1) words made of uppercase characters -only- (like "YES")
> > > 2) words made of lowercase character -only- (like "yes")
> > > 3) and words with only the first letter capitalized (like "Yes")
> > > * and I need to do all these considering the fact that not all letters
> > > are indeed English letters.
> > >
> > > I went through different documention section but couldn't find a right
> > > condition, function or method for it.
> >
> > At the command prompt:
> >
> >
> > >>> dir('')
> > # result edited for clarity
> > [ ... 'isalnum', 'isalpha', 'isdigit', 'islower',
> > 'isspace', 'istitle', 'isupper',  ... ]
> >
> > Then do this:
> >
> > >>> help(''.islower)
> >
> > and read the text it provides. Then experiment on the command line:
> >
> > >>> 'abcd1234'.islower()
> > True
> > >>> 'aBcd1234'.islower()
> > False
>
> Forget what I said; I didn't know about the str.is* methods.

... or about the unicode.is* [same bunch of] methods, which may
possibly address the OP's
"not all letters are indeed English letters" concerns. If he's stuck
with 8-bit str objects, he may need to ensure the locale is set
properly, as vaguely hinted at in the docs that Steven pointed him to.

Cheers,
John

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


screen output problem

2006-11-25 Thread Ritesh Raj Sarraf
Hi,

I have, for very long, been trying to find a consistent solution (which
could work across major python platforms - Linux, Windows, Mac OS X)
for the following problem.

I have a function which downloads files from the web. I've made the
function threaded. I'm trying to implement a progress bar for it which
could work across all the platforms.

The problem is that when the progress bar is displayed, all the threads
overwrite the progress bar.

I've thought of using curses but AFAIK curses is not available for
Windows.

Is there a generic way to accomplish the following:

progress = "[===]\n[===]"
for x in range(5):
sys.stdout.write(progress + "\r")

Basically, I want a way through which I want to display data on two
lines and make sure that "\r" overwrites the two lines without putting
a newline making sure that whatever library it uses is available across
all major Python platforms.

Thanks,
Ritesh

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


Re: Graph Data Structures

2006-11-25 Thread Nathan Harmston
Hi,

The idea is that I m going to use it to build graphs for sequence
alignment (at the moment), I read a discussion on the corebio
(reimplementation of biopython) group about using intervals to
represent sequence slices. The idea being that, my graph may contain
millions of alignments and storing the sequence (the actual ATGC) is
not required.

class Node(object):
 pass

class Interval(Node):
_id = "gene1"
 _start = 50
_end = 200
_strand = 1

class Sequence(object):
_sequence = "atgtcgtgagagagagttgtgag."

So one interval on one sequence would align to another interval from
another sequence, but I want changes I make to the interval to be
reflected in the representation later. If I reverse complement it i
want the interval to store this information but the Sequence only
shows this later on when I call use it calling repr or str.

Do you get what I mean.
Many Thanks

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


Re: Graph Data Structures

2006-11-25 Thread Robin Becker
Nathan Harmston wrote:
>> > https://networkx.lanl.gov/
..

I got it back just once, but when I clicked again I see this



RuntimeErrorPython 2.4.4c1: /usr/bin/python
Sat Nov 25 16:21:16 2006

A problem occurred in a Python script. Here is the sequence of function 
calls leading up to the error, in the order they occurred.
  /build/bdist.linux-x86_64/egg/tracrst/macro.py in 
render_macro(self=, req=, 
self.__dict__ = {'this': }, 
parent_pool = , 
libsvn = , libsvn.core = 
, 
libsvn.core.application_pool = 

RuntimeError: instance.__dict__ not accessible in restricted mode
   args = ('instance.__dict__ not accessible in restricted mode',)


perhaps I'm seeing different apache processes or something
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Graph Data Structures

2006-11-25 Thread John Machin

Nathan Harmston wrote:
> Hi,
>
> The idea is that I m going to use it to build graphs for sequence
> alignment (at the moment), I read a discussion on the corebio
> (reimplementation of biopython) group about using intervals to
> represent sequence slices. The idea being that, my graph may contain
> millions of alignments and storing the sequence (the actual ATGC) is
> not required.
>
> class Node(object):
>  pass
>
> class Interval(Node):
> _id = "gene1"
>  _start = 50
> _end = 200
> _strand = 1

What is the point of subclassing Node if it's just a dummy?

>
> class Sequence(object):
> _sequence = "atgtcgtgagagagagttgtgag."
>
> So one interval on one sequence would align to another interval from
> another sequence, but I want changes I make to the interval to be
> reflected in the representation later. If I reverse complement it i
> want the interval to store this information but the Sequence only
> shows this later on when I call use it calling repr or str.
>
> Do you get what I mean.

Only vaguely. You use several terms which appear to be from your trade
jargon as they are not understandable when interpreted in either the
context of Python-speak or ordinary English e.g. "sequence",
"alignment", "ATGC", "reverse complement", "interval".

Two options:
(a) communicate understandably
(b) wait till your wontoks are back from holidays.

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


Re: Dynamic function execution

2006-11-25 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Fredrik Lundh  <[EMAIL PROTECTED]> wrote:
>Andy Wu wrote:
>
>> def func(seconds = None, minutes = None, hours = None):
>> ...
>> 
>> In my program I can get a string object('seconds', 'minutes', 'hours')
>> to specify which parameter to use, the problem is I don't know how to
>> call the function.
>> 
>> Say I have a string 'minutes' and a integer 30, now I need to call the
>> func this way: func(minutes = 30), how do I do this?
>
>func(**{"minutes": 30})
>
>
>

Now I'm confused:  what's the advantage of 

  def func(seconds = None, minutes = None, hours = None):
  print seconds
  print minutes
  print hours

  func(**{"minutes": 30})

over

  def func(seconds = None, minutes = None, hours = None):
  print seconds
  print minutes
  print hours

  func(minutes = 30)

?  Or am I missing the point that a better example of what 
Mr. Wu really wants is

  def func(seconds = None, minutes = None, hours = None):
  print seconds
  print minutes
  print hours

  dimension = "minutes"
  func(**{dimension: 30})

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


Re: case insensitive dictionary

2006-11-25 Thread Rob Williscroft
John Henry wrote in news:1164494606.514366.124810
@l39g2000cwd.googlegroups.com in comp.lang.python:

> I believe the standard dictionary should be amened to allow the use of
> case insensitive keys - as an option.  

class idict( dict ):

  class __istr( str ):

def __eq__( self, other ):
  return self.lower() == other.lower()

def __hash__( self ):
  return self.lower().__hash__()

  def __setitem__( self, k, v ):
dict.__setitem__( self, idict.__istr( k ), v )

d = idict( a = 1, b = 2 )
d['A'] = 3

print d

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: case insensitive dictionary

2006-11-25 Thread vbgunz

John Henry wrote:
> I believe the standard dictionary should be amened to allow the use of
> case insensitive keys - as an option.  I found some work done by others
> to do that at:
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/283455
>
> but the problem with that approach is that they lowercase the keys
> immediately when you create the dictionary and so the true identity of
> the key is lost.
>
> Of course, I can subclass it and save a copy of the "real" key but
> that's kind of messcy.
>
> In other words:
>
> If I have:
>
> pets=caselessDict()
>
> pets["Cat"] = 3
> pets["Dog"] = 2
>
> I would like to see:
>
>pets["cat"]  prints 3
>pets["DOG"] prints 2
>
> but
>
>print pets.keys()
>
> should print:
>
> "Cat", "Dog"
>
> not:
>
> "cat", "dog"

You can try to title-case the list returned with keys() like so:
print [x.title() for x in pets.keys()]

Not a perfect solution but you get what you want... just an idea :)

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


Re: my small hashlib - using pythons hash-functions

2006-11-25 Thread Robert Kern
Fredrik Lundh wrote:
> Mathias Panzenboeck wrote:
> 
>> But the question is: *IS* this derived work? I mean, it's not copied code.
>> It's the same hashing-logic, which I learned by watching pythons code.
> 
> given that it's only a few lines of code, and there's hardly any other 
> way to write those lines if you want to implement the same algorithm, 
> I'd say it falls under "fair use".  crediting the Python developers in 
> the source code should be good enough.

If you'll forgive my pedantry, that's not "fair use," but simply the use of
material that cannot be copyrighted by itself (in many jursidictions, at least)
because it is so short, obvious, non-creative, etc.

A good overview of fair use is here:

http://fairuse.stanford.edu/Copyright_and_Fair_Use_Overview/chapter9/index.html

IANAL. TINLA.

-- 
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: case insensitive dictionary

2006-11-25 Thread tomasz . kulawik . groups . 1
John Henry napisal(a):
> I believe the standard dictionary should be amened to allow the use of
> case insensitive keys - as an option.  I found some work done by others
> to do that at:
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/283455
>
> but the problem with that approach is that they lowercase the keys
> immediately when you create the dictionary and so the true identity of
> the key is lost.
>
> Of course, I can subclass it and save a copy of the "real" key but
> that's kind of messcy.
>
> In other words:
>
> If I have:
>
> pets=caselessDict()
>
> pets["Cat"] = 3
> pets["Dog"] = 2
>
> I would like to see:
>
>pets["cat"]  prints 3
>pets["DOG"] prints 2
>
> but
>
>print pets.keys()
>
> should print:
>
> "Cat", "Dog"
>
> not:
>
> "cat", "dog"

How about:

>>> class Dictstr(str):
... def __hash__(self):
... return str.__hash__(self.lower())
... def __eq__(self,other):
... return self.lower()==other.lower()
...
>>> class dictt(dict):
... def __setitem__(self, key, value):
... if isinstance(key, str):
... dict.__setitem__(self, Dictstr(key), value)
... else:
... dict.__setitem__(self, key, value)
... def __getitem__(self, key):
... if isinstance(key, str):
... return dict.__getitem__(self, Dictstr(key))
... else:
... return dict.__getitem__(self, key)
...
>>> d=dictt()
>>> d[1]=1
>>> d['Cat']='Cat'
>>> d['Dog']='Dog'
>>> d['dOg']
'Dog'
>>> d.keys()
[1, 'Dog', 'Cat']

Note that you would need to redefine also __init__, __contains__ and
other methods.

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


Re: Graph Data Structures

2006-11-25 Thread Nathan Harmston
Hi,

It seems that by just going through the problem writing out a better
explanation for the reply I have figured out a solution and the
problem isnt as difficult as I thought it would be.

What is a wontok?

Thanks

Nathan

PS --> the start of my reply:

class Interval(object):
 _id = "gene1"
  _start = 50
 _end = 200
 _strand = 1

class Sequence(object):
_sequence = "atgtcgtgagagagagttgtgag."

> Only vaguely. You use several terms which appear to be from your trade
> jargon

Sequence is a string made from a restricted alphabet (A,T,G,C...).
Sequences can be aligned:  1 ATGCTGCAT
  2 TAGCTGTTA
  ---
 25

I m trying to represent this as a graph Interval(id=1, start=2, end=6,
strand=1) ---edge--Interval(id=2, start=2, end=6, strand=1)

The problem is I was planning on storing the sequences in a dictionary
{id:Seq}, however each dictionary would represent a different source
of sequences. File1, File2... (
STORE THE SOURCES AS A DICT AND HAVE SOURCE IN INTERVAL ASWELL
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About alternatives to Matlab

2006-11-25 Thread sturlamolden

Phil Schmidt wrote:

> Thanks for that list. I'm currently in the process of getting quotes
> for a bunch of Matlab tools for hardware-in-the-loop simulation. Big
> bucks.

Yup, and better spent elsewhere...


> I'd love to use Python, but I'm not comfortable with the hardware side
> of that. I'm certain that most, if not all data acquisition hardware
> comes with DLL drivers, which I could interface with using ctypes. I'm
> concerned though about spending more time messing around with the
> hardware interface than it's worth.

Usually you have to mess equally much with Matlab, writing CMEX
interfaces between the DLLs and Matlab. And afterwards you get the
headache of Matlab's single-threaded environment and horrible
pass-by-value sematics.


> Do you have any experience with this side of the Matlab replacement
> question? How about anyone else? Any recommendations?

If you are afraid of doing some C coding or using ctypes, I'd say go
for LabView. When it comes to data acquisition, LabView is far superior
to Matlab. And data acquisition hardware usually comes with LabView
drivers ready to run. LabView can also compile programs that you can
run on real-time OS'es and common DSP chips, so you will not need to
port your code to these targets if you need hard real-time constraints
in your system.

First find out what drivers or APIs are supplied with the hardware.
Then do the decision of which language to use - including Python,
Matlab, LabView, Java, C# .NET, C or C++. I would in any case get a
quote for LabView as well, i does not cost you anything just to obtain
the quote. Generally, development time is far more expensive than
licenses, even with the ultra-expensive Matlab and LabView software.
Using Python just for the sake of using Python is silly.

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


Re: Graph Data Structures

2006-11-25 Thread John Machin

Nathan Harmston wrote:
> Hi,
>
> It seems that by just going through the problem writing out a better
> explanation for the reply I have figured out a solution and the
> problem isnt as difficult as I thought it would be.

Often happens.

>
> What is a wontok?

It's Melanesian Pidgin (from the English "one talk") meaning a person
who speaks the same language as you, a member of your clan, ... the
context being that [at least in Papua New Guinea] there are relatively
many languages each with relatively not many speakers :-)

>
> Thanks
>
> Nathan
>
> PS --> the start of my reply:
>
> class Interval(object):
>  _id = "gene1"
>   _start = 50
>  _end = 200
>  _strand = 1
>
> class Sequence(object):
> _sequence = "atgtcgtgagagagagttgtgag."
>
> > Only vaguely. You use several terms which appear to be from your trade
> > jargon
>
> Sequence is a string made from a restricted alphabet (A,T,G,C...).
> Sequences can be aligned:  1 ATGCTGCAT
>   2 TAGCTGTTA
>   ---
>  25

I'm sure they can be, but appearances can be deceptive when you mix
tabs and spaces -- or whatever caused the above 4 lines to be not
vertically aligned but staggered diagonally like a flight of ducks
heading equatorwards for winter.

Sometimes a line of code (e.g. str1[2:6] == str2[2:6]) is worth a
thousand pictures :-)

>
> I m trying to represent this as a graph Interval(id=1, start=2, end=6,
> strand=1) ---edge--Interval(id=2, start=2, end=6, strand=1)
>
> The problem is I was planning on storing the sequences in a dictionary
> {id:Seq}, however each dictionary would represent a different source
> of sequences. File1, File2... (
> STORE THE SOURCES AS A DICT

Mapping what keys to what values?

> AND HAVE SOURCE IN INTERVAL ASWELL

So you had a data modelling problem. These are often better solved as a
separate step before you think about implementation details like
dictionaries.

Good luck with your project.

Cheers,
John

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


Re: Dynamic function execution

2006-11-25 Thread John Machin
Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>,
> Fredrik Lundh  <[EMAIL PROTECTED]> wrote:
> >Andy Wu wrote:
> >
> >> def func(seconds = None, minutes = None, hours = None):
> >> ...
> >>
> >> In my program I can get a string object('seconds', 'minutes', 'hours')
> >> to specify which parameter to use, the problem is I don't know how to
> >> call the function.
> >>
> >> Say I have a string 'minutes' and a integer 30, now I need to call the
> >> func this way: func(minutes = 30), how do I do this?
> >
> >func(**{"minutes": 30})
> >
> >
> >
>
> Now I'm confused:  what's the advantage of
>
>   def func(seconds = None, minutes = None, hours = None):
>   print seconds
>   print minutes
>   print hours
>
>   func(**{"minutes": 30})
>
> over
>
>   def func(seconds = None, minutes = None, hours = None):
>   print seconds
>   print minutes
>   print hours
>
>   func(minutes = 30)
>
> ?  Or am I missing the point that a better example of what
> Mr. Wu really wants is
>
>   def func(seconds = None, minutes = None, hours = None):
>   print seconds
>   print minutes
>   print hours
>
>   dimension = "minutes"
>   func(**{dimension: 30})
>
> ?

Hi Cameron,

You're on the right track. A better example would have the last two
lines replaced by:

# Simulate obtaining data
argument_name = "minutes"
argument_value = 30
# Then ...
func(**{argument_name: argument_value})

:-)

Cheers,
John

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


Re: Local variables persist in functions?

2006-11-25 Thread Scott David Daniels
[EMAIL PROTECTED] wrote:
> I'm a bit baffled.  Here is a bit of fairly straightforward code:
> 
> def _chunkify( l, chunkSize, _curList = list() ): ... 
> _chunkify simply breaks a sequence into a sequence of smaller lists of
> size <= chunkSize.  The first call works fine, but if I call it
> multiple times, weirdness happens.
> 
> Considering the default value of _curList, these statements should be
> identical.  Any pointers?  Did I miss something in the python reference
> manual?  (running 2.4.3, fyi)

You've already got the real answer.  How about considering iterators,
since I presume you are chunking to help some kind of processing.:

 def chunky(src, size):
 '''Produce a (possibly long source) in size-chunks or less.'''
 assert size > 0
 for start in range(0, len(src), size):
 yield src[start : start + size]

 def chunkify(alist, size, _curList=None):
 if _curList is None:
 return list(chunky(alist, size))
 _curList.extend(list(chunky(alist, size)))
 return _curList

I suspect most often you can use chunky directly:
 for chunk in chunky(somedata, size):
 ...

 for size in range(1, 30):
 print size, list(chunky('abcdefghijklmnopqrstuvwxyz', size))


--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a -very- case sensitive search

2006-11-25 Thread John Machin

Dustan wrote:

>
> If you're using google groups, it for some reason thought my example
> code was 'quoted text', which it certainly isn't, seeing as it's not
> found anywhere prior to my message.

Sigh. And if we're NOT using Google Groups, it still thinks so ...

The reason is that your "example code" was in fact a screen-dump of a
Python interactive session, in which lines are preceded by ">>>" which
Google Groups simplistically thinks is quoted text from a previous
message.

HTH,
John

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


Re: problem with global variable in a module

2006-11-25 Thread hollowspook
Thanks for all the replys.


"Diez B. Roggisch 写道:
"
> hollowspook schrieb:
> > def aa():
> > global b
> > b=b+1
> > print b
> >
> > b=1
> > aa()
> >
> > The above code runs well in python shell.
> >
> > However I  have a problem as follows.
> >
> > new a file named test.py
> > 
> >
> > def aa():
> > global b
> > b=b+1
> > print b
> > -
> >
> > Then in python shell,
> >
> > from test import *
> > b=1
> > aa()
> >
> > The error message is :
> > Traceback (most recent call last):
> >   File "", line 1, in ?
> >   File "test.py", line 3, in aa
> > b=b+1
> > NameError: global name 'b' is not defined
> >
> > Why this happens? Please do me a favor.
>
> Because python does not know "real" globals - globals are always only
> global on a module level. Now using the "from module import *"-syntax
> asks for trouble. Because your global b above is global to the
> __main__-module, not to the module test. But the aa-function expects it
> to live in tests.
>
> To make your example work, do it as this:
>
> import test
>
> test.b = 1
> test.aa()
>
>
> See
> http://effbot.org/pyfaq/tutor-whats-the-difference-between-import-foo-and-from-foo-import.htm
> 
> Diez

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

Re: Return float problem.

2006-11-25 Thread YunBin Lee
John, Thanks for your help!

> Did you notice that the garbage is a whole number? Why? Because you
> have been (more or less) plucking ints out of some arbitrary place on
> the stack, floating them, and printing them.

I don't know how to solve it (or the right way), could you give me some
examples?

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


Re: Python 2.5 idle and print command How do I suppress a line feed?

2006-11-25 Thread Steve
See
http://www.ferg.org/projects/python_gotchas.html#contents_item_4

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


who is maintainer of xml-rpc module?

2006-11-25 Thread Mark Harrison
So, I've made a couple of small but useful additions to
the xml-rpc package.  Is there an assigned maintainer
of the package I should communicate with?

I've got the server side running under apache/mod_python, which
is a bit more industrial strength than the simple xmlrpc server,
and a patch for 64 bit int values.

I'd like to get these into wider circulation if possible...
what's the best way to do this?

Many TIA!
Mark

-- 
Mark Harrison
Pixar Animation Studios
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Return float problem.

2006-11-25 Thread John Machin
YunBin Lee wrote:
> John, Thanks for your help!
>
> > Did you notice that the garbage is a whole number? Why? Because you
> > have been (more or less) plucking ints out of some arbitrary place on
> > the stack, floating them, and printing them.
>
> I don't know how to solve it (or the right way), could you give me some
> examples?

Is this homework?

Examples of what? Do you want me to write your code for you?

Examples? The Internet is loaded with *working* example C code split
over several .c and .h files.

How much C have you done? In other words, what is your level of
expertise? I would have thought that function prototypes and include
files would be something you would have already mastered before you
tried to write a Python extension wrapper for some C code.

You have been given 3 big fat hints.  If you didn't understand any of
them, after reference to your C textbook and Googling, please feel free
to ask again.

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


Re: Return float problem.

2006-11-25 Thread YunBin Lee
Hello john.
I solve it by add '#include "example.h"' into wrap.c, recompiled all
c-sources, and it works on the right way!

Content of example.h:
== example.h =
#ifndef __EXAMPLE_H__
#define __EXAMPLE_H__

double fact(double n);

#endif
== end example.h =

Anyway, Thanks for you answer again!

On 11月26日, 上午11时12分, "YunBin Lee" <[EMAIL PROTECTED]>
wrote:
> John, Thanks for your help!
>
> > Did you notice that the garbage is a whole number? Why? Because you
> > have been (more or less) plucking ints out of some arbitrary place on
> > the stack, floating them, and printing them.I don't know how to solve it 
> > (or the right way), could you give me some
> examples?

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

Re: combining the path and fileinput modules SOLVED

2006-11-25 Thread wo_shi_big_stomach
Dennis Lee Bieber wrote:
> On Sat, 25 Nov 2006 07:58:26 -0800, wo_shi_big_stomach
> <[EMAIL PROTECTED]> declaimed the following in
> comp.lang.python:
> 
>>   File "p2.py", line 23, in ?
>> for line in fileinput.input(f,):
>>   File
>> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/fileinput.py",
>> line 231, in next
>> line = self.readline()
>>   File
>> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/fileinput.py",
>> line 320, in readline
>> self._file = open(self._filename, "r")
>>
>> This looks similar to before -- fileinput.input() still isn't operating
>> on the input.
>>
>   And where is the actual exception message line -- the one with the
> error code/description.
>  
> 
>> dir = path('/home/wsbs/Maildir')
>> #for f in dir.walkfiles('*'):
>> for f in filter(os.path.isfile, dir.walkfiles('*')):
> 
>   If I understand the documentation of fileinput, you shouldn't even
> need this output loop; fileinput is designed to expect a list of files
> (that it works with a single file seems an afterthought)

Yes, thanks. This is the key point.

Feeding fileinput.input() a list rather than a single file (or whatever
it's called in Python) got my program working. Thanks!

> 
>>  for line in fileinput.input(f,):
>   for line in fileinput.input(filter(os.path.isfile, 
>   dir.walkfiles("*")),
>   inplace=1):
> 
> should handle all the files... 

Indeed it does -- too many times.

Sorry, but this (and the program you provided) iterate over the entire
list N times, where N is the number of files, rather than doing one
iteration on each file.

For instance, using your program with inplace editing and a ".bak" file
extension for the originals, I ended up with filenames like
name.bak.bak.bak.bak.bak in a directory with five files in it.

I don't have this third party path
> module, so the directory tree walking isn't active, but...

The path module:

http://www.jorendorff.com/articles/python/path/

is a *lot* cleaner than os.path; see the examples at that URL.

Thanks for the great tip about fileinput.input(), and thanks to all who
answered my query. I've pasted the working code below.

/wsbs

import fileinput
import os
import re
import string
import sys
from path import path

# p2.py - fix broken SMTP headers in email files
#
# recurses from dir and searches all subdirs
# for each file, evaluates whether 1st line starts with "From "
# for each match, program deletes line

# recurse dirs
dir = path('/home/wsbs/Maildir')
g = dir.walkfiles('*')
for line in fileinput.input(g, inplace=1, backup='.bak'):
# just print 2nd and subsequent lines
if not fileinput.isfirstline():
print line.rstrip('\n')
# check first line only
elif fileinput.isfirstline():
if not re.search('^From ',line):
print line.rstrip('\n')
fileinput.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Graph Data Structures

2006-11-25 Thread Pieter Swart
Nathan Harmston wrote:

> Currently I am working on a generic graph library  so I can do various
> graph based analysis for various projects I have ideas for. Currently
> I am implementing Graph as a wrapper around a dictionary. Currently my
> implementation works like this:
>
> t = Graph()
> n1 = Node("Node1")
> n2 = Node("Test2")
> edge1 = Edge("Test3")
> t += n1{ n1:{}}
> t[n1][n2] = edge1{ n1:{n2:edge1}
>
> However this isnt actually ending up with the structure I want. I want
> it to finally end up as ..{ n1:{n2:edge1}, n2:{}}. Is
> there anyway I can do this simply

Nathan

By now you probably discovered that the networkx package can handle
this.
If I have this right, you want to create a digraph with
a directed edge from "Node1" to "Node2" and this edge
has the string "Test3" attached to it. In networkx, this is exacty what
the  XDiGraph class was designed to do. Here DiGraph means
directed graph and the X means you are allowed to add (any)
data to the edge,for example:

>>> import networkx as nx
>>> t = nx.XDiGraph()
>>> t.add_edge( "Node1", "Node2", "Test3")


> Also I am looking at having a large graph and was wondering if anyone
> knew of anyway I could reduce the memory requirements of this
> structure and improve the speed of queries on it. I m thinking writing
> a C extension for itis this a good idea and where would I start?
> Or does Python have some kind of transparent memory access module I
> can implement.
>

Networkx was designed so that you can hook your own
C extension in. However, making it ispeed or memory efficient
is quite application dependent. I am still not clear as to exactly what

class of algorithms you want to implement via a string-interval
representation, and whether you demand exact alignment or whether
missing/incorrect data etc. is allowed as part of the alignment
problem.

HTH
Pieter Swart

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


Re: About alternatives to Matlab

2006-11-25 Thread Phil Schmidt
sturlamolden wrote:

> Using Python just for the sake of using Python is silly.

Well, that kind of gets right to my point. Does the "added" effort with
Python to interface with data acquisition hardware really result in
less productivity? I am very familiar with Matlab, Labview, and Python,
and frankly, Python is the most productive and powerful programming
language of the three. But it's the hardware compatibility thing that
concerns me with Python.

It seems the answers are hard to come by on this issue. I sure would be
willing to give it a try, except that I'm getting paid to get a job
done, not to tinker around with Python and DAQ hardware. But if
tinkering around could save my project money on commercial software,
and still get it done on schedule, it would be a big win. I just don't
have confidence that it would.

Phil

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


Re: About alternatives to Matlab

2006-11-25 Thread Robert Kern
Phil Schmidt wrote:
> sturlamolden wrote:
> 
>> Using Python just for the sake of using Python is silly.
> 
> Well, that kind of gets right to my point. Does the "added" effort with
> Python to interface with data acquisition hardware really result in
> less productivity? I am very familiar with Matlab, Labview, and Python,
> and frankly, Python is the most productive and powerful programming
> language of the three. But it's the hardware compatibility thing that
> concerns me with Python.

Without knowing the hardware that you want to use, it's quite difficult for us
to tell you anything useful. Most likely, you're simply going to have to sit
down with a list of the hardware that you want to use, the existing solutions
for interfacing with that hardware (e.g. already written MATLAB, LabView, or
Python extension modules for that hardware), and their costs. You're going to
have to weigh those costs against the cost of using ctypes or something similar
to wrap the raw DLLs if a Python extension module isn't available.

We might be able to help you locate the already-existing Python wrappers for
your hardware, but the rest are judgement calls that only you can make. To make
an accurate judgement, you will probably need to have a little bit of experience
trying to wrap one such raw DLL. If you can't afford the time to do that one
experiment, then you probably have your answer.

-- 
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: screen output problem

2006-11-25 Thread Calvin Spealman
On 25 Nov 2006 15:27:26 -0800, Ritesh Raj Sarraf <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have, for very long, been trying to find a consistent solution (which
> could work across major python platforms - Linux, Windows, Mac OS X)
> for the following problem.
>
> I have a function which downloads files from the web. I've made the
> function threaded. I'm trying to implement a progress bar for it which
> could work across all the platforms.
>
> The problem is that when the progress bar is displayed, all the threads
> overwrite the progress bar.
>
> I've thought of using curses but AFAIK curses is not available for
> Windows.
>
> Is there a generic way to accomplish the following:
>
> progress = "[===]\n[===]"
> for x in range(5):
> sys.stdout.write(progress + "\r")
>
> Basically, I want a way through which I want to display data on two
> lines and make sure that "\r" overwrites the two lines without putting
> a newline making sure that whatever library it uses is available across
> all major Python platforms.
>
> Thanks,
> Ritesh
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Take a look at this:
http://cheeseshop.python.org/pypi/progressbar

-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list