New Project for rpm spec file creation

2013-12-07 Thread Unix SA
Hello Guys,

I am starting new project on github for rpm spec file creation .. currently
repository is empty and i am looking for ideas from the people who are
experts in creating rpms for different applications 

please share your ideas to me .. . currently what i know is i can have some
template file for .SPEC file and i can ask some inputs from users and
update that template file .. but looks like there are lot of template i
will have to look in .. so if you got any better idea, please clone my
repository and help to contribute.. .. or just reply back with your ideas..

Thanks in advance.

https://github.com/dhajoshi/rpm-spec-generator

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


Re: Managing Google Groups headaches

2013-12-07 Thread wxjmfauth
Rusi:

"unicode as a medium is universal in the same way that
ASCII used to be"

Probably, you do not realize deeply how this sentence
is correct. Unicode and ascii are constructed in the
same way. It has not even to do with "characters", but
with mathematics.

It is on this level the FSR fails. It is mathematically
wrong by design!

jmf


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


Re: Managing Google Groups headaches

2013-12-07 Thread Steven D'Aprano
On Sat, 07 Dec 2013 02:16:02 -0800, wxjmfauth wrote:

> Rusi:
> 
> "unicode as a medium is universal in the same way that ASCII used to be"
> 
> Probably, you do not realize deeply how this sentence is correct.
> Unicode and ascii are constructed in the same way. It has not even to do
> with "characters", but with mathematics.
> 
> It is on this level the FSR fails. It is mathematically wrong by design!


I'm reminded of that fellow, I don't remember his name, who *years* after 
the Wright Brothers had flown, and there were dozens of people building 
aeroplanes, was still trying to convince everyone that heavier-than-air 
flight was mathematically impossible.


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


Re: One liners

2013-12-07 Thread Steven D'Aprano
On Fri, 06 Dec 2013 22:27:00 -0500, Roy Smith wrote:

> Just for fun, I took a look through the Songza code base.  66 kloc of
> non-whitespace Python.  I found 192 ternary expressions.  Here's a few
> of the more bizarre ones (none of which I consider remotely readable):
> 
> -- 
> extracols = ( sorted(set.union(*(set(t.data.keys()) for t in tracks)))
>   if tracks else [] )

[extra parentheses added so I can split the line over two]

I actually don't find that too bad, readability-wise. Not ideal, but I 
can follow it. However, I wonder why t.data.keys() is converted to a set 
before being unpacked? Even assuming that data.keys are not necessarily 
unique, wouldn't building the union make them so?

extracols = ( sorted(set.union(*(t.data.keys()) for t in tracks)))
  if tracks else [] )


Also, you can get rid of the `if tracks` check altogether by using a 
bound method instead of an unbound method:

extracols = sorted(set().union(*(t.data.keys()) for t in tracks))

ought to work even if tracks is empty.



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


Re: Managing Google Groups headaches

2013-12-07 Thread Chris Angelico
On Sat, Dec 7, 2013 at 10:25 PM, Steven D'Aprano
 wrote:
> On Sat, 07 Dec 2013 02:16:02 -0800, wxjmfauth wrote:
>
>> Rusi:
>>
>> "unicode as a medium is universal in the same way that ASCII used to be"
>>
>> Probably, you do not realize deeply how this sentence is correct.
>> Unicode and ascii are constructed in the same way. It has not even to do
>> with "characters", but with mathematics.
>>
>> It is on this level the FSR fails. It is mathematically wrong by design!
>
>
> I'm reminded of that fellow, I don't remember his name, who *years* after
> the Wright Brothers had flown, and there were dozens of people building
> aeroplanes, was still trying to convince everyone that heavier-than-air
> flight was mathematically impossible.

Nearest I can find is:

https://en.wikipedia.org/wiki/Simon_Newcomb#On_the_impossibility_of_a_flying_machine

He at least accepted the Wrights' work once he found out about it.
Also, he didn't make repeated usenet posts that torpedo you in the
face and leave an "Uh?"-shaped hole. [1] I'm still not sure what jmf
meant by the above.

ChrisA

[1] http://bofh.ntk.net/BOFH/1999/bastard99-24.php
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: One liners

2013-12-07 Thread Jussi Piitulainen
Steven D'Aprano writes:

> On Fri, 06 Dec 2013 22:27:00 -0500, Roy Smith wrote:
> 
> > Just for fun, I took a look through the Songza code base.  66 kloc of
> > non-whitespace Python.  I found 192 ternary expressions.  Here's a few
> > of the more bizarre ones (none of which I consider remotely readable):
> > 
> > -- 
> > extracols = ( sorted(set.union(*(set(t.data.keys()) for t in tracks)))
> >   if tracks else [] )
> 
> [extra parentheses added so I can split the line over two]
> 
> I actually don't find that too bad, readability-wise. Not ideal, but I 
> can follow it. However, I wonder why t.data.keys() is converted to a set 
> before being unpacked? Even assuming that data.keys are not necessarily 
> unique, wouldn't building the union make them so?
> 
> extracols = ( sorted(set.union(*(t.data.keys()) for t in tracks)))
>   if tracks else [] )
> 
> 
> Also, you can get rid of the `if tracks` check altogether by using a 
> bound method instead of an unbound method:
> 
> extracols = sorted(set().union(*(t.data.keys()) for t in tracks))
> 
> ought to work even if tracks is empty.

I suspect in the original code tracks could be None (or False) and
then the part of the code that bombs is 'for t in tracks' because
tracks is not iterable.

