ANN: pandas v0.15.1

2014-11-09 Thread Jeff Reback
Hello,

We are proud to announce v0.15.1 of pandas, a minor release from 0.15.0.

This release includes a small number of API changes, several new features,
enhancements, and performance improvements along with a large number of bug
fixes.

This was a short release of 3 weeks with 59 commits by 20 authors
encompassing 87 issues.

We recommend that all users upgrade to this version.

For a more a full description of Whatsnew for v0.15.1 here:
http://pandas.pydata.org/pandas-docs/stable/whatsnew.html

*What is it:*

*pandas* is a Python package providing fast, flexible, and expressive data
structures designed to make working with “relational” or “labeled” data both
easy and intuitive. It aims to be the fundamental high-level building block
for
doing practical, real world data analysis in Python. Additionally, it has
the
broader goal of becoming the most powerful and flexible open source data
analysis / manipulation tool available in any language.


Documentation:
http://pandas.pydata.org/pandas-docs/stable/

Source tarballs, windows binaries are available on PyPI:
https://pypi.python.org/pypi/pandas

windows binaries are courtesy of  Christoph Gohlke and are built on Numpy
1.8
macosx wheels will be available soon, courtesy of Matthew Brett

Please report any issues here:
https://github.com/pydata/pandas/issues


Thanks

The Pandas Development Team


Contributors to the 0.15.1 release

   -
   - Aaron Staple
   - Andrew Rosenfeld
   - Anton I. Sipos
   - Artemy Kolchinsky
   - Bill Letson
   - Dave Hughes
   - David Stephens
   - Guillaume Horel
   - Jeff Reback
   - Joris Van den Bossche
   - Kevin Sheppard
   - Nick Stahl
   - Sanghee Kim
   - Stephan Hoyer
   - TomAugspurger
   - WANG Aiyong
   - behzad nouri
   - immerrr
   - jnmclarty
   - jreback
   - pallav-fdsi
   - unutbu
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


ANN: pandas v0.15.1

2014-11-09 Thread Jeff Reback
Hello,

We are proud to announce v0.15.1 of pandas, a minor release from 0.15.0.

This release includes a small number of API changes, several new features,
enhancements, and performance improvements along with a large number of bug
fixes.

This was a short release of 3 weeks with 59 commits by 20 authors
encompassing 87 issues.

We recommend that all users upgrade to this version.

For a more a full description of Whatsnew for v0.15.1 here:
http://pandas.pydata.org/pandas-docs/stable/whatsnew.html

*What is it:*

*pandas* is a Python package providing fast, flexible, and expressive data
structures designed to make working with “relational” or “labeled” data both
easy and intuitive. It aims to be the fundamental high-level building block
for
doing practical, real world data analysis in Python. Additionally, it has
the
broader goal of becoming the most powerful and flexible open source data
analysis / manipulation tool available in any language.


Documentation:
http://pandas.pydata.org/pandas-docs/stable/

Source tarballs, windows binaries are available on PyPI:
https://pypi.python.org/pypi/pandas

windows binaries are courtesy of  Christoph Gohlke and are built on Numpy
1.8
macosx wheels will be available soon, courtesy of Matthew Brett

Please report any issues here:
https://github.com/pydata/pandas/issues


Thanks

The Pandas Development Team


Contributors to the 0.15.1 release

   -
   - Aaron Staple
   - Andrew Rosenfeld
   - Anton I. Sipos
   - Artemy Kolchinsky
   - Bill Letson
   - Dave Hughes
   - David Stephens
   - Guillaume Horel
   - Jeff Reback
   - Joris Van den Bossche
   - Kevin Sheppard
   - Nick Stahl
   - Sanghee Kim
   - Stephan Hoyer
   - TomAugspurger
   - WANG Aiyong
   - behzad nouri
   - immerrr
   - jnmclarty
   - jreback
   - pallav-fdsi
   - unutbu
-- 
https://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: How do i reduce this to a single function - the code is largely similar, just a direction of search toggle.

2014-11-09 Thread Veek M
Ned Batchelder wrote:

 On 11/7/14 9:52 AM, Veek M wrote:
 and you want to end up on the def token, not the def in

yep, bumped into this :) thanks!

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


functools documentation - help with funny words

2014-11-09 Thread Veek M
https://docs.python.org/3.4/library/functools.html

1. A key function is a callable that accepts one argument and returns 
another value indicating the position in the desired collation sequence.

x = ['x','z','q']; sort(key=str.upper)

My understanding is that, x, y, .. are passed to the key function which 
converts it to upper case and returns the value, which is then sorted.
So what does he mean by 'position in the desired...? Position is 0, 1, 2..

upper is 'normalizing' the input and then sort gathers the values and sorts 
them.. so where is the 'key' function returning a position in the sorted-
list.. or whatever.. what does a key function do?

2. lru_cache

Since a dictionary is used to cache results, the positional and keyword 
arguments to the function must be hashable.

basically says that the args must be immutable and not subject to change 
because he's using the args as part of a key to the result?

To help measure the effectiveness of the cache and tune the maxsize 
parameter, the wrapped function is instrumented with a cache_info() function 
that returns a named tuple showing hits, misses, maxsize and currsize

What does he mean by 'instrument'? Just a 'helper' function or is it nested 
in lru_cache or structured in some special way.

An LRU (least recently used) cache works best when the most recent calls 
are the best predictors of upcoming calls (for example, the most popular 
articles on a news server tend to change each day).

What? So if article1 changes.. how does that predict anything..? If article1 
is most popular, you want it in the cache, but it'll become most popular 
only after some time.. or is he saying that popular articles must be kicked 
out off the cache at the end of 24hrs?






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


dictionary issue for formatted print

2014-11-09 Thread Yusuf Can Bayrak
when dictionary has one value for each key it's okey. I'm just type '%
greek_letters' and it's working.

But how can i assign dict's values to formatted print, if it has more
values than one.


1. # -*- coding: utf-8 -*-
2. greek_letters = {
3. 'omega': ['ω','Ω'], 'psi': ['ψ', 'Ψ'] , 'kapa':
'κ', 'to': ['τ', 'Τ'], 'lambda': ['λ', 'Λ'],
4. 'ksi': ['ξ', 'Ξ'], 'delta': ['δ', 'Δ'], 'mu':
['μ'], 'sigma': ['σ', 'Σ'], 'epsilon': ['ε', 'Ε'],
5. 'gamma': ['γ', 'Γ'], 'phi': ['φ', 'Φ'],
'theta': ['θ', 'Θ']
6. }
7. print 'x(%(to)s) = A * cos(%(omega)s * %(to)s + %(theta)s)' %
greek_letters.values()[1]


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


What is description attribute in python?

2014-11-09 Thread satishmlmlml
What does description attribute in the following code mean?

curs.execute('select * from people')
colnames = [desc[0] for desc in curs.description]

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


What does zip mean?

2014-11-09 Thread satishmlmlml
What does zip return in the following piece of code?

curs.execute('select * from people')
colnames = [desc[0] for desc in curs.description]
rowdicts = []
for row in curs.fetchall():
   rowdicts.append(dict(zip(colnames, row)))

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


Re: What is description attribute in python?

2014-11-09 Thread Steven D'Aprano
satishmlm...@gmail.com wrote:

 What does description attribute in the following code mean?
 
 curs.execute('select * from people')
 colnames = [desc[0] for desc in curs.description]

It's an attribute called description. You would need to read the
documentation for curs to know what it does.

What is curs? Where does it come from?


-- 
Steven

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


Re: What does zip mean?

2014-11-09 Thread Steven D'Aprano
satishmlm...@gmail.com wrote:

 What does zip return in the following piece of code?

Have you read the Fine Manual?

In Python 2, zip returns a list:

zip(['a', 'b', 'c'], [1, 2, 3])

= [('a', 1), ('b', 2), ('c', 3)]

https://docs.python.org/2/library/functions.html#zip


In Python 3, zip does the same, except instead of a list, it returns a
special iterator which produces the items on demand rather than in advance.

https://docs.python.org/3/library/functions.html#zip



 curs.execute('select * from people')
 colnames = [desc[0] for desc in curs.description]
 rowdicts = []
 for row in curs.fetchall():
rowdicts.append(dict(zip(colnames, row)))

zip(colnames, row) will return:

(first column name, first item of row),
(second column name, second item of row),
(third column name, third item of row),
etc.



-- 
Steven

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


Re: What does zip mean?

2014-11-09 Thread milos zorica
sorry my bad

On Sun, Nov 9, 2014 at 7:58 AM, Steven D'Aprano 
steve+comp.lang.pyt...@pearwood.info wrote:

 satishmlm...@gmail.com wrote:

  What does zip return in the following piece of code?

 Have you read the Fine Manual?

 In Python 2, zip returns a list:

 zip(['a', 'b', 'c'], [1, 2, 3])

 = [('a', 1), ('b', 2), ('c', 3)]

 https://docs.python.org/2/library/functions.html#zip


 In Python 3, zip does the same, except instead of a list, it returns a
 special iterator which produces the items on demand rather than in advance.

 https://docs.python.org/3/library/functions.html#zip



  curs.execute('select * from people')
  colnames = [desc[0] for desc in curs.description]
  rowdicts = []
  for row in curs.fetchall():
 rowdicts.append(dict(zip(colnames, row)))

 zip(colnames, row) will return:

 (first column name, first item of row),
 (second column name, second item of row),
 (third column name, third item of row),
 etc.



 --
 Steven

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




-- 
Milos Zorica
+1 845 277 0549 | +1 786 471 4846
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is description attribute in python?

