rst and pypandoc

2015-03-02 Thread alb
Hi everyone,

I'm writing a document in restructured text and I'd like to convert it 
to latex for printing. To accomplish this I've used semi-successfully 
pandoc and the wrapper pypandoc.

My biggest issue is with figures and references to them. We've our macro 
to allocate figures so I'm forced to bypass the rst directive /.. 
figure/, moreover I haven't happened to find how you can reference to a 
figure in the rst docs.

For all the above reasons I'm writing snippets of pure latex in my rst 
doc, but I'm having issues with the escape characters:

i = '\ref{fig:abc}'
print pypandoc.convert(i, 'latex', format='rst')
ef\{fig:abc\}

because of the \r that is interpreted by python as special character.

If I try to escape with '\' I don't seem to find a way out...

Any idea/pointer/suggestion?

Al

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
-- 
https://mail.python.org/mailman/listinfo/python-list


reload a module imported with importlib.machinery.SourceFileLoader

2015-03-02 Thread Tal Einat
Hi everyone,

I'm trying to import a module with tests, run the tests, then patch
some things with mock.patch, reload the tests module and re-run the
tests. This is part of an interactive course in which the tests module
is written by the user. Therefore I'm using
importlib.machinery.SourceFileLoader to import the tests module, like
so:

importlib.machinery.SourceFileLoader("tmp", path).load_module("tmp")

This works just fine. However, when trying to reload the module,
importlib.reload(module) is raising the following exception:

Traceback (most recent call last):
  File ".../tests.py", line 28, in 
reload_module(module)
  File ".../custom_test_helpers.py", line 18, in reload_module
importlib.reload(module)
  File ".../lib/python3.4/importlib/__init__.py", line 149, in reload
methods.exec(module)
  File "", line 1134, in exec
AttributeError: 'NoneType' object has no attribute 'name'

Am I going about this the wrong way? Is this a bug in importlib? If it
is a bug, and suggestions for a workaround?

I'm running Python 3.4.2, installed via pyenv on OSX 10.8.

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


Python27.dll could not be found

2015-03-02 Thread Sarvagya Pant
I have been writing a c++ program that is supposed to call the python
function. The code is a snippet from python.org itself.
#include 
#include 
#include 

int main()
{
Py_SetProgramName("Learning");
Py_Initialize();
PyRun_SimpleString("import hashlib\nprint hashlib.md5('sarvagya
pant').hexdigest()");
Py_Finalize();
return 0;
}

I have used Visual Studio 2010. I have linked the include directories and
lib files correctly. It gets correctly built. Dependency walker shows the
file depends upon Python27.dll.
I have looked into the folder Dlls of python. It is not there. Also I have
checked both System and System32 folder. It is not present in there too.
Python version is 2.7. How can I get Python27.dll to deploy my app for
customers? Please help.

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


Re: Python Worst Practices

2015-03-02 Thread Chris Angelico
On Mon, Mar 2, 2015 at 3:52 AM, Mark Lawrence  wrote:
>> It's not one that we use out here in the Antipodes... probably a
>> British peculiarity. Or perhaps an English peculiarity, but I would
>> guess more likely British.
>>
>> ChrisA
>>
>
> British.  Never call me English, my mum was Welsh and would come back from
> the grave to haunt you :)

Ah, I didn't know you were part Welsh. The name Lawrence is a good
English one, and Breamore is itself in England. But I shall strive to
remember :)

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


Md5 is different in Windows and Linux

2015-03-02 Thread Sarvagya Pant
Hello, I am amazed that the  md5 of a file given by python in windows is
different than that of linux. Consider the following code:

import hashlib
def md5_for_file(f, block_size=2**20):
md5 = hashlib.md5()
while True:
data = f.read(block_size)
if not data:
break
md5.update(data)
return md5.hexdigest()

f = open("somefile.txt")
print md5_for_file(f)

When I run the program I get the checksum value:
2f9cc8da53ee89762a34702f745d2956

But on this site http://onlinemd5.com/ and on linux it has value
E10D4E3847713472F51BC606852712F1.

Why is there difference in value of Checksum computed by python in windows
and other system.?

-- 
*sarvagya*
Hello
Check the MD5
of this file-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about python package numpy

2015-03-02 Thread Robert Kern

On 2015-03-01 20:32, fl wrote:

Hi,

It is difficult to install numpy package for my PC Windows 7, 64-bit OS. In
the end, I install Enthought Canopy, which is recommended on line because it
does install numpy automatically. Now, I can test it with

import numpy

it succeeds. On http://wiki.scipy.org/Cookbook, it shows some interesting
code example snippet, such as Cookbook / ParticleFilter, Markov chain etc.

I don't know how I can access these code examples, because I don't know where
Enthought Canopy installs these package.

Could you help me on using numpy examples?


None of these examples come prepackaged in any distribution I am aware of. You 
are intended to copy-and-paste them from the wiki if you want to use them.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Md5 is different in Windows and Linux

2015-03-02 Thread Tim Golden
On 02/03/2015 06:19, Sarvagya Pant wrote:
> Hello, I am amazed that the  md5 of a file given by python in windows is
> different than that of linux. Consider the following code:
> 
> import hashlib
> def md5_for_file(f, block_size=2**20):
> md5 = hashlib.md5()
> while True:
> data = f.read(block_size)
> if not data:
> break
> md5.update(data)
> return md5.hexdigest()
> 
> f = open("somefile.txt")
> print md5_for_file(f)
> 
> When I run the program I get the checksum value:
> 2f9cc8da53ee89762a34702f745d2956
> 
> But on this site http://onlinemd5.com/ and on linux it has value
> E10D4E3847713472F51BC606852712F1.
> 
> Why is there difference in value of Checksum computed by python in
> windows and other system.?


Because you're opening the file in text mode (implicitly; that's the
default) which silently converts certain characters. If you open it in
binary mode:

f = open("somefile.txt", "rb")

then you should see the same result

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


Re: Md5 is different in Windows and Linux

2015-03-02 Thread Peter Otten
Sarvagya Pant wrote:

> Hello, I am amazed that the  md5 of a file given by python in windows is
> different than that of linux. Consider the following code:
> 
> import hashlib
> def md5_for_file(f, block_size=2**20):
> md5 = hashlib.md5()
> while True:
> data = f.read(block_size)
> if not data:
> break
> md5.update(data)
> return md5.hexdigest()
> 
> f = open("somefile.txt")
> print md5_for_file(f)
> 
> When I run the program I get the checksum value:
> 2f9cc8da53ee89762a34702f745d2956
> 
> But on this site http://onlinemd5.com/ and on linux it has value
> E10D4E3847713472F51BC606852712F1.
> 
> Why is there difference in value of Checksum computed by python in windows
> and other system.?

You have to open the file in binary mode

f = open("somefile.txt", "rb")

Otherwise on Windows "\r\n" will be translated to "\n" while Linux passes 
the bytes unchanged -- and thus md5.update() will see different data and 
produce a different checksum.


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


Re: Python Worst Practices

2015-03-02 Thread alister
On Sun, 01 Mar 2015 20:14:13 -0800, Rustom Mody wrote:

> On Sunday, March 1, 2015 at 10:32:00 PM UTC+5:30, Marko Rauhamaa wrote:
>> Mark Lawrence :
>> 
>> > Are you suggesting that we Brits have a single "home accent"?  If you
>> > are, you need to stand up as your voice is rather muffled.  That by
>> > the way is a British expression that may or may not be used around
>> > the Commonwealth.  Should we unlearn it to fit in with American
>> > English? Two chances, zero or none.
>> 
>> What you (or I) speak in our native surroundings is up to you (and me).
>> 
>> However, when I exhange software engineering ideas with you, I wish
>> both of us could stick to American English.
> 
> When I was in college, there was this course called ‹Accounting and
> Bookkeeping›
> It was a disaster since I always accounted on the wrong side of the
> ledger.
> I guess I only passed because the teacher occasionally also accounted on
> the wrong side of the ledger!!
> 
> With due respect Marko, are you accounting on the wrong side of the
> ledger?
> 
> If some non-native of English expresses him/herself poorly we still try
> to understand – its even in the code of conduct or somethin
> 
> And yet you insist that a Brit (or English or whatever) should change
> his ways¹?


or as another analogy why don't you (Marco) try telling a Barber in 
Seville that he should be speaking Latin Spanish not that strange 
variation he uses?

I suspect the  reaction you get will be far more severe than the one you 
are getting from we English (& Brits)


-- 
system has been recalled
-- 
https://mail.python.org/mailman/listinfo/python-list


PyPI, reStructuredText and readthedocs problems

2015-03-02 Thread Leonardo Giordani
Hi all,