One could write [f(t) for t in tracks or []] and it wouldn't be blamed
on a binary operator - or maybe it would - but I suspect the cleaner
design would be to first make sure that an empty tracks is an empty
list (or an empty whatever-it-needs-to-be):

  if tracks is None:
 tracks = []
  ...
  extracols = sorted(set.union(*(t.data.keys()) for t in tracks))

Still, is t.data.keys() a collection of sets? Maybe frozensets? And
then their unions are being sorted by set inclusion, which is not a
total order. Does sorted work correctly with a partial order? I don't
think it does.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ASCII and Unicode

2013-12-07 Thread giacomo boffi
Steven D'Aprano  writes:

> Ironically, your post was not Unicode.  [...] Your post was sent
> using a legacy encoding, Windows-1252, also known as CP-1252

i access rusi's post using a NNTP server,
and in his post i see

Content-Type: text/plain; charset=UTF-8

is it possible that what you see is an artifact
of the gateway?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Managing Google Groups headaches

2013-12-07 Thread Roy Smith
In article <[email protected]>,
 [email protected] wrote:

> It is on this level the FSR fails.

What is "FSR"?  I apologize if this was explained earlier in the thread 
and I can't find the reference.

https://en.wikipedia.org/wiki/FSR#Science_and_technology was no help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: One liners

2013-12-07 Thread Rotwang

On 07/12/2013 12:41, Jussi Piitulainen wrote:

[...]

   if tracks is None:
  tracks = []


Sorry to go off on a tangent, but in my code I often have stuff like 
this at the start of functions:


tracks = something if tracks is None else tracks

or, in the case where I don't intend for the function to be passed 
non-default Falsey values:


tracks = tracks or something

Is there any reason why the two-line version that avoids the ternary 
operator should be preferred to the above?

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


Re: Managing Google Groups headaches

2013-12-07 Thread Tim Chase
On 2013-12-07 11:08, Roy Smith wrote:
> In article <[email protected]>,
>  [email protected] wrote:
> 
> > It is on this level the FSR fails.
> 
> What is "FSR"?  I apologize if this was explained earlier in the
> thread and I can't find the reference.

Flexible String Representation = PEP393

http://www.python.org/dev/peps/pep-0393/

-tkc



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


Re: Managing Google Groups headaches

2013-12-07 Thread Rotwang

On 07/12/2013 16:08, Roy Smith wrote:

In article <[email protected]>,
  [email protected] wrote:


It is on this level the FSR fails.


What is "FSR"?  I apologize if this was explained earlier in the thread
and I can't find the reference.


It's the Flexible String Representation, introduced in Python 3.3:

http://www.python.org/dev/peps/pep-0393/
--
https://mail.python.org/mailman/listinfo/python-list


Re: One liners

2013-12-07 Thread Michael Torrie
On 12/07/2013 09:13 AM, Rotwang wrote:
> On 07/12/2013 12:41, Jussi Piitulainen wrote:
>> [...]
>>
>>if tracks is None:
>>   tracks = []
> 
> Sorry to go off on a tangent, but in my code I often have stuff like 
> this at the start of functions:
> 
>  tracks = something if tracks is None else tracks
> 
> or, in the case where I don't intend for the function to be passed 
> non-default Falsey values:
> 
>  tracks = tracks or something
> 
> Is there any reason why the two-line version that avoids the ternary 
> operator should be preferred to the above?

I think for such a short operation, and for a common need like this,
what you do is fine.  Personally I prefer the part you quoted from
Jussi, but your examples are just fine for correctness and readability.
 I think Dan's gripes come when cleverness is taken to the extreme.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: One liners

2013-12-07 Thread Steven D'Aprano
On Sat, 07 Dec 2013 16:13:09 +, Rotwang wrote:

> On 07/12/2013 12:41, Jussi Piitulainen wrote:
>> [...]
>>
>>if tracks is None:
>>   tracks = []
> 
> Sorry to go off on a tangent, but in my code I often have stuff like
> this at the start of functions:
> 
>  tracks = something if tracks is None else tracks
> 
> or, in the case where I don't intend for the function to be passed
> non-default Falsey values:
> 
>  tracks = tracks or something
> 
> Is there any reason why the two-line version that avoids the ternary
> operator should be preferred to the above?

Only if you need to support Python 2.4, which doesn't have the ternary if 
operator :-)



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


Re: Managing Google Groups headaches

2013-12-07 Thread rusi
On Saturday, December 7, 2013 3:46:02 PM UTC+5:30, [email protected] wrote:
> Rusi:

> "unicode as a medium is universal in the same way that
> ASCII used to be"

> Probably, you do not realize deeply how this sentence
> is correct. Unicode and ascii are constructed in the
> same way. It has not even to do with "characters", but
> with mathematics.

On the contrary, I'd say we have some rather interesting
'characters' out here.

> It is on this level the FSR fails. It is mathematically
> wrong by design!

Now thats an even more interesting statement. Only not sure what it means
Here are some attempts

It is wrong therefore unmathematical
It is designed so its wrong
It is mathematical so its undesigned

Any Ive missed??
-- 
https://mail.python.org/mailman/listinfo/python-list


[newbie] struggling wth tkinter

2013-12-07 Thread Jean Dubois
I'm trying to go through a tutorial on tkinter which has the code below as an 
example. The only thing I see when running it is a little popup with "Click 
mouse here to quit" which works as expected but always shows the following 
error-message.
However the "main" window which should let you enter the numbers is not shown.

This is the quit error message:
Traceback (most recent call last):
  File "./feet2meters.py", line 3, in 
from tkinter import ttk
ImportError: cannot import name ttk

This is the code:
#!/usr/bin/env python
from tkinter import *
from tkinter import ttk

def calculate(*args):
try:
value = float(feet.get())
meters.set((0.3048 * value * 1.0 + 0.5)/1.0)
except ValueError:
pass

root = Tk()
root.title("Feet to Meters")

mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)

feet = StringVar()
meters = StringVar()

feet_entry = ttk.Entry(mainframe, width=7, textvariable=feet)
feet_entry.grid(column=2, row=1, sticky=(W, E))

ttk.Label(mainframe, textvariable=meters).grid(column=2, row=2, sticky=(W, E))
ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=3, 
row=3, sticky=W)

ttk.Label(mainframe, text="feet").grid(column=3, row=1, sticky=W)
ttk.Label(mainframe, text="is equivalent to").grid(column=1, row=2, sticky=E)
ttk.Label(mainframe, text="meters").grid(column=3, row=2, sticky=W)

for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)

feet_entry.focus()
root.bind('', calculate)

root.mainloop()

thanks in advance
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: One liners

2013-12-07 Thread Michael Torrie
On 12/06/2013 08:27 PM, Roy Smith wrote:
> In article <[email protected]>,
>  Steven D'Aprano  wrote:
> 
>> The ternary if is slightly unusual and unfamiliar
> 
> It's only unusual an unfamiliar if you're not used to using it :-)  
> Coming from a C/C++ background, I always found the lack of a ternary 
> expression rather limiting.  There was much rejoicing in these parts 
> when it was added to the language relatively recently.  I use them a lot.
> 
> On the other hand, I found list comprehensions to be mind-bogglingly 
> confusing when I first saw them (read: slightly unusual and unfamiliar).  
> It took me a long time to warm up to the concept.  Now I love them.
> 
>> As for readability, I accept that ternary if is unusual compared to other 
>> languages, but it's still quite readable in small doses. If you start 
>> chaining them:
>>
>> result = a if condition else b if flag else c if predicate else d 
>>
>> you probably shouldn't.
> 
> That I agree with (and it's just as true in C as it is in Python).
> 
> Just for fun, I took a look through the Songza code base.  66 kloc of 
> non-whitespace Python.  I found 192 ternary expressions.  Here's a few 
> of the more bizarre ones (none of which I consider remotely readable):
> 
> --
> extracols = sorted(set.union(*(set(t.data.keys()) for t in tracks))) if 
> tracks else []

This is a generator expressions, and ternary ifs are common and often
needed in generator expressions.

> --
> c2s = compids2songs(set(targets.keys()) | 
> set.union(*map(set,targets.itervalues())),self.docmap,self.logger) if 
> targets else {}

I suspect the ternary distracted you on this one.  The ternary here is
needed because if targets is None the expression fails.  This part
anyway is a common idiom.

The rest is basically making a set (list of unique items only) of the
combined keys and values from the "targets" dictionary.  Now I'm not
sure why the programmer needs do this, but nevertheless that's what it's
doing.  set.union is used because that can iterate over a list of sets,
which is what the map returns.  I suppose they could have done this, but
it wouldn't be much clearer unless you knew what sets, map and
itervalues do:

if targets:
c2s = compids2songs(
set(targets.keys()) |
  set.union(*map(set,targets.itervalues())),
self.docmap,
self.logger )
else:
   c2s = {}

In any case the ternary operator isn't really the part you were
complaining about.  Personally if I needed to do this particular
operation a lot (combine keys and values into a set), I'd write a
function that returned the set.  Still can't avoid the ternary, though,
unless you made compids2songs a little smarter (and we don't know what
compids2songs does with an empty set):

def dict_keys_and_values_set (some_dict):
   return set(some_dict.keys()) |
set.union(*map(set,some_dict.itervalues()))

c2s = compids2songs( dict_keys_and_values_set(targets) ) if targets else {}

or I suppose you could o this:

c2s = {}
if targets: c2s = compids2songs( dict_keys_and_values_set(targets) )

Just a matter of taste.

> --
> code = 2 if (pmp3,paac)==(mmp3,maac) else 3 if any(x is None for x in 
> (pmp3,paac,mmp3,maac)) else 4
> --

This one probably could stand to be reworked for sure!  A standard if
block would be much clearer.  Definitely an example of a programmer
thinking he was clever... maybe a git bisect could identify the author
and we can shame him.

> Anybody else have some fun ternary abuse examples?

Only the last one seems to be problematic to me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: One liners

2013-12-07 Thread Michael Torrie
On 12/07/2013 09:56 AM, Michael Torrie wrote:
>> extracols = sorted(set.union(*(set(t.data.keys()) for t in tracks))) if 
>> tracks else []
> 
> This is a generator expressions, and ternary ifs are common and often
> needed in generator expressions.

Oops. This is not a generator expression at all!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Managing Google Groups headaches

2013-12-07 Thread Ned Batchelder

On 12/7/13 11:27 AM, rusi wrote:

On Saturday, December 7, 2013 3:46:02 PM UTC+5:30, [email protected] wrote:

Rusi:



"unicode as a medium is universal in the same way that
ASCII used to be"



Probably, you do not realize deeply how this sentence
is correct. Unicode and ascii are constructed in the
same way. It has not even to do with "characters", but
with mathematics.


On the contrary, I'd say we have some rather interesting
'characters' out here.


It is on this level the FSR fails. It is mathematically
wrong by design!


Now thats an even more interesting statement. Only not sure what it means
Here are some attempts

It is wrong therefore unmathematical
It is designed so its wrong
It is mathematical so its undesigned

Any Ive missed??



JMF: Please stop making this claim.  The last 20 times you claimed it 
you didn't convince anyone on this list, and I doubt you have any new 
information.


Rusi: if you are interested in the details, search the archives.

--
Ned Batchelder, http://nedbatchelder.com

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


Re: One liners

2013-12-07 Thread rusi
On Saturday, December 7, 2013 10:26:04 PM UTC+5:30, Michael Torrie wrote:
> On 12/06/2013 08:27 PM, Roy Smith wrote:
> >  Steven D'Aprano  wrote:
> >> The ternary if is slightly unusual and unfamiliar
> > It's only unusual an unfamiliar if you're not used to using it :-)  
> > Coming from a C/C++ background, I always found the lack of a ternary 
> > expression rather limiting.  There was much rejoicing in these parts 
> > when it was added to the language relatively recently.  I use them a lot.
> > On the other hand, I found list comprehensions to be mind-bogglingly 
> > confusing when I first saw them (read: slightly unusual and unfamiliar).  
> > It took me a long time to warm up to the concept.  Now I love them.
> >> As for readability, I accept that ternary if is unusual compared to other 
> >> languages, but it's still quite readable in small doses. If you start 
> >> chaining them:
> >> result = a if condition else b if flag else c if predicate else d 
> >> you probably shouldn't.
> > That I agree with (and it's just as true in C as it is in Python).
> > Just for fun, I took a look through the Songza code base.  66 kloc of 
> > non-whitespace Python.  I found 192 ternary expressions.  Here's a few 
> > of the more bizarre ones (none of which I consider remotely readable):
> > --
> > extracols = sorted(set.union(*(set(t.data.keys()) for t in tracks))) if 
> > tracks else []

> This is a generator expressions, and ternary ifs are common and often
> needed in generator expressions.

> > --
> > c2s = compids2songs(set(targets.keys()) | 
> > set.union(*map(set,targets.itervalues())),self.docmap,self.logger) if 
> > targets else {}

> I suspect the ternary distracted you on this one.  The ternary here is
> needed because if targets is None the expression fails.  This part
> anyway is a common idiom.

> The rest is basically making a set (list of unique items only) of the
> combined keys and values from the "targets" dictionary.  Now I'm not
> sure why the programmer needs do this, but nevertheless that's what it's
> doing.  set.union is used because that can iterate over a list of sets,
> which is what the map returns.  I suppose they could have done this, but
> it wouldn't be much clearer unless you knew what sets, map and
> itervalues do:

> if targets:
> c2s = compids2songs(
> set(targets.keys()) |
>   set.union(*map(set,targets.itervalues())),
> self.docmap,
> self.logger )
> else:
>c2s = {}

> In any case the ternary operator isn't really the part you were
> complaining about.  Personally if I needed to do this particular
> operation a lot (combine keys and values into a set), I'd write a
> function that returned the set.  Still can't avoid the ternary, though,
> unless you made compids2songs a little smarter (and we don't know what
> compids2songs does with an empty set):

> def dict_keys_and_values_set (some_dict):
>return set(some_dict.keys()) |
> set.union(*map(set,some_dict.itervalues()))

> c2s = compids2songs( dict_keys_and_values_set(targets) ) if targets else {}

> or I suppose you could o this:

> c2s = {}
> if targets: c2s = compids2songs( dict_keys_and_values_set(targets) )

> Just a matter of taste.

> > --
> > code = 2 if (pmp3,paac)==(mmp3,maac) else 3 if any(x is None for x in 
> > (pmp3,paac,mmp3,maac)) else 4
> > --

Just trying to rewrite that in a way which I try to use for long if-exprs

code =  2if (pmp3,paac)==(mmp3,maac)   else
3if any(x is None for x in (pmp3,paac,mmp3,maac))  else
4


> This one probably could stand to be reworked for sure!  A standard if
> block would be much clearer.  Definitely an example of a programmer
> thinking he was clever... maybe a git bisect could identify the author
> and we can shame him.


The logic for writing (and hopefully reading) it this way is like this:

In math we often have equations that are defined by cases -- typically typeset 
with a large curly bracket.  Those else's hanging at the end are to be read as
a signal to read this whole expr and though under a big curly brace.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: One liners

2013-12-07 Thread Jussi Piitulainen
Rotwang writes:

> On 07/12/2013 12:41, Jussi Piitulainen wrote:
> > [...]
> >
> >if tracks is None:
> >   tracks = []
> 
> Sorry to go off on a tangent, but in my code I often have stuff like
> this at the start of functions:
> 
>  tracks = something if tracks is None else tracks
> 
> or, in the case where I don't intend for the function to be passed
> non-default Falsey values:
> 
>  tracks = tracks or something
> 
> Is there any reason why the two-line version that avoids the ternary
> operator should be preferred to the above?

My motivation is that the "one-armed if" highlights the condition,
together with the fact that nothing is changed unless the condition
holds. That said, I'm also fine with the forms you use.

On another tangent, I wish people called the conditional expression
the conditional expression. The number of its slots is about the least
salient property of the thing. :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] struggling wth tkinter

2013-12-07 Thread Dave Angel
On Sat, 7 Dec 2013 08:52:08 -0800 (PST), Jean Dubois 
 wrote:
I'm trying to go through a tutorial on tkinter which has the code 
below as an example. The only thing I see when running it is a little 
popup with "Click mouse here to quit" which works as expected but 
always shows the following error-message.
However the "main" window which should let you enter the numbers is 

not shown.

This is the quit error message:
Traceback (most recent call last):
  File "./feet2meters.py", line 3, in 
from tkinter import ttk
ImportError: cannot import name ttk



This is the code:
#!/usr/bin/env python
from tkinter import *
from tkinter import ttk


Thanks for supplying the complete traceback.  But you should also 
tell the python version and what OS.  I'll guess python 3.3 on Linux. 



Finally,  what version tk are you running?  These widgets were 
introduced in tk 8.5


Since it failed on the second import, none of the rest of the code 
matters. However, since you're not running it from a terminal window, 
it's conceivable that your ide is affecting the result.


--
DaveA

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


Re: [newbie] struggling wth tkinter

2013-12-07 Thread Cousin Stanley

>  
> The only thing I see when running it is a little popup 
> with "Click mouse here to quit" which works as expected 
> but always shows the following error-message. 

  This seems to be left over from an earlier post
  where you were binding a mouse event to a tk label

  Did you create a  new  file ?


> However the "main" window which should let you enter the
> numbers is not shown.
> 
> This is the quit error message:
> Traceback (most recent call last):
> File "./feet2meters.py", line 3, in 
> from tkinter import ttk
> ImportError: cannot import name ttk
> 
> This is the code:
>  

  If I copy/paste your code as posted
  into a new file named ftom.py
  and change the she-bang line
  as follows 

#!/usr/bin/env python3

  Then from the command line 

python3 ftom.py

  Your code runs as expected
  using python 3.2.3 


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: One liners

2013-12-07 Thread Terry Reedy

On 12/7/2013 11:13 AM, Rotwang wrote:

On 07/12/2013 12:41, Jussi Piitulainen wrote:

[...]

   if tracks is None:
  tracks = []


Sorry to go off on a tangent, but in my code I often have stuff like
this at the start of functions:

 tracks = something if tracks is None else tracks

or, in the case where I don't intend for the function to be passed
non-default Falsey values:

 tracks = tracks or something

Is there any reason why the two-line version that avoids the ternary
operator should be preferred to the above?


The 'extra' line is not necessary, as one can write

if tracks is None: tracks = [] # or something

I prefer this because it exactly expresses what one want done. The other 
branch


else: tracks = tracks

is superfluous and to me unaesthetic.

--
Terry Jan Reedy

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


Re: One liners

2013-12-07 Thread Mark Lawrence

On 06/12/2013 23:54, Dan Stromberg wrote:


Does anyone else feel like Python is being dragged too far in the
direction of long, complex, multiline one-liners?  Or avoiding temporary
variables with descriptive names?  Or using regex's for everything under
the sun?

What happened to using classes?  What happened to the beautiful emphasis
on readability?  What happened to debuggability (which is always harder
than writing things in the first place)?  And what happened to string
methods?

I'm pleased to see Python getting more popular, but it feels like a lot
of newcomers are trying their best to turn Python into Perl or
something, culturally speaking.



I see all of the above as being down to poor quality programmers who are 
new to Python and have their priorities wrong.  The following is 
extracted from Steve Maguire's "Writing Solid Code".  It's my belief 
that this is a reasonable summing up.


Jack's Priority List  Jill's Priority List
Correctness   Correctness
Global efficiency Testability
Size  Global efficiency
Local efficiency  Maintainability/clarity
Personal convenience  Consistency
Maintainability/clarity   Size
Personal expression   Local efficiency
Testability   Personal expression
Consistency   Personal convenience

Jill wants to write good quality, Pythonic code, Jack doesn't, yep?

--
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: [newbie] struggling wth tkinter

2013-12-07 Thread Terry Reedy

On 12/7/2013 1:12 PM, Dave Angel wrote:

On Sat, 7 Dec 2013 08:52:08 -0800 (PST), Jean Dubois
 wrote:

I'm trying to go through a tutorial on tkinter which has the code

below as an example. The only thing I see when running it is a little
popup with "Click mouse here to quit" which works as expected but always
shows the following error-message.

However the "main" window which should let you enter the numbers is

not shown.

This is the quit error message:
Traceback (most recent call last):
  File "./feet2meters.py", line 3, in 
from tkinter import ttk
ImportError: cannot import name ttk


That is supposed to work.


This is the code:
#!/usr/bin/env python
from tkinter import *
from tkinter import ttk


Thanks for supplying the complete traceback.  But you should also tell
the python version and what OS.  I'll guess python 3.3 on Linux.

Finally,  what version tk are you running?  These widgets were
introduced in tk 8.5


In 8.4, they were in the Tile extension. I do not know if that will 
work. Better, probably, to upgrade.


Since it failed on the second import, none of the rest of the code
matters. However, since you're not running it from a terminal window,
it's conceivable that your ide is affecting the result.


Until you are able to import ttk, I believe you could remove the import 
and all 'ttk.' appearances, as I do not see anything ttk-specific.



--
Terry Jan Reedy

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


Re: interactive help on the base object

2013-12-07 Thread Gregory Ewing

Mark Lawrence wrote:

Is it just me, or is this basically useless?

class object
 |  The most base type


It's also a somewhat strange construction from an English language
point of view. To make sense, it requires interpreting the word
"base" as an adjective, and when used that way it has connotations
of something to turn your nose up at. I'm assuming that's not the
impression we want to give!

Maybe something like "The ultimate base class of all classes"
would be better.

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


Re: One liners

2013-12-07 Thread bryan rasmussen
Someone was thinking in ruby there.



On Sat, Dec 7, 2013 at 1:14 AM, Dan Stromberg  wrote:

>
> On Fri, Dec 6, 2013 at 4:10 PM, Michael Torrie  wrote:
>
>> On 12/06/2013 04:54 PM, Dan Stromberg wrote:
>> > Does anyone else feel like Python is being dragged too far in the
>> direction
>> > of long, complex, multiline one-liners?  Or avoiding temporary variables
>> > with descriptive names?  Or using regex's for everything under the sun?
>> >
>> > What happened to using classes?  What happened to the beautiful
>> emphasis on
>> > readability?  What happened to debuggability (which is always harder
>> than
>> > writing things in the first place)?  And what happened to string
>> methods?
>> >
>> > I'm pleased to see Python getting more popular, but it feels like a lot
>> of
>> > newcomers are trying their best to turn Python into Perl or something,
>> > culturally speaking.
>>
>> I have not seen any evidence that this trend of yours is widespread.
>> The Python code I come across seems pretty normal to me.  Expressive and
>> readable.  Haven't seen any attempt to turn Python into Perl or that
>> sort of thing.  And I don't see that culture expressed on the list.
>> Maybe I'm just blind...
>
>
> I'm thinking mostly of stackoverflow, but here's an example I ran into (a
> lot of) on a job:
>
> somevar = some_complicated_thing(somevar) if
> some_other_complicated_thing(somevar) else somevar
>
> Would it really be so bad to just use an if statement?  Why are we
> assigning somevar to itself?  This sort of thing was strewn across 3 or 4
> physical lines at a time.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Is It Bug?

2013-12-07 Thread Mahan Marwat
Why this is not working.

>>> 'Hello, World'.replace('\\', '\\')

To me, Python will interpret '' to '\\'. And the replace method will 
replace '\\' with '\'. So, the result will be 'Hello, \World'. But it's give me 
'Hello, World'.

The result I want form the code is 'Hello, \World'.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: interactive help on the base object

2013-12-07 Thread Ned Batchelder

On 12/7/13 7:10 PM, Gregory Ewing wrote:

Mark Lawrence wrote:

Is it just me, or is this basically useless?

class object
 |  The most base type


It's also a somewhat strange construction from an English language
point of view. To make sense, it requires interpreting the word
"base" as an adjective, and when used that way it has connotations
of something to turn your nose up at. I'm assuming that's not the
impression we want to give!

Maybe something like "The ultimate base class of all classes"
would be better.



I've heard this described as "the root of the class hierarchy."

--
Ned Batchelder, http://nedbatchelder.com

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


Is It Bug?

2013-12-07 Thread Mahan Marwat
Why this is not working.

>>> 'Hello, World'.replace('\\', '\\')

To me, Python will interpret '' to '\\'. And the replace method will 
replace '\\' with '\'. So, the result will be 'Hello, \World'. But it's give me 
'Hello, World'.

The result I want form the code is 'Hello, \World'.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is It Bug?

2013-12-07 Thread Iuri
This way, it will replace '\' with '\', so nothing change.

>>> 'Hello, World'.replace('', '\\')
'Hello, \\World'
>>> print 'Hello, World'.replace('', '\\')
Hello, \World


On Sat, Dec 7, 2013 at 10:58 PM, Mahan Marwat  wrote:

> Why this is not working.
>
> >>> 'Hello, World'.replace('\\', '\\')
>
> To me, Python will interpret '' to '\\'. And the replace method will
> replace '\\' with '\'. So, the result will be 'Hello, \World'. But it's
> give me 'Hello, World'.
>
> The result I want form the code is 'Hello, \World'.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is It Bug?

2013-12-07 Thread Mark Lawrence

On 08/12/2013 00:59, Mahan Marwat wrote:

Why this is not working.


'Hello, World'.replace('\\', '\\')


Whoops a daisy!!! ---- ???



To me, Python will interpret '' to '\\'. And the replace method will 
replace '\\' with '\'. So, the result will be 'Hello, \World'. But it's give me 
'Hello, World'.

The result I want form the code is 'Hello, \World'.




--
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: Is It Bug?

2013-12-07 Thread Chris Angelico
On Sun, Dec 8, 2013 at 11:59 AM, Mahan Marwat  wrote:
> Why this is not working.
>
 'Hello, World'.replace('\\', '\\')
>
> To me, Python will interpret '' to '\\'. And the replace method will 
> replace '\\' with '\'. So, the result will be 'Hello, \World'. But it's give 
> me 'Hello, World'.
>
> The result I want form the code is 'Hello, \World'.

You're replacing with the same as the source string. That's not going
to change anything.

The first thing to get your head around is Python string literals.
You'll find them well described in the online tutorial, or poke around
in the interactive interpreter. Once you master that, you should be
able to understand what you're trying to do here.

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


Re: Is It Bug?

2013-12-07 Thread MRAB

On 08/12/2013 00:59, Mahan Marwat wrote:

Why this is not working.


'Hello, World'.replace('\\', '\\')


To me, Python will interpret '' to '\\'. And the replace method
will replace '\\' with '\'. So, the result will be 'Hello, \World'.
But it's give me 'Hello, World'.

The result I want form the code is 'Hello, \World'.


The original string contains 2 actual backslashes:


print('Hello, World')

Hello, \\World

Both the search and replacement strings contain 1 backslash:


print('\\')

\

You're asking it to replace every backslash with a backslash!

If you want to replace 2 consecutive backslashed with a single
backslash:

>>> 'Hello, World'.replace('', '\\')
'Hello, \\World'

Maybe it's clearer if you print it:

>>> print('Hello, World'.replace('', '\\'))
Hello, \World
--
https://mail.python.org/mailman/listinfo/python-list


Re: Is It Bug?

2013-12-07 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> The first thing to get your head around is Python string literals.
> You'll find them well described in the online tutorial, or poke around
> in the interactive interpreter. 

A couple of ideas to explore along those lines:

1) Read up on raw strings, i.e.

r'Hello, \World'

instead of 

'Hello, \\Word'

There's nothing you can do with raw strings that you can't do with 
regular strings, but they're easier to read when you start to use 
backslashes.

2) When in doubt about what I'm looking at in a string, I turn it into a 
list.  So, if I do:

>>> s = 'Hello, \\World'
>>> print s
Hello, \World

What is that character after the space?  Is it a backslash, or is it 
something that Python is printing as \W?  Not sure?  Just do:

>>> print list(s)
['H', 'e', 'l', 'l', 'o', ',', ' ', '\\', 'W', 'o', 'r', 'l', 'd']

and it's immediately obvious which it is.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Does Python optimize low-power functions?

2013-12-07 Thread Michael Torrie
On 12/06/2013 12:32 PM, Nick Cash wrote:
> Nope:
> 
> Python 3.3.0 (default, Sep 25 2013, 19:28:08) 
> [GCC 4.7.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 import dis
 dis.dis(lambda x: x*x)
>   1   0 LOAD_FAST0 (x) 
>   3 LOAD_FAST0 (x) 
>   6 BINARY_MULTIPLY  
>   7 RETURN_VALUE 
 dis.dis(lambda x: x**2)
>   1   0 LOAD_FAST0 (x) 
>   3 LOAD_CONST   1 (2) 
>   6 BINARY_POWER 
>   7 RETURN_VALUE 
> 
> 
> The reasons why have already been answered, I just wanted to point
> out that Python makes it extremely easy to check these sorts of
> things for yourself.

But this is just the interpreter bytecode that dis is showing.  It's not
showing the underlying implementation of binary_power, for example.
That could be defined in C code with any number of optimizations, and
indeed it appears that some are being done.  dis is great for showing
how python code breaks down, but it can't tell you much about the code
that underlies the byte codes themselves.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: One liners

2013-12-07 Thread Rotwang

On 07/12/2013 16:25, Steven D'Aprano wrote:

On Sat, 07 Dec 2013 16:13:09 +, Rotwang wrote:


On 07/12/2013 12:41, Jussi Piitulainen wrote:

[...]

if tracks is None:
   tracks = []


Sorry to go off on a tangent, but in my code I often have stuff like
this at the start of functions:

  tracks = something if tracks is None else tracks

or, in the case where I don't intend for the function to be passed
non-default Falsey values:

  tracks = tracks or something

Is there any reason why the two-line version that avoids the ternary
operator should be preferred to the above?


Only if you need to support Python 2.4, which doesn't have the ternary if
operator :-)


Thanks, and likewise to everyone else who replied.

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


Re: interactive help on the base object

2013-12-07 Thread Mark Janssen
>>> Is it just me, or is this basically useless?
>>>
>>> class object
>>>  |  The most *base* type
>>
[[Terry Reedy:]]
> How about something like.
> The default top *superclass* for all Python classes.

How 'bout you foos just admit that you didn't realize you've been
confused this whole time?  (It *is* possible isn't it?)

Mr. Ewing says "base" has to be interpreted as an *adjective* because
otherwise it would mean the BOTTOM (like the BASE of the pyramid),
while Terry responds that it is the TOP (*super*class).  Earlier,
Steven D'Aprano wanted to argue that this distinction was irrelevant,
but obviously it can't very well be both at once now cannit?

Could-the-world-be-so-crazy-confused-and-then-shoot-the-messenger?

Sadly, yes.

MarkJ
Tacoma, Washington
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: interactive help on the base object

2013-12-07 Thread Devin Jeanpierre
On Fri, Dec 6, 2013 at 9:03 AM, Mark Lawrence  wrote:
> Is it just me, or is this basically useless?
>
 help(object)
> Help on class object in module builtins:
>
> class object
>  |  The most base type
>

>
> Surely a few more words, or a pointer to this
> http://docs.python.org/3/library/functions.html#object, would be better?

It's good enough to give anyone that's seen it before a reminder of
what it is. pydoc is useless or worse if you don't know anything about
what you're reading. For example, the HTML docs frequently point out
potential security vulnerabilities in usages of libraries where pydoc
does not. (The wording *is* awkward, though.)

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


Re: Is It Bug?

2013-12-07 Thread rusi
On Sunday, December 8, 2013 6:28:24 AM UTC+5:30, Mahan Marwat wrote:
> Why this is not working.

> >>> 'Hello, World'.replace('\\', '\\')

> To me, Python will interpret '' to '\\'. And the replace method
> will replace '\\' with '\'. So, the result will be 'Hello,
> \World'. But it's give me 'Hello, World'.

> The result I want form the code is 'Hello, \World'.

I am mystified by this question.
Yes '\\' may be one slash or two or something else more exotic.
But whatever it is (and its not a syntax error like with '\') it is something.
So how can replace(something,something)  be anything other
than a no-op?

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


Re: Is It Bug?

2013-12-07 Thread Joshua Gardner
If I'm having to deal with incessant backslashes in a string I'll often
use the r'\' (raw string literal) syntax. Simplifies things quite a bit.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is It Bug?

2013-12-07 Thread Tim Roberts
Mahan Marwat  wrote:
>
>Why this is not working.
>
 'Hello, World'.replace('\\', '\\')
>
>To me, Python will interpret '' to '\\'. 

It's really important that you think about the difference between the way
string literals are written in Python code, and the way the strings
actually look in memory.

The Python literal 'Hello, World' contains exactly 2 backslashes.  We
have to spell it with 4 backslashes to get that result, but in memory there
are only two.

Similarly, the Python literal '\\' contains exactly one character.

So, if your goal is to change 2 backslashes to 1, you would need
'Hello, World'.replace('','\\')

However, REMEMBER that if you just have the command-line interpreter echo
the result of that, it's going to show you the string representation, in
which each backslash is shown as TWO characters.  Observe:

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> s = 'Hello, World'
>>> s
'Hello, World'
>>> print s
Hello, \\World
>>> s = s.replace('','\\')
>>> s
'Hello, \\World'
>>> print s
Hello, \World
>>>
-- 
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] struggling wth tkinter

2013-12-07 Thread Jean Dubois
Op zaterdag 7 december 2013 19:12:50 UTC+1 schreef Dave Angel:
> On Sat, 7 Dec 2013 08:52:08 -0800 (PST), Jean Dubois 
> 
>  wrote:
> 
> > I'm trying to go through a tutorial on tkinter which has the code 
> 
> below as an example. The only thing I see when running it is a little 
> 
> popup with "Click mouse here to quit" which works as expected but 
> 
> always shows the following error-message.
> 
> > However the "main" window which should let you enter the numbers is 
> 
> not shown.
> 
> > This is the quit error message:
> 
> > Traceback (most recent call last):
> 
> >   File "./feet2meters.py", line 3, in 
> 
> > from tkinter import ttk
> 
> > ImportError: cannot import name ttk
> 
> 
> 
> > This is the code:
> 
> > #!/usr/bin/env python
> 
> > from tkinter import *
> 
> > from tkinter import ttk
> 
> 
> 
> Thanks for supplying the complete traceback.  But you should also 
> 
> tell the python version and what OS.  I'll guess python 3.3 on Linux. 
> 
> 
> 
> 
> 
> Finally,  what version tk are you running?  These widgets were 
> 
> introduced in tk 8.5
> 
> 
> 
> Since it failed on the second import, none of the rest of the code 
> 
> matters. However, since you're not running it from a terminal window, 
> 
> it's conceivable that your ide is affecting the result.
> 
> 
> 
> -- 
> 
> DaveA

I have two pythons installed on my system:
Python 2.7.3 and Python 3.2.3
When using python2 I get the errors mentioned above
When using python3 (I removed the shebang and started as python3 
feettometers.py) then I get these errors:

coolens@antec2:~$ python3 feet2meters.py 
Traceback (most recent call last):
  File "feet2meters.py", line 1, in 
from tkinter import *
  File "/home/coolens/tkinter.py", line 2, in 
import Tkinter as tk
ImportError: No module named Tkinter

I tried to fix this by installing
apt-get install python3-tk (python3-tk_3.2.3-1_amd64.deb)

but the error remains

What should I do now?

thanks in advance
jean
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie] struggling wth tkinter

2013-12-07 Thread Chris Angelico
On Sun, Dec 8, 2013 at 6:40 PM, Jean Dubois  wrote:
> coolens@antec2:~$ python3 feet2meters.py
> ImportError: No module named Tkinter

In Python 3, the module's named tkinter instead of Tkinter. You should
be able to do the exact same import but with the lower-case name, or
if you need to support both:

try:
import tkinter as tk
except ImportError:
import Tkinter as tk

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


Re: [newbie] struggling wth tkinter

2013-12-07 Thread Jean Dubois
Op zaterdag 7 december 2013 19:23:30 UTC+1 schreef Cousin Stanley:
> >  
> 
> > The only thing I see when running it is a little popup 
> 
> > with "Click mouse here to quit" which works as expected 
> 
> > but always shows the following error-message. 
> 
> 
> 
>   This seems to be left over from an earlier post
> 
>   where you were binding a mouse event to a tk label
> 
> 
> 
>   Did you create a  new  file ?
> 
> 
> 
> 
> 
> > However the "main" window which should let you enter the
> 
> > numbers is not shown.
> 
> > 
> 
> > This is the quit error message:
> 
> > Traceback (most recent call last):
> 
> > File "./feet2meters.py", line 3, in 
> 
> > from tkinter import ttk
> 
> > ImportError: cannot import name ttk
> 
> > 
> 
> > This is the code:
> 
> >  
> 
> 
> 
>   If I copy/paste your code as posted
> 
>   into a new file named ftom.py
> 
>   and change the she-bang line
> 
>   as follows 
> 
> 
> 
> #!/usr/bin/env python3
> 
> 
> 
>   Then from the command line 
> 
> 
> 
> python3 ftom.py
> 
> 
> 
>   Your code runs as expected
> 
>   using python 3.2.3 
I tried you suggestion above:

This is what I get:
Traceback (most recent call last):
  File "./feet2meters.py", line 2, in 
from tkinter import *
  File "/home/jean/tkinter.py", line 2, in 
import Tkinter as tk
ImportError: No module named Tkinter

and this is my python3-version:
Python 3.2.3 (default, Sep 25 2013, 18:22:43) 
[GCC 4.6.3] on linux2

any idea what is going wrong?

thanks in advance
jean
-- 
https://mail.python.org/mailman/listinfo/python-list