Re: one more question

2009-07-14 Thread alex23
amr...@iisermohali.ac.in wrote:
> I tried but its not coming.

How much are you prepared to pay for help with this? Or are you just
asking us to do all the work for you?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: missing 'xor' Boolean operator

2009-07-14 Thread Tim Roberts
"Dr. Phillip M. Feldman"  wrote:
>
>Here's a related issue: I would like to see an option for type checking on
>operands of logical operators, so that attempting to apply a logical
>operator to non-Boolean entities generates a warning message.  With operand
>type checking, 'xor' and != would be different.

How would you define "Boolean entities"?  Do you mean the True and False
values?  Such a change would break virtually every Python program ever
written.

In any case, this idea is dead in the water.  It would break a whole bunch
of existing code from before the conditional operator:

xxx = testme and truevalue or falsevalue
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why did you choose the programming language(s)you currently use?

2009-07-14 Thread Mensanator
On Jul 14, 4:58�pm, Nobody  wrote:
> On Tue, 14 Jul 2009 11:47:08 -0700, Paul Rubin wrote:
> >> - unlimited precision integers
> >> - easy to program
> >> - IDE not required
> >> - reasonable speed
> >> - math library needs to include number theoretic functions
> >> � like GCD, LCM, Modular Inverse, etc.
> >> - not fucking retarded like F#
>
> > Have you looked at Haskell?
>
> Given his comment about F#, I have a suspicion that he might be
> dogmatically opposed to functional languages generally.

Not dogmatically opposed, I installed it because
I actually wanted to try functional progrsmming.
My mistake was listening to that Harrop dude who
didn't bother to explain that F# is part of a
government program that provides jobs for retards.

To wit: F# has a rational data type, that's cool.
But wait, F# has TWO rational data types. Huh?
Well, after they made the first, some jackass
came up with a second type that stores data more
efficiently.

And, of course, the second type doesn't have the
same functionality as the first, so you need both.

And of the myriad data type converion methods, guess
which possible conversion methods are conspicuous
by their absense? That's right, type1 <==> type2
rational conversions don't exist.

At that point, I decided I wasn't going to put up
crap like that and threw it away.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why did you choose the programming language(s)you currently use?

2009-07-14 Thread Mensanator
On Jul 14, 1:47�pm, Paul Rubin  wrote:
> Mensanator  writes:
> > - unlimited precision integers
> > - easy to program
> > - IDE not required
> > - reasonable speed
> > - math library needs to include number theoretic functions
> > � like GCD, LCM, Modular Inverse, etc.
> > - not fucking retarded like F#
>
> Have you looked at Haskell?
>
> > As for negatives, the GMP library doesn't factor.
>
> Maybe with some MIRACL bindings...

That's the factoring program (factor.exe from
the MIRACL package) I made reference to.

I don't know how to fix the bug nor how to bind
it to Python.

What I do (or did at one time) know is how figure
out how to recompile it, change the output to be
database compatible, consistent messages rather
than such useless messages as "this number is prime".

The Python program, as it captures the StdOut,
can watch for the bug. The bug is that factor.exe
occasionally gets stuck on a composite while deep
into the factoring process. Sometimes, however,
this getting stuck can be resolved if you send the
composite back to the beginning and start over.
The factor.exe program isn't smart enough to try
this, it simply returns COMPOSITE amongst the
PRIME_FACTORS. The calling Python program can then
collect the unfactored composites and call factor.exe
again with each of them sending them back to the
start of the factoring. If they successfully factor
on the second pass, Python then appends them to
the factors from the first pass to achieve a complete
factorization that factor.exe can produce in theory
but not in practice.
-- 
http://mail.python.org/mailman/listinfo/python-list


one more question

2009-07-14 Thread amrita

Dear all,

Just one more thing i want to ask that suppose i have a file like:---


 47 8   ALA   H H  7.85 0.02 1
 48 8   ALA   HAH  2.98 0.02 1
 49 8   ALA   HBH  1.05 0.02 1
 50 8   ALA   C C179.39  0.3 1
 51 8   ALA   CAC 54.67  0.3 1
 52 8   ALA   CBC 18.85  0.3 1
 53 8   ALA   N N123.95  0.3 1
10715   ALA   H H  8.05 0.02 1
10815   ALA   HAH  4.52 0.02 1

now what i want that i will make another file in which first it will write
the position of ALA lets say 8 then its name ALA and then the chemical
shift value for only three atoms C,CA and CB.

Means it will be someting like:

8  ALA  C = 179.39  CA = 54.67  CB = 18.85

I tried but its not coming.


Thanks,
Amrita Kumari
Research Fellow
IISER Mohali
Chandigarh
INDIA

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


Re: missing 'xor' Boolean operator

2009-07-14 Thread Miles Kaufmann

On Jul 15, 2009, at 12:07 AM, Dr. Phillip M. Feldman wrote:

I appreciate the effort that people have made, but I'm not impressed  
with any
of the answers.  For one thing, xor should be able to accept an  
arbitrary

number of input arguments (not just two)


You originally proposed this in the context of the existing short- 
circuit boolean operators.  Those operators (being infix) take only  
two operands.



and should return True if and only
if the number of input arguments that evaluate to True is odd


The existing and/or operators always return the value of one of the  
operands--not necessarily True or False--which is another important  
property, but one that can't be translated fully to xor.  Given the  
lack of context in your original post, hopefully you'll forgive me  
being unimpressed by your not being impressed. :)



Here's my code:

def xor(*args):
  """xor accepts an arbitrary number of input arguments, returning  
True
  if and only if bool() evaluates to True for an odd number of the  
input

  arguments."""

  result= False

  for arg in args:
 if bool(arg): result= not result

  return result


If all you want is a True or False result, I'd write it like this:

import operator
def xor(*args):
return reduce(operator.xor, map(bool, args)) # or imap

In order to make it act more like the other logical operators, I'd use  
MRAB's 2-argument xor as the reducer--though I can't really see the  
utility.


def xor2(a, b):
return (not b and a) or (not a and b)

def xor(*args):
return reduce(xor2, args)

You may also find this question interesting:

http://stackoverflow.com/questions/432842/

-Miles

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


Re: missing 'xor' Boolean operator

2009-07-14 Thread Dr. Phillip M. Feldman

I appreciate the effort that people have made, but I'm not impressed with any
of the answers.  For one thing, xor should be able to accept an arbitrary
number of input arguments (not just two), and should return True if and only
if the number of input arguments that evaluate to True is odd (see
www.mathworld.com article on xor).  Here's my code:

def xor(*args):
   """xor accepts an arbitrary number of input arguments, returning True
   if and only if bool() evaluates to True for an odd number of the input
   arguments."""

   result= False

   for arg in args:
  if bool(arg): result= not result

   return result



MRAB-2 wrote:
> 
> Ethan Furman wrote:
>> Robert Kern wrote:
>>> On 2009-07-14 14:56, Dr. Phillip M. Feldman wrote:
>>>
 != does do what I want, except that it doesn't indicate to someone 
 reading
 the code that the operands are being treated as logicals.  
 (Readability is
 supposed to be one of the major selling points of Python).  But, this
 is
 probably good enough.
>>>
>>>
>>> In the words of those greater than myself, "Not every one-liner needs 
>>> to be in the standard library."
>>>
>>> def xor(a, b):
>>> return bool(a) != bool(b)
>>>
>> 
>> Let's see...
>> 
>>   and returns the last object that is "true"
>>   or  returns the first object that is "true"
>> 
>> so should xor return the only object that is "true", else False/None?
>> 
>> def xor(a, b)
>> if a and b:
>> return None
>> elif a:
>> return a
>> elif b:
>> return b
>> else:
>> return None
>> 
> How about:
> 
> def xor(a, b):
>  return not b and a or not a and b
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/missing-%27xor%27-Boolean-operator-tp24485116p24491580.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: How to keep a function as a generator function when the yield operator is moved into its sub-functions??

2009-07-14 Thread Dave Angel

weafon wrote:

Hi guys,

I have a question about the usage of yield. As shown in the below 
example, in general, if there is a code segment commonly used by two 
or more functions, we may isolate the segment into a function and then 
call it from other functions if necessary.


def func1():
   
   while(cond):
   .
   commoncode()
   ...


def func2():
   
   while(cond):
   .
   commoncode()
   ...

def commoncode()
   
   
   

However, if there is a 'yield' operation in the common code segment, 
the isolation causes that func1 and func2 become a non-generator 
function!! Although I can prevent such an isolation by just 
duplicating the segment in func1 and func2 to keep both of them being 
generator functions, the code may become ugly and hard to maintain 
particularly when coomoncode() is long.


The problem may be resolved if I can define the commoncode() as an 
inline function or marco. Unfortunately, inline and marco do not seems 
to be implemented in python. Thus, how can I isolate a common segment 
into a function when there are yield operations in the common segment?


Thanks,
Weafon

You are implying there's something special or unique about yield in 
this.  Return has the same problem, and many other flow control 
constructs.   Also, variable definitions and scoping.


So you can't just copy any old bunch of adjacent lines out of two 
functions, put it into a third, and call it factoring.  Give us a 
specific example you're puzzled about, and we can try to solve it.


DaveA

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


Re: Tkinter / Entry widget problem

2009-07-14 Thread John McMonagle
Andras Szabo wrote:
> Hello. I searched the archives but couldn't find a solution to a problem
> related to the Entry widget in Tkinter.
> 
> When creating a pop-up window in an app, which contains an Entry widget,
> I want this widget to contain some default string, to have all this
> default string selected (as if the user had manually selected
> everything), and to have the focus transferred to this widget.
> 
> (The idea is then that if the window pops up, the user won't have to
> click or press Tab any more before being able to type what is needed in
> the textbox, overwriting what is written there already.)
> 
> I thought this might be the way to go:
> 
> entrybox=Entry(toplevel_parent_window)
> entrybox.insert(0,"Some default string")
> entrybox.select_range(0,END)
> entrybox.focus_set()
> entrybox.pack()
> 
> But it doesn't seem to work - the focus is not transferred to the Entry
> widget, and the text does not appear to be selected (even though after
> this entrybox.selection_present() returns True).
> 
> What am I doing wrong?
> 
> andras

You're probably not updating after the focus_set.

Try the following:

from Tkinter import *
r = Tk()


def click():
t = Toplevel(r)
e = Entry(t)
e.pack()
b = Button(t, text='Close', command=t.destroy)
b.pack()
e.insert(0, 'Default')
e.select_range(0, END)
e.focus_set()
r.update()



b = Button(r, text='Press', command=click)
b.pack()

r.mainloop()



Regards,

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


Re: explode()

2009-07-14 Thread Dave Angel



The one thing I really dislike about Python over PHP is that
Python can usually only appear in the cgi directory (unless other
arragements are made with your hosting provider or if you reconfigure
Apache on your own server if you have your own).  With PHP, I can put
them in any folder on my Web site without any problem.  

	Regards, 





		Fred 

  
You should talk to your hosting provider.  With mine, all you need do 
differently for directories other than cgi-bin is to do a chmod on the 
file to make it executable.  Have you tried that?  Is it hosted on Unix 
or Windows?


DaveA

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


Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Paul Rubin
Douglas Alan  writes:
> I can't see that a binary search tree would typically have
> particularly good cache-friendliness, so I can't see why a flat-array
> representation, such as is done for a binary heap, would have
> particularly worse cache-reference.

That is a good point.  Maybe we should be paying more attention to
cache-oblivious algorithms.

  http://en.wikipedia.org/wiki/Cache-oblivious_algorithm

H. Prokop's masters' thesis cited in the wiki article explains the
subject very well.  A fair amount of work has been done on it since
then, but not as much as one might expect.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why did you choose the programming language(s)you currently use?