Some time ago I open sourced a package named postage (
https://pypi.python.org/pypi/postage/).

I am experiencing issues with documentation. The project is hosted on
GitHub (https://github.com/lgiordani/postage), where the README.md is
perfectly rendered. My issues are:

1. I use pandoc to convert README.md to README.rst. This latter is rendered
by GitHUb as well, but when I upload the package to PyPI I get a messy
result (look at the package page).

2. When I import the project into readthedocs.org the build fails with no
output. This is the only information I get

- 8< -

Build for postage

Built: Feb. 27, 2015. 10:41 a.m.

State: Finished

Outcome: Failed (Status Code: 0)

Version: latest

Type: html

Build Standard Output

- 8< -

May someone help me figuring out what's wrong in my code?
Thanks!

Leo


Leonardo Giordani
@tw_lgiordani  - lgiordani.com
My profile on About.me  - My GitHub page

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


Re: suggestions for functional style (singleton pattern?)

2015-03-02 Thread Fabien

On 01.03.2015 06:05, Michael Torrie wrote:

  A module*is*  a singleton pattern, particularly one
that maintains state.  I use sometimes use this feature for sharing
config and other data between other modules (global state when it's
required).


I do this too, after some helping recommendations I got from this 
discussion group. I find it neat to use a module for sharing config 
states, but I always wondered: does this pattern fall into the "globals 
are devil" category?


Cheers,

Fabien

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


Re: Md5 is different in Windows and Linux

2015-03-02 Thread Denis McMahon
On Mon, 02 Mar 2015 12:04:46 +0545, Sarvagya Pant wrote:

> When I run the program I get the checksum value:
> 2f9cc8da53ee89762a34702f745d2956
> 
> But on this site http://onlinemd5.com/ and on linux it has value
> E10D4E3847713472F51BC606852712F1.
> 
> Why is there difference in value of Checksum computed by python in
> windows and other system.?

Perhaps windows file io is padding the file to the block size? Or maybe 
the windows version has different end of lines.

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


Re: PyPI, reStructuredText and readthedocs problems

2015-03-02 Thread INADA Naoki
PyPI parses your README strictly.

$ rst2html.py --strict README.rst
README.rst:700: (INFO/1) Duplicate implicit target name: "fingerprint".
Exiting due to level-1 (INFO) system message.

But I don't know how to avoid this error when converting from markdown.

On Mon, Mar 2, 2015 at 6:35 PM Leonardo Giordani <
giordani.leona...@gmail.com> wrote:

> Hi all,
>
> Some time ago I open sourced a package named postage (
> https://pypi.python.org/pypi/postage/).
>
> I am experiencing issues with documentation. The project is hosted on
> GitHub (https://github.com/lgiordani/postage), where the README.md is
> perfectly rendered. My issues are:
>
> 1. I use pandoc to convert README.md to README.rst. This latter is
> rendered by GitHUb as well, but when I upload the package to PyPI I get a
> messy result (look at the package page).
>
> 2. When I import the project into readthedocs.org the build fails with no
> output. This is the only information I get
>
> - 8< -
>
> Build for postage
>
> Built: Feb. 27, 2015. 10:41 a.m.
>
> State: Finished
>
> Outcome: Failed (Status Code: 0)
>
> Version: latest
>
> Type: html
>
> Build Standard Output
>
> - 8< -
>
> May someone help me figuring out what's wrong in my code?
> Thanks!
>
> Leo
>
>
> Leonardo Giordani
> @tw_lgiordani  - lgiordani.com
> My profile on About.me  - My GitHub
> page 
>  --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: suggestions for functional style (singleton pattern?)

2015-03-02 Thread Mario Figueiredo
On Mon, 02 Mar 2015 11:19:06 +0100, Fabien 
wrote:

>On 01.03.2015 06:05, Michael Torrie wrote:
>>   A module*is*  a singleton pattern, particularly one
>> that maintains state.  I use sometimes use this feature for sharing
>> config and other data between other modules (global state when it's
>> required).
>
>I do this too, after some helping recommendations I got from this 
>discussion group. I find it neat to use a module for sharing config 
>states, but I always wondered: does this pattern fall into the "globals 
>are devil" category?
>

Global constants are conceptually different than global variables. It
is just that in Python there is no semantic diference between the two.
The former are OK and a useful pattern, whereas the latter are the
ones we call evil.
-- 
https://mail.python.org/mailman/listinfo/python-list


Uncanny valley of languages

2015-03-02 Thread Jonas Wielicki
On 01.03.2015 18:34, Mark Lawrence wrote:
> On 01/03/2015 17:01, Marko Rauhamaa wrote:
>> Mark Lawrence :
>>
>>> Are you suggesting that we Brits have a single "home accent"?  If you
>>> are, you need to stand up as your voice is rather muffled.  That by the
>>> way is a British expression that may or may not be used around the
>>> Commonwealth.  Should we unlearn it to fit in with American English? Two
>>> chances, zero or none.
>>
>> What you (or I) speak in our native surroundings is up to you (and me).
>>
>> However, when I exhange software engineering ideas with you, I wish both
>> of us could stick to American English.
>>
>>
>> Marko
>>
> 
> Well I'm not going to, so tough, or is that togh?  Colour, harbour,
> tyre, antogonise are the way I spell words, and I'm not changing the
> habits of a lifetime simply because I'm on a technical site.
> 

I wonder whether this discussion has anything to do with the Uncanny
Valley [1]. Anyone who is not native to some dialect of English just has
to learn that language it if they want to be taken serious in the SE
world. That’s kind of a law. On the other hand, there are some British
refuse to learn a few minor adaptions to their native tongue, while
others have to trade their native tongue completely.

This leads me to believe that due to the fact that there are so many
similarities between en_US and en_GB (they are even closer than C and
C++, which are already taken as being the same language with dialects by
some), it feels as if en_US was dictating them how to live their own
language, while in fact, they are distinct and noone tries to dictate
anything about en_GB.

That said, I also prefer the British spelling. But that is just, like,
my opinion, man.

regards,
jwi


   [1]: https://en.wikipedia.org/wiki/Uncanny_valley



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyPI, reStructuredText and readthedocs problems

2015-03-02 Thread Wolfgang Maier

On 03/02/2015 11:33 AM, INADA Naoki wrote:

PyPI parses your README strictly.

$ rst2html.py --strict README.rst
README.rst:700: (INFO/1) Duplicate implicit target name: "fingerprint".
Exiting due to level-1 (INFO) system message.

But I don't know how to avoid this error when converting from markdown.



The other occurence of a title Fingerprint is at line 436. I guess you 
will have to change one of the two titles (maybe Fingerprints ?) to make 
things work.



On Mon, Mar 2, 2015 at 6:35 PM Leonardo Giordani
mailto:giordani.leona...@gmail.com>> wrote:

Hi all,

Some time ago I open sourced a package named postage
(https://pypi.python.org/pypi/postage/).

I am experiencing issues with documentation. The project is hosted
on GitHub (https://github.com/lgiordani/postage), where the
README.md is perfectly rendered. My issues are:

1. I use pandoc to convert README.md to README.rst. This latter is
rendered by GitHUb as well, but when I upload the package to PyPI I
get a messy result (look at the package page).

2. When I import the project into readthedocs.org
 the build fails with no output. This is the
only information I get

- 8< -

Build for postage

Built: Feb. 27, 2015. 10:41 a.m.

State: Finished

Outcome: Failed (Status Code: 0)

Version: latest

Type: html

Build Standard Output

- 8< -

May someone help me figuring out what's wrong in my code?
Thanks!

Leo



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


Re: rst and pypandoc

2015-03-02 Thread Wolfgang Maier

On 03/02/2015 08:59 AM, alb wrote:

Hi everyone,

I'm writing a document in restructured text and I'd like to convert it
to latex for printing. To accomplish this I've used semi-successfully
pandoc and the wrapper pypandoc.

My biggest issue is with figures and references to them. We've our macro
to allocate figures so I'm forced to bypass the rst directive /..
figure/, moreover I haven't happened to find how you can reference to a
figure in the rst docs.

For all the above reasons I'm writing snippets of pure latex in my rst
doc, but I'm having issues with the escape characters:

i = '\ref{fig:abc}'
print pypandoc.convert(i, 'latex', format='rst')
ef\{fig:abc\}

because of the \r that is interpreted by python as special character.

If I try to escape with '\' I don't seem to find a way out...



what exactly do you mean by not finding a way out ? Escaping with a '\' 
should work. Of course, that backslash will print for clarity, but I 
suppose you want to write this to a file ? What happens if you do so ?


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


Re: Design thought for callbacks

2015-03-02 Thread Cem Karan

On Feb 26, 2015, at 3:00 PM, Ethan Furman  wrote:

> On 02/26/2015 11:54 AM, Ian Kelly wrote:
> 
>> Sometimes I wonder whether anybody reads my posts.
> 
> It's entirely possible the OP wasn't ready to understand your solution four 
> days ago, but two days later the OP was.

Thank you Ethan, that was precisely my problem.

Thanks,
Cem Karan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Design thought for callbacks

2015-03-02 Thread Cem Karan

On Feb 26, 2015, at 7:04 PM, Fabio Zadrozny  wrote:

> 
> On Wed, Feb 25, 2015 at 9:46 AM, Cem Karan  wrote:
> 
> On Feb 24, 2015, at 8:23 AM, Fabio Zadrozny  wrote:
> 
> > Hi Cem,
> >
> > I didn't read the whole long thread, but I thought I'd point you to what 
> > I'm using in PyVmMonitor (http://www.pyvmmonitor.com/) -- which may already 
> > cover your use-case.
> >
> > Take a look at the callback.py at 
> > https://github.com/fabioz/pyvmmonitor-core/blob/master/pyvmmonitor_core/callback.py
> >
> > And its related test (where you can see how to use it): 
> > https://github.com/fabioz/pyvmmonitor-core/blob/master/_pyvmmonitor_core_tests/test_callback.py
> >  (note that it falls back to a strong reference on simple functions -- 
> > i.e.: usually top-level methods or methods created inside a scope -- but 
> > otherwise uses weak references).
> 
> That looks like a better version of what I was thinking about originally.  
> However, various people on the list have convinced me to stick with strong 
> references everywhere.  I'm working out a possible API right now, once I have 
> some code that I can use to illustrate what I'm thinking to everyone, I'll 
> post it to the list.
> 
> Thank you for showing me your code though, it is clever!
> 
> Thanks,
> Cem Karan
> 
> ​Hi Cem,
> 
> Well, I decided to elaborate a bit on the use-case I have and how I use it 
> (on a higher level): 
> http://pydev.blogspot.com.br/2015/02/design-for-client-side-applications-in.html
> 
> So, you can see if it may be worth for you or not (I agree that sometimes you 
> should keep strong references, but for my use-cases, weak references usually 
> work better -- with the only exception being closures, which is handled 
> different anyways but with the gotcha of having to manually unregister it).

As I mentioned in an earlier post, I've been quite busy at home, and expect to 
be for a few days to come, so I apologize both for being so late posting, and 
for not posting my own API plans.

Your blog post has given me quite a bit to think about, thank you!  Do you mind 
if I work up an API similar to yours?  I'm planning on using a different 
license (not LGPL), which is why I ask.

Thanks,
Cem Karan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Design thought for callbacks

2015-03-02 Thread Cem Karan
On Feb 26, 2015, at 2:54 PM, Ian Kelly  wrote:
> On Feb 26, 2015 4:00 AM, "Cem Karan"  wrote:
> >
> >
> > On Feb 26, 2015, at 12:36 AM, Gregory Ewing  
> > wrote:
> >
> > > Cem Karan wrote:
> > >> I think I see what you're talking about now.  Does WeakMethod
> > >> (https://docs.python.org/3/library/weakref.html#weakref.WeakMethod) solve
> > >> this problem?
> > >
> > > Yes, that looks like it would work.
> >
> >
> > Cool!
> 
> Sometimes I wonder whether anybody reads my posts. I suggested a solution 
> involving WeakMethod four days ago that additionally extends the concept to 
> non-method callbacks (requiring a small amount of extra effort from the 
> client in those cases, but I think that is unavoidable. There is no way that 
> the framework can determine the appropriate lifetime for a closure-based 
> callback.)

I apologize about taking so long to reply to everyone's posts, but I've been 
busy at home.

Ian, it took me a while to do some research to understand WHY what you were 
suggesting was important; you're right about storing the object as well as the 
method/function separately, but I think that WeakMethod might solve that 
completely, correct?  Are there any cases where WeakMethod wouldn't work?

Thanks,
Cem Karan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyPI, reStructuredText and readthedocs problems

2015-03-02 Thread Leonardo Giordani
Sorry, seems that GMail cannot understand I'm on a ML, and just answered
the single persons.

[Thread with INADA]
Thank you.

Seems that rst2html.py uses the header of a section as the id of the
corresponding HTML anchor.
Since I had two headers with the same title there was a name clash.
I just changed one of the headers and the problem is gone.


[Thread with Wolfgang]
On 03/02/2015 12:11 PM, Leonardo Giordani wrote:

> Thanks, spotted!
>
> Now readthedocs fails with this message
>
> Traceback (most recent call last):
>File "/home/docs/checkouts/
> readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/cmdline.py
> <
> http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/cmdline.py>",
> line 253, in main
>  warningiserror, tags, verbosity, parallel)
>File "/home/docs/checkouts/
> readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/application.py
> <
> http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/application.py>",
> line 107, in __init__
>  confoverrides or {}, self.tags)
>File "/home/docs/checkouts/
> readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/config.py
> <
> http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/config.py>",
> line 229, in __init__
>  execfile_(filename, config)
>File "/home/docs/checkouts/
> readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/util/pycompat.py
> <
> http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/util/pycompat.py>",
> line 105, in execfile_
>  exec code in _globals
>File "conf.py", line 31, in 
>  import postage
>File "/home/docs/checkouts/
> readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/__init__.py
> <
> http://readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/__init__.py>",
> line 10, in 
>  from postage import messaging
>File "/home/docs/checkouts/
> readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py
> <
> http://readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py>",
> line 4, in 
>  import pika
> ImportError: No module named pika
>
> Exception occurred:
>File "/home/docs/checkouts/
> readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py
> <
> http://readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py>",
> line 4, in 
>  import pika
> ImportError: No module named pika
> The full traceback has been saved in /tmp/sphinx-err-R4ZC2D.log, if you
> want to report the issue to the developers.
> Please also report this if it was a user error, so that a better error
> message can be provided next time.
> A bug report can be filed in the tracker at <
> https://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks!
>
> I however configured the build to use a virtualenv and specified 'pika' in
> my requirements.txt file.
>
>
Look at the complete output from readthedocs:

Setup Output



checkout
-



venv
-

Using real prefix '/usr'
New python executable in /home/docs/checkouts/
readthedocs.org/user_builds/postage/envs/latest/bin/python
Installing setuptools, pip...done.
Running virtualenv with interpreter /home/docs/bin/python


doc_builder
-

Requirement already up-to-date: sphinx==1.2.2 in
/var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
Requirement already up-to-date: virtualenv==1.10.1 in
/var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
Requirement already up-to-date: setuptools==1.1 in
/var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
Requirement already up-to-date: docutils==0.11 in
/var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
Requirement already up-to-date: mkdocs==0.11.1 in
/var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
Requirement already up-to-date: mock==1.0.1 in
/var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
Requirement already up-to-date: pillow==2.6.1 in
/var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
Requirement already up-to-date: readthedocs-sphinx-ext==0.4.4 in
/var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
Requirement already up-to-date: Jinja2>=2.7.1 in
/var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
(from mkdocs==0.11.1)
Requirement already up-to-date: Markdown>=2.3.1,<2.5 in
/var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
(from mkdocs==0.11.1)
Requirement already up-to-date: PyYAML>=3.10 in
/var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
(from mkdocs==0.11.1)
Requirement already up-to-date: watchdog>=0.7.0 in
/va

Pythonic locale

2015-03-02 Thread Albert-Jan Roskam
Hi,

The Python locale standard libraries has some oddities and (long-standing) bugs.
Example oddity: SETlocale *returns* a locale; getlocale output cannot always be 
consumed by setlocale. Example bug: resetlocale fails in Windows. What is your 
opinion about the work-around code below? 


import sys
import os
import locale as locale_

locale_.setlocale(locale_.LC_ALL, "")

class PythonicLocale(object):
 
LC_ALL = locale_.LC_ALL 
LC_CTYPE = locale_.LC_CTYPE

def __init__(self, failsafe=False):
self.failsafe = failsafe

@property
def locale(self):
"""Partial wrapper for locale in standard library"""
# LANG and LC_ALL sometimes not set
if not sys.platform.startswith("win"):
if locale_.getlocale()[0] is None and self.failsafe:
os.environ["LANG"] = "en_US"
os.environ["LC_ALL"] = "en_US.UTF-8"
# getlocale output cannot be consumed by setlocale
return locale_.setlocale(locale_.LC_ALL)

@locale.setter
def locale(self, category_and_locale_tuple):
locale_.setlocale(*category_and_locale_tuple)

@locale.deleter
def locale(self):
if sys.platform.startswith("win"):
# resetlocale() is broken in Windows
locale_.setlocale(locale_.LC_ALL, "")
else: 
locale_.resetlocale()

def getdefaultlocale(self):
return locale_.getdefaultlocale()


if __name__ == "__main__":
locale = PythonicLocale() 
# getter
print locale.locale
# setter
locale.locale = (locale.LC_ALL, "german")
print locale.locale
# deleter
del locale.locale
# check if deleter worked
print locale.locale

Thanks!

Regards,

Albert-Jan



~~

All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 

fresh water system, and public health, what have the Romans ever done for us?

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


Re: PyPI, reStructuredText and readthedocs problems

2015-03-02 Thread Leonardo Giordani
The libev problem happens on my local Ubuntu 14.10 too. It is not a pike
requirement however (not installed by 'pip install pika').
Seems that pika forces some requirements when on readthedocs through this
code

on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
requirements = list()
if on_rtd:
  requirements.append('tornado')
  requirements.append('twisted')
  requirements.append('pyev')

I contacted Gavin Roy, the pika maintainer, to check this with him.

Thanks


Leonardo Giordani
@tw_lgiordani  - lgiordani.com
My profile on About.me  - My GitHub page


2015-03-02 12:43 GMT+01:00 Leonardo Giordani :

> Sorry, seems that GMail cannot understand I'm on a ML, and just answered
> the single persons.
>
> [Thread with INADA]
> Thank you.
>
> Seems that rst2html.py uses the header of a section as the id of the
> corresponding HTML anchor.
> Since I had two headers with the same title there was a name clash.
> I just changed one of the headers and the problem is gone.
>
>
> [Thread with Wolfgang]
> On 03/02/2015 12:11 PM, Leonardo Giordani wrote:
>
>> Thanks, spotted!
>>
>> Now readthedocs fails with this message
>>
>> Traceback (most recent call last):
>>File "/home/docs/checkouts/
>> readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/cmdline.py
>> <
>> http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/cmdline.py>",
>> line 253, in main
>>  warningiserror, tags, verbosity, parallel)
>>File "/home/docs/checkouts/
>> readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/application.py
>> <
>> http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/application.py>",
>> line 107, in __init__
>>  confoverrides or {}, self.tags)
>>File "/home/docs/checkouts/
>> readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/config.py
>> <
>> http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/config.py>",
>> line 229, in __init__
>>  execfile_(filename, config)
>>File "/home/docs/checkouts/
>> readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/util/pycompat.py
>> <
>> http://readthedocs.org/user_builds/postage/envs/feature-docs/local/lib/python2.7/site-packages/sphinx/util/pycompat.py>",
>> line 105, in execfile_
>>  exec code in _globals
>>File "conf.py", line 31, in 
>>  import postage
>>File "/home/docs/checkouts/
>> readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/__init__.py
>> <
>> http://readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/__init__.py>",
>> line 10, in 
>>  from postage import messaging
>>File "/home/docs/checkouts/
>> readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py
>> <
>> http://readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py>",
>> line 4, in 
>>  import pika
>> ImportError: No module named pika
>>
>> Exception occurred:
>>File "/home/docs/checkouts/
>> readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py
>> <
>> http://readthedocs.org/user_builds/postage/checkouts/feature-docs/postage/messaging.py>",
>> line 4, in 
>>  import pika
>> ImportError: No module named pika
>> The full traceback has been saved in /tmp/sphinx-err-R4ZC2D.log, if you
>> want to report the issue to the developers.
>> Please also report this if it was a user error, so that a better error
>> message can be provided next time.
>> A bug report can be filed in the tracker at <
>> https://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks!
>>
>> I however configured the build to use a virtualenv and specified 'pika'
>> in my requirements.txt file.
>>
>>
> Look at the complete output from readthedocs:
>
> Setup Output
>
>
>
> checkout
> -
>
>
>
> venv
> -
>
> Using real prefix '/usr'
> New python executable in /home/docs/checkouts/
> readthedocs.org/user_builds/postage/envs/latest/bin/python
> Installing setuptools, pip...done.
> Running virtualenv with interpreter /home/docs/bin/python
>
>
> doc_builder
> -
>
> Requirement already up-to-date: sphinx==1.2.2 in
> /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
> Requirement already up-to-date: virtualenv==1.10.1 in
> /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
> Requirement already up-to-date: setuptools==1.1 in
> /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
> Requirement already up-to-date: docutils==0.11 in
> /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
> Requirement already up-to-date: mkdocs==0.11.1 in
> /var/build/user_builds/postage/envs/latest/lib/python2.7/site-packages
>

date

2015-03-02 Thread greymausg
I have a csv file, the first item on a line is the date in the format
2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
replying "Expecting an integer". (I am really trying to get the offset
in weeks from that date to today())



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


Re: rst and pypandoc

2015-03-02 Thread Dave Angel

On 03/02/2015 02:59 AM, alb wrote:

Hi everyone,

I'm writing a document in restructured text and I'd like to convert it
to latex for printing. To accomplish this I've used semi-successfully
pandoc and the wrapper pypandoc.


I don't see other responses yet, so I'll respond even though i don't 
know pyandoc.




My biggest issue is with figures and references to them. We've our macro
to allocate figures so I'm forced to bypass the rst directive /..
figure/, moreover I haven't happened to find how you can reference to a
figure in the rst docs.

For all the above reasons I'm writing snippets of pure latex in my rst
doc, but I'm having issues with the escape characters:

i = '\ref{fig:abc}'
print pypandoc.convert(i, 'latex', format='rst')
ef\{fig:abc\}

because of the \r that is interpreted by python as special character.


I don't know whether your problem is understanding what Python does with 
literals, or what pyandoc wants.  I can only help with the former.


You could try printing the i to see what it looks like, if you don't 
understand Python literal escaping.  Perhaps something like:


print "++" + i + "++"

Those pluses tend to help figure out what happens when you have control 
codes mixed in the line.  For example as it stands, the 0x0d character 
will have the effect of overwriting those first two "++"


A second method is to look at the string in hex:

print i.encode("hex")



If I try to escape with '\' I don't seem to find a way out...




You should be a lot more explicit with all three parts of that 
statement.  Try:



I'm trying to get a string of
 
When I try to escape with '\'
  i = '\\ref{fig:abc}'
I get the following exception:
  






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


Re: Python Worst Practices

2015-03-02 Thread Marko Rauhamaa
alister :

> or as another analogy why don't you (Marco) try telling a Barber in
> Seville that he should be speaking Latin Spanish not that strange
> variation he uses?

If the barber conference language were Latin, and some Spaniard insisted
on speaking Western Andalusian, I sure would consider that obnoxious.

Similarly, I've heard some Finnish representatives in the Nordic Council
complain how the Danish insist on speaking Danish. The official language
there is Swedish.

> I suspect the reaction you get will be far more severe than the one
> you are getting from we English (& Brits)

I don't understand your reaction. The rest of us are willing to walk a
mile (say, Finnish -> American English) and you are up in arms about
having to shift a foot (say, Scouse -> American English).


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


Re: Python27.dll could not be found

2015-03-02 Thread Dave Angel

On 03/02/2015 01:00 AM, Sarvagya Pant wrote:

I have been writing a c++ program that is supposed to call the python
function. The code is a snippet from python.org itself.
#include 
#include 
#include 

int main()
{
 Py_SetProgramName("Learning");
 Py_Initialize();
 PyRun_SimpleString("import hashlib\nprint hashlib.md5('sarvagya
pant').hexdigest()");
 Py_Finalize();
 return 0;
}


Please be more explicit about what you know and what you guess.



I have used Visual Studio 2010. I have linked the include directories and
lib files correctly. It gets correctly built.


Do you just mean that there are no errors displayed during the build?


Dependency walkerPlease be more explicit about what you know and what you guess.

 shows the

file depends upon Python27.dll.
I have looked into the folder Dlls of python. It is not there.


What is not there?  Your executable, or Python27.dll ?  And exactly what 
folder(s) are you looking?



Also I have
checked both System and System32 folder. It is not present in there too.
Python version is 2.7. How can I get Python27.dll to deploy my app for
customers? Please help.



Python27.dll does not deploy your app.  Your app loads Python27.dll.

You can search for a file in Windows by doing something like:

 dir /s c:\somefile.dll

at a cmd prompt.  Does that find whatever file you're seeking?

When I ran Windows, I had written a simple utility that searched the 
PATH for a specified file.  I called it which.bat  to match the Linux 
equivalent.



I don't run Windows very often, but on my wife's machine I see 
python27.dll in


c:\windows\syswow64

That's on a Windows7 machine running 64bit version.  Location will be 
different on various versions of Windows.


You can look to see where the system thinks the Python executable is 
located by doing


ftype .py
and seeing what it shows.  Mine shows Python.File

  Then do
assoc  Python.File

to see an actual path.


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


Re: date

2015-03-02 Thread Fabien

On 02.03.2015 12:55, greymausg wrote:

I have a csv file, the first item on a line is the date in the format
2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
replying "Expecting an integer". (I am really trying to get the offset
in weeks from that date to today())


Have you tried Pandas? http://pandas.pydata.org/

If your csv file has no other problems, the following should do the trick:

import pandas as pd
df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]})

Cheers,

Fabien




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


Re: rst and pypandoc

2015-03-02 Thread Steven D'Aprano
alb wrote:

[...]
> For all the above reasons I'm writing snippets of pure latex in my rst
> doc, but I'm having issues with the escape characters:
> 
> i = '\ref{fig:abc}'

Since \r is an escape character, that will give you carriage return followed
by "ef{fig:abc".

The solution to that is to either escape the backslash:

i = '\\ref{fig:abc}'


or use a raw string:

i = r'\\ref{fig:abc}'


Oh, by the way, "i" is normally a terrible variable name for a string. Not
only doesn't it explain what the variable is for, but there is a very
strong convention in programming circles (not just Python, but hundreds of
languages) that "i" is a generic variable name for an integer. Not a
string.



> print pypandoc.convert(i, 'latex', format='rst')
> ef\{fig:abc\}
> 
> because of the \r that is interpreted by python as special character.
> 
> If I try to escape with '\' I don't seem to find a way out...

Can you show what you are doing? Escaping the backslash with another
backslash does work:

py> for c in '\\ref':
... print(c, ord(c))
...
\ 92
r 114
e 101
f 102

so either you are doing something wrong, or the error lies elsewhere.


-- 
Steven

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


Re: Python Worst Practices

2015-03-02 Thread MRAB

On 2015-03-02 04:49, Dave Angel wrote:

On 03/01/2015 08:59 PM, MRAB wrote:

On 2015-03-02 01:37, Dennis Lee Bieber wrote


You'd be able to run it on a TI99/4 (in which the BASIC interpreter,
itself, was run on an interpreter... nothing like taking the first
"16-bit"
home computer and shackling it with an interpreted language that was
run on
an interpreted language)


