numpy array operation

2013-01-29 Thread C. Ng
Is there a numpy operation that does the following to the array?

1 2  ==>  4 3
3 4   2 1

Thanks in advance.


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


Re: numpy array operation

2013-01-29 Thread Peter Otten
C. Ng wrote:

> Is there a numpy operation that does the following to the array?
> 
> 1 2  ==>  4 3
> 3 4   2 1

How about

>>> a
array([[1, 2],
   [3, 4]])
>>> a[::-1].transpose()[::-1].transpose()
array([[4, 3],
   [2, 1]])

Or did you mean

>>> a.reshape((4,))[::-1].reshape((2,2))
array([[4, 3],
   [2, 1]])

Or even

>>> -a + 5
array([[4, 3],
   [2, 1]])


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


Re: Further evidence that Python may be the best language forever

2013-01-29 Thread Michael Poeltl
hi Stefan,

* Stefan Behnel  [2013-01-29 08:00]:
> Michael Torrie, 29.01.2013 02:15:
> > On 01/28/2013 03:46 PM, Malcolm McCrimmon wrote:
> >> My company recently hosted a programming competition for schools
> >> across the country.  One team made it to the finals using the Python
> >> client, one of the four default clients provided (I wrote it).  Most
> >> of the other teams were using Java or C#.  Guess which team won?
> >>
> >> http://www.windward.net/codewar/2013_01/finals.html
> 
> We did a similar (although way smaller) contest once at a university. The
> task was to write a network simulator. We had a C team, a Java team and a
> Python team, four people each. The Java and C people knew their language,
> the Python team just started learning it.
> 
> The C team ended up getting totally lost and failed. The Java team got most
> things working ok and passed. The Python team got everything working, but
> additionally implemented a web interface for the simulator that monitored
> and visualised its current state. They said it helped them with debugging.
quite interesting!
I'd liked to see the code
is it available for 'download'?

thx
Michael
> 
> 
> > What language was the web page hosted in?  It comes up completely blank
> > for me. :)
> 
> Yep, same here. Hidden behind a flash wall, it seems.
> 
> Stefan
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list

-- 
Michael Poeltl
Computational Materials Physics  voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
---
slackware-13.37 | vim-7.3 | python-3.2.3 | mutt-1.5.21 | elinks-0.12
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy array operation

2013-01-29 Thread Tim Williams
On Tuesday, January 29, 2013 3:41:54 AM UTC-5, C. Ng wrote:
> Is there a numpy operation that does the following to the array?
> 
> 
> 
> 1 2  ==>  4 3
> 
> 3 4   2 1
> 
> 
> 
> Thanks in advance.

>>> import numpy as np
>>> a=np.array([[1,2],[3,4]])
>>> a
array([[1, 2],
   [3, 4]])
>>> np.fliplr(np.flipud(a))
array([[4, 3],
   [2, 1]])

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


[os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread iMath
why [os.path.join(r'E:\Python', name) for name in []] returns [] ?
please explain it in detail !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread Chris Angelico
On Wed, Jan 30, 2013 at 12:21 AM, iMath  wrote:
> why [os.path.join(r'E:\Python', name) for name in []] returns [] ?
> please explain it in detail !

That's a list comprehension. If you're familiar with functional
programming, it's like a map operation. Since the input list (near the
end of the comprehension, just inside its square brackets) is empty,
so is the result list, and os.path.join is never called.

I've given you a massive oversimplification. The docs are here:

http://docs.python.org/3.3/tutorial/datastructures.html#list-comprehensions

Pro tip: The docs are there before you ask the question, too. You
might find it faster to search them than to ask and wait for an answer
:)

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


Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread Jean-Michel Pichavant
- Original Message -
> why [os.path.join(r'E:\Python', name) for name in []] returns [] ?
> please explain it in detail !
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

You're mapping an empty list.

"for name in []"

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread Steven D'Aprano
iMath wrote:

> why [os.path.join(r'E:\Python', name) for name in []] returns [] ?

Because you are iterating over an empty list, [].

That list comprehension is the equivalent of:


result = []
for name in []:
result.append( os.path.join(r'E:\Python', name) )


Since you iterate over an empty list, the body of the loop never executes, 
and the result list remains empty.

What did you expect it to do?


-- 
Steven

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


Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread Dave Angel

On 01/29/2013 08:21 AM, iMath wrote:

why [os.path.join(r'E:\Python', name) for name in []] returns [] ?
please explain it in detail !



[ os.path.join(r'E:\Python', name) for name in [] ]

It'd be nice if you would explain what part of it bothers you.  Do you 
know what a list comprehension is?  Do you know how to decompose a list 
comprehension into a for-loop?  Do you know that [] is an empty list object?



res = []
for name in []:
res.append(  )

Since the for loop doesn't loop even once, the result is the initial 
value, the empty loop.


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


Re: environment fingerprint

2013-01-29 Thread Andrew Berg
On 2013.01.29 07:18, Jabba Laci wrote:
> Hi,
> 
> I have a script that I want to run in different environments: on
> Linux, on Windows, on my home machine, at my workplace, in virtualbox,
> etc. In each environment I want to use different configurations. For
> instance the temp. directory on Linux would be /tmp, on Windows
> c:\temp, etc. When the script starts, I want to test the environment
> and load the corresponding config. settings. How to get an
> OS-independent fingerprint of the environment?
http://docs.python.org/3.3/library/platform.html
http://docs.python.org/3.3/library/os.html#os.environ

-- 
CPython 3.3.0 | Windows NT 6.2.9200.16461 / FreeBSD 9.1-RELEASE
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixxx DJ app and Python

2013-01-29 Thread David Hutto
On Mon, Jan 28, 2013 at 10:10 AM,   wrote:
>
> Hi guys,
>
> I am thinking of driving a DJ application from Python.
> I am running Linux and I found the Mixxx app.
> Does anyone know if there are python bindings, or if this is possible at all?
> or does anyone have experience with another software that does the same DJ 
> thing?
>
> I have also found the pymixxx module that I could install... but I didn't 
> find any documentation so far or example code that could help me start (I'm 
> keeping on searching).
>
> Finally maybe that there is any DJ app that could be driven by pygame.midi?
>
> Any idea appreciated.
> Sorry to fail to be more specific.

I'd just go with a command line app that triggered a .wav file at
certain points using time.sleep(x)

Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixxx DJ app and Python

2013-01-29 Thread David Hutto
On Tue, Jan 29, 2013 at 11:06 AM, David Hutto  wrote:
> On Mon, Jan 28, 2013 at 10:10 AM,   wrote:
>>
>> Hi guys,
>>
>> I am thinking of driving a DJ application from Python.
>> I am running Linux and I found the Mixxx app.
>> Does anyone know if there are python bindings, or if this is possible at all?
>> or does anyone have experience with another software that does the same DJ 
>> thing?
>>

Hydrogen, and audacity work perfectly together.


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixxx DJ app and Python

2013-01-29 Thread David Hutto
>>> Does anyone know if there are python bindings, or if this is possible at 
>>> all?
>>> or does anyone have experience with another software that does the same DJ 
>>> thing?
>>>
>
>Hydrogen, and audacity work perfectly together.


What I was about to do is take the mic, get the soundtrack/beat to the
song going, and then plug it into audacity for further modification,
or you can roll your own.

--


Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixxx DJ app and Python

2013-01-29 Thread David Hutto
On Tue, Jan 29, 2013 at 11:16 AM, David Hutto  wrote:
 Does anyone know if there are python bindings, or if this is possible at 
 all?
 or does anyone have experience with another software that does the same DJ 
 thing?

>>
>>Hydrogen, and audacity work perfectly together.
>
>
 What I was about to do is take the output to the headphones, get the
soundtrack/beat to the
 song going, and then plug it into audacity(mic) for further modification,
 or you can roll your own.

> --
>
>
> Best Regards,
> David Hutto
> CEO: http://www.hitwebdevelopment.com



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I have issues installing pycrypto (and thus fabric) with pip

2013-01-29 Thread Nicholas Kolatsis
Thanks. I've gotten everything working now.

For anyone else who comes along, 'sudo apt-get install python-dev' did the job.

> 
> Note that Fabric is useful for much, MUCH more than this.
> 

I look forward to finding out :)

> 
> Off-topic: why is your virtualenv/project name so weird?
> 

Noted. It's the naming pattern that I use for my projects. I should use 
something better but I'm using this because I usually restart something several 
times before I'm happy with it. I was reading up on branching with git earlier. 
It looks like that will put an end to this bad practice.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixxx DJ app and Python

2013-01-29 Thread mikprog
On Tuesday, January 29, 2013 4:13:09 PM UTC, David Hutto wrote:
[..]
> 
> >> or does anyone have experience with another software that does the same DJ 
> >> thing?
> 
> 
> 
> 
> Hydrogen, and audacity work perfectly together.


Hi David,
thanks for your reply.
I am not sure though that this is going to help me.
We have built a kind of basic controller that sends commands via bluetooth. 
Then I should have some device (like a linux pc or raspberry Pi) where I have 
my applications that listen for these bluetooth commands and drives a DJ 
application accordingly (like mixing two sounds, sync them etc).

Obviously to write the whole application will take ages and I saw that the 
Mixxx one does everything I want.
So I am searching for a way to interface to it programatically.

Do you mean that Hydrogen and Audacity would replace the Mixxx app and I can 
call their functionality from Python?
Or were you thinking about something else?

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


Re: Mixxx DJ app and Python

2013-01-29 Thread David Hutto
On Tue, Jan 29, 2013 at 11:18 AM,   wrote:
> On Tuesday, January 29, 2013 4:13:09 PM UTC, David Hutto wrote:
> [..]
>>
>> >> or does anyone have experience with another software that does the same 
>> >> DJ thing?
>>
>>
>>
>>
>> Hydrogen, and audacity work perfectly together.
>
>
> Hi David,
> thanks for your reply.
> I am not sure though that this is going to help me.
> We have built a kind of basic controller that sends commands via bluetooth.
> Then I should have some device (like a linux pc or raspberry Pi) where I have 
> my applications that listen for these bluetooth commands and drives a DJ 
> application accordingly (like mixing two sounds, sync them etc).
>
> Obviously to write the whole application will take ages and I saw that the 
> Mixxx one does everything I want.
> So I am searching for a way to interface to it programatically.


Well you can just use their(Mixx's) source code that they used from
another wav form manipulation library(more than likely), after the
trigger from the bluetooth. If you're talking voice, and music to
sync, then either go with transmitting at the same, or take two
receivers(one for each transmitter), and run them in unison on
different frequencies, after they've been received..

I've never tried this, but it seems logical.

>
> Do you mean that Hydrogen and Audacity would replace the Mixxx app and I can 
> call their functionality from Python?
> Or were you thinking about something else?
>
> Thanks,
> Mik
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixxx DJ app and Python

2013-01-29 Thread Ben
This may not be too helpful, but I built a TCP server into the Mixxx 
application (in C++). I placed the server in ratecontroller (as I needed to 
vary the rate remotely). I then could send and receive TCP packets with a 
single board computer that ran a python client.

It wasn't too bad. If you want I can see if I can release the server code.

On Tuesday, January 29, 2013 11:19:34 AM UTC-5, David Hutto wrote:
> On Tue, Jan 29, 2013 at 11:16 AM, David Hutto  wrote:
> 
>  Does anyone know if there are python bindings, or if this is possible at 
>  all?
> 
>  or does anyone have experience with another software that does the same 
>  DJ thing?
> 
> 
> 
> >>
> 
> >>Hydrogen, and audacity work perfectly together.
> 
> >
> 
> >
> 
>  What I was about to do is take the output to the headphones, get the
> 
> soundtrack/beat to the
> 
>  song going, and then plug it into audacity(mic) for further modification,
> 
>  or you can roll your own.
> 
> 
> 
> > --
> 
> >
> 
> >
> 
> > Best Regards,
> 
> > David Hutto
> 
> > CEO: http://www.hitwebdevelopment.com
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Best Regards,
> 
> David Hutto
> 
> CEO: http://www.hitwebdevelopment.com

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


Re: Mixxx DJ app and Python

2013-01-29 Thread David Hutto
On Tue, Jan 29, 2013 at 11:45 AM, Ben  wrote:
> This may not be too helpful, but I built a TCP server into the Mixxx 
> application (in C++). I placed the server in ratecontroller (as I needed to 
> vary the rate remotely). I then could send and receive TCP packets with a 
> single board computer that ran a python client.
>
>

So you used a digital buffer region for your wave forms? How did you
handle the rest of the data; allocate memory, or delete if the data
became too lengthy?

-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Split string data have ","

2013-01-29 Thread moonhkt
Hi All

Python 2.6.2 on AIX 5.3
How to using split o

>>> y = '"abc.p,zip.p",a,b'
>>> print y
"abc.p,zip.p",a,b
>>>

>>> k= y.split(",")
>>> print k[0]
"abc.p
>>>

Need Result, First element is
abc.p,zip.p
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mixxx DJ app and Python

2013-01-29 Thread mikprog
On Tuesday, January 29, 2013 4:45:18 PM UTC, Ben wrote:
> This may not be too helpful, but I built a TCP server into the Mixxx 
> application (in C++). I placed the server in ratecontroller (as I needed to 
> vary the rate remotely). I then could send and receive TCP packets with a 
> single board computer that ran a python client.


Hi Ben,
this would be actually interesting to look at.
If you are not going to face problems, please send me the code.

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


RE: Split string first data have ",

2013-01-29 Thread Nick Cash
> >>> y = '"abc.p,zip.p",a,b'
> >>> print y
> "abc.p,zip.p",a,b
> >>>

>>> x = "what is your question??"
>>> print x

I'm guessing that you want to split on ",", but want the quoted section to be a 
single token? 
Have you looked at the CSV module (http://docs.python.org/3/library/csv.html)?

If my guess is wrong, or you're having difficulties with the csv module, a more 
specific question will help you get the answer you're looking for.

-Nick Cash

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


Re: Mixxx DJ app and Python

2013-01-29 Thread mikprog
On Tuesday, January 29, 2013 4:42:07 PM UTC, David Hutto wrote:
[..]
> 
> Well you can just use their(Mixx's) source code that they used from
> 
> another wav form manipulation library(more than likely), after the
> 
> trigger from the bluetooth. If you're talking voice, and music to
> 
> sync, then either go with transmitting at the same, or take two
> 
> receivers(one for each transmitter), and run them in unison on
> 
> different frequencies, after they've been received..
> 
> 
> 
> I've never tried this, but it seems logical.
> 

Thanks David.
It seems that the code is in C++ so I should write Python wrappers myself, 
which could be interesting, but given the time frame I have is just not 
possible, Pity :-(
However I was not going to transmit sounds, but just commands to mix the sounds 
that are already in the same machine were the Mixxx is going to run.
I hope I will have time to come back to it in future.

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


Re: Split string data have ","

2013-01-29 Thread Tim Chase
On Tue, 29 moonhkt  wrote:
> >>> y = '"abc.p,zip.p",a,b'
> >>> print y
> "abc.p,zip.p",a,b
> >>>
> 
> >>> k= y.split(",")
> >>> print k[0]
> "abc.p
> >>>
> 
> Need Result, First element is
> abc.p,zip.p

The csv module should handle this nicely:

  >>> import csv
  >>> y = '"abc.p,zip.p",a,b'
  >>> print y
  "abc.p,zip.p",a,b
  >>> r = csv.reader([y])
  >>> print r.next()
  ['abc.p,zip.p', 'a', 'b']

-tkc



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


Re: Mixxx DJ app and Python

2013-01-29 Thread David Hutto
> Thanks David.
> It seems that the code is in C++ so I should write Python wrappers myself,

Or ctypes.
which could be interesting, but given the time frame I have is just
not possible, Pity :-(
> However I was not going to transmit sounds, but just commands to mix the 
> sounds that are already in the same machine were the Mixxx is going to run.


A filter is minutia in comparison of code

so it was always going to be a comand line app, with a python GUI, to
perform alterations on the wave forms?.

> I hope I will have time to come back to it in future.
>

Just a little practice, that makes every programmer listening scramble.


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Split string data have ","

2013-01-29 Thread Chris Rebert
On Jan 29, 2013 9:05 AM, "moonhkt"  wrote:
>
> Hi All
>
> Python 2.6.2 on AIX 5.3
> How to using split o
>
> >>> y = '"abc.p,zip.p",a,b'
> >>> print y
> "abc.p,zip.p",a,b
> >>>
>
> >>> k= y.split(",")
> >>> print k[0]
> "abc.p
> >>>
>
> Need Result, First element is
> abc.p,zip.p

Try the csv module or the shlex module.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ] returns []

2013-01-29 Thread rusi
On Jan 29, 6:22 pm, iMath  wrote:
> 在 2013年1月29日星期二UTC+8下午9时21分16秒,iMath写道:
>
> > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? please 
> > explain it in detail !
> >>> [os.path.join(r'E:\Python', name) for name in []]
>
> []

[Small algebra lesson]
In algebra there is the concept of identity and absorbent.
For example, 1 is the identity for multiply and 0 is the absorbent.
ie for all x: 1 * x = x
and 0 * x = 0
[end algebra lesson]

In the case of lists, [] is an identity for ++ but behaves like an
absorbent for comprehensions.
Modern terminology for 'absorbent' is 'zero-element'. I personally
find the older terminology more useful.

Others have pointed out why operationally [] behaves like an absorbent
in comprehensions.
Ive seen even experienced programmers trip up on this so I believe its
good to know it as an algebraic law in addition to the operational
explanation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Further evidence that Python may be the best language forever

2013-01-29 Thread Malcolm McCrimmon
Sure!  I don't think we've publicly posted the teams' implementations, but the 
original client code is all up 
here--http://www.windward.net/codewar/2013_01/windwardopolis.php

The issue with the original link may be if you're running Firefox--it's a Vimeo 
video, and I know they have some ongoing issues with Firefox that prevent their 
videos from displaying or playing back.

On Tuesday, January 29, 2013 3:31:05 AM UTC-7, Michael Poeltl wrote:
> hi Stefan,
> 
> 
> 
> * Stefan Behnel  [2013-01-29 08:00]:
> 
> > Michael Torrie, 29.01.2013 02:15:
> 
> > > On 01/28/2013 03:46 PM, Malcolm McCrimmon wrote:
> 
> > >> My company recently hosted a programming competition for schools
> 
> > >> across the country.  One team made it to the finals using the Python
> 
> > >> client, one of the four default clients provided (I wrote it).  Most
> 
> > >> of the other teams were using Java or C#.  Guess which team won?
> 
> > >>
> 
> > >> http://www.windward.net/codewar/2013_01/finals.html
> 
> > 
> 
> > We did a similar (although way smaller) contest once at a university. The
> 
> > task was to write a network simulator. We had a C team, a Java team and a
> 
> > Python team, four people each. The Java and C people knew their language,
> 
> > the Python team just started learning it.
> 
> > 
> 
> > The C team ended up getting totally lost and failed. The Java team got most
> 
> > things working ok and passed. The Python team got everything working, but
> 
> > additionally implemented a web interface for the simulator that monitored
> 
> > and visualised its current state. They said it helped them with debugging.
> 
> quite interesting!
> 
> I'd liked to see the code
> 
> is it available for 'download'?
> 
> 
> 
> thx
> 
> Michael
> 
> > 
> 
> > 
> 
> > > What language was the web page hosted in?  It comes up completely blank
> 
> > > for me. :)
> 
> > 
> 
> > Yep, same here. Hidden behind a flash wall, it seems.
> 
> > 
> 
> > Stefan
> 
> > 
> 
> > 
> 
> > -- 
> 
> > http://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> -- 
> 
> Michael Poeltl
> 
> Computational Materials Physics  voice: +43-1-4277-51409
> 
> Univ. Wien, Sensengasse 8/12 fax:   +43-1-4277-9514 (or 9513) 
> 
> A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
> 
> ---
> 
> slackware-13.37 | vim-7.3 | python-3.2.3 | mutt-1.5.21 | elinks-0.12
> 
> ---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The best, friendly and easy use Python Editor.

2013-01-29 Thread rusi
On Jan 25, 10:35 pm, "Leonard, Arah" 
wrote:
> >> It's just a text file after all.
>
> > True indeed, let's not worry about trivial issues like indentation, mixing 
> > tabs and spaces or whatever.  Notepad anybody? :)
>
> Hey, I didn't say Notepad was the *best* tool for the job, just that Python 
> scripts are merely
> text files.

"text files" ok. "Merely text files" needs some rebuttal
http://blog.languager.org/2012/10/html-is-why-mess-in-programming-syntax.html
Yeah its a bit tongue-in-cheek and does not directly answer the OP (to
which anyway I said: interpreter is more important than editor)
-- 
http://mail.python.org/mailman/listinfo/python-list


Galry, a high-performance interactive visualization package in Python

2013-01-29 Thread Cyrille Rossant
Dear all,

I'm making available today a first pre-release of Galry <
http://rossant.github.com/galry/>, a BSD-licensed high performance
interactive visualization toolbox in Python based on OpenGL. Its
matplotlib-like high-level interface allows to interactively visualize
plots with tens of millions of points. Galry is highly flexible and
natively supports 2D plots, 3D meshes, text, planar graphs, images, custom
shaders, etc. The low-level interface can be used to write graphical
interfaces in Qt with efficient visualization widgets.

The goal of this beta pre-release is to ensure that Galry can work on the
widest possible range of systems and graphics cards (OpenGL v2+ is
required).

If you're interested, please feel free to give it a try! Also, I'd very
much appreciate if you could fill in a really short form on the webpage to
indicate what you'd like to do with this package. Your feedback will be
invaluable in the future development of Galry.

Best regards,
Cyrille Rossant
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numpy array operation

2013-01-29 Thread Alok Singhal
On Tue, 29 Jan 2013 00:41:54 -0800, C. Ng wrote:

> Is there a numpy operation that does the following to the array?
> 
> 1 2  ==>  4 3
> 3 4   2 1
> 
> Thanks in advance.

How about:

>>> import numpy as np
>>> a = np.array([[1,2],[3,4]])
>>> a
array([[1, 2],
   [3, 4]])
>>> a[::-1, ::-1]
array([[4, 3],
   [2, 1]])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Galry, a high-performance interactive visualization package in Python

2013-01-29 Thread Terry Reedy

On 1/29/2013 1:23 PM, Cyrille Rossant wrote:


The goal of this beta pre-release is to ensure that Galry can work on
the widest possible range of systems and graphics cards (OpenGL v2+ is
required).

> 

From that site:
"Mandatory dependencies include Python 2.7,"

For a new, still-beta package, this is somewhat sad. 2.7 is 3.5 years 
old and has only 1.5 years of semi-normal maintainance left. It will be 
more like 1 year when you get to your final release.


If you are not supporting anything before 2.7, it should not be hard to 
make your python code also support 3.x. Use the future imports for print 
and unicode. Others have written more guidelines.


"Numpy, either PyQt4 or PySide, PyOpenGL, matplotlib"

These all support 3.2,3.3 (PyOpenGl says 'experimental').

--
Terry Jan Reedy


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


Re: numpy array operation

2013-01-29 Thread Terry Reedy

On 1/29/2013 1:49 PM, Alok Singhal wrote:

On Tue, 29 Jan 2013 00:41:54 -0800, C. Ng wrote:


Is there a numpy operation that does the following to the array?

1 2  ==>  4 3
3 4   2 1

Thanks in advance.


How about:


import numpy as np
a = np.array([[1,2],[3,4]])
a

array([[1, 2], [3, 4]])

a[::-1, ::-1]

array([[4, 3], [2, 1]])



Nice. The regular Python equivalent is

a = [[1,2],[3,4]]
print([row[::-1] for row in a[::-1]])
>>>
[[4, 3], [2, 1]]

The second slice can be replaced with reversed(a), which returns an 
iterator, to get

[row[::-1] for row in reversed(a)]
The first slice would have to be list(reversed(a)) to get the same result.

--
Terry Jan Reedy

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


Quepy, transform questions in natural language into queries in a DB language using python

2013-01-29 Thread Elias Andrawos
We are sharing an open source framework that we made here at
Machinalis: Quepy https://github.com/machinalis/quepy

Quepy is a Python framework to transform questions in natural language into
queries in a database language.
It can be easily adapted to different types of questions in natural
language, so that with little code you can build your own interface to
a database in natural language.

Currently, Quepy supports only the SPARQL query language, but in
future versions and with the collaboration of the community we are
planning to extend it to other database query languages.

You are invited to participate and collaborate with the project.

We leave here links to the documentation [0], the source code [1], and
also a Pypi package [2].

Also, as an example, we have an online instance of Quepy the interacts
with DBpedia available [3].

Source code for this example instance is available within the Quepy
package so you can kickstart your project from an existing, working
example.

If you like it, or if you have suggestions: Tell us about it! We're
just an email away [4].

Cheers!

[0] https://github.com/machinalis/quepy
[1] http://quepy.readthedocs.org/
[2] http://pypi.python.org/pypi/quepy/
[3] quepy.machinalis.com (Don't expect a QA system, it's an example)
[4] quepyproject[(at)]machinalis.com

We're doing an online hangout to show example code and answer questions about 
the project: 
Hangout event on Wed, January 30 at 14:00 UTC or Hangout event on Wed, January 
30 at 19:00 UTC

Also we invite you to try the new user interface:
http://quepy.machinalis.com/

Regards Elías
-- 
http://mail.python.org/mailman/listinfo/python-list


GeoBases: data services and visualization

2013-01-29 Thread Alex
This new project provides tools to play with geographical data. It also works 
with non-geographical data, except for map visualizations :).

There are embedded data sources in the project, but you can easily play with 
your own data in addition to the available ones. Files containing data about 
airports, train stations, countries, ... are loaded, then you can:

 - performs various types of queries ( find this key, or find keys with this 
property)
 - fuzzy searches based on string distance ( find things roughly named like 
this)
 - geographical searches ( find things next to this place)
 - get results on a map, or export it as csv data, or as a Python object

This is entirely written in Python. The core part is a Python package, but 
there is a command line tool as well! 

For tutorials and documentation, check out 
http://opentraveldata.github.com/geobases/
-- 
http://mail.python.org/mailman/listinfo/python-list


Ways to apply while learning....

2013-01-29 Thread agamal100
Hello,
I am learning programming as a spare time hobby and learning python through 
codecademy.

Today I have downloaded and installed aptana, and found out that although I 
have been progressing for some time now but I do not remember how to code and I 
have to look everything up.

I want to know what is the best way to learn python and some small projects 
that I can make using console(I know there is a long way to develop something 
for the desktop)

Thank you.
ps: I am coming from vb6 paradigm.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ways to apply while learning....

2013-01-29 Thread David Hutto
On Tue, Jan 29, 2013 at 5:57 PM,   wrote:
> Hello,
> I am learning programming as a spare time hobby and learning python through 
> codecademy.
>
> Today I have downloaded and installed aptana, and found out that although I 
> have been progressing for some time now but I do not remember how to code and 
> I have to look everything up.

When using different languages to mean client needs,this will be a necessity.

>
> I want to know what is the best way to learn python and some small projects 
> that I can make using console

you might need to utilize subrocess, but many ahve their preference.
(I know there is a long way to develop something for the desktop)
Do you mean command line app, or with a GUI?
>
> Thank you.
> ps: I am coming from vb6 paradigm.
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: environment fingerprint

2013-01-29 Thread Jabba Laci
Hi,

Thanks for the tip. I came up with the solution below. For my purposes
the short fingerprint is enough.

Laszlo

==

import platform as p
import uuid
import hashlib

def get_fingerprint(md5=False):
"""
Fingerprint of the current operating system/platform.

If md5 is True, a digital fingerprint is returned.
"""
sb = []
sb.append(p.node())
sb.append(p.architecture()[0])
sb.append(p.architecture()[1])
sb.append(p.machine())
sb.append(p.processor())
sb.append(p.system())
sb.append(str(uuid.getnode())) # MAC address
text = '#'.join(sb)
if md5:
md5 = hashlib.md5()
md5.update(text)
return md5.hexdigest()
else:
return text

def get_short_fingerprint(length=6):
"""
A short digital fingerprint of the current operating system/platform.

Length should be at least 6 characters.
"""
assert 6 <= length <= 32
#
return get_fingerprint(md5=True)[-length:]

On Tue, Jan 29, 2013 at 2:43 PM, Andrew Berg  wrote:
> On 2013.01.29 07:18, Jabba Laci wrote:
>> Hi,
>>
>> I have a script that I want to run in different environments: on
>> Linux, on Windows, on my home machine, at my workplace, in virtualbox,
>> etc. In each environment I want to use different configurations. For
>> instance the temp. directory on Linux would be /tmp, on Windows
>> c:\temp, etc. When the script starts, I want to test the environment
>> and load the corresponding config. settings. How to get an
>> OS-independent fingerprint of the environment?
> http://docs.python.org/3.3/library/platform.html
> http://docs.python.org/3.3/library/os.html#os.environ
>
> --
> CPython 3.3.0 | Windows NT 6.2.9200.16461 / FreeBSD 9.1-RELEASE
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: environment fingerprint

2013-01-29 Thread Chris Angelico
On Wed, Jan 30, 2013 at 10:33 AM, Jabba Laci  wrote:
> if md5:
> md5 = hashlib.md5()
> md5.update(text)
> return md5.hexdigest()

Simpler:
if md5:
return hashlib.md5(text).hexdigest()

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


Re: ] returns []