2014-11-09 Thread satishmlmlml
curs is coming from the following piece of code

import sqlite3
conn = sqlite3.connect('dbase1')
curs = conn.cursor()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is description attribute in python?

2014-11-09 Thread Deepfriedice

On 09/11/14 20:59, Steven D'Aprano wrote:

It's an attribute called description. You would need to read the
documentation for curs to know what it does.

What is curs? Where does it come from?


It looks like a cursor from an SQL DB library.
For example, sqlite3 in the standard library provides a 
Cursor.description attribute:


https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.description
 This read-only attribute provides the column names of the last query. 
 To remain compatible with the Python DB API, it returns a 7-tuple for 
 each column where the last six items of each tuple are None.


 It is set for SELECT statements without any matching rows as well.

You'll have to read the documentation from the library you're using to 
determine what it actually does.

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


What is rstrip() in python?

2014-11-09 Thread satishmlmlml
What is rstrip() in python?

What does it do in the following piece of code?

import sqlite3
conn = sqlite3.connect('dbase1')
curs = conn.cursor()

file = open('data.txt')
rows = [line.rstrip().split(',') for line in file]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is rstrip() in python?

2014-11-09 Thread Chris Angelico
On Sun, Nov 9, 2014 at 10:11 PM,  satishmlm...@gmail.com wrote:
 What is rstrip() in python?

 What does it do in the following piece of code?

 import sqlite3
 conn = sqlite3.connect('dbase1')
 curs = conn.cursor()

 file = open('data.txt')
 rows = [line.rstrip().split(',') for line in file]

Do you know what type of object 'line' is here? Do you know what you
get when you iterate over a file?

Get an object of that type in the interactive interpreter, maybe like this:

file = open('data.txt')
line = next(file)

Then you can find out about its methods:

help(line.rstrip)

That should tell you what you want to know.

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


Re: [Python-Dev] Dinamically set __call__ method

2014-11-09 Thread Gregory Ewing

Ethan Furman wrote:
And the thing going on is the normal python behavior (in 
__getattribute__, I believe) of examining the returned attribute to see 
if it is a descriptor, and if so invoking it.


Only if you look it up through the instance, though.
Normally, if you look up an attribute on a class,
the descriptor protocol doesn't get triggered.

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


Engaging, powerful - video inspriration/learning - Your best selections

2014-11-09 Thread flebber
Not fans of videos hey(well python videos anyway) bugger.

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


Re: What is description attribute in python?

2014-11-09 Thread Tim Chase
On 2014-11-09 02:42, satishmlm...@gmail.com wrote:
 What does description attribute in the following code mean?
 
 curs.execute('select * from people')
 colnames = [desc[0] for desc in curs.description]

http://legacy.python.org/dev/peps/pep-0249/#cursor-attributes

-tkc




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


Re: Syncing audio and video for casual recording

2014-11-09 Thread Steven D'Aprano
posted  mailed

Tobiah wrote:

 I decided I'd like to publish some youtube videos of me playing
 an instrument.  The audio being the important bit, I'd like to use
 my existing mics, which I've been sending through a USB audio interface
 to my computer.
 
 I don't have any camera yet, other than a prosumer digital
 camera that does take decent video.  The problem that I'm
 anticipating is the syncing of audio and video.
[...]


I think you may have sent this to the wrong mailing list (or newsgroup).
This is about the Python programming language.



-- 
Steven

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


Re: What is rstrip() in python?

2014-11-09 Thread Steven D'Aprano
satishmlm...@gmail.com wrote:

 What is rstrip() in python?

Have you read the Fine Manual?

Did you try googling first?

https://duckduckgo.com/html/?q=python+rstrip


 What does it do in the following piece of code?

It removes trailing whitespace.


 import sqlite3
 conn = sqlite3.connect('dbase1')
 curs = conn.cursor()
 
 file = open('data.txt')
 rows = [line.rstrip().split(',') for line in file]


-- 
Steven

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


Re: [Python-Dev] Dinamically set __call__ method

2014-11-09 Thread Steven D'Aprano
Gregory Ewing wrote:

 Ethan Furman wrote:
 And the thing going on is the normal python behavior (in
 __getattribute__, I believe) of examining the returned attribute to see
 if it is a descriptor, and if so invoking it.
 
 Only if you look it up through the instance, though.
 Normally, if you look up an attribute on a class,
 the descriptor protocol doesn't get triggered.

Since this whole thread is about giving instances their own individual
__call__ methods, I don't think that doing the look-up on the class is part
of the requirements :-)

This seems to work for me:



class call_instance(object):
def __get__(self, obj, cls=None):
if cls is None:  cls = type(obj)
if obj is None:  obj = cls
return obj.my_call

class SomeClass(object):
__call__ = call_instance()


a = SomeClass()
b = SomeClass()
c = SomeClass()
c.eggs = 23

from types import MethodType
a.my_call = lambda x, y=1: x/y
b.my_call = lambda spam: str(spam).upper()
c.my_call = MethodType(lambda self: self.eggs + 1, c)




-- 
Steven

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


Re:dictionary issue for formatted print

2014-11-09 Thread Dave Angel
Yusuf Can Bayrak yusufcanbay...@gmail.com Wrote in message:
 when dictionary has one value for each key it's okey. I'm just type '% 
 greek_letters' and it's working. 
 
 But how can i assign dict's values to formatted print, if it has more values 
 than one. # -*- coding: utf-8 -*-greek_letters = {
 'omega': ['ω','Ω'], 'psi': ['ψ', 'Ψ'] , 'kapa': 'κ', 'to': ['τ', 'Τ'], 
 'lambda': ['λ', 'Λ'],'ksi': ['ξ', 'Ξ'], 'delta': ['δ', 
 'Δ'], 'mu': ['μ'], 'sigma': ['σ', 'Σ'], 'epsilon': ['ε', 'Ε'],
 'gamma': ['γ', 'Γ'], 'phi': ['φ', 'Φ'], 'theta': ['θ', 'Θ']   
  }print 'x(%(to)s) = A * cos(%(omega)s * %(to)s + %(theta)s)' % 
 greek_letters.values()[1]
 

How do you intend for the logic to choose? You need to decide the
 logic  (usually by doing it by hand) before you can figure out
 how to code it.

My assumption is that you want the expression to decide  (the
 thing starting A *
). So you'll need to have two separate keys,
 like omega and Omega. The dictionary gets a little larger,  and
 it just works.

-- 
DaveA

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


Re: What is description attribute in python?

2014-11-09 Thread Mark Lawrence

On 09/11/2014 11:05, satishmlm...@gmail.com wrote:

curs is coming from the following piece of code

import sqlite3
conn = sqlite3.connect('dbase1')
curs = conn.cursor()



Today's exercise is to find the documentation and read it before posting 
another question.  Better still is to use the interactive prompt to run 
the above and the help facility at the same time. IMHO this is the best 
possible way to learn Python.


--
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: What is rstrip() in python?

2014-11-09 Thread Mark Lawrence

On 09/11/2014 11:11, satishmlm...@gmail.com wrote:

What is rstrip() in python?


It's a function or method call.



What does it do in the following piece of code?


I'm not actually sure.  Would you be kind enough to look it up in the 
documentation for me and let me know, thanks?




import sqlite3
conn = sqlite3.connect('dbase1')
curs = conn.cursor()

file = open('data.txt')
rows = [line.rstrip().split(',') for line in file]



--
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: dictionary issue for formatted print

2014-11-09 Thread Peter Otten
Yusuf Can Bayrak wrote:

 when dictionary has one value for each key it's okey. I'm just type '%
 greek_letters' and it's working.
 
 But how can i assign dict's values to formatted print, if it has more
 values than one.
 

1. # -*- coding: utf-8 -*-
2. greek_letters = {
3. 'omega': ['ω','Ω'], 'psi': ['ψ', 'Ψ'] , 'kapa':
'κ', 'to': ['τ', 'Τ'], 'lambda': ['λ', 'Λ'],
4. 'ksi': ['ξ', 'Ξ'], 'delta': ['δ', 'Δ'], 'mu':
['μ'], 'sigma': ['σ', 'Σ'], 'epsilon': ['ε', 'Ε'],
5. 'gamma': ['γ', 'Γ'], 'phi': ['φ', 'Φ'],
'theta': ['θ', 'Θ']
6. }
7. print 'x(%(to)s) = A * cos(%(omega)s * %(to)s + %(theta)s)' %
greek_letters.values()[1]

You can build a temporary dict:

 greek_letters = {
... 'omega': ['ω','Ω'], 'to': ['τ', 'Τ'], 'theta': ['θ', 'Θ']}
 print 'x(%(to)s) = A * cos(%(omega)s * %(to)s + %(theta)s)' % {
... k: v[1] for k, v in greek_letters.items()}
x(Τ) = A * cos(Ω * Τ + Θ)

Python also offers an alternative style of formatting that allows 
subscripts:

 print 'x({to[0]}) = A * cos({omega[1]} * {to[0]} + {theta[1]})'.format(
... **greek_letters)
x(τ) = A * cos(Ω * τ + Θ)


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


Re: functools documentation - help with funny words

2014-11-09 Thread Ian Kelly
On Sun, Nov 9, 2014 at 2:06 AM, Veek M vek.m1...@gmail.com wrote:
 https://docs.python.org/3.4/library/functools.html

 1. A key function is a callable that accepts one argument and returns
 another value indicating the position in the desired collation sequence.

 x = ['x','z','q']; sort(key=str.upper)

This call isn't correct. sort is a list method, not a builtin.  So the
above should be:

 x = ['x', 'z', 'q']
 x.sort(key=str.upper)

 My understanding is that, x, y, .. are passed to the key function which
 converts it to upper case and returns the value, which is then sorted.
 So what does he mean by 'position in the desired...? Position is 0, 1, 2..

 upper is 'normalizing' the input and then sort gathers the values and sorts
 them.. so where is the 'key' function returning a position in the sorted-
 list.. or whatever.. what does a key function do?

When you pass a key function to the list.sort method, the key function
is called on each element of the list, and the return values are
compared to sort the list in place of the elements.  For example:

 sorted(['23', '4', '162'])
['162', '23', '4']

Because '162'  '23'  '4'.  But:

 sorted(['23', '4', '162'], key=int)
['4', '23', '162']

Because 4  23  162.

https://docs.python.org/3/glossary.html?highlight=%22key+function%22

 2. lru_cache

 Since a dictionary is used to cache results, the positional and keyword
 arguments to the function must be hashable.

 basically says that the args must be immutable and not subject to change
 because he's using the args as part of a key to the result?

https://docs.python.org/3/glossary.html?highlight=hashable

 To help measure the effectiveness of the cache and tune the maxsize
 parameter, the wrapped function is instrumented with a cache_info() function
 that returns a named tuple showing hits, misses, maxsize and currsize

 What does he mean by 'instrument'? Just a 'helper' function or is it nested
 in lru_cache or structured in some special way.

It means code added in some way to enable debugging or performance analysis.

http://en.wikipedia.org/wiki/Instrumentation_(computer_programming)

In this case it takes the form of a method added to the function object:

 @functools.lru_cache()
... def codepoint(s): return ord(s)
...
 list(map(codepoint, 'abracadabra'))
[97, 98, 114, 97, 99, 97, 100, 97, 98, 114, 97]
 codepoint.cache_info()
CacheInfo(hits=6, misses=5, maxsize=128, currsize=5)

 An LRU (least recently used) cache works best when the most recent calls
 are the best predictors of upcoming calls (for example, the most popular
 articles on a news server tend to change each day).

 What? So if article1 changes.. how does that predict anything..? If article1
 is most popular, you want it in the cache, but it'll become most popular
 only after some time.. or is he saying that popular articles must be kicked
 out off the cache at the end of 24hrs?

By predicts it means whether the fact that an item was recently
requested is positively correlated with the probability that it will
soon be requested again. Popular articles are an example of this; when
an article is requested, there is a good chance that it was requested
because it is featured or trending and will likely be requested again
soon.  On the other hand if the incoming requests tend to be random
and not correlated in time, then an LRU cache won't work as well. If
each request is negatively correlated with its probability of being
requested again soon (e.g. a graph traversal where some property is
being computed once for each node; once it's been computed for a
particular node, it won't be called with the same node again during
the same traversal), then an LRU cache may not perform well at all.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What is rstrip() in python?

2014-11-09 Thread Terry Reedy

On 11/9/2014 6:11 AM, satishmlm...@gmail.com wrote:

What is rstrip() in python?


The manuals have a rather complete index.  If 'rstrip' is missing from 
the index, let us know so we can fix it.


--
Terry Jan Reedy

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


Re: What is rstrip() in python?

2014-11-09 Thread Joel Goldstick
On Sun, Nov 9, 2014 at 12:46 PM, Terry Reedy tjre...@udel.edu wrote:
 On 11/9/2014 6:11 AM, satishmlm...@gmail.com wrote:

 What is rstrip() in python?

google on 'rstrip python' gets this at first link:
https://docs.python.org/2/library/stdtypes.html#str.rstrip

google is your friend.


 The manuals have a rather complete index.  If 'rstrip' is missing from the
 index, let us know so we can fix it.

 --
 Terry Jan Reedy

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



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


Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
Python script that does batch find and replace in txt files Need a python 
script that opens all .txt files in a folder find replace/delete text and save 
files.

I have text files and I need to perform below steps for each file. 

Step 1: Put cursor at start of file and Search for Contact's Name:. Delete 
all the rows before it.
Step 2: Put cursor at end of file, Search for Contact's Name: select option 
UP.
Step 3: Search for Photo of the Replace with blanks
Step 4: Search for Contact is Replace with blanks
Step 5: Search for Contact's Name: Replace with blanks
Step 6: Search for Age: Replace with blanks
Step 7: Search for Sex: Replace with blanks
Step 8: Search for House No: Replace with blanks
Step 9: Search for available Replace with blanks
Step 10: Remove Empty Lines Containing Blank Characters from file
Step 11: Trim Leading Space for each line
Step 12: Trim Trailing Space after each line
Step 13: Search for - (hyphen) Replace with _ (underscore)
Step 14: Save file.

Currently I have recorded a macro in Notepad++.
I open each file, run macro and save file.
As there are many files I was looking for a program to automate the process. 

I posted the same query in Notepad++ forum. I got a reply that it can be done 
by using Python script.

Kindly do the needful. 

Thank you.
khalidness

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


Re: [Python-Dev] Dinamically set __call__ method

2014-11-09 Thread Ethan Furman

On 11/09/2014 03:38 AM, Gregory Ewing wrote:

Ethan Furman wrote:


And the thing going on is the normal python behavior (in __getattribute__, I 
believe) of examining the returned
attribute to see if it is a descriptor, and if so invoking it.


Only if you look it up through the instance, though.
Normally, if you look up an attribute on a class,
the descriptor protocol doesn't get triggered.


Hrmm, maybe we're not talking about the same thing.  I was responding to your 
comment:


(BTW, I'm actually surprised that this technique makes c callable.
There must be more going on that just look up __call__ in the class
object, because evaluating C.__call__ just returns the descriptor
and doesn't invoking the descriptor mechanism.)


which seems to clash with what you just said.

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


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Mark Lawrence

On 09/11/2014 19:58, Syed Khalid wrote:

Python script that does batch find and replace in txt files Need a python 
script that opens all .txt files in a folder find replace/delete text and save 
files.

I have text files and I need to perform below steps for each file.

Step 1: Put cursor at start of file and Search for Contact's Name:. Delete 
all the rows before it.
Step 2: Put cursor at end of file, Search for Contact's Name: select option 
UP.
Step 3: Search for Photo of the Replace with blanks
Step 4: Search for Contact is Replace with blanks
Step 5: Search for Contact's Name: Replace with blanks
Step 6: Search for Age: Replace with blanks
Step 7: Search for Sex: Replace with blanks
Step 8: Search for House No: Replace with blanks
Step 9: Search for available Replace with blanks
Step 10: Remove Empty Lines Containing Blank Characters from file
Step 11: Trim Leading Space for each line
Step 12: Trim Trailing Space after each line
Step 13: Search for - (hyphen) Replace with _ (underscore)
Step 14: Save file.

Currently I have recorded a macro in Notepad++.
I open each file, run macro and save file.
As there are many files I was looking for a program to automate the process.

I posted the same query in Notepad++ forum. I got a reply that it can be done 
by using Python script.

Kindly do the needful.

Thank you.
khalidness



No problem once your cheque made payable to the Python Software 
Foundation has been cashed.  I'll pluck a figure of £200 out of the air, 
YMMV.


--
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: Python script that does batch find and replace in txt files

2014-11-09 Thread Albert-Jan Roskam




- Original Message -
 From: Syed Khalid khalidn...@gmail.com
 To: python-list@python.org
 Cc: 
 Sent: Sunday, November 9, 2014 8:58 PM
 Subject: Python script that does batch find and replace in txt files
 
 Python script that does batch find and replace in txt files Need a python 
 script 
 that opens all .txt files in a folder find replace/delete text and save files.
 
 I have text files and I need to perform below steps for each file. 
 
 Step 1: Put cursor at start of file and Search for Contact's 
 Name:. Delete all the rows before it.
 Step 2: Put cursor at end of file, Search for Contact's Name: 
 select option UP.
 Step 3: Search for Photo of the Replace with blanks
 Step 4: Search for Contact is Replace with blanks
 Step 5: Search for Contact's Name: Replace with blanks
 Step 6: Search for Age: Replace with blanks
 Step 7: Search for Sex: Replace with blanks
 Step 8: Search for House No: Replace with blanks
 Step 9: Search for available Replace with blanks
 Step 10: Remove Empty Lines Containing Blank Characters from file
 Step 11: Trim Leading Space for each line
 Step 12: Trim Trailing Space after each line
 Step 13: Search for - (hyphen) Replace with _ (underscore)

 Step 14: Save file.

something like (untested)


import glob, codecs, re, os

regex = re.compile(rAge: |Sex: |House No: ) # etc etc

for txt in glob.glob(/some/path/*.txt):
with codecs.open(txt, encoding=utf-8) as f:
oldlines = f.readlines()
for i, line in enumerate(oldlines):
if Contact's Name:  in line:
break
newlines = [regex.sub(, line).strip().replace(-, _) for line in 
oldlines[i:]
with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
w.write(os.linesep.join(newlines))




 
 Currently I have recorded a macro in Notepad++.
 I open each file, run macro and save file.
 As there are many files I was looking for a program to automate the process. 
 
 I posted the same query in Notepad++ forum. I got a reply that it can be done 
 by 
 using Python script.
 
 Kindly do the needful. 
 
 Thank you.
 khalidness
 
 -- 
 https://mail.python.org/mailman/listinfo/python-list
 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
Hi Albert,

Thank you for script.

I am getting the below error :

  File EamClean.log, line 12
with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
   ^
SyntaxError: invalid syntax

Kindly do the needful.

On Mon, Nov 10, 2014 at 1:53 AM, Albert-Jan Roskam fo...@yahoo.com wrote:





 - Original Message -
  From: Syed Khalid khalidn...@gmail.com
  To: python-list@python.org
  Cc:
  Sent: Sunday, November 9, 2014 8:58 PM
  Subject: Python script that does batch find and replace in txt files
 
  Python script that does batch find and replace in txt files Need a
 python script
  that opens all .txt files in a folder find replace/delete text and save
 files.
 
  I have text files and I need to perform below steps for each file.
 
  Step 1: Put cursor at start of file and Search for Contact's
  Name:. Delete all the rows before it.
  Step 2: Put cursor at end of file, Search for Contact's Name:
  select option UP.
  Step 3: Search for Photo of the Replace with blanks
  Step 4: Search for Contact is Replace with blanks
  Step 5: Search for Contact's Name: Replace with blanks
  Step 6: Search for Age: Replace with blanks
  Step 7: Search for Sex: Replace with blanks
  Step 8: Search for House No: Replace with blanks
  Step 9: Search for available Replace with blanks
  Step 10: Remove Empty Lines Containing Blank Characters from file
  Step 11: Trim Leading Space for each line
  Step 12: Trim Trailing Space after each line
  Step 13: Search for - (hyphen) Replace with _ (underscore)

  Step 14: Save file.

 something like (untested)


 import glob, codecs, re, os

 regex = re.compile(rAge: |Sex: |House No: ) # etc etc

 for txt in glob.glob(/some/path/*.txt):
 with codecs.open(txt, encoding=utf-8) as f:
 oldlines = f.readlines()
 for i, line in enumerate(oldlines):
 if Contact's Name:  in line:
 break
 newlines = [regex.sub(, line).strip().replace(-, _) for line in
 oldlines[i:]
 with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
 w.write(os.linesep.join(newlines))




 
  Currently I have recorded a macro in Notepad++.
  I open each file, run macro and save file.
  As there are many files I was looking for a program to automate the
 process.
 
  I posted the same query in Notepad++ forum. I got a reply that it can be
 done by
  using Python script.
 
  Kindly do the needful.
 
  Thank you.
  khalidness
 
  --
  https://mail.python.org/mailman/listinfo/python-list
 

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


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
My Script, 

I have added 

import glob, codecs, re, os

regex = re.compile(rAge: |Sex: |House No: ) # etc etc
Script I executed in EditRocket :

for txt in glob.glob(/D:/Python/source/*.txt):   
with codecs.open(txt, encoding=utf-8) as f:
oldlines = f.readlines()
for i, line in enumerate(oldlines):
if Contact's Name: in line:
break
newlines = [regex.sub(, line).strip().replace(-, _) for line in 
oldlines[i:]
with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
w.write(os.linesep.join(newlines))


Error Message :

  File EamClean.log, line 12
with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
   ^
SyntaxError: invalid syntax

Kindly do the needful



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


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
Code after adding path of .txt files :

import glob, codecs, re, os

regex = re.compile(rAge: |Sex: |House No: ) # etc etc

for txt in glob.glob(D:/Python/source/*.txt):
with codecs.open(txt, encoding=utf-8) as f:
oldlines = f.readlines()
for i, line in enumerate(oldlines):
if Elector's Name: in line:
break
newlines = [regex.sub(, line).strip().replace(-, _) for line in
oldlines[i:]
with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
w.write(os.linesep.join(newlines))


I executed code in edit rocket.

Error message :


File EamClean.log, line 12
with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
   ^
SyntaxError: invalid syntax





On Mon, Nov 10, 2014 at 2:22 AM, Syed Khalid khalidn...@gmail.com wrote:

 Hi Albert,

 Thank you for script.

 I am getting the below error :

   File EamClean.log, line 12
 with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
^
 SyntaxError: invalid syntax

 Kindly do the needful.

 On Mon, Nov 10, 2014 at 1:53 AM, Albert-Jan Roskam fo...@yahoo.com
 wrote:





 - Original Message -
  From: Syed Khalid khalidn...@gmail.com
  To: python-list@python.org
  Cc:
  Sent: Sunday, November 9, 2014 8:58 PM
  Subject: Python script that does batch find and replace in txt files
 
  Python script that does batch find and replace in txt files Need a
 python script
  that opens all .txt files in a folder find replace/delete text and save
 files.
 
  I have text files and I need to perform below steps for each file.
 
  Step 1: Put cursor at start of file and Search for Contact's
  Name:. Delete all the rows before it.
  Step 2: Put cursor at end of file, Search for Contact's Name:
  select option UP.
  Step 3: Search for Photo of the Replace with blanks
  Step 4: Search for Contact is Replace with blanks
  Step 5: Search for Contact's Name: Replace with blanks
  Step 6: Search for Age: Replace with blanks
  Step 7: Search for Sex: Replace with blanks
  Step 8: Search for House No: Replace with blanks
  Step 9: Search for available Replace with blanks
  Step 10: Remove Empty Lines Containing Blank Characters from file
  Step 11: Trim Leading Space for each line
  Step 12: Trim Trailing Space after each line
  Step 13: Search for - (hyphen) Replace with _ (underscore)

  Step 14: Save file.

 something like (untested)


 import glob, codecs, re, os

 regex = re.compile(rAge: |Sex: |House No: ) # etc etc

 for txt in glob.glob(/some/path/*.txt):
 with codecs.open(txt, encoding=utf-8) as f:
 oldlines = f.readlines()
 for i, line in enumerate(oldlines):
 if Contact's Name:  in line:
 break
 newlines = [regex.sub(, line).strip().replace(-, _) for line in
 oldlines[i:]
 with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
 w.write(os.linesep.join(newlines))




 
  Currently I have recorded a macro in Notepad++.
  I open each file, run macro and save file.
  As there are many files I was looking for a program to automate the
 process.
 
  I posted the same query in Notepad++ forum. I got a reply that it can
 be done by
  using Python script.
 
  Kindly do the needful.
 
  Thank you.
  khalidness
 
  --
  https://mail.python.org/mailman/listinfo/python-list
 



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


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread MRAB

On 2014-11-09 21:20, Syed Khalid wrote:


Code after adding path of .txt files :

import glob, codecs, re, os

regex = re.compile(rAge: |Sex: |House No: ) # etc etc

for txt in glob.glob(D:/Python/source/*.txt):
 with codecs.open(txt, encoding=utf-8) as f:
 oldlines = f.readlines()
 for i, line in enumerate(oldlines):
 if Elector's Name: in line:
 break
 newlines = [regex.sub(, line).strip().replace(-, _) for line
in oldlines[i:]
 with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
 w.write(os.linesep.join(newlines))


I executed code in edit rocket.

Error message :


File EamClean.log, line 12
 with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
^
SyntaxError: invalid syntax


[snip]

The previous line is missing a ']' on the end. It should be:

newlines = [regex.sub(, line).strip().replace(-, _) for line 
in oldlines[i:]]


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


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
Albert,

Thanks a million for script,

It worked fine after I closed the bracket.


import glob, codecs, re, os

regex = re.compile(rAge: |Sex: |House No:  ) # etc etc

for txt in glob.glob(D:/Python/source/*.txt):
with codecs.open(txt, encoding=utf-8) as f:
oldlines = f.readlines()
for i, line in enumerate(oldlines):
if Elector's Name: in line:
break
newlines = [regex.sub(, line).strip().replace(-, _) for line in
oldlines[i:]]
with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
w.write(os.linesep.join(newlines))


This program is not deleting the empty lines containing blank characters.
Kindly do the needful.


On Mon, Nov 10, 2014 at 2:50 AM, Syed Khalid khalidn...@gmail.com wrote:


 Code after adding path of .txt files :

 import glob, codecs, re, os

 regex = re.compile(rAge: |Sex: |House No: ) # etc etc

 for txt in glob.glob(D:/Python/source/*.txt):
 with codecs.open(txt, encoding=utf-8) as f:
 oldlines = f.readlines()
 for i, line in enumerate(oldlines):
 if Elector's Name: in line:
 break
 newlines = [regex.sub(, line).strip().replace(-, _) for line in
 oldlines[i:]
 with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
 w.write(os.linesep.join(newlines))


 I executed code in edit rocket.

 Error message :


 File EamClean.log, line 12
 with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
^
 SyntaxError: invalid syntax





 On Mon, Nov 10, 2014 at 2:22 AM, Syed Khalid khalidn...@gmail.com wrote:

 Hi Albert,

 Thank you for script.

 I am getting the below error :

   File EamClean.log, line 12
 with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
^
 SyntaxError: invalid syntax

 Kindly do the needful.

 On Mon, Nov 10, 2014 at 1:53 AM, Albert-Jan Roskam fo...@yahoo.com
 wrote:





 - Original Message -
  From: Syed Khalid khalidn...@gmail.com
  To: python-list@python.org
  Cc:
  Sent: Sunday, November 9, 2014 8:58 PM
  Subject: Python script that does batch find and replace in txt files
 
  Python script that does batch find and replace in txt files Need a
 python script
  that opens all .txt files in a folder find replace/delete text and
 save files.
 
  I have text files and I need to perform below steps for each file.
 
  Step 1: Put cursor at start of file and Search for Contact's
  Name:. Delete all the rows before it.
  Step 2: Put cursor at end of file, Search for Contact's Name:
  select option UP.
  Step 3: Search for Photo of the Replace with blanks
  Step 4: Search for Contact is Replace with blanks
  Step 5: Search for Contact's Name: Replace with blanks
  Step 6: Search for Age: Replace with blanks
  Step 7: Search for Sex: Replace with blanks
  Step 8: Search for House No: Replace with blanks
  Step 9: Search for available Replace with blanks
  Step 10: Remove Empty Lines Containing Blank Characters from file
  Step 11: Trim Leading Space for each line
  Step 12: Trim Trailing Space after each line
  Step 13: Search for - (hyphen) Replace with _ (underscore)

  Step 14: Save file.

 something like (untested)


 import glob, codecs, re, os

 regex = re.compile(rAge: |Sex: |House No: ) # etc etc

 for txt in glob.glob(/some/path/*.txt):
 with codecs.open(txt, encoding=utf-8) as f:
 oldlines = f.readlines()
 for i, line in enumerate(oldlines):
 if Contact's Name:  in line:
 break
 newlines = [regex.sub(, line).strip().replace(-, _) for line
 in oldlines[i:]
 with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
 w.write(os.linesep.join(newlines))




 
  Currently I have recorded a macro in Notepad++.
  I open each file, run macro and save file.
  As there are many files I was looking for a program to automate the
 process.
 
  I posted the same query in Notepad++ forum. I got a reply that it can
 be done by
  using Python script.
 
  Kindly do the needful.
 
  Thank you.
  khalidness
 
  --
  https://mail.python.org/mailman/listinfo/python-list
 




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


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Albert-Jan Roskam


On Sun, Nov 9, 2014 10:51 PM CET Syed Khalid wrote:

Albert,

Thanks a million for script,

It worked fine after I closed the bracket.


import glob, codecs, re, os

regex = re.compile(rAge: |Sex: |House No:  ) # etc etc

for txt in glob.glob(D:/Python/source/*.txt):
with codecs.open(txt, encoding=utf-8) as f:
oldlines = f.readlines()
for i, line in enumerate(oldlines):
if Elector's Name: in line:
break
newlines = [regex.sub(, line).strip().replace(-, _) for line in
oldlines[i:]]

You're welcome

newlines = [regex.sub(, line).strip().replace(-, _) for line in
oldlines[i:] if line.strip()]
-- 
https://mail.python.org/mailman/listinfo/python-list


__missing__ for the top-level Python script

2014-11-09 Thread Chris Angelico
Let's have some fun nutting out possible implementations for a bad idea :)

If you want a dictionary that prepopulates itself on demand, you
implement __missing__. Is there a way to implement the same thing for
the __main__ module? Since it isn't imported (as such), I don't think
switch out what's in sys.modules will work, though I'm open to
correction on that.

Desired result: Implicit imports.

## test.py
print(Path separator is,os.sep)
try:
print(Version, psycopg2.__version__, of psycopg2 is installed.)
except NameError:
print(You don't have psycopg2 installed.)
sys.exit(1)

So the semantics should be: If NameError would be raised (not
including UnboundLocalError, which still represents an error), attempt
to import the absent name. If successful, continue as if it had
already been done. If ImportError is raised, suppress it and let the
original NameError happen.

Yes, this is extremely unPythonic. But just as an intellectual
exercise, can this be done?

I'm assuming Python 3 here, so if there's something neat that can be
done with import hooks, go for it.

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


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
Albert,

Code is not removing  empty lines containing blank characters and not removing 
leading and trailing spaces present in each line. 




import glob, codecs, re, os

regex = re.compile(rAge: |Sex: |House No:  ) # etc etc

for txt in glob.glob(D:/Python/source/*.txt):   
with codecs.open(txt, encoding=utf-8) as f:
oldlines = f.readlines()
for i, line in enumerate(oldlines):
if Elector's Name: in line:
break
newlines = [regex.sub(, line).strip().replace(-, _) for line in 
oldlines[i:]]
with codecs.open(txt + _out.txt, wb, encoding=utf-8) as w:
w.write(os.linesep.join(newlines))

Kindly do the needful
-- 
https://mail.python.org/mailman/listinfo/python-list


Python modules

2014-11-09 Thread Steve Hayes
I have a book on Python that advocates dividing programs into modules, and
importing them when needed. 

I have a question about this.

I can understand doing that in a compiled language, where different modules
can be imported from all sorts of places when the program is compiled. 

But I understand that Python is an interpreted language, and If I wrote a
program in Python like that, and wanted to run it on another computer, how
would it find all the modules to import at run-time, unless I copied the whole
directory structure over to the other computer?




-- 
Steve Hayes from Tshwane, South Africa
Web:  http://www.khanya.org.za/stevesig.htm
Blog: http://khanya.wordpress.com
E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python modules

2014-11-09 Thread Deepfriedice

On 10/11/14 14:55, Steve Hayes wrote:

I have a book on Python that advocates dividing programs into modules, and
importing them when needed.

I have a question about this.

I can understand doing that in a compiled language, where different modules
can be imported from all sorts of places when the program is compiled.

But I understand that Python is an interpreted language, and If I wrote a
program in Python like that, and wanted to run it on another computer, how
would it find all the modules to import at run-time, unless I copied the whole
directory structure over to the other computer?


You copy over the directory structure, or wrap it in a compressed archive.

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


Re: Python modules

2014-11-09 Thread Ben Finney
Steve Hayes hayes...@telkomsa.net writes:

 I have a book on Python that advocates dividing programs into modules,
 and importing them when needed.

Which book is this? (This is not essential to your question, but it
might help to gauge your broader learning environment.)

 I can understand doing that in a compiled language, where different
 modules can be imported from all sorts of places when the program is
 compiled.

Python is a compiled language; when you run a Python program a necessary
step is to compile the Python source to a bytecode for actual execution.

Usually, the compilation step is done dynamically; but (barring
contrived examples) it is always done prior to running the program.

 But I understand that Python is an interpreted language

The two are not mutually exclusive. The Python interpreter works with
compiled Python code, it does not execute the source directly.

 If I wrote a program in Python like that, and wanted to run it on
 another computer, how would it find all the modules to import at
 run-time, unless I copied the whole directory structure over to the
 other computer?

That's the idea, yes. You need to distinguish between:

* The standard library: installed along with the Python interpreter when
  you install that, and available on the default module search path.

* Third-party modules: installed using your package manager (ideally by
  the operating system package manager), again to a location already
  part of the default module search path on your system.

* Modules specific to the application you're writing: Keep these in a
  known hierarchy, and use the distribution tools to package them to
  keep them together when distributing to oher machines.

Use abolute import for standard library and third-party modules. Use
relative import for application-private modules.

This ensures your aplication's private modules don't conflict with
current or future names of modules from the standard library or third
parties.

You are working through the Python tutorial step by step, right?
URL:https://docs.python.org/3/tutorial/ This topic is covered when you
learn about modules URL:https://docs.python.org/3/tutorial/modules.html.

-- 
 \   “I am amazed, O Wall, that you have not collapsed and fallen, |
  `\since you must bear the tedious stupidities of so many |
_o__)  scrawlers.” —anonymous graffiti, Pompeii, 79 CE |
Ben Finney

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


Re: Python modules

2014-11-09 Thread Steve Hayes
On Mon, 10 Nov 2014 16:12:07 +1100, Ben Finney ben+pyt...@benfinney.id.au
wrote:

Steve Hayes hayes...@telkomsa.net writes:

 I have a book on Python that advocates dividing programs into modules,
 and importing them when needed.

Which book is this? (This is not essential to your question, but it
might help to gauge your broader learning environment.)

Cunningham, Katie. 2014. Teach yourself Python in 24 hours.
   Indianapolis: Sams.
   ISBN: 978-0-672-33687-4
   For Python 2.7.5

 I can understand doing that in a compiled language, where different
 modules can be imported from all sorts of places when the program is
 compiled.

Python is a compiled language; when you run a Python program a necessary
step is to compile the Python source to a bytecode for actual execution.

Usually, the compilation step is done dynamically; but (barring
contrived examples) it is always done prior to running the program.

 But I understand that Python is an interpreted language

The two are not mutually exclusive. The Python interpreter works with
compiled Python code, it does not execute the source directly.

 If I wrote a program in Python like that, and wanted to run it on
 another computer, how would it find all the modules to import at
 run-time, unless I copied the whole directory structure over to the
 other computer?

That's the idea, yes. You need to distinguish between:

* The standard library: installed along with the Python interpreter when
  you install that, and available on the default module search path.

* Third-party modules: installed using your package manager (ideally by
  the operating system package manager), again to a location already
  part of the default module search path on your system.

* Modules specific to the application you're writing: Keep these in a
  known hierarchy, and use the distribution tools to package them to
  keep them together when distributing to oher machines.

Use abolute import for standard library and third-party modules. Use
relative import for application-private modules.

This ensures your aplication's private modules don't conflict with
current or future names of modules from the standard library or third
parties.

So if I want to run it on another computer, where do I look for the compiled
executable program to copy?


-- 
Steve Hayes from Tshwane, South Africa
Web:  http://www.khanya.org.za/stevesig.htm
Blog: http://khanya.wordpress.com
E-mail - see web page, or parse: shayes at dunelm full stop org full stop uk
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python modules

2014-11-09 Thread Ben Finney
Steve Hayes hayes...@telkomsa.net writes:

 So if I want to run it on another computer, where do I look for the
 compiled executable program to copy?

You generally don't do that (the compiled files tend to be specific to
various aspects of the target platform). This is a way that i's
important to remember that most Python interpreters require compiled
Python code.

Instead, to have a Python program run on a different computer, the files
to copy are the *source* files — preferably, in the hierarchy those
files expect.

You can do this with ‘rsync’ URL:https://rsync.samba.org/ for simple
cases.

For more complex cases, look into Python's distribution and packaging
tools URL:https://python-packaging-user-guide.readthedocs.org/.

For even more complex cases (e.g. where the Python code is only part of
a more diverse code base), look into deployment systems and operating
system packages.

-- 
 \ “When we pray to God we must be seeking nothing — nothing.” |
  `\—Francis of Assisi |
_o__)  |
Ben Finney

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


[issue2636] Adding a new regex module (compatible with re)

2014-11-09 Thread Nick Coghlan

Nick Coghlan added the comment:

Thanks for pushing this one forward Serhiy! Your approach sounds like a
fine plan to me.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2636
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22825] Modernize TextFile

2014-11-09 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

Proposed patch makes distutils.text_file.TextFile support context management 
and iterator protocols. It makes the use of TextFile simpler. The patch also 
includes other minor modernizations.

--
components: Distutils
files: text_file.diff
keywords: patch
messages: 230886
nosy: dstufft, eric.araujo, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Modernize TextFile
type: enhancement
versions: Python 3.5
Added file: http://bugs.python.org/file37151/text_file.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22825
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2636] Adding a new regex module (compatible with re)

2014-11-09 Thread Jeffrey C. Jacobs

Jeffrey C. Jacobs added the comment:

If I recall, I started this thread with a plan to update re itself with 
implementations of various features listed in the top post.  If you look at the 
list of files uploaded by me there are seme complete patches for Re to add 
various features like Atomic Grouping.  If we wish to therefore bring re to 
regex standard we could start with those features.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2636
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22826] Support context management protocol in bkfile

2014-11-09 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

Proposed patch makes bkfile (file-like class used in freeze) support the 
context management protocol. This makes bkfile more file-like and makes the use 
of it simpler and more robust.

--
components: Demos and Tools
files: bkfile.diff
keywords: patch
messages: 230888
nosy: serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Support context management protocol in bkfile
type: enhancement
versions: Python 3.5
Added file: http://bugs.python.org/file37152/bkfile.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22826
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22827] Backport ensurepip to 2.7 (PEP 477)

2014-11-09 Thread Donald Stufft

New submission from Donald Stufft:

As specified in PEP 477, this backports PEP 453 (ensurepip) to the Python 2.7 
branch. Key differences from PEP 453 are:

* It is not run by default in the Makefile
* There is no venv modules, so downstream can remove it (though are asked to 
patch it to provide instructions redirecting people to how they should install 
pip).
* The ``pip`` command is installed as well as ``pipX`` and ``pipX.Y``.
* Given the above, --default-pip is hidden and no-oped and --no-default-pip is 
added to restore the Python 3.x behavior.

This also includes a (slightly modified to make it work on 2.x) backport of 
unittest.mock as test._mock_backport in order to make it reasonable to run the 
ensurepip tests without actually installing pip.

This patch does not include any changes to the Windows installers or to the OS 
X installers. I've nosey'd Ned Deily for the OS X installer changes, I'm not 
sure who is doing the Windows Installers now adays.

Note: The attached patch does not contain the actual .whl files which are 
required. This is because it makes the patch into a 2M patch and the tracker 
didn't like that very much. This patch can be applied and then just copy over 
the Lib/ensurepip/_bundled directory from Python 3.4.

--
files: pep-477.patch
keywords: needs review, patch
messages: 230889
nosy: doko, dstufft, ncoghlan, ned.deily
priority: normal
severity: normal
stage: patch review
status: open
title: Backport ensurepip to 2.7 (PEP 477)
type: enhancement
versions: Python 2.7
Added file: http://bugs.python.org/file37154/pep-477.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22827
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22828] Backport ensurepip to 2.7 (PEP 477)

2014-11-09 Thread Donald Stufft

New submission from Donald Stufft:

As specified in PEP 477, this backports PEP 453 (ensurepip) to the Python 2.7 
branch. Key differences from PEP 453 are:

* It is not run by default in the Makefile
* There is no venv modules, so downstream can remove it (though are asked to 
patch it to provide instructions redirecting people to how they should install 
pip).
* The ``pip`` command is installed as well as ``pipX`` and ``pipX.Y``.
* Given the above, --default-pip is hidden and no-oped and --no-default-pip is 
added to restore the Python 3.x behavior.

This also includes a (slightly modified to make it work on 2.x) backport of 
unittest.mock as test._mock_backport in order to make it reasonable to run the 
ensurepip tests without actually installing pip.

This patch does not include any changes to the Windows installers or to the OS 
X installers. I've nosey'd Ned Deily for the OS X installer changes, I'm not 
sure who is doing the Windows Installers now adays.

--
files: pep-477.patch
keywords: needs review, patch
messages: 230890
nosy: doko, dstufft, ncoghlan, ned.deily
priority: normal
severity: normal
stage: patch review
status: open
title: Backport ensurepip to 2.7 (PEP 477)
type: enhancement
versions: Python 2.7
Added file: http://bugs.python.org/file37153/pep-477.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22828
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22828] Backport ensurepip to 2.7 (PEP 477)

2014-11-09 Thread Donald Stufft

Donald Stufft added the comment:

Closing this in favor of http://bugs.python.org/issue22827

--
resolution:  - duplicate
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22828
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22827] Backport ensurepip to 2.7 (PEP 477)

2014-11-09 Thread Donald Stufft

Changes by Donald Stufft don...@stufft.io:


--
nosy: +steve.dower

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22827
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22827] Backport ensurepip to 2.7 (PEP 477)

2014-11-09 Thread Donald Stufft

Donald Stufft added the comment:

Second patch just fixes the docs to specify the correct behavior for 2.7 and it 
fixes ensurepip.bootstrap() to match the default 2.7 behavior when executing 
python -m ensurepip.

--
Added file: http://bugs.python.org/file37155/pep-477-2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22827
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22826] Support context management protocol in bkfile

2014-11-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

This looks correct and it improves readability.

One nit,  please put the doubled with on a single line instead of using the 
awkward line break (which looks weird with respect to the indentation of the 
with-block):

+with open(config_c_in) as infp, bkfile.open(config_c, 'w') as outfp:

--
nosy: +rhettinger

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22826
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22829] Add --prompt option to venv

2014-11-09 Thread Łukasz Balcerzak

New submission from Łukasz Balcerzak:

virtualenv tool allows to set alternative prompt prefix, Python's venv module 
should allow this too.

Basically, this allows one to run:

python -mvenv --prompt Quux myenv

And see (Quux) as a prefix after environment activation (instead of the 
myenv in this case).

--
files: venv-prompt-argument.patch
keywords: patch
messages: 230894
nosy: Łukasz.Balcerzak
priority: normal
severity: normal
status: open
title: Add --prompt option to venv
versions: Python 3.5
Added file: http://bugs.python.org/file37156/venv-prompt-argument.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22829
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21288] hashlib.pbkdf2_hmac Hash Constructor

2014-11-09 Thread Eric Beurre

Changes by Eric Beurre h...@ericbeurre.com:


--
nosy: +egbutter

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21288
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22830] functools.cmp_to_key: misleading key function description

2014-11-09 Thread Terry J. Reedy

New submission from Terry J. Reedy:

https://docs.python.org/3.4/library/functools.html#functools.cmp_to_key says  
A key function is a callable that accepts one argument and returns another 
value indicating the position in the desired collation sequence.  A python 
list poster (Veek M) 'value indicating the position' as meaning 0, 1, 2, ... 
and I would read it that way if I did not know better.

Entries for min() and max() say The key argument specifies a one-argument 
ordering function like that used for list.sort().  This would be reused here.  
We also, now, have a Glossary entry for 'key function'.  This could be referred 
to instead.

--
assignee: docs@python
components: Documentation
messages: 230895
nosy: docs@python, terry.reedy
priority: normal
severity: normal
stage: needs patch
status: open
title: functools.cmp_to_key: misleading key function description
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22830
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22434] Use named constants internally in the re module

2014-11-09 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you Raymond for the review.

 I especially like the removal of superfluous OPCODES dictionary lookups

The disadvantage is that now backporting patches to old branches is harder.

 Since the op codes are singletons, you can use identity tests instead of
 equality checks in sre_parse.py:

This is deliberate. There is small change that the opcodes could became an 
integers in future (after adding introspection to pattern object, or make it 
copyable, or allowing serialization of compiled codes). is instead of == 
can cause subtle bug. Note that is is used during parsing, but getwidth() is 
called from sre_compile.py.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22434
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22830] functools.cmp_to_key: misleading key function description

2014-11-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

I'll add a link to the glossary entry for key function and to the sorting 
howto.  Also, I'll change value indicating the position to value to be used 
as the sort key.

The form sentence being discussed should probably remain close to how it is 
currently written.  It is part of a two sentence paragraph that contrasts cmp 
functions versus key functions, so the parallel sentence structure is part of 
what it is trying to communicate.

FWIW, interpreting value indicating position as 0, 1, 2, etc isn't incorrect. 
 That is a possible key function.

In general, I prefer doc changes to be very minor when they have a history of 
many people reading them correctly; otherwise, we risk moving away from 
something that was already working pretty well.

--
assignee: docs@python - rhettinger
nosy: +rhettinger

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22830
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I will prepare a 3.5 patch for this.  There are not many instances other than 
those you found (but several times as many in tests).  I presume that most 
non-test instances were converted by the 2to3 fixer.

How about frozenset([...]) to frozenset({...})?  There are 4 occurrences of 
this. The semantic match between frozenset and {...} is better than with [...], 
but the visual gain in nearly nil.

I will leave the one idlelib instance in CodeContext for when I am editing the 
file anyway (for both 3.4 and 3.5), which should be soon.

--
nosy: +terry.reedy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22826] Support context management protocol in bkfile

2014-11-09 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Thank you Raymond. I found my old patch written 5 months ago. It drastically 
simplifies bkfile by using monkey-patching. What approach looks better to you?

--
Added file: http://bugs.python.org/file37157/bkfile2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22826
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I did not look at Docs yet.

I could not repeat the timing results on my machine running from the command 
line, as I got '0.015 usec per loop' for both, and same for both frozenset 
variations.  Running timeit.repeat interactively and selecting the best 
reproduced your timing ratio: .16 to .42.  For frozenset, I get .36 to .42 in 
favor of changing to frozenset({...}).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22831] Use with to avoid possible fd leaks

2014-11-09 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

Here is large patch which convert a code which potentially can leak file 
descriptor to use the with statement so files are always closed. This can make 
effect mainly on alternative Python implementation without reference counting. 
But even on CPython this will get rid from resource leaking warnings.

--
components: Demos and Tools, Library (Lib), Tests
files: fd_leaks.diff
keywords: patch
messages: 230901
nosy: rhettinger, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Use with to avoid possible fd leaks
type: resource usage
versions: Python 3.5
Added file: http://bugs.python.org/file37158/fd_leaks.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22831
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22490] Using realpath for __PYVENV_LAUNCHER__ makes Homebrew installs fragile

2014-11-09 Thread Vinay Sajip

Vinay Sajip added the comment:

 I don't quite understand why you use __PYVENV_LAUNCHER__

When I first developed the venv functionality it was definitely needed, but it 
looks as if it is not needed now. Perhaps to fix this completely, the following 
needs to be done, on the assumption that __PYVENV_LAUNCHER__ is no longer 
needed:

1. Remove the reference to it in distlib, and use sys.executable instead. Once 
pip incorporates this fix, the Homebrew problem should go away. (I have already 
made the change in the distlib repo, but this needs to be released in order for 
pip to consider vendoring it, and then pip needs to be released before Python 
can incorporate it).

2. Remove references to the environment variable in Python itself, using 
sys.executable instead.

As the env var was an implementation detail, ISTM it could be removed in a 3.4 
point release - would you agree?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22490
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22434] Use named constants internally in the re module

2014-11-09 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
resolution:  - fixed
stage: patch review - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22434
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Isn't such changes considered code churn?

If it is not, I have a huge patch which makes Python sources to use more modern 
idioms, including replacing set constructors with set literals (I have counted 
three occurrences not in tests). Are you interesting to look on it Raymond?

--
nosy: +serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

[I will prepare a 3.5 patch for this.]

Thanks, I will review when you're done.

[How about frozenset([...]) to frozenset({...})? ]

Yes, the frozenset() examples should change to match the actual repr:

frozenset([10, 20, 30])
   frozenset({10, 20, 30})

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

[Isn't such changes considered code churn?]

This sort of thing is always a judgment call.  The patch will affect very few 
lines of code, give a little speed-up, and make the code easier to read.  In 
the case of the docs, it is almost always worthwhile to update to the current, 
idiomatic form.  Also, the set literal case is special because it has built-in 
language support, possible peephole optimizations, and there was a repr change 
as well.  That said, it is rarely a good idea to change tests because we don't 
have tests for tests and because the end-user will never see any value.

On the balance, I think this one is a reasonable thing to do, but I would show 
a great deal more hesitancy for a a huge patch which makes Python sources to 
use more modern idioms.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Terry J. Reedy

Terry J. Reedy added the comment:

My timing for set((1,2,3)) is .29, faster than for set([1,2,3]) (.42) but still 
slower than for {1,2,3} (.16).  So I will change such instances also.

The same timing for frozenset((1,2,3)) (.29) is faster than the best timing for 
frozenset({1,2,3}), (.36), so I will not change that unless discussed and 
agreed on.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22827] Backport ensurepip to 2.7 (PEP 477)

2014-11-09 Thread Matthias Klose

Matthias Klose added the comment:

The mock backport doesn't come with a license.  Please either include it in the 
file, or make it clear that the backport has the same license as python (?).

--
nosy: +michael.foord

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22827
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22827] Backport ensurepip to 2.7 (PEP 477)

2014-11-09 Thread Donald Stufft

Donald Stufft added the comment:

The backport is taken from Python 3.4 so it's the same license as everything 
else.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22827
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22827] Backport ensurepip to 2.7 (PEP 477)

2014-11-09 Thread Donald Stufft

Donald Stufft added the comment:

IOW it's literally Lib/unittest/mock.py from the 3.x series.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22827
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

 The same timing for frozenset((1,2,3)) (.29) is faster than the best
 timing for frozenset({1,2,3}), (.36),

I don't see the tuple form used anywhere in the code.
The timing is a bit quicker for the tuple form because the peephole optimizer 
constant folds the tuple (use dis to see this).


 so I will not change that 
 unless discussed and agreed on.

Maybe, I should just make the patch.  It's becoming harder to talk about than 
to just fix.

--
assignee:  - rhettinger

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Serhiy, about your 'huge patch' to modernize code:

I am more positive than some because:

1) To me, a one-time gentile change is not 'churning'.

2) As we link to many, most, or even all python-coded stdlib modules (I think 
there is a proposal for 'all'), there is more benefit to using modern idioms.

On the other hand, 'huge' patches can be too much to discuss, justify, and 
review all at once.

Using {.. } for sets consistently is a nice-sized chunk to consider.  We can 
identify, discuss, and decide on each sub-case (I have identified 4 so far).  
It has the additional benefit of being a performance enhancement.
---

'set((...' is used in distutils (which I will not change) and in many tests.  
So that is not an issue.  'frozenset((' is used 5 times in regular module code.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Attaching a patch.  Doesn't change tests for the reasons mentioned above.  
Leaves idle, 2-to-3, and mocking for their respective module maintainers to 
deal with holistically (as part of their routine maintenance).

--
keywords: +patch
Added file: http://bugs.python.org/file37159/set_literal.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22830] functools.cmp_to_key: misleading key function description

2014-11-09 Thread Terry J. Reedy

Terry J. Reedy added the comment:

I agree with your comments and proposed changes and will leave this to you.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22830
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Okay, I missed the frozenset(( examples in my search.  There are all in 
one-time set-up code.  Attaching a patch for them as well.

--
Added file: http://bugs.python.org/file37160/more_set_literals.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

You have missed Parser/asdl.py and Tools/clinic/clinic.py.

--
Added file: http://bugs.python.org/file37161/set_literal_2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Serhiy, as I said before, please omit idlelib/CodeContext.

You both skipped reprlib.py.  Should it be changed to produce the standard 
repr() result? The existing lines:

F:\Python\dev\35\lib\reprlib.py: 91: return self._repr_iterable(x, 
level, 'set([', '])', self.maxset)
F:\Python\dev\35\lib\reprlib.py: 95: return self._repr_iterable(x, 
level, 'frozenset([', '])',

If it is, its tests will have to be changed too.

--
keywords:  -patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Hmm, didn't look at those parts of the tree.  I'll change the one-line in 
Parser and leave the little atrocities in clinic.py for Larry to fix :-)

Reprlib was skipped intentionally.  There is a separate tracker item for it.  
http://bugs.python.org/issue22824

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

If there are no objections, I would like to apply my two patches (plus the 
one-line asdl.py change) and leave the rest to the discretion the module 
maintainers (mock, code context, clinic, and 2-to-3).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22791] datetime.utcfromtimestamp() shoud have option for create tz aware datetime

2014-11-09 Thread Akira Li

Akira Li added the comment:

I agree the documentation should nudge towards aware
datetime objects.

I've attached a documentation patch as an example.

--
keywords: +patch
Added file: 
http://bugs.python.org/file37162/issue22791-utcfromtimestamp-aware.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22791
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 4480506137ed by Raymond Hettinger in branch 'default':
Issue #22823: Use set literals instead of creating a set from a list
https://hg.python.org/cpython/rev/4480506137ed

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22823] Use set literals instead of creating a set from a list

2014-11-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Larry, would you care to apply or approve Serhiy's updates to clinic.py?

--
assignee: rhettinger - larry
nosy: +larry

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22823
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22824] Update reprlib to use set literals

2014-11-09 Thread Berker Peksag

Berker Peksag added the comment:

Here's a patch to use set literals and frozenset({'a'}) in reprlib.

--
keywords: +patch
stage: needs patch - patch review
Added file: http://bugs.python.org/file37163/issue22824.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22824
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22824] Update reprlib to use set literals

2014-11-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

That looks great.  Go ahead an apply (with a MISC/NEWS entry and an update to 
the example on line 22 of Docs/tutorial/stdlib2.rst).

--
assignee:  - berker.peksag

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22824
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22824] Update reprlib to use set literals

2014-11-09 Thread Berker Peksag

Berker Peksag added the comment:

Thanks for the review, Raymond. Patch updated:

- Updated the documentation
- Added two test cases for set literals
- Replaced old run_unittest calls with ``unittest.main()``

--
Added file: http://bugs.python.org/file37164/issue22824_v2.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22824
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22830] functools.cmp_to_key: misleading key function description

2014-11-09 Thread Roundup Robot

Roundup Robot added the comment:

New changeset dbe1744ec62e by Raymond Hettinger in branch '2.7':
Issue 22830:  Clarify docs for functools.cmp_to_key().
https://hg.python.org/cpython/rev/dbe1744ec62e

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22830
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22830] functools.cmp_to_key: misleading key function description

2014-11-09 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 63274cf1b40d by Raymond Hettinger in branch '3.4':
Issue 22830:  Clarify docs for functools.cmp_to_key().
https://hg.python.org/cpython/rev/63274cf1b40d

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22830
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20152] Derby #15: Convert 50 sites to Argument Clinic across 9 files

2014-11-09 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 6e6532d313a1 by Brett Cannon in branch 'default':
Issue 20152, 22821: Port the fcntl module to Argument Clinic.
https://hg.python.org/cpython/rev/6e6532d313a1

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20152
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22821] Argument of wrong type is passed to fcntl()

2014-11-09 Thread Brett Cannon

Brett Cannon added the comment:

Fixed in 3.5 as part of 6e6532d313a1 as it was easier to integrate it as part 
of the Clinic patch.

--
stage: patch review - commit review
versions:  -Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22821
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue20152] Derby #15: Convert 50 sites to Argument Clinic across 9 files

2014-11-09 Thread Brett Cannon

Brett Cannon added the comment:

Finally finished!

I am never trusting Larry to count anything ever again. ;)

--
resolution:  - fixed
stage: commit review - resolved
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue20152
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22830] functools.cmp_to_key: misleading key function description

2014-11-09 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22830
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22832] Tweak parameter names for fcntl module

2014-11-09 Thread Brett Cannon

New submission from Brett Cannon:

http://bugs.python.org/review/20152/ is filled with various suggestions from 
Serhiy on how to update the function parameters in the fcntl module to more 
closely match what is in the man pages. This should be fully 
backwards-compatible as the parameters are positional-only. It should be easy 
as the code doesn't need to change thanks to Argument Clinic. Trick will be 
updating both the code and the docs.

--
assignee: docs@python
components: Documentation
keywords: easy
messages: 230931
nosy: brett.cannon, docs@python, serhiy.storchaka
priority: normal
severity: normal
stage: needs patch
status: open
title: Tweak parameter names for fcntl module
type: enhancement
versions: Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22832
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22833] The decode_header() function decodes raw part to bytes or str, depending on encoded part

2014-11-09 Thread py.user

New submission from py.user:

It depends on encoded part in the header, what email.header.decode_header() 
returns.
If the header has both raw part and encoded part, the function returns (bytes, 
None) for the raw part. But if the header has only raw part, the function 
returns (str, None) for it.

 import email.header
 
 s = 'abc=?koi8-r?q?\xc1\xc2\xd7?='
 email.header.decode_header(s)
[(b'abc', None), (b'\xc1\xc2\xd7', 'koi8-r')]
 
 s = 'abc'
 email.header.decode_header(s)
[('abc', None)]


There should be (bytes, None) for both cases.

--
components: Library (Lib), email
messages: 230932
nosy: barry, py.user, r.david.murray
priority: normal
severity: normal
status: open
title: The decode_header() function decodes raw part to bytes or str, depending 
on encoded part
versions: Python 3.3, Python 3.4, Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22833
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22833] The decode_header() function decodes raw part to bytes or str, depending on encoded part

2014-11-09 Thread py.user

Changes by py.user bugzilla-mail-...@yandex.ru:


--
type:  - behavior

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22833
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22834] Unexpected FileNotFoundError when current directory is removed

2014-11-09 Thread Martin Panter

New submission from Martin Panter:

I encountered this when I added a unit test case that invoked os.chdir() with a 
temporary directory on Linux. After the directory was removed, some of the 
subsequent test cases failed, although I don’t think they should depend on a 
particular CWD.

I suspect the main problem might be code that is trying to dynamically import 
modules, and the interpreter is trying to search for modules in the current 
directory. I would expect it to happily go on to the other standard module 
directories or raise ImportError, just like if the current directory is valid 
but empty, or an nonexistent directory is in the module search path list.

Code to set up missing CWD:

import os
from tempfile import TemporaryDirectory
with TemporaryDirectory() as dir:
os.chdir(dir)

Quick recovery:

os.chdir(/)

Examples of failures:

 \N{COPYRIGHT SIGN}
  File stdin, line 1
SyntaxError: (unicode error) \N escapes not supported (can't load unicodedata 
module)
 datetime.strptime(, )
Traceback (most recent call last):
  File stdin, line 1, in module
  File frozen importlib._bootstrap, line 2237, in _find_and_load
  File frozen importlib._bootstrap, line , in _find_and_load_unlocked
  File frozen importlib._bootstrap, line 2164, in _find_spec
  File frozen importlib._bootstrap, line 1940, in find_spec
  File frozen importlib._bootstrap, line 1911, in _get_spec
  File frozen importlib._bootstrap, line 1879, in _path_importer_cache
FileNotFoundError: [Errno 2] No such file or directory
 HTTPConnection(localhost).request(GET, /)
Traceback (most recent call last):
  File stdin, line 1, in module
  File /usr/lib/python3.4/http/client.py, line 1090, in request
self._send_request(method, url, body, headers)
  File /usr/lib/python3.4/http/client.py, line 1128, in _send_request
self.endheaders(body)
  File /usr/lib/python3.4/http/client.py, line 1086, in endheaders
self._send_output(message_body)
  File /usr/lib/python3.4/http/client.py, line 924, in _send_output
self.send(msg)
  File /usr/lib/python3.4/http/client.py, line 859, in send
self.connect()
  File /usr/lib/python3.4/http/client.py, line 836, in connect
self.timeout, self.source_address)
  File /usr/lib/python3.4/socket.py, line 491, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File /usr/lib/python3.4/socket.py, line 530, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
  File /usr/lib/python3.4/encodings/__init__.py, line 98, in search_function
level=0)
  File /usr/lib/python3.4/encodings/idna.py, line 3, in module
import stringprep, re, codecs
  File frozen importlib._bootstrap, line 2237, in _find_and_load
  File frozen importlib._bootstrap, line , in _find_and_load_unlocked
  File frozen importlib._bootstrap, line 2164, in _find_spec
  File frozen importlib._bootstrap, line 1940, in find_spec
  File frozen importlib._bootstrap, line 1911, in _get_spec
  File frozen importlib._bootstrap, line 1879, in _path_importer_cache
FileNotFoundError: [Errno 2] No such file or directory

 from datetime import datetime
 from http.client import HTTPConnection
These two also generate the FileNotFoundError

My workaround is to add this to my test case:
self.addCleanup(os.chdir, os.getcwd())

--
components: Interpreter Core
messages: 230933
nosy: vadmium
priority: normal
severity: normal
status: open
title: Unexpected FileNotFoundError when current directory is removed
type: behavior
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22834
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22835] urllib2/httplib is rendering 400s for every authenticated-SSL request, suddenly

2014-11-09 Thread Dustin Oprea

New submission from Dustin Oprea:

I am trying to do an authenticated-SSL request to an Nginx server using 
*requests*, which wraps urllib2/httplib. It's worked perfectly for months until 
Friday on my local system (Mac 10.9.5), and there have been no 
upgrades/patches. 

My Python 2.7.6 client fails when connecting to Nginx, locally. I get a 400, 
with this:

html
headtitle400 No required SSL certificate was sent/title/head
body bgcolor=white
centerh1400 Bad Request/h1/center
centerNo required SSL certificate was sent/center
hrcenternginx/1.4.6 (Ubuntu)/center
/body
/html

This is an example that uses urllib2/httplib, directly:

import urllib2
import httplib

cert_filepath = '/var/lib/rt_data/ssl/rt.crt.pem'
key_filepath = '/var/lib/rt_data/ssl/rt.private_key.pem'

url = 'https://deploy_api.local:8443/auth/admin/1/hosts'


class HTTPSClientAuthHandler(urllib2.HTTPSHandler):
Wrapper to allow for authenticated SSL connections.

def __init__(self, key, cert):
urllib2.HTTPSHandler.__init__(self)
self.key = key
self.cert = cert

def https_open(self, req):
# Rather than pass in a reference to a connection class, we pass in
# a reference to a function which, for all intents and purposes,
# will behave as a constructor
return self.do_open(self.getConnection, req)

def getConnection(self, host, timeout=300):
return httplib.HTTPSConnection(host, key_file=self.key, 
cert_file=self.cert)

opener = urllib2.build_opener(HTTPSClientAuthHandler(key_filepath, 
cert_filepath))
response = opener.open(url)

response_data = response.read()
print(response_data)

These are the factors:

- It works when connecting to the remote server. Both local and remote are 
Nginx with similar configs.
- cURL works perfectly:

  curl -s -v -X GET -k --cert /var/lib/rt_data/ssl/rt.crt.pem --key 
/var/lib/rt_data/ssl/rt.private_key.pem 
https://server.local:8443/auth/admin/1/hosts

- I've tried under Vagrant with Ubuntu 12.04 (2.7.3) and 14.04 (2.7.6). No 
difference.
- It works with Python 3.4 on the local system. This only has only affected 2.7 
very suddenly.

Due to the error-message above, it seems like there's a break down in sending 
the certificate/key.

I have no idea what's going on, and this has caused me a fair amount of 
distress. Can you provide me a direction?

--
components: Library (Lib)
messages: 230934
nosy: Dustin.Oprea
priority: normal
severity: normal
status: open
title: urllib2/httplib is rendering 400s for every authenticated-SSL request, 
suddenly
type: behavior
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22835
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22824] Update reprlib to use set literals

2014-11-09 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 147fda13bec8 by Raymond Hettinger in branch 'default':
Issue #22824:  Updated reprlib output format for sets to use set literals.
https://hg.python.org/cpython/rev/147fda13bec8

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22824
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue22824] Update reprlib to use set literals

2014-11-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Thanks for the patch.

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue22824
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >