Re: Compiling extensions on Python 2.7, Windows 10 64 bit

2016-04-30 Thread Andrea Gavana
Hi,

On Friday, 29 April 2016, Igor Korot  wrote:

> Andrea,
>
> On Fri, Apr 29, 2016 at 4:27 PM, Andrea Gavana  > wrote:
> > Hi,
> >
> >
> > On Friday, 29 April 2016, Igor Korot >
> wrote:
> >>
> >> Andrea,
> >>
> >> On Fri, Apr 29, 2016 at 3:45 PM,   > wrote:
> >> > Dear list,
> >> >
> >> > I have been trying to compile wxPython Phoenix
> >> > (https://github.com/wxWidgets/Phoenix) from source on Windows 10 64
> bit,
> >> > Python 2.7 64 bit, using the very handy Microsoft Visual C++ Compiler
> for
> >> > Python 2.7 (
> https://www.microsoft.com/en-us/download/details.aspx?id=44266).
> >> >
> >> > I started with Python 2.7.8, then wiped out that installation and used
> >> > Python 2.7.11: cleaned the build directory, everything, and rebuilt
> the
> >> > Phoenix modules from scratch.
> >> >
> >> > Upon starting the Phoenix demo, I got the same error message I had
> with
> >> > Python 2.7.8:
> >> >
> >> > D:\MyProjects\Phoenix\demo>python Main.py
> >> > 
> >> > Traceback (most recent call last):
> >> >   File "C:\Python27\lib\site-packages\wxPhoenix\wx\core.py", line
> 1955,
> >> > in Notify
> >> > self.notify()
> >> >   File "C:\Python27\lib\site-packages\wxPhoenix\wx\core.py", line
> 3034,
> >> > in Notify
> >> > self.result = self.callable(*self.args, **self.kwargs)
> >> >   File "Main.py", line 2601, in ShowMain
> >> > frame = wxPythonDemo(None, "wxPython: (A Demonstration)")
> >> >   File "Main.py", line 1531, in __init__
> >> > self.SetOverview(self.overviewText, mainOverview)
> >> >   File "Main.py", line 2130, in SetOverview
> >> > self.nb.SetPageText(0, os.path.split(name)[1])
> >> > SystemError: ..\Objects\longobject.c:998: bad argument to internal
> >> > function
> >> >
> >> > The error message refers (apparently) to this Python bug:
> >> >
> >> > https://bugs.python.org/issue23842
> >> >
> >> > But I assumed that it had been fixed way before 2.7.11. Now I am
> >> > stuck and I have no idea on what to try next.
> >> >
> >> > Does anyone have suggestions/comments on where I should look for/what
> I
> >> > should do/what I should change in order to get the extension running
> on
> >> > Python 2.7?
> >> >
> >> > Thank you in advance for your suggestions :-)
> >>
> >> Did you try with python 3.x?
> >>
> >> IIUC, Phoenix should be made for python 3.x, and classic is for 2.7
> >> series.
> >>
> >
> >
> > No, Phoenix is meant to work on Python 2 and 3 at the same time. That's
> the
> > very reason it was created.
>
> But is it compiling with python 3.x?
> Because the bug should be definitely fixed there.
>


This is not relevant to the question I have asked. I will be using it with
Python 3 as well, but I would like to know if anybody has a suggestion on
what I may be doing wrong on Python *2*, since I have many projects happily
running with that version of Python.

Andrea.




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


Re: manpage writing [rst, asciidoc, pod] was [Re: What should Python apps do when asked to show help?]

2016-04-30 Thread Paul Rubin
Rustom Mody  writes:
> At that point what I gleaned was that original makeinfo was in C
> New one was rewritten in perl.

The previous one was definitely written in C and I've looked at the code
some.  I hadn't known there was a new one.  The C one was actually the
second one.  The first one was written in Emacs Lisp but it was
painfully slow on the hardware of that era.  The C version was
cumbersome by comparison.  If they wanted to get rid of the C version
now that the hardware is 100x faster or more, it's amusing that they did
a Perl rewrite instead of reviving the Lisp version.  Pandoc has a
significant user base now though, and it looks like it also supports
texinfo.  So I wonder what the new Makeinfo does that pandoc doesn't.
Maybe pandoc doesn't support Info?  That could be added, I'm sure.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: web facing static text db

2016-04-30 Thread Gordon Levi
"Fetchinson ."  wrote:

>Hi folks,
>
>I have a very specific set of requirements for a task and was
>wondering if anyone had good suggestions for the best set of tools:
>
>* store text documents (about 10 pages)
>* the data set is static (i.e. only lookups are performed, no delete,
>no edit, no addition)
>* only one operation required: lookup of pages by matching words in them
>* very simple web frontend for querying the words to be matched
>* no authentication or authorization, frontend completely public
>* deployment at webfaction
>* deadline: yesterday :)
>
>Which web framework and db engine would you recommend?
>
>So far I'm familiar with turbogears but would be willing to learn
>anything if sufficiently basic since my needs are pretty basic (I
>think).
>

What do need that storing the documents in HTML format and Google
Custom Search does not provide
?
-- 
https://mail.python.org/mailman/listinfo/python-list


EuroPython 2016: Extra Hot Topics - Call for Proposals

2016-04-30 Thread M.-A. Lemburg
The Program work group is happy to announce that there will be an
extra Call for Proposals early in June. This call is limited to hot
topics and most recent developments in software and technology.

Why is there a second call ?


Planning a big conference is a challenge: On one hand people like to
know what will be on our talk schedule to make up their mind and make
travel arrangements early. On the other hand technology is progressing
at the speed of light these days.

So what’s the solution ? Attend anyway - EuroPython is always a great
idea !

Seriously, we have given this some thought and decided to make another
extra Call for Proposals just weeks before the conference.

This CfP is strictly reserved for

 * hot topics
 * emerging technologies
 * brand new developments in software & hardware
 * recent results in research and science

Some suggestions for topics:

 * Exciting new hardware & Internet of Things
 * Robotics
 * Virtual Reality
 * AI & Deep Learning

This call will be open for nine days only:


*** Saturday June 4th 0:00 to Sunday June 12th 24:00 CEST ***


The program work group will select the most exciting and intriguing
submissions and will notify the winners on short notice.


With gravitational regards,
--
EuroPython 2016 Team
http://ep2016.europython.eu/
http://www.europython-society.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to download a flash video from this site?

2016-04-30 Thread zljubisic
On Friday, 29 April 2016 22:40:10 UTC+2, Chris Angelico  wrote:
> Since you're asking on this list, I'll assume you're using Beautiful
> Soup and/or youtube-dl. You'll need to go into more detail about what
> you're trying to do, and where the Python problem is.
> 
> ChrisA

The situation is very simple. I would like to use a beutifullsoap but I can't 
figure out how to get the filename that I could download.

For example I opened the page 
https://hrti.hrt.hr/#/video/show/2203605/trebizat-prica-o-jednoj-vodi-i-jednom-narodu-dokumentarni-film

in firefox and than from menu Tools > Web Developer > Network I found that 
there is a playlist on page

https://prd-hrt.spectar.tv/player/get_smil/id/2203605/video_id/2203605/token/Cny6ga5VEQSJ2uZaD2G8pg/token_expiration/1462043309/asset_type/Movie/playlist_template/nginx/channel_name/trebiat__pria_o_jednoj_vodi_i_jednom_narodu_dokumentarni_film/playlist.m3u8?foo=bar

in which chunks of video are listed like this:
01_1461582488.0329_00.ts
01_1461582488.0329_01.ts
01_1461582488.0329_02.ts
...
01_1461582488.0329_000359.ts

>From the m3u8 list I can get the first chunk by downloading the following:
https://prd-hrt-vod.spectar.tv/OD/VoD/c2v_production_2201645/03_1461582488.0329_00.ts

My poblem is how to get from 

https://hrti.hrt.hr/#/video/show/2203605/trebizat-prica-o-jednoj-vodi-i-jednom-narodu-dokumentarni-film

a m3u8 list?

After getting the m3u8 list file, I will be able to download all chunks and 
record the video.

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


Re: Not x.islower() has different output than x.isupper() in list output...

2016-04-30 Thread Christopher Reimer

On 4/29/2016 11:43 PM, Stephen Hansen wrote:
The official documentation is accurate. 


That may be true on a technical level. But the identically worded text 
in the documentation implies otherwise. Maybe I'm nitpicking this. Even 
if I submitted a bug to request a clearer explanation in the 
documentation, I doubt it would get change. The programmer still has an 
obligation to test the code to make sure that it works as expected, 
which was what I did that until I found the concise statement that 
worked exactly as I wanted it to.


Thank you,

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


Re: Not x.islower() has different output than x.isupper() in list output...

2016-04-30 Thread Chris Angelico
On Sun, May 1, 2016 at 2:48 AM, Christopher Reimer
 wrote:
> On 4/29/2016 11:43 PM, Stephen Hansen wrote:
>>
>> The official documentation is accurate.
>
>
> That may be true on a technical level. But the identically worded text in
> the documentation implies otherwise. Maybe I'm nitpicking this. Even if I
> submitted a bug to request a clearer explanation in the documentation, I
> doubt it would get change. The programmer still has an obligation to test
> the code to make sure that it works as expected, which was what I did that
> until I found the concise statement that worked exactly as I wanted it to.

Let's take it away from letter case and to something that everyone
should be able to grok.

isalpha(...) method of builtins.str instance
S.isalpha() -> bool

Return True if all characters in S are alphabetic
and there is at least one character in S, False otherwise.

isdigit(...) method of builtins.str instance
S.isdigit() -> bool

Return True if all characters in S are digits
and there is at least one character in S, False otherwise.

It should be pretty obvious that there are some strings which are
neither alphabetic nor digits. Thus these two are not opposites,
despite the identical wording in the docs.

It's exactly the same with letter case. Some strings are neither
uppercase nor lowercase, and thus they'll be False on both checks.

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


Re: Not x.islower() has different output than x.isupper() in list output...

2016-04-30 Thread Stephen Hansen
On Sat, Apr 30, 2016, at 09:48 AM, Christopher Reimer wrote:
> On 4/29/2016 11:43 PM, Stephen Hansen wrote:
> > The official documentation is accurate. 
> 
> That may be true on a technical level. But the identically worded text 
> in the documentation implies otherwise. 

That's the thing -- no it doesn't. The documentation is very specific:
if all cased characters in the string are lowercase, and there's at
least one cased character.

It only seems to because you're packing a loop and test on substrings
into an operation.

   list(filter((lambda x: not x.islower()), string))

Let's unpack that. This is basically what you're doing:

result = []
for ch in string:
if not ch.islower():
result.append(ch)

You're thinking of the whole "string", but you're operating on
single-character substrings, and when " ".islower() is run, its false.
Because the two-pronged test, a) if all cased characters are lowercase
and b) there is at least one cased character. b) is failing. Ergo,
you're getting the underscores.

-- 
Stephen Hansen
  m e @ i x o k a i  . i o
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: web facing static text db

2016-04-30 Thread Fetchinson . via Python-list
On 4/30/16, Gordon Levi  wrote:
> "Fetchinson ."  wrote:
>
>>Hi folks,
>>
>>I have a very specific set of requirements for a task and was
>>wondering if anyone had good suggestions for the best set of tools:
>>
>>* store text documents (about 10 pages)
>>* the data set is static (i.e. only lookups are performed, no delete,
>>no edit, no addition)
>>* only one operation required: lookup of pages by matching words in them
>>* very simple web frontend for querying the words to be matched
>>* no authentication or authorization, frontend completely public
>>* deployment at webfaction
>>* deadline: yesterday :)
>>
>>Which web framework and db engine would you recommend?
>>
>>So far I'm familiar with turbogears but would be willing to learn
>>anything if sufficiently basic since my needs are pretty basic (I
>>think).
>>
>
> What do need that storing the documents in HTML format and Google
> Custom Search does not provide
> ?

Wow! Thanks, I was not aware of that, sounds exactly what I need.

Thanks for all the other ideas too.

Cheers,
Daniel



-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Not x.islower() has different output than x.isupper() in list output...

2016-04-30 Thread Christopher Reimer

On 4/30/2016 10:11 AM, Stephen Hansen wrote:
You're thinking of the whole "string", but you're operating on 
single-character substrings, and when " ".islower() is run, its false. 
Because the two-pronged test, a) if all cased characters are lowercase 
and b) there is at least one cased character. b) is failing. Ergo, 
you're getting the underscores.


I see where the problem lies in my thinking. I went looking for a single 
line solution for the whole string. If I had constructed a for loop and 
tried to reduce it to a single line, I *may* have understood the 
relationship between the different parts. Or maybe not. Blaming the 
documentation is a lot easier. ;)


Thank you,

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


Re: about special characters

2016-04-30 Thread Jianling Fan
Hello everyone,

Thanks very much for all your replies and sorry for the inconvience.
This is my first time to post question in this list.

I am using python 2.7 in Windows 7 Enterprise version.

Here is the the filename that cause the problem: "Decock-2013-On the
potential of δ18O and δ15N.pdf"
When I delete the "δ" in the filename, the script works good.

Here is the output:

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> runfile('P:/sync.py', wdir='P:')
Traceback (most recent call last):
  File "", line 1, in 
  File 
"C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
line 699, in runfile
execfile(filename, namespace)
  File 
"C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
line 74, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
  File "P:/sync.py", line 50, in 
sync_files(src, dest)
  File "P:/sync.py", line 43, in sync_files
sync(dir_cmp)
  File "P:/sync.py", line 20, in sync
shutil.rmtree(f_right)
  File "C:\Python27\lib\shutil.py", line 236, in rmtree
onerror(os.listdir, path, sys.exc_info())
  File "C:\Python27\lib\shutil.py", line 234, in rmtree
names = os.listdir(path)
WindowsError: [Error 3] The system cannot find the path specified:
'P:/mystuff\\Decock-2013-On the potential of d18O and d15N.pdf/*.*'


Here is my code to do this work: I am using this script to sync my
files between different disks.

#coding=utf-8

import filecmp, shutil, os, sys

SRC = r'C:/Disk/mystuff'
DEST = r'P:/mystuff'

IGNORE = ['Thumbs.db']

def get_cmp_paths(dir_cmp, filenames):
return ((os.path.join(dir_cmp.left, f),
os.path.join(dir_cmp.right, f)) for f in filenames)

def sync(dir_cmp):
for f_left, f_right in get_cmp_paths(dir_cmp, dir_cmp.right_only):
if os.path.isfile(f_right):
os.remove(f_right)
else:
shutil.rmtree(f_right)
print('delete %s' % f_right)
for f_left, f_right in get_cmp_paths(dir_cmp,
dir_cmp.left_only+dir_cmp.diff_files):
if os.path.isfile(f_left):
shutil.copy2(f_left, f_right)
else:
shutil.copytree(f_left, f_right)
print('copy %s' % f_left)
for sub_cmp_dir in dir_cmp.subdirs.values():
sync(sub_cmp_dir)

def sync_files(src, dest, ignore=IGNORE):
if not os.path.exists(src):
print('= =b Please check the source directory was exist')
print('- -b Sync file failure !!!')
return
if os.path.isfile(src):
print('#_# We only support for sync directory but not a single
file,one file please do it by yourself')
print('- -b Sync file failure !!!')
return
if not os.path.exists(dest):
os.makedirs(dest)
dir_cmp = filecmp.dircmp(src, dest, ignore=IGNORE)
sync(dir_cmp)
print('^_^ Sync file finished!')

if __name__ == '__main__':
src, dest = SRC, DEST
if len(sys.argv) == 3:
src, dest = sys.argv[1:3]
sync_files(src, dest)



Thanks again!


On 29 April 2016 at 19:01, Steven D'Aprano  wrote:
> On Sat, 30 Apr 2016 09:33 am, Jianling Fan wrote:
>
>> Hello everyone,
>>
>> I am trying to use python 27 copying some of my folders and files to
>> another directory.
>> My code works good for other files but I have some problem to copy
>> files that have some special characters in the filename. like
>> filenames contain Greek "δ"  or latin "š".
>> it always gave a error that "No such file or directory:"
>>
>> Any help will be appreciate!
>
> Please put yourself in our shoes. Read your message above, and, imagine that
> you know NOTHING else about your program than what you write above. What
> answer would you give?
>
> Please tell us what you have actually done. How do you copy the files? How
> do you enter the file names? What OS are you using?
>
>
>
> --
> Steven
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Jianling Fan
樊建凌
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: about special characters

2016-04-30 Thread Terry Reedy

On 4/30/2016 2:13 PM, Jianling Fan wrote:


I am using python 2.7 in Windows 7 Enterprise version.

Here is the the filename that cause the problem: "Decock-2013-On the
potential of δ18O and δ15N.pdf"
When I delete the "δ" in the filename, the script works good.


You may be able to get "δ" (and other Greek characters) to work on your 
system with 2.7, but if you want to be able to work with any filename on 
Windows, get Python 3.4 or later and use text strings, not byte strings. 
You may someday run into a Name-your-title.pdf file name with other 
'strange' characters from other


Windows filenames are unicode strings and are stored, I believe, with 
utf-16 encoding.  Even in early 3.x versions, there were Windows path 
problems, for instance with east Asian characters.  Multiple 3.x patches 
seem to have fixed the problems. So merely using unicode is not, in 
general, sufficient.


--
Terry Jan Reedy


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


Re: about special characters

2016-04-30 Thread MRAB

On 2016-04-30 19:13, Jianling Fan wrote:

Hello everyone,

Thanks very much for all your replies and sorry for the inconvience.
This is my first time to post question in this list.

I am using python 2.7 in Windows 7 Enterprise version.

Here is the the filename that cause the problem: "Decock-2013-On the
potential of δ18O and δ15N.pdf"
When I delete the "δ" in the filename, the script works good.

Here is the output:

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

runfile('P:/sync.py', wdir='P:')

Traceback (most recent call last):
  File "", line 1, in 
  File 
"C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
line 699, in runfile
execfile(filename, namespace)
  File 
"C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
line 74, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
  File "P:/sync.py", line 50, in 
sync_files(src, dest)
  File "P:/sync.py", line 43, in sync_files
sync(dir_cmp)
  File "P:/sync.py", line 20, in sync
shutil.rmtree(f_right)
  File "C:\Python27\lib\shutil.py", line 236, in rmtree
onerror(os.listdir, path, sys.exc_info())
  File "C:\Python27\lib\shutil.py", line 234, in rmtree
names = os.listdir(path)
WindowsError: [Error 3] The system cannot find the path specified:
'P:/mystuff\\Decock-2013-On the potential of d18O and d15N.pdf/*.*'


Here is my code to do this work: I am using this script to sync my
files between different disks.

#coding=utf-8

import filecmp, shutil, os, sys

SRC = r'C:/Disk/mystuff'
DEST = r'P:/mystuff'

IGNORE = ['Thumbs.db']

def get_cmp_paths(dir_cmp, filenames):
return ((os.path.join(dir_cmp.left, f),
os.path.join(dir_cmp.right, f)) for f in filenames)

def sync(dir_cmp):
for f_left, f_right in get_cmp_paths(dir_cmp, dir_cmp.right_only):
if os.path.isfile(f_right):
os.remove(f_right)
else:
shutil.rmtree(f_right)
print('delete %s' % f_right)
for f_left, f_right in get_cmp_paths(dir_cmp,
dir_cmp.left_only+dir_cmp.diff_files):
if os.path.isfile(f_left):
shutil.copy2(f_left, f_right)
else:
shutil.copytree(f_left, f_right)
print('copy %s' % f_left)
for sub_cmp_dir in dir_cmp.subdirs.values():
sync(sub_cmp_dir)

def sync_files(src, dest, ignore=IGNORE):
if not os.path.exists(src):
print('= =b Please check the source directory was exist')
print('- -b Sync file failure !!!')
return
if os.path.isfile(src):
print('#_# We only support for sync directory but not a single
file,one file please do it by yourself')
print('- -b Sync file failure !!!')
return
if not os.path.exists(dest):
os.makedirs(dest)
dir_cmp = filecmp.dircmp(src, dest, ignore=IGNORE)
sync(dir_cmp)
print('^_^ Sync file finished!')

if __name__ == '__main__':
src, dest = SRC, DEST
if len(sys.argv) == 3:
src, dest = sys.argv[1:3]
sync_files(src, dest)


[snip]
You're using bytestrings (str). As soon as you step out of the ASCII
range, you can face problems with which encoding it's using.

The simplest fix is to switch to using Unicode.

Start with this change:

SRC = ur'C:/Disk/mystuff'
DEST = ur'P:/mystuff'

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


Re: about special characters

2016-04-30 Thread Jianling Fan
Oh, it works!

This is the simplest and best way!

Thanks very much!



On 30 April 2016 at 13:42, MRAB  wrote:
> On 2016-04-30 19:13, Jianling Fan wrote:
>>
>> Hello everyone,
>>
>> Thanks very much for all your replies and sorry for the inconvience.
>> This is my first time to post question in this list.
>>
>> I am using python 2.7 in Windows 7 Enterprise version.
>>
>> Here is the the filename that cause the problem: "Decock-2013-On the
>> potential of δ18O and δ15N.pdf"
>> When I delete the "δ" in the filename, the script works good.
>>
>> Here is the output:
>>
>> Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit
>> (Intel)] on win32
>> Type "help", "copyright", "credits" or "license" for more information.
>
> runfile('P:/sync.py', wdir='P:')
>>
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>   File
>> "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
>> line 699, in runfile
>> execfile(filename, namespace)
>>   File
>> "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py",
>> line 74, in execfile
>> exec(compile(scripttext, filename, 'exec'), glob, loc)
>>   File "P:/sync.py", line 50, in 
>> sync_files(src, dest)
>>   File "P:/sync.py", line 43, in sync_files
>> sync(dir_cmp)
>>   File "P:/sync.py", line 20, in sync
>> shutil.rmtree(f_right)
>>   File "C:\Python27\lib\shutil.py", line 236, in rmtree
>> onerror(os.listdir, path, sys.exc_info())
>>   File "C:\Python27\lib\shutil.py", line 234, in rmtree
>> names = os.listdir(path)
>> WindowsError: [Error 3] The system cannot find the path specified:
>> 'P:/mystuff\\Decock-2013-On the potential of d18O and d15N.pdf/*.*'
>>
>>
>> Here is my code to do this work: I am using this script to sync my
>> files between different disks.
>>
>> #coding=utf-8
>>
>> import filecmp, shutil, os, sys
>>
>> SRC = r'C:/Disk/mystuff'
>> DEST = r'P:/mystuff'
>>
>> IGNORE = ['Thumbs.db']
>>
>> def get_cmp_paths(dir_cmp, filenames):
>> return ((os.path.join(dir_cmp.left, f),
>> os.path.join(dir_cmp.right, f)) for f in filenames)
>>
>> def sync(dir_cmp):
>> for f_left, f_right in get_cmp_paths(dir_cmp, dir_cmp.right_only):
>> if os.path.isfile(f_right):
>> os.remove(f_right)
>> else:
>> shutil.rmtree(f_right)
>> print('delete %s' % f_right)
>> for f_left, f_right in get_cmp_paths(dir_cmp,
>> dir_cmp.left_only+dir_cmp.diff_files):
>> if os.path.isfile(f_left):
>> shutil.copy2(f_left, f_right)
>> else:
>> shutil.copytree(f_left, f_right)
>> print('copy %s' % f_left)
>> for sub_cmp_dir in dir_cmp.subdirs.values():
>> sync(sub_cmp_dir)
>>
>> def sync_files(src, dest, ignore=IGNORE):
>> if not os.path.exists(src):
>> print('= =b Please check the source directory was exist')
>> print('- -b Sync file failure !!!')
>> return
>> if os.path.isfile(src):
>> print('#_# We only support for sync directory but not a single
>> file,one file please do it by yourself')
>> print('- -b Sync file failure !!!')
>> return
>> if not os.path.exists(dest):
>> os.makedirs(dest)
>> dir_cmp = filecmp.dircmp(src, dest, ignore=IGNORE)
>> sync(dir_cmp)
>> print('^_^ Sync file finished!')
>>
>> if __name__ == '__main__':
>> src, dest = SRC, DEST
>> if len(sys.argv) == 3:
>> src, dest = sys.argv[1:3]
>> sync_files(src, dest)
>>
> [snip]
> You're using bytestrings (str). As soon as you step out of the ASCII
> range, you can face problems with which encoding it's using.
>
> The simplest fix is to switch to using Unicode.
>
> Start with this change:
>
> SRC = ur'C:/Disk/mystuff'
> DEST = ur'P:/mystuff'
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Jianling Fan
樊建凌
-- 
https://mail.python.org/mailman/listinfo/python-list


How to fill in abbreviation in one column based on state name in another column?

2016-04-30 Thread David Shi via Python-list
I am trying to use apply to execute a lookup function, so that we can put 
abbreviation in a new column, in accordance to a state name in another column.
Does anyone knows how to make this to work?
Regards.
David
state_to_code = {"VERMONT": "VT", "GEORGIA": "GA", "IOWA": "IA", "Armed Forces 
Pacific": "AP", "GUAM": "GU",                 "KANSAS": "KS", "FLORIDA": "FL", 
"AMERICAN SAMOA": "AS", "NORTH CAROLINA": "NC", "HAWAII": "HI",                 
"NEW YORK": "NY", "CALIFORNIA": "CA", "ALABAMA": "AL", "IDAHO": "ID", 
"FEDERATED STATES OF MICRONESIA": "FM",                 "Armed Forces 
Americas": "AA", "DELAWARE": "DE", "ALASKA": "AK", "ILLINOIS": "IL",            
     "Armed Forces Africa": "AE", "SOUTH DAKOTA": "SD", "CONNECTICUT": "CT", 
"MONTANA": "MT", "MASSACHUSETTS": "MA",                 "PUERTO RICO": "PR", 
"Armed Forces Canada": "AE", "NEW HAMPSHIRE": "NH", "MARYLAND": "MD", "NEW 
MEXICO": "NM",                 "MISSISSIPPI": "MS", "TENNESSEE": "TN", "PALAU": 
"PW", "COLORADO": "CO", "Armed Forces Middle East": "AE",                 "NEW 
JERSEY": "NJ", "UTAH": "UT", "MICHIGAN": "MI", "WEST VIRGINIA": "WV", 
"WASHINGTON": "WA",                 "MINNESOTA": "MN", "OREGON": "OR", 
"VIRGINIA": "VA", "VIRGIN ISLANDS": "VI", "MARSHALL ISLANDS": "MH",             
    "WYOMING": "WY", "OHIO": "OH", "SOUTH CAROLINA": "SC", "INDIANA": "IN", 
"NEVADA": "NV", "LOUISIANA": "LA",                 "NORTHERN MARIANA ISLANDS": 
"MP", "NEBRASKA": "NE", "ARIZONA": "AZ", "WISCONSIN": "WI", "NORTH DAKOTA": 
"ND",                 "Armed Forces Europe": "AE", "PENNSYLVANIA": "PA", 
"OKLAHOMA": "OK", "KENTUCKY": "KY", "RHODE ISLAND": "RI",                 
"DISTRICT OF COLUMBIA": "DC", "ARKANSAS": "AR", "MISSOURI": "MO", "TEXAS": 
"TX", "MAINE": "ME"}
#table['moa_state_name'] = map(lambda x: x.upper(), table['moa_state_name'])def 
convert_state(row):    abbrev1 =  state_to_code(table['moa_state_name']) 
#'aatest'    if abbrev1:         return abbrev1 ##state_to_code[abbrev[0]]    
return np.nan#print convert_state(table['moa_state_name'])
table.insert(0, "abbrev", np.nan)table['abbrev'] = table.apply(convert_state, 
axis=1)
print state_to_code['ARKANSAS']
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to fill in abbreviation in one column based on state name in another column?

2016-04-30 Thread Joel Goldstick
could you post in plaintext as its really hard to figure out what your
code is doing

On Sat, Apr 30, 2016 at 4:40 PM, David Shi via Python-list
 wrote:
> I am trying to use apply to execute a lookup function, so that we can put 
> abbreviation in a new column, in accordance to a state name in another column.
> Does anyone knows how to make this to work?
> Regards.
> David
> state_to_code = {"VERMONT": "VT", "GEORGIA": "GA", "IOWA": "IA", "Armed 
> Forces Pacific": "AP", "GUAM": "GU", "KANSAS": "KS", 
> "FLORIDA": "FL", "AMERICAN SAMOA": "AS", "NORTH CAROLINA": "NC", "HAWAII": 
> "HI", "NEW YORK": "NY", "CALIFORNIA": "CA", "ALABAMA": "AL", 
> "IDAHO": "ID", "FEDERATED STATES OF MICRONESIA": "FM", "Armed 
> Forces Americas": "AA", "DELAWARE": "DE", "ALASKA": "AK", "ILLINOIS": "IL",   
>   "Armed Forces Africa": "AE", "SOUTH DAKOTA": "SD", 
> "CONNECTICUT": "CT", "MONTANA": "MT", "MASSACHUSETTS": "MA", 
> "PUERTO RICO": "PR", "Armed Forces Canada": "AE", "NEW HAMPSHIRE": "NH", 
> "MARYLAND": "MD", "NEW MEXICO": "NM", "MISSISSIPPI": "MS", 
> "TENNESSEE": "TN", "PALAU": "PW", "COLORADO": "CO", "Armed Forces Middle 
> East": "AE", "NEW JERSEY": "NJ", "UTAH": "UT", "MICHIGAN": 
> "MI", "WEST VIRGINIA": "WV", "WASHINGTON": "WA", "MINNESOTA": 
> "MN", "OREGON": "OR", "VIRGINIA
 ": "VA", "VIRGIN ISLANDS": "VI", "MARSHALL ISLANDS": "MH", 
"WYOMING": "WY", "OHIO": "OH", "SOUTH CAROLINA": "SC", "INDIANA": "IN", 
"NEVADA": "NV", "LOUISIANA": "LA", "NORTHERN MARIANA ISLANDS": 
"MP", "NEBRASKA": "NE", "ARIZONA": "AZ", "WISCONSIN": "WI", "NORTH DAKOTA": 
"ND", "Armed Forces Europe": "AE", "PENNSYLVANIA": "PA", 
"OKLAHOMA": "OK", "KENTUCKY": "KY", "RHODE ISLAND": "RI", 
"DISTRICT OF COLUMBIA": "DC", "ARKANSAS": "AR", "MISSOURI": "MO", "TEXAS": 
"TX", "MAINE": "ME"}
> #table['moa_state_name'] = map(lambda x: x.upper(), 
> table['moa_state_name'])def convert_state(row):abbrev1 =  
> state_to_code(table['moa_state_name']) #'aatest'if abbrev1: 
> return abbrev1 ##state_to_code[abbrev[0]]return np.nan#print 
> convert_state(table['moa_state_name'])
> table.insert(0, "abbrev", np.nan)table['abbrev'] = table.apply(convert_state, 
> axis=1)
> print state_to_code['ARKANSAS']
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to fill in abbreviation in one column based on state name in another column?

2016-04-30 Thread Bob Gailer
1) Your code seems to be missing a lot.
2) it's better to post a small sample of the dictionary rather than the
whole thing.
3) remove the comments that don't seem to say anything useful.
4) tell us what problems you are having
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What should Python apps do when asked to show help?

2016-04-30 Thread cs

On 30Apr2016 13:23, Steven D'Aprano  wrote:

On Sat, 30 Apr 2016 12:49 pm, Ben Finney wrote:

Random832  writes:

On Fri, Apr 29, 2016, at 22:27, Rustom Mody wrote:
> Instead it does some ½-assed fall-between-the-stools of both

That doesn't answer the question of why, if you (Well, Ethan, but
you're taking the same position here) hate pagers so much


That's not a question relevant here; nobody inthe discussion has a
position fairly characterised as “hate pagers so much”. So you're
arguing against a straw man.

Rather, the position being argued is that they *do* like pagers; they
like pagers enough that they want the existing ‘PAGER’ environment
variable setting to remain untouched.


So they want the PAGER environment variable to specify what pager they
want...


_When_ they want a pager.


And, simulatenously, they want
Python's help to not use a pager at the interactive prompt.


...so long as applications don't actually make use of that PAGER environment
variable to determine the pager they want to use.


_When_ it is asked to use a pager.

What they (and, very often, me) want is that most things, including pydoc, to 
_NOT_ invoke a pager automatically, _unasked_.


So tools which page without asking are unwelcome, because that requires a mode 
switch when everything else (sed/grep/print/write/ls) do straight up unpaged 
output.



(1) If you want man, and nothing else in the universe, to automatically use
a pager, then set MANPAGER="less" (or whatever you wish to use), and unset
PAGER.

(2) If you don't want *anything* to use a pager, then unset both MANPAGER
and PAGER. You may have to report a feature request / bug report for
applications which force their own pager.

(3) In Python specifically, you can trivially and easily tell help() to
output directly to stdout. (At least on Linux, I haven't tested it
elsewhere.) Simply use PAGER=cat on the command line you use to launch the
interactive environment. This will affect no other running or future
processes (apart from subprocesses launched from your interactive Python
session), allowing you to keep your PAGER for everything else.

(4) If you want more than that, then patches are welcome :-)


This requires terrible domain specific knowledge. What about programs other 
than man?


And setting PAGER=cat before invoking interactive python is no better, because 
it will screw with $PAGER in any subprocess spawned from that environment.


What those of use in the "my terminal emulator scrolls nicely thank you" camp 
want is that most command line things, when asked to simply print some help 
text, _print_ it and do not page it. And often would like a way to tell pydoc 
to not page, such as a pydoc specific switch (possibly an environment 
variable).



Seriously, I'm thinking that a keyword argument to help might be useful:

help(object, pager=None)

where:
- pager=None gives the current behaviour;
- pager="foo" calls out to the external program "foo";
- pager=callable passes the help text to callable().


I'd be asking for pager=None to look at help.default_pager, which itself might 
obey your rules above. That way help.default_pager can be a callable which 
consults $PAGER or falls back to some inbuilt pager (presumably as now), but 
which a user can sumply go:


 help.default_pager=None

at the Python prompt and have unpaged output from there on.


I think that would make it easier to test help(). Thoughts?


Yes it would. I'm +1 _provided_ the user can set a global to tune the default 
mode, as otherwise it burdens the user with saying:


 help(foo, stdout.write)   # or "print" ?

whenever they want help. Not helpful!

Let me recite one of my favourite rules of thumb:

 If it can't be turned off, it's not a feature. - Karl Heuer

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: What should Python apps do when asked to show help?

2016-04-30 Thread cs

On 29Apr2016 11:40, Steven D'Aprano  wrote:

On Fri, 29 Apr 2016 07:08 am, Grant Edwards wrote:

On 2016-04-28, Random832  wrote:

On Thu, Apr 28, 2016, at 15:39, Grant Edwards wrote:

That's fine.  If you want two or three forms of documentation then you
prepare two or three forms of documentation.

Adding an option to run the default 'help' output through a pager or
display it in a web browser doesn't somehow force you "to compose two
forms of documentation" unless you want two forms of documentation.


The point is that having "help" output at all (beyond either a cursory
"see the manpage") implies two forms of documentation (given you already
have a manpage), and some people choose not to do that, instead
launching directly into the manpage (which implies using a pager)


But I'm saying that having --help output the manpage should not imply
using a pager.



What manpage? I don't have a manpage. The only help my application has is
whatever it outputs (which it gets from its docstring).

What is a good place where I can find out more about writing manpages?


"man 5 man"? Describes the internal format of man pages (the [ntg]roff -man 
macro set). Many people use an intermediate more human friendly format and use 
a tool to transcribe -man format text. For standalone things I find Perl's 
"POD" format fairly easy to use (the pod2man tool itself does have shortcomings 
though).



If --help is going to output the manpage, then I'm saying it can (and
should) be written to stdout without use of pager (and it shouldn't
have escape sequences or backspaces in it either).  The Unix way is
that the output from whatever --help should be plain text written to
stdout (regardless of length).


Agree. The -h/--help option will output plain text to stdout.


Yay.


If you want to output the man page, this can be accomplished simply by
doing someting like:
  os.environ["GROFF_NO_SGR"] = "1";
  os.system("man -Tascii mycmd | col -bx");


That doesn't work for me:
[steve@ando ~]$ man -Tasciii rm
man: invalid option -- T


Yes, it is nonportable. Presumes groff possibly, and GNU "man".


However, this almost works:

man -Pcat rm

appears to output unformatted, plain text to stdout.


As should:

 man rm | cat

without obscure options.


However, if you capture
the output (say, to a file) you'll see it is full of backspaces, e.g.:

N^HNA^HAM^HME^HE
  rm - remove files or directories

S^HSY^HYN^HNO^HOP^HPS^HSI^HIS^HS
  r^Hrm^Hm [_^HO_^HP_^HT_^HI_^HO_^HN]... _^HF_^HI_^HL_^HE...


Yes.


instead of

NAME
   rm - remove files or directories

[...]


Apparently `less` understands overstriking and displays it as bold (or
underlining in the case of _^H. That's very clever, but how do I get actual
plain text out of `man` without the backspaces?


That is what Grant Edwards' "col -bx" does. (Actually, col can do more, because 
tables also do funky things; let us not go there.)


But removing the overstriking is pretty easy even without col. My "unbs" script 
does it, and its core operation is this:


 s/[^^H]^H//g

Those ^Hs are literal backspace characters: remove any non-backspace followed 
by a backspace. Full script here:


 https://bitbucket.org/cameron_simpson/css/src/tip/bin/unbs


If I want the --help output run through a pager, I'll do it myself.


Easy enough to say for Linux/Unix users, but there are those who might not
have a pager that is easy to use, or at all. pydoc goes to considerable
trouble to work out the best pager available for your platform, falling
back to its own if needed. To use that is literally a two liner:

import pydoc
pydoc.pager(HELPTEXT)


Aye, but what is wanted by some of us is an easy incantation to tune that to 
plain old sys.stdout.write in some flavour.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: What should Python apps do when asked to show help?

2016-04-30 Thread Random832
On Sat, Apr 30, 2016, at 19:51, c...@zip.com.au wrote:
> _When_ they want a pager.

Why would they need an environment variable at all in that case, rather
than explicitly invoking the pager by name?

To me, *not* having PAGER=cat signifies that someone *does* want a
pager. That may be a crappy convention, but it's the one we're stuck
with.

> And setting PAGER=cat before invoking interactive python is no better,
> because 
> it will screw with $PAGER in any subprocess spawned from that
> environment.

But why would you not *also* want PAGER=cat in those subprocesses? You
don't want those things to spawn pagers that you haven't asked
explicitly for, either, right?

I don't get the "It's terrible if I run man or git it won't open a
pager, but I don't want pydoc to use a pager" viewpoint. It just doesn't
make any sense to me.

> Let me recite one of my favourite rules of thumb:
> 
>   If it can't be turned off, it's not a feature. - Karl Heuer

You turn it off by setting PAGER=cat. The fact that pydoc uses a pager
is the *same* feature as the fact that git and man do.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What should Python apps do when asked to show help?

2016-04-30 Thread Grant Edwards
On 2016-05-01, Random832  wrote:
> On Sat, Apr 30, 2016, at 19:51, c...@zip.com.au wrote:
>> _When_ they want a pager.
>
> Why would they need an environment variable at all in that case, rather
> than explicitly invoking the pager by name?

We don't want to use a PAGER variable to specify when we want a pager
and when we don't want a pager.  If we want a pager we append "| less"
to the command.  If we don't want a pager, we don't append that to the
command.

For historical reasons, "man" invokes a pager by default.  I'm not
crazy about that. If you want to argue that it's being inconsistent
then you're right: man shouldn't invoke a pager either.

-- 
Grant

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


Re: What should Python apps do when asked to show help?

2016-04-30 Thread Random832
On Sat, Apr 30, 2016, at 22:30, Grant Edwards wrote:
> We don't want to use a PAGER variable to specify when we want a pager
> and when we don't want a pager.  If we want a pager we append "| less"
> to the command.  If we don't want a pager, we don't append that to the
> command.

Setting PAGER=cat - permanently, in your profile, and never ever
changing it - gives this result, yet it's described by some people here
as "So I have to cripple my shell [...]?" What is crippled? Evidently
you're not "we", since this "crippled" state of affairs seems to be a
perfectly acceptable one to you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What should Python apps do when asked to show help?

2016-04-30 Thread Steven D'Aprano
On Sun, 1 May 2016 09:51 am, c...@zip.com.au wrote:

> Let me recite one of my favourite rules of thumb:
> 
> If it can't be turned off, it's not a feature. - Karl Heuer


My microwave oven has a safety lock which prevents the mechanism from
operating (generating microwaves) while the door is open. Since I can't
turn it off, it is not a feature! What if I want to stick my head in the
microwave and cook it?

*wink*


Often-wanting-to-microwave-somebody-else's-head-ly y'rs,



-- 
Steven

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


Re: What should Python apps do when asked to show help?

2016-04-30 Thread cs

On 30Apr2016 23:46, Random832  wrote:

On Sat, Apr 30, 2016, at 22:30, Grant Edwards wrote:

We don't want to use a PAGER variable to specify when we want a pager
and when we don't want a pager.  If we want a pager we append "| less"
to the command.  If we don't want a pager, we don't append that to the
command.


Setting PAGER=cat - permanently, in your profile, and never ever
changing it - gives this result, yet it's described by some people here
as "So I have to cripple my shell [...]?" What is crippled? Evidently
you're not "we", since this "crippled" state of affairs seems to be a
perfectly acceptable one to you.


This is an interesting argument.

Yes, PAGER=cat would make "man" also not page, and likely almost everything.  
And yet I am unwilling to do so. Why?


On reflection, my personal problems with this approach are twofold:

- I want $PAGER to specify my preferred pager when I do want a pager, so 
  setting it to "cat" does not inform apps about my wishes


- in an interactive shell, yes I can type "| less"; it seems painful (oh for 
  the happy days of yore when this was spelt "|pg":-)


I am going to try PAGER=cat as an experiment to seem how it feels. Now, I _do_ 
wish "man" to page for a number of reasons (a) my brain expects it (b) I like 
the nice colour highlighting of headings etc (c) manual pages and other 
_lengthy_ documents _are_ better paged than not. This last is in contrast to 
"help" messages, even lengthy usage messages: these are short enough that I 
feel they should not be paged, and if I come across a glaring exception i can 
always page them myself.


Fortunately for me, I am already in the position of mucking with "man"; my 
despite for GNU info with its weird non-paging browser and the accompanying GNU 
manual pages which all too frequently say "man is defunct, go look in info - we 
don't bother with man" drove me to rewrite "man" to try to suck in info files 
into flat pagable text. So telling my shell this:


 man(){ PAGER=less command man ${1+"$@"}; }

is no hardship.

I'll give this a go and see how it feels.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: What should Python apps do when asked to show help?

2016-04-30 Thread Chris Angelico
On Sun, May 1, 2016 at 3:24 PM,   wrote:
> Yes, PAGER=cat would make "man" also not page, and likely almost everything.
> And yet I am unwilling to do so. Why?
>
> On reflection, my personal problems with this approach are twofold:
>
> - I want $PAGER to specify my preferred pager when I do want a pager, so
> setting it to "cat" does not inform apps about my wishes

So you expect the environment variable to say which of multiple pagers
you might want, but only when you already want a pager. Okay. How is
an app supposed to know whether or not to use a pager? How do you
expect them to mindread?

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