2013-01-29 Thread marty . musatov
MUSATOV
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread iMath
在 2013年1月29日星期二UTC+8下午9时33分26秒,Steven D'Aprano写道:
> iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns 
> [] ? Because you are iterating over an empty list, []. That list 
> comprehension is the equivalent of: result = [] for name in []: 
> result.append( os.path.join(r'E:\Python', name) ) Since you iterate over an 
> empty list, the body of the loop never executes, and the result list remains 
> empty. What did you expect it to do? -- Steven

just in order to get the full path name of each file .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread Chris Angelico
On Wed, Jan 30, 2013 at 12:56 PM, iMath  wrote:
> 在 2013年1月29日星期二UTC+8下午9时33分26秒,Steven D'Aprano写道:
>> iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns 
>> [] ? Because you are iterating over an empty list, []. That list 
>> comprehension is the equivalent of: result = [] for name in []: 
>> result.append( os.path.join(r'E:\Python', name) ) Since you iterate over an 
>> empty list, the body of the loop never executes, and the result list remains 
>> empty. What did you expect it to do? -- Steven
>
> just in order to get the full path name of each file .

Then it's done exactly what it should. It's given you the full path of
all of your list of zero files.

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


Re: Split string data have ","

2013-01-29 Thread moonhkt
On Jan 30, 1:08 am, Chris Rebert  wrote:
> On Jan 29, 2013 9:05 AM, "moonhkt"  wrote:
>
>
>
>
>
>
>
>
>
>
>
> > Hi All
>
> > Python 2.6.2 on AIX 5.3
> > How to using split o
>
> > >>> y = '"abc.p,zip.p",a,b'
> > >>> print y
> > "abc.p,zip.p",a,b
>
> > >>> k= y.split(",")
> > >>> print k[0]
> > "abc.p
>
> > Need Result, First element is
> > abc.p,zip.p
>
> Try the csv module or the shlex module.