The "16-bit" CPU had a 16-bit address bus (64K address space). If you
were going to switch from an 8-bit processor to a 16-bit processor, one
of the pluses you'd be looking for would the ability to directly
address more than 64K.



The 16 bit address bus permitted addressing of 64k words.  On most
processors, that was 64k bytes, though I know one Harris had no bytes,
but every memory access was 16 bits.  It therefore had the equivalent of
128k bytes.  Likewise I believe some of the DEC and DG minis had 128k
bytes of addressability.


I have (or had, not sure where it is!) a manual of the TMS9900
processor, and I'm sure it addresses 64k _bytes_.

Wikipedia says "65,536 bytes or 32,768 words".


Usually, the term 8bit processor was referring to the size of the
register(s), not the address bus.  All the 8 bit micro-processors had 16
bit address buses.  In fact, 4 bit processors generally had 12 to 16 bit
address buses as well.  So a 4 bit processor with a 16 bit address bus
could address 32k bytes, a half byte (a nybble) at a time).

The IBM PC's 8088 had an 8 bit data-bus and 20 address lines.  But they
called it a 16bit processor, to try to distinguish it from 8 bit
processors like the 8080.  Anyway, it was code compatible with the 8086,
which really did have a 16bit data bus and 20 bit address bus.



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


Re: Python Worst Practices

2015-03-02 Thread Manolo Martínez
On 03/02/15 at 08:59am, alister wrote:
 
> or as another analogy why don't you (Marco) try telling a Barber in 
> Seville that he should be speaking Latin Spanish not that strange 
> variation he uses?
> 
> I suspect the  reaction you get will be far more severe than the one you 
> are getting from we English (& Brits)
> 
In fact, you would find that most Spaniards, in an international
Spanish-speaking context, will tune down their dialectal idiosyncracies
and aim for a 'neutral Spanish' of sorts.

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


Re: rst and pypandoc

2015-03-02 Thread alb
Hi Dave,

Dave Angel  wrote:
[]
> You should be a lot more explicit with all three parts of that 
> statement.  Try:
> 
> 
> I'm trying to get a string of

\ref{fig:A.B}

but unfortunately I need to go through a conversion between rst and 
latex. This is because a simple text like this:


this is a simple list of items:

 - item A.
 - item B.



gets translated into latex by pypandoc as this:


\begin{itemize}
  \item item A.
  \item item B.
\end{itemize}


And it's much simpler to write my document with rst markup rather than latex.

So my question is what should my restructured text look like in order to 
get it through pypandoc and get the following:

\ref{fig:abc}


Apparently rst only allows the following type of references:

- external hyperlink targets
- internal hyperlink targets
- indirect hyperlink targets
- implicit hyperlink targets

and I want to get a later that has a reference to a figure, but none of 
those seem to be able to do so. Therefore I thought about passing an 
inline text in my rst in order to get it through the conversion as is, 
but apparently I'm stuck with the various escaping mechanisms.

My python script reads the text and passes it on to pypandoc:

i = "%\n" % text
o = pypandoc.convert(i, 'latex', format='rst')

So if text is:


this is some text with a reference to Figure \ref{fig:abc}


I would like o to be like:

this is some text with a reference to Figaure \ref{fig:abc}

but I get:

ef\{fig:abc\}

Al

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


Re: date

2015-03-02 Thread Steven D'Aprano
greymausg wrote:

> I have a csv file, the first item on a line is the date in the format
> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
> replying "Expecting an integer". (I am really trying to get the offset
> in weeks from that date to today())

What is "date"? Where does it come from?

If it is your own function, then we cannot help you unless you show us the
code for it.

If you mean the standard library date, then you should say so.


py> from datetime import datetime
py> today = datetime.today()
py> astring = "2014-12-27"
py> another_day = datetime.strptime(astring, "%Y-%m-%d")
py> difference = today - another_day
py> difference.days
65
py> difference.days/7  # weeks
9.285714285714286


-- 
Steven

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


Re: Python Worst Practices

2015-03-02 Thread Dave Angel

On 03/02/2015 07:38 AM, MRAB wrote:

On 2015-03-02 04:49, Dave Angel wrote:

On 03/01/2015 08:59 PM, MRAB wrote:

On 2015-03-02 01:37, Dennis Lee Bieber wrote






The 16 bit address bus permitted addressing of 64k words.  On most
processors, that was 64k bytes, though I know one Harris had no bytes,
but every memory access was 16 bits.  It therefore had the equivalent of
128k bytes.  Likewise I believe some of the DEC and DG minis had 128k
bytes of addressability.


I have (or had, not sure where it is!) a manual of the TMS9900
processor, and I'm sure it addresses 64k _bytes_.

Wikipedia says "65,536 bytes or 32,768 words".



Like I said, on most processors, it was 64k bytes.

interestingly enough I know of one architecture which used 128k for the 
8-bit Z80, even though that processor only had 16 address lines.  Being 
a server, the code was mostly static, and fit in 64k.  But they also 
wanted 64k for data.  So they used one of the processor status lines as 
a select between two banks of memory. When the processor was fetching an 
instruction, it got it from bank 0, while if it was fetching or writing 
data, it went to bank 1.  Obviously they had a mode where it read and 
wrote from bank 0 as data, both for bootstrapping, and for overlays or 
whatever.



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


Re: Md5 is different in Windows and Linux

2015-03-02 Thread Gene Heskett


On Monday 02 March 2015 01:19:46 Sarvagya Pant wrote:
> Hello, I am amazed that the  md5 of a file given by python in windows
> is different than that of linux. Consider the following code:
>
> import hashlib
> def md5_for_file(f, block_size=2**20):
> md5 = hashlib.md5()
> while True:
> data = f.read(block_size)
> if not data:
> break
> md5.update(data)
> return md5.hexdigest()
>
> f = open("somefile.txt")
> print md5_for_file(f)
>
> When I run the program I get the checksum value:
> 2f9cc8da53ee89762a34702f745d2956
>
> But on this site http://onlinemd5.com/ and on linux it has value
> E10D4E3847713472F51BC606852712F1.
>
> Why is there difference in value of Checksum computed by python in
> windows and other system.?

Line endings?

Cheers, Gene Heskett
-- 
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: rst and pypandoc

2015-03-02 Thread alb
Hi Steven,

Steven D'Aprano  wrote:
[]
> Since \r is an escape character, that will give you carriage return followed
> by "ef{fig:abc".
> 
> The solution to that is to either escape the backslash:
> 
> i = '\\ref{fig:abc}'
> 
> 
> or use a raw string:
> 
> i = r'\\ref{fig:abc}'

ok, maybe I wasn't clear from the very beginning, but searching for a 
solution is a journey that takes time and patience.

The worngly named variable i (as noted below), contains the *i*nput of 
my text which is supposed to be restructured text. The output is what 
pypandoc spits out after conversion:

i = "\\begin{tag}{%s}{%s}\n %s\n \\end{tag}" % (some, restructured, text)
o = pypandoc.convert(i, 'latex', format='rst')

Now if i contains some inline text, i.e. text I do not want to convert 
in any other format, I need my text to be formatted accordingly in order 
to inject some escape symbols in i.

Rst escapes with "\", but unfortunately python also uses "\" for escaping!

> 
> Oh, by the way, "i" is normally a terrible variable name for a string. Not
> only doesn't it explain what the variable is for, but there is a very
> strong convention in programming circles (not just Python, but hundreds of
> languages) that "i" is a generic variable name for an integer. Not a
> string.

I'm not in the position to argue about good practices, I simply found 
more appropriate to have i for input and o for output, considering they 
are used like this:

i = "some string"
o = pypandoc.convert(i, ...)
f.write(o)

with very little risk to cause misunderstanding.

> Can you show what you are doing? Escaping the backslash with another
> backslash does work:
> 
> py> for c in '\\ref':
> ... print(c, ord(c))
> ...
> \ 92
> r 114
> e 101
> f 102
> 
> so either you are doing something wrong, or the error lies elsewhere.

As said above, the string is converted by pandoc first and then printed. 
At this point the escaping becomes tricky (at least to me).

In [17]: inp = '\\ref{fig:abc}'

In [18]: print pypandoc.convert(inp, 'latex', format='rst')
ref\{fig:abc\}

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


Re: rst and pypandoc

2015-03-02 Thread Dave Angel

On 03/02/2015 08:51 AM, alb wrote:

Hi Steven,

Steven D'Aprano  wrote:
[]

Since \r is an escape character, that will give you carriage return followed
by "ef{fig:abc".

The solution to that is to either escape the backslash:

i = '\\ref{fig:abc}'


or use a raw string:

i = r'\\ref{fig:abc}'


Actually that'd be:
   i = r'\ref{fig:abc}'




ok, maybe I wasn't clear from the very beginning, but searching for a
solution is a journey that takes time and patience.

The worngly named variable i (as noted below), contains the *i*nput of
my text which is supposed to be restructured text. The output is what
pypandoc spits out after conversion:

i = "\\begin{tag}{%s}{%s}\n %s\n \\end{tag}" % (some, restructured, text)
o = pypandoc.convert(i, 'latex', format='rst')

Now if i contains some inline text, i.e. text I do not want to convert
in any other format, I need my text to be formatted accordingly in order
to inject some escape symbols in i.

Rst escapes with "\", but unfortunately python also uses "\" for escaping!


Only when the string is in a literal.  If you've read it from a file, or 
built it by combining other strings, or...  then the backslash is just 
another character to Python.






Oh, by the way, "i" is normally a terrible variable name for a string. Not
only doesn't it explain what the variable is for, but there is a very
strong convention in programming circles (not just Python, but hundreds of
languages) that "i" is a generic variable name for an integer. Not a
string.


I'm not in the position to argue about good practices, I simply found
more appropriate to have i for input and o for output, considering they
are used like this:

i = "some string"
o = pypandoc.convert(i, ...)
f.write(o)

with very little risk to cause misunderstanding.


How about "in" and "out"?  Or perhaps some name that indicates what 
semantics the string represents, like   "rst_string"  and "html_string" 
or whatever they actually are?





Can you show what you are doing? Escaping the backslash with another
backslash does work:

py> for c in '\\ref':
... print(c, ord(c))
...
\ 92
r 114
e 101
f 102

so either you are doing something wrong, or the error lies elsewhere.


As said above, the string is converted by pandoc first and then printed.
At this point the escaping becomes tricky (at least to me).

In [17]: inp = '\\ref{fig:abc}'

In [18]: print pypandoc.convert(inp, 'latex', format='rst')
ref\{fig:abc\}



What did you expect/desire the pyandoc output to be?  Now that you don't 
have the embedded 0x0a, is there something else that's wrong?


If it's in the internals of pyandoc, I'll probably be of no help.  But 
your first question was about escaping;  I'm not sure what it's about now.


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


Re: rst and pypandoc

2015-03-02 Thread MRAB

On 2015-03-02 13:51, alb wrote:

Hi Steven,

Steven D'Aprano  wrote:
[]

Since \r is an escape character, that will give you carriage return followed
by "ef{fig:abc".

The solution to that is to either escape the backslash:

i = '\\ref{fig:abc}'


or use a raw string:

i = r'\\ref{fig:abc}'


ok, maybe I wasn't clear from the very beginning, but searching for a
solution is a journey that takes time and patience.

The worngly named variable i (as noted below), contains the *i*nput of
my text which is supposed to be restructured text. The output is what
pypandoc spits out after conversion:

i = "\\begin{tag}{%s}{%s}\n %s\n \\end{tag}" % (some, restructured, text)
o = pypandoc.convert(i, 'latex', format='rst')

Now if i contains some inline text, i.e. text I do not want to convert
in any other format, I need my text to be formatted accordingly in order
to inject some escape symbols in i.

Rst escapes with "\", but unfortunately python also uses "\" for escaping!



Oh, by the way, "i" is normally a terrible variable name for a string. Not
only doesn't it explain what the variable is for, but there is a very
strong convention in programming circles (not just Python, but hundreds of
languages) that "i" is a generic variable name for an integer. Not a
string.


I'm not in the position to argue about good practices, I simply found
more appropriate to have i for input and o for output, considering they
are used like this:

i = "some string"
o = pypandoc.convert(i, ...)
f.write(o)

with very little risk to cause misunderstanding.


Can you show what you are doing? Escaping the backslash with another
backslash does work:

py> for c in '\\ref':
... print(c, ord(c))
...
\ 92
r 114
e 101
f 102

so either you are doing something wrong, or the error lies elsewhere.


As said above, the string is converted by pandoc first and then printed.
At this point the escaping becomes tricky (at least to me).

In [17]: inp = '\\ref{fig:abc}'

In [18]: print pypandoc.convert(inp, 'latex', format='rst')
ref\{fig:abc\}


Have you tried escaping the escape character by doubling the backslash?

inp = 'ref{fig:abc}'

or:

inp = r'\\ref{fig:abc}'

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


Re: date

2015-03-02 Thread Mark Lawrence

On 02/03/2015 12:25, Fabien wrote:

On 02.03.2015 12:55, greymausg wrote:

I have a csv file, the first item on a line is the date in the format
2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
replying "Expecting an integer". (I am really trying to get the offset
in weeks from that date to today())


Have you tried Pandas? http://pandas.pydata.org/

If your csv file has no other problems, the following should do the trick:

import pandas as pd
df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]})

Cheers,

Fabien



IMHO complete overkill.  Give me the Steven D'Aprano solution any day of 
the week.


--
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: rst and pypandoc

2015-03-02 Thread MRAB

On 2015-03-02 14:08, Dave Angel wrote:

On 03/02/2015 08:51 AM, alb wrote:

Hi Steven,

Steven D'Aprano  wrote:



[snip]


Oh, by the way, "i" is normally a terrible variable name for a string. Not
only doesn't it explain what the variable is for, but there is a very
strong convention in programming circles (not just Python, but hundreds of
languages) that "i" is a generic variable name for an integer. Not a
string.


I'm not in the position to argue about good practices, I simply found
more appropriate to have i for input and o for output, considering they
are used like this:

i = "some string"
o = pypandoc.convert(i, ...)
f.write(o)

with very little risk to cause misunderstanding.


How about "in" and "out"?  Or perhaps some name that indicates what
semantics the string represents, like   "rst_string"  and "html_string"
or whatever they actually are?


[snip]

"in" is a reserved word, but "in_" would be OK.

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


(Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices]

2015-03-02 Thread Steven D'Aprano
Marko Rauhamaa wrote:

> alister :
> 
>> or as another analogy why don't you (Marco) try telling a Barber in
>> Seville that he should be speaking Latin Spanish not that strange
>> variation he uses?
> 
> If the barber conference language were Latin, and some Spaniard insisted
> on speaking Western Andalusian, I sure would consider that obnoxious.
> 
> Similarly, I've heard some Finnish representatives in the Nordic Council
> complain how the Danish insist on speaking Danish. The official language
> there is Swedish.

I'm reminded of the British Prime Minister David Lloyd George, who
apparently made a habit of answering difficult or embarrassing questions in
parliament in his native Welsh.


>> I suspect the reaction you get will be far more severe than the one
>> you are getting from we English (& Brits)
> 
> I don't understand your reaction. The rest of us are willing to walk a
> mile (say, Finnish -> American English) and you are up in arms about
> having to shift a foot (say, Scouse -> American English).

"Not one inch!"

Sometimes the small differences are more important than the big. Your
Finnishness is not threatened by learning English, any more than Mark's
Britishness would be threatened by him learning Russian.

[Now there's a thought... with the historical relationships between Finland
and Russia, I wonder whether Finns would be as blasé about using a foreign
language if it were Russian rather than English? But I digress.]

Whereas the comparatively small differences between British and American
English are all the more important because they distinguish the two. Nobody
is ever going to mistake Finland and the Finish people for Americans, even
if you learn to speak American English. But for Britons to use American
English is, in a way, to cease to be Britons at all.

Personally, I think that monocultures are harmful and ought to be resisted,
whether than monoculture is one-species-of-wheat, one-operating-system, or
one-language. The English-speaking world is threatened by American cultural
and linguistic monoculture[1], and that's a bad thing. The same applies to
the rest of the world, but to a much lesser extent. Having a rich and
varied cultural ecosystem is important, and regional differences in
language and culture are an essential part in that.

Variations in idiom and spelling are a good thing. They open our minds to
new possibilities, remind us that we aren't all the same, and keep life
fresh. I remember the first time I realised that when Indians talk about "a
code" they aren't using "wrong English", they are using a regional
variation. In British and American English, "code" in the programming
sense[2] is a mass or uncountable noun, like air[3], milk, music and
housework. You cannot have "three milks", you have to add some sort of unit
to it: three litres of milk, five pieces of music, too much housework, five
*pieces of code*. But in Indian English, you can count code: *five codes*.
How wonderful! I'll probably never use it myself, but I am enriched just to
know it exists.





[1] Yes, I watch as many American movies and television shows as the next
guy. I'm allowed to take the parts of their culture I approve of and reject
the parts I don't.

[2] As opposed to the sense of secret codes and ciphers.

[3] In the sense of air that we breathe. One can still have "airs and
graces", although we rarely quantify just how many airs somebody is putting
on.



-- 
Steven

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


Re: rst and pypandoc

2015-03-02 Thread Steven D'Aprano
Dave Angel wrote:

> On 03/02/2015 08:51 AM, alb wrote:
>> Hi Steven,
>>
>> Steven D'Aprano  wrote:
>> []
>>> Since \r is an escape character, that will give you carriage return
>>> followed by "ef{fig:abc".
>>>
>>> The solution to that is to either escape the backslash:
>>>
>>> i = '\\ref{fig:abc}'
>>>
>>>
>>> or use a raw string:
>>>
>>> i = r'\\ref{fig:abc}'
> 
> Actually that'd be:
> i = r'\ref{fig:abc}'


D'oh!

I mean, you spotted my deliberate mistake to check if you were paying
attention. Well done!


> How about "in" and "out"?  Or perhaps some name that indicates what
> semantics the string represents, like   "rst_string"  and "html_string"
> or whatever they actually are?

Can't use "in", it's a keyword.




-- 
Steven

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


Re: date

2015-03-02 Thread Steven D'Aprano
Mark Lawrence wrote:

> Give me the Steven D'Aprano solution any day of
> the week.


Sounds ominous. Is that better or worse than the final solution?



-- 
Steven

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


Re: date

2015-03-02 Thread greymausg
On 2015-03-02, Fabien  wrote:
> On 02.03.2015 12:55, greymausg wrote:
>> I have a csv file, the first item on a line is the date in the format
>> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
>> replying "Expecting an integer". (I am really trying to get the offset
>> in weeks from that date to today())
>
> Have you tried Pandas? http://pandas.pydata.org/
>
> If your csv file has no other problems, the following should do the trick:
>
> import pandas as pd
> df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]})

Ta. Will try

>
> Cheers,
>
> Fabien
>
>
>
>


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


Re: date

2015-03-02 Thread greymausg
On 2015-03-02, Steven D'Aprano  wrote:
> greymausg wrote:
>
>> I have a csv file, the first item on a line is the date in the format
>> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
>> replying "Expecting an integer". (I am really trying to get the offset
>> in weeks from that date to today())
>
> What is "date"? Where does it come from?
>
> If it is your own function, then we cannot help you unless you show us the
> code for it.
>
> If you mean the standard library date, then you should say so.
>
>
> py> from datetime import datetime
> py> today = datetime.today()
> py> astring = "2014-12-27"
> py> another_day = datetime.strptime(astring, "%Y-%m-%d")
> py> difference = today - another_day
> py> difference.days
> 65
> py> difference.days/7  # weeks
> 9.285714285714286
>
>

Standard datetime.date, if it were not, I would have written.
Will try, thanks for the info.


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


Re: date

2015-03-02 Thread Tim Golden
On 02/03/2015 14:44, Steven D'Aprano wrote:
> Mark Lawrence wrote:
> 
>> Give me the Steven D'Aprano solution any day of
>> the week.
> 
> 
> Sounds ominous. Is that better or worse than the final solution?
> 
> 
> 

Well if you can have it on any day of the week it can't be *that* final?

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


Re: rst and pypandoc

2015-03-02 Thread Steven D'Aprano
alb wrote:

> Hi Steven,
> 
> Steven D'Aprano  wrote:
> []
>> Since \r is an escape character, that will give you carriage return
>> followed by "ef{fig:abc".
>> 
>> The solution to that is to either escape the backslash:
>> 
>> i = '\\ref{fig:abc}'
>> 
>> 
>> or use a raw string:
>> 
>> i = r'\\ref{fig:abc}'

Dave has corrected my typo in the above: it should be r'\ref', the whole
point of raw strings is that you don't need to escape the backslashes.



> ok, maybe I wasn't clear from the very beginning, but searching for a
> solution is a journey that takes time and patience.
> 
> The worngly named variable i (as noted below), contains the *i*nput of
> my text which is supposed to be restructured text. The output is what
> pypandoc spits out after conversion:

Ah, well that's not a bad convention for small utility functions, but I
wouldn't want single-letter names to be used in anything bigger than, say,
a dozen lines. Having i for input and o for output right next to each other
helps too. But you're still swimming against the convention that i means an
integer. Whether you decide it is worth going against that convention in
your own code is up to you, but when asking for help, it is worth your
while to be the least surprising or different as you can manage.


> i = "\\begin{tag}{%s}{%s}\n %s\n \\end{tag}" % (some, restructured, text)
> o = pypandoc.convert(i, 'latex', format='rst')
> 
> Now if i contains some inline text, i.e. text I do not want to convert
> in any other format, I need my text to be formatted accordingly in order
> to inject some escape symbols in i.
> 
> Rst escapes with "\", but unfortunately python also uses "\" for escaping!

Yes, but only in string literals. In Python source code, "\r" makes a
carriage return, but when reading from the keyboard (say, using the
raw_input function), from a file, or anything other than a string literal,
a string consisting of "\r" is just backslash-r.

So, worst case, you can always assemble your strings like this:

backslash = chr(92)
i = (backslash + "begin{tag}{%s}{%s}\n %s\n " + backslash + "end{tag}" 
% (some, restructured, text))

although that is a PITA.


I recommend using raw triple strings, and avoid needing \n escapes:

i = r"""\begin{tag}{%s}{%s}
 %s
 \end{tag}""" % (some, restructured, text)



>> Can you show what you are doing? Escaping the backslash with another
>> backslash does work:
>> 
>> py> for c in '\\ref':
>> ... print(c, ord(c))
>> ...
>> \ 92
>> r 114
>> e 101
>> f 102
>> 
>> so either you are doing something wrong, or the error lies elsewhere.
> 
> As said above, the string is converted by pandoc first and then printed.
> At this point the escaping becomes tricky (at least to me).
> 
> In [17]: inp = '\\ref{fig:abc}'

If you print inp at this point, you should see that it contains exactly what
you expect: backslash, R E F etc.


> In [18]: print pypandoc.convert(inp, 'latex', format='rst')
> ref\{fig:abc\}

and now the backslash is gone, and the braces are escaped. This suggests
that the problems lies with pypandoc. Perhaps you need to add extra
backslashes, so that pypandoc will convert a double-backslash to a single
one. Consult your pypandoc documentation, and try this:


inp = 'ref{fig:abc}'  # That's FOUR backslashes, to get \\

# or as a raw-string:

inp = '\\ref{fig:abc}'
assert inp[0] == inp[1] == chr(92)
out = pypandoc.convert(inp, 'latex', format='rst') 
print out, out == r"\ref\{fig:abc\}"


-- 
Steven

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


Re: date

2015-03-02 Thread Mark Lawrence

On 02/03/2015 14:44, Steven D'Aprano wrote:

Mark Lawrence wrote:


Give me the Steven D'Aprano solution any day of
the week.



Sounds ominous. Is that better or worse than the final solution?



As in "this program will inadvertantly self distruct in five seconds"?

--
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: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices]

2015-03-02 Thread Marko Rauhamaa
Steven D'Aprano :

> Marko Rauhamaa wrote:
>> Similarly, I've heard some Finnish representatives in the Nordic
>> Council complain how the Danish insist on speaking Danish. The
>> official language there is Swedish.
>
> I'm reminded of the British Prime Minister David Lloyd George, who
> apparently made a habit of answering difficult or embarrassing
> questions in parliament in his native Welsh.

What are the Danish embarrassed about? C++? C#? Delphi? ALGOL 60? BNF?

> But for Britons to use American English is, in a way, to cease to be
> Britons at all.

Did Hugh Laurie have to turn in his British passport?

--

But don't despair! I just ran into this (http://speakmoreclearly.com/>):

Do you want to speak English fluently and with an American accent?

-> Sick of being asked to repeat yourself?

-> Tired of people not understanding you?

-> Worried about losing your job or no one hiring you?

-> Trouble being understood on the phone?

-> Embarrassed or shy in social situations?

If you answered ‘yes’ to any of the above questions, then I have
great news for you!

You CAN change your accent and start speaking English like an
American. In less than 15 minutes a day and from the comfort of your
own home.

You just need to know the RIGHT way to practise. Our Ultimate
American Accent Training Package gives you all the exercises and
methods you need for improving your English pronunciation.


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


Re: Design thought for callbacks

2015-03-02 Thread Ian Kelly
On Mon, Mar 2, 2015 at 4:04 AM, Cem Karan  wrote:
> On Feb 26, 2015, at 2:54 PM, Ian Kelly  wrote:
>> On Feb 26, 2015 4:00 AM, "Cem Karan"  wrote:
>> >
>> >
>> > On Feb 26, 2015, at 12:36 AM, Gregory Ewing  
>> > wrote:
>> >
>> > > Cem Karan wrote:
>> > >> I think I see what you're talking about now.  Does WeakMethod
>> > >> (https://docs.python.org/3/library/weakref.html#weakref.WeakMethod) 
>> > >> solve
>> > >> this problem?
>> > >
>> > > Yes, that looks like it would work.
>> >
>> >
>> > Cool!
>>
>> Sometimes I wonder whether anybody reads my posts. I suggested a solution 
>> involving WeakMethod four days ago that additionally extends the concept to 
>> non-method callbacks (requiring a small amount of extra effort from the 
>> client in those cases, but I think that is unavoidable. There is no way that 
>> the framework can determine the appropriate lifetime for a closure-based 
>> callback.)
>
> I apologize about taking so long to reply to everyone's posts, but I've been 
> busy at home.
>
> Ian, it took me a while to do some research to understand WHY what you were 
> suggesting was important; you're right about storing the object as well as 
> the method/function separately, but I think that WeakMethod might solve that 
> completely, correct?  Are there any cases where WeakMethod wouldn't work?

WeakMethod only works for bound method objects. If you pass it a
non-method function, you'll get a TypeError:

>>> from weakref import WeakMethod
>>> WeakMethod(lambda: None)
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.4/weakref.py", line 49, in __new__
.format(type(meth))) from None
TypeError: argument should be a bound method, not 

This check uses duck typing, so you could perhaps write a method-like
class with __self__ and __func__ attributes and pass that to the
WeakMethod constructor in the case of non-methods. There's a bigger
issue with this however, which is that WeakMethod works by keeping
weak references to *both* the object and the function, meaning that as
soon as the function has no other references, the WeakMethod expires
even if the object is still alive. This isn't a problem for methods
because it's the transience of the method object, not the underlying
function, that WeakMethod seeks to work around. But it doesn't by
itself do anything to solve the problem of closures or lambdas that
may themselves be transient.

Revisiting the implementation I suggested previously, I want to make a
correction. This would be better solved with a WeakValueDictionary:

class Listenable:
def __init__(self):
self._callbacks = weakref.WeakValueDictionary()

def listen(self, callback, owner=None):
if owner is None:
if isinstance(callback, types.MethodType):
owner = weakref.WeakMethod(callback)
else:
owner = callback
# TODO: Should anything happen if the callback is already in the dict?
self._callbacks[callback] = owner

def do_callbacks(self, message):
for callback in self._callbacks.keys():
callback(message)

This approach has two benefits over the previous one: it simplifies
the callback management a bit, and it avoids making the assumption
that the owner is hashable (it assumes instead that the callback is
hashable, but I think that's reasonable).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Worst Practices

2015-03-02 Thread alister
On Mon, 02 Mar 2015 14:19:45 +0200, Marko Rauhamaa wrote:

> alister :
> 
>> or as another analogy why don't you (Marco) try telling a Barber in
>> Seville that he should be speaking Latin Spanish not that strange
>> variation he uses?
> 
> If the barber conference language were Latin, and some Spaniard insisted
> on speaking Western Andalusian, I sure would consider that obnoxious.
> 
> Similarly, I've heard some Finnish representatives in the Nordic Council
> complain how the Danish insist on speaking Danish. The official language
> there is Swedish.
> 
>> I suspect the reaction you get will be far more severe than the one you
>> are getting from we English (& Brits)
> 
> I don't understand your reaction. The rest of us are willing to walk a
> mile (say, Finnish -> American English) and you are up in arms about
> having to shift a foot (say, Scouse -> American English).
> 
> 
> Marko

Because the language is English not American.
the Standard for English is by very definition UK English
English is spoken badly enough as it is without deliberately speaking it 
worse!


As I said earlier tell a Spaniard they need to learn Latin Spanish 
because traditional Spanish is not standard & see how far you get.
if they are laid back about it try the same thing with he French


-- 
Detroit is Cleveland without the glitter.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Worst Practices

2015-03-02 Thread Mark Lawrence

On 02/03/2015 15:32, alister wrote:

On Mon, 02 Mar 2015 14:19:45 +0200, Marko Rauhamaa wrote:


alister :


or as another analogy why don't you (Marco) try telling a Barber in
Seville that he should be speaking Latin Spanish not that strange
variation he uses?


If the barber conference language were Latin, and some Spaniard insisted
on speaking Western Andalusian, I sure would consider that obnoxious.

Similarly, I've heard some Finnish representatives in the Nordic Council
complain how the Danish insist on speaking Danish. The official language
there is Swedish.


I suspect the reaction you get will be far more severe than the one you
are getting from we English (& Brits)


I don't understand your reaction. The rest of us are willing to walk a
mile (say, Finnish -> American English) and you are up in arms about
having to shift a foot (say, Scouse -> American English).


Marko


Because the language is English not American.
the Standard for English is by very definition UK English
English is spoken badly enough as it is without deliberately speaking it
worse!


As I said earlier tell a Spaniard they need to learn Latin Spanish
because traditional Spanish is not standard & see how far you get.
if they are laid back about it try the same thing with he French




This http://en.wikipedia.org/wiki/Canarian_Spanish is interesting.

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

2015-03-02 Thread Fabien

On 02.03.2015 15:26, Mark Lawrence wrote:


Have you tried Pandas? http://pandas.pydata.org/

If your csv file has no other problems, the following should do the
trick:

import pandas as pd
df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]})

Cheers,

Fabien



IMHO complete overkill.  Give me the Steven D'Aprano solution any day of
the week.


Without knowing anything about the OP background, I still hope my 
suggestion is a good one. Pandas is one of the best thing that happened 
to me in my python life, I'm happy to at least suggest it. But yeah, if 
you just want to read the csv and do no data crunching on it, pandas is 
"overkill".


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


Re: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices]

2015-03-02 Thread Chris Angelico
On Tue, Mar 3, 2015 at 1:39 AM, Steven D'Aprano
 wrote:
> Whereas the comparatively small differences between British and American
> English are all the more important because they distinguish the two. Nobody
> is ever going to mistake Finland and the Finish people for Americans, even
> if you learn to speak American English. But for Britons to use American
> English is, in a way, to cease to be Britons at all.

Which, I suspect, is part of why the pound is still alive and well,
and hasn't been replaced with the euro. Maybe some other countries
don't mind becoming the United States of Europe, but the British
resist the encroachment, and rightly so.

> ... a mass or uncountable noun, like air[3], milk, music and
> housework. You cannot have "three milks", you have to add some sort of unit
> to it: three litres of milk...

And yet, oddly enough, you wouldn't bat an eyelid if someone asks for
"two sugars" in his tea. Or his hot chocolate... mmm, time for me to
go make myself one, I think. Two sugars, a splosh of milk, caramel hot
chocolate powder, and butter. Not "one butter", because that concept
doesn't exist, but very definitely "two sugars", because the sugar
comes in discrete units.

(Not "discreet units", mind, although I do trust my sugar not to blab
about the sorts of drinks I put it in.)

> [1] Yes, I watch as many American movies and television shows as the next
> guy. I'm allowed to take the parts of their culture I approve of and reject
> the parts I don't.

Part of resisting monoculture is accepting other people's cultures,
not just sticking with your own. Embracing that difference. So go
ahead: Watch "McHale's Navy" and "Yes Minister", and appreciate the
comedy of both - decide for yourself which one you find more to your
liking, but know that they both exist, and they represent different
styles.

(Aside: Even in an American TV show like Once Upon A Time, it's
possible for non-American accents to be welcomed. Belle is played by
an Aussie, and her distinctive accent is commented on in-universe.
Somehow, she picked up an accent that's completely different from her
father's and her mother's, but is its own particular style and speech.
Maybe she learned the accent from one of her books.)

We embrace Unicode in Python 3 because it allows us to welcome
Russian, Icelandic, Arabic, and Chinese programmers and allow them to
write variable names in their own languages, using their own scripts
(or, in the case of Icelandic, a script very similar to ours but with
a few additional letters). We should equally embrace American and
British English - and Indian English, and Australian English, and any
other variant that people want to code in. You want to write your code
in North-East Scots? Sure. You want to write your code in Gaelic? No
problem (though personally, I prefer garlic to Gaelic). You want to
use "colour" instead of "color"? Also not a problem, and should be
easy enough for someone to understand who normally spells it the other
way.

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


Re: date

2015-03-02 Thread Chris Angelico
On Tue, Mar 3, 2015 at 2:24 AM, Mark Lawrence  wrote:
> On 02/03/2015 14:44, Steven D'Aprano wrote:
>>
>> Mark Lawrence wrote:
>>
>>> Give me the Steven D'Aprano solution any day of
>>> the week.
>>
>>
>>
>> Sounds ominous. Is that better or worse than the final solution?
>>
>
> As in "this program will inadvertantly self distruct in five seconds"?

It's usually implied as being externally enforced, so I'd say it's
more akin to my solution to all manner of Windows problems.

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


Re: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices]

2015-03-02 Thread Joel Goldstick
I like "Old Tricks". I learn lots of British english idioms.  I'm from NYC

On Mon, Mar 2, 2015 at 10:45 AM, Chris Angelico  wrote:
> On Tue, Mar 3, 2015 at 1:39 AM, Steven D'Aprano
>  wrote:
>> Whereas the comparatively small differences between British and American
>> English are all the more important because they distinguish the two. Nobody
>> is ever going to mistake Finland and the Finish people for Americans, even
>> if you learn to speak American English. But for Britons to use American
>> English is, in a way, to cease to be Britons at all.
>
> Which, I suspect, is part of why the pound is still alive and well,
> and hasn't been replaced with the euro. Maybe some other countries
> don't mind becoming the United States of Europe, but the British
> resist the encroachment, and rightly so.
>
>> ... a mass or uncountable noun, like air[3], milk, music and
>> housework. You cannot have "three milks", you have to add some sort of unit
>> to it: three litres of milk...
>
> And yet, oddly enough, you wouldn't bat an eyelid if someone asks for
> "two sugars" in his tea. Or his hot chocolate... mmm, time for me to
> go make myself one, I think. Two sugars, a splosh of milk, caramel hot
> chocolate powder, and butter. Not "one butter", because that concept
> doesn't exist, but very definitely "two sugars", because the sugar
> comes in discrete units.
>
> (Not "discreet units", mind, although I do trust my sugar not to blab
> about the sorts of drinks I put it in.)
>
>> [1] Yes, I watch as many American movies and television shows as the next
>> guy. I'm allowed to take the parts of their culture I approve of and reject
>> the parts I don't.
>
> Part of resisting monoculture is accepting other people's cultures,
> not just sticking with your own. Embracing that difference. So go
> ahead: Watch "McHale's Navy" and "Yes Minister", and appreciate the
> comedy of both - decide for yourself which one you find more to your
> liking, but know that they both exist, and they represent different
> styles.
>
> (Aside: Even in an American TV show like Once Upon A Time, it's
> possible for non-American accents to be welcomed. Belle is played by
> an Aussie, and her distinctive accent is commented on in-universe.
> Somehow, she picked up an accent that's completely different from her
> father's and her mother's, but is its own particular style and speech.
> Maybe she learned the accent from one of her books.)
>
> We embrace Unicode in Python 3 because it allows us to welcome
> Russian, Icelandic, Arabic, and Chinese programmers and allow them to
> write variable names in their own languages, using their own scripts
> (or, in the case of Icelandic, a script very similar to ours but with
> a few additional letters). We should equally embrace American and
> British English - and Indian English, and Australian English, and any
> other variant that people want to code in. You want to write your code
> in North-East Scots? Sure. You want to write your code in Gaelic? No
> problem (though personally, I prefer garlic to Gaelic). You want to
> use "colour" instead of "color"? Also not a problem, and should be
> easy enough for someone to understand who normally spells it the other
> way.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list



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


Re: date

2015-03-02 Thread alister
On Tue, 03 Mar 2015 02:51:28 +1100, Chris Angelico wrote:

> On Tue, Mar 3, 2015 at 2:24 AM, Mark Lawrence 
> wrote:
>> On 02/03/2015 14:44, Steven D'Aprano wrote:
>>>
>>> Mark Lawrence wrote:
>>>
 Give me the Steven D'Aprano solution any day of the week.
>>>
>>>
>>>
>>> Sounds ominous. Is that better or worse than the final solution?
>>>
>>>
>> As in "this program will inadvertantly self distruct in five seconds"?
> 
> It's usually implied as being externally enforced, so I'd say it's more
> akin to my solution to all manner of Windows problems.
> 
> ChrisA

Is that the same as my solution to windows related problems?

(Dad bought a new laptop on Sat it was sterilised (As in disinfected ) 
immediately & has never run Windowz - lucky thing).




-- 
Loose bits sink chips.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: suggestions for functional style (singleton pattern?)

2015-03-02 Thread Michael Torrie
On 03/02/2015 03:19 AM, Fabien wrote:
> On 01.03.2015 06:05, Michael Torrie wrote:
>>   A module*is*  a singleton pattern, particularly one
>> that maintains state.  I use sometimes use this feature for sharing
>> config and other data between other modules (global state when it's
>> required).
> 
> I do this too, after some helping recommendations I got from this 
> discussion group. I find it neat to use a module for sharing config 
> states, but I always wondered: does this pattern fall into the "globals 
> are devil" category?

In traditional languages, globals were considered evil in part because
of the ambiguity they raised (a problem of scope, really).  In a
function if you see a reference to a variable, and if globals were used,
you then have confusion over whether the variable is local or global
(could be both if one covers the other).  And globals could be set from
anywhere.  Debugging and logical patterns become a lot harder with this
ambiguity and errors are introduced.

Modules don't have the same problems when used as a store for globals
for several reasons.  First, because they have a namespace associated
with them.  You can tell at a glance which name in your function is a
reference to this "global" module.  Now if you did do a "from module
import *" then you can't tell as easily what is coming from the module
and what is locally defined.  But the cool thing here is if you rebind a
variable imported from a module in your local namespace, it actually
doesn't change the "global" variable (attribute).  Instead it just
rebinds your local name.  So if you want to change an attribute in the
module, you have to refer to it via the module.attribute path.

Secondly, one should rarely write to a module's namespace from outside
that module (though you can).  Instead treat the module in an OOP
fashion, and write business methods to alter the module's state in a
specific way.  This encapsulation protects and insulates the module's
users from implementation details that could change from time to time.
Now I don't know of any way of implementing class-style properties on a
module as you can do in a class, but if that were needed you would write
a standard class and instantiate a singleton inside the module itself
perhaps.

As with all broad statements, saying globals are evil is simply not
always true.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Worst Practices

2015-03-02 Thread Travis Griggs

> On Mar 1, 2015, at 5:53 PM, Dennis Lee Bieber  wrote:
> 
> On Sun, 1 Mar 2015 20:16:26 + (UTC), alister
>  declaimed the following:
> 
>> 
>> The language is called English, the clue is in the name. interestingly 
>> most 'Brits' can switch between American English & English without too 
>> much trouble (I still have a problem with Chips) 
>> 
>   Okay... Is that a reference to (US) Fries, or US usage reference to
> (UK) Crisps.
> 
>   Might as well add the confusion of biscuit <> cookie (my biscuits look
> like your scones)... And lets not bring up the subject of suspenders...
> Bonnets, boots, and lifts.
> 
>   A pub's a bar; a bar's a gate; a gate's a street

Reminds me of Richard Lederer’s writings. 

http://www.etni.org.il/farside/crazyenglish.htm

Whether or not Brits should sprinkle the letter ‘u’ around for some extra 
spice, seems like the very smallest of our worries.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: date

2015-03-02 Thread Chris Angelico
On Tue, Mar 3, 2015 at 3:09 AM, alister
 wrote:
 Sounds ominous. Is that better or worse than the final solution?


>>> As in "this program will inadvertantly self distruct in five seconds"?
>>
>> It's usually implied as being externally enforced, so I'd say it's more
>> akin to my solution to all manner of Windows problems.
>>
>> ChrisA
>
> Is that the same as my solution to windows related problems?
>
> (Dad bought a new laptop on Sat it was sterilised (As in disinfected )
> immediately & has never run Windowz - lucky thing).

Yes. What Steven is referencing is:

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

And is unrelated to this:

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

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


Re: date

2015-03-02 Thread Mark Lawrence

On 02/03/2015 15:51, Chris Angelico wrote:

On Tue, Mar 3, 2015 at 2:24 AM, Mark Lawrence  wrote:

On 02/03/2015 14:44, Steven D'Aprano wrote:


Mark Lawrence wrote:


Give me the Steven D'Aprano solution any day of
the week.




Sounds ominous. Is that better or worse than the final solution?



As in "this program will inadvertantly self distruct in five seconds"?


It's usually implied as being externally enforced, so I'd say it's
more akin to my solution to all manner of Windows problems.

ChrisA



Heard the joke about the three engineers in the car that breaks down?

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

2015-03-02 Thread Mark Lawrence

On 02/03/2015 15:42, Fabien wrote:

On 02.03.2015 15:26, Mark Lawrence wrote:


Have you tried Pandas? http://pandas.pydata.org/

If your csv file has no other problems, the following should do the
trick:

import pandas as pd
df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]})

Cheers,

Fabien



IMHO complete overkill.  Give me the Steven D'Aprano solution any day of
the week.


Without knowing anything about the OP background, I still hope my
suggestion is a good one. Pandas is one of the best thing that happened
to me in my python life, I'm happy to at least suggest it. But yeah, if
you just want to read the csv and do no data crunching on it, pandas is
"overkill".

Fabien


I've used pandas myself and I'll admit to being very impressed.  However 
the OP originally said 'I have a csv file, the first item on a line is 
the date in the format 2015-03-02 I try to get that as a date by 
date(row[0]), but it barfs, replying "Expecting an integer".'  Without 
finding out exactly what the OP is trying to achieve, telling them to 
download a package such as pandas just to convert a string to a date is 
overkill when there's a solution in the stdlib.


--
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: suggestions for functional style (singleton pattern?)

2015-03-02 Thread Ian Kelly
On Mon, Mar 2, 2015 at 8:59 AM, Michael Torrie  wrote:
> Now I don't know of any way of implementing class-style properties on a
> module as you can do in a class, but if that were needed you would write
> a standard class and instantiate a singleton inside the module itself
> perhaps.

This works, although I'm not sure that I would do it in real code.

>>> class PropertyModule(types.ModuleType):
... @property
... def parrot(self):
... return "Norwegian Blue"
...
>>> sys.modules['parrot_sketch'] = PropertyModule('parrot_sketch')
>>> import parrot_sketch
>>> parrot_sketch.parrot
'Norwegian Blue'

Note that if the user does "from parrot_sketch import parrot", then
the property is evaluated at import time and any changes won't be
reflected in the local binding, which might cause some surprises.

Also, this isn't really a singleton any longer since the user might
just create another instance of the class, but you can hide the class
and present just the module as the API.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Worst Practices

2015-03-02 Thread alister
On Mon, 02 Mar 2015 08:25:40 -0800, Travis Griggs wrote:

> seems like the very smallest of our worries.

"There is no egg in eggplant"

What the blood heck is eggplant?

oh wait you mean aubergine

this page is clearly about American English. 
We are even more obtuse, it stops Johnnie Foreigner knowing what we are 
up to - seems to be far more effective than Enigma :-)

IIRC the Americans managed something similar with the Navaho.




-- 
Falling in love is a lot like dying.  You never get to do it enough to
become good at it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Worst Practices

2015-03-02 Thread Jon Ribbens
On 2015-03-02, Dennis Lee Bieber  wrote:
>   A pub's a bar; a bar's a gate; a gate's a street

If each of those is supposed to be English first and then the American
equivalent second, then I'm afraid the first one is misleading and the
other two are just nonsense.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: date

2015-03-02 Thread greymausg
On 2015-03-02, greymausg  wrote:
> On 2015-03-02, Steven D'Aprano  wrote:
>> greymausg wrote:
>>
>>> I have a csv file, the first item on a line is the date in the format
>>> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
>>> replying "Expecting an integer". (I am really trying to get the offset
>>> in weeks from that date to today())
>>
>> What is "date"? Where does it come from?
>>
>> If it is your own function, then we cannot help you unless you show us the
>> code for it.
>>
>> If you mean the standard library date, then you should say so.
>>
>>
>> py> from datetime import datetime
>> py> today = datetime.today()
>> py> astring = "2014-12-27"
>> py> another_day = datetime.strptime(astring, "%Y-%m-%d")
>> py> difference = today - another_day
>> py> difference.days
>> 65
>> py> difference.days/7  # weeks
>> 9.285714285714286
>>
>>
>
> Standard datetime.date, if it were not, I would have written.
> Will try, thanks for the info.
>
>

Thanks to all, the strptime did the trick, after I realized
that I was comparing a 2digit year to a 4digit.


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


Sort list of dictionaries

2015-03-02 Thread Charles Heizer
Hello,
I'm new to python and I'm trying to find the right way to solve this issue I 
have.

I'm trying to sort this list by name and then by version numbers. The problem 
I'm having is that I can not get the version numbers sorted with the highest at 
the top or sorted properly. 

mylist = [{'name': u'com.google.earth', 'version': u'7.1.2.2041'},
{'name': u'com.google.earth', 'version': u'7.1.2.2019'},
{'name': u'com.google.Chrome', 'version': u'40.0.2214.93'},
{'name': u'com.google.Chrome', 'version': u'40.0.2214.91'},
{'name': u'com.google.Chrome', 'version': u'40.0.2214.111'},
{'name': u'com.google.Chrome', 'version': u'39.0.2171.99'},
{'name': u'com.google.Chrome', 'version': u'39.0.2171.95'},
{'name': u'com.google.Chrome', 'version': u'39.0.2171.71'},
{'name': u'com.google.Chrome', 'version': u'38.0.2125.122'},
{'name': u'com.google.Chrome', 'version': u'38.0.2125.111'},
{'name': u'com.google.Chrome', 'version': u'38.0.2125.104'},
{'name': u'com.google.Chrome', 'version': u'38.0.2125.101'},
{'name': u'com.google.Chrome', 'version': u'37.0.2062.94'},
{'name': u'com.google.Chrome', 'version': u'37.0.2062.120'},
{'name': u'com.google.Chrome', 'version': u'36.0.1985.143'},
{'name': u'com.google.Chrome', 'version': u'36.0.1985.125'},
{'name': u'com.google.Chrome', 'version': u'35.0.1916.153'},
{'name': u'com.google.Chrome', 'version': u'35.0.1916.114'},
{'name': u'com.google.Chrome', 'version': u'34.0.1847.137'},
{'name': u'com.google.Chrome', 'version': u'34.0.1847.131'},
{'name': u'com.google.Chrome', 'version': u'34.0.1847.116'},
{'name': u'com.google.Chrome', 'version': u'33.0.1750.152'},
{'name': u'com.google.Chrome', 'version': u'33.0.1750.149'},
{'name': u'com.google.Chrome', 'version': u'33.0.1750.146'},
{'name': u'com.google.Chrome', 'version': u'32.0.1700.107'},
{'name': u'com.google.Chrome', 'version': u'31.0.1650.63'},
{'name': u'com.google.Chrome', 'version': u'31.0.1650.57'}]

sortedlist = sorted(mylist , key=lambda x, y: x['name'] 
LooseVersion(elem['version'])), reverse=True)

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


Re: Sort list of dictionaries

2015-03-02 Thread Emile van Sebille

On 3/2/2015 10:17 AM, Charles Heizer wrote:

Hello,
I'm new to python and I'm trying to find the right way to solve this issue I 
have.

I'm trying to sort this list by name and then by version numbers. The problem 
I'm having is that I can not get the version numbers sorted with the highest at 
the top or sorted properly.

mylist = [{'name': u'com.google.earth', 'version': u'7.1.2.2041'},
{'name': u'com.google.earth', 'version': u'7.1.2.2019'},
{'name': u'com.google.Chrome', 'version': u'40.0.2214.93'},
{'name': u'com.google.Chrome', 'version': u'40.0.2214.91'},
{'name': u'com.google.Chrome', 'version': u'40.0.2214.111'},
{'name': u'com.google.Chrome', 'version': u'39.0.2171.99'},
{'name': u'com.google.Chrome', 'version': u'39.0.2171.95'},
{'name': u'com.google.Chrome', 'version': u'39.0.2171.71'},
{'name': u'com.google.Chrome', 'version': u'38.0.2125.122'},
{'name': u'com.google.Chrome', 'version': u'38.0.2125.111'},
{'name': u'com.google.Chrome', 'version': u'38.0.2125.104'},
{'name': u'com.google.Chrome', 'version': u'38.0.2125.101'},
{'name': u'com.google.Chrome', 'version': u'37.0.2062.94'},
{'name': u'com.google.Chrome', 'version': u'37.0.2062.120'},
{'name': u'com.google.Chrome', 'version': u'36.0.1985.143'},
{'name': u'com.google.Chrome', 'version': u'36.0.1985.125'},
{'name': u'com.google.Chrome', 'version': u'35.0.1916.153'},
{'name': u'com.google.Chrome', 'version': u'35.0.1916.114'},
{'name': u'com.google.Chrome', 'version': u'34.0.1847.137'},
{'name': u'com.google.Chrome', 'version': u'34.0.1847.131'},
{'name': u'com.google.Chrome', 'version': u'34.0.1847.116'},
{'name': u'com.google.Chrome', 'version': u'33.0.1750.152'},
{'name': u'com.google.Chrome', 'version': u'33.0.1750.149'},
{'name': u'com.google.Chrome', 'version': u'33.0.1750.146'},
{'name': u'com.google.Chrome', 'version': u'32.0.1700.107'},
{'name': u'com.google.Chrome', 'version': u'31.0.1650.63'},
{'name': u'com.google.Chrome', 'version': u'31.0.1650.57'}]

sortedlist = sorted(mylist , key=lambda x, y: x['name'] 
LooseVersion(elem['version'])), reverse=True)


You'll need to fix LooseVersion or elem or both -- or show them so we 
can help.


Emile





Thanks,
Charlie




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


Re: Sort list of dictionaries

2015-03-02 Thread Charles Heizer
Sorry,

sortedlist = sorted(mylist , key=lambda elem: "%s %s" % (elem['name'], 
LooseVersion(elem['version'])), reverse=True)

This is what I was trying but LooseVersion() was not sorting version numbers 
like I thought it would. You will notice that Chrome version "40.0.2214.111" is 
higher than "40.0.2214.91" but in the end result it's not sorting it that way.

Thanks,
Charlie

On Monday, March 2, 2015 at 10:32:40 AM UTC-8, Emile van Sebille wrote:
> On 3/2/2015 10:17 AM, Charles Heizer wrote:
> > Hello,
> > I'm new to python and I'm trying to find the right way to solve this issue 
> > I have.
> >
> > I'm trying to sort this list by name and then by version numbers. The 
> > problem I'm having is that I can not get the version numbers sorted with 
> > the highest at the top or sorted properly.
> >
> > mylist = [{'name': u'com.google.earth', 'version': u'7.1.2.2041'},
> > {'name': u'com.google.earth', 'version': u'7.1.2.2019'},
> > {'name': u'com.google.Chrome', 'version': u'40.0.2214.93'},
> > {'name': u'com.google.Chrome', 'version': u'40.0.2214.91'},
> > {'name': u'com.google.Chrome', 'version': u'40.0.2214.111'},
> > {'name': u'com.google.Chrome', 'version': u'39.0.2171.99'},
> > {'name': u'com.google.Chrome', 'version': u'39.0.2171.95'},
> > {'name': u'com.google.Chrome', 'version': u'39.0.2171.71'},
> > {'name': u'com.google.Chrome', 'version': u'38.0.2125.122'},
> > {'name': u'com.google.Chrome', 'version': u'38.0.2125.111'},
> > {'name': u'com.google.Chrome', 'version': u'38.0.2125.104'},
> > {'name': u'com.google.Chrome', 'version': u'38.0.2125.101'},
> > {'name': u'com.google.Chrome', 'version': u'37.0.2062.94'},
> > {'name': u'com.google.Chrome', 'version': u'37.0.2062.120'},
> > {'name': u'com.google.Chrome', 'version': u'36.0.1985.143'},
> > {'name': u'com.google.Chrome', 'version': u'36.0.1985.125'},
> > {'name': u'com.google.Chrome', 'version': u'35.0.1916.153'},
> > {'name': u'com.google.Chrome', 'version': u'35.0.1916.114'},
> > {'name': u'com.google.Chrome', 'version': u'34.0.1847.137'},
> > {'name': u'com.google.Chrome', 'version': u'34.0.1847.131'},
> > {'name': u'com.google.Chrome', 'version': u'34.0.1847.116'},
> > {'name': u'com.google.Chrome', 'version': u'33.0.1750.152'},
> > {'name': u'com.google.Chrome', 'version': u'33.0.1750.149'},
> > {'name': u'com.google.Chrome', 'version': u'33.0.1750.146'},
> > {'name': u'com.google.Chrome', 'version': u'32.0.1700.107'},
> > {'name': u'com.google.Chrome', 'version': u'31.0.1650.63'},
> > {'name': u'com.google.Chrome', 'version': u'31.0.1650.57'}]
> >
> > sortedlist = sorted(mylist , key=lambda x, y: x['name'] 
> > LooseVersion(elem['version'])), reverse=True)
> 
> You'll need to fix LooseVersion or elem or both -- or show them so we 
> can help.
> 
> Emile
> 
> 
> 
> >
> > Thanks,
> > Charlie
> >
-- 
https://mail.python.org/mailman/listinfo/python-list


Direct Client Requirement for Data Application Engineer (Hadoop) - Sunnyvale CA

2015-03-02 Thread tiya . akrid
Hi
 
Please let me know if you have anyone available for below position
 
Position - Data Application Engineer
Location: Sunnyvale, CA (local candidates ONLY)
Interview Process - Onsite
Duration - 6 months + contract
 
The Marketing Science team is looking for a Software Data Application Developer 
with experience in working on Data platforms.
 
Responsibilities: 
* Write data-driven, automation scripts for scraping, parsing through complex 
data.
* Must have programming experience in Java, C++, Perl or Python 
* Strong understanding of database concepts 
* Maintain and create new automated test cases using Python/Perl/Shell 
* Must be an expert in SQL
* Ability to come up with test scenarios and write test plans and test cases 
 
Qualifications:
* Four or more years of development or test development experience in BI/DW
* Strong understanding of Datawarehouse, Big Data and BI Analytics concepts
* Demonstrated experience implementing automation frameworks using scripting 
languages/tools like Shell, Java, Python etc.
* Hands-on experience with Hadoop and tools such as Hive, Sqoop, Pig, Impala 
and Spark is preferred
* Experience using data driven tests to validate 3rd party API calls
 
Please send word format resume along with below details for further process
Hadoop ___years of experience
Datawarehouse ___years of experience
BI Analytics ___years of experience
Scripting tools (shell / Java / Python) ___years of experience
3rd party API Calls ___years of experience
Any experience with Hive / Sqoop / Pig / Impala/ Spark?
Rates on c2c
Availability
Current Location
 
Thanks
 
Tiya
Akrid Software Inc
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sort list of dictionaries

2015-03-02 Thread Ian Kelly
On Mon, Mar 2, 2015 at 11:38 AM, Charles Heizer  wrote:
> Sorry,
>
> sortedlist = sorted(mylist , key=lambda elem: "%s %s" % (elem['name'], 
> LooseVersion(elem['version'])), reverse=True)
>
> This is what I was trying but LooseVersion() was not sorting version numbers 
> like I thought it would. You will notice that Chrome version "40.0.2214.111" 
> is higher than "40.0.2214.91" but in the end result it's not sorting it that 
> way.

Because it's a string they're sorted lexicographically, and in that
ordering "40.0.2214.111" is less than "40.0.2214.91". Instead of a
string you should probably use some sort of version info tuple. A
simple tuple of ints may suffice, although you may need to get a
little cleverer if there are ever any version strings that aren't
entirely dotted numeric.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: rst and pypandoc

2015-03-02 Thread Dave Angel

On 03/02/2015 09:43 AM, Steven D'Aprano wrote:

Dave Angel wrote:


On 03/02/2015 08:51 AM, alb wrote:

Hi Steven,

Steven D'Aprano  wrote:




or use a raw string:

i = r'\\ref{fig:abc}'


Actually that'd be:
 i = r'\ref{fig:abc}'



D'oh!

I mean, you spotted my deliberate mistake to check if you were paying
attention. Well done!



How about "in" and "out"?  Or perhaps some name that indicates what
semantics the string represents, like   "rst_string"  and "html_string"
or whatever they actually are?


Can't use "in", it's a keyword.



And D'oh right back at ya.  Ironic isn't it that I make a second mistake 
in the same message I correct yours?



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


Re: Sort list of dictionaries

2015-03-02 Thread Dave Angel

On 03/02/2015 01:38 PM, Charles Heizer wrote:

Sorry,

sortedlist = sorted(mylist , key=lambda elem: "%s %s" % (elem['name'], 
LooseVersion(elem['version'])), reverse=True)

This is what I was trying but LooseVersion() was not sorting version numbers like I thought it 
would. You will notice that Chrome version "40.0.2214.111" is higher than 
"40.0.2214.91" but in the end result it's not sorting it that way.



Please don't top-post.  put your remarks after whatever quoting you do.

You still haven't posted your LooseVersion() function source.  I agree 
with Emile that it's likely to be the problem.



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


Re: Sort list of dictionaries

2015-03-02 Thread Charles Heizer
Never mind, the light bulb finally went off. :-\

sortedlist = sorted(mylist , key=lambda elem: "%s %s" % ( elem['name'], 
(".".join([i.zfill(5) for i in elem['version'].split(".")])) ), reverse=True)

On Monday, March 2, 2015 at 10:40:30 AM UTC-8, Charles Heizer wrote:
> Sorry,
> 
> sortedlist = sorted(mylist , key=lambda elem: "%s %s" % (elem['name'], 
> LooseVersion(elem['version'])), reverse=True)
> 
> This is what I was trying but LooseVersion() was not sorting version numbers 
> like I thought it would. You will notice that Chrome version "40.0.2214.111" 
> is higher than "40.0.2214.91" but in the end result it's not sorting it that 
> way.
> 
> Thanks,
> Charlie
> 
> On Monday, March 2, 2015 at 10:32:40 AM UTC-8, Emile van Sebille wrote:
> > On 3/2/2015 10:17 AM, Charles Heizer wrote:
> > > Hello,
> > > I'm new to python and I'm trying to find the right way to solve this 
> > > issue I have.
> > >
> > > I'm trying to sort this list by name and then by version numbers. The 
> > > problem I'm having is that I can not get the version numbers sorted with 
> > > the highest at the top or sorted properly.
> > >
> > > mylist = [{'name': u'com.google.earth', 'version': u'7.1.2.2041'},
> > > {'name': u'com.google.earth', 'version': u'7.1.2.2019'},
> > > {'name': u'com.google.Chrome', 'version': u'40.0.2214.93'},
> > > {'name': u'com.google.Chrome', 'version': u'40.0.2214.91'},
> > > {'name': u'com.google.Chrome', 'version': u'40.0.2214.111'},
> > > {'name': u'com.google.Chrome', 'version': u'39.0.2171.99'},
> > > {'name': u'com.google.Chrome', 'version': u'39.0.2171.95'},
> > > {'name': u'com.google.Chrome', 'version': u'39.0.2171.71'},
> > > {'name': u'com.google.Chrome', 'version': u'38.0.2125.122'},
> > > {'name': u'com.google.Chrome', 'version': u'38.0.2125.111'},
> > > {'name': u'com.google.Chrome', 'version': u'38.0.2125.104'},
> > > {'name': u'com.google.Chrome', 'version': u'38.0.2125.101'},
> > > {'name': u'com.google.Chrome', 'version': u'37.0.2062.94'},
> > > {'name': u'com.google.Chrome', 'version': u'37.0.2062.120'},
> > > {'name': u'com.google.Chrome', 'version': u'36.0.1985.143'},
> > > {'name': u'com.google.Chrome', 'version': u'36.0.1985.125'},
> > > {'name': u'com.google.Chrome', 'version': u'35.0.1916.153'},
> > > {'name': u'com.google.Chrome', 'version': u'35.0.1916.114'},
> > > {'name': u'com.google.Chrome', 'version': u'34.0.1847.137'},
> > > {'name': u'com.google.Chrome', 'version': u'34.0.1847.131'},
> > > {'name': u'com.google.Chrome', 'version': u'34.0.1847.116'},
> > > {'name': u'com.google.Chrome', 'version': u'33.0.1750.152'},
> > > {'name': u'com.google.Chrome', 'version': u'33.0.1750.149'},
> > > {'name': u'com.google.Chrome', 'version': u'33.0.1750.146'},
> > > {'name': u'com.google.Chrome', 'version': u'32.0.1700.107'},
> > > {'name': u'com.google.Chrome', 'version': u'31.0.1650.63'},
> > > {'name': u'com.google.Chrome', 'version': u'31.0.1650.57'}]
> > >
> > > sortedlist = sorted(mylist , key=lambda x, y: x['name'] 
> > > LooseVersion(elem['version'])), reverse=True)
> > 
> > You'll need to fix LooseVersion or elem or both -- or show them so we 
> > can help.
> > 
> > Emile
> > 
> > 
> > 
> > >
> > > Thanks,
> > > Charlie
> > >
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: rst and pypandoc

2015-03-02 Thread Ben Finney
Dave Angel  writes:

> And D'oh right back at ya.  Ironic isn't it that I make a second
> mistake in the same message I correct yours?

https://en.wikipedia.org/wiki/Muphry%27s_law>

-- 
 \ “Truth would quickly cease to become stranger than fiction, |
  `\ once we got as used to it.” —Henry L. Mencken |
_o__)  |
Ben Finney

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


Re: Python Worst Practices

2015-03-02 Thread sohcahtoa82
On Monday, March 2, 2015 at 9:13:21 AM UTC-8, Jon Ribbens wrote:
> On 2015-03-02, Dennis Lee Bieber  wrote:
> > A pub's a bar; a bar's a gate; a gate's a street
> 
> If each of those is supposed to be English first and then the American
> equivalent second, then I'm afraid the first one is misleading and the
> other two are just nonsense.

American here.  To me, a pub and a bar are different, but similar.

A bar is where people go to get drinks.  They might serve food, but rarely does 
anybody actually order some.  A pub on the other hand, has a greater focus on 
food and is commonly visited to get food along with their beer.

Of course, I imagine plenty of fellow Americans would disagree with me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Direct Client Requirement for Software Engineer in Quality - Sunnyvale CA

2015-03-02 Thread tiya . akrid
Hi
 
Please let me know if you have anyone suitable for the below position
 
Job title: Software Engineer in Quality
Location: Sunnyvale, CA
Interview Process: Onsite
Duration: 6 months + contract
 
Responsibilities:
Work on an existing application in the Marketing Science team focused on 
maintaining internal application as well making enhancements and new features 
to the system.
Initially focus on quality by creating test plans, test data, data validation 
SQL scripts and analyze test results and then automate some of the testing and 
quality checks
Adding more integration to new channels and sources of data via web services as 
well as custom data feeds
Work closely with marketing business and technology teams and provide on-going 
support and guidance.
Develop scalable and reusable processes and automation frameworks for analyzing 
data and delivering ongoing quality metrics (leveraging SQL, PL SQL, UNIX, 
PYTHON and other tools)
 
Required Skills and Experience:
3 - 8 years' experience developing and testing highly distributed, complex 
eCommerce Platforms
At least 3 years hands-on software programming, Automation Scripting, White box 
testing experience
Python scripting experience, strong knowledge and experience in automated 
testing (API testing preferred), someone who has experience working in an Agile 
development environment, and someone who is comfortable owning the testing for 
a feature or project and working directly with API developers
Extensive hands-on QA & white box testing, and automation.
Nice to have - string prior QE , Python scripting
Hands-on experience working with relational DB  ( Oracle, MySQL, PostgreSQL) as 
well NoSQL DB such as Cassandra, Redshift
 
Kindly send your resume with below details for further process

Automation Scripting _ years of experience

White Box testing _ years of experience

Python Scripting _ years of experience

eCommerce Platforms _ years of experience

Rates on c2c

Availability

Current Location

 

Thanks

 

Tiya

Akrid Software Inc

t...@akrid.us
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Md5 is different in Windows and Linux

2015-03-02 Thread sohcahtoa82
On Monday, March 2, 2015 at 12:43:59 AM UTC-8, Sarvagya Pant wrote:
> Hello, I am amazed that the  md5 of a file given by python in windows is 
> different than that of linux. Consider the following code:
> 
> import hashlib
> def md5_for_file(f, block_size=2**20):
>     md5 = hashlib.md5()
>     while True:
>     data = f.read(block_size)
>     if not data:
>     break
>     md5.update(data)
>     return md5.hexdigest()
> 
> f = open("somefile.txt")
> print md5_for_file(f)
> 
> 
> When I run the program I get the checksum value: 
> 2f9cc8da53ee89762a34702f745d2956
> 
> But on this site http://onlinemd5.com/ and on linux it has value 
> E10D4E3847713472F51BC606852712F1.
> 
> 
> Why is there difference in value of Checksum computed by python in windows 
> and other system.?
> 
> -- 
> 
> sarvagya

I don't know which is worse, the fact that you're composing your message in 
HTML, or the fact that you're using Comic Sans as your font.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Sort list of dictionaries

2015-03-02 Thread Peter Otten
Charles Heizer wrote:

> Never mind, the light bulb finally went off. :-\
> 
> sortedlist = sorted(mylist , key=lambda elem: "%s %s" % ( elem['name'],
> (".".join([i.zfill(5) for i in elem['version'].split(".")])) ),
> reverse=True)

This lightbulb will break with version numbers > 9 ;)

Here are two alternatives:

result = sorted(
mylist,
key=lambda elem: (elem['name'], LooseVersion(elem['version'])),
reverse=True)

result = sorted(
mylist,
key=lambda e: (e["name"], tuple(map(int, e["version"].split(".",
reverse=True)


Personally, I prefer to not use a lambda:

def name_version(elem):
return elem['name'], LooseVersion(elem['version'])

result = sorted(mylist, key=name_version, reverse=True)


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


Re: Python27.dll could not be found

2015-03-02 Thread Gisle Vanem

Dave Angel wrote:


When I ran Windows, I had written a simple utility that searched the PATH for a 
specified file.
I called it which.bat to match the Linux equivalent.


I've written a similar tool; envtool --path --python python27.dll

Matches in %PATH:
  15 May 2013 - 21:43:38: f:\ProgramFiler\Python27\python27.dll
Matches in Python's sys.path[]:
  15 May 2013 - 21:43:38: f:\programfiler\Python27\python27.dll

(available at http://watt-32.net/misc/#envtool )


You can look to see where the system thinks the Python executable is located by 
doing

 ftype .py
and seeing what it shows.  Mine shows Python.File

   Then do
 assoc  Python.File

to see an actual path.


That will give you the path of python.exe. Not pythonXX.dll (as the
OP had problems with).

But by Windows DLL loading rules, it's IMHO safer to have pythonXX.dll
in the directory of python[w].exe. On Windows, ACAICR the Python MSI
installer puts pythonXX.dll in %Windir\system32. So it depends on how
the OP installed his Python.


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


Re: Python27.dll could not be found

2015-03-02 Thread Dave Angel

I INTENDED to send it to the list, but made the same mistake myself.


 Forwarded Message 
Subject: Re: Python27.dll could not be found
Date: Mon, 02 Mar 2015 08:51:07 -0500
From: Dave Angel 
To: Sarvagya Pant 

Sarvaqya accidentally sent me private email, so I'm forwarding with
comments to the list.

On 03/02/2015 08:22 AM, Sarvagya Pant wrote:

Hi thanks to all. Python.dll was found in my C:/Windows/SysWOW64 dir. As my
executable depends upon python.dll, it was required if I have to deploy my
executable.


So, was that directory on your PATH?  If so, Windows should have just
found it, and you'd have had no problem.

If you're instead talking about building an install for other machines,
that may or may not have Python 2.7 installed, you should say so.
PythonXX.dll may very well load other files when your code loads and
uses it, so an installation is usually a much more complex problem than
what you stated.

I have no idea what the best package manager is for Windows, but you
could start by looking at:

https://pypi.python.org/pypi/setuptools


--
DaveA



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


Re: Python27.dll could not be found

2015-03-02 Thread Dave Angel

On 03/02/2015 02:22 PM, Gisle Vanem wrote:

Dave Angel wrote:


When I ran Windows, I had written a simple utility that searched the
PATH for a specified file.
I called it which.bat to match the Linux equivalent.


I've written a similar tool; envtool --path --python python27.dll

Matches in %PATH:
   15 May 2013 - 21:43:38: f:\ProgramFiler\Python27\python27.dll
Matches in Python's sys.path[]:
   15 May 2013 - 21:43:38: f:\programfiler\Python27\python27.dll

(available at http://watt-32.net/misc/#envtool )


You can look to see where the system thinks the Python executable is
located by doing

 ftype .py
and seeing what it shows.  Mine shows Python.File

   Then do
 assoc  Python.File

to see an actual path.


That will give you the path of python.exe. Not pythonXX.dll (as the
OP had problems with).


I just figured it was extra information the OP could use;  finding the 
executable is a useful thing, even though different from finding the DLL.




But by Windows DLL loading rules, it's IMHO safer to have pythonXX.dll
in the directory of python[w].exe. On Windows, ACAICR the Python MSI
installer puts pythonXX.dll in %Windir\system32. So it depends on how
the OP installed his Python.


Doesn't do much good to have the DLL only in the python directory, if 
you're going to load it in a default way from a C++ program.  Python.exe 
doesn't do much, it mainly parses the commandline and invokes the DLL. 
Other programs that want to call Python functions don't need the exe, 
and therefore count on the DLL being on the Windows path.


The OP sent me a private message saying:
   "Python.dll was found in my C:/Windows/SysWOW64 dir"

I responded and intended it to be posted to the list, but messed up. 
You should see it by now.



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


Re: Python Worst Practices

2015-03-02 Thread Mark Lawrence

On 01/03/2015 17:52, Marko Rauhamaa wrote:

Mark Lawrence :


On 01/03/2015 17:01, Marko Rauhamaa wrote:

What you (or I) speak in our native surroundings is up to you (and
me).

However, when I exhange software engineering ideas with you, I wish
both of us could stick to American English.


Well I'm not going to, so tough, or is that togh? Colour, harbour,
tyre, antogonise are the way I spell words, and I'm not changing the
habits of a lifetime simply because I'm on a technical site.


Wow, a somewhat Chauvinistic attitude, wouldn't you say? The French will
learn it. The Germans will learn it. Us Finns will learn it. Only you
won't learn it because you won't change the habits of a lifetime.



No I wouldn't, autistic is far more accurate.

--
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: Picking apart a text line

2015-03-02 Thread Russell Owen

On 2/26/15 7:53 PM, memilanuk wrote:

So... okay.  I've got a bunch of PDFs of tournament reports that I want
to sift thru for information.  Ended up using 'pdftotext -layout
file.pdf file.txt' to extract the text from the PDF.  Still have a few
little glitches to iron out there, but I'm getting decent enough results
for the moment to move on.


...

So back to the lines of text I have stored as strings in a list.  I
think I want to convert that to a list of lists, i.e. split each line
up, store that info in another list and ditch the whitespace.  Or would
I be better off using dicts?  Originally I was thinking of how to
process each line and split it them up based on what information was
where - some sort of nested for/if mess.  Now I'm starting to think that
the lines of text are pretty uniform in structure i.e. the same field is
always in the same location, and that list slicing might be the way to
go, if a bit tedious to set up initially...?

Any thoughts or suggestions from people who've gone down this particular
path would be greatly appreciated.  I think I have a general
idea/direction, but I'm open to other ideas if the path I'm on is just
blatantly wrong.


It sounds to me as if the best way to handle all this is keep the 
information it in a database, preferably one available from the network 
and centrally managed, so whoever enters the information in the first 
place enters it there. But I admit that setting such a thing up requires 
some overhead.


Simpler alternatives include using SQLite, a simple file-based database 
system, or numpy structured arrays (arrays with named fields). Python 
includes a standard library module for sqlite and numpy is easy to install.


-- Russell

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


Re: Python Worst Practices

2015-03-02 Thread Jon Ribbens
On 2015-03-02, sohcahto...@gmail.com  wrote:
> On Monday, March 2, 2015 at 9:13:21 AM UTC-8, Jon Ribbens wrote:
>> On 2015-03-02, Dennis Lee Bieber  wrote:
>> >A pub's a bar; a bar's a gate; a gate's a street
>> 
>> If each of those is supposed to be English first and then the American
>> equivalent second, then I'm afraid the first one is misleading and the
>> other two are just nonsense.
>
> American here.  To me, a pub and a bar are different, but similar.
>
> A bar is where people go to get drinks.  They might serve food, but
> rarely does anybody actually order some.  A pub on the other hand,
> has a greater focus on food and is commonly visited to get food
> along with their beer.
>
> Of course, I imagine plenty of fellow Americans would disagree with me.

The distinction is nuanced and not well defined, but most British
people would think your definition above is certainly not entirely
wrong. They're definitely both places primarily for alcohol but
which may serve other purposes. If there's more wood and brass it's
probably a pub; if there's more glass and chrome and coloured lighting
it's probably a bar.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: rst and pypandoc

2015-03-02 Thread alb
Hi Dave,

Dave Angel  wrote:
[]
>> Rst escapes with "\", but unfortunately python also uses "\" for escaping!
> 
> Only when the string is in a literal.  If you've read it from a file, or 
> built it by combining other strings, or...  then the backslash is just 
> another character to Python.

Holy s***t! that is enlightning. I'm not going to ask why is that so, 
but essentially this changes everything. Indeed I'm passing some strings 
as literal (as my example), some others are simply read from a file 
(well the file is read into a list of dictionaries and then I convert 
one of those keys into latex).

The it would mean that the following text (in a file) should be 
swallowed by python as if the backslash was just another character:


this is \some text


unfortunately when I pass that to pypandoc, as if it was restructured 
text, I get the following:

In [36]: f = open('test.txt', 'r')

In [37]: s = f.read()

In [38]: print s
this is \some restructured text.


In [39]: print pypandoc.convert(s, 'latex', format='rst')
this is some restructured text.

what happened to my backslash???

If I try to escape my backslash I get something worse:

In [40]: f = open('test.txt', 'r')

In [41]: s = f.read()

In [42]: print s
this is \\some restructured text.


In [43]: print pypandoc.convert(s, 'latex', format='rst')
this is \textbackslash{}some restructured text.

since a literal backslash gets converted to a literal latex backslash.

[]
>> As said above, the string is converted by pandoc first and then printed.
>> At this point the escaping becomes tricky (at least to me).
>>
>> In [17]: inp = '\\ref{fig:abc}'
>>
>> In [18]: print pypandoc.convert(inp, 'latex', format='rst')
>> ref\{fig:abc\}
>>
> 
> What did you expect/desire the pyandoc output to be?  Now that you don't 
> have the embedded 0x0a, is there something else that's wrong?

I need to get \ref{fig:abc} in my latex file in order to get a 
reference. It seems to me I'm not able to pass inline text to pandoc and 
every backslash is treated...somehow.

> If it's in the internals of pyandoc, I'll probably be of no help.  But 
> your first question was about escaping;  I'm not sure what it's about now.

It's still about escaping in both python and restructured text since I 
want my substring (is part of the text) to pass unchanged through 
pypandoc. 

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


Re: rst and pypandoc

2015-03-02 Thread alb
Hi MRAB,

MRAB  wrote:
[]
> Have you tried escaping the escape character by doubling the backslash?
> 
> inp = 'ref{fig:abc}'

In [54]: inp = 'ref{fig:abc}'

In [55]: print pypandoc.convert(inp, 'latex', format='rst')
\textbackslash{}ref\{fig:abc\}

the backslash is considered as literal text for latex and is escaped 
with the appropriate command.

> or:
> 
> inp = r'\\ref{fig:abc}'
> 

In [56]: inp = r'\\ref{fig:abc}'

In [57]: print pypandoc.convert(inp, 'latex', format='rst')
\textbackslash{}ref\{fig:abc\}

same as above. The result I aim to would be:

In [BINGO]: print pypandoc.convert(inp, 'latex', format='rst')
\ref{fig:abc}

Al

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


Re: rst and pypandoc

2015-03-02 Thread alb
Hi Dave,

Dave Angel  wrote:
[]
>>> or use a raw string:
>>>
>>> i = r'\\ref{fig:abc}'
> 
> Actually that'd be:
>i = r'\ref{fig:abc}'

Could you explain why I then see the following difference:

In [56]: inp = r'\\ref{fig:abc}'

In [57]: print pypandoc.convert(inp, 'latex', format='rst')
\textbackslash{}ref\{fig:abc\}


In [58]: inp = r'\ref{fig:abc}'

In [59]: print pypandoc.convert(inp, 'latex', format='rst')
ref\{fig:abc\}

The two results are clearly *not* the same, even though the two inp 
/claim/ to be the same...

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


Re: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices]

2015-03-02 Thread Gregory Ewing

Steven D'Aprano wrote:

I remember the first time I realised that when Indians talk about "a
code" they aren't using "wrong English", they are using a regional
variation.


I don't think this is confined to Indians. I've noticed
that people from a Fortran scientific-computing background
tend to use the word that way as well.

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


Re: rst and pypandoc

2015-03-02 Thread Chris Angelico
On Tue, Mar 3, 2015 at 9:30 AM, alb  wrote:
> Hi Dave,
>
> Dave Angel  wrote:
> []
>>> Rst escapes with "\", but unfortunately python also uses "\" for escaping!
>>
>> Only when the string is in a literal.  If you've read it from a file, or
>> built it by combining other strings, or...  then the backslash is just
>> another character to Python.
>
> Holy s***t! that is enlightning. I'm not going to ask why is that so,
> but essentially this changes everything. Indeed I'm passing some strings
> as literal (as my example), some others are simply read from a file
> (well the file is read into a list of dictionaries and then I convert
> one of those keys into latex).

You have two different things happening here. The first is the concept
of a "string literal", and the second is how pandoc handles things.

Python's string literals come in a few different forms, but the most
common is the one that looks the same as in several other languages.
You start with a quote character, you put all your stuff in the
middle, and you finish with another quote:

"Hello, world!"

Trouble is, this makes it really hard to put quotes into your string:

"I said, "Hello, world!""

That's not going to work properly! So we need to tell Python that
those interior quotes aren't the end of the string. That's done with a
backslash:

"I said, \"Hello, world!\""

And of course, that means you have to escape the backslash if you want
to have one in the text. But all of this is just for putting *string
literals* into your source code. If it's not Python source code, these
rules don't apply. You can read a line of text from the user and it'll
be unchanged:

>>> msg = input("Enter a string: ")
Enter a string: This is a string, but not a "string literal".
>>> print(msg)
This is a string, but not a "string literal".

(in Python 2, use raw_input instead of input)

Same applies to reading from a file, or anywhere else. If it's not
Python source code, it doesn't matter what characters are in the
string, they're all just characters.

> unfortunately when I pass that to pypandoc, as if it was restructured
> text, I get the following:
>
> In [36]: f = open('test.txt', 'r')
>
> In [37]: s = f.read()
>
> In [38]: print s
> this is \some restructured text.
>
>
> In [39]: print pypandoc.convert(s, 'latex', format='rst')
> this is some restructured text.
>
> what happened to my backslash???

That's something you'll have to figure out with pypandoc. I don't know
how it interprets the backslash, so you'll have to dig into its
documentation. At least now, though, you can print out your string and
see that it really does have its backslash in it.

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


Re: rst and pypandoc

2015-03-02 Thread Mark Lawrence

On 02/03/2015 22:40, alb wrote:

Hi Dave,

Dave Angel  wrote:
[]

or use a raw string:

i = r'\\ref{fig:abc}'


Actually that'd be:
i = r'\ref{fig:abc}'


Could you explain why I then see the following difference:

In [56]: inp = r'\\ref{fig:abc}'

In [57]: print pypandoc.convert(inp, 'latex', format='rst')
\textbackslash{}ref\{fig:abc\}


In [58]: inp = r'\ref{fig:abc}'

In [59]: print pypandoc.convert(inp, 'latex', format='rst')
ref\{fig:abc\}

The two results are clearly *not* the same, even though the two inp
/claim/ to be the same...

Al



The two inps are *not* the same.  Steven D'Aprano mislead you with a 
typo, or so he claims :)  Dave Angel pointed this out.  Steven replied. 
 You've either missed these emails or simply not read them.


--
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: rst and pypandoc

2015-03-02 Thread Ben Finney
Chris Angelico  writes:

> And of course, that means you have to escape the backslash if you want
> to have one in the text. But all of this is just for putting *string
> literals* into your source code. If it's not Python source code, these
> rules don't apply. You can read a line of text from the user and it'll
> be unchanged

To put it another way: The source code is not the value itself. The
string value is created *from* the characters in the source code, and
the sequence of characters in the string value may be different.

When the string value comes from somewhere else, it bypasses this
interpretation of source code — because it's not source code!

String literals exist in your Python source code. They are not the same
thing as the string value itself, and the sequence fo characters may be
different.

-- 
 \ “Try adding “as long as you don't breach the terms of service – |
  `\  according to our sole judgement” to the end of any cloud |
_o__)  computing pitch.” —Simon Phipps, 2010-12-11 |
Ben Finney

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


Re: rst and pypandoc

2015-03-02 Thread Steven D'Aprano
alb wrote:

> Could you explain why I then see the following difference:
> 
> In [56]: inp = r'\\ref{fig:abc}'
> 
> In [57]: print pypandoc.convert(inp, 'latex', format='rst')
> \textbackslash{}ref\{fig:abc\}
> 
> 
> In [58]: inp = r'\ref{fig:abc}'
> 
> In [59]: print pypandoc.convert(inp, 'latex', format='rst')
> ref\{fig:abc\}
> 
> The two results are clearly *not* the same, even though the two inp
> /claim/ to be the same...
 
The two inp are not the same.

I'm sorry if I confused you with my earlier typo, but 

inp = r'\\ref{fig:abc}'

starts with TWO backslashes, while:

inp = r'\ref{fig:abc}'


starts with ONE backslash. Not the same.

I suspect you've been hitting your head against this problem for so long
you're starting to shy at shadows. Take a step back, a deep breath, and
remember your basic debugging skills:


a = r'\\ref{fig:abc}'
b = r'\ref{fig:abc}'
print a == b
print a, b
print repr(a), repr(b)
print len(a), len(b)


I'm sure that you know how to do such simple things to investigate whether
two inputs are in fact the same or not, and the fact that you failed to do
so is just a sign of your frustration and stress.


-- 
Steven

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


Re: rst and pypandoc

2015-03-02 Thread Dave Angel

On 03/02/2015 05:40 PM, alb wrote:

Hi Dave,

Dave Angel  wrote:
[]

or use a raw string:

i = r'\\ref{fig:abc}'


Actually that'd be:
i = r'\ref{fig:abc}'


Could you explain why I then see the following difference:

In [56]: inp = r'\\ref{fig:abc}'


print inp
   and you should get
 \\ref{fig:abc}



In [57]: print pypandoc.convert(inp, 'latex', format='rst')
\textbackslash{}ref\{fig:abc\}


In [58]: inp = r'\ref{fig:abc}'


print inp
and you should get
   \ref{fig:abc}

This is NOT the same.

The rules are not arbitrary.  They're quite necessary, and it's the same 
for lots of different languages.  When in a regular literal, the 
backslash is an escape character that combines with the following 
character.  When in a raw literal, the backslash is a backslash, unless 
it's at the end of the string, in which case it's not the end of the 
string, it's an escaped quotation.  (Or something.  Just don't use 
*trailing* backslash in a raw literal)




In [59]: print pypandoc.convert(inp, 'latex', format='rst')
ref\{fig:abc\}

The two results are clearly *not* the same, even though the two inp
/claim/ to be the same...



When I said backslashes are not special in data read from a file, I 
should also say neither are quotes, or tabs, or anything else.  Python 
just reads them in, and stuffs them into a string object.  Newlines are 
special if you use readline(), but if you use read(), they're not 
special either (except on MSDOS compatible variants, which use two bytes 
for newline.  Even there, if you read a file in "b" mode, they're not 
special either.


So your code is going to mostly be getting strings from files, or from 
calculations, and these backslashes won't be special.  It's only in 
*testing* that you usually deal with this literal stuff.  Or in places 
where the data is fixed, and hardcoded in the source.



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


Re: rst and pypandoc

2015-03-02 Thread Steven D'Aprano
alb wrote:

> In [39]: print pypandoc.convert(s, 'latex', format='rst')
> this is some restructured text.
> 
> what happened to my backslash???

You'll need to read your pypandoc documentation to see what it says about
backslashes.


> If I try to escape my backslash I get something worse:
> 
> In [40]: f = open('test.txt', 'r')
> 
> In [41]: s = f.read()
> 
> In [42]: print s
> this is \\some restructured text.
> 
> 
> In [43]: print pypandoc.convert(s, 'latex', format='rst')
> this is \textbackslash{}some restructured text.
> 
> since a literal backslash gets converted to a literal latex backslash.

Why is this a problem? Isn't the ultimate aim to pass it through latex,
which will then covert the \textbackslash{} back into a backslash? If not,
I have misunderstood something.

If not, you could do something like this:

s = 'this is %(b)ssome restructured text.'
t = pypandoc.convert(s, 'latex', format='rst')
assert t == 'this is %(b)ssome restructured text.'
print t % {'b': '\\'}


taking care to escape any actual percent signs in your text as '%%'.

To be clear, what I'm doing here is using Python's % string interpolation to
post-process the Latex output:

- replace every '%' in your input string with '%%';
- replace every backslash in your input string with '%(b)s';
- convert;
- post-process using %.



-- 
Steven

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


Re: Md5 is different in Windows and Linux

2015-03-02 Thread Thomas Rachel

Am 02.03.2015 20:14 schrieb sohcahto...@gmail.com:

On Monday, March 2, 2015 at 12:43:59 AM UTC-8, Sarvagya Pant wrote:



f = open("somefile.txt")


This one is the problem. Under Windows, you have to open the file in 
binary to avoid that something "bad" happens with it.


So just do

f = open("somefile.txt", "rb")

and you should be fine.



I don't know which is worse, the fact that you're composing your message in 
HTML, or the fact that you're using Comic Sans as your font.


#2 wouldn't be possible without #1...


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


Re: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices]

2015-03-02 Thread Sturla Molden
Steven D'Aprano  wrote:

> Variations in idiom and spelling are a good thing. They open our minds to
> new possibilities, remind us that we aren't all the same, and keep life
> fresh. I remember the first time I realised that when Indians talk about "a
> code" they aren't using "wrong English", they are using a regional
> variation. In British and American English, "code" in the programming
> sense[2] is a mass or uncountable noun, like air[3], milk, music and
> housework. 

I can assure you that in a veterinary sence, Yersey cows will produce a
milk with higher fat content.

In a lingustic sence the "a" is not a count -- that would be the word "one"
--, it is the indefinite article. Here is the difference:

The Enigma machine produced a code that only Alan Turing could break. If I
say the Enigma machine produced one code that only Alan Turing could break,
it means all the other codes could be broken by someone else.

What if I say "this file contains a long Fortran code"? Or what if I say
"this file contains one long Fortran code"? There is a subtile difference
in meaning here. 

Sturla

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


Re: (Still OT) Nationalism, language and monoculture [was Re: Python Worst Practices]

2015-03-02 Thread Steven D'Aprano
Sturla Molden wrote:

> Steven D'Aprano  wrote:
> 
>> Variations in idiom and spelling are a good thing. They open our minds to
>> new possibilities, remind us that we aren't all the same, and keep life
>> fresh. I remember the first time I realised that when Indians talk about
>> "a code" they aren't using "wrong English", they are using a regional
>> variation. In British and American English, "code" in the programming
>> sense[2] is a mass or uncountable noun, like air[3], milk, music and
>> housework.
> 
> I can assure you that in a veterinary sence, Yersey cows will produce a
> milk with higher fat content.

A good example of the complexity and subtlety of English grammar. I don't
know enough linguistics to tell you what "a milk" in that sense is called,
but it's not the same as "1 milk", "2 milks" etc. I'm not even sure what
the purpose of the "a" is, since it reads fine without it.

I chalk that up to "English is weird", like the way we sometimes refer to
money as a mass noun ("two buckets of money", not "two monies") and other
times we treat it as a mass plural noun ("please hand all monies to the
bursar", but it would be weird to say "please hand five monies to the
bursar").

Oh, and of course since language is complicated and speakers of language are
lazy, there are contexts where one does say "two milks" as a short-hand,
like we say "two sugars" when we mean "two spoonfuls of sugar" or "serves
of sugar". The unit of measure is implied by context.


> In a lingustic sence the "a" is not a count -- that would be the word
> "one" --, it is the indefinite article. Here is the difference:
> 
> The Enigma machine produced a code that only Alan Turing could break. If I
> say the Enigma machine produced one code that only Alan Turing could
> break, it means all the other codes could be broken by someone else.

No. It means that there is one secret code that Turing, and only Turing,
could break, and some unknown number (possibly zero, possibly millions) of
codes that he could not break. Whether other people could break these other
codes is not stated. Whether you say "a code" or "one code" (or "fifteen
codes" for that matter) is irrelevant.

There is a weak implication that if Turing cannot break the other codes,
nobody else could either. That's not necessarily true in real life, but as
a rough rule of thumb, we can reason like this: since there is one code
that Turing can break but others cannot, he must be cleverer at breaking
secret codes than everyone else. If he is cleverer at breaking codes, then
it is unlikely that they could break codes that he cannot. If they could
break an Enigma code, so could he. Therefore, if he cannot break them,
neither can anyone else.


> What if I say "this file contains a long Fortran code"? Or what if I say
> "this file contains one long Fortran code"? There is a subtile difference
> in meaning here.


In British/American/Australian English, you wouldn't say either of those.
You would say "a long piece of Fortran code" or "a long example of Fortran
code". Or more likely, "a long Fortran program". Program is counted: there
is no difficulty in B/A/A English to say "I have written 17 programs".

We can substitute "one" for "a" and the meaning remains the same:

"Here is a long example of Fortran code."

"Here is one long example of Fortran code."


In neither case does it imply that there is only one example of Fortran code
which is long in the entire world.

(This is bringing back memories of when I was, oh, four or so, when I got
into a long argument with my teacher that "a hundred" and "one hundred"
were different. You counted "ninety-nine, *a* hundred, a hundred and one, a
hundred and two, ... a hundred and ninety-nine, *one* hundred, one hundred
and one...")



-- 
Steven

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


tarfile vs zipfile

2015-03-02 Thread Seth P
Is there a reason tarfile and zipfile don't use the same method/member names, 
where it makes sense?  Consider the following six methods/members, which I 
would expect to be the same (with the possible exception of mtime vs date_time, 
which are of different types).  It almost seems like someone went out of their 
way to make it difficult to use them interchangeably.

tarfile  zipfile

  TarFile  ZipFile
getmember(name)  getinfo(name)
getmembers() infolist()
getnames()   namelist()

  TarInfo  ZipInfo
name filename
mtimedate_time
size file_size
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tarfile vs zipfile

2015-03-02 Thread Ben Finney
Seth P  writes:

> Is there a reason tarfile and zipfile don't use the same method/member
> names, where it makes sense?

One likely explanation is that the modules's APIs were designed by
different people unaware of the work of the other.

-- 
 \“We have to go forth and crush every world view that doesn't |
  `\believe in tolerance and free speech.” —David Brin |
_o__)  |
Ben Finney

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


  1   2   >