Connect to Default Printer

2016-03-23 Thread Bryon Fawcett
Good afternoon.

Could you please advise me how to connect the python software to my default
printer.

Regards,

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


Re: Python to do CDC on XML files

2016-03-23 Thread Bruce Kirk
I agree, the challenge is the volume of the data to compare is 13. Million 
records. So it needs to be very fast

Sent from my iPad

> On Mar 23, 2016, at 4:47 PM, Bob Gailer  wrote:
> 
> 
> On Mar 23, 2016 4:20 PM, "Bruce Kirk"  wrote:
> >
> > Does anyone know of any existing projects on how to generate a change data 
> > capture on 2 very large xml files.
> >
> > The xml structures are the same, it is the data within the files that may 
> > differ.
> >
> It should not be too difficult to write a program that locates the tags 
> delimiting each record, then compare them.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: crash while using PyCharm / Python3

2016-03-23 Thread Adam

"Adam"  wrote in message 
news:ncikss$tks$1...@news.albasani.net...
>
> Host OS:Ubuntu Desktop 14.04 LTS / Unity
>
> System crashed while using PyCharm / Python3.
> Booting takes forever and stuck at the purple screen with
> the Ubuntu logo and the five dots cycling.
> How to fix?
>

Searching for this thread in a browser lead to
the code.activestate.com website where
I see posts from Daniel Wilcox.
But, in my newsreader, I do not see his posts,
which is why his posts are not getting any response.
Daniel, how/where are you responding to this thread?


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


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Rustom Mody
On Thursday, March 24, 2016 at 8:54:49 AM UTC+5:30, Chris Angelico wrote:
> On Thu, Mar 24, 2016 at 12:41 AM, BartC  wrote:
> > To extend this analogy better, executing byte-code to directly perform a
> > task itself might be equivalent to travelling on foot, while everyone is
> > suggesting taking the bus, tube or taxi.
> >
> > But when you are on foot, it might be worth looking at what's slowing you
> > down, or indeed at whether you are actually being slowed down at all. With
> > walking it's easy because 3mph is typical, you'll know when something is
> > obviously wrong (dragging or carrying a huge amount of baggage with you for
> > example). Running byte-code is not so obvious.
> >
> 
> It's easy to see that carrying five boxes of books will slow down
> you're walking *dramatically*. In fact, it's probably quicker to take
> just one of them, and then come back for another one, and so on. When
> you travel by car, it's much harder to measure the cost of the five
> boxes, but it made so much difference in walking time that you should
> probably take one box at a time, right?
> 
> This is how you're currently evaluating Python. Instead of starting
> with the most simple and obvious code and refining from there, you're
> starting from a whole lot of preconceived ideas about what's "fast" or
> "slow", and assuming/expecting that they'll all still be valid. Many
> of them won't be, yet you still persist in doing things based on what
> you expect to be the case (because of what's fast/slow in C or some
> other language). We've explained this a number of times, and one by
> one, we're coming to the conclusion that you not only don't understand
> Python, you don't *want* to understand Python; and until you actually
> understand how the language works, timing stats are dubious.
> 
> Do you understand why people aren't taking your results very seriously?

Terry recommended
a. re module
b. array lookup
c. dict lookup

Putting aside Bart's objection to re module for the moment,
he has already posted a list-lookup version.
In effect he has complied with the suggestions of experienced members of this
list (in this case a python-dev)

Can I request you (Bart) to re-post these data??
- if-else
- list-lookup
- dict-lookup
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Chris Angelico
On Thu, Mar 24, 2016 at 12:41 AM, BartC  wrote:
> To extend this analogy better, executing byte-code to directly perform a
> task itself might be equivalent to travelling on foot, while everyone is
> suggesting taking the bus, tube or taxi.
>
> But when you are on foot, it might be worth looking at what's slowing you
> down, or indeed at whether you are actually being slowed down at all. With
> walking it's easy because 3mph is typical, you'll know when something is
> obviously wrong (dragging or carrying a huge amount of baggage with you for
> example). Running byte-code is not so obvious.
>

It's easy to see that carrying five boxes of books will slow down
you're walking *dramatically*. In fact, it's probably quicker to take
just one of them, and then come back for another one, and so on. When
you travel by car, it's much harder to measure the cost of the five
boxes, but it made so much difference in walking time that you should
probably take one box at a time, right?

This is how you're currently evaluating Python. Instead of starting
with the most simple and obvious code and refining from there, you're
starting from a whole lot of preconceived ideas about what's "fast" or
"slow", and assuming/expecting that they'll all still be valid. Many
of them won't be, yet you still persist in doing things based on what
you expect to be the case (because of what's fast/slow in C or some
other language). We've explained this a number of times, and one by
one, we're coming to the conclusion that you not only don't understand
Python, you don't *want* to understand Python; and until you actually
understand how the language works, timing stats are dubious.

Do you understand why people aren't taking your results very seriously?

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


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread BartC

On 23/03/2016 10:48, Chris Angelico wrote:

On Wed, Mar 23, 2016 at 9:34 PM, BartC  wrote:



Someone could be interested in cars, mechanics and performance without
wanting to know the most Pythonic way to get from Kings Cross to Heathrow.


But if I complain that the trek across four blocks of London cost me
ninety minutes and my train ticket (which I then had to get replaced),
you would blame it on me getting lost, rather than accepting my
assertion that London's slow to get around. And if you said "hey, take
a bus or a taxi next time", and I next time walked and got lost again,
you would rightly call me a fool. And if I then had the audacity to
say that London's streets are badly designed, because I looked at them
and even without knowing what sort of traffic goes on them, I can tell
that those are slow roads... you'd have very little respect for my
statements about London. It wouldn't matter if I'm the world's
greatest expert on hiking from Adelaide to Perth; it wouldn't matter
how many nuances of Nullarbor sand I'm familiar with, nor how best to
find drinking water there. I clearly know nothing about London, and my
complaints about the city should be taken with a grain of salt, until
such time as I put in the effort to get to know YOUR city YOUR way.


To extend this analogy better, executing byte-code to directly perform a 
task itself might be equivalent to travelling on foot, while everyone is 
suggesting taking the bus, tube or taxi.


But when you are on foot, it might be worth looking at what's slowing 
you down, or indeed at whether you are actually being slowed down at 
all. With walking it's easy because 3mph is typical, you'll know when 
something is obviously wrong (dragging or carrying a huge amount of 
baggage with you for example). Running byte-code is not so obvious.


Interestingly, the typical difference between my byte-code and 
CPython's, is roughly the same as between (my) cycling and walking. With 
odd spots where CPython is quicker (which I'm investigating...).


While PyPy can sometimes beat both of those, on a straight downhill 
section, but I suspect it cheats there a little by being motor-assisted.


(FWIW, in central London usually I walk or cycle. I wouldn't walk from 
King's Cross to LHR, nearly 20 miles, unless I had nothing better to do, 
or there was no alternative.)


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


Re: numpy arrays

2016-03-23 Thread Nobody
> What you want is called *transposing* the array:
> 
> http://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html
> 
> That should be a sufficiently fast operation.

Transposing itself is fast, as it just swaps the strides and dimensions
without touching the data (i.e. it returns a new view of the original
array), but subsequent operations may be slower as the data is no longer
contiguous (i.e. iterating over the flattened array in order won't result
in sequential memory access).

If that's an issue, you can use numpy.ascontiguousarray() to make a
contiguous copy of the data.

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


Re: Key Binding Problem

2016-03-23 Thread Wildman via Python-list
On Wed, 23 Mar 2016 20:34:08 -0400, Dennis Lee Bieber wrote:

> On Wed, 23 Mar 2016 10:58:09 -0500, Wildman via Python-list
>  declaimed the following:
> 
>>On Wed, 23 Mar 2016 02:47:47 -0400, Terry Reedy wrote:
>>
>>>  def load_image(self, _):
>>>  # load image file
>>> 
>>> You must pass the bound method, as you did, and not the function itself 
>>> (which has two parameters).
>>
>>I meant to ask a followup question in my previous post but
>>it slipped my mind.
>>
>>What is the best thing to do...
>>Define all procedures this way, (self. event)?
> 
>   Not "." but "," -- separate arguments

That was a typo.  My fingers have dyslexia.

>   Anything that is a method in a class object will tend to receive the
> object itself as the first argument (commonly called "self" in Python, "me"
> in Visual BASIC, "this" in C++). Tk callback functions (I think you were
> using Tkinter) likely pass the event data (that is, what triggered the
> callback -- a key-in callback passes information about the key that was
> pressed).
> 
>>Define all event handlers this way?
> 
>   If they are methods of a Tk class, then likely they need this format...
> But for classes you create yourself, it depends on how you intend to invoke
> them.

Thanks for the info.

>>Define only the event handlers that will be called from
>>elsewhere in the code, as in this case?
> 
>   Uhm... If an event handler is never invoked, why write it?

I was referring to procedures called by a button click as
opposed to a procedure calledd from elsewhere in the code.
I guess there is no difference.  I assume that is what you
meant.

-- 
 GNU/Linux user #557453
The cow died so I don't need your bull!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Not downloading

2016-03-23 Thread eryk sun
On Wed, Mar 23, 2016 at 12:31 PM, louis anderson
 wrote:
> After a workshop in my school today regarding python, i have downloaded it on 
> my laptop
> however when i go to launch it, it either tells me to modify python, repair 
> python or uninstall
> python. It will not let me go onto python at all. I do not know what is going 
> on and i hope
> yourselves can help me.

This problem is unlikely to be resolved on this list since attachments
don't work here (e.g. for screenshots and zipped log files). Please
create an issue on bugs.python.org.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Mark Lawrence

On 23/03/2016 23:55, Steven D'Aprano wrote:

On Thu, 24 Mar 2016 03:24 am, Random832 wrote:


On Wed, Mar 23, 2016, at 12:08, Mark Lawrence wrote:

And doing it 'Pythonically' can lead to suggestions such as the
following the other day:

   c, psource = psource[0], psource[1:]

(where psource is a very long string), which even I could tell, from
knowing what goes on behind the scenes, wasn't going to work well
(duplicating the rest of the string roughly every other character).



It would work perfectly. How would it duplicate the rest of the string
roughly every other character?


Er, I think he's suggesting that this would be in an inner loop
(something like while psource: c, psource = psource[0], psource[1:]).
What I'm not sure of is why he thinks this is pythonic.


Because somebody here (Dennis) criticised his earlier code for passing "your
entire source string along with the character from it to the function", and
suggested splitting the string into its head and tail instead. Dennis' code
started:

 while psource:
 c, psource = psource[0], psource[1:]
 lxsymbol = disptable[min(ord(c), 256)](c, psource)


But one positive: this conclusively proves that "Pythonic" is in the eye of
the beholder. Dennis thinks that c, psource = psource[0], psource[1:] is
reasonable Python code; you think it's not ("I'm not sure why [Bart] thinks
this is pythonic").

Pythonic or not, Bart is correct to be concerned about the performance,


Where and when did he ever say anything about performance with respect 
to the above piece of code?


--
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: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Chris Angelico
On Thu, Mar 24, 2016 at 11:12 AM, Random832  wrote:
> I guess the question is, what do you _actually_ need the tail string
> for? If you're using it in a loop, to pop further characters from (the
> scenario that would cause it to be copying the string over lots of
> times), wouldn't it make more sense to use a StringIO (or, in the real
> world where your C source code isn't a string, a file) and let that
> class take care of handing out characters when you ask for them?
>
> Like...
>
> fsource = StringIO(psource)
>
> while True:
> c = fsource.read(1)
> lxsymbol = disptable[min(ord(c), 256)](c, fsource)

Or... just grab an iterator off the string and call next() on it?

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


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Random832
On Wed, Mar 23, 2016, at 19:55, Steven D'Aprano wrote:
> while psource:
> c, psource = psource[0], psource[1:]
> lxsymbol = disptable[min(ord(c), 256)](c, psource)
> 
> 
> But one positive: this conclusively proves that "Pythonic" is in the eye
> of
> the beholder. Dennis thinks that c, psource = psource[0], psource[1:] is
> reasonable Python code; you think it's not ("I'm not sure why [Bart]
> thinks
> this is pythonic").

I guess the question is, what do you _actually_ need the tail string
for? If you're using it in a loop, to pop further characters from (the
scenario that would cause it to be copying the string over lots of
times), wouldn't it make more sense to use a StringIO (or, in the real
world where your C source code isn't a string, a file) and let that
class take care of handing out characters when you ask for them?

Like...

fsource = StringIO(psource)

while True:
c = fsource.read(1)
lxsymbol = disptable[min(ord(c), 256)](c, fsource)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Steven D'Aprano
On Thu, 24 Mar 2016 03:24 am, Random832 wrote:

> On Wed, Mar 23, 2016, at 12:08, Mark Lawrence wrote:
>> > And doing it 'Pythonically' can lead to suggestions such as the
>> > following the other day:
>> >
>> >   c, psource = psource[0], psource[1:]
>> >
>> > (where psource is a very long string), which even I could tell, from
>> > knowing what goes on behind the scenes, wasn't going to work well
>> > (duplicating the rest of the string roughly every other character).
>> >
>> 
>> It would work perfectly. How would it duplicate the rest of the string
>> roughly every other character?
> 
> Er, I think he's suggesting that this would be in an inner loop
> (something like while psource: c, psource = psource[0], psource[1:]).
> What I'm not sure of is why he thinks this is pythonic.

Because somebody here (Dennis) criticised his earlier code for passing "your
entire source string along with the character from it to the function", and
suggested splitting the string into its head and tail instead. Dennis' code
started:

while psource:
c, psource = psource[0], psource[1:]
lxsymbol = disptable[min(ord(c), 256)](c, psource)


But one positive: this conclusively proves that "Pythonic" is in the eye of
the beholder. Dennis thinks that c, psource = psource[0], psource[1:] is
reasonable Python code; you think it's not ("I'm not sure why [Bart] thinks
this is pythonic").

Pythonic or not, Bart is correct to be concerned about the performance,
since this ends up copying the string over and over again. If we start with
the string "aardvark", say, it gets split:

"a", "ardvark"
"a", "rdvark"
"r", "dvark"
"d", "vark"
"v", "ark"
"a", "rk"
"r", "k"
"k", ""

each of which involves creating two string objects. Ignoring the effects of
string interning (caching), an 8-character string gets split up into:

8 x 1 character strings;
1 x 7 character string;
1 x 6 character string;
1 x 5 character string;
1 x 4 character string;
1 x 3 character string;
1 x 2 character string;
1 x 1 character string;
1 x 0 character string;

thus creating 16 string objects in total, and copying 8+7+6+5+4+3+2+1+0
characters, or 36 characters in total.

For an N character string, we have:

N x 1 character strings;
1 x N-1 character string;
1 x N-2 character string;
1 x N-3 character string;
...
1 x 2 character string;
1 x 1 character string;
1 x 0 character string;

giving a total of sum(range(N+1)) which is N*(N+1)/2. In big-oh notation,
this is quadratic behaviour: O(N**2), and Bart is right to be concerned.

This same sort of thing is precisely why building up a string by repeated
string concatenation can be horribly slow. This is the same, only in
reverse: we're demolishing the string, one character at a time.

Now, there are practical reasons why this may not be *quite* as bad as Bart
fears:

- caching of small strings may mean that we're more like O( (N-1)**2 ),
which is (barely) better;

- the coefficient is in our favour (1/2);

- string copying may be quite efficient (although not as efficient as in C,
where they can be implemented by just a memcopy, more or less);

- the strings are getting smaller all the time, which makes memory
management easier, when compared to having to allocate growing strings;

- although against that, perhaps this ends up fragmenting memory even more?

- it *may* turn out that the cost of the rest of the work done dwarfs the
cost of copying the string in the first place

- but then again it might not.



-- 
Steven

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


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Mark Lawrence

On 23/03/2016 16:24, Random832 wrote:



On Wed, Mar 23, 2016, at 12:08, Mark Lawrence wrote:

And doing it 'Pythonically' can lead to suggestions such as the
following the other day:

   c, psource = psource[0], psource[1:]

(where psource is a very long string), which even I could tell, from
knowing what goes on behind the scenes, wasn't going to work well
(duplicating the rest of the string roughly every other character).



It would work perfectly. How would it duplicate the rest of the string
roughly every other character?


Er, I think he's suggesting that this would be in an inner loop
(something like while psource: c, psource = psource[0], psource[1:]).
What I'm not sure of is why he thinks this is pythonic.



It was in response to Dennis Lee Bieber 
http://code.activestate.com/lists/python-list/700242/.  Quite why he 
thinks it won't work well I've no idea.  I'd have said it was Pythonic, 
as slicing is a standard idiom.


As for every other character, it again shows his complete ignorance of 
Python.  Although thinking about it, it you were to skip every character 
that needed processing, surely that would be really fast?


--
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: [Not actually OT] Trouble in node.js land

2016-03-23 Thread Ben Finney
Random832  writes:

> B) His software costs no money, so no harm has been done even if
> someone looking for the phone app finds it and "buys" it by mistake.

That statement assumes that only the loss of money is harm.

Do you recognise damage to public reputation as harm?

Do you recognise any other non-monetary damage as harm?

Is it legitimate to defend against such damage – for example, damage to
public reputation – through use of trademark law?

-- 
 \ “This world in arms is not spending money alone. It is spending |
  `\  the sweat of its laborers, the genius of its scientists, the |
_o__)   hopes of its children.” —Dwight Eisenhower, 1953-04-16 |
Ben Finney

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


Re: monkey patching __code__

2016-03-23 Thread Sven R. Kunze

On 23.03.2016 09:24, dieter wrote:

But you have observed that you cannot do everything with a
code substitution: a function call does not only depend on the code
but also on other properties of the function object: e.g. the
parameter processing.


Yep, that's because Python is very flexible and provides means for 
changing even that. So, it's not part of the __code__ object but part of 
the actual function. That's okay.



You might be able to change them in a similar way as "__code__" (i.e.
direct modification). Otherwise, you would need to construct a new
"function object" -- and lose the possibility to completely
change the function object in place.


Exactly. Except __globals__ we are all set and I think that'll work for 
us. I will report once we've implemented it that way.


Best,
Sven
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python to do CDC on XML files

2016-03-23 Thread Bob Gailer
On Mar 23, 2016 4:20 PM, "Bruce Kirk"  wrote:
>
> Does anyone know of any existing projects on how to generate a change
data capture on 2 very large xml files.
>
> The xml structures are the same, it is the data within the files that may
differ.
>
It should not be too difficult to write a program that locates the tags
delimiting each record, then compare them.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Not downloading

2016-03-23 Thread John Gordon
In  louis anderson 
 writes:

> After a workshop in my school today regarding python i have downloaded
> it on my laptop

Since you were in fact able to download it, your message title of
"Not downloading" is somewhat misleading...

> however when i go to launch it it either tells me to modify python
> repair python or uninstall python. It will not let me go onto python
> at all.

What operating system do you have on your laptop, and what version of
Python are you trying to install?

Python 3.5 is known to have trouble installing on Windows XP.  If you
have Win XP, try using an older 3.4 version of Python.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Python to do CDC on XML files

2016-03-23 Thread Bruce Kirk
Does anyone know of any existing projects on how to generate a change data 
capture on 2 very large xml files.

The xml structures are the same, it is the data within the files that may 
differ.

I need to take a XML file from yesterday and compare it to the XML file 
produced today and not which XML records have changed.

I have done a google search and I am not able to find much on the subject other 
than software vendors trying to sell me their products. :-)

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


Re: Not downloading

2016-03-23 Thread Igor Korot
Hi,

On Wed, Mar 23, 2016 at 1:31 PM, louis anderson
 wrote:
> Dear Python,   After a workshop in my school today 
> regarding python, i have downloaded it on my laptop however when i go to 
> launch it, it either tells me to modify python, repair python or uninstall 
> python. It will not let me go onto python at all. I do not know what is going 
> on and i hope yourselves can help me.

What OS you are running? What version?
Which python you downloaded?
What version?
Where di you downloaded it from?

Thank you.

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


Not downloading

2016-03-23 Thread louis anderson
Dear Python,   After a workshop in my school today 
regarding python, i have downloaded it on my laptop however when i go to launch 
it, it either tells me to modify python, repair python or uninstall python. It 
will not let me go onto python at all. I do not know what is going on and i 
hope yourselves can help me.
Thankyou  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:

2016-03-23 Thread Ethan Furman

On 03/22/2016 08:17 PM, Nick Eubank wrote:


Relatedly, if this is a desired behavior, any advice one how best to work
with dictionaries when one wants "True" and 1 to be different? I'm working
on a function that accepts arguments that may be "True" or 1 (meaning very
different things) and am seeking a pythonic solution...


If your keys are only numeric and True/False, you can check for and 
mutate True/False into strings "True"/"False"


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


Re: [Not actually OT] Trouble in node.js land

2016-03-23 Thread Ethan Furman

On 03/23/2016 11:08 AM, Terry Reedy wrote:

On 3/23/2016 5:03 AM, Steven D'Aprano wrote:


One developer just broke most of the Node.js ecosystem by removing an
eleven
line package from npm (the node.js package manager, somewhat similar to
Python's pip only even more critical):


Does PyPI actually delete packages, as opposed to making them harder to
find?


I don't know the exact answer, but I do know there is a big warning 
label around the delete button:


  Do NOT use this button.

  There is no undo.

  

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


Re: [Not actually OT] Trouble in node.js land

2016-03-23 Thread Terry Reedy

On 3/23/2016 5:03 AM, Steven D'Aprano wrote:


One developer just broke most of the Node.js ecosystem by removing an eleven
line package from npm (the node.js package manager, somewhat similar to
Python's pip only even more critical):


Does PyPI actually delete packages, as opposed to making them harder to 
find?



--
Terry Jan Reedy

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


Re: 0 equals False, was Re: (unknown)

2016-03-23 Thread Terry Reedy

On 3/23/2016 4:51 AM, Peter Otten wrote:


The pythonic solution is "don't do this". The == operator cannot
discriminate between 0, 0.0, and False,


and 0j and Fraction(0, 1) and Decimal(0)


or 1, 1.0, and True


and 1+0j, Fraction(1, 1) and Decimal(1)

Sets and dicts are based both based on (transitive) equality.

--
Terry Jan Reedy

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


Re: Settig some environment variables from within python.

2016-03-23 Thread Terry Reedy

On 3/23/2016 5:33 AM, Hongyi Zhao wrote:

Hi all,

I want to submit a qsub job to my hpc cluster from within python.  In
this case, I must set some environment variables specific for this qsub
job and then invoking a bash script from within python.

What python code should be used for this job?


The os module.


--
Terry Jan Reedy

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


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Random832


On Wed, Mar 23, 2016, at 12:08, Mark Lawrence wrote:
> > And doing it 'Pythonically' can lead to suggestions such as the
> > following the other day:
> >
> >   c, psource = psource[0], psource[1:]
> >
> > (where psource is a very long string), which even I could tell, from
> > knowing what goes on behind the scenes, wasn't going to work well
> > (duplicating the rest of the string roughly every other character).
> >
> 
> It would work perfectly. How would it duplicate the rest of the string 
> roughly every other character?

Er, I think he's suggesting that this would be in an inner loop
(something like while psource: c, psource = psource[0], psource[1:]).
What I'm not sure of is why he thinks this is pythonic.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Mark Lawrence

On 23/03/2016 06:09, Ben Finney wrote:

Steven D'Aprano  writes:


On Mon, 21 Mar 2016 06:47 pm, Ben Finney wrote:


Bart can show good faith by *learning* idiomatic Python, with the
humility of a beginner. And also by refraining from rhetoric about
how bad Python's performance is, until he gains experience to make
those claims.


"Humility of a beginner"... what a strange phrase to use about
somebody who has been programming for decades.


What a strange reading of what I wrote. Clearly I'm referring to the
fact Bart is a beginner in Python.

To show good faith in learning Python – if indeed that is what Bart
wants, which I'm not convinced of given how much he prefers to talk
about a different private programming language instead – then he should
be taking advantage of the teaching resources that have been offered
numerous times.


What exactly is the problem here? Is it that Bart hasn't earned the
right to say what we all know, that Python is slow, because he's an
outsider?


The problem is that Bart simultaneously is a beginner at Python, and
expresses astonishment that everyone shrugs when Bart's
dreadfully-written code performs so badly.

Good faith is contradicted by asserting knowledge of Python, complaining
about how some deliberately non-idiomatic Python code is performing
poorly, dismissing suggestions for improvement — specifically in the
context of someone who admittedly knows so little about Python.



+1

--
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: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Mark Lawrence

On 23/03/2016 10:34, BartC wrote:

On 23/03/2016 06:09, Ben Finney wrote:


The problem is that Bart simultaneously is a beginner at Python, and
expresses astonishment that everyone shrugs when Bart's
dreadfully-written code performs so badly.


My interests differ from most people here writing Python.

For example, I'm interested in byte-code (any byte-code) and what can be
done with it. Investigating how well it performs in 'extreme' cases
means executing algorithms predominantly in byte-code, not measuring how
well some library function (in some unspecified language) can cope with
the algorithm.

And doing it 'Pythonically' can lead to suggestions such as the
following the other day:

  c, psource = psource[0], psource[1:]

(where psource is a very long string), which even I could tell, from
knowing what goes on behind the scenes, wasn't going to work well
(duplicating the rest of the string roughly every other character).



It would work perfectly. How would it duplicate the rest of the string 
roughly every other character?


--
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: Key Binding Problem

2016-03-23 Thread Wildman via Python-list
On Wed, 23 Mar 2016 02:47:47 -0400, Terry Reedy wrote:

>  def load_image(self, _):
>  # load image file
> 
> You must pass the bound method, as you did, and not the function itself 
> (which has two parameters).

I meant to ask a followup question in my previous post but
it slipped my mind.

What is the best thing to do...
Define all procedures this way, (self. event)?
Define all event handlers this way?
Define only the event handlers that will be called from
elsewhere in the code, as in this case?

-- 
 GNU/Linux user #557453
More gun laws will reduce gun violence just
like Obamacare reduced insurance rates.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Key Binding Problem

2016-03-23 Thread Wildman via Python-list
On Wed, 23 Mar 2016 02:47:47 -0400, Terry Reedy wrote:

> On 3/23/2016 12:28 AM, Wildman via Python-list wrote:
>> On Wed, 23 Mar 2016 03:02:51 +, MRAB wrote:
>>
>>> On 2016-03-23 02:46, Wildman via Python-list wrote:
 My question is how do I coax bind into executing the
 button procedures?  Or is there a way to generate the
 button click event from the binding?

>>> It won't let you bind to a function called "load_image" because there
>>> isn't a function called "load_image"!
>>>
>>> The "Window" class, however, does have a method with that name.
>>>
>>> Try binding the keys in Window.__init__ or Window.init_window:
>>>
>>>   def init_window(self):
>>>   ...
>>>   root.bind("", self.load_image)
>>
>> Here is what I tried:
>>
>> class Window(tk.Frame):
>>
>>  def __init__(self, master = None):
>>  tk.Frame.__init__(self,master)
>>  self.master = master
>>  root.bind("l", self.load_image)
>>
>> I get this error and it doesn't make any sense to me:
>>
>> Exception in Tkinter callback
>> Traceback (most recent call last):
>>File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
>>  return self.func(*args)
>> TypeError: load_image() takes exactly 1 argument (2 given)
> 
> Event handlers must have one parameter (other than 'self' for methods), 
> the event, as that is what they will be passed.  You defined load_image 
> like this.
> 
>  def load_image(self):
>  # load image file
> 
> It should be this
> 
>  def load_image(self, event):
>  # load image file
> 
> You are free to ignore the event object and some people then name the 
> parameter '_' (or dummy) to signify that it will be ignored.
> 
>  def load_image(self, _):
>  # load image file
> 
> You must pass the bound method, as you did, and not the function itself 
> (which has two parameters).

Thank you very much.  I have seen sample code that used
'event' in the definition but without any explanation
as to why and without actually using it.  Since my code
seemed to run OK without it, at least until now, I didn't
give it much thought.  My mistake.

I am new to python so understanding comes a little slower
for me.  And I am not a professional programmer.  I enjoy
it as a hobby so my experience is more limited where the
advanced topics are concerned.  Thanks to the knowledgeable
people here I am gaining insight as I go.  Thanks again!

-- 
 GNU/Linux user #557453
May the Source be with you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Ned Batchelder
On Wednesday, March 23, 2016 at 6:35:12 AM UTC-4, BartC wrote:
> On 23/03/2016 06:09, Ben Finney wrote:
> 
> > The problem is that Bart simultaneously is a beginner at Python, and
> > expresses astonishment that everyone shrugs when Bart's
> > dreadfully-written code performs so badly.
> 
> My interests differ from most people here writing Python.
> 
> For example, I'm interested in byte-code (any byte-code) and what can be 
> done with it. Investigating how well it performs in 'extreme' cases 
> means executing algorithms predominantly in byte-code, not measuring how 
> well some library function (in some unspecified language) can cope with 
> the algorithm.

Thanks for clarifying your focus.  As you explore this topic, keep in mind
then that you are only looking at part of Python.  When you find yourself
wondering why the bytecode is a certain way, the answer might be, "Because
wherever this bytecode is run, the standard library is available, and this
problem is better solved with a thing in the standard library."

This doesn't mean your investigations are invalid, but they are only part
of the story.  When it seems to you like Python has made a strange choice,
you may have to broaden your perspective to understand it.

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


Re: [Not actually OT] Trouble in node.js land

2016-03-23 Thread Random832
On Wed, Mar 23, 2016, at 10:52, Steven D'Aprano wrote:
> - He didn't bother to check to see whether the name was in use when he
> picked it.

Someone not making a commercial product shouldn't have to worry about a
name collision with something they've never heard of.

> - The lawyers were polite but firm.
> 
> - He apparently made no attempt to negotiate, just told them no. Twice.

I'd missed the part where the lawyers contacted him directly. The next
step should have been a lawsuit, not to do an end run around the law by
trying to convince someone else to enact extralegal enforcement on their
behalf.

> - His own account didn't dispute the possibility of confusion between two
> software packages with the same name. He could have argued "My software
> in
> a command-line tool for creating Javascript projects; yours is a chat
> client. There is no possibility of confusion between the two." But he
> gives
> no indication that he did this.
> 
> It probably wouldn't do him much good if he made that argument, since the
> courts tend to use the "Moron in a hurry" test. If a stupid person who is
> not paying attention could be confused by the reuse of the name, then it
> shouldn't be allowed. They're both software, right? It's not like one was
> software and the other was a brand of chocolate biscuit. But, judging
> from
> his own story, it doesn't appear he even made that argument.

A) His software is a command line tool, how's someone looking for a
phone app going to find it in the first place?
B) His software costs no money, so no harm has been done even if someone
looking for the phone app finds it and "buys" it by mistake.

Even if the interpretation of the law used by the court _is_ that phone
apps and command line tools are the same "area", this is, if true, a
failure of the system that people should fight against rather than just
accept.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 0 equals False, was Re: (unknown)

2016-03-23 Thread gst
Le mercredi 23 mars 2016 04:52:02 UTC-4, Peter Otten a écrit :
> Nick Eubank wrote:
> 
> > Hello All,
> > 
> > 
> > Found an odd behavior I'd never known about today, not sure if it's a bug
> > or known. Python 3.4.4 (anaconda). 
> > True, False, 0, 1 can all be used as dictionary keys.
> > 
> > But Apparently True and 1 hash to the same item and False and 0 hash to
> > the same item, so they can easily overwrite (which I spent a while banging
> > my head over today).
> > 
> > In other words:
> > 
> >  In[1]:
> >  d = {True: 'a', False: 'b'}
> >  d[0] = 'z'
> >  d[False]
> > 
> > Out[1]:
> >  'z'
> > 
> > I understand that True and False are sub-types of ints, but it's not clear
> > to me why (i.e. certainly didn't feel intuitive) that they would be
> > treated the same as keys.
> > 
> > Relatedly, if this is a desired behavior, any advice one how best to work
> > with dictionaries when one wants "True" and 1 to be different? I'm working
> > on a function that accepts arguments that may be "True" or 1 (meaning very
> > different things) and am seeking a pythonic solution...


I would include the type in the dictionary key:

d = {}

x = True

d[(type(x), x)] = 42

x = 1

d[(type(x), x)] = "foo"

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


Re: [Not actually OT] Trouble in node.js land

2016-03-23 Thread Steven D'Aprano
On Thu, 24 Mar 2016 12:33 am, Random832 wrote:

> On Wed, Mar 23, 2016, at 05:03, Steven D'Aprano wrote:
>> https://medium.com/@azerbike/i-ve-just-liberated-my-modules-9045c06be67c
>> 
>> Of course, moving his allegedly infringing package "kik" to github isn't
>> going to fix the problem. It's still allegedly infringing.
> 
> I think the issue, and it is a reasonable one, is that this was not
> determined in a court of law. It's not actually clear to me that it's
> infringing or not (yes, they're both computer programs, but they do very
> different things, so it's not clear if they are or that they ought to be
> the "same area"), and it's arguably something that Kik Interactive Inc.
> should have had to actually sue him for rather than demanding a third
> party to arbitrarily mess with his stuff.
> 
> And there's also the fact that corporations apparently have absolutely
> no concept of how to properly communicate with someone to ask them to
> change something or stop doing something.

I don't think this is the case at all. If the author of the package had
tried to negotiate, and been rebuffed, he surely would have said so. "Look,
I tried to be reasonable, but they wouldn't be reasonable, so I had no
choice!". But that's not what his own account of the story shows. His
account shows clearly:

- He didn't bother to check to see whether the name was in use when he
picked it.

- The lawyers were polite but firm.

- He apparently made no attempt to negotiate, just told them no. Twice.

- His own account didn't dispute the possibility of confusion between two
software packages with the same name. He could have argued "My software in
a command-line tool for creating Javascript projects; yours is a chat
client. There is no possibility of confusion between the two." But he gives
no indication that he did this.

It probably wouldn't do him much good if he made that argument, since the
courts tend to use the "Moron in a hurry" test. If a stupid person who is
not paying attention could be confused by the reuse of the name, then it
shouldn't be allowed. They're both software, right? It's not like one was
software and the other was a brand of chocolate biscuit. But, judging from
his own story, it doesn't appear he even made that argument.

Instead, it seems that his argument was simple: "No. Don't want to."

So the lawyers did the right thing: instead of suing him, they approached
the people hosting the software, and got them to take it down. There is a
prima facie evidence of trademark infringement, and the alleged infringer
has made no attempt to deny infringement, defend himself or rename the
package, even when asked. 

So they took down *one* package. At which point, the author spat the dummy
and took down 250 or so packages, including the one which brought Node.js
to its knees.

It's hard to feel sympathy for the guy when *his own account* of what took
place makes him out to be a totally self-centred dick with poor impulse
control.

But now this is off-topic. There are difficult people in all programming
language communities, and it could have been *any* package that was removed
suddenly with no warning. What's more interesting is the difference between
language communities which can easily weather such troubles or those that
can't.


-- 
Steven

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


Re: os.rename on Windows

2016-03-23 Thread eryk sun
On Wed, Mar 23, 2016 at 7:17 AM, Steven D'Aprano  wrote:
>
> According to the documentation, os.rename(original, new) will fail if new
> already exists.

In 3.3+ you can use os.replace. For POSIX systems it's functionally
the same as os.rename. pyosreplace [1] backports os.replace for 2.6,
2.7 and 3.2.

Ignore the comment on the PyPI page that MoveFileEx isn't guaranteed
to be atomic. It won't do a CopyFile because os.replace doesn't use
the flag MOVEFILE_COPY_ALLOWED. For a cross-volume move, which can't
be executed atomically in a single NtSetInformationFile system call,
os.replace fails with the Windows error code ERROR_NOT_SAME_DEVICE
(0x0011 or 17).

[1]: https://pypi.python.org/pypi/pyosreplace

> Would somebody be kind enough to tell me what OSError is raised?

If the file already exists, os.rename fails with winerror set to
ERROR_ALREADY_EXISTS (0x00B7 or 183). If you need to support 2.x, you
should handle WindowsError, which is a subclass of OSError that has
the "winerror" attribute. In 3.3+ OSError itself has the "winerror"
attribute, and in this case WindowsError is just an alias for OSError.
For 3.3+ you can also handle the cross-platform FileExistsError
subclass of OSError.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: os.rename on Windows

2016-03-23 Thread sjmsoft
Python 2.7.11 on Windows 7 Enterprise (64-bit machine, 32-bit Python) and two 
Windows Server 2012 R2 (64-bit machines, both 32-bit and 64-bit Pythons):

183
17
WindowsError(183, 'Cannot create a file when that file already exists')

HTH,
  Steve
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Not actually OT] Trouble in node.js land

2016-03-23 Thread Random832
On Wed, Mar 23, 2016, at 05:03, Steven D'Aprano wrote:
> https://medium.com/@azerbike/i-ve-just-liberated-my-modules-9045c06be67c
> 
> Of course, moving his allegedly infringing package "kik" to github isn't 
> going to fix the problem. It's still allegedly infringing.

I think the issue, and it is a reasonable one, is that this was not
determined in a court of law. It's not actually clear to me that it's
infringing or not (yes, they're both computer programs, but they do very
different things, so it's not clear if they are or that they ought to be
the "same area"), and it's arguably something that Kik Interactive Inc.
should have had to actually sue him for rather than demanding a third
party to arbitrarily mess with his stuff.

And there's also the fact that corporations apparently have absolutely
no concept of how to properly communicate with someone to ask them to
change something or stop doing something.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: E-commerce system in Python

2016-03-23 Thread Nicolas Évrard
* Arshpreet Singh  [2016-03-18 05:25 +0100]: 

I am looking for an E-commerce system in python to sell things things
online, which can also be responsive for Android and IOS.

A  quick Google search brought me  http://getsaleor.com/ it uses
Django, Is there any available one using Flask or newly born asyncio
based framework?


You could build your own e-commerce system using Tryton and
flask-tryton.

http://www.tryton.org/
https://pypi.python.org/pypi/flask_tryton

We're in the process of adding basic cart functionalities to the ERP.
It will probably be included in the near future.

--
Nicolas Évrard - B2CK SPRL
E-mail/Jabber: nicolas.evr...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/
--
https://mail.python.org/mailman/listinfo/python-list


Re: os.rename on Windows

2016-03-23 Thread Steven D'Aprano
On Wed, 23 Mar 2016 11:28 pm, Random832 wrote:

> On Wed, Mar 23, 2016, at 08:17, Steven D'Aprano wrote:
>> Any Windows users here?
>>
>> print(e.winerror)  # Windows only
>> print(e.errno)
>> print(repr(e))
> 
> 183
> 17
> FileExistsError(17, 'Cannot create a file when that file already
> exists')
> 
> Python 3.5.1.

Great!

Thanks, and to Chris too (and anyone else who answers).




-- 
Steven

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


Re: os.rename on Windows

2016-03-23 Thread Random832
On Wed, Mar 23, 2016, at 08:17, Steven D'Aprano wrote:
> Any Windows users here?
>
> print(e.winerror)  # Windows only
> print(e.errno)
> print(repr(e))

183
17
FileExistsError(17, 'Cannot create a file when that file already
exists')

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


Re: os.rename on Windows

2016-03-23 Thread Chris Angelico
On Wed, Mar 23, 2016 at 11:17 PM, Steven D'Aprano  wrote:
> import os
> open('a123.junk', 'w')
> open('b123.junk', 'w')
> try:
> os.rename('a123.junk', 'b123.junk')
> except OSError as e:
> print(e.winerror)  # Windows only
> print(e.errno)
> print(repr(e))
>
> os.unlink('a123.junk')
> os.unlink('b123.junk')
>

32-bit Python on 64-bit Windows 7 in a VirtualBox VM under Debian Testing.

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:38:48) [MSC v.1900 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> open('a123.junk', 'w')
<_io.TextIOWrapper name='a123.junk' mode='w' encoding='cp1252'>
>>> open('b123.junk', 'w')
<_io.TextIOWrapper name='b123.junk' mode='w' encoding='cp1252'>
>>> try:
... os.rename('a123.junk', 'b123.junk')
... except OSError as e:
... print(e.winerror)  # Windows only
... print(e.errno)
... print(repr(e))
...
183
17
FileExistsError(17, 'Cannot create a file when that file already exists')
>>> os.unlink('a123.junk')
>>> os.unlink('b123.junk')
Traceback (most recent call last):
  File "", line 1, in 
PermissionError: [WinError 32] The process cannot access the file because it is
being used by another process: 'b123.junk'
>>>


The last error is because _ is retaining the open file, so it hasn't
been closed. Entering any non-None expression allows the unlink.

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


os.rename on Windows

2016-03-23 Thread Steven D'Aprano
Any Windows users here?


According to the documentation, os.rename(original, new) will fail if new
already exists.

Would somebody be kind enough to tell me what OSError is raised? In
particular:

# Untested.
import os
open('a123.junk', 'w')
open('b123.junk', 'w')
try:
os.rename('a123.junk', 'b123.junk')
except OSError as e:
print(e.winerror)  # Windows only
print(e.errno)
print(repr(e))

os.unlink('a123.junk')
os.unlink('b123.junk')



I'd test it myself, except I don't have access to Windows with Python.

Thanks in advance.



-- 
Steven

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


Re:

2016-03-23 Thread Erik

Hi Nick,

On 23/03/16 03:17, Nick Eubank wrote:

In other words:

  In[1]:
  d = {True: 'a', False: 'b'}
  d[0] = 'z'
  d[False]

Out[1]:
  'z'

[snip]

Relatedly, if this is a desired behavior, any advice one how best to work
with dictionaries when one wants "True" and 1 to be different?


See the accepted answer here:

http://stackoverflow.com/questions/3387691/python-how-to-perfectly-override-a-dict

If you use the class that the answer suggests and then define a subclass:

"""
class MyTransformedDict(TransformedDict):
__reverse_transform__ = {
"__True__": True,
"__False__": False,
}

def __keytransform__(self, key):
if key is True: return "__True__"
if key is False: return "__False__"
return key

def __iter__(self):
return (self.__reverse_transform__.get(k, k)
for k in super(MyTransformedDict, self).__iter__())

def __contains__(self, key):
return self.__keytransform__(key) in self.store

"""

Then as long as you wrap such dictionaries in a "MyTransformedDict()" 
(choose a better name!), it will do what:


"""
d = MyTransformedDict({True: 'a', False: 'b'})
d[0] = 'z'
d[False]
"""

Note that in your case, I've added the reverse transformation from the 
magic tokens so that iter(), .iterkeys() and .iteritems()) return the 
original True and False keys.


I've also added __contains__, but that should be in the 
"TransformedDict()" superclass (I didn't want to reproduce the whole of 
that here).


There are things missing (such as a dict-like repr()) or not done 
optimally there, but it might be a good start. This works on Python 2 and 3.


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


Re: Suggestion: make sequence and map interfaces more similar

2016-03-23 Thread Steven D'Aprano
On Wed, 23 Mar 2016 06:54 am, Marco S. wrote:

> I noticed that the sequence types does not have these methods that the map
> types  has: get(), items(), keys(), values().
> 
> It could seem useless to have them for sequences, 

That's putting it mildly.

> but I think it will ease 
> the creation of functions and methods that allow you to input a generic
> iterable as parameter, but needs to use one of these methods in case the
> parameter is a map.

Perhaps it would. But countering that is the disadvantage that you're adding
methods to sequences that have no sensible meaning for a sequence.

Strings and floats are quite different things, but occasionally it makes
sense to write a function that accepts either a string or a float. Perhaps
we could introduce methods to strings and floats to blur the difference,
to "ease the creation of functions and methods that allow you to input a
generic scalar (string, float, int) as parameter..."?

Some of these methods would be easy:

class float:
def upper(self):
return self


Some a bit more work:

def find(self, substring, start, end):
s = str(self)
return s.find(substring, start, end)

but some perplex me. What would (27.25).expand_tabs() do?


Of course this is silly. Even Perl and Javascript don't go this far in
making floats and strings interchangeable. This is a good thing: if you're
calling some_float.upper(), you've almost certainly made a programming
error, and you don't want this nonsensical method call to silently succeed.

So it is with sequences and mappings. They are *not* the same sort of thing,
even though they have a few superficial similarities, and they shouldn't
try to behave as the same thing.

What should some_dict.append(None) do? The very concept is nonsense: dicts
aren't *ordered sequences*, you can't append to a dict. Maybe you could
give dicts a method *called* "append", but it wouldn't mean the same thing
as list.append, and it probably wouldn't have the same signature:


list.append(value)
Appends value to the end of the list.

dict.append(key, value)
Adds a new key to the dict, with the given value. 
Same as dict[key] = value.


Forcing these two completely different methods to have the same name doesn't
do anything useful. That's like putting a door handle on your iPhone, in
case some day you want to treat your iPhone as a door.


> In one word, it will facilitate duck typing.

I think you have misunderstood the purpose and meaning of duck-typing.

Duck-typing is not about forcing unrelated, dissimilar types to have the
same interface just in case you want to write a function that will accept
either type.

Duck-typing is about accepting anything which "quacks like a duck". If all
you need is something which lays an egg, you shouldn't care whether it is a
chicken or a goose or a duck. It doesn't mean that dogs and cats should
have a "lay_egg" method, just in case somebody wants to accept a duck or a
dog.


> For the same reason, I would suggest the introduction of a new map type,
> vdict, a dict that by default iterates over values instead over keys. So a
> vdict object "d" wiil have iter(d) == iter(d.values()), and should also
> have a count() method, like sequence types.

I don't really see the point in this. What sort of function will expect to
iterate over a mapping, but not care whether it is getting keys or values?

Sure, there are generic functions that will iterate over *any iterable*, and
you can pass dict.keys() or dict.values(), and both will work fine. That's
exactly what duck-typing is about.

But let's imagine this hypothetical function that will accept any mapping,
and some mappings will iterate over keys and some mappings iterate over
values. What would you do with it?

def walk(the_dict):
for obj in the_dict:
print("Key =", obj)  # That's wrong, it might be a value.
value = the_dict[obj]  # That's wrong too.
the_dict[obj] = "processed"  # Still wrong.


There's nothing useful or interesting you can do with a mapping and
something which might be a key, or might be a value, but you don't know
which. You can treat them in isolation, as if they had nothing to do with a
dict, and that's about it. But in that case, why insist on a dict?

walk(the_dict.keys())
walk(the_dict.values())
walk(the_list)
walk(the_iterator)


> Indeed sequences are, in my humble opinion, a specialized case of maps,
> when keys are numeric only, are always contiguous without gaps and start
> from 0.

That's a very superficial similarity: a list ['a', 'b', 'x', 'y'] is
something like a mapping {0: 'a', 1: 'b', 2: 'x', 3: 'y'}. Seems logical,
since in both cases we write collection[2] and get 'x' back.

But think about it a bit more, and you will see that the behaviour is in
fact *very different*. For example:

the_list = ['a', 'b', 'x', 'y']
# the_list is equivalent to {0: 'a', 1: 'b', 2: 'x', 3: 'y'}
the_list.insert(0, 'z')
# the_list is now equivalent to {0: 'z', 1: 'a', 2: 'b', 

Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Chris Angelico
On Wed, Mar 23, 2016 at 9:57 PM, Tim Golden  wrote:
> On 23/03/2016 10:48, Chris Angelico wrote:
>> On Wed, Mar 23, 2016 at 9:34 PM, BartC  wrote:
>>> Someone could be interested in cars, mechanics and performance without
>>> wanting to know the most Pythonic way to get from Kings Cross to Heathrow.
>>
>> But if I complain that the trek across four blocks of London cost me
>> ninety minutes and my train ticket (which I then had to get replaced),
>> you would blame it on me getting lost, rather than accepting my
>> assertion that London's slow to get around. And if you said "hey, take
>> a bus or a taxi next time", and I next time walked and got lost again,
>> you would rightly call me a fool. And if I then had the audacity to
>> say that London's streets are badly designed, because I looked at them
>> and even without knowing what sort of traffic goes on them, I can tell
>> that those are slow roads... you'd have very little respect for my
>> statements about London. It wouldn't matter if I'm the world's
>> greatest expert on hiking from Adelaide to Perth; it wouldn't matter
>> how many nuances of Nullarbor sand I'm familiar with, nor how best to
>> find drinking water there. I clearly know nothing about London, and my
>> complaints about the city should be taken with a grain of salt, until
>> such time as I put in the effort to get to know YOUR city YOUR way.
>>
>> (Events depicted in this work are entirely fictional and have no basis
>> in reality. Really. Really truly. Anyway, I only got lost once.)
>
> Well if you tried to walk from King's Cross to Heathrow and only got
> lost once, I'm very impressed. I'm impressed if you did it at all!

I was walking something like four blocks, from one station to another
(we flew in to one of the airports and needed to take a train to
Manchester, and that involved trains on different lines). It was a
short trip and would have been an easy one, had I consulted a map
beforehand instead of thinking "Oh, it's just straight there and then
there and there, no problem!".

Obviously London's fault for being unintuitive. And for having railway
lines that don't meet at the same stations (well, maybe that's a legit
complaint, but the city has to worry about backward compatibility
too).

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


Re: numpy arrays

2016-03-23 Thread Simon Ward


On 23 March 2016 10:06:56 GMT+00:00, Heli  wrote:
>Hi, 
>
>I have a 2D numpy array like this:
>
>[[1,2,3,4],
> [1,2,3,4], 
> [1,2,3,4]
> [1,2,3,4]]
>
>Is there any fast way to convert this array to 
>
>[[1,1,1,1],
> [2,2,2,2]
> [3,3,3,3]
> [4,4,4,4]]

Use the transpose() method:
http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.ndarray.transpose.html

Simon
-- 
Sent from Kaiten Mail. Please excuse my brevity.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 0 equals False, was Re: (unknown)

2016-03-23 Thread INADA Naoki
Tips: Since True == 1, sum() can count Trues.

>>> def count_even(seq):
... return sum(i%2 == 0 for i in seq)

>>> count_even(range(100))
50
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Not actually OT] Trouble in node.js land

2016-03-23 Thread INADA Naoki
>
>
> For those curious, here's left-pad in all its glory:
>
> module.exports = leftpad;
> function leftpad (str, len, ch) {
>   str = String(str);
>   var i = -1;
>   if (!ch && ch !== 0) ch = ' ';
>   len = len - str.length;
>   while (++i < len) {
> str = ch + str;
>   }
>   return str;
> }
>
> I leave a Python translation for the experts :-)
>
>
>>> s = "foo"
>>> s.rjust(5, '@')
'@@foo'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Tim Golden
On 23/03/2016 10:48, Chris Angelico wrote:
> On Wed, Mar 23, 2016 at 9:34 PM, BartC  wrote:
>> Someone could be interested in cars, mechanics and performance without
>> wanting to know the most Pythonic way to get from Kings Cross to Heathrow.
> 
> But if I complain that the trek across four blocks of London cost me
> ninety minutes and my train ticket (which I then had to get replaced),
> you would blame it on me getting lost, rather than accepting my
> assertion that London's slow to get around. And if you said "hey, take
> a bus or a taxi next time", and I next time walked and got lost again,
> you would rightly call me a fool. And if I then had the audacity to
> say that London's streets are badly designed, because I looked at them
> and even without knowing what sort of traffic goes on them, I can tell
> that those are slow roads... you'd have very little respect for my
> statements about London. It wouldn't matter if I'm the world's
> greatest expert on hiking from Adelaide to Perth; it wouldn't matter
> how many nuances of Nullarbor sand I'm familiar with, nor how best to
> find drinking water there. I clearly know nothing about London, and my
> complaints about the city should be taken with a grain of salt, until
> such time as I put in the effort to get to know YOUR city YOUR way.
> 
> (Events depicted in this work are entirely fictional and have no basis
> in reality. Really. Really truly. Anyway, I only got lost once.)

Well if you tried to walk from King's Cross to Heathrow and only got
lost once, I'm very impressed. I'm impressed if you did it at all!

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


Re: numpy arrays

2016-03-23 Thread Heli
On Wednesday, March 23, 2016 at 11:07:27 AM UTC+1, Heli wrote:
> Hi, 
> 
> I have a 2D numpy array like this:
> 
> [[1,2,3,4],
>  [1,2,3,4], 
>  [1,2,3,4]
>  [1,2,3,4]]
> 
> Is there any fast way to convert this array to 
> 
> [[1,1,1,1],
>  [2,2,2,2]
>  [3,3,3,3]
>  [4,4,4,4]]
> 
> In general I would need to retrieve every nth element of the interior arrays 
> in to single arrays. I know I can loop over and do this, but I have really 
> big arrays and I need the fastest way to do this. 
> 
> Thanks for your help,

Thanks a lot everybody, 

Transposing is exactly what I want. I just was not sure if that would work on 
internal arrays of a 2D array. Problem solved thanks everyone.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread Chris Angelico
On Wed, Mar 23, 2016 at 9:34 PM, BartC  wrote:
> ... which even I could tell, from knowing what goes on behind the scenes,
> wasn't going to work well ...
> ...
>> Good faith is contradicted by asserting knowledge of Python, complaining
>> about how some deliberately non-idiomatic Python code is performing
>> poorly, dismissing suggestions for improvement — specifically in the
>> context of someone who admittedly knows so little about Python.
>
>
> Someone could be interested in cars, mechanics and performance without
> wanting to know the most Pythonic way to get from Kings Cross to Heathrow.

But if I complain that the trek across four blocks of London cost me
ninety minutes and my train ticket (which I then had to get replaced),
you would blame it on me getting lost, rather than accepting my
assertion that London's slow to get around. And if you said "hey, take
a bus or a taxi next time", and I next time walked and got lost again,
you would rightly call me a fool. And if I then had the audacity to
say that London's streets are badly designed, because I looked at them
and even without knowing what sort of traffic goes on them, I can tell
that those are slow roads... you'd have very little respect for my
statements about London. It wouldn't matter if I'm the world's
greatest expert on hiking from Adelaide to Perth; it wouldn't matter
how many nuances of Nullarbor sand I'm familiar with, nor how best to
find drinking water there. I clearly know nothing about London, and my
complaints about the city should be taken with a grain of salt, until
such time as I put in the effort to get to know YOUR city YOUR way.

(Events depicted in this work are entirely fictional and have no basis
in reality. Really. Really truly. Anyway, I only got lost once.)

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


Re: numpy arrays

2016-03-23 Thread Chris Angelico
On Wed, Mar 23, 2016 at 9:06 PM, Heli  wrote:
> I have a 2D numpy array like this:
>
> [[1,2,3,4],
>  [1,2,3,4],
>  [1,2,3,4]
>  [1,2,3,4]]
>
> Is there any fast way to convert this array to
>
> [[1,1,1,1],
>  [2,2,2,2]
>  [3,3,3,3]
>  [4,4,4,4]]

What you want is called *transposing* the array:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html

That should be a sufficiently fast operation.

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


Re: numpy arrays

2016-03-23 Thread Manolo Martínez
On 03/23/16 at 03:06am, Heli wrote:

> I have a 2D numpy array like this:
> 
> [[1,2,3,4],
>  [1,2,3,4], 
>  [1,2,3,4]
>  [1,2,3,4]]
> 
> Is there any fast way to convert this array to 
> 
> [[1,1,1,1],
>  [2,2,2,2]
>  [3,3,3,3]
>  [4,4,4,4]]

You don't mean just transposing your original array, as in
original_array.T, right?

> In general I would need to retrieve every nth element of the interior
> arrays in to single arrays. I know I can loop over and do this, but I
> have really big arrays and I need the fastest way to do this. 

I didn't really get this, so transposing is probably not what you need.
Anyway, just in case!

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


Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-23 Thread BartC

On 23/03/2016 06:09, Ben Finney wrote:


The problem is that Bart simultaneously is a beginner at Python, and
expresses astonishment that everyone shrugs when Bart's
dreadfully-written code performs so badly.


My interests differ from most people here writing Python.

For example, I'm interested in byte-code (any byte-code) and what can be 
done with it. Investigating how well it performs in 'extreme' cases 
means executing algorithms predominantly in byte-code, not measuring how 
well some library function (in some unspecified language) can cope with 
the algorithm.


And doing it 'Pythonically' can lead to suggestions such as the 
following the other day:


 c, psource = psource[0], psource[1:]

(where psource is a very long string), which even I could tell, from 
knowing what goes on behind the scenes, wasn't going to work well 
(duplicating the rest of the string roughly every other character).


A couple of years ago I had a project which tried to use a universal 
syntax to express algorithms, and translating it into various languages. 
The following code was generated for Python.


(/This/ is also quite a good way of learning a language, by figuring out 
how to implement a specific feature in one language, in another. Another 
way is to try and implement it...)


'N-Sieve' benchmark:

# Python source output
import sys
import math
import copy

def nsieve(m):
  flags = ([1]*(m+1))
  count = 0
  for i in range(3,m+1):
if flags[i]:
  count += 1
  j = (i+i)
  while (j<=m):
if flags[j]:
  flags[j] = 0
j = (j+i)
  sys.stdout.write(str("Primes up to "))
  sys.stdout.write(str(m))
  sys.stdout.write(str(": "))
  sys.stdout.write(str(count))
  sys.stdout.write("\n")
  return count

def start():
  nsieve(512)
  nsieve(256)
  nsieve(128)

start()

(The sys writes are used as it was easier than figuring out how to 
reliably control spacing and newlines using 'print'. The m+1's I think 
are there because the algorithm I used was 1-based).


In the case of this project, the source syntax was intended as a wrapper 
around actual Python; it was not a language in its own right. (Although, 
these simple benchmarks could generate Python, Lua or Lisp from the 
exact same source. I know zilch about Lisp, except what I had to figure 
out to make this work, and which I promptly forgot again. But the 
resulting code ran perfectly!)


But I'd be more interesting now in translating another actual language 
to Python. Now, the resulting Python is likely to be low-quality, with 
extra code needed to match the source semantics. Then performance could 
well be a factor not entirely offset by the novelty of watching Python 
flawlessly execute a program not written in Python.



Good faith is contradicted by asserting knowledge of Python, complaining
about how some deliberately non-idiomatic Python code is performing
poorly, dismissing suggestions for improvement — specifically in the
context of someone who admittedly knows so little about Python.


Someone could be interested in cars, mechanics and performance without 
wanting to know the most Pythonic way to get from Kings Cross to Heathrow.


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


Re: numpy arrays

2016-03-23 Thread Steven D'Aprano
On Wed, 23 Mar 2016 09:06 pm, Heli wrote:

> Hi,
> 
> I have a 2D numpy array like this:
> 
> [[1,2,3,4],
>  [1,2,3,4],
>  [1,2,3,4]
>  [1,2,3,4]]
> 
> Is there any fast way to convert this array to
> 
> [[1,1,1,1],
>  [2,2,2,2]
>  [3,3,3,3]
>  [4,4,4,4]]



Mathematically, this is called the "transpose" of the array, and you can do
that in numpy:

py> import numpy as np
py> arr = np.array(
... [[1,2,3,4],
...  [1,2,3,4],
...  [1,2,3,4],
...  [1,2,3,4]])
py> arr
array([[1, 2, 3, 4],
   [1, 2, 3, 4],
   [1, 2, 3, 4],
   [1, 2, 3, 4]])
py> arr.T
array([[1, 1, 1, 1],
   [2, 2, 2, 2],
   [3, 3, 3, 3],
   [4, 4, 4, 4]])



-- 
Steven

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


numpy arrays

2016-03-23 Thread Heli
Hi, 

I have a 2D numpy array like this:

[[1,2,3,4],
 [1,2,3,4], 
 [1,2,3,4]
 [1,2,3,4]]

Is there any fast way to convert this array to 

[[1,1,1,1],
 [2,2,2,2]
 [3,3,3,3]
 [4,4,4,4]]

In general I would need to retrieve every nth element of the interior arrays in 
to single arrays. I know I can loop over and do this, but I have really big 
arrays and I need the fastest way to do this. 

Thanks for your help,  
-- 
https://mail.python.org/mailman/listinfo/python-list


Settig some environment variables from within python.

2016-03-23 Thread Hongyi Zhao
Hi all,

I want to submit a qsub job to my hpc cluster from within python.  In 
this case, I must set some environment variables specific for this qsub 
job and then invoking a bash script from within python.

What python code should be used for this job?

Regards
-- 
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Suggestion: make sequence and map interfaces more similar

2016-03-23 Thread Peter Otten
Marco S. via Python-list wrote:

> I noticed that the sequence types does not have these methods that the map
> types  has: get(), items(), keys(), values().
> It could seem useless to have them for sequences, but I think it will ease
> the creation of functions and methods that allow you to input a generic
> iterable as parameter, but needs to use one of these methods in case the
> parameter is a map.
> 
> In one word, it will facilitate duck typing.

It will also break existing uses of duck typing. The first one I found:

>>> class List(list):
... def items(self):
... return list(enumerate(self))
... 
>>> from urllib.parse import urlencode
>>> urlencode([("a", "b"), ("c", "d")])
'a=b&c=d'
>>> urlencode(List([("a", "b"), ("c", "d")]))
'0=%28%27a%27%2C+%27b%27%29&1=%28%27c%27%2C+%27d%27%29'

 
> For the same reason, I would suggest the introduction of a new map type,
> vdict, a dict that by default iterates over values instead over keys. So a
> vdict object "d" wiil have iter(d) == iter(d.values()), and should also
> have a count() method, like sequence types.
> 
> Indeed sequences are, in my humble opinion, a specialized case of maps,
> when keys are numeric only, are always contiguous without gaps and start
> from 0. This way we will have a simpler way to let people to use sequences
> or maps indifferently, and let the code untouched.

Can you provide a few examples where this has /practical/ advantages?

Isn't allowing

some_list.get("key")

more likely to hide programming errors than to make code more generic in a 
useful way?

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


[Not actually OT] Trouble in node.js land

2016-03-23 Thread Steven D'Aprano
This is not actually off-topic, as it has relevance to open source projects 
like Python: the importance of getting package management right, and not 
basing your development ecosystem on cowboys who might pull the rug out from 
under your feet at any time.

Ironically, this also showcases what happens when you use a language with no 
batteries included, namely Javascript.

One developer just broke most of the Node.js ecosystem by removing an eleven 
line package from npm (the node.js package manager, somewhat similar to 
Python's pip only even more critical):

http://www.theregister.co.uk/2016/03/23/npm_left_pad_chaos/

This critical package is "left-pad". What does it do? It pads strings with 
spaces from the left. It's not just spaces though, it can pad with any 
character you like! Zeroes, commas, even hash signs! We truly live in an age 
of miracles.

The removal of this package (along with about 250 others by the same author, 
but only left-pad appears to have been noticed) crippled Node.js development 
as suddenly thousands of deployed apps could no longer download their 
dependencies.

The author removed his package in a fit of pique because he wasn't allowed 
to continue using a trademarked name. Rather than suck it up like a grown up 
and change the package name, he removed his entire collection of packages 
from npm and (temporarily) broke the entire Node.js ecosystem.

https://medium.com/@azerbike/i-ve-just-liberated-my-modules-9045c06be67c

Of course, moving his allegedly infringing package "kik" to github isn't 
going to fix the problem. It's still allegedly infringing.


More discussion here:

https://github.com/azer/left-pad/issues/4

https://news.ycombinator.com/item?id=11340510

https://www.reddit.com/r/programming/comments/4bjss2/an_11_line_npm_package_called_leftpad_with_only/

A colleague passed on this quote from an acquaintance of his:

"i asked an npm dev at a talk once if they were going to make a stable 
version and they said javascript is not like operating systems and doesn't 
need stable versions"


There's a lesson here for Python package management too. As pip becomes ever 
more popular and functional, there are certain people who believe that the 
whole "batteries included" philosophy of Python is outdated and unnecessary. 
Why have a standard library when you can just download the most recent 
version from PyPI using pip? The node.js experience shows how this can go 
badly wrong.



For those curious, here's left-pad in all its glory:

module.exports = leftpad;
function leftpad (str, len, ch) {
  str = String(str);
  var i = -1;
  if (!ch && ch !== 0) ch = ' ';
  len = len - str.length;
  while (++i < len) {
str = ch + str;
  }
  return str;
}

I leave a Python translation for the experts :-)


-- 
Steve

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


0 equals False, was Re: (unknown)

2016-03-23 Thread Peter Otten
Nick Eubank wrote:

> Hello All,
> 
> 
> Found an odd behavior I'd never known about today, not sure if it's a bug
> or known. Python 3.4.4 (anaconda).

This is a feature. Old versions of Python did not have True and False, so 
they were added in a compatible way.

> True, False, 0, 1 can all be used as dictionary keys.
> 
> But Apparently True and 1 hash to the same item and False and 0 hash to
> the same item, so they can easily overwrite (which I spent a while banging
> my head over today).
> 
> In other words:
> 
>  In[1]:
>  d = {True: 'a', False: 'b'}
>  d[0] = 'z'
>  d[False]
> 
> Out[1]:
>  'z'
> 
> I understand that True and False are sub-types of ints, but it's not clear
> to me why (i.e. certainly didn't feel intuitive) that they would be
> treated the same as keys.
> 
> Relatedly, if this is a desired behavior, any advice one how best to work
> with dictionaries when one wants "True" and 1 to be different? I'm working
> on a function that accepts arguments that may be "True" or 1 (meaning very
> different things) and am seeking a pythonic solution...

The pythonic solution is "don't do this". The == operator cannot 
discriminate between 0, 0.0, and False, or 1, 1.0, and True. 

True and False are singletons, so you can check identity with

x is True or x is False

A type check will also work: 

type(x) == bool
isinstance(x, bool) # bool cannot be subclassed

If you provide some context we may be able to come up with an alternative 
approach that fits your use case.

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


Re: Obtain the variable in bash.

2016-03-23 Thread Chris Angelico
On Wed, Mar 23, 2016 at 7:35 PM, Hongyi Zhao  wrote:
>> My guess is that you started the IDEs from your GUI in some way (the
>> Applications menu or something). If that's the case, they'll inherit
>> their environment from your GUI. You _may_ be able to have them "notice"
>> your change to .bashrc by logging out and in again, or rebooting; it
>> depends how your system is configured.
>
> I tried and find that I must set the variable in .profile file, instead
> of .bashrc, in order to let the IDEs started from my GUI to recognize
> them after I logged out and in again.

Yep, that would do it! Sometimes your GUI will be started from an
interactive shell (or one that thinks it's interactive), in which case
.bashrc will be processed, but in your case, .profile is the solution.

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


Re:

2016-03-23 Thread Chris Angelico
On Wed, Mar 23, 2016 at 2:17 PM, Nick Eubank  wrote:
> But Apparently True and 1 hash to the same item and False and 0 hash to the
> same item, so they can easily overwrite (which I spent a while banging my
> head over today).
>
> In other words:
>
>  In[1]:
>  d = {True: 'a', False: 'b'}
>  d[0] = 'z'
>  d[False]
>
> Out[1]:
>  'z'
>
> I understand that True and False are sub-types of ints, but it's not clear
> to me why (i.e. certainly didn't feel intuitive) that they would be treated
> the same as keys.
>
> Relatedly, if this is a desired behavior, any advice one how best to work
> with dictionaries when one wants "True" and 1 to be different? I'm working
> on a function that accepts arguments that may be "True" or 1 (meaning very
> different things) and am seeking a pythonic solution...

(Presumably everywhere that you write "True" you mean the boolean
value True, not the string "True", which would be completely
separate.)

Dictionary keys are defined on the basis of equality, so anything that
compares equal will match:

>>> d = {True: 'a', False: 'b'}
>>> d[0]
'b'
>>> d[0.0]
'b'

Since you have True and 1 meaning very different things, your program
is already somewhat non-Pythonic. So your best solution is probably
going to be something messy, like having your dictionary keys
incorporate the type of the object. This isn't going to be easy or
clean, but if that's what you have to work with, so be it. (It's not
half as bad as the mess I was helping one of my students with; she's
coping with a Python module that's a hyper-thin layer over an HTTP/XML
request, and it simply takes the returned XML blob and naively
converts it into a Python dictionary. Makes for some ugly code - but
that's not her fault.)

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


Re: Obtain the variable in bash.

2016-03-23 Thread Hongyi Zhao
On Wed, 23 Mar 2016 18:19:04 +1100, Chris Angelico wrote:

> Did you start pycharm/wing from the same session in which you sourced
> .bashrc? If not, they won't see that change.

Thanks a lot for this explanations.  It does behaves as you said which I 
previously not noticed. 

> 
> My guess is that you started the IDEs from your GUI in some way (the
> Applications menu or something). If that's the case, they'll inherit
> their environment from your GUI. You _may_ be able to have them "notice"
> your change to .bashrc by logging out and in again, or rebooting; it
> depends how your system is configured.

I tried and find that I must set the variable in .profile file, instead 
of .bashrc, in order to let the IDEs started from my GUI to recognize 
them after I logged out and in again.

Regards

> 
> ChrisA
-- 
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
-- 
https://mail.python.org/mailman/listinfo/python-list


Pop ups.

2016-03-23 Thread Patrick Rugamba
Hello,
This thing is making me run crazy. Am having these pop ups as I try using 
pycharm saying modify setup, and it is really annoying. I have no clue what is 
causing it but if it can’t be fixed I’d rather uninstall the programs because I 
may end up destroying my pc. I hope you guys can help.
Thanks.

Sent from Mail for Windows 10

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


Re: monkey patching __code__

2016-03-23 Thread dieter
"Sven R. Kunze"  writes:
> ...
> As far as I can see, the code replacement approach solves the problem
> once and for all. Thus is far more stable.
>
> Manually finding out every single module that might or might not have
> imported "reverse" before we could monkeypatch it might result in a
> maintenance nightmare (just think about a Django upgrade).

But you have observed that you cannot do everything with a
code substitution: a function call does not only depend on the code
but also on other properties of the function object: e.g. the
parameter processing.

You might be able to change them in a similar way as "__code__" (i.e.
direct modification). Otherwise, you would need to construct a new
"function object" -- and lose the possibility to completely
change the function object in place.

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


Suggestion: make sequence and map interfaces more similar

2016-03-23 Thread Marco S. via Python-list
I noticed that the sequence types does not have these methods that the map
types  has: get(), items(), keys(), values().

It could seem useless to have them for sequences, but I think it will ease
the creation of functions and methods that allow you to input a generic
iterable as parameter, but needs to use one of these methods in case the
parameter is a map.

In one word, it will facilitate duck typing.

For the same reason, I would suggest the introduction of a new map type,
vdict, a dict that by default iterates over values instead over keys. So a
vdict object "d" wiil have iter(d) == iter(d.values()), and should also
have a count() method, like sequence types.

Indeed sequences are, in my humble opinion, a specialized case of maps,
when keys are numeric only, are always contiguous without gaps and start
from 0. This way we will have a simpler way to let people to use sequences
or maps indifferently, and let the code untouched.
-- 
https://mail.python.org/mailman/listinfo/python-list


[no subject]

2016-03-23 Thread Nick Eubank
Hello All,


Found an odd behavior I'd never known about today, not sure if it's a bug
or known. Python 3.4.4 (anaconda).

True, False, 0, 1 can all be used as dictionary keys.

But Apparently True and 1 hash to the same item and False and 0 hash to the
same item, so they can easily overwrite (which I spent a while banging my
head over today).

In other words:

 In[1]:
 d = {True: 'a', False: 'b'}
 d[0] = 'z'
 d[False]

Out[1]:
 'z'

I understand that True and False are sub-types of ints, but it's not clear
to me why (i.e. certainly didn't feel intuitive) that they would be treated
the same as keys.

Relatedly, if this is a desired behavior, any advice one how best to work
with dictionaries when one wants "True" and 1 to be different? I'm working
on a function that accepts arguments that may be "True" or 1 (meaning very
different things) and am seeking a pythonic solution...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Obtain the variable in bash.

2016-03-23 Thread Ben Finney
Hongyi Zhao  writes:

> I exported a variable in my .bashrc as follows:
>
> export MY_VAR="fdsfads"

That ‘export’ means that child processes of this one (i.e., the shell in
which that command executed) will inherit that variable in their
environment.

Processes that are not children of this one, will not be affected.

> Then I soured the .bashrc and do the testing as follows:
>
> werner@debian-01:~$ python -c "import os; print os.environ['MY_VAR']"
> fdsfads

Yes. Because that ‘python’ process is started from a process which has
that exported variable, that ‘python’ process inherits the variable in
its environment.

> But, when I run the same commands in pycharm and wing ide, I failed the 
> obtain the value of this variable.

Were they started as child processes from the shell that is exporting
the variable?

See https://en.wikipedia.org/wiki/Environment_variable#Unix_2> for
a discussion of how the process environment variables are inherited.

-- 
 \  “Every man would like to be God, if it were possible; some few |
  `\  find it difficult to admit the impossibility.” —Bertrand |
_o__)Russell, _Power: A New Social Analysis_, 1938 |
Ben Finney

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


Re: Obtain the variable in bash.

2016-03-23 Thread Chris Angelico
On Wed, Mar 23, 2016 at 6:12 PM, Hongyi Zhao  wrote:
> I exported a variable in my .bashrc as follows:
>
> export MY_VAR="fdsfads"
>
> Then I soured the .bashrc and do the testing as follows:
>
> werner@debian-01:~$ python -c "import os; print os.environ['MY_VAR']"
> fdsfads
>
> But, when I run the same commands in pycharm and wing ide, I failed the
> obtain the value of this variable.
>
> I'm very confused with this issue.
>

Did you start pycharm/wing from the same session in which you sourced
.bashrc? If not, they won't see that change.

My guess is that you started the IDEs from your GUI in some way (the
Applications menu or something). If that's the case, they'll inherit
their environment from your GUI. You _may_ be able to have them
"notice" your change to .bashrc by logging out and in again, or
rebooting; it depends how your system is configured.

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


Obtain the variable in bash.

2016-03-23 Thread Hongyi Zhao
Hi all,

I exported a variable in my .bashrc as follows:

export MY_VAR="fdsfads"

Then I soured the .bashrc and do the testing as follows:

werner@debian-01:~$ python -c "import os; print os.environ['MY_VAR']"
fdsfads

But, when I run the same commands in pycharm and wing ide, I failed the 
obtain the value of this variable.

I'm very confused with this issue.

Any hints?

Regards
-- 
.: Hongyi Zhao [ hongyi.zhao AT gmail.com ] Free as in Freedom :.
-- 
https://mail.python.org/mailman/listinfo/python-list