Thank a lot, Using csv is good for me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Daniel W. Rouse Jr.

Hi all,

I have recently started learning Python (2.7.3) but need a better 
explanation of how to use tuples and dictionaries.


I am currently using "Learning Python" by Mark Lutz and David Ascher, 
published by O'Reilly (ISBN 1-56592-464-9)--but I find the explanations 
insufficient and the number of examples to be sparse. I do understand some 
ANSI C programming in addition to Python (and the book often wanders off 
into a comparison of C and Python in its numerous footnotes), but I need a 
better real-world example of how tuples and dictionaries are being used in 
actual Python code.


Any recommendations of a better book that doesn't try to write such compact 
and clever code for a learning book? Or, can an anyone provide an example of 
more than a three-line example of a tuple or dictionary?


The purpose of my learning Python in this case is not for enterprise level 
or web-based application level testing at this point. I initially intend to 
use it for Software QA Test Automation purposes.


Thanks in advance for any replies. 


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


Re: simple tkinter battery monitor

2013-01-29 Thread leonix . power
Thank you very much! fixed with w.after
Here is the code, works under Linux for those who have acpi.
My output of "acpi -V" is the following, the code is parsing the first line of 
the output. Any improvements are appreciated.

> $ acpi -V
> Battery 0: Discharging, 12%, 00:10:59 remaining
> Battery 0: design capacity 2200 mAh, last full capacity 1349 mAh = 61%
> Adapter 0: off-line
> Thermal 0: ok, 40.0 degrees C
> Thermal 0: trip point 0 switches to mode critical at temperature 98.0 degrees 
> C
> Thermal 0: trip point 1 switches to mode passive at temperature 93.0 degrees C
> Cooling 0: Processor 0 of 10
> Cooling 1: Processor 0 of 10
> Cooling 2: Processor 0 of 10
> Cooling 3: Processor 0 of 10
> Cooling 4: LCD 0 of 9


--
--
--


#!/usr/bin/python3.2

from re import findall, search
from threading import Thread
from time import sleep
from subprocess import Popen, call, PIPE, STDOUT
from tkinter import Tk, Label, StringVar



def runProcess(exe):
p=Popen(exe, stdout=PIPE, stderr=STDOUT)
while True:
retcode=p.poll()
line=p.stdout.readline()
yield line
if retcode is not None:
break


class BatteryMonitor:

def __init__(self):
root = Tk()
root.configure(padx=1, pady=1, bg="#555753")
root.geometry("-0+0")
root.overrideredirect(True)
root.wm_attributes("-topmost", True)
self.batteryExtendedStringVar = StringVar()
self.batteryPercentStringVar = StringVar()
self.batteryExtendedLabel = Label(root, 
textvariable=self.batteryExtendedStringVar, font=("fixed", 9), bg="#3e4446", 
fg="#d3d7cf", padx=10, pady=-1)
self.batteryPercentLabel = Label(root, 
textvariable=self.batteryPercentStringVar, font=("fixed", 9), width=4, 
bg="#3e4446", fg="#d3d7cf", padx=-1, pady=-1)
self.batteryPercentLabel.grid()
t = Thread(target=self.update_battery_level_loop)
t.start()
root.bind("", self.display_details)
self.root = root
root.mainloop()
   
def display_details(self, event):
# displays a message about details of battery status
# i.e. "on-line" or "charging, 20 min left" and so on
self.batteryPercentLabel.grid_remove()
self.batteryExtendedLabel.grid()
self.batteryExtendedLabel.after(1000, 
self.batteryExtendedLabel.grid_remove)
self.batteryPercentLabel.after(1000, 
self.batteryPercentLabel.grid)
   
def read_battery_level(self):
# dummy function used just to test the GUI
for line in runProcess(["acpi", "-V"]):
if line[11:-1]!=b"on-line":
self.level = findall(b"\d\d?", line[11:])[0]
else:
self.level = b"0"
return line[11:-1]
   
def update_battery_level_loop(self):
# threaded function, should constantly update the battery level
self.read_battery_level()
while True:

self.batteryPercentStringVar.set(str(self.level)[2:-1]+"%")

self.batteryExtendedStringVar.set(self.read_battery_level())
if self.level == 2:
runProcess(["shutdown", "-h", "now"])
return
sleep(5)





##
#
# main

BatteryMonitor()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Chris Angelico
On Wed, Jan 30, 2013 at 1:55 PM, Daniel W. Rouse Jr.
 wrote:
> I am currently using "Learning Python" by Mark Lutz and David Ascher,
> published by O'Reilly (ISBN 1-56592-464-9)--but I find the explanations
> insufficient and the number of examples to be sparse. I do understand some
> ANSI C programming in addition to Python (and the book often wanders off
> into a comparison of C and Python in its numerous footnotes), but I need a
> better real-world example of how tuples and dictionaries are being used in
> actual Python code.

Have you checked out the online documentation at
http://docs.python.org/ ? That might have what you're looking for.

By the way, you may want to consider learning and using Python 3.3
instead of the older branch 2.7; new features are only being added to
the 3.x branch now, with 2.7 getting bugfixes and such for a couple of
years, but ultimately it's not going anywhere. Obviously if you're
supporting existing code, you'll need to learn the language that it
was written in, but if this is all new code, go with the recent
version.

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


struggling with these problems

2013-01-29 Thread su29090
1.Given that  worst_offenders has been defined as a list with at least 6 
elements, write a statement that defines  lesser_offenders to be a new list 
that contains all the elements from index 5 of  worst_offenders and beyond. Do 
not modify  worst_offenders . 

I tried this but it didn't work:

lesser_offenders = worst_offenders[5:6]

2.Given a variable  temps that refers to a list, all of whose elements refer to 
values of type  float , representing temperature data, compute the average 
temperature and assign it to a variable named  avg_temp . Besides temps and  
avg_temp , you may use two other variables --  k and  total . 


I'm not sure about this one but this is what I have:

for k in range(len(temps)):
total += temps[k]

avg_temp = total / len(temps)

3.Associate the sum of the non-negative values in the list  numbers with the 
variable  sum . 

is it this:

for numbers in  sum:
if sum +=?

I'm confused at #3 the most

i'm not doing it in python 3.2.3 it's called Myprogramminglab.

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


Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Daniel W. Rouse Jr.
"Chris Angelico"  wrote in message 
news:mailman.1197.1359515470.2939.python-l...@python.org...

On Wed, Jan 30, 2013 at 1:55 PM, Daniel W. Rouse Jr.
 wrote:

I am currently using "Learning Python" by Mark Lutz and David Ascher,
published by O'Reilly (ISBN 1-56592-464-9)--but I find the explanations
insufficient and the number of examples to be sparse. I do understand 
some

ANSI C programming in addition to Python (and the book often wanders off
into a comparison of C and Python in its numerous footnotes), but I need 
a
better real-world example of how tuples and dictionaries are being used 
in

actual Python code.


Have you checked out the online documentation at
http://docs.python.org/ ? That might have what you're looking for.

I'll check the online documentation but I was really seeking a book 
recommendation or other offline resource. I am not always online, and often 
times when I code I prefer local machine documentation or a book. I do also 
have the .chm format help file in the Windows version of Python.



By the way, you may want to consider learning and using Python 3.3
instead of the older branch 2.7; new features are only being added to
the 3.x branch now, with 2.7 getting bugfixes and such for a couple of
years, but ultimately it's not going anywhere. Obviously if you're
supporting existing code, you'll need to learn the language that it
was written in, but if this is all new code, go with the recent
version.

Honestly, I don't know what code is being supported. I've just seen enough 
test automation requirements calling for Python (in addition to C# and perl) 
in some of the latest job listings that I figured I better get some working 
knowledge of Python to avoid becoming obsolete should I ever need to find 
another job. 


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


Re: Mixxx DJ app and Python

2013-01-29 Thread alex23
On Jan 29, 1:10 am, mikp...@gmail.com wrote:
> I am thinking of driving a DJ application from Python.
> I am running Linux and I found the Mixxx app.
> Does anyone know if there are python bindings, or if this is possible at all?
> or does anyone have experience with another software that does the same DJ 
> thing?

The simplest way I think would be to control Mixxx via midi, using
something like pyPortMidi:

http://alumni.media.mit.edu/~harrison/code.html

If that doesn't give you the full range of control you're after,
perhaps you could use ctypes to wrap Mixxx's code libraries?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Chris Angelico
On Wed, Jan 30, 2013 at 2:42 PM, Daniel W. Rouse Jr.
 wrote:
> "Chris Angelico"  wrote in message
> news:mailman.1197.1359515470.2939.python-l...@python.org...
>> Have you checked out the online documentation at
>> http://docs.python.org/ ? That might have what you're looking for.
>>
> I'll check the online documentation but I was really seeking a book
> recommendation or other offline resource. I am not always online, and often
> times when I code I prefer local machine documentation or a book. I do also
> have the .chm format help file in the Windows version of Python.

Ah. I think the tutorial's in the chm file, but I'm not certain. But
for actual books, I can't point to any; I learned from online info
only, never actually sought a book (in fact, the last time I used
dead-tree reference books was for C and C++). Sorry!

>> By the way, you may want to consider learning and using Python 3.3
>> instead of the older branch 2.7...
>>
> Honestly, I don't know what code is being supported. I've just seen enough
> test automation requirements calling for Python (in addition to C# and perl)
> in some of the latest job listings that I figured I better get some working
> knowledge of Python to avoid becoming obsolete should I ever need to find
> another job.

A fair point. In that case, it's probably worth learning both; they're
very similar. Learn either one first, then master the differences.

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


Re: struggling with these problems

2013-01-29 Thread MRAB

On 2013-01-30 03:26, su29090 wrote:

1.Given that  worst_offenders has been defined as a list with at least 6 
elements, write a statement that defines  lesser_offenders to be a new list 
that contains all the elements from index 5 of  worst_offenders and beyond. Do 
not modify  worst_offenders .

I tried this but it didn't work:

lesser_offenders = worst_offenders[5:6]

Python uses half-open ranges (and counts from 0), which means that the 
start index is included and the end index is excluded.


Therefore, worst_offenders[5:6] means the slice from index 5 up to, but 
excluding, index 6; in other words, an empty list.


The question says "and beyond"; in Python you can just omit the end 
index to indicate everything up to the end.



2.Given a variable  temps that refers to a list, all of whose elements refer to 
values of type  float , representing temperature data, compute the average 
temperature and assign it to a variable named  avg_temp . Besides temps and  
avg_temp , you may use two other variables --  k and  total .


I'm not sure about this one but this is what I have:

for k in range(len(temps)):
total += temps[k]

avg_temp = total / len(temps)


You didn't set the initial value of total, which is 0.


3.Associate the sum of the non-negative values in the list  numbers with the 
variable  sum .

is it this:

for numbers in  sum:
if sum +=?

I'm confused at #3 the most


Well, that's not valid Python.

What you want to do is to add each number from the list to the sum only 
if it's non-negative, i.e. greater than or equal to 0.



i'm not doing it in python 3.2.3 it's called Myprogramminglab.


Have a look at Dive Into Python:
http://www.diveintopython.net/

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


Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Mitya Sirenef

On 01/29/2013 09:55 PM, Daniel W. Rouse Jr. wrote:

Hi all,

>
> I have recently started learning Python (2.7.3) but need a better 
explanation of how to use tuples and dictionaries.

>
> I am currently using "Learning Python" by Mark Lutz and David Ascher, 
published by O'Reilly (ISBN 1-56592-464-9)--but I find the explanations 
insufficient and the number of examples to be sparse. I do understand 
some ANSI C programming in addition to Python (and the book often 
wanders off into a comparison of C and Python in its numerous 
footnotes), but I need a better real-world example of how tuples and 
dictionaries are being used in actual Python code.

>
> Any recommendations of a better book that doesn't try to write such 
compact and clever code for a learning book? Or, can an anyone provide 
an example of more than a three-line example of a tuple or dictionary?

>
> The purpose of my learning Python in this case is not for enterprise 
level or web-based application level testing at this point. I initially 
intend to use it for Software QA Test Automation purposes.

>
> Thanks in advance for any replies.


It's not finished yet, but you may find my text-movie tutorial on
dicts useful:

http://lightbird.net/larks/tmovies/dicts.html

 -m



--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

Idleness is the mother of psychology.  Friedrich Nietzsche

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


Re: struggling with these problems

2013-01-29 Thread Steven D'Aprano
On Wed, 30 Jan 2013 03:59:32 +, MRAB wrote:

> Python uses half-open ranges (and counts from 0), which means that the
> start index is included and the end index is excluded.
> 
> Therefore, worst_offenders[5:6] means the slice from index 5 up to, but
> excluding, index 6; in other words, an empty list.

Er, no. It's a one-element list: index 5 is included, index 6 is excluded.

py> L = list("abcdefgh")
py> L[5:6]
['f']




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


security quirk

2013-01-29 Thread RichD
I read Wall Street Journal, and occasionally check
articles on their Web site.  It's mostly free, with some items
available to subscribers only.  It seems random, which ones
they block, about 20%.

Anywho, sometimes I use their search utility, the usual author
or title search, and it blocks, then I look it up on Google, and
link from there, and it loads!  ok, Web gurus, what's going on?


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


Signal versus noise (was: security quirk)

2013-01-29 Thread Ben Finney
RichD  writes:

> Anywho, sometimes I use their search utility, the usual author
> or title search, and it blocks, then I look it up on Google, and
> link from there, and it loads!  ok, Web gurus, what's going on?

That evidently has nothing in particular to do with the topic of this
forum: the Python programming language.

If you want to just comment on arbitrary things with the internet at
large, you have many other forums available. Please at least try to keep
this forum on-topic.

-- 
 \ “Outside of a dog, a book is man's best friend. Inside of a |
  `\dog, it's too dark to read.” —Groucho Marx |
_o__)  |
Ben Finney

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


Re: security quirk

2013-01-29 Thread Rodrick Brown
On Tue, Jan 29, 2013 at 11:55 PM, RichD  wrote:

> I read Wall Street Journal, and occasionally check
> articles on their Web site.  It's mostly free, with some items
> available to subscribers only.  It seems random, which ones
> they block, about 20%.
>
> Anywho, sometimes I use their search utility, the usual author
> or title search, and it blocks, then I look it up on Google, and
> link from there, and it loads!  ok, Web gurus, what's going on?
>
>
Its Gremlins! I tell you Gremlins!!!


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


Re: security quirk

2013-01-29 Thread Chris Rebert
On Tue, Jan 29, 2013 at 8:55 PM, RichD  wrote:
> I read Wall Street Journal, and occasionally check
> articles on their Web site.  It's mostly free, with some items
> available to subscribers only.  It seems random, which ones
> they block, about 20%.
>
> Anywho, sometimes I use their search utility, the usual author
> or title search, and it blocks, then I look it up on Google, and
> link from there, and it loads!  ok, Web gurus, what's going on?

http://www.google.com/search?btnG=1&pws=0&q=first+click+free

BTW, this has absolutely jack squat to do with Python. Please direct
similar future inquiries to a more relevant forum.

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


Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread John Gordon
In  "Daniel W. Rouse Jr." 
 writes:

> I have recently started learning Python (2.7.3) but need a better 
> explanation of how to use tuples and dictionaries.

A tuple is a linear sequence of items, accessed via subscripts that start
at zero.

Tuples are read-only; items cannot be added, removed, nor replaced.

Items in a tuple need not be the same type.

Example:

>>> my_tuple = (1, 5, 'hello', 9.)
>>> print my_tuple[0]
1
>>> print my_tuple[2]
hello

A dictionary is a mapping type; it allows you to access items via a
meaningful name (usually a string.)

Dictionaries do not preserve the order in which items are created (but
there is a class in newer python versions, collections.OrderedDict, which
does preserve order.)

Example:

>>> person = {} # start with an empty dictionary
>>> person['name'] = 'John'
>>> person['age'] = 40
>>> person['occupation'] = 'Programmer'
>>> print person['age']
40

Dictionaries can also be created with some initial values, like so:

>>> person = { 'name': 'John', 'age': 40, 'occupation' : 'Programmer' }

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Daniel W. Rouse Jr.
"John Gordon"  wrote in message 
news:keaa9v$1ru$1...@reader1.panix.com...
In  "Daniel W. Rouse Jr." 
 writes:



I have recently started learning Python (2.7.3) but need a better
explanation of how to use tuples and dictionaries.


A tuple is a linear sequence of items, accessed via subscripts that start
at zero.

Tuples are read-only; items cannot be added, removed, nor replaced.

Items in a tuple need not be the same type.

Example:

   >>> my_tuple = (1, 5, 'hello', 9.)
   >>> print my_tuple[0]
   1
   >>> print my_tuple[2]
   hello


To me, this looks like an array. Is tuple just the Python name for an array?


A dictionary is a mapping type; it allows you to access items via a
meaningful name (usually a string.)

Dictionaries do not preserve the order in which items are created (but
there is a class in newer python versions, collections.OrderedDict, which
does preserve order.)

Example:

   >>> person = {} # start with an empty dictionary
   >>> person['name'] = 'John'
   >>> person['age'] = 40
   >>> person['occupation'] = 'Programmer'
   >>> print person['age']
   40

Dictionaries can also be created with some initial values, like so:

   >>> person = { 'name': 'John', 'age': 40, 'occupation' : 'Programmer' }

Thank you, I understand it better it is kind of like a hash table. 


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


Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Chris Angelico
On Wed, Jan 30, 2013 at 5:14 PM, Daniel W. Rouse Jr.
 wrote:
> To me, this looks like an array. Is tuple just the Python name for an array?

Not quite. An array is closer to a Python list - a tuple can be
thought of as a "frozen list", if you like. Lists can be added to,
removed from, and changed in many ways; tuples are what they are, and
there's no changing them (the objects inside it could be changed, but
WHAT objects are in it won't).

Python has no strict match to a C-style array with a fixed size and
changeable members; a Python list is closest to a C++ std::vector, if
that helps at all.

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


Re: Please provide a better explanation of tuples and dictionaries

2013-01-29 Thread Steven D'Aprano
On Tue, 29 Jan 2013 22:14:42 -0800, Daniel W. Rouse Jr. wrote:

> "John Gordon"  wrote in message
> news:keaa9v$1ru$1...@reader1.panix.com...

>> A tuple is a linear sequence of items, accessed via subscripts that
>> start at zero.
>>
>> Tuples are read-only; items cannot be added, removed, nor replaced.
>>
>> Items in a tuple need not be the same type.
>>
>> Example:
>>
>>>>> my_tuple = (1, 5, 'hello', 9.)
>>>>> print my_tuple[0]
>>1
>>>>> print my_tuple[2]
>>hello
>>
> To me, this looks like an array. Is tuple just the Python name for an
> array?

Absolutely not. Arrays can be modified in place. Tuples cannot. Arrays 
can be resized (depending on the language). Tuples cannot. Arrays are 
normally limited to a single data type. Tuples are not.

Python lists are closer to arrays, although the "array" type found in the 
array module is even closer still.

You create lists either with the list() function, or list builder 
notation using [ ].

Tuples are intended to be the equivalent of a C struct or Pascal record. 
Lists are very roughly intended to be somewhat close to an array, 
although as I said the array.py module is even closer.


>> A dictionary is a mapping type; it allows you to access items via a
>> meaningful name (usually a string.)
[...]
> Thank you, I understand it better it is kind of like a hash table.

Correct. Also known as "associative array".


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