2009-07-14 Thread Che M
On Jul 14, 11:55 am, Deep_Feelings  wrote:
> So you have chosen programming language "x" so shall you tell us why
> you did so , and  what negatives or positives it has ?

As a hobbyist--and not a real programmer*--I think I chose Python
(I don't really recall now) because of things like:

- There is a good community, including tutor list, etc.
- I wanted something that would run cross-platform (so no Visual
Basic).
- Preferred something free (so no REALBasic).
- I wanted a high level language.
- It seemed easiest to read and learn.  I like mandatory indents, for
example.
- There are a lot of libraries for it with good support.
- I liked the Zen of Python philosophy (to the extent I understood
it).
- Some high profile entities were using it, so it must have something
going for it.
- It was new enough to be a possible improvement over older languages
  while old enough to be established.
- Who can't like a computer language named Python?

Drawbacks:

- AFAIK, running multiple Python apps all show up in the Windows task
manager as
  "python.exe" (common to all non-compiled languages?) instead of the
app's name.
- Distributing as an executable is not as straightforward as I might
hope.
- I wish Python 3 wouldn't break my 2.5 code.
- If it could be quicker (compiled), that would be better. (But
haven't tried
  psyco or Shed Skin, etc.)
- I've found understanding web programming hard, but that might be
just the
  nature of web programming and not a Python thing.
- I wish wxPython had a more complete rich text editor (but overall it
is great).

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


does python have a generic object pool like commons-pool in Java

2009-07-14 Thread Rick Lawson
Appreciate any help on this. I am porting an app from Java to python
and need generic object pooling with hooks for object initialization /
cleanup and be able to specify an object timeout.

Thanks !
Rick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading floats from Excel using COM

2009-07-14 Thread John Machin
Alagalah  nekotaku.com> writes:

> 
> Hi, I am using the Range function to return a tuple from Excel.

[big snip]

Exact duplicate of question asked by "KB" on
http://groups.google.com/group/python-excel ... see my answer there.




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


Re: why did you choose the programming language(s)you currently use?

2009-07-14 Thread Martin P. Hellwig

Aahz wrote:

In article <4a5ccdd6$0$32679$9b4e6...@newsspool2.arcor-online.net>,
Stefan Behnel   wrote:

Deep_Feelings wrote:

So you have chosen programming language "x" so shall you tell us why
you did so , and  what negatives or positives it has ?

*duck*


Where do you get the duck programming language?


Probably floated around in the same C.

--
MPH
http://blog.dcuktec.com
'If consumed, best digested with added seasoning to own preference.'
--
http://mail.python.org/mailman/listinfo/python-list


Re: why did you choose the programming language(s)you currently use?

2009-07-14 Thread Chris Rebert
On Tue, Jul 14, 2009 at 5:32 PM, greg wrote:
> Deep_Feelings wrote:
>>
>> So you have chosen programming language "x" so shall you tell us why
>> you did so , and  what negatives or positives it has ?
>
> This summarises my reasons for choosing Python
> fairly well:
>
> http://www1.american.edu/cas/econ/faculty/isaac/choose_python.pdf

+1 PDF Of The Week

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


Re: Calling functions: Why this complicated ?

2009-07-14 Thread Mohan Parthasarathy
Chris,
Thanks for your clarifications


> > I am a newbie. I am reading
> > http://www.network-theory.co.uk/docs/pytut/KeywordArguments.html
> > Defining a function with "N" arguments and calling them in "M" different
> > ways. Why does it have to be this complicated ? I like the idea of
> calling
> > the function by explicitly naming the arguments, but there are so many
> other
> > ways here that is very confusing. Do people really use all these features
> ?
> > Perhaps, there is a equivalent book to "Javascript: Good Parts" for
> Python ?
>
> Oh $DEITY, don't even compare Python to JavaScript. At least in
> Python, when you try to access a non-existent attribute, a proper
> NameError exception is thrown rather than silently getting back
> "undefined"... (*has traumatic horror story flashback*)


I did not try to compare python to Javascript.  Just because there are ten
different ways of doing certain things, not all of them may be used. Over a
period of time, people tend to use certain features more and more.

Javascript is  a different beast where some of the features need to be
avoided for writing good programs. I don't know anything about python. But
it is possible that there is a subset that people use frequently which may
be sufficient to write good programs. Sure, that would not help me the
python interview test :-)

>
> The calling syntax is not so much complicated as it is liberating.
> Are you a C junkie who has never heard of named arguments?
>Just use the call sequence like you've always done.
> Are you a exacting Smalltalk or Objective-C person who likes to name
> all the arguments all the time for clarity?
>You can do that.


That's where I fit. I did not expect to see more than that :-)


> Do you want to call a function with lots of default arguments but only
> want to override a couple of them?
>Specifying them by name lets you do that succinctly.
> Do you not want to have to worry about the order of the parameters
> because it seems kinda arbitrary?
>Then specify the arguments by name.
> etc...
>
> And if you try and specify an argument twice, Python will throw an
> error, so anything truly confusing will get caught right away.
> And there's only one definition syntax, so while the call could be
> complicated, figuring out what it means by looking to the definition
> is fairly easy.
>
> There really aren't that many ways it's done in practice. In practice,
> the following styles cover 90% of cases:
> - All named arguments: foo(bar=a, baz=b, qux=c)
> - All sequential arguments: foo(a, b, c)
> - All sequential arguments, with a few optional arguments given by
> name: foo(a, b, c, flag=True, style=qux)

- Simple pass-through: foo(*args, **kwargs)
>
> Granted, there's 4 of them, but each taken by itself seems pretty easy
> to read, IMHO.


So, all four of them above has its use cases in practice i guess.

thanks
mohan



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


Re: why did you choose the programming language(s)you currently use?

2009-07-14 Thread greg

Deep_Feelings wrote:

So you have chosen programming language "x" so shall you tell us why
you did so , and  what negatives or positives it has ?


This summarises my reasons for choosing Python
fairly well:

http://www1.american.edu/cas/econ/faculty/isaac/choose_python.pdf

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


Reading floats from Excel using COM

2009-07-14 Thread Alagalah
Hi, I am using the Range function to return a tuple from Excel.

The data in the range (nREVENUE) in the excel file is 100.0, 101.0,
102.0, 103.0, 104.0

I can successfully iterate across the tuple and list, but when I try
and cast to a float to do some math, I get:

  File "C:\Python25\lib\site-packages\win32com\client\__init__.py",
line 454, in __getattr__
raise AttributeError, "'%s' object has no attribute '%s'" % (repr
(self), attr)
AttributeError: '' object has no attribute
'__float__'

 CODE *
import win32com.client
import os

excel=win32com.client.Dispatch("Excel.Application")
excel.Visible=0
excel.DisplayAlerts=False

#This is the file that contains the macro
xlsname=os.path.join(os.getcwd(),"nametest.xlsx")
nametest=excel.Workbooks.Open(xlsname)

revenue_list=excel.Range("nREVENUE")

revenue=[]
revenue.extend(revenue_list)

for i in range(len(revenue)):
rev=revenue[i]
print float(rev)

excel.Quit()
del excel



I need to use COM as I will eventually need formula support, otherwise
I would use xlutils.

Any advice on how to cast the elements to a float would be greatly
appreciated!
-- 
http://mail.python.org/mailman/listinfo/python-list


compiling python

2009-07-14 Thread Mag Gam
At my university we are trying to compile python with --enable-shared
however when I do a make many things fail. Is it a good idea to
compile python with shared libraries? It seems mod-python needs it
this way.

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


Re: missing 'xor' Boolean operator

2009-07-14 Thread Ethan Furman

Christian Heimes wrote:

Chris Rebert wrote:


Using the xor bitwise operator is also an option:
bool(x) ^ bool(y)



I prefer something like:

bool(a) + bool(b) == 1

It works even for multiple tests (super xor):

  if bool(a) + bool(b) + bool(c) + bool(d) != 1:
  raise ValueError("Exactly one of a, b, c and d must be true")

Christian



super_xor!  I like it!

In [23]: def super_xor(args, failure=False):
   : found_one = False
   : for item in args:
   : if item:
   : if found_one:
   : return failure
   : else:
   : found_one = item
   : return found_one or failure

In [25]: super_xor((0, 1, 0, []))
Out[25]: 1

In [26]: super_xor((0, 1, 0, [],('this',)))
Out[26]: False

In [27]: super_xor((0, {}, 0, [],()))
Out[27]: False

In [16]: def super_or(args, failure=False):
   : for item in args:
   : if item:
   : return item
   : else:
   : return failure
   :

In [17]: super_or((None, [], 0, 3, {}))
Out[17]: 3

In [18]: super_or((None, [], 0, (), {}))
Out[18]: False

In [19]: def super_and(args, failure=False):
   : for item in args:
   : if not item:
   : return failure
   : else:
   : return item
   :

In [20]: super_and((1, 2, 3))
Out[20]: 3

In [21]: super_and((1, 2, 3, 4))
Out[21]: 4

In [22]: super_and((1, 0, 3, 4))
Out[22]: False

A whole family of supers.  :)

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


Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Douglas Alan
I wrote:

> On Jul 14, 8:10 am, Piet van Oostrum  wrote:
>
> > Of course you can take any BST algorithm and replace pointers by indices
> > in the array and allocate new elements in the array. But then you need
> > array elements to contain the indices for the children explicitely.


> And why is this a problem?

Oh, I'm sorry -- I see what you are saying now. You're saying you can
just implement a normal binary search tree, but store the tree nodes
in an array, as if it were a chunk of memory, and use array indices as
pointers, rather than using memory addresses as pointers.

Fair enough, but I'm not sure what that would buy you. Other than,
perhaps some improved locality of reference, and the potential to
perhaps get the pointers take up less space if you know the array is
never going to grow to be very large.

|>ouglas

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


Re: Calling functions: Why this complicated ?

2009-07-14 Thread Chris Rebert
On Tue, Jul 14, 2009 at 1:40 PM, Mohan Parthasarathy wrote:
> Hi,
> I am a newbie. I am reading
> http://www.network-theory.co.uk/docs/pytut/KeywordArguments.html
> Defining a function with "N" arguments and calling them in "M" different
> ways. Why does it have to be this complicated ? I like the idea of calling
> the function by explicitly naming the arguments, but there are so many other
> ways here that is very confusing. Do people really use all these features ?
> Perhaps, there is a equivalent book to "Javascript: Good Parts" for Python ?

Oh $DEITY, don't even compare Python to JavaScript. At least in
Python, when you try to access a non-existent attribute, a proper
NameError exception is thrown rather than silently getting back
"undefined"... (*has traumatic horror story flashback*)

The calling syntax is not so much complicated as it is liberating.
Are you a C junkie who has never heard of named arguments?
Just use the call sequence like you've always done.
Are you a exacting Smalltalk or Objective-C person who likes to name
all the arguments all the time for clarity?
You can do that.
Do you want to call a function with lots of default arguments but only
want to override a couple of them?
Specifying them by name lets you do that succinctly.
Do you not want to have to worry about the order of the parameters
because it seems kinda arbitrary?
Then specify the arguments by name.
etc...

And if you try and specify an argument twice, Python will throw an
error, so anything truly confusing will get caught right away.
And there's only one definition syntax, so while the call could be
complicated, figuring out what it means by looking to the definition
is fairly easy.

There really aren't that many ways it's done in practice. In practice,
the following styles cover 90% of cases:
- All named arguments: foo(bar=a, baz=b, qux=c)
- All sequential arguments: foo(a, b, c)
- All sequential arguments, with a few optional arguments given by
name: foo(a, b, c, flag=True, style=qux)
- Simple pass-through: foo(*args, **kwargs)

Granted, there's 4 of them, but each taken by itself seems pretty easy
to read, IMHO.

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


Re: missing 'xor' Boolean operator

2009-07-14 Thread Scott David Daniels

Ethan Furman wrote:

  and returns the last object that is "true"

A little suspect this.
_and_ returns the first object that is not "true," or the last object.

  or  returns the first object that is "true"

Similarly:
_or_ returns the first object that is "true," or the last object.


so should xor return the only object that is "true", else False/None?


Xor has the problem that in two cases it can return neither of its args.
Not has behavior similar in those cases, and we see it returns False or
True.  The Pythonic solution is therefore to use False.


def xor(a, b)
if a and b:
return None
elif a:
return a
elif b:
return b
else:
return None


def xor(a, b):
if bool(a) == bool(b):
return False
else:
return a or b

Side-effect counting in applications of bool(x) is ignored here.
If minimizing side-effects is needed:

def xor(a, b):
if a:
if not b:
return a
elif b:
return b
return False

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Douglas Alan
On Jul 14, 9:19 am, Scott David Daniels  wrote:

> It may well be that there is no good simple solution, and people avoid
> writing about non-existent algorithms.

I can't imagine why that should be the case. The CLRS textbook on
algorithms, for instance, goes to some pains to mathematically prove
that there is no comparison sort that can operate in faster than O(n
log n) time.

And any decent discussion of rabies would be sure to mention that
there is no known cure.

CLRS talks about binary heaps, binary search trees, and treaps, and it
shows how to maintain a binary heap in a flat array efficiently (n log
n time overall), but it never even seems to bring up the subject as to
whether a binary search tree or a treap can also be efficiently
maintained in a flat array.

Though it may be the case that these questions are left as exercises
for the student, and therefore buried in the exercises and problem
sets that I didn't read carefully.

> Piet van Oostrum wrote:

> > Of course you can take any BST algorithm and replace pointers by indices
> > in the array and allocate new elements in the array. But then you need
> > array elements to contain the indices for the children explicitely.

> And you loower your locality of reference (cache-friendliness).
> Note the insert in Python, for example, is quite cache-friendly.

I can't see that a binary search tree would typically have
particularly good cache-friendliness, so I can't see why a flat-array
representation, such as is done for a binary heap, would have
particularly worse cache-reference.

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


Re: decorators - would be nice if...

2009-07-14 Thread Jack Diederich
On Tue, Jul 14, 2009 at 5:44 PM, Ken Seehart wrote:
> Almost every time I use decorators, I find myself wishing I had access
> to the local namespace of the context from which the decorator is
> executed.  In practice, decorator is being applied to a method, so the
> namespace in question would be the dictionary of the class being created.

As other mentioned, an example would make it clearer what you are trying to do.

> Similarly, before decorators were around, I often found myself lamenting
> the fact that a class is not created until after it's scope is
> completed, since this makes certain kinds of metaprogramming more
> difficult.  But after digging deeper, I realized why it is the way it
> is, so I don't complain about that.

Py3k to the rescue!  Because the metaclass is defined outside of the
class body it is possible to pass in a metaclass that uses a custom
dictionary.  This was added to make some common cases easier (like
knowing in which order members were defined).  This is not
backportable to 2.6 because the __metaclass__ is defined inside the
class body and possibly anywhere in the class body.

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


Re: why did you choose the programming language(s)you currently use?

2009-07-14 Thread Scott David Daniels

Aahz wrote:

In article <4a5ccdd6$0$32679$9b4e6...@newsspool2.arcor-online.net>,
Stefan Behnel   wrote:

Deep_Feelings wrote:

So you have chosen programming language "x" so shall you tell us why
you did so , and  what negatives or positives it has ?

*duck*


Where do you get the duck programming language?


It shares a type system with Python, of course.  :-)

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Douglas Alan
On Jul 14, 8:10 am, Piet van Oostrum  wrote:

> Of course you can take any BST algorithm and replace pointers by indices
> in the array and allocate new elements in the array. But then you need
> array elements to contain the indices for the children explicitely.

And why is this a problem? This is how binary heaps are typically
implemented, and it all works swimmingly. The node rotations for
keeping a binary heap balanced turn out to be suitable for
representation in a flat array. I.e., when you do the node rotations,
you only ever have to copy log n array elements.

In general, however, you can't move nodes around so easily when
represented in a flat array. A node movement in a tree represented
with pointers, might involves changing just two pointers, while when
represented as a flat array, might involve copying most of the array
to maintain the tree invariants. It just so turns out that maintaining
the invariants for a binary heap does not have this issue.

This is why I was curious about treaps, which are a type of binary
heap. The CLRS textbook on algorithms discusses treaps, but doesn't
ever mention whether they are as fortunate as less constrained binary
heaps. I'm sure I could work out for myself whether the treap
rotations are suitable for storage in a flat array, but I might make a
mistake somewhere in my reasoning, and then never know the true
answer!

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


Passing handlers between bound c++ libs

2009-07-14 Thread Freyr
I have a python bound physics library that uses handler to process
events. The passing of handlers between c++ and python causes a huge
overhead slowing down the process.  Can I implement a handler in my
custom python bound c++ lib B and pass it to blackbox python bound c++
lib A so that A would call B directly without passing through the
python layer?  Or to phrase the question differently:  Can I pass a
handler from B through python to A so that A will invoke B with out
calling into python code?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: missing 'xor' Boolean operator

2009-07-14 Thread Christian Heimes
Chris Rebert wrote:
> Using the xor bitwise operator is also an option:
> bool(x) ^ bool(y)

I prefer something like:

bool(a) + bool(b) == 1

It works even for multiple tests (super xor):

  if bool(a) + bool(b) + bool(c) + bool(d) != 1:
  raise ValueError("Exactly one of a, b, c and d must be true")

Christian

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


Re: How to unbuffer Python's output

2009-07-14 Thread David Stanek
2009/7/14 Lily Gao :
> Hi, All
>
> I am calling a python program in perl and use redirection,
>
> Like :
>
> `python x.py > 1.log 2>&1`

Try tihs instead:
python x.py 2>&1 > 1.log

-- 
David
blog: http://www.traceback.org
twitter: http://twitter.com/dstanek
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The meaning of "="

2009-07-14 Thread Aahz
In article , Piet van Oostrum   wrote:
>> a...@pythoncraft.com (Aahz) (A) wrote:
>
>>A> In article , Piet van Oostrum
>>A>  wrote: 
>
 And to get c.x = 4 working you also need a __setitem__. 
>
>>A> Nope.  You do need __setitem__ so that this works:
>
>>A> c['x'] = 4
>
>Sorry, I meant such that c.x = 4 does the same as c['x'] = 4 because
>that was what the OP wanted (I think).

c.x = 4 
already updates the instance dict, so there's no need to change any class
methods to support it.  That is, IME it's much better to add methods to
a regular class to make it more dict-like using the built-in instance
dict rather than changing any of the attribute mechanisms.  If you're
really curious, I recommend trying several approaches yourself to see
what works better.  ;-)
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Efficient binary search tree stored in a flat array?

2009-07-14 Thread Douglas Alan
On Jul 14, 7:38 am, Florian Brucker  wrote:

> Douglas Alan wrote:

> > Thank you. My question wasn't intended to be Python specific, though.
> > I am just curious for purely academic reasons about whether there is
> > such an algorithm. All the sources I've skimmed only seem to the
> > answer the question via omission. Which is kind of strange, since it
> > seems to me like an obvious question to ask.

> IIRC comp.programming would be the place to ask such questions.

Thanks, yes that does look like a good place to post such questions.
Unfortunately, it also looks to be overrun with stories on "hot girls
top and bottom sexy movie", though I'm sure I can ignore those. I'm
scared to look at the posting on "tricky bit twiddling", though.

|>ouglas

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


Re: How to check if any item from a list of strings is in a big string?

2009-07-14 Thread Scott David Daniels

Nobody wrote:

On Tue, 14 Jul 2009 02:06:04 -0300, Gabriel Genellina wrote:


Matt, how many words are you looking for, in how long a string ?
Were you able to time any( substr in long_string ) against re.compile
( "|".join( list_items )) ?
There is a known algorithm to solve specifically this problem  
(Aho-Corasick), a good implementation should perform better than R.E. (and  
better than the gen.expr. with the advantage of returning WHICH string  
matched)


Aho-Corasick has the advantage of being linear in the length of the
patterns, so the setup may be faster than re.compile(). The actual
searching won't necessarily be any faster (assuming optimal
implementations; I don't know how safe that assumption is).


Having done a fast Aho-Corasick implementation myself, I can assure you
that the actual searching can be incredibly fast.  RE conversion usually
goes to a slightly more general machine than the Aho-Corasick processing
requires.

--Scott David Daniels
scott.dani...@acm.org

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


Re: decorators - would be nice if...

2009-07-14 Thread Carl Banks
On Jul 14, 2:44 pm, Ken Seehart  wrote:
[snip]
(e.g. there does not
> seem to be a good way to use multiple metaclasses in a class hierarchy,
> and more generally you can't stack them on top of each other (you can
> only have one metaclass per class)).
>
> Thoughts?

If "stacking" metaclasses (whatever that means) is a possible approach
to your problem, you might want to ask yourself if you're trying to be
too clever.

Would you like to give us an example of a decorator you think would
benefit from having access to local namespace?  We might be able to
suggest other possibilities.


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


Re: missing 'xor' Boolean operator

2009-07-14 Thread Ethan Furman

MRAB wrote:

Ethan Furman wrote:


Robert Kern wrote:


On 2009-07-14 14:56, Dr. Phillip M. Feldman wrote:

!= does do what I want, except that it doesn't indicate to someone 
reading
the code that the operands are being treated as logicals.  
(Readability is
supposed to be one of the major selling points of Python).  But, 
this is

probably good enough.




In the words of those greater than myself, "Not every one-liner needs 
to be in the standard library."


def xor(a, b):
return bool(a) != bool(b)



Let's see...

  and returns the last object that is "true"
  or  returns the first object that is "true"

so should xor return the only object that is "true", else False/None?

def xor(a, b)
if a and b:
return None
elif a:
return a
elif b:
return b
else:
return None


How about:

def xor(a, b):
return not b and a or not a and b


In [12]: not 1 and 0 or 1 and not 0
Out[12]: True

In [13]: not 0 and 0 or 0 and not 0
Out[13]: 0

In [14]: not 1 and 1 or 1 and not 1
Out[14]: False

In [15]: not [] and [] or [] and not []
Out[15]: []

Doesn't produce consistent objects, sometimes bool, sometimes something 
else.  'Course, it all depends on what you need.


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


Re: decorators - would be nice if...

2009-07-14 Thread Diez B. Roggisch

Ken Seehart schrieb:

Almost every time I use decorators, I find myself wishing I had access
to the local namespace of the context from which the decorator is
executed.  In practice, decorator is being applied to a method, so the
namespace in question would be the dictionary of the class being created.


You can access the instance.

def decorator(method):
def _d(self, *args, **kwargs):
print self.__dict__
return method(self, *args, **kwargs)

return _d

class Foo(object):

@decorator
def bar(self, a, b):
print "bar"


f = Foo()

f.bar(1, 2)

So what exactly it is you are missing? The method's locals()?

And could you explain *why* you are missing this?


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


Re: why did you choose the programming language(s)you currently use?

2009-07-14 Thread Nobody
On Tue, 14 Jul 2009 11:47:08 -0700, Paul Rubin wrote:

