Re: Matplotlib X-axis timezone trouble

2015-07-01 Thread Chris Angelico
On Wed, Jul 1, 2015 at 3:50 PM, Peter Pearson  wrote:
> But look:
>
> >>> from datetime import datetime
> >>> import pytz
> >>> pacific = pytz.timezone("US/Pacific")
> >>> dt1 = datetime(2006, 11, 21, 16, 30, tzinfo=pacific) # no DST
> >>> dt2 = datetime(2006, 6, 14, 13, 0, tzinfo=pacific)   # yes DST
> >>> dt1.dst()
> datetime.timedelta(0)
> >>> dt2.dst()
> datetime.timedelta(0)
> >>> dt1.utcoffset()
> datetime.timedelta(-1, 57600)
> >>> dt2.utcoffset()
> datetime.timedelta(-1, 57600)
>
> The dst() values are equal, and the utcoffset() values are equal, even
> though one datetime is during DST and the other is not -- exactly the
> opposite of the example.

Just to confirm, they are still showing the times as 16:30 and 13:00, right?

Interestingly, when I tried this (pytz version 2015.4, Python 2.7.9,
Debian Jessie), I saw utcoffset() showing (-1, 58020) for both. That
seems... odd. And I can't fault your dates - those definitely ought to
be easily inside and easily outside the DST boundaries. When I try
those dates in an unrelated time converter, they do show seven- and
eight- hour offsets to UTC. Maybe we're both misunderstanding the
meaning of utcoffset()?

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


Re: Pure Python Data Mangling or Encrypting

2015-07-01 Thread alister
On Tue, 30 Jun 2015 23:25:01 +, Jon Ribbens wrote:

> On 2015-06-30, Steven D'Aprano  wrote:
>> I don't think there has been much research into keeping at least *some*
>> security even when keys have been compromised, apart from as it relates
>> to two-factor authentication.
> 
> That's because "the key" is all the secret part. If an attacker knows
> the algorithm, and the key, and the ciphertext, then *by definition* all
> is lost. If you mean keeping the algorithm secret too then that's just
> considered bad crypto.
> 
>> In the past, and still today among people who don't understand
>> Kerckhoffs' principle, people have tried to keep the cipher secret and
>> not have a key at all. E.g. atbash, or caesar cipher, which once upon a
>> time were cutting edge ciphers, as laughably insecure as they are
>> today. If the method was compromised, all was lost.
> 
> Caesar cipher has a key. It's just very small, so is easy to guess.
> 
>> Today, if the key is compromised, all is lost. Is it possible that
>> there are ciphers that are resistant to discovery of the key? Obviously
>> if you know the key you can read encrypted messages, that's what the
>> key is for, but there are scenarios where you would want security to
>> degrade gracefully instead of in a brittle all-or-nothing manner:
>>
>> - even if the attacker can read my messages, he cannot tamper with
>>   them or write new ones as me.
> 
> I suppose that could be achieved by having separate encryption and
> signing keys, but you could do the same but better by encrypting with
> multiple algorithms. It's not an unstudied area:
> https://en.wikipedia.org/wiki/Multiple_encryption

"The kipper flies at Midnight"

(from almost every WWII spy movie ever)
even if this message is decoded it is meaningless unless the attacker 
also has the meanings of the Code phrases
(which would mean your agent had been captured anyway)



-- 
That's the funniest thing I've ever heard and I will _not_ condone it.
-- DyerMaker, 17 March 2000 MegaPhone radio show
-- 
https://mail.python.org/mailman/listinfo/python-list


win32print

2015-07-01 Thread BartC
I need to print a text file to whatever printer in Windows is called 
'Generic/Text Only'. I looked for a Python solution and come across Tim 
Golden's win32print module which looks perfect, eg:


http://timgolden.me.uk/pywin32-docs/win32print.html

However, that tells me everything I need to know except how or where to 
download it!


Is this something that actually can be downloaded somewhere? (Or is it 
obsolete, or a project that I have to build myself? In which case it'll 
probably be easier to write my own Win32 code but I was trying to avoid 
that.)


--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list


Re: win32print

2015-07-01 Thread Mark Lawrence

On 01/07/2015 09:59, BartC wrote:

I need to print a text file to whatever printer in Windows is called
'Generic/Text Only'. I looked for a Python solution and come across Tim
Golden's win32print module which looks perfect, eg:

http://timgolden.me.uk/pywin32-docs/win32print.html

However, that tells me everything I need to know except how or where to
download it!

Is this something that actually can be downloaded somewhere? (Or is it
obsolete, or a project that I have to build myself? In which case it'll
probably be easier to write my own Win32 code but I was trying to avoid
that.)



That's the standard pywin32 docs that happen to be on Tim's site.  Get 
the latest pywin32 here 
http://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Capturing PyRun_String stdout

2015-07-01 Thread Chris Moller
I sent this to the wrong list a few hours ago.  I hope I've gotten it 
right this time...


=

I expect this has been asked before, but I can't find out much about it...

I'm trying to embed Python in a GTK+/C app  as a scripting language and 
I need to capture the output of PyRun_String(), PyEval_EvalCode(), or 
whatever as a char * (or wchar_t * or whatever) rather than have it go 
to stdout.


I'm using Python 3.3.2 under plain C, not C++

And, while I'm interrupting everyone's evening, another question: if I  
pass Py_single_input to PyRun_String() or 
Py_CompileString()/PyEval_EvalCode(), it accepts statements like "a=10" 
and can then properly do stuff like "print(a)".  If I use Py_eval_input 
instead, I get error messages.  In both cases, I'm using the same 
global_dict and local_dict, if that makes any difference.  What am I 
doing wrong?


Thanks,
Chris Moller
-- 
https://mail.python.org/mailman/listinfo/python-list


Capturing PyRun_String stdout

2015-07-01 Thread Chris Moller
I sent this to the wrong list a few hours ago.  I hope I've gotten it 
right this time...


=

I expect this has been asked before, but I can't find out much about it...

I'm trying to embed Python in a GTK+/C app  as a scripting language and 
I need to capture the output of PyRun_String(), PyEval_EvalCode(), or 
whatever as a char * (or wchar_t * or whatever) rather than have it go 
to stdout.


I'm using Python 3.3.2 under plain C, not C++

And, while I'm interrupting everyone's evening, another question: if I  
pass Py_single_input to PyRun_String() or 
Py_CompileString()/PyEval_EvalCode(), it accepts statements like "a=10" 
and can then properly do stuff like "print(a)".  If I use Py_eval_input 
instead, I get error messages.  In both cases, I'm using the same 
global_dict and local_dict, if that makes any difference.  What am I 
doing wrong?


Thanks,
Chris Moller
-- 
https://mail.python.org/mailman/listinfo/python-list


Can't get it to download

2015-07-01 Thread thesneakercop
I’ve made several attempts to download python to my laptop, but every time I 
open it, it ask to repair or uninstall. Can you assist me with downloading it?






Sent from Windows Mail-- 
https://mail.python.org/mailman/listinfo/python-list


Re: win32print

2015-07-01 Thread BartC

On 01/07/2015 11:15, Mark Lawrence wrote:

On 01/07/2015 09:59, BartC wrote:

I need to print a text file to whatever printer in Windows is called
'Generic/Text Only'. I looked for a Python solution and come across Tim
Golden's win32print module which looks perfect, eg:

http://timgolden.me.uk/pywin32-docs/win32print.html

However, that tells me everything I need to know except how or where to
download it!



That's the standard pywin32 docs that happen to be on Tim's site.  Get
the latest pywin32 here
http://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/


Yes, I ended up there at one point, but didn't see a win32print.py file, 
only a win32print.cpp one. I think messing about with C++ compilers and 
makefiles (that never work properly under Windows) defeats the object of 
trying to use Python for this purpose!


Presumably, nowhere on the internet is there a ready-to-use copy of 
win32print.py that someone else could just download with little effort?


(Anyway, never mind; I'm looking at a solution now that involves 
invoking Windows' rundll32 and notepad to do the job. And it saves the 
problem of instructing someone on the end of a telephone how to install 
even Python let alone locating the add-ons.


This is task that, in the eighties, would have involved sending a 
string, a byte at a time, to the parallel port, perhaps 3 lines of code. 
It's great that in 2015 everything is so much simpler!)


--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list


Re: win32print

2015-07-01 Thread Tim Golden
On 01/07/2015 12:02, BartC wrote:
> On 01/07/2015 11:15, Mark Lawrence wrote:
>> On 01/07/2015 09:59, BartC wrote:
>>> I need to print a text file to whatever printer in Windows is called
>>> 'Generic/Text Only'. I looked for a Python solution and come across Tim
>>> Golden's win32print module which looks perfect, eg:
>>>
>>> http://timgolden.me.uk/pywin32-docs/win32print.html
>>>
>>> However, that tells me everything I need to know except how or where to
>>> download it!
> 
>> That's the standard pywin32 docs that happen to be on Tim's site.  Get
>> the latest pywin32 here
>> http://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/
> 
> Yes, I ended up there at one point, but didn't see a win32print.py file,
> only a win32print.cpp one. I think messing about with C++ compilers and
> makefiles (that never work properly under Windows) defeats the object of
> trying to use Python for this purpose!
> 
> Presumably, nowhere on the internet is there a ready-to-use copy of
> win32print.py that someone else could just download with little effort?
> 
> (Anyway, never mind; I'm looking at a solution now that involves
> invoking Windows' rundll32 and notepad to do the job. And it saves the
> problem of instructing someone on the end of a telephone how to install
> even Python let alone locating the add-ons.
> 
> This is task that, in the eighties, would have involved sending a
> string, a byte at a time, to the parallel port, perhaps 3 lines of code.
> It's great that in 2015 everything is so much simpler!)
> 

If I can interrupt your Jeremiad for a moment, this page might help:

  http://timgolden.me.uk/python/win32_how_do_i/print.html

and it (and the docs you found above) relies on this download page:

  http://sourceforge.net/projects/pywin32/files/pywin32/

which, as you can see, has been available for every then-valid version
of Python for some years now.

TJG
-- 
https://mail.python.org/mailman/listinfo/python-list


EuroPython 2015 Keynote: Carrie Anne Philbin

2015-07-01 Thread M.-A. Lemburg
We are pleased to introduce our next keynote speaker for EuroPython
2015: *Carrie Anne Philbin*. She will be giving her keynote on Thursday,
July 23, to start the EuroPython Educational Summit:

 *** https://ep2015.europython.eu/en/events/educational-summit/ ***


About Carrie Anne Philbin
-

Carrie Anne is leading the education mission for the Raspberry Pi
Foundation, but is also known as an award winning secondary Computing
& ICT Teacher, Author, YouTuber:

 * Author of "Adventures in Raspberry Pi", a computing book for
   teenagers wanting to get started with Raspberry Pi and
   programming. Winner of Teach Secondary magazine’s Technology &
   Innovation Best Author award 2014.

 * Creator of a YouTube video series for teenage girls called "The
   Geek Gurl Diaries", which has won a Talk Talk Digital Hero
   Award. The episodes include interviews with women working in
   technology and hands on computer science based tutorials.

 * Vice chair of the Computing At Schools (CAS) initiative to get more
   girls and minority groups into computing, which created a workshop
   based hack day for teenagers concentrating on delivering good
   content to include all and "Hack the Curric" bringing academics,
   educators and industry experts together to create inclusive
   resources for the new Computing curriculum.

In 2012, she became a Google Certified Teacher and KS3 ICT subject
Leader at a school in East London. She has a blended and open approach
to teaching as can be seen on her website ICT with Miss P. She became
a Skype Moment Maker and ambassador for technology. She is an
evangelist and often speaks at conferences like BETT, Raspberry
Jamboree, YRS, PyCon UK and now EuroPython.


The Keynote: Designed for Education: A Python Solution
---

The problem of introducing children to programming and computer
science has seen growing attention in the past few years. Initiatives
like Raspberry Pi, Code Club, code.org, (and many more) have been
created to help solve this problem. With the introduction of a
national computing curriculum in the UK, teachers have been searching
for a text based programming language to help teach computational
thinking as a follow on from visual languages like Scratch.

The educational community has been served well by Python, benefiting
from its straight-forward syntax, large selection of libraries, and
supportive community. Education-focused summits are now a major part
of most major Python Conferences. Assistance in terms of documentation
and training is invaluable, but perhaps there are technical means of
improving the experience of those using Python in education. Clearly
the needs of teachers and their students are different to those of the
seasoned programmer. Children are unlikely to come to their teachers
with frustrations about the Global Interpreter Lock! But issues such
as usability of IDEs or comprehensibility of error messages are of
utmost importance.

In this keynote, Carrie Anne will discuss existing barriers to Python
becoming the premier language of choice for teaching computer science,
and how learning Python could be helped immensely through tooling and
further support from the Python developer community.

EuroPython Educational Summit
-

We will have Educational Summit focused talks, trainings, birds of a
feather sessions to debate and also Educational Sprints for the
building of education focused projects during the weekend.

EuroPython 2015 Educational Summit

 *** https://ep2015.europython.eu/en/events/educational-summit/ ***


In 2012, she became a Google Certified Teacher and KS3 ICT subject
Leader at a school in East London. She has a blended and open approach
to teaching as can be seen on her website ICT with Miss P. She became
a Skype Moment Maker and ambassador for technology. She is an
evangelist and often speaks at conferences like BETT, Raspberry
Jamboree, YRS, PyCon UK and now EuroPython.


The Keynote: Designed for Education: A Python Solution
---

The problem of introducing children to programming and computer
science has seen growing attention in the past few years. Initiatives
like Raspberry Pi, Code Club, code.org, (and many more) have been
created to help solve this problem. With the introduction of a
national computing curriculum in the UK, teachers have been searching
for a text based programming language to help teach computational
thinking as a follow on from visual languages like Scratch.

The educational community has been served well by Python, benefiting
from its straight-forward syntax, large selection of libraries, and
supportive community. Education-focused summits are now a major part
of most major Python Conferences. Assistance in terms of documentation
and training is invaluable, but perhaps there are technical means of
improving the experience of those using Python

Python programming classes for children

2015-07-01 Thread beliavsky--- via Python-list
My 11yo son is taking the online class "Intermediate Programming with Python" 
http://www.artofproblemsolving.com/school/course/catalog/python2 offered by the 
Art of Problem Solving company (AoPS). Classes meet for 1.5 hours a week for 12 
weeks. During the classes the instructor "lectures" (types into a console -- 
there is no sound) and students type answers to questions. There are weekly 
programming assignments. AoPS is a U.S. company whose focus is preparing 
students for math competitions.

Are there other groups offering Python courses for pre-college students?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: win32print

2015-07-01 Thread BartC

On 01/07/2015 12:28, Tim Golden wrote:

On 01/07/2015 12:02, BartC wrote:



Yes, I ended up there at one point, but didn't see a win32print.py file,



Presumably, nowhere on the internet is there a ready-to-use copy of
win32print.py that someone else could just download with little effort?



If I can interrupt your Jeremiad for a moment, this page might help:

   http://timgolden.me.uk/python/win32_how_do_i/print.html

and it (and the docs you found above) relies on this download page:

   http://sourceforge.net/projects/pywin32/files/pywin32/

which, as you can see, has been available for every then-valid version
of Python for some years now.


OK, thanks, that now works. (I need to click on a .exe file not on .zip, 
and choose a version that corresponds with what's in the registry, which 
was 3.1 in my case, not 3.12 nor 3.4 which are also installed.


This would be a better basis for solving the problem (driving a bar-code 
printer). Although it's still not certain how I might distribute the 
result (just copy the whole directory Python 3.1 tree onto a memory 
stick perhaps and send that).


--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 resuma a file download

2015-07-01 Thread zljubisic
On Wednesday, 1 July 2015 01:43:19 UTC+2, Cameron Simpson  wrote:
> On 30Jun2015 08:34, zljubi...@gmail.com  wrote:
> >I would like to download a file (http://video.hrt.hr/2906/otv296.mp4)
> >If the connection is OK, I can download the file with:
> >
> >import urllib.request
> >urllib.request.urlretrieve(remote_file, local_file)
> >
> >Sometimes when I am connected on week wireless (not mine) network I get 
> >WinError 10054 exception (windows 7).
> >
> >When it happens, I would like to resume download instead of doing everything 
> >from very beginning.
> >
> >How to do that?
> >
> >I read about Range header and chunks, but this server doesn't have any 
> >headers.
> >
> >What options do I have with this particular file?
> 
> You need to use a Range: header. I don't know what you mean when you say 
> "this 
> server doesn't have any headers". All HTTP requests and responses use 
> headers.  
> Possibly you mean you code isn't setting any headers.
> 
> What you need to do is separate your call to urlretrieve into a call to 
> construct a Request object, add a Range header, then fetch the URL using the 
> Request object, appending the results (if successful) to the end of your 
> local 
> file.
> 
> If you go to:
> 
>   
> https://docs.python.org/3/library/urllib.request.html#urllib.request.urlretrieve
> 
> and scroll up you will find example code doing that kind of thing in the 
> examples above.
> 
> Cheers,
> Cameron Simpson 
> 
> The British Interplanetary Society? How many planets are members then?
> - G. Robb

Hi,

if I understood you correctly (I am not sure about which example you are 
refering), I should do the following:
1. check already downloaded file size in bytes = downloaded
2. url = 'http://video.hrt.hr/2906/otv296.mp4'
3. req = urllib.request.Request(url)
4. req.add_header('Range', downloaded)
5. urllib.request.urlretrieve(url, 'otv296.mp4')

Is that what you were saying?

Regards.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Pure Python Data Mangling or Encrypting

2015-07-01 Thread Randall Smith

On 06/30/2015 01:33 PM, Chris Angelico wrote:

 From the software's point of view, it has two distinct
modes: server, in which it listens on a socket and receives data, and
client, in which it connects to other people's sockets and sends data.
As such, the "server" mode is the only one that receives untrusted
data from another user and stores it on the hard disk.



That's close.  There are 3 types: storage nodes, client nodes, and 
control nodes.


Communication:

storage node <--> control node
storage node <--> storage node
client node   --> storage node
client node   --> control node

Data is uploaded by clients and distributed among storage nodes.

Everything is coordinated by the control nodes (plural for redundancy).

-Randall

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


Re: Python 3 resuma a file download

2015-07-01 Thread Ian Kelly
On Wed, Jul 1, 2015 at 8:18 AM,   wrote:
> if I understood you correctly (I am not sure about which example you are 
> refering), I should do the following:
> 1. check already downloaded file size in bytes = downloaded
> 2. url = 'http://video.hrt.hr/2906/otv296.mp4'
> 3. req = urllib.request.Request(url)
> 4. req.add_header('Range', downloaded)

You need to use the correct format for the Range header; see RFC 7233.
If you have 500 bytes and want the rest of the file, then the value
for the Range header would be "bytes=500-", not just "500". You can
build that string using string formatting, e.g.
"bytes={}-".format(downloaded)

> 5. urllib.request.urlretrieve(url, 'otv296.mp4')

A couple of problems with this. One is that it doesn't use the Request
object that you just constructed, so it wouldn't pass the Range
header. The other is that it will overwrite that file, not append to
it. You should use the urllib.request.urlopen function, and pass it
the Request object rather than the URL. You can then open your local
file in append mode, read the file data from the HTTPResponse object
returned by urlopen, and write it to the local file.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: EuroPython 2015 Keynote: Carrie Anne Philbin

2015-07-01 Thread Alister

On 01/07/15 13:00, M.-A. Lemburg wrote:

We are pleased to introduce our next keynote speaker for EuroPython
2015: *Carrie Anne Philbin*. She will be giving her keynote on Thursday,
July 23, to start the EuroPython Educational Summit:

  *** https://ep2015.europython.eu/en/events/educational-summit/ ***


About Carrie Anne Philbin
-

Carrie Anne is leading the education mission for the Raspberry Pi
Foundation, but is also known as an award winning secondary Computing
& ICT Teacher, Author, YouTuber:

  * Author of "Adventures in Raspberry Pi", a computing book for
teenagers wanting to get started with Raspberry Pi and
programming. Winner of Teach Secondary magazine’s Technology &
Innovation Best Author award 2014.

  * Creator of a YouTube video series for teenage girls called "The
Geek Gurl Diaries", which has won a Talk Talk Digital Hero
Award. The episodes include interviews with women working in
technology and hands on computer science based tutorials.

  * Vice chair of the Computing At Schools (CAS) initiative to get more
girls and minority groups into computing, which created a workshop
based hack day for teenagers concentrating on delivering good
content to include all and "Hack the Curric" bringing academics,
educators and industry experts together to create inclusive
resources for the new Computing curriculum.

In 2012, she became a Google Certified Teacher and KS3 ICT subject
Leader at a school in East London. She has a blended and open approach
to teaching as can be seen on her website ICT with Miss P. She became
a Skype Moment Maker and ambassador for technology. She is an
evangelist and often speaks at conferences like BETT, Raspberry
Jamboree, YRS, PyCon UK and now EuroPython.


The Keynote: Designed for Education: A Python Solution
---

The problem of introducing children to programming and computer
science has seen growing attention in the past few years. Initiatives
like Raspberry Pi, Code Club, code.org, (and many more) have been
created to help solve this problem. With the introduction of a
national computing curriculum in the UK, teachers have been searching
for a text based programming language to help teach computational
thinking as a follow on from visual languages like Scratch.

The educational community has been served well by Python, benefiting
from its straight-forward syntax, large selection of libraries, and
supportive community. Education-focused summits are now a major part
of most major Python Conferences. Assistance in terms of documentation
and training is invaluable, but perhaps there are technical means of
improving the experience of those using Python in education. Clearly
the needs of teachers and their students are different to those of the
seasoned programmer. Children are unlikely to come to their teachers
with frustrations about the Global Interpreter Lock! But issues such
as usability of IDEs or comprehensibility of error messages are of
utmost importance.

In this keynote, Carrie Anne will discuss existing barriers to Python
becoming the premier language of choice for teaching computer science,
and how learning Python could be helped immensely through tooling and
further support from the Python developer community.

EuroPython Educational Summit
-

We will have Educational Summit focused talks, trainings, birds of a
feather sessions to debate and also Educational Sprints for the
building of education focused projects during the weekend.

 EuroPython 2015 Educational Summit

  *** https://ep2015.europython.eu/en/events/educational-summit/ ***


In 2012, she became a Google Certified Teacher and KS3 ICT subject
Leader at a school in East London. She has a blended and open approach
to teaching as can be seen on her website ICT with Miss P. She became
a Skype Moment Maker and ambassador for technology. She is an
evangelist and often speaks at conferences like BETT, Raspberry
Jamboree, YRS, PyCon UK and now EuroPython.


The Keynote: Designed for Education: A Python Solution
---

The problem of introducing children to programming and computer
science has seen growing attention in the past few years. Initiatives
like Raspberry Pi, Code Club, code.org, (and many more) have been
created to help solve this problem. With the introduction of a
national computing curriculum in the UK, teachers have been searching
for a text based programming language to help teach computational
thinking as a follow on from visual languages like Scratch.

The educational community has been served well by Python, benefiting
from its straight-forward syntax, large selection of libraries, and
supportive community. Education-focused summits are now a major part
of most major Python Conferences. Assistance in terms of documentation
and training is invaluable, but perhaps there are techni

Py_InitializeEx() in CygWin64's Python2.7

2015-07-01 Thread Gisle Vanem

I've written a C-program that embeds Python 2.7.
It has worked fine for several years using MingW or MSVC. Now I'd like
to support the python2.7.exe that comes with CygWin64.

But it seems to fail inside 'Py_InitializeEx(0)' where it just prints:
  ImportError: No module named site

What? Does really all Pythons needs a 'PYTHONPATH' set to point to the
site.py? Or is it only CygWin that is special here? Since if I do a
"set PYTHONPATH=/usr/lib/python2.7" in my shell, my program works.

These are some of the func-ptr and arguments I use during init:

 Py_SetProgramName ("/cygdrive/f/gv/VC_project/EnvTool/src/envtool.exe")
 Py_SetPythonHome ("/usr/lib/python2.7")
 Py_InitializeEx(0)   << libpython2.7.dll chokes inside here for a mysterious 
reason.

I maybe naively assumes calling 'Py_SetPythonHome' is doing part of
what parsing the PYTHONPATH should do. But it doesn't seems so.

If I from my cmd-line do a:

c:\> f:\CygWin64\bin\python2.7.exe -c "import sys; print (sys.modules)"

I can see:
  

So what could be the reason it's not able to load and parse it
without a 'PYTHONPATH' set explicit?

--
--gv
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python programming classes for children

2015-07-01 Thread Tim Golden

On 01/07/2015 14:02, beliavsky--- via Python-list wrote:

My 11yo son is taking the online class "Intermediate Programming with
Python"
http://www.artofproblemsolving.com/school/course/catalog/python2
offered by the Art of Problem Solving company (AoPS). Classes meet
for 1.5 hours a week for 12 weeks. During the classes the instructor
"lectures" (types into a console -- there is no sound) and students
type answers to questions. There are weekly programming assignments.
AoPS is a U.S. company whose focus is preparing students for math
competitions.

Are there other groups offering Python courses for pre-college
students?



I realise that this may not be the answer you want but: pretty much the 
whole of the UK Primary & Secondary education system, at one level or 
another!


TJG
--
https://mail.python.org/mailman/listinfo/python-list


Datetime timezone trouble (was: Matplotlib X-axis timezone trouble)

2015-07-01 Thread Peter Pearson
On Wed, 1 Jul 2015 17:15:38 +1000, Chris Angelico  wrote:
>
> Interestingly, when I tried this (pytz version 2015.4, Python 2.7.9,
> Debian Jessie), I saw utcoffset() showing (-1, 58020) for both. That
> seems... odd. And I can't fault your dates - those definitely ought to
> be easily inside and easily outside the DST boundaries. When I try
> those dates in an unrelated time converter, they do show seven- and
> eight- hour offsets to UTC. Maybe we're both misunderstanding the
> meaning of utcoffset()?

Here's a very simple demonstration that either something is wrong
or I don't understand how datetime and tzinfo are supposed to work:

$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
>>> from pytz import timezone
>>> from datetime import datetime
>>> pacific = timezone("US/Pacific")
>>> print(datetime(2014, 7, 7, 12, tzinfo=pacific))
2014-07-07 12:00:00-08:00
>>> print(datetime(2014, 1, 7, 12, tzinfo=pacific))
2014-01-07 12:00:00-08:00
>>> 

The "-08:00" is appropriate in the second (January) case, but the
first case is in July, and should have "-07:00".

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Datetime timezone trouble (was: Matplotlib X-axis timezone trouble)

2015-07-01 Thread Ian Kelly
On Wed, Jul 1, 2015 at 10:36 AM, Peter Pearson
 wrote:
> On Wed, 1 Jul 2015 17:15:38 +1000, Chris Angelico  wrote:
>>
>> Interestingly, when I tried this (pytz version 2015.4, Python 2.7.9,
>> Debian Jessie), I saw utcoffset() showing (-1, 58020) for both. That
>> seems... odd. And I can't fault your dates - those definitely ought to
>> be easily inside and easily outside the DST boundaries. When I try
>> those dates in an unrelated time converter, they do show seven- and
>> eight- hour offsets to UTC. Maybe we're both misunderstanding the
>> meaning of utcoffset()?
>
> Here's a very simple demonstration that either something is wrong
> or I don't understand how datetime and tzinfo are supposed to work:
>
> $ python
> Python 2.7.3 (default, Mar 13 2014, 11:03:55)
 from pytz import timezone
 from datetime import datetime
 pacific = timezone("US/Pacific")
 print(datetime(2014, 7, 7, 12, tzinfo=pacific))
> 2014-07-07 12:00:00-08:00
 print(datetime(2014, 1, 7, 12, tzinfo=pacific))
> 2014-01-07 12:00:00-08:00

>
> The "-08:00" is appropriate in the second (January) case, but the
> first case is in July, and should have "-07:00".

Use this instead:

>>> print(pacific.localize(datetime(2014, 7, 7, 12)))
2014-07-07 12:00:00-07:00

See http://pytz.sourceforge.net/#localized-times-and-date-arithmetic
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Datetime timezone trouble (was: Matplotlib X-axis timezone trouble)

2015-07-01 Thread Chris Angelico
On Thu, Jul 2, 2015 at 2:36 AM, Peter Pearson  wrote:
> On Wed, 1 Jul 2015 17:15:38 +1000, Chris Angelico  wrote:
>>
>> Interestingly, when I tried this (pytz version 2015.4, Python 2.7.9,
>> Debian Jessie), I saw utcoffset() showing (-1, 58020) for both. That
>> seems... odd. And I can't fault your dates - those definitely ought to
>> be easily inside and easily outside the DST boundaries. When I try
>> those dates in an unrelated time converter, they do show seven- and
>> eight- hour offsets to UTC. Maybe we're both misunderstanding the
>> meaning of utcoffset()?
>
> Here's a very simple demonstration that either something is wrong
> or I don't understand how datetime and tzinfo are supposed to work:
>
> $ python
> Python 2.7.3 (default, Mar 13 2014, 11:03:55)
 from pytz import timezone
 from datetime import datetime
 pacific = timezone("US/Pacific")
 print(datetime(2014, 7, 7, 12, tzinfo=pacific))
> 2014-07-07 12:00:00-08:00
 print(datetime(2014, 1, 7, 12, tzinfo=pacific))
> 2014-01-07 12:00:00-08:00

>
> The "-08:00" is appropriate in the second (January) case, but the
> first case is in July, and should have "-07:00".

Interesting. I poked around with the docstring for pytz.timezone and
replicated it more exactly, and this appears to work:

$ python
Python 2.7.9 (default, Mar  1 2015, 12:57:24)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pytz import timezone
>>> from datetime import datetime
>>> pacific = timezone("US/Pacific")
>>> utc = timezone("UTC")
>>> print(datetime(2014, 7, 7, 12, tzinfo=utc).astimezone(pacific))
2014-07-07 05:00:00-07:00
>>> print(datetime(2014, 1, 7, 12, tzinfo=utc).astimezone(pacific))
2014-01-07 04:00:00-08:00

Clearly I do not understand what's going on here.

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


Re: Recreate file associations?

2015-07-01 Thread random832
On Mon, Jun 29, 2015, at 14:25, Terry Reedy wrote:
> Registry => Windows.
> Did you check [X] Make this my default python?

I didn't see any such checkbox, in any of installers I ran.

(And, yes, I assumed windows was implied by my subject - other systems
python runs on either don't have a notion of "file associations" or
don't use them as the mechanism for executing python scripts)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Datetime timezone trouble (was: Matplotlib X-axis timezone trouble)

2015-07-01 Thread Peter Pearson
On Wed, 1 Jul 2015 10:55:02 -0600, Ian Kelly  wrote:
> On Wed, Jul 1, 2015 at 10:36 AM, Peter Pearson [wrote]:
[snip]
>> Here's a very simple demonstration that either something is wrong
>> or I don't understand how datetime and tzinfo are supposed to work:
>>
>> $ python
>> Python 2.7.3 (default, Mar 13 2014, 11:03:55)
> from pytz import timezone
> from datetime import datetime
> pacific = timezone("US/Pacific")
> print(datetime(2014, 7, 7, 12, tzinfo=pacific))
>> 2014-07-07 12:00:00-08:00
> print(datetime(2014, 1, 7, 12, tzinfo=pacific))
>> 2014-01-07 12:00:00-08:00
>
>>
>> The "-08:00" is appropriate in the second (January) case, but the
>> first case is in July, and should have "-07:00".
>
> Use this instead:
>
 print(pacific.localize(datetime(2014, 7, 7, 12)))
> 2014-07-07 12:00:00-07:00
>
> See http://pytz.sourceforge.net/#localized-times-and-date-arithmetic

Excellent.  Thank you.

To summarize, for any similarly afflicted person who finds this thread:

 - http://pytz.sourceforge.net/#localized-times-and-date-arithmetic says:

Unfortunately using the tzinfo argument of the standard datetime
constructors ‘’does not work’’ with pytz for many timezones.

It is safe for timezones without daylight saving transitions though,
such as UTC:

 - PEP 0431 says (approximately) that datetime doesn't work as well
   as we might like with DST, but will be slow to change.

 - The "localize" function is pytz's way of working around this
   shortcoming of datetime's


-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 resuma a file download

2015-07-01 Thread zljubisic
Currently I am executing the following code:

import os
import urllib.request

def Download(rfile, lfile):

retval = False

if os.path.isfile(lfile):
lsize = os.stat(lfile).st_size
else:
lsize = 0

req = urllib.request.Request(rfile)
req.add_header('Range', "bytes={}-".format(lsize))


with urllib.request.urlopen(req) as response, open(lfile, 'ab') as out_file:
data = response.read() # a `bytes` object
out_file.write(data)

if response.headers.headers['Content-Length'] == os.stat(lfile).st_size:
retval = True

return retval

Download('http://video.hrt.hr/2906/otv296.mp4', 'otv296.mp4')

The internet connection here is very slow so execution will last for say an 
hour.

In meantime, can I upgrade the procedure in a way to write to file chunk by 
chunk instead of the whole file?

Furthermore, how to know whether the file is fully completed or not?
I trid with "if response.headers.headers['Content-Length'] == 
os.stat(lfile).st_size:", but I believe there is a better way.

Big regards.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 resuma a file download

2015-07-01 Thread Chris Angelico
On Thu, Jul 2, 2015 at 5:24 AM,   wrote:
> with urllib.request.urlopen(req) as response, open(lfile, 'ab') as 
> out_file:
> data = response.read() # a `bytes` object
> out_file.write(data)
>

If a file is big enough to want to resume the download once, you
almost certainly want to be able to resume it a second time. I would
recommend not attempting to do the entire read and write as a single
operation - read chunks and write them to the disk. This will attempt
to read the entire response into a gigantic in-memory bytestring, and
only then start writing.

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


Re: Python 3 resuma a file download

2015-07-01 Thread zljubisic
But how to read chunks?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 resuma a file download

2015-07-01 Thread Peter Otten
zljubi...@gmail.com wrote:

> But how to read chunks?

Instead of

> data = response.read() # a `bytes` object
> out_file.write(data)
 
use a loop:

CHUNKSIZE = 16*1024 # for example
while True:
   data =  response.read(CHUNKSIZE)
   if not data:
   break
   out_file.write(data)


This can be simplified:

shutil.copyfileobj(response, out_file)

https://docs.python.org/dev/library/shutil.html#shutil.copyfileobj

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


Re: Python 3 resuma a file download

2015-07-01 Thread zljubisic
New version with chunks:

import os
import urllib.request

def Download(rfile, lfile):

retval = False

if os.path.isfile(lfile):
lsize = os.stat(lfile).st_size
else:
lsize = 0

req = urllib.request.Request(rfile)
req.add_header('Range', "bytes={}-".format(lsize))


response = urllib.request.urlopen(req)

with open(lfile, 'ab') as out_file:
while True:
try:
chunk = response.read(8192)
if not chunk: break
out_file.write(chunk)
except ConnectionResetError as e:
print('Exception ConnectionResetError 
{0}'.format(os.stat(lfile).st_size))



if response.headers.headers['Content-Length'] == os.stat(lfile).st_size:
retval = True

return retval

Download('http://video.hrt.hr/2906/otv296.mp4', 
'c:\\Users\\zoran\\hrt\\sync\\otv296.mp4')
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 resuma a file download

2015-07-01 Thread Peter Otten
zljubi...@gmail.com wrote:

> New version with chunks:
> 
> import os
> import urllib.request
> 
> def Download(rfile, lfile):
> 
> retval = False
> 
> if os.path.isfile(lfile):
> lsize = os.stat(lfile).st_size
> else:
> lsize = 0
> 
> req = urllib.request.Request(rfile)
> req.add_header('Range', "bytes={}-".format(lsize))
> 
> 
> response = urllib.request.urlopen(req)
> 
> with open(lfile, 'ab') as out_file:
> while True:
> try:
> chunk = response.read(8192)
> if not chunk: break
> out_file.write(chunk)
> except ConnectionResetError as e:
> print('Exception ConnectionResetError
> {0}'.format(os.stat(lfile).st_size))

Catching the exception inside the while-True loop is not a good idea.

> if response.headers.headers['Content-Length'] ==
> os.stat(lfile).st_size:
> retval = True
> 
> return retval
> 
> Download('http://video.hrt.hr/2906/otv296.mp4',
> 'c:\\Users\\zoran\\hrt\\sync\\otv296.mp4')


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


Re: Python programming classes for children

2015-07-01 Thread John Ladasky
On Wednesday, July 1, 2015 at 6:03:06 AM UTC-7, beli...@aol.com wrote:
> My 11yo son is taking the online class "Intermediate Programming with Python" 
> http://www.artofproblemsolving.com/school/course/catalog/python2 offered by 
> the Art of Problem Solving company (AoPS). Classes meet for 1.5 hours a week 
> for 12 weeks. During the classes the instructor "lectures" (types into a 
> console -- there is no sound) and students type answers to questions. There 
> are weekly programming assignments. AoPS is a U.S. company whose focus is 
> preparing students for math competitions.
> 
> Are there other groups offering Python courses for pre-college students?

I would recommend that you investigate web sites which match tutors to 
students.  Find a Python tutor who can come to your home, or meet your son at a 
nearby public library.

I love technology, but it's not good for everything.  I have taught Python to a 
range of students, from middle-school age through working professionals.  I am 
also married to an elementary school teacher, and we sometimes discuss teaching 
methods and strategies.  I can't imagine that this remote, text-only method of 
teaching would be very effective, especially for a student that young.

If you have been programming for a while, you take some things for granted that 
kids have to learn, and be shown, with great patience.  For example, my 
youngest students often have trouble at first understanding the difference 
between variable names and their contents, especially when the variables are 
strings.

The only way that I agree to teach is face-to-face.  I have had a few potential 
students ask me to tutor over Skype, and I have always declined.

I bring a laptop, and the student sits at their own computer.  I have broad 
goals for a lesson when I arrive.  However I will, and indeed I must, deviate 
from my plans when the student doesn't understand a concept.

Occasionally I type on my own laptop, when instant visual feedback is needed.  
But mostly, I converse with the student, and look over their shoulders as they 
develop their code.  I let them make mistakes.  I ask them to run their buggy 
code, and when it doesn't work the way that they intended, I ask them if they 
can figure out why.

One more thing: I do NOT teach my students Python 2.  I have been working with 
a QA Engineer whose company uses Python 2, but all of my other students are 
free to choose to learn only Python 3.  Python 3 has been available for about 
five years now, and most new code is being developed in Py3.  I will not 
handicap my students by teaching them an obsolescent version of Python.
-- 
https://mail.python.org/mailman/listinfo/python-list


how to fix TypeError: format requires a mapping

2015-07-01 Thread hinaimran . mehr
I am pulling my hair with this problem right now,

I have the following Data structure 

[http://www.pubnub.com/developers/eon/chart/spline/)

message: {
  columns: [
["y": 0.043, "x": "2015-06-30T15:53:55"],
["y": 0.045, "x": "2015-06-30T15:53:55"]
  ]

Now I have the following code 

data = cclient.samples.list(meter_name ='cpu_util', limit=2)

result_rows = []
for row in data:
 formatted = """["y": %(counter_volume)0.3f, "x": "%(timestamp)s"]""" % 
(row)
 result_rows.append(formatted)
 
 print(',\n'.join(result_rows))


clean_json(data)





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


Re: Pure Python Data Mangling or Encrypting

2015-07-01 Thread Gregory Ewing

Randall Smith wrote:


 Worse case, something that looks like this would land on the disk.

crc32 checksum + translation table + malware


It would be safer to add something to both the
beginning *and* end of the file. Some file formats,
e.g. zip, pdf, are designed to be read starting
from the end.

So I would suggest something like

  crc32 checksum + payload + translation table

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


Re: Python 3 resuma a file download

2015-07-01 Thread Cameron Simpson

On 01Jul2015 21:51, Peter Otten <__pete...@web.de> wrote:

zljubi...@gmail.com wrote:


But how to read chunks?


Instead of


data = response.read() # a `bytes` object
out_file.write(data)


use a loop:

CHUNKSIZE = 16*1024 # for example
while True:
  data =  response.read(CHUNKSIZE)
  if not data:
  break
  out_file.write(data)


It might be worth noting here that Peter's "chunk" is just an arbitrary amount 
of data to read in a unit. I'm only mentioning this because the HTTP 
specification has a "chunked-encoding" used to return binary files, and we are 
not talking about _those_ chunks.


Cheers,
Cameron Simpson 

Life is uncertain.  Eat dessert first.  - Jim Blandy
--
https://mail.python.org/mailman/listinfo/python-list


"normalizing" a value

2015-07-01 Thread bvdp
Not sure what this is called (and I'm sure it's not normalize). Perhaps 
"scaling"?

Anyway, I need to convert various values ranging from around -50 to 50 to an 0 
to 12 range (this is part of a MIDI music program). I have a number of places 
where I do:

   while x < 0: x += 12
   while x >= 12: x -= 12

Okay, that works. Just wondering if there is an easier (or faster) way to 
accomplish this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "normalizing" a value

2015-07-01 Thread MRAB

On 2015-07-02 01:12, bvdp wrote:

Not sure what this is called (and I'm sure it's not normalize). Perhaps 
"scaling"?

Anyway, I need to convert various values ranging from around -50 to 50 to an 0 
to 12 range (this is part of a MIDI music program). I have a number of places 
where I do:

while x < 0: x += 12
while x >= 12: x -= 12

Okay, that works. Just wondering if there is an easier (or faster) way to 
accomplish this.


That's called "modular arithmetic". Use the modulo operator, '%':

x = x % 12

or just:

x %= 12

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


Re: "normalizing" a value

2015-07-01 Thread Paul Rubin
bvdp  writes:
>while x < 0: x += 12
>while x >= 12: x -= 12
> Okay, that works. Just wondering if there is an easier (or faster) way
> to accomplish this.

x = x % 12

should be the same as the above.  But are you sure that's really what
you want?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "normalizing" a value

2015-07-01 Thread Denis McMahon
On Wed, 01 Jul 2015 17:12:36 -0700, bvdp wrote:

> Not sure what this is called (and I'm sure it's not normalize). Perhaps
> "scaling"?
> 
> Anyway, I need to convert various values ranging from around -50 to 50
> to an 0 to 12 range (this is part of a MIDI music program). I have a
> number of places where I do:
> 
>while x < 0: x += 12 while x >= 12: x -= 12
> 
> Okay, that works. Just wondering if there is an easier (or faster) way
> to accomplish this.

Are you sure it works? Do you simply want to reduce it to the arbitrary 
range, or do you want to also retain the relationship between different x 
values such that if x1 < x2, f(x1) < f(x2)?

Consider the following x values:

-11, -12, -13, 11, 12, 13

-11 -> 1
-12 -> 0
-13 -> 11
11 -> 11
12 -> 0
13 -> 1

So -13 gives the same output value as 11 in your current code. Is this 
what you want?

You could try the following:

# step 1, limit x to the range -50 .. 50
if x < -50:
x = -50.0
ix x >= 50:
x = 50.0
# step 2, scale x to the range 0 .. 12
x = x * 0.12 + 6.0

If you want an integer value, you need to determine which method is most 
relevant. I would suggest rounding.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Javascript website scraping using WebKit and Selenium tools

2015-07-01 Thread Veek M
I tried scraping a javascript website using two tools, both didn't work. The 
website link is: http://xdguo.taobao.com/category-499399872.htm The relevant 
text I'm trying to extract is 'GY-68...':










I'm trying to match the class="item " bit as a preliminary venture:

from pyvirtualdisplay import Display
from selenium import webdriver
import time

display = Display(visible=0, size=(800, 600))
display.start()

browser = webdriver.Firefox()
browser.get('http://xdguo.taobao.com/category-499399872.htm')
print browser.title

time.sleep(120)
content = browser.find_element_by_class_name('item ')
print content
browser.quit()

display.stop()


I get:
selenium.common.exceptions.NoSuchElementException: Message: Unable to 
locate element: {"method":"class name","selector":"item "}

I also tried using WebKit - i know the site renders okay in WebKit because i 
tested with rekonq Here, i get the page (in Chinese) but the actual/relevant 
data is not there. WebKit's supposed to run the Javascript and give me the 
final results but I don't think that's happening.

import sys
from io import StringIO
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtWebKit import *
from lxml import html
from lxml import etree

#Take this class for granted.Just use result of rendering.
class Render(QWebPage):
  def __init__(self, url):
self.app = QApplication(sys.argv)
QWebPage.__init__(self)
self.loadFinished.connect(self._loadFinished)
self.mainFrame().load(QUrl(url))
self.app.exec_()

  def _loadFinished(self, result):
self.frame = self.mainFrame()
self.app.quit()

url = 'http://xdguo.taobao.com/category-499399872.htm'
r = Render(url) #returns a Render object
result = r.frame.toHtml() #returns a QString
result_utf8 = result.toUtf8() #returns a QByteArray of utf8 data

#QByteArray->str->unicode
#contents = StringIO(unicode(result_utf8.data(), "utf-8"))
data = result_utf8.data() #returns byte string
print(data)

element = html.fromstring(data)
print(element.tag)

for img in element.xpath('//dl[@class="item "]/dt[@class="photo"]/a/img'):
print(img.get('alt'))

#archive_links = html.fromstring(str(result.toAscii()))
#print 
archive_links.xpath("/html/body/div[2]/div[3]/div[2]/div[2]/div[1]/div/div
/div/div/div/div[2]/div[2]/dl[1]/dt/a/img")

Basically I want a list of parts the seller has to offer that I can grep, 
sort, uniq. I also tried elinks and lynx with ECMAScript but that was too 
basic and didn't work.

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


Re: how to fix TypeError: format requires a mapping

2015-07-01 Thread Denis McMahon
On Wed, 01 Jul 2015 14:57:14 -0700, hinaimran.mehr wrote:

> I am pulling my hair with this problem right now,
> 
> I have the following Data structure
> 
> [ u'resource_id': u'id', u'timestamp': u'2015-06-30T15:53:55',
> u'counter_volume': 0.043}]

This isn't a print out of any python data structure that I recognise. I 
assume you have a list of dictionaries, and that each dictionary 
represents one sample.

> I need to make it something like this to put in EON pubnub charting
> libaray (see link: http://www.pubnub.com/developers/eon/chart/spline/)
> 
> message: {
>   columns: [
> ["y": 0.043, "x": "2015-06-30T15:53:55"],
> ["y": 0.045, "x": "2015-06-30T15:53:55"]
>   ]
> 
> Now I have the following code
> 
> data = cclient.samples.list(meter_name ='cpu_util', limit=2)
> 
> result_rows = []
> for row in data:
>  formatted = """["y": %(counter_volume)0.3f, "x":
>  "%(timestamp)s"]""" % (row)
>  result_rows.append(formatted)
>  
>  print(',\n'.join(result_rows))
> 
> 
> clean_json(data)

I assume you want the output as json.

The solution may be to put the data into a suitable structure and dump 
the structure to json.

import json

thing = {}
msg = {}
cols = []

for row in data:
col = {}
col['x'] = row['timestamp']
col['y'] = row['counter_volume']
cols.append(col)

msg['columns'] = cols

thing['message'] = msg

print thing

print json.dumps(thing)


-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "normalizing" a value

2015-07-01 Thread random832
On Wed, Jul 1, 2015, at 20:12, bvdp wrote:
> Not sure what this is called (and I'm sure it's not normalize). Perhaps
> "scaling"?
> 
> Anyway, I need to convert various values ranging from around -50 to 50 to
> an 0 to 12 range (this is part of a MIDI music program). I have a number
> of places where I do:
> 
>while x < 0: x += 12
>while x >= 12: x -= 12

And this gives you what you want? With e.g. 13=1, 14=2, 22=10, 23=11,
24=0, 25 = 1, etc. Seems unusual that that's what you would want.

Also note this gives an 0 to 11 range for the results, not 0 to 12.

Anyway, x %= 12 will give the same results.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python programming classes for children

2015-07-01 Thread Great Avenger Singh
On Wednesday, 1 July 2015 18:33:06 UTC+5:30, beli...@aol.com  wrote:
 
> Are there other groups offering Python courses for pre-college students?

Some months ago I took one course from Edx, They provide very good material and 
every each topic assignment is given,

You can try following:

https://www.edx.org/course/introduction-computer-science-mitx-6-00-1x-0
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "normalizing" a value

2015-07-01 Thread bvdp
On Wednesday, July 1, 2015 at 6:27:57 PM UTC-7, rand...@fastmail.us wrote:
> On Wed, Jul 1, 2015, at 20:12, bvdp wrote:
> > Not sure what this is called (and I'm sure it's not normalize). Perhaps
> > "scaling"?
> > 
> > Anyway, I need to convert various values ranging from around -50 to 50 to
> > an 0 to 12 range (this is part of a MIDI music program). I have a number
> > of places where I do:
> > 
> >while x < 0: x += 12
> >while x >= 12: x -= 12
> 
> And this gives you what you want? With e.g. 13=1, 14=2, 22=10, 23=11,
> 24=0, 25 = 1, etc. Seems unusual that that's what you would want.
> 
> Also note this gives an 0 to 11 range for the results, not 0 to 12.
> 
> Anyway, x %= 12 will give the same results.

Thanks guys. Yes, that is exactly what I want. I have a number of places where 
a MIDI note value is being generated. MIDI should be 0..127, but the process 
creates notes outside the range. Guess that's another question: if the value I 
have is <0 or >127 I add/subtract 12 'til it's in range. Don't see using modulo 
working on this???

As far as the original question: Yes, that's what I need. At times I need to 
take a note (say 14) and map it into a single octave range. So, the 12 becomes 
2. Both 14 and 2 are numeric values for note "d", just an octave apart.

Interesting that negative values translate properly. That's an non-intuitive 
result to me. Guess I should have studied that math stuff harder way back when!


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


Re: Python programming classes for children

2015-07-01 Thread Great Avenger Singh
On Thursday, 2 July 2015 07:20:03 UTC+5:30, Great Avenger Singh  wrote:
> On Wednesday, 1 July 2015 18:33:06 UTC+5:30, beli...@aol.com  wrote:
>  
> > Are there other groups offering Python courses for pre-college students?
> 
> Some months ago I took one course from Edx, They provide very good material 
> and every each topic assignment is given,
> 
> You can try following:
> 
> https://www.edx.org/course/introduction-computer-science-mitx-6-00-1x-0

If your son has already gotten basic programming concepts like execution of 
instruction that's fine. 

Otherwise give also try to this:
https://code.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "normalizing" a value

2015-07-01 Thread Steven D'Aprano
On Thu, 2 Jul 2015 10:12 am, bvdp wrote:

> Not sure what this is called (and I'm sure it's not normalize). Perhaps
> "scaling"?


Could be normalising, could be scaling.
 
> Anyway, I need to convert various values ranging from around -50 to 50 to
> an 0 to 12 range (this is part of a MIDI music program). I have a number
> of places where I do:

You say "around" -50 to 50. Can you get 51? 151? How do you want to treat
such out of range numbers?

Are the values integer valued, or can they include fractional values like
27.356?

>while x < 0: x += 12
>while x >= 12: x -= 12
> 
> Okay, that works. Just wondering if there is an easier (or faster) way to
> accomplish this.


One approach is to just re-scale the numbers from the range -50...50 to
0...12 inclusive. That is:

before => after
-50 => 0
0 => 6
50 => 12


and everything in between is scaled equivalently. Given x between -50 and 50
inclusive, calculate:

y = (x+50)/100.0*12


(Note that in Python 2, you need to make at least one of those values a
float, otherwise you may get unexpected results.)

That will give you y values from the range 0.0 to 12.0 inclusive. If x is
less than -50.0 or more than +50.0 y will likewise be out of range. You can
clip the result:

y = min(12.0, max(0.0, y))

If your x values are integer values (no fractional values) between -50 and
+50 you can use clock arithmetic. Think of a clock marked 0 to 12 (so there
are 13 values), once you reach 12 adding 1 takes you back to 0.

0, 13, 26, 39 => 0
1, 14, 27, 40 => 1
2, 15, 28, 41 => 2
...
12, 25, 38, 51 => 12


Extending that to negative values in the most obvious fashion:

-1, -14, -27, -40 => 12
...
-12, -25, -38, -51 => 1
-13, -26, -39, -52 => 0


We can do that easily with the % (modulo) operator:

y = x % y


Modulo even works with non-integer values:

py> 13.5 % 13
0.5



-- 
Steven

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


Re: "normalizing" a value

2015-07-01 Thread random832
On Wed, Jul 1, 2015, at 21:49, bvdp wrote:
> Interesting that negative values translate properly. That's an
> non-intuitive result to me. Guess I should have studied that math stuff
> harder way back when!

There are multiple interpretations of the operation, and not all
languages behave the same way as Python does with negative operands.
Python is the odd one out when one considers C/C++, C#, and Java which
all behave a different way.

In general, almost all languages behave in a way so that given q, r = a
// b, a % b; q * b + r == a. However, this simply changes the question
to how division results involving negative operands are rounded.

Here's an article by GvR about why python behaves the way it does:
http://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "normalizing" a value

2015-07-01 Thread bvdp
On Wednesday, July 1, 2015 at 7:15:28 PM UTC-7, Steven D'Aprano wrote:
> On Thu, 2 Jul 2015 10:12 am, bvdp wrote:
> 
> > Not sure what this is called (and I'm sure it's not normalize). Perhaps
> > "scaling"?
> 
> 
> Could be normalising, could be scaling.
>  
> > Anyway, I need to convert various values ranging from around -50 to 50 to
> > an 0 to 12 range (this is part of a MIDI music program). I have a number
> > of places where I do:
> 
> You say "around" -50 to 50. Can you get 51? 151? How do you want to treat
> such out of range numbers?
> 
> Are the values integer valued, or can they include fractional values like
> 27.356?
> 
> >while x < 0: x += 12
> >while x >= 12: x -= 12
> > 
> > Okay, that works. Just wondering if there is an easier (or faster) way to
> > accomplish this.
> 
> 
> One approach is to just re-scale the numbers from the range -50...50 to
> 0...12 inclusive. That is:
> 
> before => after
> -50 => 0
> 0 => 6
> 50 => 12
> 
> 
> and everything in between is scaled equivalently. Given x between -50 and 50
> inclusive, calculate:
> 
> y = (x+50)/100.0*12
> 
> 
> (Note that in Python 2, you need to make at least one of those values a
> float, otherwise you may get unexpected results.)
> 
> That will give you y values from the range 0.0 to 12.0 inclusive. If x is
> less than -50.0 or more than +50.0 y will likewise be out of range. You can
> clip the result:
> 
> y = min(12.0, max(0.0, y))
> 
> If your x values are integer values (no fractional values) between -50 and
> +50 you can use clock arithmetic. Think of a clock marked 0 to 12 (so there
> are 13 values), once you reach 12 adding 1 takes you back to 0.
> 
> 0, 13, 26, 39 => 0
> 1, 14, 27, 40 => 1
> 2, 15, 28, 41 => 2
> ...
> 12, 25, 38, 51 => 12
> 
> 
> Extending that to negative values in the most obvious fashion:
> 
> -1, -14, -27, -40 => 12
> ...
> -12, -25, -38, -51 => 1
> -13, -26, -39, -52 => 0
> 
> 
> We can do that easily with the % (modulo) operator:
> 
> y = x % y
> 
> 
> Modulo even works with non-integer values:
> 
> py> 13.5 % 13
> 0.5
> 
> 
> 
> -- 
> Steven

Thanks for this Steven. However, I think it's not correct in this case. Like I 
said in another message X%12 is working just fine. No matter what the value is.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "normalizing" a value

2015-07-01 Thread bvdp
On Wednesday, July 1, 2015 at 7:23:19 PM UTC-7, rand...@fastmail.us wrote:
> On Wed, Jul 1, 2015, at 21:49, bvdp wrote:
> > Interesting that negative values translate properly. That's an
> > non-intuitive result to me. Guess I should have studied that math stuff
> > harder way back when!
> 
> There are multiple interpretations of the operation, and not all
> languages behave the same way as Python does with negative operands.
> Python is the odd one out when one considers C/C++, C#, and Java which
> all behave a different way.
> 
> In general, almost all languages behave in a way so that given q, r = a
> // b, a % b; q * b + r == a. However, this simply changes the question
> to how division results involving negative operands are rounded.
> 
> Here's an article by GvR about why python behaves the way it does:
> http://python-history.blogspot.com/2010/08/why-pythons-integer-division-floors.html

Interesting link. Thanks. I always thought that modulo was modulo. Guess this 
is another example of why converting code between languages is hard :)

Anyway, far as shoving my MIDI notes into a single octave, x % 12 seems to be 
perfect.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3 resuma a file download

2015-07-01 Thread Tim Chase
On 2015-07-01 21:51, Peter Otten wrote:
> use a loop:
> 
> CHUNKSIZE = 16*1024 # for example
> while True:
>data =  response.read(CHUNKSIZE)
>if not data:
>break
>out_file.write(data)
> 
> 
> This can be simplified:
> 
> shutil.copyfileobj(response, out_file)

It's these little corners of Python that make me wonder how many
times I've written that `while` loop when I could have just used a
tested function from the stdlib.  Sigh.

-tkc


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


Installing Pybison

2015-07-01 Thread Great Avenger Singh
Hello Everyone,

I am installing Pybison from following Source:

https://github.com/smvv/pybison

After installing all required dependencies I am able to run "sodo python 
setup.py install" without any errors.

I am getting following error while Running "python -c import bison"

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.7/dist-packages/bison.py", line 23, in 
from bison_ import ParserEngine
ImportError: /usr/local/lib/python2.7/dist-packages/bison_.so: undefined 
symbol: py_callback
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "normalizing" a value

2015-07-01 Thread Mark Lawrence

On 02/07/2015 01:12, bvdp wrote:

Not sure what this is called (and I'm sure it's not normalize). Perhaps 
"scaling"?

Anyway, I need to convert various values ranging from around -50 to 50 to an 0 
to 12 range (this is part of a MIDI music program). I have a number of places 
where I do:

while x < 0: x += 12
while x >= 12: x -= 12

Okay, that works. Just wondering if there is an easier (or faster) way to 
accomplish this.



Further to other answers have you tried looking for a library, or even 
just a recipe, that has already been written and tested that does this 
for you?


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Javascript website scraping using WebKit and Selenium tools

2015-07-01 Thread dieter
Veek M  writes:

> I tried scraping a javascript website using two tools, both didn't work. The 
> website link is: http://xdguo.taobao.com/category-499399872.htm The relevant 
> text I'm trying to extract is 'GY-68...':
>
> 
>
> 
> 
>  id="4002-6778075404" data-spm-anchor-id="a1z10.5-c.w4002-6778075404.11">
>  src="//img.alicdn.com/bao/uploaded/i4/TB1HMt3FFaFaVXX_!!0-
> item_pic.jpg_240x240.jpg" alt="GY-68 BMP180 ?? BOSCH?? ??? ??
> BMP085">
> 
> 

> ...

When I try to access the link above, I am redirected to a
login page - which, of course, may look very different from what you expect.
You may need to pass on authentication information along with
your request in order to get the page you are expecting.

Note also, that todays sites often heavily use Javascript - which
means that a page only gets the final look when the Javascript
has been executed.


Once the problems to get the "final" HTML code solved,
I would use "lxml" and its "xpath" support to locate any
relevant HTML information.

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


Re: Installing Pybison

2015-07-01 Thread dieter
Great Avenger Singh  writes:
> I am installing Pybison from following Source:
>
> https://github.com/smvv/pybison
>
> After installing all required dependencies I am able to run "sodo python 
> setup.py install" without any errors.
>
> I am getting following error while Running "python -c import bison"
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/local/lib/python2.7/dist-packages/bison.py", line 23, in 
> from bison_ import ParserEngine
> ImportError: /usr/local/lib/python2.7/dist-packages/bison_.so: undefined 
> symbol: py_callback

This likely means that some required external (C-level) library is
either missing on your system or cannot be found.

Typical approach to resolve an issue of this kind: look for installation
instructions, especially instructions telling about external dependencies.
Ensure, all dependencies are installed. In case, they are
installed in non-standard locations, use "LD_LIBRARY_PATH" to make
those installations known.

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


Re: Javascript website scraping using WebKit and Selenium tools

2015-07-01 Thread Veek M
dieter wrote:

> Once the problems to get the "final" HTML code solved,
> I would use "lxml" and its "xpath" support to locate any
> relevant HTML information.

Hello Dieter, yes - you are correct. (though I don't think there's any auth 
to browse - nice that you actually tried) He's using jsonP and updating his 
html. I decided to manually mangle it.

urllib to download, re to nuke the jsonp(".stuff i want..") and 
then lxml. It works and I got the text. Now i need to translate - many 
thanks.

I should have checked first using HTTP Headers to see what he was 
downloading - i'm an ass. Oh well solved :)
-- 
https://mail.python.org/mailman/listinfo/python-list