Re: Writing a Carriage Return in Unicode

2009-11-21 Thread Gregory Ewing

Steve Howell wrote:

If you are
going to couple character sets to their legacy physical
implementations, you should also have a special extra character to dot
your i's and cross your t's.


No, no, no. For that device you need to output a series
of motion vectors for the scribing point. Plus control
characters for "dip nib" and "apply blotter", and
possibly also "pluck goose" for when the print head
becomes worn.

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


Re: Go versus Brand X

2009-11-21 Thread Gregory Ewing

On Nov 21, 11:20 am, John Roth  wrote:

>

Go is simply C with most (but not all) of the warts
removed and some more modern features added.


Syntax-wise, I find myself disappointed that they didn't
do as good a job of removing the warts as they could
have.

For example, there are good reasons for putting types
after variable names, but just swapping them around doesn't
quite work. C's "int x" reads well because it mimics similar
constructs in English which qualify a noun with another
noun, e.g. "President Obama". If you say "Obama President",
it doesn't sound right. You need some extra punctuation
to make it meaningful: "Obama, President".

Similarly, I think just a little bit more punctuation
is needed to make name-first declarations readable. For
my money, it's hard to beat the Wirth style:

  func foo(x: int; y: char): float

However, Go's designers seem to favour using the absolute
minimum number of characters they can get away with.

Although if they *really* wanted that, they would have
dropped most of the semicolons and used indentation-based
block structure instead of curly braces. I would have
forgiven them several other sins if they'd done that. :-)

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


python setup.py build 32-bits on x86_64 machine

2009-11-21 Thread Sérgio Monteiro Basto
Hi,
I am in x86_64 arch , but I need 
compile things on 32 bits.
python setup.py build

Can't change the fact that distutils creates x86_64 
directories:
gcc -pthread -shared build/temp.linux-x86_64-2.3/ 

Also if I try with a python compile in 32bits and installed 
in system .

how I force distutils build to 32-bits ? 

Thanks in advance, 

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


Re: parallel class structures for AST-based objects

2009-11-21 Thread Gregory Ewing

Steve Howell wrote:


My objection to the interface you describe is that Node defines the
type of operations that can be done to it by third-party code, which
is something that I cannot predict


I think you have the right idea with a mapping from node
classes to implementations of operations, but your
intermediate classes SumPrettyPrintNode etc. are not
necessary. Just put functions implementing the operations
directly into the mapping.

Another thing is that the mappings should be somewhere
global that can be extended, perhaps through a registration
interface. Putting the mapping dicts inside the node classes
doesn't gain you anything over simply using methods. All
you've done is reimplement method dispatch.

A third thing is that instead of just looking up the node
class in the mapping, you may want to walk up the MRO and
try each of the base classes until you find a match. That
way, nodes will effectively inherit implementations from
their base classes for any operations that they don't
explicitly implement.

This inheritance behaviour becomes important if you have
two developers A and B, where A adds new classes and B
adds new operations. If A and B don't talk to each other,
you necessarily end up with gaps in the matrix: A's classes
won't have implementations for B's operations.

The best you can hope for is that the missing operations
will somehow fall back gracefully on default implementations.
Inheritance allows this to be achieved: if A derives all
his classes from existing node classes, and B provides
default implementations of all his operations for the root
Node class, then some implementation will always be found
for every class/operation combination.

Now, there's actually a very easy way of implementing all
this. Your registration interface could simply be

  def register_operation(klass, operation_name, function):
setattr(klass, operation_name, function)

In other words, monkey-patch the classes to add the new
functions directly as methods. Since it's so simple, you
could even do away with the registration function altogether
and just have developers insert methods directly into the
classes.

Some people might consider this an ugly hack, but the
end result is almost exactly the same, it's very simple,
and it's very efficient, making use of Python's existing
method dispatch machinery instead of reinventing it
yourself.

One reason you might want to keep the registration function,
even if all it's doing is modifying the classes, is to
make it easier to find where operations are being defined,
by searching for calls to register_operation().

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


Re: Imitating "tail -f"

2009-11-21 Thread Matt Nordhoff
Jason Sewall wrote:
> FWIW, GNU tail on Linux uses inotify for tail -f:
> 
> http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c
> 
> The wikipedia page for inotify lists several python bindings:
> 
> http://en.wikipedia.org/wiki/Inotify
> 
> Not much help for non-Linux users, but there it is. Too bad, because
> inotify is pretty cool.
> 
> Jason

Some other operating systems have similar facilities, e.g. FSEvents on OS X.
-- 
Matt Nordhoff
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: plotting arrow in python

2009-11-21 Thread Gregory Ewing

rudra wrote:


0.0 0.0 0.1
0.0 0.1 0.1
0.1 0.0 0.5

like that! the first two column are coordinate and 3rd one is
magnitude of moment (say: x y,m)!! so what i want to do is draw an
arrow of magnitude(m) in the position (x,y).


There seems to be some information missing there.
How do you know what direction to draw the arrow in?

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


Re: Too Many Values To Unpack

2009-11-21 Thread Steven D'Aprano
On Sat, 21 Nov 2009 21:06:08 -0800, Dennis Lee Bieber wrote:

>   I apparently thought "for ... in dictionary" would return (key,
> value) pairs, but it appears that it only returns the key itself -- and
> a single key can't be unpacked.
> 
>   Misleading error... too many /targets/ to unpack...

No, the error is fine.


>>> for x, y in {1:'a'}:
... pass
...
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unpack non-sequence
>>>
>>> for x, y in {'a':1}:
... pass
...
Traceback (most recent call last):
  File "", line 1, in 
ValueError: need more than 1 value to unpack
>>>
>>> for x, y in {'parrot':1}:
... pass
...
Traceback (most recent call last):
  File "", line 1, in 
ValueError: too many values to unpack


Strings are iterable, and so unpack into individual characters.


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


Re: Too Many Values To Unpack

2009-11-21 Thread Gregory Ewing

Dennis Lee Bieber wrote:


I apparently thought "for ... in dictionary" would return (key,
value) pairs, but it appears that it only returns the key itself -- and
a single key can't be unpacked.

Misleading error... too many /targets/ to unpack...


My guess is that the keys are strings, which means it's
unpacking them into characters, in which case a key of
length 3 or more will produce that message.

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


Re: Imitating "tail -f"

2009-11-21 Thread Jason Sewall
FWIW, GNU tail on Linux uses inotify for tail -f:

http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/tail.c

The wikipedia page for inotify lists several python bindings:

http://en.wikipedia.org/wiki/Inotify

Not much help for non-Linux users, but there it is. Too bad, because inotify
is pretty cool.

Jason

On Nov 21, 2009 11:11 PM,  wrote:

On 02:43 am, ivo...@gmail.com wrote: > > I'm trying to simply imitate what
"tail -f" does, i.e. read...
select(), poll(), epoll, etc. all have the problem where they don't support
files (in the thing-on-a-filesystem sense) at all.  They just indicate the
descriptor is readable or writeable all the time, regardless.

"tail -f" is implemented by sleeping a little bit and then reading to see if
there's anything new.

Jean-Paul

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


Re: Imitating "tail -f"

2009-11-21 Thread exarkun

On 02:43 am, ivo...@gmail.com wrote:
I'm trying to simply imitate what "tail -f" does, i.e. read a file, 
wait

until it's appended to and process the new data, but apparently I'm
missing something.

The code is:

54 f = file(filename, "r", 1)
55 f.seek(-1000, os.SEEK_END)
56 ff = fcntl.fcntl(f.fileno(), fcntl.F_GETFL)
57 fcntl.fcntl(f.fileno(), fcntl.F_SETFL, ff | os.O_NONBLOCK)
58
59 pe = select.poll()
60 pe.register(f)
61 while True:
62 print repr(f.read())
63 print pe.poll(1000)

The problem is: poll() always returns that the fd is ready (without
waiting), but read() always returns an empty string. Actually, it
doesn't matter if I turn O_NDELAY on or off. select() does the same.

Any advice?


select(), poll(), epoll, etc. all have the problem where they don't 
support files (in the thing-on-a-filesystem sense) at all.  They just 
indicate the descriptor is readable or writeable all the time, 
regardless.


"tail -f" is implemented by sleeping a little bit and then reading to 
see if there's anything new.


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


Re: How do I create a vanilla object in C?

2009-11-21 Thread Carl Banks
On Nov 21, 12:49 pm, rnich...@mightyheave.com wrote:
> I need to create a vanilla object in C, something I can do
> PyObject_SetAttr on.  Obviously, I do something somewhat like this every
> time I create a minimal python class.  I need to know how to do this in C
> though.


First of all, if you don't need to share this object with any Python
code, then I'd suggest you just use a dict (create with PyDict_New).

If you do need to share it with Python, one thing to consider is
whether it isn't easier to create the object in Python and pass it to
the C code.

If these suggestions aren't suitable, then you'll have to create a new
vanilla type, then create an instance of that type.  Unfortunately
it's not too convenient from C.  It's easy enough to define types and
C (see the C-API documentation), but in order to use PyObject_SetAttr
on it you'll have to make sure the type has a dictionary, so you'd
have to set the tp_dictoffset member to the offset of your dict in the
Python structure.

Another thing you can do is to call type directly (as you can do in
Python) with the name, bases, dict, as in the following example (error
checking and reference counting omitted):

name = PyString_FromString("vanilla");
bases = PyTuple_New(0);
dict = PyDict_New();
vanilla_type = PyObject_CallObject(
&PyType_Type,name,bases,dict,0);

Then call the vanilla type (however you create it) to get a vanilla
object:

vanilla_object = PyObject_CallObject(vanilla_type,0);


Definitely not the most straightforward thing to do from C.


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


Re: Go versus Brand X

2009-11-21 Thread Mensanator
On Nov 21, 6:11 pm, Steve Howell  wrote:
> On Nov 21, 11:20 am, John Roth  wrote:
>
>
>
>
>
> > On Nov 21, 8:40 am, Duncan Booth  wrote:
>
> > > a...@pythoncraft.com (Aahz) wrote:
> > > > Comparing Go to another computer language -- do you recognize it?
>
> > > >http://www.cowlark.com/2009-11-15-go/
>
> > > Yes, spotted it at the first 'fi'.
>
> > This isn't the first time anyone has criticized Go. The interesting,
> > and somewhat sad, thing is that the entire mess can be explained
> > very easily by looking at the beginning of the language design
> > FAQ on the Go web site. See if you recognize the names of the
> > principle people who designed it.
>
> > Yep. Go is simply C with most (but not all) of the warts
> > removed and some more modern features added. Brought to you
> > by the same people who brought you C and Unix all those years ago.
> > The use of the Plan 9 toolchain is not a coincidence.
>
> The assertion that Go is simply C with warts removed and modern
> features added is not surprising.
>
> If you read the Go FAQ, you will see that there is no claim anywhere
> that they are trying to solve the problem that 40 years of language
> development since Algol has not produced super-sexy quantum leaps of
> improvement.  Instead, they are trying to solve the problem that in
> the last ten years, there haven not seen ANY improvement in systems
> programming languages ("No major systems language has emerged in over
> a decade").  The critics of Go probably fall into four categories:
>
>   1) Some do not understand the goals of the Go project itself, so
> they are criticizing Go for not solving problems that were never in
> Go's bailiwick to begin with.
>   2) Some believe that Go does not deliver on its goal to modernize
> systems programming languages.
>   3) Some do not accept the premise that there has been no progress
> outside of Go in the last ten years with regards to systems
> programming languages, and they are wondering why Google invented Go
> instead of embracing other technologies.
>   4) Some people do not even believe that the problem is important--do
> we actually need a modern systems programming language, or do we just
> need modern programming languages to perform well under all
> circumstances, or at least be adaptable?
>
> My list probably isn't even nearly exhaustive.

Like those who think Python programmers would be interedted in
Go because it has an import statement.
-- 
http://mail.python.org/mailman/listinfo/python-list


Imitating "tail -f"

2009-11-21 Thread Ivan Voras
I'm trying to simply imitate what "tail -f" does, i.e. read a file, wait
until it's appended to and process the new data, but apparently I'm
missing something.

The code is:

 54 f = file(filename, "r", 1)
 55 f.seek(-1000, os.SEEK_END)
 56 ff = fcntl.fcntl(f.fileno(), fcntl.F_GETFL)
 57 fcntl.fcntl(f.fileno(), fcntl.F_SETFL, ff | os.O_NONBLOCK)
 58
 59 pe = select.poll()
 60 pe.register(f)
 61 while True:
 62 print repr(f.read())
 63 print pe.poll(1000)

The problem is: poll() always returns that the fd is ready (without
waiting), but read() always returns an empty string. Actually, it
doesn't matter if I turn O_NDELAY on or off. select() does the same.

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


Re: python bijection

2009-11-21 Thread Raymond Hettinger
On Nov 19, 3:24 pm, Joshua Bronson  wrote:
> I couldn't find a library providing a bijective map data structure
> (allowing for constant-time lookups by value) in the few minutes I
> looked, so I took a few more minutes to code one 
> up:http://bitbucket.org/jab/toys/src/tip/bijection.py
>
> Is this at all worth releasing? Comments and suggestions welcome.
>
> Josh

Hello Joshua,

I have a few design ideas and comments for you.

* The idea of using __call__ for looking-up inverse values was
inspired.  That is useable, clean, and easy to remember; however, as
discussed below, there are issues though with its actual use in real
code.

* Am not excited by the inverse iterators.  With just a regular
mapping you can write:

for a, b in m.items() ...   # consider either a or b be the
key and the other to be the value

  That meets all of the needs that would have been served by
iter_inverse_keys() or iter_inverse_values() or whatnot.  The mirrored
API doesn't really provide much in the way of value added.

* After exercising the API on a couple of samples, I'm worried that
almost any inverse-method based API makes it difficult to review code
while keeping straight the intended meaning of the forward and inverse
relationships.  Am thinking that it is simpler, faster, and clearer to
just use two dictionaries -- that approach lets the variable names
communicate the important info.  For example, the following code helps
keep the coder and code reviewer from conflating the forward and
inverse directions:

   myurl = ip2url[myip]
   myip = url2ip[myurl]

Contrast that with:

   myurl = site_bijection[myip]
   myip = site_bijection(myurl)

With the latter, it is darned difficult to detect accidental
conflation of brackets with parentheses.

* So, I'm thinking that code needing a bijection would be better-off
with two ordinary dicts, perhaps augmented by a couple of convenience
functions:

biject_add(site_bijection, ip=myip, url=myurl)# Create a
new pairing, raise ValueError if either key
  # maps to
more than one value (in violation of the
  # bijection
invariant: one-to-one and onto)

biject_remove(ip=myip)# Clear an
entry from both dicts
or
biject_remove(url=myurl)

Alternatively, another possible approach is to used use the class
generation approach (such as that used by named_tuple()) to generate a
custom bijection class with either attribute based or keyworded
accessors:

Attribute based accessors:

  site = Bijection('ip', 'url')
  site.url[myip] = myurl

  for ip, url in site.items() ...
  print site.ip[myurl]
  myurl = site.url.pop(myip)

Keyword accessors:

  site = Bijection('ip', 'url')
  site.set(ip=myip, url=myurl)
  myurl = site.get(ip=myip)
  myip = set.get(url=myurl)
  myurl = site.pop(ip=myip)
  site.del(ip=myip)
  site.del(url=myurl)


Hope these ideas help.  The ultimate success of the Bijection code
will depend on its clarity, simplicity, and speed.  Experiment with
various approaches to find-out which looks the best in real code.  It
cannot be error-prone or it is doomed.  Also, it should not introduce
much overhead processing or else people will avoid it.  The API should
be trivially simple so that people remember how to use it months after
seeing it for the first time.

Good luck and happy hunting,



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


Re: plotting arrow in python

2009-11-21 Thread r
On Nov 21, 7:36 pm, Lie Ryan  wrote:
(..snip..)
> If you want to avoid 3rd party modules, take a look at turtle and
> Tkinter in the standard library.

Just to add to Ryans words...
If you want to avoid 3rd party modules, take a look at turtle and the
Tkinter *Canvas* widget in the standard library. Here is an example.

#-- start code --#
try:
import Tkinter as tk
except ImportError:
import tkinter as tk #python 3+

app = tk.Tk()
canvas = tk.Canvas(app)
canvas.create_line(0,0, 50,50, arrow='last')
canvas.pack()
app.mainloop()
#-- end code --#

remove the try/except when you know which one to use. I just wanted to
make sure it ran out-the-box for you, have fun!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonpath

2009-11-21 Thread Dave Angel

Ray Holt wrote:

Is there a way to make python point to a different directory for modules. I
don't like to keep my modules in the program directory, but I can't figure
out from the shell how to get the program to look in another directory. I am
using XP Pro as an operating system and python2.6

  
There are a few standard places that Python already looks for module 
imports.  To see what they are on your system, you could simply look at 
sys.path.


import sys
for path in sys.path:
print path

In particular, you probably want to use the directory under appdata:

C:\Documents and Settings\\Application 
Data\Python\Python26\site-packages



where  is your user-name.

DaveA

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


Re: Writing a Carriage Return in Unicode

2009-11-21 Thread Steve Howell
On Nov 21, 12:12 am, Steven D'Aprano  wrote:
> On Thu, 19 Nov 2009 23:22:22 -0800, Scott David Daniels wrote:
>
> > If you've actually typed on a physical typewriter, you know that moving
> > the carriage back is a distinct operation from rolling the platen
> > forward;
>
> I haven't typed on a physical typewriter for nearly a quarter of a
> century.
>
> If you've typed on a physical typewriter, you'll know that to start a new
> page, you have to roll the platen forward until the page ejects, then
> move the typewriter guide forward to leave space, then feed a new piece
> of paper into the typewriter by hand, then roll the platen again until
> the page is under the guide, then push the guide back down again. That's
> FIVE distinct actions, and if you failed to do them, you would type but
> no letters would appear on the (non-existent) page. Perhaps we should
> specify that text files need a five-character sequence to specify a new
> page too?
>
> > both operations are accomplished when you push the carriage
> > back using the bar, but you know they are distinct.  Hell, MIT even had
> > "line starve" character that moved the cursor up (or rolled the platen
> > back).
> > 
>
> > Lots of people talk about "dos-mode files" and "windows files" as if
> > Microsoft got it wrong; it did not -- Unix made up a convenient fiction
> > and people went along with it. (And, yes, if Unix had been there first,
> > their convention was, in fact, better).
>
> This makes zero sense. If Microsoft "got it right", then why is the Unix
> convention "convenient" and "better"? Since we're not using teletype
> machines, I would say Microsoft is now using an *inconvenient* fiction.
>
> --
> Steven

It's been a long time since I have typed on a physical typewriter as
well, but I still vaguely remember all the crazy things I had to do to
get the tab key to produce a predictable indentation on the paper
output.

I agree with Steven that "\r\n" is completely insane.  If you are
going to couple character sets to their legacy physical
implementations, you should also have a special extra character to dot
your i's and cross your t's.  Apparently neither Unix or Microsoft got
that right.  I mean, think about it, dotting the i is a distinct
operation from creating the undotted "i." ;)

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


Re: plotting arrow in python

2009-11-21 Thread Lie Ryan

rudra wrote:

Dear friends,
I am very new in python. Actually, I think I will not do much python
then using it to plotting data. I have not done any "real" thing in
python, so plz be easy. Now , the problem
I have a data set:
0.0 0.0 0.1
0.0 0.1 0.1
0.1 0.0 0.5

like that! the first two column are coordinate and 3rd one is
magnitude of moment (say: x y,m)!! so what i want to do is draw an
arrow of magnitude(m) in the position (x,y).
I know how python read array, and how to draw an array(via
matplotlib)...but totally confused with this one.
can you people plz help?


If you want to stay with regular python distribution, take a look on 
pygame (http://www.pygame.org/ ).


If you want to avoid 3rd party modules, take a look at turtle and 
Tkinter in the standard library.

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


Re: parallel class structures for AST-based objects

2009-11-21 Thread Steve Howell
On Nov 21, 4:33 pm, Richard Thomas  wrote:
>
> This looks more structurally sound:
>
> class Node(object):
>    def eval(self):
>       raise NotImplementedError
>    def pprint(self):
>       raise NotImplementedError
>

My objection to the interface you describe is that Node defines the
type of operations that can be done to it by third-party code, which
is something that I cannot predict, and which (pscouples every
subclass of Node to eval() and pprint(), even though those subclasses
might not care about either operation.  They might be reimplementing
only one of those operations, or some completely different operation.

>
> class Sum(BinaryOperatorNode):
>    operator = lambda x, y: x + y
>
> class Product(BinaryOperatorNode):
>    operator = lambda x, y: x * y
>

I do like the notion of driving up Sum/Product abstractions like
"operator" into BinaryOperatorNode, but that is sort of an artifact of
my toy example, not my main design dilemma.

> I don't know what you're doing exactly but if all you need is to be
> able to parse and evaluate expressions then you can get very decent
> mileage out of overriding operators, to the extent that the whole
> thing you are trying to do could be a single class...
>
> class Expression(object):
>def __init__(self, func):
>   self.func = func
>def __call__(self, **context):
>   while isinstance(self, Expression):
>  self = self.func(context)
>   return self
>def __add__(self, other):
>   return Expression(lambda context: self.func(context) + other)
>def __mul__(self, other):
> [snipped]

It is my fault for muddying the conversation with a toy example that
evaluates arithmetic expressions.  My particular problem involves a
mini-language that describes how you want to descend Python data
structures.


> But maybe that's not what you need. No need to overengineer if it is
> though, keep it simple, simple is better than complex.


Yep!  I am trying to keep things simple, but my wish to extend is not
speculative at this point; it is real.  I have an expression syntax,
which I call pyDTL, that I want these operations on:

  * generate two different versions of Python code that expresses the
operation
  * eagerly evaluate the expression on some object
  * pretty-print the expression itself
  * use the expression as a prototype for stub objects to determine
what operations they allow
  * etc

All of those requirements create the need to somehow create new
objects or functions that correspond to the same AST.

I describe pyDTL here:

http://showellonprogramming.blogspot.com/2009/11/mini-ddl-for-python.html

Here is a simple example:

 echo '{.foo, .bar(){.spam, .eggs} }' | python dtl/parse.py
 dict(
 foo = obj.foo,
 bar = (lambda bar:
 dict(
 spam = bar.spam,
 eggs = bar.eggs,
 ))(obj.bar()),
 )


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


Re: parallel class structures for AST-based objects

2009-11-21 Thread Richard Thomas
On 22 Nov, 00:07, MRAB  wrote:
> Steve Howell wrote:
> > I have been writing some code that parses a mini-language, and I am
> > running into what I know is a pretty common design pattern problem,
> > but I am wondering the most Pythonic way to solve it.
>
> > Basically, I have a bunch of really simple classes that work together
> > to define an expression--in my oversimplified example code below,
> > those are Integer, Sum, and Product.
>
> > Then I want to write different modules that work with those expression
> > objects.  In my example, I have a parallel set of classes that enable
> > you to evaluate an expression, and another set of objects that enable
> > you to pretty-print the expression.
>
> > The below code works as intended so far (tested under 2.6), but before
> > I go too much further with this design, I want to get a sanity check
> > and some ideas on other ways to represent the interrelationships
> > within the code.  Basically, the issue here is that you have varying
> > behavior in two dimensions--a node right now is only a Product/Integer/
> > Sum so far, but I might want to introduce new concepts like
> > Difference, Quotient, etc.  And right now the only things that you can
> > do to expressions is eval() them and pprint() them, but you eventually
> > might want to operate on the expressions in new ways, including fairly
> > abstract operations that go beyond a simple walking of the tree.
>
> > Here is the code:
>
> >     ###
> >     # base classes just represents the expression itself, which
> >     # get created by a parser or unit tests
> >     # example usage is
> >     # expression = Product(Sum(Integer(5),Integer(2)), Integer(6))
> >     class Integer:
> >         def __init__(self, val):
> >             self.val = val
>
> >     class BinaryOp:
> >         def __init__(self, a,b):
> >             self.a = a
> >             self.b = b
>
> >     class Sum(BinaryOp):
> >         pass
>
> >     class Product(BinaryOp):
> >         pass
>
> >     
>
> >     class EvalNode:
> >         def __init__(self, node):
> >             self.node = node
>
> >         def evaluatechild(self, child):
> >             return EvalNode.factory(child).eval()
>
> >         @staticmethod
> >         def factory(child):
> >             mapper = {
> >                 'Sum': SumEvalNode,
> >                 'Product': ProductEvalNode,
> >                 'Integer': IntegerEvalNode
> >                 }
> >             return abstract_factory(child, mapper)
>
> >     class SumEvalNode(EvalNode):
> >         def eval(self):
> >             a = self.evaluatechild(self.node.a)
> >             b = self.evaluatechild(self.node.b)
> >             return a + b
>
> >     class ProductEvalNode(EvalNode):
> >         def eval(self):
> >             a = self.evaluatechild(self.node.a)
> >             b = self.evaluatechild(self.node.b)
> >             return a * b
>
> >     class IntegerEvalNode(EvalNode):
> >         def eval(self): return self.node.val
>
> >     ###
>
> >     class PrettyPrintNode:
> >         def __init__(self, node):
> >             self.node = node
>
> >         def pprint_child(self, child):
> >             return PrettyPrintNode.factory(child).pprint()
>
> >         @staticmethod
> >         def factory(child):
> >             mapper = {
> >                 'Sum': SumPrettyPrintNode,
> >                 'Product': ProductPrettyPrintNode,
> >                 'Integer': IntegerPrettyPrintNode
> >                 }
> >             return abstract_factory(child, mapper)
>
> >     class SumPrettyPrintNode(PrettyPrintNode):
> >         def pprint(self):
> >             a = self.pprint_child(self.node.a)
> >             b = self.pprint_child(self.node.b)
> >             return '(the sum of %s and %s)' % (a, b)
>
> >     class ProductPrettyPrintNode(PrettyPrintNode):
> >         def pprint(self):
> >             a = self.pprint_child(self.node.a)
> >             b = self.pprint_child(self.node.b)
> >             return '(the product of %s and %s)' % (a, b)
>
> >     class IntegerPrettyPrintNode(PrettyPrintNode):
> >         def pprint(self): return self.node.val
>
> >     ##
> >     # Not sure where this method really "wants to be" structurally,
> >     # or what it should be named, but it reduces some duplication
>
> >     def abstract_factory(node, node_class_mapper):
> >         return node_class_mapper[node.__class__.__name__](node)
>
> >     expression = Product(Sum(Integer(5),Integer(2)), Integer(6))
>
> >     evaluator = EvalNode.factory(expression)
> >     print evaluator.eval()
>
> >     pprinter = PrettyPrintNode.factory(expression)
> >     print pprinter.pprint()
>
> I don't see the point of EvalNode and PrettyPrintNode. Why don't you
> just give Integer, Sum and Product 'eval' and 'pprint' methods?

This looks more structurally sound:

class Node(object):
   def eval(self):
  raise NotImplementedError
   def pprint(self):
  raise NotImplementedError

class

Re: How do I create a vanilla object in C?

2009-11-21 Thread Daniel Fetchinson
> I need to create a vanilla object in C, something I can do
> PyObject_SetAttr on.  Obviously, I do something somewhat like this every
> time I create a minimal python class.  I need to know how to do this in C
> though.

Please see

http://docs.python.org/extending/index.html
http://docs.python.org/c-api/index.html
http://docs.python.org/c-api/object.html

HTH,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: parallel class structures for AST-based objects

2009-11-21 Thread Steve Howell
On Nov 21, 4:07 pm, MRAB  wrote:
>
> I don't see the point of EvalNode and PrettyPrintNode. Why don't you
> just give Integer, Sum and Product 'eval' and 'pprint' methods?

That's a good question, and it's the crux of my design dilemma.  If
ALL I ever wanted to to with Integer/Sum/Product was to eval() and
pprint(), then I would just add those methods to Integer, Sum, and
Product, and be done with it, as you suggest.  But what happens when
somebody wants to extend capability?  Should every future software
developer that wants to use Integer/Sum/Product extend those classes
to get work done?  What if they want to store additional state for
nodes?

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


Re: Go versus Brand X

2009-11-21 Thread Steve Howell
On Nov 21, 11:20 am, John Roth  wrote:
> On Nov 21, 8:40 am, Duncan Booth  wrote:
>
> > a...@pythoncraft.com (Aahz) wrote:
> > > Comparing Go to another computer language -- do you recognize it?
>
> > >http://www.cowlark.com/2009-11-15-go/
>
> > Yes, spotted it at the first 'fi'.
>
> This isn't the first time anyone has criticized Go. The interesting,
> and somewhat sad, thing is that the entire mess can be explained
> very easily by looking at the beginning of the language design
> FAQ on the Go web site. See if you recognize the names of the
> principle people who designed it.
>
> Yep. Go is simply C with most (but not all) of the warts
> removed and some more modern features added. Brought to you
> by the same people who brought you C and Unix all those years ago.
> The use of the Plan 9 toolchain is not a coincidence.
>

The assertion that Go is simply C with warts removed and modern
features added is not surprising.

If you read the Go FAQ, you will see that there is no claim anywhere
that they are trying to solve the problem that 40 years of language
development since Algol has not produced super-sexy quantum leaps of
improvement.  Instead, they are trying to solve the problem that in
the last ten years, there haven not seen ANY improvement in systems
programming languages ("No major systems language has emerged in over
a decade").  The critics of Go probably fall into four categories:

  1) Some do not understand the goals of the Go project itself, so
they are criticizing Go for not solving problems that were never in
Go's bailiwick to begin with.
  2) Some believe that Go does not deliver on its goal to modernize
systems programming languages.
  3) Some do not accept the premise that there has been no progress
outside of Go in the last ten years with regards to systems
programming languages, and they are wondering why Google invented Go
instead of embracing other technologies.
  4) Some people do not even believe that the problem is important--do
we actually need a modern systems programming language, or do we just
need modern programming languages to perform well under all
circumstances, or at least be adaptable?

My list probably isn't even nearly exhaustive.

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


Re: parallel class structures for AST-based objects

2009-11-21 Thread MRAB

Steve Howell wrote:

I have been writing some code that parses a mini-language, and I am
running into what I know is a pretty common design pattern problem,
but I am wondering the most Pythonic way to solve it.

Basically, I have a bunch of really simple classes that work together
to define an expression--in my oversimplified example code below,
those are Integer, Sum, and Product.

Then I want to write different modules that work with those expression
objects.  In my example, I have a parallel set of classes that enable
you to evaluate an expression, and another set of objects that enable
you to pretty-print the expression.

The below code works as intended so far (tested under 2.6), but before
I go too much further with this design, I want to get a sanity check
and some ideas on other ways to represent the interrelationships
within the code.  Basically, the issue here is that you have varying
behavior in two dimensions--a node right now is only a Product/Integer/
Sum so far, but I might want to introduce new concepts like
Difference, Quotient, etc.  And right now the only things that you can
do to expressions is eval() them and pprint() them, but you eventually
might want to operate on the expressions in new ways, including fairly
abstract operations that go beyond a simple walking of the tree.

Here is the code:

###
# base classes just represents the expression itself, which
# get created by a parser or unit tests
# example usage is
# expression = Product(Sum(Integer(5),Integer(2)), Integer(6))
class Integer:
def __init__(self, val):
self.val = val

class BinaryOp:
def __init__(self, a,b):
self.a = a
self.b = b

class Sum(BinaryOp):
pass

class Product(BinaryOp):
pass



class EvalNode:
def __init__(self, node):
self.node = node

def evaluatechild(self, child):
return EvalNode.factory(child).eval()

@staticmethod
def factory(child):
mapper = {
'Sum': SumEvalNode,
'Product': ProductEvalNode,
'Integer': IntegerEvalNode
}
return abstract_factory(child, mapper)

class SumEvalNode(EvalNode):
def eval(self):
a = self.evaluatechild(self.node.a)
b = self.evaluatechild(self.node.b)
return a + b

class ProductEvalNode(EvalNode):
def eval(self):
a = self.evaluatechild(self.node.a)
b = self.evaluatechild(self.node.b)
return a * b

class IntegerEvalNode(EvalNode):
def eval(self): return self.node.val

###

class PrettyPrintNode:
def __init__(self, node):
self.node = node

def pprint_child(self, child):
return PrettyPrintNode.factory(child).pprint()

@staticmethod
def factory(child):
mapper = {
'Sum': SumPrettyPrintNode,
'Product': ProductPrettyPrintNode,
'Integer': IntegerPrettyPrintNode
}
return abstract_factory(child, mapper)

class SumPrettyPrintNode(PrettyPrintNode):
def pprint(self):
a = self.pprint_child(self.node.a)
b = self.pprint_child(self.node.b)
return '(the sum of %s and %s)' % (a, b)

class ProductPrettyPrintNode(PrettyPrintNode):
def pprint(self):
a = self.pprint_child(self.node.a)
b = self.pprint_child(self.node.b)
return '(the product of %s and %s)' % (a, b)

class IntegerPrettyPrintNode(PrettyPrintNode):
def pprint(self): return self.node.val

##
# Not sure where this method really "wants to be" structurally,
# or what it should be named, but it reduces some duplication

def abstract_factory(node, node_class_mapper):
return node_class_mapper[node.__class__.__name__](node)


expression = Product(Sum(Integer(5),Integer(2)), Integer(6))

evaluator = EvalNode.factory(expression)
print evaluator.eval()

pprinter = PrettyPrintNode.factory(expression)
print pprinter.pprint()


I don't see the point of EvalNode and PrettyPrintNode. Why don't you
just give Integer, Sum and Product 'eval' and 'pprint' methods?
--
http://mail.python.org/mailman/listinfo/python-list


parallel class structures for AST-based objects

2009-11-21 Thread Steve Howell
I have been writing some code that parses a mini-language, and I am
running into what I know is a pretty common design pattern problem,
but I am wondering the most Pythonic way to solve it.

Basically, I have a bunch of really simple classes that work together
to define an expression--in my oversimplified example code below,
those are Integer, Sum, and Product.

Then I want to write different modules that work with those expression
objects.  In my example, I have a parallel set of classes that enable
you to evaluate an expression, and another set of objects that enable
you to pretty-print the expression.

The below code works as intended so far (tested under 2.6), but before
I go too much further with this design, I want to get a sanity check
and some ideas on other ways to represent the interrelationships
within the code.  Basically, the issue here is that you have varying
behavior in two dimensions--a node right now is only a Product/Integer/
Sum so far, but I might want to introduce new concepts like
Difference, Quotient, etc.  And right now the only things that you can
do to expressions is eval() them and pprint() them, but you eventually
might want to operate on the expressions in new ways, including fairly
abstract operations that go beyond a simple walking of the tree.

Here is the code:

###
# base classes just represents the expression itself, which
# get created by a parser or unit tests
# example usage is
# expression = Product(Sum(Integer(5),Integer(2)), Integer(6))
class Integer:
def __init__(self, val):
self.val = val

class BinaryOp:
def __init__(self, a,b):
self.a = a
self.b = b

class Sum(BinaryOp):
pass

class Product(BinaryOp):
pass



class EvalNode:
def __init__(self, node):
self.node = node

def evaluatechild(self, child):
return EvalNode.factory(child).eval()

@staticmethod
def factory(child):
mapper = {
'Sum': SumEvalNode,
'Product': ProductEvalNode,
'Integer': IntegerEvalNode
}
return abstract_factory(child, mapper)

class SumEvalNode(EvalNode):
def eval(self):
a = self.evaluatechild(self.node.a)
b = self.evaluatechild(self.node.b)
return a + b

class ProductEvalNode(EvalNode):
def eval(self):
a = self.evaluatechild(self.node.a)
b = self.evaluatechild(self.node.b)
return a * b

class IntegerEvalNode(EvalNode):
def eval(self): return self.node.val

###

class PrettyPrintNode:
def __init__(self, node):
self.node = node

def pprint_child(self, child):
return PrettyPrintNode.factory(child).pprint()

@staticmethod
def factory(child):
mapper = {
'Sum': SumPrettyPrintNode,
'Product': ProductPrettyPrintNode,
'Integer': IntegerPrettyPrintNode
}
return abstract_factory(child, mapper)

class SumPrettyPrintNode(PrettyPrintNode):
def pprint(self):
a = self.pprint_child(self.node.a)
b = self.pprint_child(self.node.b)
return '(the sum of %s and %s)' % (a, b)

class ProductPrettyPrintNode(PrettyPrintNode):
def pprint(self):
a = self.pprint_child(self.node.a)
b = self.pprint_child(self.node.b)
return '(the product of %s and %s)' % (a, b)

class IntegerPrettyPrintNode(PrettyPrintNode):
def pprint(self): return self.node.val

##
# Not sure where this method really "wants to be" structurally,
# or what it should be named, but it reduces some duplication

def abstract_factory(node, node_class_mapper):
return node_class_mapper[node.__class__.__name__](node)


expression = Product(Sum(Integer(5),Integer(2)), Integer(6))

evaluator = EvalNode.factory(expression)
print evaluator.eval()

pprinter = PrettyPrintNode.factory(expression)
print pprinter.pprint()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem combining Scientific (leastSquaresFit) and scipy (odeint)

2009-11-21 Thread Colin W.

Harold Fellermann wrote:

Hi,

I need to perform leastSquaresFit of a model that is given by a
differential equation for which there seems to be no analytic
solution. So, I am trying to solve the ODE numerically (using
scipy.integrate.odeint) within the function I provide to
leastSquaresFit as a model:

def func(L, t, a, k) :
return -k * L * (1 - ( 1 - a*L**(-1./3) )**3.)

def model((k, L0, a), t) :
solution = odeint( func, array(L0[0]), array([0,t]), args=(a,k) )
return L0 - solution[1][0]

params, chisq = leastSquaresFit(model, params, data)

Unfortunately, this approach runs into an error (ValueError: shape
mismatch: objects cannot be broadcast to a single shape) that seems to
stem from the fact that leastSquaresFit is based on automatic
derivation (DerivVar), and according to the manual "the function [that
defines the model] may only use the mathematical functions known to
the module FirstDerivatives".

What is a good solution or workaround to this problem which appears to
be quite a standard situation to me?

Thanks for any help, harold.

You might consider using numpy.

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


Re: ANN: PyGUI Mailing List

2009-11-21 Thread Terry Reedy

Gregory Ewing wrote:

There is now a mailing list for discussion of PyGUI:

  http://mail.python.org/mailman/listinfo/pygui


Having it mirrored to news.gmane,org, if you have not yet, like other 
python.org lists, would make it easier to follow or join. Perhaps it 
will happen automatically, I do not know.


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


Re: plotting arrow in python

2009-11-21 Thread Stef Mientki

rudra wrote:

Dear friends,
I am very new in python. Actually, I think I will not do much python
then using it to plotting data. I have not done any "real" thing in
python, so plz be easy. Now , the problem
I have a data set:
0.0 0.0 0.1
0.0 0.1 0.1
0.1 0.0 0.5

like that! the first two column are coordinate and 3rd one is
magnitude of moment (say: x y,m)!! so what i want to do is draw an
arrow of magnitude(m) in the position (x,y).
I know how python read array, and how to draw an array(via
matplotlib)...but totally confused with this one.
can you people plz help?
  

maybe take a look at VPython
cheers,
Stef
--
http://mail.python.org/mailman/listinfo/python-list


extending dictonary

2009-11-21 Thread nospam
Is there any way to extend the dictonary in such manner that I can 
insert muliplay value to each keys and return one of the value as the 
default value. I would like to have similar syste that I drawed out below.



tree[nucelotide_postionc][nucleotide]=default(value subtree) This should 
be returned when doing lookup without any

tree[nucelotide_postionc][nucleotide]=Postive value
tree[nucelotide_postionc][nucleotide]=Negative value
--
http://mail.python.org/mailman/listinfo/python-list


Are you happy with the current web deployment options?

2009-11-21 Thread Antonio Cangiano
Phusion is a Dutch company that vastly improved the status quo of Ruby
and Rails deployment through their open source module for Apache and
nginx.

Now they are publicly asking whether Pythonistas would be interested
in a similar solution for Python (and Django of course).

Not many Pythonistas read their Ruby-oriented blog, so I thought I'd
share the link here: 
http://izumi.plan99.net/blog/index.php/2009/11/21/phusion-passenger-for-python/


Cheers,
Antonio
--
http://ThinkCode.TV - High-quality programming screencasts
http://antoniocangiano.com - Zen and the Art of Programming
Follow me on Twitter: http://twitter.com/acangiano
Author of "Ruby on Rails for Microsoft Developers" (Wrox, 2009)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Too Many Values To Unpack

2009-11-21 Thread Carsten Haese
Victor Subervi wrote:
>   File "/var/www/html/angrynates.com/cart/catTree.py
> ", line 25, in getChildren
> for (nm, dt) in levelDict:
> ValueError: too many values to unpack
> 
> Please advise.

I already explained what's causing this error. Read my first response on
this thread.
(http://mail.python.org/pipermail/python-list/2009-November/1227008.html)

--
Carsten Haese
http://informixdb.sourceforge.net

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


plotting arrow in python

2009-11-21 Thread rudra
Dear friends,
I am very new in python. Actually, I think I will not do much python
then using it to plotting data. I have not done any "real" thing in
python, so plz be easy. Now , the problem
I have a data set:
0.0 0.0 0.1
0.0 0.1 0.1
0.1 0.0 0.5

like that! the first two column are coordinate and 3rd one is
magnitude of moment (say: x y,m)!! so what i want to do is draw an
arrow of magnitude(m) in the position (x,y).
I know how python read array, and how to draw an array(via
matplotlib)...but totally confused with this one.
can you people plz help?
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I create a vanilla object in C?

2009-11-21 Thread rnichols
I need to create a vanilla object in C, something I can do
PyObject_SetAttr on.  Obviously, I do something somewhat like this every
time I create a minimal python class.  I need to know how to do this in C
though.
-- 
http://mail.python.org/mailman/listinfo/python-list


pythonpath

2009-11-21 Thread Ray Holt
Is there a way to make python point to a different directory for modules. I
don't like to keep my modules in the program directory, but I can't figure
out from the shell how to get the program to look in another directory. I am
using XP Pro as an operating system and python2.6
-- 
http://mail.python.org/mailman/listinfo/python-list


memoize again

2009-11-21 Thread yota.n...@gmail.com
I spent a lot of time looking for tips on how to properly write
cache / memoize function.
Testing, merging and fixing contributed but half finished pieces of
code.
Here is the summary of what I learned through a clean example, might
it be useful for beginners.

#!/usr/bin/env python3.1 (should work in python 2.5)

def dcache(function) :
""" simple, dict based cache """
return memoize(function, cache={})

def ccache(cache = {}):
""" with dict-like custom cache. Can be any class with
at least __contains__, __setitem__ and  __getitem__ methods """
def xcache(function):
return memoize(function, cache=cache)
return xcache

class memoize(object):
def __init__(self, function, cache):
self.function=function
self.cache=cache

def __get__(self, instance, cls=None):
self.instance = instance
return self

def __call__(self, *args):
if args not in self.cache:
self.cache[args] = self.function(self.instance, *args)
return self.cache[args]

which can be used as this:
- with the custom cache

@ccache(cache=customCache())
def compute(self, alpha, beta):
return alpha + beta

- or with a default dict() cache

@dcache
def compute(self, alpha, beta):
return alpha + beta

Each time compute() is called, the memoize decorator looks first into
the cache for a value whose key is the *args tuple.

The full content of the cache can be acessed as compute.cache.


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


Re: Go versus Brand X

2009-11-21 Thread Nobody
On Fri, 20 Nov 2009 17:12:36 -0800, Aahz wrote:

> Comparing Go to another computer language -- do you recognize it?

"Here is a language so far ahead of its time that it was not only an
improvement on its predecessors but also on nearly all its successors."

 - C. A. R. Hoare (although he was actually referring to ALGOL-60).

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


Re: python simply not scaleable enough for google?

2009-11-21 Thread Nobody
On Fri, 20 Nov 2009 09:51:49 -0800, sturlamolden wrote:

> You can make a user-space scheduler and run a 10 tasklets on a
> threadpool. But there is a GIL in stackless as well.
> 
> Nobody wants 10 OS threads, not with Python, not with Go, not with
> C.
> 
> Also note that Windows has native support for "taskelets", regardless
> of language. They are called "fibers" (as opposed to "threads") and
> are created using the CreateFiber system call. I would not be
> surprised if Unix'es has this as well. We do not need Stackless for
> light-weight threads. We can just take Python's threading modules' C
> code and replace CreateThread with CreateFiber.

POSIX.1-2001 and POSIX.1-2004 have makecontext(), setcontext(),
getcontext() and swapcontext(), but obsoleted by POSIX.1-2008.

They are available on Linux; I don't know about other Unices.

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


Re: Go versus Brand X

2009-11-21 Thread John Roth
On Nov 21, 8:40 am, Duncan Booth  wrote:
> a...@pythoncraft.com (Aahz) wrote:
> > Comparing Go to another computer language -- do you recognize it?
>
> >http://www.cowlark.com/2009-11-15-go/
>
> Yes, spotted it at the first 'fi'.

This isn't the first time anyone has criticized Go. The interesting,
and somewhat sad, thing is that the entire mess can be explained
very easily by looking at the beginning of the language design
FAQ on the Go web site. See if you recognize the names of the
principle people who designed it.

Yep. Go is simply C with most (but not all) of the warts
removed and some more modern features added. Brought to you
by the same people who brought you C and Unix all those years ago.
The use of the Plan 9 toolchain is not a coincidence.

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


Problem combining Scientific (leastSquaresFit) and scipy (odeint)

2009-11-21 Thread Harold Fellermann
Hi,

I need to perform leastSquaresFit of a model that is given by a
differential equation for which there seems to be no analytic
solution. So, I am trying to solve the ODE numerically (using
scipy.integrate.odeint) within the function I provide to
leastSquaresFit as a model:

def func(L, t, a, k) :
return -k * L * (1 - ( 1 - a*L**(-1./3) )**3.)

def model((k, L0, a), t) :
solution = odeint( func, array(L0[0]), array([0,t]), args=(a,k) )
return L0 - solution[1][0]

params, chisq = leastSquaresFit(model, params, data)

Unfortunately, this approach runs into an error (ValueError: shape
mismatch: objects cannot be broadcast to a single shape) that seems to
stem from the fact that leastSquaresFit is based on automatic
derivation (DerivVar), and according to the manual "the function [that
defines the model] may only use the mathematical functions known to
the module FirstDerivatives".

What is a good solution or workaround to this problem which appears to
be quite a standard situation to me?

Thanks for any help, harold.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about scrapy tutorial

2009-11-21 Thread Cousin Stanley

> i have no idea what scrapy is 
> 

  http://scrapy.org/

Scrapy is a fast high-level screen scraping and web
crawling framework, used to crawl websites and extract 
structured data from their pages. It can be used for 
a wide range of purposes, from data mining to monitoring 
and automated testing.

  Also, previously unknown to me 
  before google-izing  


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: Newbie question about scrapy tutorial

2009-11-21 Thread Zeynel
Now I use EditpadPro and IDLE which appears to be adequate for
beginning level. But PyDev looks fun, I'll try it.

By the way, I realized that the spider sends the scraped data to the
pipelines.py. Now everything is working.

On Nov 21, 11:21 am, DreiJane  wrote:
> Sorry,
>
> i have no idea what scrapy is - but i see, that you try to use
> idle with pipes or anything like that. That cannot work.
> idle doesn't even handle __file__ correctly. Use a full-fledged
> python IDE (PyDev under Eclipse leaves very few wishes open) or
> test in a python interpreter shell.
>
> Good luck, DreiJane

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


Re: Problem w/ smtplib

2009-11-21 Thread Victor Subervi
On Sat, Nov 21, 2009 at 1:16 PM, Kev Dwyer  wrote:

>
> 2009/11/21 Victor Subervi 
>
> On Sat, Nov 21, 2009 at 12:04 PM, Kev Dwyer wrote:
>>
>>> On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote:
>>>
>>> Hello Victor,
>>>
>>> The information that you have sent comes from the client side of the
>>> transaction, so it isn't possible to tell why the server disconnected.
>>> Assuming that there is an SMTP server listening on port 25, you need to
>>> check the SMTP server logs.
>>
>>
>> There wasn't anything in /var/log/maillog. Is that where I should have
>> checked?
>>
>>
>>> You might need to crank up the logging to
>>> get useful output.
>>>
>>
>> How?
>> Look at the output below:
>>
>> [r...@13gems stcroixresort]# netstat -tulp
>> Active Internet connections (only servers)
>> Proto Recv-Q Send-Q Local Address   Foreign
>> Address State   PID/Program name
>> tcp0  0 *:mysql
>> *:* LISTEN  24488/mysqld
>> tcp0  0 *:pop3
>> *:* LISTEN  5278/tcpserver
>> tcp0  0 *:ftp
>> *:* LISTEN  26564/vsftpd
>> tcp0  0 localhost.localdomai:domain
>> *:* LISTEN  11845/named
>> tcp0  0 *:smtp
>> *:* LISTEN  5274/tcpserver
>> tcp0  0 localhost.localdomain:rndc
>> *:* LISTEN  11845/named
>> tcp0  0 *:http
>> *:* LISTEN  5201/httpd
>> tcp0  0 localhost:domain
>> *:* LISTEN  11845/named
>> tcp0  0 *:ssh
>> *:* LISTEN  15509/sshd
>> tcp0  0 localhost:rndc
>> *:* LISTEN  11845/named
>> udp0  0 localhost.locald:domain
>> *:* 11845/named
>> udp0  0 localhost:domain
>> *:* 11845/named
>> [r...@13gems stcroixresort]# qmailctl stat
>> /service/qmail-send: up (pid 5266) 594565 seconds
>> /service/qmail-send/log: up (pid 5271) 594565 seconds
>> /service/qmail-smtpd: up (pid 5274) 594565 seconds
>> /service/qmail-smtpd/log: up (pid 5276) 594565 seconds
>> /service/qmail-pop3d: up (pid 5278) 594565 seconds
>> /service/qmail-pop3d/log: up (pid 5279) 594565 seconds
>> messages in queue: 0
>> messages in queue but not yet preprocessed: 0
>>
>> Please advise.
>> TIA,
>> V
>>
>
> Hello Victor,
>
>  I'm afraid I don't know much about mail servers, you need to check the
> server docs or ask on a qmail mailing list.
>
> If you really think this is a python issue, then you could try:
> >>> import smtplib
> >>> server = smtplib.SMTP()
> >>> server.set_debuglevel(1)
> >>> server.connect()
> connect: ('localhost', 25)
> connect: (25, 'localhost')
> reply: '220 pluto.site ESMTP Postfix\r\n'
> reply: retcode (220); Msg: pluto.site ESMTP Postfix
> connect: pluto.site ESMTP Postfix
> (220, 'pluto.site ESMTP Postfix')
> >>> server.quit()
> send: 'quit\r\n'
> reply: '221 2.0.0 Bye\r\n'
> reply: retcode (221); Msg: 2.0.0 Bye
> (221, '2.0.0 Bye')
>
>
> and see if there are any error messages/tracebacks in the output; but if
> you still get a disconnect exception then it's unlikely that this is a
> python issue.
>

Thank you. Yes, there was an error.
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem w/ smtplib

2009-11-21 Thread Kev Dwyer
2009/11/21 Victor Subervi 

> On Sat, Nov 21, 2009 at 12:04 PM, Kev Dwyer wrote:
>
>> On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote:
>>
>> Hello Victor,
>>
>> The information that you have sent comes from the client side of the
>> transaction, so it isn't possible to tell why the server disconnected.
>> Assuming that there is an SMTP server listening on port 25, you need to
>> check the SMTP server logs.
>
>
> There wasn't anything in /var/log/maillog. Is that where I should have
> checked?
>
>
>> You might need to crank up the logging to
>> get useful output.
>>
>
> How?
> Look at the output below:
>
> [r...@13gems stcroixresort]# netstat -tulp
> Active Internet connections (only servers)
> Proto Recv-Q Send-Q Local Address   Foreign Address
> State   PID/Program name
> tcp0  0 *:mysql *:*
> LISTEN  24488/mysqld
> tcp0  0 *:pop3  *:*
> LISTEN  5278/tcpserver
> tcp0  0 *:ftp   *:*
> LISTEN  26564/vsftpd
> tcp0  0 localhost.localdomai:domain *:*
> LISTEN  11845/named
> tcp0  0 *:smtp  *:*
> LISTEN  5274/tcpserver
> tcp0  0 localhost.localdomain:rndc  *:*
> LISTEN  11845/named
> tcp0  0 *:http  *:*
> LISTEN  5201/httpd
> tcp0  0 localhost:domain*:*
> LISTEN  11845/named
> tcp0  0 *:ssh   *:*
> LISTEN  15509/sshd
> tcp0  0 localhost:rndc  *:*
> LISTEN  11845/named
> udp0  0 localhost.locald:domain
> *:* 11845/named
> udp0  0 localhost:domain
> *:* 11845/named
> [r...@13gems stcroixresort]# qmailctl stat
> /service/qmail-send: up (pid 5266) 594565 seconds
> /service/qmail-send/log: up (pid 5271) 594565 seconds
> /service/qmail-smtpd: up (pid 5274) 594565 seconds
> /service/qmail-smtpd/log: up (pid 5276) 594565 seconds
> /service/qmail-pop3d: up (pid 5278) 594565 seconds
> /service/qmail-pop3d/log: up (pid 5279) 594565 seconds
> messages in queue: 0
> messages in queue but not yet preprocessed: 0
>
> Please advise.
> TIA,
> V
>

Hello Victor,

 I'm afraid I don't know much about mail servers, you need to check the
server docs or ask on a qmail mailing list.

If you really think this is a python issue, then you could try:
>>> import smtplib
>>> server = smtplib.SMTP()
>>> server.set_debuglevel(1)
>>> server.connect()
connect: ('localhost', 25)
connect: (25, 'localhost')
reply: '220 pluto.site ESMTP Postfix\r\n'
reply: retcode (220); Msg: pluto.site ESMTP Postfix
connect: pluto.site ESMTP Postfix
(220, 'pluto.site ESMTP Postfix')
>>> server.quit()
send: 'quit\r\n'
reply: '221 2.0.0 Bye\r\n'
reply: retcode (221); Msg: 2.0.0 Bye
(221, '2.0.0 Bye')


and see if there are any error messages/tracebacks in the output; but if you
still get a disconnect exception then it's unlikely that this is a python
issue.

Cheers,

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


Re: Problem w/ smtplib

2009-11-21 Thread Victor Subervi
On Sat, Nov 21, 2009 at 12:04 PM, Kev Dwyer  wrote:

> On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote:
>
> Hello Victor,
>
> The information that you have sent comes from the client side of the
> transaction, so it isn't possible to tell why the server disconnected.
> Assuming that there is an SMTP server listening on port 25, you need to
> check the SMTP server logs.


There wasn't anything in /var/log/maillog. Is that where I should have
checked?


> You might need to crank up the logging to
> get useful output.
>

How?
Look at the output below:

[r...@13gems stcroixresort]# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address   Foreign Address
State   PID/Program name
tcp0  0 *:mysql *:*
LISTEN  24488/mysqld
tcp0  0 *:pop3  *:*
LISTEN  5278/tcpserver
tcp0  0 *:ftp   *:*
LISTEN  26564/vsftpd
tcp0  0 localhost.localdomai:domain *:*
LISTEN  11845/named
tcp0  0 *:smtp  *:*
LISTEN  5274/tcpserver
tcp0  0 localhost.localdomain:rndc  *:*
LISTEN  11845/named
tcp0  0 *:http  *:*
LISTEN  5201/httpd
tcp0  0 localhost:domain*:*
LISTEN  11845/named
tcp0  0 *:ssh   *:*
LISTEN  15509/sshd
tcp0  0 localhost:rndc  *:*
LISTEN  11845/named
udp0  0 localhost.locald:domain
*:* 11845/named
udp0  0 localhost:domain
*:* 11845/named
[r...@13gems stcroixresort]# qmailctl stat
/service/qmail-send: up (pid 5266) 594565 seconds
/service/qmail-send/log: up (pid 5271) 594565 seconds
/service/qmail-smtpd: up (pid 5274) 594565 seconds
/service/qmail-smtpd/log: up (pid 5276) 594565 seconds
/service/qmail-pop3d: up (pid 5278) 594565 seconds
/service/qmail-pop3d/log: up (pid 5279) 594565 seconds
messages in queue: 0
messages in queue but not yet preprocessed: 0

Please advise.
TIA,
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem w/ smtplib

2009-11-21 Thread Kev Dwyer
On Sat, 21 Nov 2009 08:19:52 -0500, Victor Subervi wrote:

Hello Victor,

The information that you have sent comes from the client side of the 
transaction, so it isn't possible to tell why the server disconnected.  
Assuming that there is an SMTP server listening on port 25, you need to 
check the SMTP server logs.  You might need to crank up the logging to 
get useful output.  

If the information that you pasted in comes from a Django traceback then 
you could check the Django page on e-mail at 
http://docs.djangoproject.com/en/dev/topics/email/#topics-email
(dev version, you might need to view an older version).

Cheers,

Kev

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


Re: python server developer

2009-11-21 Thread garabik-news-2005-05
Bobby  wrote:
> Hello,
> We are looking for Python server developer
> location : Hyderabad
> Experience : 3 years .
> Send me your updated resume with availability for Telephonic interview

Hyderabad, India or Hyderabad, Pakistan?
(no, I am not going to apply in either case, even if I think I do
qualify - I already have a nice, reasonably python related job).

-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question about scrapy tutorial

2009-11-21 Thread DreiJane
Sorry,

i have no idea what scrapy is - but i see, that you try to use
idle with pipes or anything like that. That cannot work.
idle doesn't even handle __file__ correctly. Use a full-fledged
python IDE (PyDev under Eclipse leaves very few wishes open) or
test in a python interpreter shell.

Good luck, DreiJane
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: PyGUI Mailing List

2009-11-21 Thread Gregory Ewing

There is now a mailing list for discussion of PyGUI:

  http://mail.python.org/mailman/listinfo/pygui


What is PyGUI?
--

PyGUI is a cross-platform GUI toolkit designed to be lightweight
and have a highly Pythonic API.

  http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/

--
Gregory Ewing
greg.ew...@canterbury.ac.nz
http://www.cosc.canterbury.ac.nz/greg.ewing/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Too Many Values To Unpack

2009-11-21 Thread Victor Subervi
On Sat, Nov 21, 2009 at 2:10 AM, Dennis Lee Bieber wrote:

>And my follow-up to that original thread stated that it /was/
> pseudo-code, not something tested.  My goal was to illustrate the
> general concepts of processing a recursive/nested data set stored in a
> flat/relational table.
>

Of course and appreciated.

>
>"expand()" was responsible for taking each "key" from a select query
> and creating an empty dictionary with that "key" as, well, key. Then the
> recursive operation would perform a select query used to populate the
> empty dictionary, ad infinitum.
>

Here is the output with just one test category:
{'cat1': {}}

Here is the code to which that output is fed:

def getChildren(levelDict, level = 0):
  MAXLEVEL = 7
  if level > MAXLEVEL:
return  #possibly the data has a cycle/loop
  for (nm, dt) in levelDict:
cursor.execute('''select c.name from categories as c
  inner join relationship as r
  on c.ID = r.Child
  inner join categories as p
  on r.Parent = p.ID
  where p.category = %s
  order by c.name''', (nm,))
levelDict[nm] = expand(cursor.fetchall())
# recursive call to do next level
getChildren(levelDict[nm], level + 1)
  # no data return as we are mutating dictionaries in place

When this script is called from another script, the python interpreter
throws the following error:

Traceback (most recent call last):
  File "createCats.py", line 8, in ?
from catTree import catTree
  File "/var/www/html/angrynates.com/cart/catTree.py", line 85, in ?
catTree()
  File "/var/www/html/angrynates.com/cart/catTree.py", line 76, in catTree
getChildren(theTree)
  File "/var/www/html/angrynates.com/cart/catTree.py", line 25, in
getChildren
for (nm, dt) in levelDict:
ValueError: too many values to unpack

Please advise.
TIA,
V
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: crontab problem

2009-11-21 Thread Victor Subervi
On Sat, Nov 21, 2009 at 8:59 AM, Chris Rebert  wrote:

>
> And this is germane to Python (and not instead say, *nix) how exactly?
>

Oops! Wrong list!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem with pyqt.. help please...

2009-11-21 Thread Benjamin Kaplan
On Sat, Nov 21, 2009 at 8:47 AM, Jebagnana Das wrote:

> Hi friends,
>  I've recently changed to ubuntu 9.04.. I've not had any
> problem with the installation of pyqt as it is available from the ubuntu
> repositories with umpteen number of packages.. Anyhow i've to download
> tarball file for python 3.1 and installed it.. I found that PyQt4 supports
> python 3.1(Am i right?)..
>
> I wanted to check the pyqt installation with a sample program..
>
> import sys
> from PyQt4 import QtGui
> app=QtGui.QApplication(sys.argv)
> widget=QtGui.QWidget()
> widget.resize(250,150)
> widget.setWindowTitle('Simple')
> widget.show()
> sys.exit(app.exec_())
>
> when i issued the command
> $python simple.py
> it worked perfectly since it's executed with 2.6 installation..
> But when i tried to execute it with
> $python3 simple.py
> it showed the error like
> ImportError: No module named PyQt4
> So i searched the sys.path for 2.6 and included
> /usr/lib/python2.6/dist-packages
> in python3 sys.path...
> Now when i tried to run this with python3  the error is like..
> ImportError: /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so: undefined
> symbol: PyString_FromString
> I got the same error when i tried to execute another program... So can u
> please tell me how to solve this problem?? Am i heading in the right
> direction???...
>
> Thanks & Regards...
>
> Jebagnanadas,
> Python Learner..
>
>
As a general rule, never add packages that were installed for another
version of Python . There are inconsistencies between versions, so the C
libraries (like PyQT) always need to be recompiled. This is especially true
between Python 2.x and Python 3.x, where there were some fundamental changes
to the language. If you want to use PyQT on Python 3, download it and
compile it yourself.

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


Re: crontab problem

2009-11-21 Thread Chris Rebert
On Sat, Nov 21, 2009 at 5:47 AM, Victor Subervi  wrote:
> Hi;
> I have the following in crontab -eu root:
> @daily /usr/local/bin/mysql-backup-daily.sh
> @weekly /usr/local/bin/mysql-backup-weekly.sh
> @monthly /usr/local/bin/mysql-backup-monthly.sh
>
> [r...@13gems globalsolutionsgroup.vi]# ls /usr/local/bin/mysql-*
> /usr/local/bin/mysql-daily.sh  /usr/local/bin/mysql-monthly.sh
> /usr/local/bin/mysql-weekly.sh
>
> These scripts worked on another server. The daily writes to:
> /usr/backup/database/mysql-backups/mysql-backup-dailys/
> However, a day later, nothing is there. Please advise.

And this is germane to Python (and not instead say, *nix) how exactly?

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


problem with pyqt.. help please...

2009-11-21 Thread Jebagnana Das
Hi friends,
 I've recently changed to ubuntu 9.04.. I've not had any problem
with the installation of pyqt as it is available from the ubuntu
repositories with umpteen number of packages.. Anyhow i've to download
tarball file for python 3.1 and installed it.. I found that PyQt4 supports
python 3.1(Am i right?)..

I wanted to check the pyqt installation with a sample program..

import sys
from PyQt4 import QtGui
app=QtGui.QApplication(sys.argv)
widget=QtGui.QWidget()
widget.resize(250,150)
widget.setWindowTitle('Simple')
widget.show()
sys.exit(app.exec_())

when i issued the command
$python simple.py
it worked perfectly since it's executed with 2.6 installation..
But when i tried to execute it with
$python3 simple.py
it showed the error like
ImportError: No module named PyQt4
So i searched the sys.path for 2.6 and included
/usr/lib/python2.6/dist-packages
in python3 sys.path...
Now when i tried to run this with python3  the error is like..
ImportError: /usr/lib/python2.6/dist-packages/PyQt4/QtGui.so: undefined
symbol: PyString_FromString
I got the same error when i tried to execute another program... So can u
please tell me how to solve this problem?? Am i heading in the right
direction???...

Thanks & Regards...

Jebagnanadas,
Python Learner..
-- 
http://mail.python.org/mailman/listinfo/python-list


crontab problem

2009-11-21 Thread Victor Subervi
Hi;
I have the following in crontab -eu root:
@daily /usr/local/bin/mysql-backup-daily.sh
@weekly /usr/local/bin/mysql-backup-weekly.sh
@monthly /usr/local/bin/mysql-backup-monthly.sh

[r...@13gems globalsolutionsgroup.vi]# ls /usr/local/bin/mysql-*
/usr/local/bin/mysql-daily.sh  /usr/local/bin/mysql-monthly.sh
/usr/local/bin/mysql-weekly.sh

These scripts worked on another server. The daily writes to:
/usr/backup/database/mysql-backups/mysql-backup-dailys/
However, a day later, nothing is there. Please advise.
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


python server developer

2009-11-21 Thread Bobby
Hello,
We are looking for Python server developer
location : Hyderabad
Experience : 3 years .
Send me your updated resume with availability for Telephonic interview
-- 
http://mail.python.org/mailman/listinfo/python-list


Problem w/ smtplib

2009-11-21 Thread Victor Subervi
Hi;
I get the following error:

 /var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py52
   session.sendmail(clientEmail, ourEmail1, header+msg)
53 #  session.sendmail(clientEmail, ourEmail2, header+msg)
54
55 mailSpreadsheet()
56
 *mailSpreadsheet* = 
/var/www/html/globalsolutionsgroup.vi/mailSpreadsheet.py in *mailSpreadsheet
*()47   order += 'TOTAL: $' + str(total)
48
   msg = 'Here is the order from %s:\n\n %s' % (string.replace(client,
'_', ' '), order)
49   session = smtplib.SMTP("localhost")
50   session.login(user, passwd) # only if it requires auth
51
   header = "Subject: %s \r\nContent-type: text/html;
charset=utf-8\r\n\r\n" % subject
 session *undefined*, *global* *smtplib* = , smtplib.*SMTP* = 
 /usr/lib64/python2.4/smtplib.py in *__init__*(self=,
host='localhost', port=0, local_hostname=None)   242
 self.esmtp_features = {}
   243 if host:
   244 (code, msg) = self.connect(host, port)
   245 if code != 220:
   246 raise SMTPConnectError(code, msg)
 code *undefined*, msg *undefined*, *self* = , self.*
connect* = >, *host* =
'localhost', *port* = 0   /usr/lib64/python2.4/smtplib.py in
*connect*(self=, host='localhost', port=25)   305 if not self.sock:
   306 raise socket.error, msg
   307 (code, msg) = self.getreply()
   308 if self.debuglevel > 0: print>>stderr, "connect:", msg
   309 return (code, msg)
 code *undefined*, *msg* = 'getaddrinfo returns an empty list', *self* =
, self.*getreply* = >   /usr/lib64/python2.4/smtplib.py in
*getreply*(self=)   349 if line == '':
   350 self.close()
   351
 raise SMTPServerDisconnected("Connection unexpectedly closed")
   352
 if self.debuglevel > 0: print>>stderr, 'reply:', repr(line)
   353 resp.append(line[4:].strip())
 *global* *SMTPServerDisconnected* = *
SMTPServerDisconnected*: Connection unexpectedly closed
  args = ('Connection unexpectedly closed',)

Why did this connection close? How do I fix it? I tried commenting out the
authentication line. I have imported smtplib.
TIA,
Victor
-- 
http://mail.python.org/mailman/listinfo/python-list


How do I print to text browser with Qthread? (in PyQt)

2009-11-21 Thread someone
Hello,
I wrote Qthread that gets in the constructor a textBrowser from PyQt
application
and I tryed to print in this widget text that is updated each 5
seconds
(Like application that counts numbers of the text brouser)

Is anyone can explain me how to do this?
I would glad if you can attach a code example.
thanks
someone
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: DOM related question and problem

2009-11-21 Thread elca



Stefan Behnel-3 wrote:
> 
> elca, 18.11.2009 19:04:
>> these day im making python script related with DOM.
>> 
>> problem is these day many website structure is very complicate .
>> [...]
>> what is best method to check  can extract such like following info
>> quickly?
> 
> This should help:
> 
> http://blog.ianbicking.org/2008/12/10/lxml-an-underappreciated-web-scraping-library/
> 
> Stefan
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

hello
yes..i know this website already.
but failed to use it lxml solution

-- 
View this message in context: 
http://old.nabble.com/DOM-related-question-and-problem-tp26412730p26455800.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Writing a Carriage Return in Unicode

2009-11-21 Thread sturlamolden
On 21 Nov, 08:10, Dennis Lee Bieber  wrote:

>         Of course, if you are describing a /real/ /manual/ typewriter, you
> would rapidly discover that the sequence is  -- since pushing
> the bar would often trigger the line feed before it would slide the
> carriage to the right.
>
>         But on a teletype, it would be , and maybe a few 
> for timing -- as the  was the slower operation, and would complete
> while the other characters were operated upon...

Ah, yes you are right :-)

The sequence is  on a typewriter.

Which is why the RETURN button often had the symbol

 |
<|









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


Re: extending dictonary

2009-11-21 Thread Steven D'Aprano
On Sat, 21 Nov 2009 09:25:38 +0100, nospam wrote:

> Is there any way to extend the dictonary in such manner that I can
> insert muliplay value to each keys and return one of the value as the
> default value. I would like to have similar syste that I drawed out
> below.
> 
> 
> tree[nucelotide_postionc][nucleotide]=default(value subtree) This should
> be returned when doing lookup without any
> tree[nucelotide_postionc][nucleotide]=Postive value
> tree[nucelotide_postionc][nucleotide]=Negative value

I'm sorry, I don't understand what you are asking. What are tree, 
nucelotide_postionc, nucleotide, subtree? What are positive value and 
negative value?

If each key has multiple values, how do you want to specify which value 
to return?


The simplest way to associate multiple values with a key is to use a list:

>>> d = {}
>>> d['a'] = [2, 3, 4]
>>> d['b'] = [5, 6]
>>> d['a'].append(0)
>>> d
{'a': [2, 3, 4, 0], 'b': [5, 6]}

If you like, you can take the convention that the first item in the list 
is the default, and write this:

>>> print d['b'][0]
5


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


Re: Writing a Carriage Return in Unicode

2009-11-21 Thread sturlamolden
On 21 Nov, 09:12, Steven D'Aprano  wrote:

> Oh please, that's historical revisionism -- \r\n wasn't invented by
> Microsoft. Microsoft didn't "get it right", they simply copied what CP/M
> did, on account of the original MS-DOS being essentially a clone of CP/M.

Actyually \r\n goes back to early mechanical typewriters with
typebars, such as the Hermes. The operator would hit CR to return the
paper carriage and LF to move down to the next line.






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


Re: Writing a Carriage Return in Unicode

2009-11-21 Thread Steven D'Aprano
On Thu, 19 Nov 2009 23:22:22 -0800, Scott David Daniels wrote:

> MRAB wrote:
>> u'\u240D' isn't a carriage return (that's u'\r') but a symbol (a
>> visible "CR" graphic) for carriage return. Windows programs normally
>> expect lines to end with '\r\n'; just use u'\n' in programs and open
>> the text files in text mode ('r' or 'w').
> 
> 
> This is the one thing from standards that I believe Microsoft got right
> where others did not.

Oh please, that's historical revisionism -- \r\n wasn't invented by 
Microsoft. Microsoft didn't "get it right", they simply copied what CP/M 
did, on account of the original MS-DOS being essentially a clone of CP/M.

And of course the use of \r\n predates computers -- CR+LF (Carriage 
Return + LineFeed) were necessary to instruct the print head on teletype 
printers to move down one line and return to the left. It was a physical 
necessity for the oldest computer operating systems, because the only 
printers available were teletypes.


> The ASCII (American Standard for Information
> Interchange) standard end of line is _both_ carriage return (\r) _and_
> line feed (\n)

I doubt that very much. Do you have a reference for this?

It is true that the predecessor to ANSI (not ASCII), ASA, specified \r\n 
as the line terminator, but ISO specified that both \n and \r\n should be 
accepted.


> I believe in that order.

You "believe" in that order? But you're not sure?

That's the trouble with \r\n, or \n\r -- it's an arbitrary choice, and 
therefore hard to remember which it is. I've even seen proprietary 
business-to-business software where the developers (apparently) couldn't 
remember which was the standard, so when exporting data to text, you had 
to choose which to use for line breaks.

Of course, being Windows software, they didn't think that you might want 
to transfer the text file to a Unix system, or a Mac, and so didn't offer 
\n or \r alone as line terminators.


> The Unix operating system, in its enthusiasm to make _everything_
> simpler (against Einstein's advice, "Everything should be made as simple
> as possible, but not simpler.") decided that end-of-line should be a
> simple line feed and not carriage return line feed.

Why is it "too simple" to have line breaks be a single character? What is 
the downside of the Unix way? Why is \r\n "better"? We're not using 
teletypes any more.

Or for that matter, classic Mac OS, which used a single \r as newline.

Likewise for other OSes, such as Commodore, Amiga, Multics...


> Before they made
> that decision, there was debate about the order of cr-lf or lf-cr, or
> inventing a new EOL character ('\037' == '\x1F' was the candidate).

IBM operating systems that use EBCDIC used the NEL (NExt Line) character 
for line breaks, keeping CR and LF for other uses. 

The Unicode standard also specifies that any of the following be 
recognised as line separators or terminators:

LF, CR, CR+LF, NEL, FF (FormFeed, \f), LS (LineSeparator, U+2028) and PS 
(ParagraphSeparator, U+2029).


> If you've actually typed on a physical typewriter, you know that moving
> the carriage back is a distinct operation from rolling the platen
> forward; 

I haven't typed on a physical typewriter for nearly a quarter of a 
century.

If you've typed on a physical typewriter, you'll know that to start a new 
page, you have to roll the platen forward until the page ejects, then 
move the typewriter guide forward to leave space, then feed a new piece 
of paper into the typewriter by hand, then roll the platen again until 
the page is under the guide, then push the guide back down again. That's 
FIVE distinct actions, and if you failed to do them, you would type but 
no letters would appear on the (non-existent) page. Perhaps we should 
specify that text files need a five-character sequence to specify a new 
page too?


> both operations are accomplished when you push the carriage
> back using the bar, but you know they are distinct.  Hell, MIT even had
> "line starve" character that moved the cursor up (or rolled the platen
> back).
> 
> 
> Lots of people talk about "dos-mode files" and "windows files" as if
> Microsoft got it wrong; it did not -- Unix made up a convenient fiction
> and people went along with it. (And, yes, if Unix had been there first,
> their convention was, in fact, better).

This makes zero sense. If Microsoft "got it right", then why is the Unix 
convention "convenient" and "better"? Since we're not using teletype 
machines, I would say Microsoft is now using an *inconvenient* fiction.




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