>> - unlimited precision integers
>> - easy to program
>> - IDE not required
>> - reasonable speed
>> - math library needs to include number theoretic functions
>>   like GCD, LCM, Modular Inverse, etc.
>> - not fucking retarded like F#
> 
> Have you looked at Haskell?

Given his comment about F#, I have a suspicion that he might be
dogmatically opposed to functional languages generally.

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


Re: missing 'xor' Boolean operator

2009-07-14 Thread MRAB

Ethan Furman wrote:

Robert Kern wrote:

On 2009-07-14 14:56, Dr. Phillip M. Feldman wrote:

!= does do what I want, except that it doesn't indicate to someone 
reading
the code that the operands are being treated as logicals.  
(Readability is

supposed to be one of the major selling points of Python).  But, this is
probably good enough.



In the words of those greater than myself, "Not every one-liner needs 
to be in the standard library."


def xor(a, b):
return bool(a) != bool(b)



Let's see...

  and returns the last object that is "true"
  or  returns the first object that is "true"

so should xor return the only object that is "true", else False/None?

def xor(a, b)
if a and b:
return None
elif a:
return a
elif b:
return b
else:
return None


How about:

def xor(a, b):
return not b and a or not a and b
--
http://mail.python.org/mailman/listinfo/python-list


Re: bad behaviour in interactive Python prompt

2009-07-14 Thread ~km
On 14 Jul., 15:26, Mark Dickinson  wrote:
> Where did your version of Python 2.6 come from?
>
> If you built your copy of Python 2.6 from source, then the problem is
> probably that either the readline library is missing, or (much more
> likely) the include files for the readline library are missing.  Look
> for a package called something like libreadline5-dev or readline-devel
> and install it, and then try rebuilding Python.
>
> Mark

Yes, I built it from source and never thought that there might be such
a library. Now I've re-compiled and my problem is solved!

Have many thanks Mark, and Chris Rebert, too, who responded to my
deleted post, which I've received per mail. Sorry for that incidence.

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


Re: bad behaviour in interactive Python prompt

2009-07-14 Thread ~km
On 14 Jul., 15:26, Mark Dickinson  wrote:
> Where did your version of Python 2.6 come from?
>
> If you built your copy of Python 2.6 from source, then the problem is
> probably that either the readline library is missing, or (much more
> likely) the include files for the readline library are missing.  Look
> for a package called something like libreadline5-dev or readline-devel
> and install it, and then try rebuilding Python.
>
> Mark

Yes, I built it from source and never thought that there might be such
a library. Now I've re-compiled and my problem is solved!

Have many thanks Mark, and Chris Rebert, too, who responded to my
deleted post, which I've received per mail. Sorry for that incidence.

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


decorators - would be nice if...

2009-07-14 Thread Ken Seehart

Almost every time I use decorators, I find myself wishing I had access
to the local namespace of the context from which the decorator is
executed.  In practice, decorator is being applied to a method, so the
namespace in question would be the dictionary of the class being created.

Similarly, before decorators were around, I often found myself lamenting
the fact that a class is not created until after it's scope is
completed, since this makes certain kinds of metaprogramming more
difficult.  But after digging deeper, I realized why it is the way it
is, so I don't complain about that.

But it would have been a simple thing to add an argument 'locals' to the
decorator specification.  It's somewhat more difficult to add that now
because of compatibility issues, but perhaps there is a way to get the
same effect.

I can work around all of this by making my decorators just store data to
be processed by a metaclass, but that solution is less elegant.  Also,
it has the slight disadvantage of requiring the use of a metaclass which
would otherwise not be necessary.  I prefer to save metaclass
implementation as a last resort for various reasons (e.g. there does not
seem to be a good way to use multiple metaclasses in a class hierarchy,
and more generally you can't stack them on top of each other (you can
only have one metaclass per class)).

Thoughts?

- Ken


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


Re: How to check if any item from a list of strings is in a big string?

2009-07-14 Thread Nobody
On Tue, 14 Jul 2009 02:06:04 -0300, Gabriel Genellina wrote:

>> Matt, how many words are you looking for, in how long a string ?
>> Were you able to time any( substr in long_string ) against re.compile
>> ( "|".join( list_items )) ?
> 
> There is a known algorithm to solve specifically this problem  
> (Aho-Corasick), a good implementation should perform better than R.E. (and  
> better than the gen.expr. with the advantage of returning WHICH string  
> matched)

Aho-Corasick has the advantage of being linear in the length of the
patterns, so the setup may be faster than re.compile(). The actual
searching won't necessarily be any faster (assuming optimal
implementations; I don't know how safe that assumption is).

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


Re: missing 'xor' Boolean operator

2009-07-14 Thread Ethan Furman

Robert Kern wrote:

On 2009-07-14 14:56, Dr. Phillip M. Feldman wrote:

!= does do what I want, except that it doesn't indicate to someone 
reading
the code that the operands are being treated as logicals.  
(Readability is

supposed to be one of the major selling points of Python).  But, this is
probably good enough.



In the words of those greater than myself, "Not every one-liner needs to 
be in the standard library."


def xor(a, b):
return bool(a) != bool(b)



Let's see...

  and returns the last object that is "true"
  or  returns the first object that is "true"

so should xor return the only object that is "true", else False/None?

def xor(a, b)
if a and b:
return None
elif a:
return a
elif b:
return b
else:
return None

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


Re: Why not enforce four space indentations in version 3.x?

2009-07-14 Thread David Bolen
John Nagle  writes:

>Python 3 enforces the rule that you can't mix tabs and spaces
> for indentation in the same file.  That (finally) guarantees that
> the indentation you see is what the Python parser sees.  That's
> enough to prevent non-visible indentation errors.

Are you sure?  It seems to restrict them in the same block, but not in
the entire file.  At least I was able to use both space and tab
indented blocks in the same file with Python 3.0 and 3.1.  I suspect
precluding any mixture at all at the file level would be more
intrusive, for example, when trying to combine multiple code sources
in a single file.

Not that this really changes your final point, since the major risk
of a mismatch between the parser vs. visual display is within a single
block.

>It also means that the Python parser no longer has to have
> any concept of how many spaces equal a tab.  So the problem
> is now essentially solved.

"has to have" being a future possibility at this point, since I'm
fairly sure the 3.x parser does technically still have the concept of
a tab size of 8, though now it can be an internal implementation
detail.

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


Re: The meaning of "="

2009-07-14 Thread Piet van Oostrum
> a...@pythoncraft.com (Aahz) (A) wrote:

>A> In article , Piet van Oostrum
>A>  wrote: 

>>> And to get c.x = 4 working you also need a __setitem__. 

>A> Nope.  You do need __setitem__ so that this works:

>A> c['x'] = 4

Sorry, I meant such that c.x = 4 does the same as c['x'] = 4 because
that was what the OP wanted (I think).
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to keep a function as a generator function when the yield operator is moved into its sub-functions??

2009-07-14 Thread Diez B. Roggisch

weafon schrieb:

Hi guys,

I have a question about the usage of yield. As shown in the below 
example, in general, if there is a code segment commonly used by two or 
more functions, we may isolate the segment into a function and then call 
it from other functions if necessary.


def func1():
   
   while(cond):
   .
   commoncode()
   ...


def func2():
   
   while(cond):
   .
   commoncode()
   ...

def commoncode()
   
   
   

However, if there is a 'yield' operation in the common code segment, the 
isolation causes that func1 and func2 become a non-generator function!! 



No. Not writing them as generators makes them a non-generator-function.

You are way to unspecific with your examples. But if func1 and func2 are 
themselves supposed to be generators, there is nothing preventing you 
from using them as such.


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


Re: missing 'xor' Boolean operator

2009-07-14 Thread Robert Kern

On 2009-07-14 14:56, Dr. Phillip M. Feldman wrote:

!= does do what I want, except that it doesn't indicate to someone reading
the code that the operands are being treated as logicals.  (Readability is
supposed to be one of the major selling points of Python).  But, this is
probably good enough.


In the words of those greater than myself, "Not every one-liner needs to be in 
the standard library."


def xor(a, b):
return bool(a) != bool(b)

--
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: Best Way to Handle All Exceptions

2009-07-14 Thread Piet van Oostrum
> Carl Banks  (CB) wrote:

>CB> On Jul 14, 4:48 am, Lawrence D'Oliveiro central.gen.new_zealand> wrote:
>>> In message <93f6a517-63d8-4c80-
>>> 
>>> bf19-4614b7099...@m7g2000prd.googlegroups.com>, Carl Banks wrote:
>>> > Or would you rather let all unexpected exceptions print to standard
>>> > error, which is often a black hole in non-interactive sitations?
>>> 
>>> Since when?
>>> 
>>> Cron, for example, collects standard error and mails it to you.

>CB> 1. Cron is only one way to run programs non-interactively. (Would that
>CB> work with, say, Windows services?)
>CB> 2. Many systems don't run MTAs these days
>CB> 3. In my experience the pipeline from cron to mail delivery is error
>CB> prone, mainly due to the complexity of configuring MTAs
>CB> 4. Even if all this works, you might just want to do your logging
>CB> directly in Python anyway

Even then, I think the program would get structured better if the FTP
code would only catch FTP-specific errors, including socket errors
(which is what all_errors does) and to catch programming errors etc on
another level, e.g by the mentioned sys.excepthook.
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Calling functions: Why this complicated ?

2009-07-14 Thread Mohan Parthasarathy
Hi,
I am a newbie. I am reading

http://www.network-theory.co.uk/docs/pytut/KeywordArguments.html

Defining a function with "N" arguments and calling them in "M" different
ways. Why does it have to be this complicated ? I like the idea of calling
the function by explicitly naming the arguments, but there are so many other
ways here that is very confusing. Do people really use all these features ?
Perhaps, there is a equivalent book to "Javascript: Good Parts" for Python ?

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


ANN: RuPy '09 Conference

2009-07-14 Thread Jakub P. Nowak
RuPy 2009 :: Strongly Dynamic Conference

Poznan, Poland
November 7-8, 2009

:: Call for speakers

RuPy is a conference about dynamically typed programming languages.
Held for the first time in April 2007 it gathered enthusiasts
from Poland and other countries.

The idea behind the conference is to liven up the
community and make these technologies more popular in Europe.

The first conference was a middle-sized one but came out as
a huge success. We believe it was a great experience for both
attendees and speakers.

RuPy 2009 committee is looking for speakers willing to present
a Python, Ruby, Groovy or any other related subject.
If you have an interesting talk in mind go ahead and submit a
talk proposal. The talk proposal should include a talk title,
brief introduction and your short resume/biography.

To our invited speakers we offer free accommodation, full
board and possibility to interact with a very lively IT community.
You are also free to participate in all the extra events -
'Geek party' always turns out great!

You can also support us by linking to our site and informing
all your friends about the event and the possibility to submit
a talk proposal.

Potential speakers should submit an abstract using the following
form:

https://spreadsheets.google.com/viewform?formkey=dEFEYndsQWR2TGFzRFpzcU9IbFlCT2c6MA..

by September 30th, 2009 for consideration.

If you have any special presentation needs, let us know.

For more details check our site:
http://www.rupy.eu

Best regards,
--
Jakub P. Nowak
RuPy Committee
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why did you choose the programming language(s)you currently use?

2009-07-14 Thread Aahz
In article <4a5ccdd6$0$32679$9b4e6...@newsspool2.arcor-online.net>,
Stefan Behnel   wrote:
>Deep_Feelings wrote:
>>
>> So you have chosen programming language "x" so shall you tell us why
>> you did so , and  what negatives or positives it has ?
>
>*duck*

Where do you get the duck programming language?
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: explode()

2009-07-14 Thread Jonathan Gardner
On Jul 14, 6:56 am, Fred Atkinson  wrote:
>
> Agreed, it doesn't.  But if my hosting provider won't change it, I'm
> stuck with it.  
>

Nowadays you can find hosts that allow you to run FastCGI scripts in
any language for dirt cheap. (Hostmonster for instance.) If your host
doesn't allow it, it's time to upgrade.

Any hosting service that supports Ruby on Rails supports Python
through the exact same mechanism.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: missing 'xor' Boolean operator

2009-07-14 Thread Chris Rebert
> Mark Dickinson wrote:
>>
>> On Jul 14, 7:25 pm, "Dr. Phillip M. Feldman" 
>> wrote:
>>> Current Boolean operators are 'and', 'or', and 'not'.  It would be nice
>>> to
>>> have an 'xor' operator as well.
>>
>> Hmm.  I don't think 'nice' is sufficient.  You'd need to make the case
>> that it's sufficiently useful to justify adding a new keyword 'xor' to
>> the language;  I suspect that would be an uphill struggle. :)
>>
>> I'll just note that:
>>
>> (1) It's easy to emulate xor:  'x xor y' <-> bool(x) != bool(y)
>>
>> (2) 'and' and 'or' are special in that they have useful short-
>> circuiting behaviour; xor doesn't have this property (that is, you
>> always need to evaluate *both* operands to determine the result).
>>
>> I'd also guess that 'xor' would be much less used than 'and' or 'or',
>> but maybe that's just a reflection of the sort of code that I tend to
>> write.
On Tue, Jul 14, 2009 at 12:56 PM, Dr. Phillip M.
Feldman wrote:

> Here's a related issue: I would like to see an option for type checking on
> operands of logical operators, so that attempting to apply a logical
> operator to non-Boolean entities generates a warning message.  With operand
> type checking, 'xor' and != would be different.

That's probably not gonna happen. Python is dynamically and duck
typed, and has a sweet coercion system (__bool__ or __nonzero__
depending on your version) to coerce non-booleans to booleans in a
sensible and useful way. So, it's not gonna change any time soon.

Some illustrative examples:
>>> #empty containers considered false
>>> bool([] or {} or set() or "")
>>> False
>>> #zero and null considered false
>>> bool(0 or None)
>>> False
>>> #anything else is, by default, true
>>> bool(object())
>>> True

And like I said, a class can override a special method to provide
whatever boolean semantics are desired. It's surprisingly handy.

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


Re: one-time factory in python for an experienced java guy

2009-07-14 Thread Jonathan Gardner
On Jul 14, 7:03 am, phonky  wrote:
>
> Now, I do not know yet how the account number scheme looks like.

Exactly. The data store knows a lot more than the client (your
program) will ever know.

The correct answer is to do nothing. Use your data store to generate
the IDs for you. The implementations discussed here will not generate
unique IDs across invocations, but the data store will persist the
sequence for you appropriately.

The more correct answer is to abstract away the client to your data
store as well. See SQLAlchemy.

If you're writing a data store, you're doing it wrong. See PostgreSQL,
MySQL, or any other data store out there that are perfectly fine for
development and production use.

I like to use UUIDs for the IDs. Others like big ints that are a
sequence. I've seen people use encrypted big ints, basically random
strings that aren't really random. In the end, you only have to change
the code that talks to the data store, and the rest of your program
only cares about the equality of the id.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: missing 'xor' Boolean operator

2009-07-14 Thread Dr. Phillip M. Feldman

!= does do what I want, except that it doesn't indicate to someone reading
the code that the operands are being treated as logicals.  (Readability is
supposed to be one of the major selling points of Python).  But, this is
probably good enough.

Here's a related issue: I would like to see an option for type checking on
operands of logical operators, so that attempting to apply a logical
operator to non-Boolean entities generates a warning message.  With operand
type checking, 'xor' and != would be different.


Mark Dickinson wrote:
> 
> On Jul 14, 7:25 pm, "Dr. Phillip M. Feldman" 
> wrote:
>> Current Boolean operators are 'and', 'or', and 'not'.  It would be nice
>> to
>> have an 'xor' operator as well.
> 
> Hmm.  I don't think 'nice' is sufficient.  You'd need to make the case
> that it's sufficiently useful to justify adding a new keyword 'xor' to
> the language;  I suspect that would be an uphill struggle. :)
> 
> I'll just note that:
> 
> (1) It's easy to emulate xor:  'x xor y' <-> bool(x) != bool(y)
> 
> (2) 'and' and 'or' are special in that they have useful short-
> circuiting behaviour; xor doesn't have this property (that is, you
> always need to evaluate *both* operands to determine the result).
> 
> I'd also guess that 'xor' would be much less used than 'and' or 'or',
> but maybe that's just a reflection of the sort of code that I tend to
> write.
> 
> --
> Mark
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: 
http://www.nabble.com/missing-%27xor%27-Boolean-operator-tp24485116p24486661.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: missing 'xor' Boolean operator

2009-07-14 Thread Mark Dickinson
On Jul 14, 8:43 pm, Chris Rebert  wrote:
> On Tue, Jul 14, 2009 at 11:47 AM, Mark Dickinson wrote:
> > (1) It's easy to emulate xor:  'x xor y' <-> bool(x) != bool(y)
>
> Using the xor bitwise operator is also an option:
> bool(x) ^ bool(y)

Good point.  For some reason I expected bitwise operations on bools to
return ints rather than bools.  Now I know better. :-)

Thanks,

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


python-list@python.org

2009-07-14 Thread Chris Rebert
On Tue, Jul 14, 2009 at 12:15 PM, ~km wrote:
> Hi,
>
> I'm experiencing a strange behaviour of the Python prompt when using
> the
> four arrow keys ( not the VIM' nor Emacs' ones ;-) ). Instead of
> getting
> the previous and next command respectively I get ugly characters. See
> it
> yourself:
> http://tinypic.com/view.php?pic=m78cgp&s=3
>
> This is not directly Python-specific, but you feel quite handicapped
> if
> you must rewrite each command again... so my obvious question is:
>
> How can I fix this? Please, let me know if you can tell me something.

I would guess that your Python wasn't compiled with GNU readline support.
Do you get an error if you `import readline`?

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


Re: missing 'xor' Boolean operator

2009-07-14 Thread Chris Rebert
On Tue, Jul 14, 2009 at 11:47 AM, Mark Dickinson wrote:
> On Jul 14, 7:25 pm, "Dr. Phillip M. Feldman" 
> wrote:
>> Current Boolean operators are 'and', 'or', and 'not'.  It would be nice to
>> have an 'xor' operator as well.
>
> Hmm.  I don't think 'nice' is sufficient.  You'd need to make the case
> that it's sufficiently useful to justify adding a new keyword 'xor' to
> the language;  I suspect that would be an uphill struggle. :)
>
> I'll just note that:
>
> (1) It's easy to emulate xor:  'x xor y' <-> bool(x) != bool(y)

Using the xor bitwise operator is also an option:
bool(x) ^ bool(y)

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


Re: bad behaviour in interactive Python prompt

2009-07-14 Thread Mark Dickinson
On Jul 14, 8:20 pm, "~km"  wrote:
> I'm experiencing a strange behaviour of the Python prompt when using
> the
> four arrow keys ( not the VIM' nor Emacs' ones ;-) ). Instead of
> getting
> the previous and next command respectively I get ugly characters. See
> it
> yourself:http://tinypic.com/view.php?pic=m78cgp&s=3
>
> This is not directly Python-specific, but you feel quite handicapped
> if
> you must rewrite each command again... so my obvious question is:
>
> How can I fix this? Please, let me know if you can tell me something.
>
> Additional information:
> I'm running Ubuntu Linux
> I've tried the python prompt in several shell environments and got the
> same issue in csh, dash... all negative.

Where did your version of Python 2.6 come from?

If you built your copy of Python 2.6 from source, then the problem is
probably that either the readline library is missing, or (much more
likely) the include files for the readline library are missing.  Look
for a package called something like libreadline5-dev or readline-devel
and install it, and then try rebuilding Python.

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


Re: select lines in python

2009-07-14 Thread David Gibb
I think what Grant is saying is that you should read the documentation
for the re module.

David

On Tue, Jul 14, 2009 at 3:12 PM, Grant Edwards wrote:
> On 2009-07-14, amr...@iisermohali.ac.in  wrote:
>
>> Can i become more precise like instead of printing all lines
>> for PHE and ASP is it possible that for PHE python will print
>> only those lines which will have information about H and HA
>> and for ASP it will print those lines which will have
>> information about HA and HB?
>
> Yes.
>
> --
> Grant Edwards                   grante             Yow! I KAISER ROLL?!
>                                  at               What good is a Kaiser Roll
>                               visi.com            without a little COLE SLAW
>                                                   on the SIDE?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


bad behaviour in interactive Python prompt

2009-07-14 Thread ~km
Hi,

I'm experiencing a strange behaviour of the Python prompt when using
the
four arrow keys ( not the VIM' nor Emacs' ones ;-) ). Instead of
getting
the previous and next command respectively I get ugly characters. See
it
yourself:
http://tinypic.com/view.php?pic=m78cgp&s=3

This is not directly Python-specific, but you feel quite handicapped
if
you must rewrite each command again... so my obvious question is:

How can I fix this? Please, let me know if you can tell me something.

Additional information:
I'm running Ubuntu Linux
I've tried the python prompt in several shell environments and got the
same issue in csh, dash... all negative.

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


python-list@python.org

2009-07-14 Thread ~km
Hi,

I'm experiencing a strange behaviour of the Python prompt when using
the
four arrow keys ( not the VIM' nor Emacs' ones ;-) ). Instead of
getting
the previous and next command respectively I get ugly characters. See
it
yourself:
http://tinypic.com/view.php?pic=m78cgp&s=3

This is not directly Python-specific, but you feel quite handicapped
if
you must rewrite each command again... so my obvious question is:

How can I fix this? Please, let me know if you can tell me something.

Additional information:
I'm running Ubuntu Linux
I've tried the python prompt in several shell environments and got the
same issue in csh, dash... all negative.

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


Re: select lines in python

2009-07-14 Thread Grant Edwards
On 2009-07-14, amr...@iisermohali.ac.in  wrote:

> Can i become more precise like instead of printing all lines
> for PHE and ASP is it possible that for PHE python will print
> only those lines which will have information about H and HA
> and for ASP it will print those lines which will have
> information about HA and HB?

Yes.

-- 
Grant Edwards   grante Yow! I KAISER ROLL?!
  at   What good is a Kaiser Roll
   visi.comwithout a little COLE SLAW
   on the SIDE?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: select lines in python

2009-07-14 Thread amrita
Can i become more precise like instead of printing all lines for PHE and
ASP is it possible that for PHE python will print only those lines which
will have information about H and HA and for ASP it will print those lines
which will have information about HA and HB.

Thanks


> On Tue, 14 Jul 2009 18:48:06 +0100, David Gibb  wrote:
>
> [Something top-posted, which I've shuffled down]
>
>> On Tue, Jul 14, 2009 at 1:33 PM,  wrote:
>>> Dear all,
>>>
>>> Can anyone tell me that suppose i have a file having content like:
>>>
>>>    _Atom_name
>>>      _Atom_type
>>>      _Chem_shift_value
>>>      _Chem_shift_value_error
>>>      _Chem_shift_ambiguity_code
>>>     1     1   PHE       H     H      8.49     0.02    
>>> 1
>>>     2     1   PHE       HA    H      4.60     0.02    
>>> 1
>>>     3     1   PHE       CA    C     57.83      0.3    
>>> 1
>>>     4     2   LEU       H     H      8.23     0.02    
>>> 1
>>>     5     2   LEU       HA    H      4.25     0.02    
>>> 1
>>>     6     2   LEU       HB2   H      1.54     0.02    
>>> 1
>>>     7     3   ASP       H     H      8.10     0.02    
>>> 1
>>>     8     3   ASP       HA    H      4.52     0.02    
>>> 1
>>>     9     3   ASP       HB2   H      2.65     0.02    
>>> 1
>>> stop
>>>
>>>
>>> now what i want that instead of copying all the lines it will just
>>> write
>>> the information about PHE and ASP then how i acn do that using python
>>> programming.Kindly tell me the command for that.
>
>> try something like:
>>
>> for line in open("filename").readlines():
>> if (re.search("PHE|ASP",line):
>> print line
>>
>
> The readlines() is unnecessary, and if your file is at all long you'd
> be better off precompiling the regular expression.
>
> import re
>
> expr = re.compile("PHE|ASP")
> with open("filename") as f:
>  for line in f:
>  if expr.search(line):
>  print line
>
> --
> Rhodri James *-* Wildebeest Herder to the Masses
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Amrita Kumari
Research Fellow
IISER Mohali
Chandigarh
INDIA

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


Re: missing 'xor' Boolean operator

2009-07-14 Thread Mark Dickinson
On Jul 14, 7:25 pm, "Dr. Phillip M. Feldman" 
wrote:
> Current Boolean operators are 'and', 'or', and 'not'.  It would be nice to
> have an 'xor' operator as well.

Hmm.  I don't think 'nice' is sufficient.  You'd need to make the case
that it's sufficiently useful to justify adding a new keyword 'xor' to
the language;  I suspect that would be an uphill struggle. :)

I'll just note that:

(1) It's easy to emulate xor:  'x xor y' <-> bool(x) != bool(y)

(2) 'and' and 'or' are special in that they have useful short-
circuiting behaviour; xor doesn't have this property (that is, you
always need to evaluate *both* operands to determine the result).

I'd also guess that 'xor' would be much less used than 'and' or 'or',
but maybe that's just a reflection of the sort of code that I tend to
write.

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


Re: why did you choose the programming language(s)you currently use?

2009-07-14 Thread Stefan Behnel
Deep_Feelings wrote:
> So you have chosen programming language "x" so shall you tell us why
> you did so , and  what negatives or positives it has ?

Java, pays a living.

*duck*

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


missing 'xor' Boolean operator

2009-07-14 Thread Dr. Phillip M. Feldman

Current Boolean operators are 'and', 'or', and 'not'.  It would be nice to
have an 'xor' operator as well.
-- 
View this message in context: 
http://www.nabble.com/missing-%27xor%27-Boolean-operator-tp24485116p24485116.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: How to keep a function as a generator function when the yield operator is moved into its sub-functions??

2009-07-14 Thread Miles Kaufmann

On Jul 14, 2009, at 2:03 PM, weafon wrote:


Hi guys,

I have a question about the usage of yield. As shown in the below  
example, in general, if there is a code segment commonly used by two  
or more functions, we may isolate the segment into a function and  
then call it from other functions if necessary.


def func1():
  
  while(cond):
  .
  commoncode()
  ...


def func2():
  
  while(cond):
  .
  commoncode()
  ...

def commoncode()
  
  
  

However, if there is a 'yield' operation in the common code segment,  
the isolation causes that func1 and func2 become a non-generator  
function!! Although I can prevent such an isolation by just  
duplicating the segment in func1 and func2 to keep both of them  
being generator functions, the code may become ugly and hard to  
maintain particularly when coomoncode() is long.


The problem may be resolved if I can define the commoncode() as an  
inline function or marco. Unfortunately, inline and marco do not  
seems to be implemented in python. Thus, how can I isolate a common  
segment into a function when there are yield operations in the  
common segment?


def func1():
...
while cond:
...
for x in commoncode():
yield x
...

See also:
 - PEP 380: http://www.python.org/dev/peps/pep-0380/
 - Stackless: http://www.stackless.com/

-Miles

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


Re: select lines in python

2009-07-14 Thread Rhodri James

On Tue, 14 Jul 2009 18:48:06 +0100, David Gibb  wrote:

[Something top-posted, which I've shuffled down]


On Tue, Jul 14, 2009 at 1:33 PM,  wrote:

Dear all,

Can anyone tell me that suppose i have a file having content like:

   _Atom_name
     _Atom_type
     _Chem_shift_value
     _Chem_shift_value_error
     _Chem_shift_ambiguity_code
    1     1   PHE       H     H      8.49     0.02     1
    2     1   PHE       HA    H      4.60     0.02     1
    3     1   PHE       CA    C     57.83      0.3     1
    4     2   LEU       H     H      8.23     0.02     1
    5     2   LEU       HA    H      4.25     0.02     1
    6     2   LEU       HB2   H      1.54     0.02     1
    7     3   ASP       H     H      8.10     0.02     1
    8     3   ASP       HA    H      4.52     0.02     1
    9     3   ASP       HB2   H      2.65     0.02     1
stop


now what i want that instead of copying all the lines it will just write
the information about PHE and ASP then how i acn do that using python
programming.Kindly tell me the command for that.



try something like:

for line in open("filename").readlines():
if (re.search("PHE|ASP",line):
print line



The readlines() is unnecessary, and if your file is at all long you'd
be better off precompiling the regular expression.

import re

expr = re.compile("PHE|ASP")
with open("filename") as f:
for line in f:
if expr.search(line):
print line

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


How to keep a function as a generator function when the yield operator is moved into its sub-functions??

2009-07-14 Thread weafon

Hi guys,

I have a question about the usage of yield. As shown in the below 
example, in general, if there is a code segment commonly used by two or 
more functions, we may isolate the segment into a function and then call 
it from other functions if necessary.


def func1():
   
   while(cond):
   .
   commoncode()
   ...


def func2():
   
   while(cond):
   .
   commoncode()
   ...

def commoncode()
   
   
   

However, if there is a 'yield' operation in the common code segment, the 
isolation causes that func1 and func2 become a non-generator function!! 
Although I can prevent such an isolation by just duplicating the segment 
in func1 and func2 to keep both of them being generator functions, the 
code may become ugly and hard to maintain particularly when coomoncode() 
is long.


The problem may be resolved if I can define the commoncode() as an 
inline function or marco. Unfortunately, inline and marco do not seems 
to be implemented in python. Thus, how can I isolate a common segment 
into a function when there are yield operations in the common segment?


Thanks,
Weafon





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


Re: Why not enforce four space indentations in version 3.x?

2009-07-14 Thread John Nagle

walterbyrd wrote:

I believe Guido himself has said that all indentions should be four
spaces - no tabs.

Since backward compatibility is being thrown away anyway, why not
enforce the four space rule?

At least that way, when I get python code from somebody else, I would
know what I am looking at, without having to do a hex dump, or
something.


   Python 3 enforces the rule that you can't mix tabs and spaces
for indentation in the same file.  That (finally) guarantees that
the indentation you see is what the Python parser sees.  That's
enough to prevent non-visible indentation errors.

   It also means that the Python parser no longer has to have
any concept of how many spaces equal a tab.  So the problem
is now essentially solved.

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


ImportError: No module named _functools

2009-07-14 Thread Tony Lay
I'm sooo close to getting this meld program runninghad to install
a lot of things in /usr/local to get to pygtk2 functional and I'm
trying to run the meld program and get...

RHEL4 server


Traceback (most recent call last):
  File "/usr/local/bin/meld", line 35, in 
import gettext
  File "/usr/local/lib/python2.6/gettext.py", line 49, in 
import locale, copy, os, re, struct, sys
  File "/usr/local/lib/python2.6/locale.py", line 15, in 
import functools
  File "/usr/local/lib/python2.6/functools.py", line 10, in 
from _functools import partial, reduce
ImportError: No module named _functools

This is with me building all of the dependencies as well as python
with
./configure --prefix=/usr/local --exec-prefix=/usr/local
make distclean
make
make -i install
ldconfig

export PYTHONHOME=/usr/local/lib/python2.6
export PYTHONPATH=/usr/local/lib/python2.6:/usr/local/lib/python2.6/
site-packages

I thought it might have been an err of the application, but I ran
python and received the same error:
[r...@orlstscts1 meld-1.0.0]# python
Python 2.6.2 (r262:71600, Jul 14 2009, 11:47:04)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import functools
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.6/functools.py", line 10, in 
from _functools import partial, reduce
ImportError: No module named _functools

Kind of a python n00b, but the functools.py is there, it's in the
path...everything seems to be lined up right.

Problem is that the server this is on is stable (read older), and I am
to not touch the older software unless it's as a last resort.  For
this reason everything is in /usr/local and built from the ground up.

I'm hoping that there's some silly dependency I'm missing.  I've
installed the following:
atk-1.26.0
pkg-config-0.23
cairo-1.8.8
libglade-2.6.4
pycairo-1.8.6
fontconfig-2.7.0
libpng-1.2.37
pygobject-2.18.0
freetype-2.1.10
libxml2-2.7.3
pygtk-2.15.2
gettext-0.17
meld-1.0.0
pygtk-2.8.6
glade3-3.6.7
meld-1.1.5
Python-2.6.2
glib-2.20.4
glibc-2.9
meld-1.3.0 (no install)
tcl8.5.7
tk8.5.7
gtk+-2.16.4
pango-1.20.5
intltool-0.35.5
pixman-0.15.14

Took me a while to get by fontconfig/freetype junk because (usr/local/
lib/libfontconfig.so: undefined reference to `FT_Select_Size') but
that's a little OT.

If there are any recommendations of what to attack or further
information would help let me know!

Regards,

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


Re: why did you choose the programming language(s)you currently use?

2009-07-14 Thread Mensanator
On Jul 14, 10:55 am, Deep_Feelings  wrote:
> So you have chosen programming language "x" so shall you tell us why
> you did so , and  what negatives or positives it has ?

language must have

- unlimited precision integers
- easy to program
- IDE not required
- reasonable speed
- math library needs to include number theoretic functions
  like GCD, LCM, Modular Inverse, etc.
- not fucking retarded like F#

That leaves Python (along with gympy, the Python wrapper for
the GMP library, which could be used with C or C++ if it weren't
for the ease of use issue) as the obvious choice.

As for negatives, the GMP library doesn't factor.

As for positives, you can call a factoring program from Python
and capture the output (and have it correct the bug in the factoring
program without having to fix the factoring program).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: one-time factory in python for an experienced java guy

2009-07-14 Thread phonky

Thanks for all replies.

I need to practice much more pythonese
In fact I don't think to understand all
of your suggestions, so I'll need to
go through them and decide what approach I am going
to take.

Thanks a lot!
--
http://mail.python.org/mailman/listinfo/python-list


Re: select lines in python

2009-07-14 Thread David Gibb
try something like:

for line in open("filename").readlines():
if (re.search("PHE|ASP",line):
print line

On Tue, Jul 14, 2009 at 1:33 PM,  wrote:
> Dear all,
>
> Can anyone tell me that suppose i have a file having content like:
>
>    _Atom_name
>      _Atom_type
>      _Chem_shift_value
>      _Chem_shift_value_error
>      _Chem_shift_ambiguity_code
>     1     1   PHE       H     H      8.49     0.02     1
>     2     1   PHE       HA    H      4.60     0.02     1
>     3     1   PHE       CA    C     57.83      0.3     1
>     4     2   LEU       H     H      8.23     0.02     1
>     5     2   LEU       HA    H      4.25     0.02     1
>     6     2   LEU       HB2   H      1.54     0.02     1
>     7     3   ASP       H     H      8.10     0.02     1
>     8     3   ASP       HA    H      4.52     0.02     1
>     9     3   ASP       HB2   H      2.65     0.02     1
> stop
>
>
> now what i want that instead of copying all the lines it will just write
> the information about PHE and ASP then how i acn do that using python
> programming.Kindly tell me the command for that.
>
> Thanks,
> Amrita Kumari
> Research Fellow
> IISER Mohali
> Chandigarh
> INDIA
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


select lines in python

2009-07-14 Thread amrita
Dear all,

Can anyone tell me that suppose i have a file having content like:

_Atom_name
  _Atom_type
  _Chem_shift_value
  _Chem_shift_value_error
  _Chem_shift_ambiguity_code
 1 1   PHE   H H  8.49 0.02 1
 2 1   PHE   HAH  4.60 0.02 1
 3 1   PHE   CAC 57.83  0.3 1
 4 2   LEU   H H  8.23 0.02 1
 5 2   LEU   HAH  4.25 0.02 1
 6 2   LEU   HB2   H  1.54 0.02 1
 7 3   ASP   H H  8.10 0.02 1
 8 3   ASP   HAH  4.52 0.02 1
 9 3   ASP   HB2   H  2.65 0.02 1
stop


now what i want that instead of copying all the lines it will just write
the information about PHE and ASP then how i acn do that using python
programming.Kindly tell me the command for that.

Thanks,
Amrita Kumari
Research Fellow
IISER Mohali
Chandigarh
INDIA

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


Re: Python code for testing well parenthesized expression

2009-07-14 Thread Duncan Booth
John Machin  wrote:

> Try an iterative version of checking that () [] and {}
> are balanced and nested appropriately.

Here's how I might approach the more general case:

def balanced(s, parens=("()",)):
'''
Example:
>>> balanced('aAAA(b[bb(c]c))')
True
>>> balanced('aAAA(b[bb(c]c))', parens=("()", "[]"))
False
'''
s = re.sub("[^%s]+" % re.escape("".join(parens)), "", s)
for i in range(len(s)/2):
for p in parens:
s = s.replace(p, "")
return not s

For short strings this is obviously slower than your 'iterative' function, 
but the run time mostly depends on the number of pairs of parentheses 
rather than the total length of the string, so for example it starts 
winning on a string with 2 pairs of parentheses about 75 characters long.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to determine if python is run interactively? (-i)

2009-07-14 Thread Duncan Booth
jfrancis4...@mailinator.com wrote:

> how do you determine, from within a python program, whether the python
> interpreter was launched in interactive mode?

sys.flags.interactive or sys.flags.inspect

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


Re: how to set timeout while colling a soap method?

2009-07-14 Thread ryles
On Jul 13, 9:07 am, dzizes  wrote:
> Hello!
>
> I wrote some some python code for executing a soap method:
>
> import SOAPpy
> from SOAPpy import WSDL
>
> _server = WSDL.Proxy(some wsdl)
> r=_server.generuj(some parameters...)
> print r.encode('cp1250')
>
> It works fine. However, the execution time of this soap method might be
> long. Therefore, I would like to set a timeout like 1 minute, after which I
> would post a timeoute message.
>
> Any ideas?
> Greats,
>
> --
> View this message in 
> context:http://www.nabble.com/how-to-set-timeout-while-colling-a-soap-method-...
> Sent from the Python - python-list mailing list archive at Nabble.com.

I don't believe SOAPpy supports this directly. You can set the timeout
globally before you make your SOAP call:

import socket
socket.setdefaulttimeout(60)

http://docs.python.org/library/socket.html#socket.setdefaulttimeout
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why did you choose the programming language(s)you currently use?

2009-07-14 Thread MRAB

Deep_Feelings wrote:

So you have chosen programming language "x" so shall you tell us why
you did so , and  what negatives or positives it has ?


I've heard of "C" and "D", but not "x", unless you mean XPL (X
Programming Language) or PLAN-X. :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best Way to Handle All Exceptions

2009-07-14 Thread Carl Banks
On Jul 14, 4:48 am, Lawrence D'Oliveiro  wrote:
> In message <93f6a517-63d8-4c80-
>
> bf19-4614b7099...@m7g2000prd.googlegroups.com>, Carl Banks wrote:
> > Or would you rather let all unexpected exceptions print to standard
> > error, which is often a black hole in non-interactive sitations?
>
> Since when?
>
> Cron, for example, collects standard error and mails it to you.

1. Cron is only one way to run programs non-interactively. (Would that
work with, say, Windows services?)
2. Many systems don't run MTAs these days
3. In my experience the pipeline from cron to mail delivery is error
prone, mainly due to the complexity of configuring MTAs
4. Even if all this works, you might just want to do your logging
directly in Python anyway


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


Re: Tkinter / Entry widget problem

2009-07-14 Thread Andras Szabo
So it's either that I use Python 2.5.1, or that I use it on a Mac.  
(John, your code still doesn't work the way it's supposed to here.) I  
guess I'll upgrade to 2.6.1 and see if it makes a difference. (The  
Tkinter/Tcl versions are the same for me.) Thanks for your help.


andras

On Jul 14, 2009, at 5:07 PM, John Posner wrote:




Andras Szabo wrote:



Hello. I searched the archives but couldn't find a solution to a
problem related to the Entry widget in Tkinter.

When creating a pop-up window in an app, which contains an Entry
widget, I want this widget to contain some default string, to have  
all

this default string selected (as if the user had manually selected
everything), and to have the focus transferred to this widget.

(The idea is then that if the window pops up, the user won't have to
click or press Tab any more before being able to type what is needed
in the textbox, overwriting what is written there already.)

I thought this might be the way to go:

entrybox=Entry(toplevel_parent_window)
entrybox.insert(0,"Some default string")
entrybox.select_range(0,END)
entrybox.focus_set()
entrybox.pack()

But it doesn't seem to work - the focus is not transferred to the
Entry widget, and the text does not appear to be selected (even  
though

after this entrybox.selection_present() returns True).

What am I doing wrong?



Nothing, I would think. Can you post a minimal runnable example?

Peter


This works for me, on Windows and Linux:

from Tkinter import *

rt = Tk()
rt.title("root window")
pop = Toplevel()
pop.title("second window")

entrybox=Entry(pop)
entrybox.insert(0,"Some default string")
entrybox.select_range(0,END)
entrybox.focus_set()
entrybox.pack()

rt.withdraw()
rt.mainloop()


On Win/XP SP3:

> python
Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit
 (Intel)] on   win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>> Tkinter.TkVersion
8.5
>>> Tkinter.TclVersion
8.5

On Ubuntu Linux (Ubu-SL 2.6.27.14-generic):

$ python
Python 2.6.1 (r261:67515, Jan  9 2009, 19:06:23)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>> Tkinter.TkVersion
8.4004
>>> Tkinter.TclVersion
8.4004


-John




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


how to determine if python is run interactively? (-i)

2009-07-14 Thread jfrancis4970
how do you determine, from within a python program, whether the python
interpreter was launched in interactive mode? in other words, if i
have a program called "test.py", i want to ensure that the program was
launched with this command line:

python -i test.py

(and not just with "python test.py"). the reason is that i'm doing
some very expensive and lengthy initialization in my test.py program
that will be useless unless the program exits to the python prompt
when it is done, where the user can run further python commands.

obviously i can't use sys.argv since that is only for parameters
passed to the test.py program, not for parameters passed to the python
interpreter itself. i haven't found a way to access these options...

any help would be greatly appreciated!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The meaning of "="

2009-07-14 Thread Aahz
In article , Piet van Oostrum   wrote:
>> Lawrence D'Oliveiro  (LD) wrote:
>
>>LD> In message , Aahz wrote:
>
>>Aahz> class AttrDict:
>>Aahz> def __getitem__(self, key):
>>Aahz> return getattr(self, key)
>
>>LD> OK, let's try it:
>
>>LD> >>> c = {}
>>LD> >>> c["x"] = 3
>>LD> >>> c.x = 4   
>>LD> Traceback (most recent call last):
>>LD>   File "", line 1, in 
>>LD> AttributeError: 'dict' object has no attribute 'x'
>>LD> >>> class AttrDict:
>>LD> ... def __getitem__(self, key):
>>LD> ... return getattr(self, key)
>>LD> ...
>>LD> >>> c.x = 4
>>LD> Traceback (most recent call last):
>>LD>   File "", line 1, in 
>>LD> AttributeError: 'dict' object has no attribute 'x'
>
>>LD> Nope, still doesn't work...
>
>Of course you need c = AttrDict()

Absolutely -- Lawrence really needs to learn to do his own debugging.

>And to get c.x = 4 working you also need a __setitem__. 

Nope.  You do need __setitem__ so that this works:

c['x'] = 4

>And to get c["x"] working AtrrDict should subclass dict:

Definitely not.  There's a perfectly good dict inside a regular class
instance already.  The only reason to subclass from dict is so that you
get all the dict methods for free; however, the cost is that you get
ugly bugs because of e.g.

c['update'] = 'foo'

Overally, I think it's much better/safer to explicitly pull the dict
methods you want to use.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
-- 
http://mail.python.org/mailman/listinfo/python-list


why did you choose the programming language(s)you currently use?

2009-07-14 Thread Deep_Feelings
So you have chosen programming language "x" so shall you tell us why
you did so , and  what negatives or positives it has ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Proposal: Decimal literals in Python.

2009-07-14 Thread MRAB

Scott David Daniels wrote:

Tim Roberts wrote:
My favorite notation for this comes from Ada, which allows arbitrary 
bases

from 2 to 16, and allows for underscores within numeric literals:

  x23_bin : constant :=  2#0001_0111#;
  x23_oct : constant :=  8#27#;
  x23_dec : constant := 10#23#;
  x23_hex : constant := 16#17#;

And mine is one w/o the base 10 bias:
.f.123 == 0x123
.7.123 == 0o123
.1.1101 == 0b1101
That is, ..
-- show the base by showing base-1 in the base.
I actually built this into "OZ," an interpretter.


Smalltalk uses "r" (for "radix"). If we also permit underscores:

x23_bin =  2r0001_0111
x23_oct =  8r27
x23_dec = 10r23
x23_hex = 16r17
--
http://mail.python.org/mailman/listinfo/python-list


Re: Best Way to Handle All Exceptions

2009-07-14 Thread Carl Banks
On Jul 14, 2:14 am, Steven D'Aprano
 wrote:
> On Tue, 14 Jul 2009 01:30:48 -0700, Carl Banks wrote:
> > Seriously, do you *ever* take more than 2 seconds to consider whether
> > you might be missing something obvious before following up with these
> > indignant knee-jerk responses?
>
> Obviously not.
>
> [...]
>
> > Or would you rather let all unexpected exceptions print to standard
> > error, which is often a black hole in non-interactive sitations?
>
> Fair point. Of course you're right.

I don't want to be mean or anything.  I agree with you on 95% of
issues probably, of course I only follow up to disagree

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


Re: Why does extend() fail in this case, and what am I doing wrong?

2009-07-14 Thread Xavier Ho
I see. Thanks!

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: cont...@xavierho.com
Website: http://xavierho.com/


On Tue, Jul 14, 2009 at 11:20 PM, Jochen Schulz  wrote:

> Xavier Ho:
> >
> > Why doesn't the second output print [1, 2, 3,  , 7, 8, 9] ?
> -- snip
> > print a.n.extend([6, 7, 8, 9])
>
> extend doesn't fail. It just returns None and extends the list in place.
>
> In [1]: l = [1, 2, 3]
>
> In [2]: l.extend([4, 5, 6])
>
> In [3]: l
> Out[3]: [1, 2, 3, 4, 5, 6]
>
>
> J.
> --
> When I get home from the supermarket I don't know what to do with all the
> plastic.
> [Agree]   [Disagree]
> 
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkpcoiwACgkQ+AfZydWK2zmchgCfZjRCOGTa0OZ1Q045sCLZfpvD
> EIEAnjJ8/uNwPYFfCsGNbQIDd5+LnkbA
> =fCdV
> -END PGP SIGNATURE-
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Proposal: Decimal literals in Python.

2009-07-14 Thread Scott David Daniels

Tim Roberts wrote:

My favorite notation for this comes from Ada, which allows arbitrary bases
from 2 to 16, and allows for underscores within numeric literals:

  x23_bin : constant :=  2#0001_0111#;
  x23_oct : constant :=  8#27#;
  x23_dec : constant := 10#23#;
  x23_hex : constant := 16#17#;

And mine is one w/o the base 10 bias:
.f.123 == 0x123
.7.123 == 0o123
.1.1101 == 0b1101
That is, ..
-- show the base by showing base-1 in the base.
I actually built this into "OZ," an interpretter.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: one-time factory in python for an experienced java guy

2009-07-14 Thread pdpi
On Jul 14, 3:03 pm, phonky  wrote:
> Hi
>
> I have searched all over and haven't found the solution
> for my problem yet. I am new to python, and all the time realize I
> do program python in java, which is not great.
>
> Besides being a real-life problem, I want to
> solve it as elegant as I can, using it to
> also learn about python (I know I could just
> hack something easy for now).
>
> That's what I want to do.
>
> I have an Account class.
> An Account instance has to get an account number.
> On instance creation, I want the account number to
> be generated (I don't want callers to pass
> the account # to ensure uniqueness):
>
> class Account(object):
>         def __init__(self, holder):
>                 self.__accountnumber = self.__generate_account_number()
>
> Now, I do not know yet how the account number scheme looks like.
> For now, I just want to have an incremental number; later,
> when going to production, we'll need the proper one.
>
> Furthermore, as we plan to distribute the package, we want
> to allow custom account numbering schemes. Thus, customers
> should be able to plug in their own AccountNumberGenerator implementation.
>
> For now, I have a generators.py module.
>
> I have an AccountNumberGenerator base class,
> all subclasses should implement "generate".
>
> I have an IncrementalGenerator subclass.
>
> So for now, I need to instantiate IncrementalGenerator,
> allowing for a future module to plugin their own generator.
>
> Any suggestions on how to do this?
> Thanks so much

You don't want an AccountNumberGenerator class and subclassing, all
you need is an iterator/generator of some form.

These might help:
http://docs.python.org/tutorial/classes.html#iterators
http://docs.python.org/tutorial/classes.html#generators
(in fact, that whole page is pretty relevant)

Once your code expects one of those, it's trivially easy to plug
something else in there.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: one-time factory in python for an experienced java guy

2009-07-14 Thread Aahz
In article <23406$4a5c9c7d$d9a2f023$27...@news.hispeed.ch>,
phonky   wrote:
>
>import itertools
>
> class Account(object):
>def __init__(self, holder, gen=itertools.count()):
>   self.__accountnumber = gen.next()
>
>If you consider my python illiteracy,
>
>"itertools.count(): Make an iterator that returns consecutive integers 
>starting with n"
>
>to me that sounds like that solves the increment issue, but what about
>future modules wanting to plug in a different
>numbering format, e.g. 205434.1234 or whatever?

Here's what I would do:

class Account:
gen = itertools.count
gen_instance = None

def __init__(self, holder):
if self.gen_instance is None:
self.__class__.gen_instance = self.gen()
self._account = self.gen_instance()

Notice that I'm using only a single underscore for ``_account`` to make
inheritance simpler, and I'm using ``self`` to access class attributes
*except* when I need to *set* the class attribute, which requires
``self.__class__``.

Now anyone who wants to change the generator can simply do
module.Account.gen = other_gen 
and it will work as long as no Account() instances have been created (you
don't want the generator to change mid-stream, right?).
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: one-time factory in python for an experienced java guy

2009-07-14 Thread Peter Otten
phonky wrote:

> Thanks Paul,
> 
>> Ugh, just forget everything you ever knew about java.  Do some Zen
>> exercises to erase your mind.  Then read a Python tutorial as if
>> you're starting from nothing.
> 
> Yeah, surely right, but easier said than done...
> I'm working on it.
> 
> Taking your example.
> 
> import itertools
> 
>  class Account(object):
> def __init__(self, holder, gen=itertools.count()):
>self.__accountnumber = gen.next()
> 
> If you consider my python illiteracy,
> 
> "itertools.count(): Make an iterator that returns consecutive integers
> starting with n"
> 
> to me that sounds like that solves the increment issue, but what about
> future modules wanting to plug in a different
> numbering format, e.g. 205434.1234 or whatever?

In that case you may want to stick with the class attribute:

>>> class Account(object):
... def __init__(self):
... self.account = self.next_account()
... def __str__(self):
... return "Account(number=%r)" % self.account
... __repr__ = __str__
...
>>> from itertools import count
>>> Account.next_account = count(42).next
>>> a = Account()
>>> b = Account()
>>> a, b
(Account(number=42), Account(number=43))
>>> from uuid import uuid1
>>> Account.next_account = staticmethod(uuid1)
>>> c = Account()
>>> d = Account()
>>> c, d
(Account(number=UUID('b0f8dfc6-7087-11de-be16-001d923f29c5')), 
Account(number=UUID('b310c90e-7087-11de-be16-001d923f29c5')))

You can plug in arbitrary callables at runtime. The only complication I can 
see is that you may have to wrap them into a staticmethod to prevent python 
from passing the self reference. You can avoid that if you just use a global 
instead:

# account.py
next_account = ...
class Account(object):
   def __init__(self): self.number = next_account()

You can then set the factory elsewhere

# main.py
import account
account.next_account = ...
a = Account()

In general in python we like to keep simple things simple rather than 
creating a huge bureaucracy.

Peter

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


Re: Why does extend() fail in this case, and what am I doing wrong?

2009-07-14 Thread Jochen Schulz
Xavier Ho:
>
> Why doesn't the second output print [1, 2, 3,  , 7, 8, 9] ?
-- snip
> print a.n.extend([6, 7, 8, 9])

extend doesn't fail. It just returns None and extends the list in place.

In [1]: l = [1, 2, 3]

In [2]: l.extend([4, 5, 6])

In [3]: l
Out[3]: [1, 2, 3, 4, 5, 6]


J.
-- 
When I get home from the supermarket I don't know what to do with all the
plastic.
[Agree]   [Disagree]
 


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


Re: one-time factory in python for an experienced java guy

2009-07-14 Thread Paul Rubin
phonky  writes:
> "itertools.count(): Make an iterator that returns consecutive integers
> starting with n"
> 
> to me that sounds like that solves the increment issue, but what about
> future modules wanting to plug in a different
> numbering format, e.g. 205434.1234 or whatever?

You'd write a different generator for that, and use it instead of
itertools.count.  E.g. (untested):

  def different_gen():
  a  = 201593.0768  # initial number
  while True:
 yield '%.04f'% a
 a += 123.4567  # increase in increments of this much
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does extend() fail in this case, and what am I doing wrong?

2009-07-14 Thread MRAB

Xavier Ho wrote:

Why doesn't the second output print [1, 2, 3,  , 7, 8, 9] ?
The code is run at: http://codepad.org/wgLU4JZh

class A():
def __init__(self):
self.n = [1, 2, 3, 4, 5]
   
a = A()

print a.n
print a.n.extend([6, 7, 8, 9])

#Output:
#[1, 2, 3, 4, 5]
#None

I really don't know, but I'm probably missing something. Any pointers 
would be great.



The extend() method modifies the list in-place and returns None. Try
printing a.n after extending.
--
http://mail.python.org/mailman/listinfo/python-list


Re: one-time factory in python for an experienced java guy

2009-07-14 Thread Mahmoud Abdelkader
What Paul was trying to elaborate on is that have your customers or whomever
will use this implement their own generator protocol to generate whatever
number format they need. Paul just gave you an example with
itertools.count(), where it is an infinite generator that yields count+1
every time.

Read up on the iterator protocol, have your customers pass in a generator to
establish their own formats.
http://docs.python.org/library/stdtypes.html#iterator-types

This is much more elegant than AbstractCustomerRandomFormatGenerator..etc
which is what the reference to "erase everything from Java" is attempting to
relate.

--
mahmoud mack abdelkader
python powered
http://blog.mahmoudimus.com/
mahm...@linux.com


On Tue, Jul 14, 2009 at 10:55 AM, phonky  wrote:

> Thanks Paul,
>
>  Ugh, just forget everything you ever knew about java.  Do some Zen
>> exercises to erase your mind.  Then read a Python tutorial as if
>> you're starting from nothing.
>>
>
> Yeah, surely right, but easier said than done...
> I'm working on it.
>
> Taking your example.
>
> import itertools
>
>class Account(object):
>   def __init__(self, holder, gen=itertools.count()):
>  self.__accountnumber = gen.next()
>
> If you consider my python illiteracy,
>
> "itertools.count(): Make an iterator that returns consecutive integers
> starting with n"
>
> to me that sounds like that solves the increment issue, but what about
> future modules wanting to plug in a different
> numbering format, e.g. 205434.1234 or whatever?
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why does extend() fail in this case, and what am I doing wrong?

2009-07-14 Thread Pablo Torres N.
This has been asked extensively before, here and elsewhere.

On Tue, Jul 14, 2009 at 09:52, Xavier Ho wrote:
> Why doesn't the second output print [1, 2, 3,  , 7, 8, 9] ?
> The code is run at: http://codepad.org/wgLU4JZh
>
> class A():
>     def __init__(self):
>     self.n = [1, 2, 3, 4, 5]
>
> a = A()
> print a.n
> print a.n.extend([6, 7, 8, 9])
>
> #Output:
> #[1, 2, 3, 4, 5]
> #None
>
> I really don't know, but I'm probably missing something. Any pointers would
> be great.
>
> Best regards,
>
> Ching-Yun "Xavier" Ho, Technical Artist
>
> Contact Information
> Mobile: (+61) 04 3335 4748
> Skype ID: SpaXe85
> Email: cont...@xavierho.com
> Website: http://xavierho.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>



-- 
Pablo Torres N.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: one-time factory in python for an experienced java guy

2009-07-14 Thread phonky

Thanks Paul,


Ugh, just forget everything you ever knew about java.  Do some Zen
exercises to erase your mind.  Then read a Python tutorial as if
you're starting from nothing.


Yeah, surely right, but easier said than done...
I'm working on it.

Taking your example.

import itertools

class Account(object):
   def __init__(self, holder, gen=itertools.count()):
  self.__accountnumber = gen.next()

If you consider my python illiteracy,

"itertools.count(): Make an iterator that returns consecutive integers 
starting with n"


to me that sounds like that solves the increment issue, but what about
future modules wanting to plug in a different
numbering format, e.g. 205434.1234 or whatever?


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


Why does extend() fail in this case, and what am I doing wrong?

2009-07-14 Thread Xavier Ho
Why doesn't the second output print [1, 2, 3,  , 7, 8, 9] ?
The code is run at: http://codepad.org/wgLU4JZh

class A():
def __init__(self):
self.n = [1, 2, 3, 4, 5]

a = A()
print a.n
print a.n.extend([6, 7, 8, 9])

#Output:
#[1, 2, 3, 4, 5]
#None

I really don't know, but I'm probably missing something. Any pointers would
be great.

Best regards,

Ching-Yun "Xavier" Ho, Technical Artist

Contact Information
Mobile: (+61) 04 3335 4748
Skype ID: SpaXe85
Email: cont...@xavierho.com
Website: http://xavierho.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >