Re: warnings filters for varying message

2013-06-28 Thread Peter Otten
John Reid wrote:

> Looking at the docs for warnings.simplefilter
> (http://docs.python.org/2/library/warnings.html) I think the following
> script should only produce one warning at each line as any message is
> matched by the simple filter
> 
> import warnings
> warnings.simplefilter('default')
> for i in xrange(2):
> warnings.warn('Warning message') # This prints 1 warning
> warnings.warn("Warning %d" % i)  # This prints 2 warnings
> 
> What do I need to do to get the warnings module just to print one
> warning for the second warnings.warn line?

$ cat warn_once_orig.py
import warnings

for i in xrange(2):
warnings.warn('Warning message')
warnings.warn("Warning %d" % i)
$ python -i warn_once_orig.py 
warn_once_orig.py:4: UserWarning: Warning message
  warnings.warn('Warning message')
warn_once_orig.py:5: UserWarning: Warning 0
  warnings.warn("Warning %d" % i)
warn_once_orig.py:5: UserWarning: Warning 1
  warnings.warn("Warning %d" % i)
>>> __warningregistry__
{('Warning message', , 4): True, ('Warning 
0', , 5): True, ('Warning 1', , 5): True}

As you can see the message is part of the key that determines the identity 
of a warning. At first glance I see no official way to defeat that, so 
here's a quick hack:

$ cat warn_once.py
import warnings

class WarningMessage(str):
def __hash__(self):
return 0
def __eq__(self, other):
return isinstance(other, str)

for i in xrange(2):
warnings.warn('Warning message')
warnings.warn(WarningMessage("Warning %d" % i))
$ python warn_once.py 
warn_once.py:10: UserWarning: Warning message
  warnings.warn('Warning message')
warn_once.py:11: UserWarning: Warning 0
  warnings.warn(WarningMessage("Warning %d" % i))


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


Re: Making a pass form cgi => webpy framework

2013-06-28 Thread Robert Kern

On 2013-06-28 04:38, Νίκος wrote:

Στις 28/6/2013 2:08 πμ, ο/η Cameron Simpson έγραψε:



Pick a simple framework or templating engine and try it. I have no
recommendations to make in this area myself.


Can you explain to me the difference of the former and latter?


A templating engine takes your data and applies it to templates that you have 
written to generate the final HTML that is sent to the web browser.


A web framework is a library that provides tools and a way of structuring your 
that makes it easier to write a web application. Web frameworks typically 
include a templating engine or provide support for working with external 
templating engines. In addition, web frameworks provide many other services, 
like routing URLs to specific parts of your code, managing pools of database 
connections, handling web sessions, validating form data, and connecting your 
code to many different ways of deploying web applications without having to 
rewrite your code.


--
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: Making a pass form cgi => webpy framework

2013-06-28 Thread Νίκος

Στις 28/6/2013 12:35 μμ, ο/η Robert Kern έγραψε:

On 2013-06-28 04:38, Νίκος wrote:

Στις 28/6/2013 2:08 πμ, ο/η Cameron Simpson έγραψε:



Pick a simple framework or templating engine and try it. I have no
recommendations to make in this area myself.


Can you explain to me the difference of the former and latter?


A templating engine takes your data and applies it to templates that you
have written to generate the final HTML that is sent to the web browser.

A web framework is a library that provides tools and a way of
structuring your that makes it easier to write a web application. Web
frameworks typically include a templating engine or provide support for
working with external templating engines. In addition, web frameworks
provide many other services, like routing URLs to specific parts of your
code, managing pools of database connections, handling web sessions,
validating form data, and connecting your code to many different ways of
deploying web applications without having to rewrite your code.


I see, your explanation started to make things clearer to me.
What is the easiest and simplest web framework you advise me to use?

Also please provide a well written and simple tutorial i can read upon.
Thank you.

--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list


Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.

2013-06-28 Thread 88888 Dihedral
Jason Friedman於 2013年6月28日星期五UTC+8上午11時52分33秒寫道:
> > I was hoping to have a good laugh. :|
> 
> 
> 
> 
> 
> > Although I wouldn't call it hostile.
> 
> 
> 
> I think the python community is being educated in how to spam and troll at 
> the same time.
> 
> 
> 
> It is possible the OP has a mental disease, which is about as funny as heart 
> disease and cancer and not blameworthy.  This is the poster's website from a 
> previous post on this forum:  http://thrinaxodon.wordpress.com.

KIND OF BORING TO SHOW HOW THE LISP PROGRAMMING
WAS ASSIMULATED BY THE PYTHON COMMUNITY.

OF COURSE PYTHON IS A GOOD LANGUAGE FOR DEVELOPING
ARTIFICIAL INTELEGENT ROBOT PROGRAMS NOT SO BRAIN DAMAGES,
OR SO SLAVERY AS C/C++ OR ASEMBLY PARTS.



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


Re: Making a pass form cgi => webpy framework

2013-06-28 Thread Robert Kern

On 2013-06-28 11:15, Νίκος wrote:

Στις 28/6/2013 12:35 μμ, ο/η Robert Kern έγραψε:

On 2013-06-28 04:38, Νίκος wrote:

Στις 28/6/2013 2:08 πμ, ο/η Cameron Simpson έγραψε:



Pick a simple framework or templating engine and try it. I have no
recommendations to make in this area myself.


Can you explain to me the difference of the former and latter?


A templating engine takes your data and applies it to templates that you
have written to generate the final HTML that is sent to the web browser.

A web framework is a library that provides tools and a way of
structuring your that makes it easier to write a web application. Web
frameworks typically include a templating engine or provide support for
working with external templating engines. In addition, web frameworks
provide many other services, like routing URLs to specific parts of your
code, managing pools of database connections, handling web sessions,
validating form data, and connecting your code to many different ways of
deploying web applications without having to rewrite your code.


I see, your explanation started to make things clearer to me.
What is the easiest and simplest web framework you advise me to use?

Also please provide a well written and simple tutorial i can read upon.
Thank you.


I will not advise you to do anything. I will point you to a web framework that I 
happen to like, but you will need to read its documentation to decide if it is 
right for you. I cannot provide any help in installing or using it.


  http://flask.pocoo.org/
  http://flask.pocoo.org/docs/tutorial/

--
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


Problems with subclassing enum34

2013-06-28 Thread Thomas Heller

trying out the enum34 module.

What I want to create is a subclass of enum.Enum that is also
based on ctypes.c_int so that I can better use enum instances
in ctypes api calls.

When I do this, I get a metaclass conflict:


>>> class MyEnum(ctypes.c_int, enum.Enum):
...FOOBAR = 0
...
Traceback (most recent call last):
  File "", line 1, in 
TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class must be a 
(non-strict) subclass of the metaclasses of all its bases

>>>



When I do this, it does not work either:

>>> class MyEnum_meta(type(ctypes.c_int), type(enum.Enum)):
... pass
...
>>> class MyEnum(ctypes.c_int, enum.Enum):
... FOOBAR = 42
... __metaclass__ = MyEnum_meta
...
>>> MyEnum.FOOBAR
42
>>>

It should have printed ''.

Any ideas?

Thanks,
Thomas
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why is the argparse module so inflexible?

2013-06-28 Thread Andrew Berg
After getting over the hurdles I initially explained and moving forward, I've 
found that standard command-line parsing and its conventions
are far too ingrained in the design of argparse to make it useful as a general 
command parser. I think I would end up overriding a
substantial amount of the module to make it do what I want, and I would really 
rather not try to shoehorn one paradigm into another.
Unfortunately, getopt provides none of the benefits I sought with argparse, and 
optparse is deprecated, so I will probably be rolling my own
custom parser.

-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with subclassing enum34

2013-06-28 Thread Robert Kern

On 2013-06-28 11:48, Thomas Heller wrote:

trying out the enum34 module.

What I want to create is a subclass of enum.Enum that is also
based on ctypes.c_int so that I can better use enum instances
in ctypes api calls.

When I do this, I get a metaclass conflict:


 >>> class MyEnum(ctypes.c_int, enum.Enum):
...FOOBAR = 0
...
Traceback (most recent call last):
   File "", line 1, in 
TypeError: Error when calling the metaclass bases
 metaclass conflict: the metaclass of a derived class must be a (non-strict)
subclass of the metaclasses of all its bases
 >>>



When I do this, it does not work either:

 >>> class MyEnum_meta(type(ctypes.c_int), type(enum.Enum)):
... pass


enum.EnumMeta uses super() in its __new__() implementation but 
_ctypes.PyCSimpleType doesn't. Thus, only _ctypes.PyCSimpleType.__new__() gets a 
chance to run. Switching the order of the two might work.


--
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: Don't feed the troll...

2013-06-28 Thread Antoon Pardon

Op 26-06-13 23:02, Ian Kelly schreef:

On Wed, Jun 26, 2013 at 1:46 PM, Antoon Pardon
  wrote:

But you didn't even go to the trouble of trying to find out
what those concerns would be and how strong people feel about
them. You just took your assumptions about those concerns for
granted and proceeded from there.


Jumping back in here, I for one don't give a hoot about their
concerns, beyond the basic assumption that they feel the same way I do
about Nikos' threads and wish that he would leave.  I just want to
maintain a positive and welcoming atmosphere around here.


So what do you think would be a good approach towards people
who are behaving in conflict with this wish of yours? Just
bluntly call them worse than the troll or try to approach them
in a way that is less likely to antangonize them?


I expect
that most of the posters here are adults and can fend for themselves
regarding their own concerns, and I'm not interested in being the list
mom.


It is not about being the list's mom. It's about approaching
people, whom you would like to influence in changing their
behaviour, in a way that is more likely to gain you their
good will towards you.

If what you want is indeed a positive and welcoming atmosphere,
I would say such an approach would be more effective in getting
it.


Why should I care about the rational you gave. It is based on
your own assumptions, on how you weight the possible outcomes against
each other. Someone who doesn't care about trolls or even may
enjoy observing a heated exchange may come to an entirely different
conclusion on what behaviour is good for the group in case he
extrapolated his own preferences on the group.

And you may not have purposely made things up to justify your
proposal, but how you went about it, that is probably what you
actually did. Because that is what we as humans generally do
in this kind of situations.


"Made things up"?  This response to the situation is not just our own
assumptions at work, but the collective experience of the Internet,
going back decades.


The collective experience of theachers is that punishment for bad 
performance works, despite research showing otherwise.


Besides I was talking about rurpy's basic assumptions about what
the costs would be for various subgroups in different scenario's.
These were all based on his own interpretations. What he did
was trying to imagine how costly it would feel for him, should
he have be in a particular situation with a particular preference.
As far as I can see he didn't ask other people what their preference
was and how costly particular situations would feel to them.

So yes he made those up. Now I accept he was trying to get at an
honest estimation of factors involved, but human biases working
as they do, there is little reason to think his result is in
any way objective or useful.


Now as far as I am concerned you can be as blunt as you want to
be. I just don't understand why you think you should be so
careful to Nikos, while at the same time you saw no need for
careful wording here.


Nobody is suggesting that we should make any effort to try to avoid
hurting Nikos' feelings, contrary to what you seem to be implying
here.


I am implying nothing. I'm just pointing out the difference between
how rurpy explains we should behave towards Nikos and how he behaved
towards the flamers. If there is some sort of implication it is with
rurpy in that difference and not with me in me pointing it out.


Be as blunt as you want with him, but please recognize that
troll baiting /does not work/ as a means of making the troll go away
and only serves to further degrade the list.


It's not clear to me what you are precisely saying here. Do you think
being blunt is a form of troll baiting or not? Because my impression
of those who are bothered by the flamers, was that being blunt was just
a form of troll baiting and would just cause similar kind of list 
degradation.


Do you think being blunt is a good way in keeping a welcoming and
postive atmosphere in this group?


Second, I *am* concerned in that I find a lot of Nikos's responses
frustrating and I realize other people feel the same.


Stop telling you are concerned. Start showing.


How?  By joining in with the flaming and being just as
counter-productive?


I am not so sure it would be counter-productive. A joint flaming
of a troll can be an effective way to increase coherence in a
group.


I'm not going to try to "show" my concern because
it is not important to me whether others can see it.


I doubt that is a good way in keeping this group positive
and welcoming. But it is your choice.


Do you have mumbers on that? Otherwise those three decades of internet
don't mean much.


The only actual study on the topic that I'm aware of is this one:

http://www.guardian.co.uk/education/2011/jun/13/internet-trolls-improbable-research


Thanks for this. Unfortunatly there is not much to rely on. The only 
thing I can get from this, is that there can be more wa

Re: Problems with subclassing enum34

2013-06-28 Thread 88888 Dihedral
Thomas Heller於 2013年6月28日星期五UTC+8下午6時48分38秒寫道:
> trying out the enum34 module.
> 
> 
> 
> What I want to create is a subclass of enum.Enum that is also
> 
> based on ctypes.c_int so that I can better use enum instances
> 
> in ctypes api calls.
> 
> 
> 
> When I do this, I get a metaclass conflict:
> 
> 
> 
> 
> 
>  >>> class MyEnum(ctypes.c_int, enum.Enum):
> 
> ...FOOBAR = 0
> 
> ...
> 
> Traceback (most recent call last):
> 
>File "", line 1, in 
> 
> TypeError: Error when calling the metaclass bases
> 
>  metaclass conflict: the metaclass of a derived class must be a 
> 
> (non-strict) subclass of the metaclasses of all its bases
> 
>  >>>
> 
> 
> 
> 
> 
> 
> 
> When I do this, it does not work either:
> 
> 
> 
>  >>> class MyEnum_meta(type(ctypes.c_int), type(enum.Enum)):
> 
> ... pass
> 
> ...
> 
>  >>> class MyEnum(ctypes.c_int, enum.Enum):
> 
> ... FOOBAR = 42
> 
> ... __metaclass__ = MyEnum_meta
> 
> ...
> 
>  >>> MyEnum.FOOBAR
> 
> 42
> 
>  >>>
> 
> 
> 
> It should have printed ''.
> 
> 
> 
> Any ideas?
> 
> 
> 
> Thanks,
> 
> Thomas

Just use a dictionary for the job. Python i not c/c++.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making a pass form cgi => webpy framework

2013-06-28 Thread rusi
On Friday, June 28, 2013 3:45:27 PM UTC+5:30, Νίκος wrote:
> Στις 28/6/2013 12:35 μμ, ο/η Robert Kern έγραψε:
> I see, your explanation started to make things clearer to me.
> What is the easiest and simplest web framework you advise me to use?
> 

Here's a picture of the web-development scene as I see it:

At one extreme there are mega-frameworks like django.
At the other one can write everything as you have been trying.

Both these can be unsatisfactory (as you are discovering!)

In between is a line which follows from Robert Kern's suggestions.

So my advise is to understand and follow these suggestions.  IOW take each of 
the items mentioned here (starting templating):

> > A web framework is a library that provides tools and a way of
> > structuring your that makes it easier to write a web application. Web
> > frameworks typically include a templating engine or provide support for
> > working with external templating engines. In addition, web frameworks
> > provide many other services, like routing URLs to specific parts of your
> > code, managing pools of database connections, handling web sessions,
> > validating form data, and connecting your code to many different ways of
> > deploying web applications without having to rewrite your code.

1. Now run a web-search for that.
2. See if it looks of any use to you
3. Check the available libraries
4. Install and try out* something that looks simple
5. When stuck -- either concepts or details -- come back here and ask

* Not on a live server!!
-- 
http://mail.python.org/mailman/listinfo/python-list


? get negative from prod(x) when x is positive integers

2013-06-28 Thread Vincent Davis
I have a list of a list of integers. The lists are long so i cant really
show an actual example of on of the lists, but I know that they contain
only the integers 1,2,3,4. so for example.
s2 = [[1,2,2,3,2,1,4,4],[2,4,3,2,3,1]]

I am calculating the product, sum, max, min of each list in s2 but I
get negative or 0 for the product for a lot of the lists. (I am doing this
in ipython)

for x in s2:
print('len = ', len(x), 'sum = ', sum(x), 'prod = ', prod(x), 'max = ',
max(x), 'min = ', min(x))

...

('len = ', 100, 'sum = ', 247, 'prod = ', 0, 'max = ', 4, 'min = ', 1)
('len = ', 100, 'sum = ', 230, 'prod = ', -4611686018427387904, 'max =
', 4, 'min = ', 1)
('len = ', 100, 'sum = ', 261, 'prod = ', 0, 'max = ', 4, 'min = ', 1)

.

('prod =', 0, 'max =', 4, 'min =', 1)
('prod =', 1729382256910270464, 'max =', 4, 'min =', 1)
('prod =', 0, 'max =', 4, 'min =', 1)




Whats going on?



Vincent Davis
720-301-3003
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ? get negative from prod(x) when x is positive integers

2013-06-28 Thread Peter Otten
Vincent Davis wrote:

> I have a list of a list of integers. The lists are long so i cant really
> show an actual example of on of the lists, but I know that they contain
> only the integers 1,2,3,4. so for example.
> s2 = [[1,2,2,3,2,1,4,4],[2,4,3,2,3,1]]
> 
> I am calculating the product, sum, max, min of each list in s2 but I
> get negative or 0 for the product for a lot of the lists. (I am doing this
> in ipython)
> 
> for x in s2:
> print('len = ', len(x), 'sum = ', sum(x), 'prod = ', prod(x), 'max =
> ',
> max(x), 'min = ', min(x))
> 
> ...
> 
> ('len = ', 100, 'sum = ', 247, 'prod = ', 0, 'max = ', 4, 'min = ', 1)
> ('len = ', 100, 'sum = ', 230, 'prod = ', -4611686018427387904, 'max =
> ', 4, 'min = ', 1)
> ('len = ', 100, 'sum = ', 261, 'prod = ', 0, 'max = ', 4, 'min = ', 1)
> 
> .
> 
> ('prod =', 0, 'max =', 4, 'min =', 1)
> ('prod =', 1729382256910270464, 'max =', 4, 'min =', 1)
> ('prod =', 0, 'max =', 4, 'min =', 1)
> 
> 
> 
> 
> Whats going on?

Instead of Python's integer type (int/long) numpy uses the faster machine 
integers (typically 32 or 64 bit) that overflow:

>>> a = numpy.array([0x, 0x])
>>> numpy.prod(a)
-8589934591
>>> a.dtype
dtype('int64')

As a workaround you can use Python's ints (slower)

>>> a = numpy.array([0x, 0x], dtype=object)
>>> numpy.prod(a)
18446744065119617025L

or float (loss of precision)

>>> a = numpy.array([0x, 0x], dtype=float)
>>> numpy.prod(a)
1.8446744065119617e+19


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


Re: ? get negative from prod(x) when x is positive integers

2013-06-28 Thread Joshua Landau
On 28 June 2013 15:38, Vincent Davis  wrote:
> I have a list of a list of integers. The lists are long so i cant really
> show an actual example of on of the lists, but I know that they contain only
> the integers 1,2,3,4. so for example.
> s2 = [[1,2,2,3,2,1,4,4],[2,4,3,2,3,1]]
>
> I am calculating the product, sum, max, min of each list in s2 but I get
> negative or 0 for the product for a lot of the lists. (I am doing this in
> ipython)
>
> for x in s2:
> print('len = ', len(x), 'sum = ', sum(x), 'prod = ', prod(x), 'max = ',
> max(x), 'min = ', min(x))
>
> ...
>
> ('len = ', 100, 'sum = ', 247, 'prod = ', 0, 'max = ', 4, 'min = ', 1)
> ('len = ', 100, 'sum = ', 230, 'prod = ', -4611686018427387904, 'max = ', 4,
> 'min = ', 1)
> ('len = ', 100, 'sum = ', 261, 'prod = ', 0, 'max = ', 4, 'min = ', 1)
>
> .
>
> ('prod =', 0, 'max =', 4, 'min =', 1)
> ('prod =', 1729382256910270464, 'max =', 4, 'min =', 1)
> ('prod =', 0, 'max =', 4, 'min =', 1)
>
> 
>
>
> Whats going on?

Let me guess.
These are your lists (sorted):

[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4]

[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4]

[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4]

You are using numpy.prod()

Numpy.prod overflows:

>>> numpy.prod([-9223372036854775808, 2])
... 0

You want to use something that doesn't such as:

def prod(iter):
p = 1
for elem in iter:
p *= elem
return p

and then you get your correct products:

8002414661101704746694488837062656
3907429033741066770846918377472
682872717747345471717929714096013312
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with subclassing enum34

2013-06-28 Thread Ethan Furman

On 06/28/2013 03:48 AM, Thomas Heller wrote:

trying out the enum34 module.

What I want to create is a subclass of enum.Enum that is also
based on ctypes.c_int so that I can better use enum instances
in ctypes api calls.


Have you tried using enum.IntEnum?  If you were able to pass ints in before, 
IntEnum should work.

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


Re: Problems with subclassing enum34

2013-06-28 Thread Thomas Heller

Am 28.06.2013 17:16, schrieb Ethan Furman:

On 06/28/2013 03:48 AM, Thomas Heller wrote:

trying out the enum34 module.

What I want to create is a subclass of enum.Enum that is also based
on ctypes.c_int so that I can better use enum instances in ctypes
api calls.


Have you tried using enum.IntEnum?  If you were able to pass ints in
 before, IntEnum should work.


I'm sure that IntEnum works as expected, but I need enums that are
subclasses of ctypes.c_int (so that argument type checking and return
value conversions in ctypes api calls work).

Robert Kern:



enum.EnumMeta uses super() in its __new__() implementation but
_ctypes.PyCSimpleType doesn't. Thus, only
_ctypes.PyCSimpleType.__new__() gets a chance to run. Switching the
order of the two might work.



Robert found the problem but I'm unsure if there is a solution.
Also I'm unsure whether this is a bug in ctypes or in enum or if
they are simply incompatible.

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


Re: ? get negative from prod(x) when x is positive integers

2013-06-28 Thread Vincent Davis
@Joshua
"You are using numpy.prod()"
Wow, since sum([1,2,3,4]) worked I tried prod([1,2,3,4]) and got the right
answer so I just used that. Confusing that it would use numpy.prod(), I
realize now there is no python prod(). At no point do I "import numpy" in
my code. The seems to be a result of using ipython, or at least how I am
using it "ipython notebook --pylab inline".

Thanks

Vincent Davis
720-301-3003


On Fri, Jun 28, 2013 at 4:04 PM, Joshua Landau
wrote:

> On 28 June 2013 15:38, Vincent Davis  wrote:
> > I have a list of a list of integers. The lists are long so i cant really
> > show an actual example of on of the lists, but I know that they contain
> only
> > the integers 1,2,3,4. so for example.
> > s2 = [[1,2,2,3,2,1,4,4],[2,4,3,2,3,1]]
> >
> > I am calculating the product, sum, max, min of each list in s2 but I
> get
> > negative or 0 for the product for a lot of the lists. (I am doing this in
> > ipython)
> >
> > for x in s2:
> > print('len = ', len(x), 'sum = ', sum(x), 'prod = ', prod(x), 'max =
> ',
> > max(x), 'min = ', min(x))
> >
> > ...
> >
> > ('len = ', 100, 'sum = ', 247, 'prod = ', 0, 'max = ', 4, 'min = ', 1)
> > ('len = ', 100, 'sum = ', 230, 'prod = ', -4611686018427387904, 'max =
> ', 4,
> > 'min = ', 1)
> > ('len = ', 100, 'sum = ', 261, 'prod = ', 0, 'max = ', 4, 'min = ', 1)
> >
> > .
> >
> > ('prod =', 0, 'max =', 4, 'min =', 1)
> > ('prod =', 1729382256910270464, 'max =', 4, 'min =', 1)
> > ('prod =', 0, 'max =', 4, 'min =', 1)
> >
> > 
> >
> >
> > Whats going on?
>
> Let me guess.
> These are your lists (sorted):
>
> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
> 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
> 4, 4, 4, 4, 4, 4, 4, 4]
>
> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
> 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
> 4, 4, 4, 4, 4, 4, 4, 4]
>
> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
> 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3,
> 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4,
> 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
> 4, 4, 4, 4, 4, 4, 4, 4]
>
> You are using numpy.prod()
>
> Numpy.prod overflows:
>
> >>> numpy.prod([-9223372036854775808, 2])
> ... 0
>
> You want to use something that doesn't such as:
>
> def prod(iter):
> p = 1
> for elem in iter:
> p *= elem
> return p
>
> and then you get your correct products:
>
> 8002414661101704746694488837062656
> 3907429033741066770846918377472
> 682872717747345471717929714096013312
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with subclassing enum34

2013-06-28 Thread Thomas Heller

Am 28.06.2013 17:25, schrieb Thomas Heller:

Robert Kern:



enum.EnumMeta uses super() in its __new__() implementation but
_ctypes.PyCSimpleType doesn't. Thus, only
_ctypes.PyCSimpleType.__new__() gets a chance to run. Switching the
order of the two might work.



Robert found the problem but I'm unsure if there is a solution.
Also I'm unsure whether this is a bug in ctypes or in enum or if
they are simply incompatible.


I forgot to mention that switching the order of metaclasses didn't work.

Thomas

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


Re: ? get negative from prod(x) when x is positive integers

2013-06-28 Thread Terry Reedy

On 6/28/2013 10:38 AM, Vincent Davis wrote:

I have a list of a list of integers. The lists are long so i cant really
show an actual example of on of the lists, but I know that they contain
only the integers 1,2,3,4. so for example.
s2 = [[1,2,2,3,2,1,4,4],[2,4,3,2,3,1]]

I am calculating the product, sum, max, min of each list in s2 but I
get negative or 0 for the product for a lot of the lists. (I am doing
this in ipython)


Based on Python2 (from print output). Look at the underlying version to 
make sure it is 2.7. Using Python 3 or something based on it is better 
unless you *really* have to use Python 2.



for x in s2:
 print('len = ', len(x), 'sum = ', sum(x), 'prod = ', prod(x), 'max
= ', max(x), 'min = ', min(x))


prod is not a Python builtin. I am guessing ipython adds it as a C-coded 
builtin because a Python-coded function* would not have the overflow bug 
exhibited below. See for instance

https://en.wikipedia.org/wiki/Integer_overflow

Not having to worry about this, because Python comes with 
multi-precision integers, is a great thing about using Python rather 
than almost any other language.



* I do not remember it this was always true for old enough Pythons.


('len = ', 100, 'sum = ', 247, 'prod = ', 0, 'max = ', 4, 'min = ', 1)
('len = ', 100, 'sum = ', 230, 'prod = ', -4611686018427387904, 'max = ', 4, 
'min = ', 1)


def prod(seq):
res=1
for i in seq:
res *= i
return res

should work for you.

--
Terry Jan Reedy

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


Re: Problems with subclassing enum34

2013-06-28 Thread Robert Kern

On 2013-06-28 16:32, Thomas Heller wrote:

Am 28.06.2013 17:25, schrieb Thomas Heller:

Robert Kern:



enum.EnumMeta uses super() in its __new__() implementation but
_ctypes.PyCSimpleType doesn't. Thus, only
_ctypes.PyCSimpleType.__new__() gets a chance to run. Switching the
order of the two might work.



Robert found the problem but I'm unsure if there is a solution.
Also I'm unsure whether this is a bug in ctypes or in enum or if
they are simply incompatible.


I forgot to mention that switching the order of metaclasses didn't work.


You may also need to manually deal with the conflict between Enum.__new__() and 
c_int.__new__().


--
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: ? get negative from prod(x) when x is positive integers

2013-06-28 Thread Robert Kern

On 2013-06-28 16:26, Vincent Davis wrote:

@Joshua
"You are using numpy.prod()"
Wow, since sum([1,2,3,4]) worked I tried prod([1,2,3,4]) and got the right
answer so I just used that. Confusing that it would use numpy.prod(), I realize
now there is no python prod(). At no point do I "import numpy" in my code. The
seems to be a result of using ipython, or at least how I am using it "ipython
notebook --pylab inline".


The --pylab option will do the following import:

  from matplotlib.pyplot import *

That includes a "from numpy import *" in there.

--
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: Problems with subclassing enum34

2013-06-28 Thread Ethan Furman

On 06/28/2013 08:32 AM, Thomas Heller wrote:

Am 28.06.2013 17:25, schrieb Thomas Heller:

Robert Kern:



enum.EnumMeta uses super() in its __new__() implementation but
_ctypes.PyCSimpleType doesn't. Thus, only
_ctypes.PyCSimpleType.__new__() gets a chance to run. Switching the
order of the two might work.



Robert found the problem but I'm unsure if there is a solution.
Also I'm unsure whether this is a bug in ctypes or in enum or if
they are simply incompatible.


I forgot to mention that switching the order of metaclasses didn't work.


Here's the traceback:

Traceback (most recent call last):
  File "ct.py", line 7, in 
class MyEnum(ctypes.c_int, Enum):
  File "/home/ethan/source/enum/enum/py2_enum.py", line 149, in __new__
enum_class = super(EnumMeta, metacls).__new__(metacls, cls, bases, 
classdict)
TypeError: Error when calling the metaclass bases
_ctypes.PyCSimpleType.__new__(MyEnum_meta) is not safe, use type.__new__()

Not sure how to fix that.

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


what happened?

2013-06-28 Thread mpowers
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.

2013-06-28 Thread Wayne Werner

On Fri, 28 Jun 2013, 8 Dihedral wrote:


KIND OF BORING TO SHOW HOW THE LISP PROGRAMMING
WAS ASSIMULATED BY THE PYTHON COMMUNITY.

OF COURSE PYTHON IS A GOOD LANGUAGE FOR DEVELOPING
ARTIFICIAL INTELEGENT ROBOT PROGRAMS NOT SO BRAIN DAMAGES,
OR SO SLAVERY AS C/C++ OR ASEMBLY PARTS.


Best. Post. EVER.

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


Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.

2013-06-28 Thread Joel Goldstick
On Fri, Jun 28, 2013 at 2:52 PM, Wayne Werner  wrote:

> On Fri, 28 Jun 2013, 8 Dihedral wrote:
>
>  KIND OF BORING TO SHOW HOW THE LISP PROGRAMMING
>> WAS ASSIMULATED BY THE PYTHON COMMUNITY.
>>
>> OF COURSE PYTHON IS A GOOD LANGUAGE FOR DEVELOPING
>> ARTIFICIAL INTELEGENT ROBOT PROGRAMS NOT SO BRAIN DAMAGES,
>> OR SO SLAVERY AS C/C++ OR ASEMBLY PARTS.
>>
>
> Best. Post. EVER.
>

In the 'general' category? or  by a 'bot'?

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



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.

2013-06-28 Thread Joshua Landau
On 28 June 2013 19:52, Wayne Werner  wrote:
> On Fri, 28 Jun 2013, 8 Dihedral wrote:
>
>> KIND OF BORING TO SHOW HOW THE LISP PROGRAMMING
>> WAS ASSIMULATED BY THE PYTHON COMMUNITY.
>>
>> OF COURSE PYTHON IS A GOOD LANGUAGE FOR DEVELOPING
>> ARTIFICIAL INTELEGENT ROBOT PROGRAMS NOT SO BRAIN DAMAGES,
>> OR SO SLAVERY AS C/C++ OR ASEMBLY PARTS.
>
>
> Best. Post. EVER.

Dihedral is the one spammer to this list who I appreciate -- he comes
up with spookily accurate gems one day and then hilarious nonsense the
next. One could with all the spammers were bots - they seem to post
less too.

Alas, Dihedral is in a class of his own.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.

2013-06-28 Thread Joel Goldstick
On Fri, Jun 28, 2013 at 3:22 PM, Joshua Landau
wrote:

> On 28 June 2013 19:52, Wayne Werner  wrote:
> > On Fri, 28 Jun 2013, 8 Dihedral wrote:
> >
> >> KIND OF BORING TO SHOW HOW THE LISP PROGRAMMING
> >> WAS ASSIMULATED BY THE PYTHON COMMUNITY.
> >>
> >> OF COURSE PYTHON IS A GOOD LANGUAGE FOR DEVELOPING
> >> ARTIFICIAL INTELEGENT ROBOT PROGRAMS NOT SO BRAIN DAMAGES,
> >> OR SO SLAVERY AS C/C++ OR ASEMBLY PARTS.
> >
> >
> > Best. Post. EVER.
>
> Dihedral is the one spammer to this list who I appreciate -- he comes
> up with spookily accurate gems one day and then hilarious nonsense the
> next. One could with all the spammers were bots - they seem to post
> less too.
>
> Alas, Dihedral is in a class of his own.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I was under the impression that Dihedral is a bot, not a person.  Amusing,
none the less

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.

2013-06-28 Thread Joshua Landau
On 28 June 2013 20:35, Joel Goldstick  wrote:
>
> On Fri, Jun 28, 2013 at 3:22 PM, Joshua Landau 
> wrote:
>>
>> On 28 June 2013 19:52, Wayne Werner  wrote:
>> > On Fri, 28 Jun 2013, 8 Dihedral wrote:
>> >
>> >> KIND OF BORING TO SHOW HOW THE LISP PROGRAMMING
>> >> WAS ASSIMULATED BY THE PYTHON COMMUNITY.
>> >>
>> >> OF COURSE PYTHON IS A GOOD LANGUAGE FOR DEVELOPING
>> >> ARTIFICIAL INTELEGENT ROBOT PROGRAMS NOT SO BRAIN DAMAGES,
>> >> OR SO SLAVERY AS C/C++ OR ASEMBLY PARTS.
>> >
>> >
>> > Best. Post. EVER.
>>
>> Dihedral is the one spammer to this list who I appreciate -- he comes
>> up with spookily accurate gems one day and then hilarious nonsense the
>> next. One could with all the spammers were bots - they seem to post
>> less too.
>>
>> Alas, Dihedral is in a class of his own.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
>
> I was under the impression that Dihedral is a bot, not a person.  Amusing,
> none the less

Well, yes; I wrote my post knowing that. I was saying with "One could
wi[s]h all the spammers were bots - they seem to post less too" that I
would rather that other spammers on this list were more like Dihedral
-- bots :P. We'd have fewer, much more enlightening posts from them
that-a way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: FACTS: WHY THE PYTHON LANGUAGE FAILS.

2013-06-28 Thread Wayne Werner

On Fri, 28 Jun 2013, Joel Goldstick wrote:





On Fri, Jun 28, 2013 at 2:52 PM, Wayne Werner  wrote:
  On Fri, 28 Jun 2013, 8 Dihedral wrote:

KIND OF BORING TO SHOW HOW THE LISP PROGRAMMING
WAS ASSIMULATED BY THE PYTHON COMMUNITY.

OF COURSE PYTHON IS A GOOD LANGUAGE FOR DEVELOPING
ARTIFICIAL INTELEGENT ROBOT PROGRAMS NOT SO BRAIN DAMAGES,
OR SO SLAVERY AS C/C++ OR ASEMBLY PARTS.


Best. Post. EVER.


In the 'general' category? or  by a 'bot'?


I think generally - because Dihedral is a bot. I don't think it would be 
nearly as awesome if it were a person.


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


Re: How to make a web framework

2013-06-28 Thread Giorgos Tzampanakis
On 2013-06-27, gamesbrain...@gmail.com wrote:

> I've used web frameworks, but I don't know how they work. Is there
> anywhere that I can learn how this all works from scratch?

Yes, read the source code of a mature framework.

-- 
Real (i.e. statistical) tennis and snooker player rankings and ratings:
http://www.statsfair.com/ 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to make a web framework

2013-06-28 Thread Joel Goldstick
On Fri, Jun 28, 2013 at 5:00 PM, Giorgos Tzampanakis <
giorgos.tzampana...@gmail.com> wrote:

> On 2013-06-27, gamesbrain...@gmail.com wrote:
>
> > I've used web frameworks, but I don't know how they work. Is there
> > anywhere that I can learn how this all works from scratch?
>

Although it is dated, there is an Apress book called Pro Django which digs
into how Django works underneath the hook. You need to understand Python at
more than a basic level to get much out of it.

>
> Yes, read the source code of a mature framework.
>
> --
> Real (i.e. statistical) tennis and snooker player rankings and ratings:
> http://www.statsfair.com/
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Survey - how much do you rely on Free/Open Source Software?

2013-06-28 Thread Tony
Hi,

I'm conducting a survey that aims to measure the importance that Open 
Source/Free Software has to people and organizations around the world.
Answering is very quick (mostly one click per answer)
Please answer it by clicking the link below:
https://docs.google.com/forms/d/1bY5KQgsuPeGMwRoTY2DWU6q-210l7RQ1kcVLRUfLlsA/viewform

After answering, you'll be able to see the results of all answers given so far.

Please help us to obtain accurate data by forwarding this survey to many 
different types of people (meaning, beyound the geek circles!)

NOTE: All answers are optional. Answering only one or two questions is 
perfectly ok.
-- 
http://mail.python.org/mailman/listinfo/python-list


indexerror: list index out of range??

2013-06-28 Thread Titiksha Joshi
Hi,
I am working on the following code but am getting the error: list index out of 
range. I surfed through the group but somehow I am not able to fix my 
error.Please guide.Structure is given below:
m is a list of 5 elements. I have to match elements of m from fields in file 
ALL_BUSES_FINAL.cvs.
m=['631138', '601034', '2834', '2908', '64808']

i=0
while i
if m[i] in line:
IndexError: list index out of range
>>> 

I see the line,a being correct but print (i) does not show up after 2. and 
index error comes up. I am too confused now. Please guide.
Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is the argparse module so inflexible?

2013-06-28 Thread Ethan Furman

On 06/27/2013 03:49 PM, Steven D'Aprano wrote:


[rant]
I think it is lousy design for a framework like argparse to raise a
custom ArgumentError in one part of the code, only to catch it elsewhere
and call sys.exit. At the very least, that ought to be a config option,
and off by default.

Libraries should not call sys.exit, or raise SystemExit. Whether to quit
or not is not the library's decision to make, that decision belongs to
the application layer. Yes, the application could always catch
SystemExit, but it shouldn't have to.


So a library that is explicitly designed to make command-line scripts easier 
and friendlier should quit with a traceback?

Really?

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


Re: Why is the argparse module so inflexible?

2013-06-28 Thread Modulok
Have you looked into docopt?

-Modulok-


On Fri, Jun 28, 2013 at 7:36 PM, Ethan Furman  wrote:

> On 06/27/2013 03:49 PM, Steven D'Aprano wrote:
>
>>
>> [rant]
>> I think it is lousy design for a framework like argparse to raise a
>> custom ArgumentError in one part of the code, only to catch it elsewhere
>> and call sys.exit. At the very least, that ought to be a config option,
>> and off by default.
>>
>> Libraries should not call sys.exit, or raise SystemExit. Whether to quit
>> or not is not the library's decision to make, that decision belongs to
>> the application layer. Yes, the application could always catch
>> SystemExit, but it shouldn't have to.
>>
>
> So a library that is explicitly designed to make command-line scripts
> easier and friendlier should quit with a traceback?
>
> Really?
>
> --
> ~Ethan~
> --
> http://mail.python.org/**mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: indexerror: list index out of range??

2013-06-28 Thread Chris Angelico
On Sat, Jun 29, 2013 at 11:20 AM, Titiksha Joshi
 wrote:
> Hi,
> I am working on the following code but am getting the error: list index out 
> of range. I surfed through the group but somehow I am not able to fix my 
> error.Please guide.Structure is given below:
> m is a list of 5 elements. I have to match elements of m from fields in file 
> ALL_BUSES_FINAL.cvs.
> m=['631138', '601034', '2834', '2908', '64808']
>
> i=0
> while i print(i)
> my_file = open("ALL_BUSES_FINAL.csv", "r+")
> for line in my_file:
> if m[i] in line:
> print (line)
> a.append(line)
> i+=1
> print(a)
> my_file.close()

What this does is open the file once for every string in 'm', and read
through it. But you increment i for every line in the file, that's why
you're having problems.

I think you probably want to open the file once and iterate over it,
but you'll need to figure out what you're trying to do before you can
figure out how to do it in Python :)

Also, be up-front about homework assignments. Honesty won't hurt you
(since we can all tell anyway), and it means we know you're trying to
learn, not to cheat. And yes, there are a discouraging number of
people who do try to cheat, so setting yourself apart from them is
well worth it. :)

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


Re: indexerror: list index out of range??

2013-06-28 Thread Dave Angel

On 06/28/2013 09:20 PM, Titiksha Joshi wrote:

Hi,
I am working on the following code but am getting the error: list index out of 
range. I surfed through the group but somehow I am not able to fix my 
error.Please guide.Structure is given below:
m is a list of 5 elements. I have to match elements of m from fields in file 
ALL_BUSES_FINAL.cvs.
m=['631138', '601034', '2834', '2908', '64808']



It's not hard to see what's wrong in the following excerpt, but it is 
hard to guess what you really wanted.


Did you want to find all lines which match any of the strings in m?  Or 
are you just satisfied to match each of the strings in m against *some* 
line of the file?  Or is it something else entirely?


You have a nested loop here (for loop inside a while loop), and you're 
confusing the limit values for the outer one.



i=0
while i

You increment i here, but do not check if it's reached the end of the m. 
 So eventually it does, and crashes.



 print(a)
 my_file.close()


The output is as follows:
0
LAKEFLD  3227,631138

['LAKEFLD  3227,631138\n']

1
NOBLES   3013,601034

['LAKEFLD  3227,631138\n', 'NOBLES   3013,601034\n']

2
GR_ISLD  I,2834

['LAKEFLD  3227,631138\n', 'NOBLES   3013,601034\n', 'GR_ISLD  I,2834\n']

FTTHOMP  928,2908

['LAKEFLD  3227,631138\n', 'NOBLES   3013,601034\n', 'GR_ISLD  I,2834\n', 
'FTTHOMP  928,2908\n']

VICTRYH  15,64808

['LAKEFLD  3227,631138\n', 'NOBLES   3013,601034\n', 'GR_ISLD  I,2834\n', 
'FTTHOMP  928,2908\n', 'VICTRYH  15,64808\n']
Traceback (most recent call last):
   File "C:\Users\TJ\dist_tracking.py", line 40, in 
 if m[i] in line:
IndexError: list index out of range




I see the line,a being correct but print (i) does not show up after 2. and 
index error comes up. I am too confused now. Please guide.
Thanks in advance.



Another big problem will arise as soon as you have a string in m which 
is a strict substring of a value in the line.  You'll get false matches. 
 So presumably you really want to use csv logic, and have explicit 
fields that you're searching for, rather than using 'in' operator.  And 
at that point, maybe you just want to check field #2 of each line.



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


python adds an extra half space when reading from a string or list

2013-06-28 Thread charles benoit
number_drawn=()
def load(lot_number,number_drawn):
first=input("enter first lot: ")
last=input("enter last lot: ")
for lot_number in range(first,last):
line_out=str(lot_number)
for count in range(1,5):
number_drawn=raw_input("number: ")
line_out=line_out+(number_drawn)
print line_out
finale_line.append(line_out)
finale_line2=finale_line

load(lot_number,number_drawn)


print finale_line
print(" "*4),
for n in range(1,41):
print n,  #this is to produce a line of numbers to compare to
output#
for a in finale_line:
print"\n",
print a[0]," ",
space_count=1
for b in range(1,5):
if int(a[b])<10:
 print(" "*(int(a[b])-space_count)),int(a[b]),
 space_count=int(a[b])
else:
print(" "*(a[b]-space_count)),a[b],
space_count=a[b]+1







number_drawn=()
def load(lot_number,number_drawn):
first=input("enter first lot: ")
last=input("enter last lot: ")
for lot_number in range(first,last):
line_out=str(lot_number)
for count in range(1,5):
number_drawn=raw_input("number: ")
line_out=line_out+(number_drawn)
print line_out
finale_line.append(line_out)
finale_line2=finale_line

load(lot_number,number_drawn)


print finale_line
print(" "*4),
for n in range(1,41):
print n,  #this is to produce a line of numbers to compare to
output#
for a in finale_line:
print"\n",
print a[0]," ",
space_count=1
for b in range(1,5):
if int(a[b])<10:
 print(" "*(int(a[b])-space_count)),int(a[b]),
 space_count=int(a[b])
else:
print(" "*(a[b]-space_count)),a[b],
space_count=a[b]+1








this generates

enter first lot: 1
enter last lot: 4
number: 2
number: 3
number: 4
number: 5
12345
number: 1
number: 2
number: 3
number: 4
21234
number: 3
number: 4
number: 5
number: 6
33456
['12345', '21234', '33456']
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40
1 2   3   4   5
21   2   3   4
3  3   4   5   6
>#as you can see many numbers are between the lines of a normal print#
#I thought this was due to "white space" int he format .So I tried  a list
of strings and got the same results.#
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: indexerror: list index out of range??

2013-06-28 Thread Titiksha
On Friday, June 28, 2013 8:20:28 PM UTC-5, Titiksha wrote:
> Hi,
> 
> I am working on the following code but am getting the error: list index out 
> of range. I surfed through the group but somehow I am not able to fix my 
> error.Please guide.Structure is given below:
> 
> m is a list of 5 elements. I have to match elements of m from fields in file 
> ALL_BUSES_FINAL.cvs.
> 
> m=['631138', '601034', '2834', '2908', '64808']
> 
> 
> 
> i=0
> 
> while i 
> print(i)
> 
> my_file = open("ALL_BUSES_FINAL.csv", "r+")
> 
> for line in my_file:
> 
> if m[i] in line:
> 
> print (line)
> 
> a.append(line)
> 
> i+=1
> 
> print(a)
> 
> my_file.close()
> 
> 
> 
> 
> 
> The output is as follows:
> 
> 0
> 
> LAKEFLD  3227,631138
> 
> 
> 
> ['LAKEFLD  3227,631138\n']
> 
> 
> 
> 1
> 
> NOBLES   3013,601034
> 
> 
> 
> ['LAKEFLD  3227,631138\n', 'NOBLES   3013,601034\n']
> 
> 
> 
> 2
> 
> GR_ISLD  I,2834
> 
> 
> 
> ['LAKEFLD  3227,631138\n', 'NOBLES   3013,601034\n', 'GR_ISLD  I,2834\n']
> 
> 
> 
> FTTHOMP  928,2908
> 
> 
> 
> ['LAKEFLD  3227,631138\n', 'NOBLES   3013,601034\n', 'GR_ISLD  I,2834\n', 
> 'FTTHOMP  928,2908\n']
> 
> 
> 
> VICTRYH  15,64808
> 
> 
> 
> ['LAKEFLD  3227,631138\n', 'NOBLES   3013,601034\n', 'GR_ISLD  I,2834\n', 
> 'FTTHOMP  928,2908\n', 'VICTRYH  15,64808\n']
> 
> Traceback (most recent call last):
> 
>   File "C:\Users\TJ\dist_tracking.py", line 40, in 
> 
> if m[i] in line:
> 
> IndexError: list index out of range
> 
> >>> 
> 
> 
> 
> I see the line,a being correct but print (i) does not show up after 2. and 
> index error comes up. I am too confused now. Please guide.
> 
> Thanks in advance.

Thanks for helping out! 
Dave you mentioned about false matches in case of string in m is substring of 
line. How do I manage that issue? Is there any other method I should look into?

What I am looking to do is..I have a list of m which I need to map in the same 
sequence to the ALL_BUSES_FINAL file and get the entire line which has the 
string in m.I want to iterate through all the lines in ALL_BUSES_FINAL to match 
the all strings in m.




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


Re: Why is the argparse module so inflexible?

2013-06-28 Thread rusi
On Saturday, June 29, 2013 7:06:37 AM UTC+5:30, Ethan Furman wrote:
> On 06/27/2013 03:49 PM, Steven D'Aprano wrote:
> > [rant]
> > I think it is lousy design for a framework like argparse to raise a
> > custom ArgumentError in one part of the code, only to catch it elsewhere
> > and call sys.exit. At the very least, that ought to be a config option,
> > and off by default.
> >
> > Libraries should not call sys.exit, or raise SystemExit. Whether to quit
> > or not is not the library's decision to make, that decision belongs to
> > the application layer. Yes, the application could always catch
> > SystemExit, but it shouldn't have to.
> 
> 
> So a library that is explicitly designed to make command-line scripts easier 
> and friendlier should quit with a traceback?
> 
> Really?

So a library that behaves like an app is OK?

Really?

I would have thought that with the sophistication of python's exception 
mechanism in place there would be corresponding peps in place proscribing such 
behavior.  In the same way that if I submitted my super-duper library for 
inclusion into python with 7 spaces indentation, some kind dev would reply with

http://www.python.org/dev/peps/pep-0008/#indentation
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is the argparse module so inflexible?

2013-06-28 Thread Isaac To
On Sat, Jun 29, 2013 at 9:36 AM, Ethan Furman  wrote:

> On 06/27/2013 03:49 PM, Steven D'Aprano wrote:
>
>>
>> Libraries should not call sys.exit, or raise SystemExit. Whether to quit
>> or not is not the library's decision to make, that decision belongs to
>> the application layer. Yes, the application could always catch
>> SystemExit, but it shouldn't have to.
>>
>
> So a library that is explicitly designed to make command-line scripts
> easier and friendlier should quit with a traceback?
>
> Really?
>

Perhaps put the functionality "handling of the exception of library to
sys.exit with a message" into a method so that the user can override it
(e.g., so that it just throw the same exception to the caller of the
library)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is the argparse module so inflexible?

2013-06-28 Thread Terry Reedy

On 6/29/2013 12:12 AM, rusi wrote:

On Saturday, June 29, 2013 7:06:37 AM UTC+5:30, Ethan Furman wrote:

On 06/27/2013 03:49 PM, Steven D'Aprano wrote:

[rant]
I think it is lousy design for a framework like argparse to raise a
custom ArgumentError in one part of the code, only to catch it elsewhere
and call sys.exit. At the very least, that ought to be a config option,
and off by default.

Libraries should not call sys.exit, or raise SystemExit. Whether to quit
or not is not the library's decision to make, that decision belongs to
the application layer. Yes, the application could always catch
SystemExit, but it shouldn't have to.



So a library that is explicitly designed to make command-line scripts easier
and friendlier should quit with a traceback?

Really?


So a library that behaves like an app is OK?


No, Steven is right as a general rule (do not raise SystemExit), but 
argparse was considered an exception because its purpose is to turn a 
module into an app. With the responses I have seen here, I agree that 
this is a bit short-sighted, as inflexible behavior. The tracker issue 
could use more review and comment.


--
Terry Jan Reedy

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


Re: Why is the argparse module so inflexible?

2013-06-28 Thread Steven D'Aprano
On Fri, 28 Jun 2013 18:36:37 -0700, Ethan Furman wrote:

> On 06/27/2013 03:49 PM, Steven D'Aprano wrote:
>>
>> [rant]
>> I think it is lousy design for a framework like argparse to raise a
>> custom ArgumentError in one part of the code, only to catch it
>> elsewhere and call sys.exit. At the very least, that OUGHT TO BE A
>> CONFIG OPTION, and OFF BY DEFAULT.

[emphasis added]

>> Libraries should not call sys.exit, or raise SystemExit. Whether to
>> quit or not is not the library's decision to make, that decision
>> belongs to the application layer. Yes, the application could always
>> catch SystemExit, but it shouldn't have to.
> 
> So a library that is explicitly designed to make command-line scripts
> easier and friendlier should quit with a traceback?
> 
> Really?

Yes, really.

Tracebacks are not that unfriendly, generally speaking. In my experience, 
the average non-technical person is no more confused and distressed by a 
traceback extending over thirty lines than they are by a one line error 
message. As the developer, I should see the tracebacks by default[1]. If 
I want to suppress or simplify them, then I should take explicit steps to 
do so, either by catching the exception and calling sys.exit myself, or 
at least by setting a runtime config option to the library.

This also allows me to enable debugging in my app by showing tracebacks, 
or disable it by hiding them. That should be my decision, not the 
library. If the library catches exceptions then exits, throwing away 
potentially useful information, that makes it difficult to debug anything 
relying on the library.

I'm willing to concede that, just maybe, something like argparse could 
default to "catch exceptions and exit" ON rather than OFF. 


[1] There's something in the Zen of Python about that...


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