Re: setuptools + data_files = 2

2014-10-23 Thread Simon Kennedy
On Wednesday, 22 October 2014 19:43:25 UTC+1, luc2  wrote:
> hello, would you know how to make data_files work in setuptools ?
> i can't figure out how to put datas in the generated .tar.gz

If you're creating an sdist then you'll need to create a MANIFEST.in file in 
the same folder as setup.py with the following contents

include share/test_file.txt

If you're creating a bdist (egg or wheel) the parameter name you need is

package_data={'share': [share/test_file.txt]},
-- 
https://mail.python.org/mailman/listinfo/python-list


Truthiness

2014-10-23 Thread Simon Kennedy
Just out of academic interest, is there somewhere in the Python docs where the 
following is explained?

>>> 3 == True
False
>>> if 3:
print("It's Twue")

It's Twue

i.e. in the if statement 3 is True but not in the first
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Truthiness

2014-10-23 Thread Simon Kennedy
Thanks everyone. That's a thorough enough explanation for me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OS X Menubar in Tkinter

2014-10-28 Thread Simon Kennedy
On Thursday, 23 October 2014 20:02:43 UTC+1, Chris Angelico  wrote:
> I don't think it's possible to auto-solve the Google Groups formatting
> issues at the mailing list level, as the fundamental problem is that
> information isn't being transmitted. (Forcing everything to be wrapped
> and forcing blank line removal risks breaking other formatting.) The
> last time I had a job interview with Google, I said that I wanted to
> spend my 20% time fixing Google Groups' paragraph handling... and then
> they didn't hire me. Not sure if this is coincidental or not. :)
> 
> ChrisA

Hopefully something may be happening...

https://productforums.google.com/d/msg/apps/4WQcWWajjvU/0NF7JgezGS0J
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a counter

2014-10-16 Thread Simon Kennedy
On Wednesday, 15 October 2014 19:39:43 UTC+1, Shiva  wrote:
> I am trying to search a string through files in a directory - however while
> Python script works on it and writes a log - I want to present the user with
> count of number of strings found. So it should increment for each string 
> found.

You may ignore the following if you are just starting out on your Python 
learning odyssey but if you're past the early stages and looking to try 
something different then read on.

When you looked through the other answers and found a solution you're happy 
with that does not use the standard library you can look through the 
documentation and find a stdlib 
(https://docs.python.org/2.7/library/index.html) provided way that may be 
slightly more elegant for counting strings.

Something like the following ::

>>> from collections import defaultdict
>>> counter = defaultdict(int)
>>> counter['string1'] += 1
>>> counter['string2'] += 1
>>> counter['string1'] += 1
>>> print('Count string1={string1}, string2={string2}'.format(**counter), 
end='\r')
Count string1=2, string2=1

https://docs.python.org/3/library/collections.html#collections.defaultdict

In the above code defaultdict is like a dictionary but if a key is not found 
then it uses the `int` factory parameter to add a value that is an integer with 
a value of 0  (which is what executing ``int()`` returns if you do it in the 
interactive Python prompt) for the dictionary key you're trying to access.

or ::

>>> from collections import Counter
>>> counter = Counter()
>>> s = 'string1 string2 string1'
>>> s.split()
['string1', 'string2', 'string1']
>>> counter.update(s.split())
>>> print('Count string1={string1}, string2={string2}'.format(**counter), 
end='\r')
Count string1=2, string2=1

https://docs.python.org/2.7/library/collections.html#collections.Counter

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


Re: Is there an easy way to control indents in Python

2014-10-16 Thread Simon Kennedy
On Wednesday, 15 October 2014 20:31:15 UTC+1, Ian  wrote:
> I agree. I very rarely use blank lines inside functions. As I see it,
> if you feel you need a blank line for separation within a function,
> that's an indication your function is overly complex and should be
> broken up.

Whereas I feel that if I wanted to write code which looked like that I'd have 
learnt/learned Perl ;-)

Each to their own.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Creating a counter

2014-10-16 Thread Simon Kennedy
On Thursday, 16 October 2014 15:05:47 UTC+1, Ian  wrote:
> I would have suggested a Counter if I thought it fit the OP's use
> case. If you're listing directory contents, you're not going to have
> any repeated strings, so all the counts will be 1, and your Counter
> might as well be a list, which is what you got from calling
> os.listdir() in the first place. So I was more inclined to think that
> the OP was only trying to count one thing.

I read the OP's question as he was looking for the string in the contents of 
each file in the directory not in the file names themselves but as you say...

> In any case, the question turned out to actually be about printing,
> not counting.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there an easy way to control indents in Python

2014-10-20 Thread Simon Kennedy
On Saturday, 18 October 2014 11:53:16 UTC+1, Steven D'Aprano  wrote:
> I'm curious what aspect of idiomatic Perl code you are referring to. When
> people talk about Perl code dismissively, I normally think of three things:
> 
> - excessively long one-liners;
> - excessive use of symbols and sigils ("line noise");
> - "More Than One [Thousand] Ways To Do It"

I'll preface the following by stating that I program in Python as a hobby and 
that the only programming I've done professionally was a few years ago now and 
consisted of a Visual Basic style language (Wonderware Intouch) and a piece of 
software called ABB Sattline.

Not having ever attempted to go beyond even the basics of Perl, the aspect that 
causes me to refer to Perl 'dismissively' as well comment in this thread, is 
that I don't find Perl to be an aesthetically pleasing language and I consider 
Python functions which have no blank lines in them to be a small step towards 
Perl.

Some people do not like Python's indentation rules but for me it's a large part 
of what draws me to program in Python. Spaces for indentation and blank lines 
are both aspects of how I like to program. 

I write in Python because I like to, not because I have to.

I think the only reason I might code a function with no blank lines was if I 
was programming in a language that using blank lines caused it to run too 
slowly.
 
> Are you suggesting that Perl functions tend to be too small? What do you
> consider "too small"?

No function is "too small". A one line function if it helps to describe the 
higher level code where it is called is fine by me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there an easy way to control indents in Python

2014-10-21 Thread Simon Kennedy
On Monday, 20 October 2014 18:56:05 UTC+1, Ian  wrote:
> Rather, I'm saying that where the blank line is should be the start of
> a new function. There would still be a blank line, just no longer
> inside the function.
> 
> Now, maybe you think there should be more blank lines in the above, in
> which case we'll just have to disagree on that point.

Why did you separate the above 2 sequences of thoughts by a blank line? Is the 
inherent pause in the communication of your thoughts not also applicable to 
your code?

Where we see the pause between thoughts appears to be in a different place. I 
see them both within the function and between the functions and I assume you 
see them between the functions only.

BTW I'm more than happy to disagree. There is no right or wrong answer unless 
Guido wants to pronounce on the issue :-J
-- 
https://mail.python.org/mailman/listinfo/python-list