Re: TypeError: list indices must be integers, not tuple

2015-02-10 Thread Ryan Stuart
Hi,

There is a lot of issues with this code. First, setting fav to a 1 tuples
with a string probably isn't what you want. What you probably mean is:

if restraunt == ("Pizza"):
fav = 1

Second, when you are trying to lookup items in Menu, you are using the
incorrect fav. Lists have int indicies (just like the error points out).
Values like ("1") aren't integers.

Thirdly, Menu is a list of lists. To fetch "Barbeque pizza" from Menu, you
need to do Menu[0][0], not Menu[0, 0].

Finally, Python comes with a style guide which you can find in pep8
. Your code violates that guide
in many places. It might be worth working through the Python Tutorial
.

Cheers

On Tue Feb 10 2015 at 9:55:40 AM  wrote:

> import random
> RandomNum = random.randint(0,7)
> restraunt = raw_input("What's your favourite takeaway?Pizza, Chinease or
> Indian?")
> if restraunt == ("Pizza"):
> fav = ("1")
>
> elif restraunt == ("Chinease"):
> fav = ("2")
>
> elif restraunt == ("Indian"):
> fav = ("3")
>
> else:
> print("Try using a capital letter, eg; 'Chinease'")
>
> Menu = [["Barbeque pizza","Peparoni","Hawain"],["
> Curry","Noodles","Rice"],["Tika Masala","Special Rice","Onion Bargees"]]
>
> print Menu[fav,RandomNum]
>^
> TypeError: list indices must be integers, not tuple
>
> How do I set a variable to a random number then use it as a list indece,
> (I'm only a student in his first 6 months of using python)
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.x stuffing utf-8 into SQLite db

2015-02-10 Thread Skip Montanaro
On Mon, Feb 9, 2015 at 11:54 AM, Matthew Ruffalo  wrote:
> I think it's most likely that the encoding issues happened in the export
> from XLSX to CSV (unless the data is malformed in the original XLSX
> file, of course).

Aha! Lookee here... (my apologies to all you HTML mail haters - sometimes
it even comes in handy. :-)


This snapshot was taken against a running LibreOffice instance here at work
(on Linux). It would appear the fancy schmancy apostrophe was hosed up
before the data ever got to me. Had a guy here with Windows pop up the
original file I got in an actual Excel instance. Same bogosity.

Knowing that, I don't feel the least bit timid about just editing the darn
CSV file to correct the encode/decode/encode error before loading the data
into SQLite. I was worried that since I was doing some Python 3.x stuff
involving Unicode for the first time that I'd screwed something up.

Skip

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


Re: Weird behavior on __dict__ attr

2015-02-10 Thread Steven D'Aprano
Shiyao Ma wrote:

> Hi.
> 
> My context is a little hard to reproduce.
> 
> NS3 is a network simulation tool written in C++. I am using its Python
> binding.
> 
> So the class I am dealing with is from a .so file.

So it is written in (probably) C and you don't have source code for it.

> Say, I do the following:
> 
> %
> 
> import ns.network.Node as Node
> 
> # Node is a class
> # it has a __dict__ attr
> 
> # Now I instantiate an instance of Node
> n = Node()
> 
> # I checked, there is no __dict__ on 'n'
> # but the following succeeds.
> 
> n.foobar = 3

It is hard to say exactly what is happening without source code. If Node is 
an extension class written in C, it could do almost anything. It certainly 
doesn't need to follow Python conventions for Python classes.


If this were a pure-Python class, I can think of at least three ways to get 
this behaviour:

- use __slots__ so that the class has a fixed set of members 
  with no __dict__ used or needed;

- use a custom descriptor

- use a custom metaclass that changes the behaviour of lookups;

I presume that extension classes written in C can do similar things.


> My understanding is the foobar is stored in n.__dict__, but seemingly n
> has no __dict__.
> 
> So where does the foobar go?

Here are some diagnostic tools you can use to try to determine what is going 
on:

print(vars(n))
print(dir(n))
print(n.__slots__)
o = Node.__dict__['foobar']
print(type(o), repr(o))




-- 
Steve

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


Re: Python 3.x stuffing utf-8 into SQLite db

2015-02-10 Thread Chris Angelico
On Tue, Feb 10, 2015 at 5:52 AM, Skip Montanaro
 wrote:
>
> This snapshot was taken against a running LibreOffice instance here at work 
> (on Linux). It would appear the fancy schmancy apostrophe was hosed up before 
> the data ever got to me. Had a guy here with Windows pop up the original file 
> I got in an actual Excel instance. Same bogosity.
>

Just what you always want to see, messy data!

> Knowing that, I don't feel the least bit timid about just editing the darn 
> CSV file to correct the encode/decode/encode error before loading the data 
> into SQLite. I was worried that since I was doing some Python 3.x stuff 
> involving Unicode for the first time that I'd screwed something up.
>

Py3 makes things so easy that the chances are you got it right :) As
long as the encoding parameter on the open() call matches the file's
actual encoding, chances are you're fine - everything else is done
with Unicode characters.

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


Re: Varable parsing error with python

2015-02-10 Thread OmPs
On 10 Feb 2015 13:12, "Chris Angelico"  wrote:
>
> On Tue, Feb 10, 2015 at 6:30 PM, OmPs  wrote:
> > def _getPackgeVersion(xmlfile, p):
> > package = str(p)
> > if isinstance(fpmdict["application"]["package"], list):
> > for i in fpmdict["application"]["package"]:
> > if i["@name"] == p:
> > _pkgVersion = i["version"]
> > else:
> > _pkgversion = fpmdict["application"]["package"]["version"]
> > return _pkgVersion
>
> One of your branches doesn't have a return statement in it, so Python
> just returns None. You may want to unindent that return statement one
> level.
>
Tried that as well getting the same error.
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: __next__ and StopIteration

2015-02-10 Thread Ian Kelly
On Mon, Feb 9, 2015 at 5:59 PM, Chris Kaynor  wrote:
> On Mon, Feb 9, 2015 at 4:42 PM, Steven D'Aprano
>  wrote:
>> so that's an excellent sign that doing so is best practice, but it should
>> not be seen as *required*. After all, perhaps you have good reason for
>> wanting your iterable class to only be iterated over once.
>
> In fact, there is one in the stdlib, the "file" object, which has a
> __iter__ which returns self. The code below shows this,

Fair point. I suppose that's because the file paradigm itself has a
concept of current position that can't easily be abstracted away.

> The "file" object is also an example of this. It is technically a
> broken iterator according to the docs:
>
> Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600
> 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
 f = open("d:/test.txt")
 iter(f) is f
> True
 for l in f:
> ... print(l)
> ...
> line 1
>
> line 2
>
> line 3
>
 for l in f:
> ... print(l)
> ...
 f.seek(0)
> 0
 for l in f:
> ... print(l)
> ...
> line 1
>
> line 2
>
> line 3
>
 next(f)
> Traceback (most recent call last):
>   File "", line 1, in 
> StopIteration
 f.seek(0)
> 0
 next(f) # This should throw StopIteration as it has previously thrown 
 StopIteration.
> 'line 1\n'

IIRC the docs also warn that mixing file iteration with other file
methods results in undefined or broken behavior. Maybe that's only for
Python 2 files, however.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Varable parsing error with python

2015-02-10 Thread OmPs
On 10 Feb 2015 13:59, "OmPs"  wrote:
>
>
> On 10 Feb 2015 13:12, "Chris Angelico"  wrote:
> >
> > On Tue, Feb 10, 2015 at 6:30 PM, OmPs  wrote:
> > > def _getPackgeVersion(xmlfile, p):
> > > package = str(p)
> > > if isinstance(fpmdict["application"]["package"], list):
> > > for i in fpmdict["application"]["package"]:
> > > if i["@name"] == p:
> > > _pkgVersion = i["version"]
> > > else:
> > > _pkgversion = fpmdict["application"]["package"]["version"]
> > > return _pkgVersion
> >
> > One of your branches doesn't have a return statement in it, so Python
> > just returns None. You may want to unindent that return statement one
> > level.
> >
> Tried that as well getting the same error.

I feel its something to do with variable substitution.

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


Re: TypeError: list indices must be integers, not tuple

2015-02-10 Thread Mark Lawrence

On 10/02/2015 00:05, Ryan Stuart wrote:

Hi,

There is a lot of issues with this code. First, setting fav to a 1
tuples with a string probably isn't what you want. What you probably
mean is:

if restraunt == ("Pizza"):
 fav = 1

Second, when you are trying to lookup items in Menu, you are using the
incorrect fav. Lists have int indicies (just like the error points out).
Values like ("1") aren't integers.

Thirdly, Menu is a list of lists. To fetch "Barbeque pizza" from Menu,
you need to do Menu[0][0], not Menu[0, 0].

Finally, Python comes with a style guide which you can find in pep8
. Your code violates that
guide in many places. It might be worth working through the Python
Tutorial .

Cheers

On Tue Feb 10 2015 at 9:55:40 AM mailto:james8boo...@hotmail.com>> wrote:

import random
RandomNum = random.randint(0,7)
restraunt = raw_input("What's your favourite takeaway?Pizza,
Chinease or Indian?")
if restraunt == ("Pizza"):
 fav = ("1")

elif restraunt == ("Chinease"):
 fav = ("2")

elif restraunt == ("Indian"):
 fav = ("3")

else:
 print("Try using a capital letter, eg; 'Chinease'")

Menu = [["Barbeque
pizza","Peparoni","Hawain"],["__Curry","Noodles","Rice"],["__Tika
Masala","Special Rice","Onion Bargees"]]

print Menu[fav,RandomNum]
^
TypeError: list indices must be integers, not tuple

How do I set a variable to a random number then use it as a list
indece, (I'm only a student in his first 6 months of using python)
--
https://mail.python.org/__mailman/listinfo/python-list




If you can show me a one tuple anywhere in the original code I'll 
happily buy you a tipple of your choice.


Also please don't top post here, it makes following long threads 
difficult if not impossible to follow, thanks.


--
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: doc buglets?

2015-02-10 Thread Rustom Mody
On Monday, February 9, 2015 at 9:25:45 PM UTC+5:30, Mark Lawrence wrote:
> On 09/02/2015 11:28, Rustom Mody wrote:
> > Poking around in help() (python 3.4.2) I find
> >
> > * PACKAGES
> > does not seem to have anything on packages
> > * DYNAMICFEATURES
> > seems to be some kind of footnote
> > * SPECIALATTRIBUTES
> > has 'bases' and 'subclasses'. It seems to me a more consistent naming
> > for OOP would be in order.  These are the OOP-metaphors I am familiar with
> > - superclass ↔ subclass
> > - base class ↔ derived class
> > - parent class ↔ child class
> >
> > [Yeah if this is a bug its more than a docbug.
> > So no, I am not suggesting changing the actual attribute names which would 
> > be a
> > breaking change, just the stuff in help()
> > ]
> >
> 
> So raise an issue and attach a patch.

Sure – can do.
However for the first two I am not sure what the intentions of those entries are

And for the third, I am not clear that anyone other than me finds the 
mismatching
metaphors galling.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Incompatible idioms: relative imports, top-level program file

2015-02-10 Thread Rustom Mody
On Sunday, February 8, 2015 at 3:52:19 AM UTC+5:30, Gregory Ewing wrote:
> Rustom Mody wrote:
> > Wanted to try out sympy.
> > apt-install promised ź GB download, ž GB space usage
> > 
> > Just getting a src-tarball was: 6M download, 30M after opening the tar.
> 
> Have you actually tried compiling and using that
> tarball, though?
> 
> Sympy hooks into a lot of other libraries that
> are themselves quite large. Apt-get was probably
> planning to download and install all of them,
> hence the large download size.
> 
> If you tried to install from source, you would
> likely have to install all those dependencies
> yourself, or configure it to skip the ones you
> don't want if it allows that.
> 
> -- 
> Greg

Yeah...
Sympy output as on display 
http://nbviewer.ipython.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-5-Sympy.ipynb
looks quite beautiful and probably needs all those Tex etc fonts

As it happens I did not need that
I just wanted to demo some differences between object-level and meta-level .
I guess the best choice for that would be lisp.
I could not figure racket out – terminologies seem to have changed in the last 
couple of decades – so I took sympy's distinction of python-variable and 
math-variable as a good enough exemplar of meta-level and object-level.
[Python's namespaces are not really firstclass like (some) scheme's are -- eg 
locals() makes a copy]

Anyway… My point was not that particular use-case but the general point that 
one may 
want to play around with alternate packaging systems
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: list indices must be integers, not tuple

2015-02-10 Thread Dave Angel

On 02/10/2015 06:35 AM, Mark Lawrence wrote:

On 10/02/2015 00:05, Ryan Stuart wrote:

Hi,





If you can show me a one tuple anywhere in the original code I'll
happily buy you a tipple of your choice.


print Menu[fav,RandomNum]

was in the original code



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


Re: TypeError: list indices must be integers, not tuple

2015-02-10 Thread Mark Lawrence

On 10/02/2015 14:28, Dave Angel wrote:

On 02/10/2015 06:35 AM, Mark Lawrence wrote:

On 10/02/2015 00:05, Ryan Stuart wrote:

Hi,





If you can show me a one tuple anywhere in the original code I'll
happily buy you a tipple of your choice.


print Menu[fav,RandomNum]

was in the original code





Thanks for the correction, I should have been more careful how I phrased 
my reply :(


--
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: TypeError: list indices must be integers, not tuple

2015-02-10 Thread Chris Angelico
On Wed, Feb 11, 2015 at 1:28 AM, Dave Angel  wrote:
>> If you can show me a one tuple anywhere in the original code I'll
>> happily buy you a tipple of your choice.
>
>
> print Menu[fav,RandomNum]
>
> was in the original code

That's not a one-tuple (as in, a tuple with one element), it's a
two-element tuple. The point is that ("3") doesn't create a tuple,
it's just superfluous parentheses.

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


tabs and the Python3 console

2015-02-10 Thread Laura Creighton
I have the debian version of python3 installed here.

Python 3.4.2 (default, Nov 13 2014, 07:01:52) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

But I cannot seem to type a tab here:

>>> def fn(**kw):
...

(I type a tab here, and get a beep.  If I type a tab again I get:

Display all 178 possibilities? (y or n)
ArithmeticError(chr(
AssertionError( class
AttributeError( classmethod(
BaseException(  compile(
BlockingIOError(complex(
BrokenPipeError(continue

...

Do I need a python3 enabled with readline support, or something?

Thanks very much,
Laura Creighton


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


Re: Varable parsing error with python

2015-02-10 Thread Dave Angel

On 02/10/2015 03:29 AM, OmPs wrote:

On 10 Feb 2015 13:12, "Chris Angelico"  wrote:


On Tue, Feb 10, 2015 at 6:30 PM, OmPs  wrote:

 def _getPackgeVersion(xmlfile, p):
 package = str(p)
 if isinstance(fpmdict["application"]["package"], list):
 for i in fpmdict["application"]["package"]:
 if i["@name"] == p:
 _pkgVersion = i["version"]
 else:
 _pkgversion = fpmdict["application"]["package"]["version"]
 return _pkgVersion


One of your branches doesn't have a return statement in it, so Python
just returns None. You may want to unindent that return statement one
level.


Tried that as well getting the same error.


The code above has at least two errors.  Fix them both, post a new 
version, and tell us the error you now get.


First error is that there's no return statement for the case where the 
first if is true.  You might fix that by unindenting, or by adding 
another return somewhere, or whatever.


Second error, depending on how you fixed the first one, is that for some 
paths through the function, _pkgVersion isn't initialized.  So if those 
conditions happen, and if you fixed the first error, you'll get an 
exception like:


UnboundLocalError: local variable '_pkgVersion' referenced before assignment

There also may be logic errors.  For example, if there are multiple 
places where the if i["@name...   logic triggers, do you want the 
_pkgversion to be the first such, or the last such.  What do you want 
for a value if there no matches?





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


Re: Monte Carlo probability calculation in Python

2015-02-10 Thread Paul Moore
On Monday, 9 February 2015 21:57:51 UTC, Paul  Moore  wrote:
> On Friday, 6 February 2015 23:49:51 UTC, Steven D'Aprano  wrote:
> > Very nice! Care to share the code?
> 
> Will do.

Here's the code I used for the Monopoly calculations.

import numpy as np

def monopoly(samples):
# 2d6 x 3
num = 2
sides = 6
rolls = 3
dice = np.random.randint(1, sides + 1, size=(samples, rolls, num))

# Doubles are if the two dice are the same
doubles = dice[...,0] == dice[...,1]
# Reroll if this (and all previous rolls) are doubles
reroll = np.logical_and.accumulate(doubles, axis=1)
# Keep the first entry, and any valid rerolls
keep = np.insert(reroll, 0, True, axis=1)
# The last column (all 3 are doubles) is "go to gaol"
keep, gaol = np.split(keep, [-1], axis=-1)
gaol = gaol[...,0]

# Add up all the rolls and zero out any we don't want to keep
totals = dice.sum(axis=-1) * keep
# Remove any "go to gaol" cases
totals = totals[~gaol,...]
# Add up the distance moved
totals = totals.sum(axis=-1)

gaol_count = np.sum(gaol)

return totals, gaol_count

samples = 100
totals, gaol_count = monopoly(samples)

print("Average distance moved =", totals.mean())
print("Percentage of times you go to gaol: {:%}".format(gaol_count/samples))
for i, count in enumerate(np.bincount(totals)):
print("{:>2} {}".format(i, count))

The actual calculations are fairly simple, once you get your head round the 
tricks you need to do everything array-based. The part I find the hardest by 
far, is keeping track of the dimensions of the arrays involved, and what I need 
to do to match up axes, etc. For example, it took me a long time to work out 
what was going wrong with stripping out the "go to gaol" cases. The problem 
turned out to be that I needed the line "gaol = gaol[...,0]" to strip off a 
dimension - but it was really hard working out what was going on, particularly 
as numpy broadcasts the values you have, so you don't get errors, just weirdly 
wrong answers. (This isn't unique to numpy, I remember having the same issues 
when I used to work with J).

One thing it'd be nice to do would be to abstract out the array dimension for 
the number of samples, so that the "application" code could be written as if 
working on just one sample, and the driver code extended that to multiple 
samples. But I don't have the first idea how I'd do that without ending up 
looping in Python, which is what I need to avoid if I want performance to 
remain good.

Lots of scope for more things to learn here, then :-)

Thanks again to everyone that helped.
Paul
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: list indices must be integers, not tuple

2015-02-10 Thread Dave Angel

On 02/10/2015 09:33 AM, Chris Angelico wrote:

On Wed, Feb 11, 2015 at 1:28 AM, Dave Angel  wrote:

If you can show me a one tuple anywhere in the original code I'll
happily buy you a tipple of your choice.



print Menu[fav,RandomNum]

was in the original code


That's not a one-tuple (as in, a tuple with one element), it's a
two-element tuple. The point is that ("3") doesn't create a tuple,
it's just superfluous parentheses.


You're right of course. I didn't notice the meaning of one-tuple; I took 
Mark's comment as if he had said:


If you can show me a  one tuple anywhere ...

The original error message said there was a tuple;  I knew that fav 
wasn't the tuple, but the combination of fav and RandomNum was.



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


Re: tabs and the Python3 console

2015-02-10 Thread Vincent Vande Vyvre

Le 10/02/2015 15:36, Laura Creighton a écrit :

I have the debian version of python3 installed here.

Python 3.4.2 (default, Nov 13 2014, 07:01:52)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
But I cannot seem to type a tab here:


def fn(**kw):

...

(I type a tab here, and get a beep.  If I type a tab again I get:

Display all 178 possibilities? (y or n)
ArithmeticError(chr(
AssertionError( class
AttributeError( classmethod(
BaseException(  compile(
BlockingIOError(complex(
BrokenPipeError(continue

...

Do I need a python3 enabled with readline support, or something?

Thanks very much,
Laura Creighton




It's a recent change (3.4), use the argument -S if you want the old 
behaviour


https://docs.python.org/3/library/site.html#rlcompleter-config

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


Re: tabs and the Python3 console

2015-02-10 Thread Laura Creighton
In a message of Tue, 10 Feb 2015 16:50:54 +0100, Vincent Vande Vyvre writes:
>Le 10/02/2015 15:36, Laura Creighton a écrit :
>> I have the debian version of python3 installed here.
>>
>> Python 3.4.2 (default, Nov 13 2014, 07:01:52)
>> [GCC 4.9.2] on linux
>> Type "help", "copyright", "credits" or "license" for more information.
>> But I cannot seem to type a tab here:
>>
> def fn(**kw):
>> ...
>>
>> (I type a tab here, and get a beep.  If I type a tab again I get:
>>
>> Display all 178 possibilities? (y or n)
>> ArithmeticError(chr(
>> AssertionError( class
>> AttributeError( classmethod(
>> BaseException(  compile(
>> BlockingIOError(complex(
>> BrokenPipeError(continue
>> 
>> ...
>>
>> Do I need a python3 enabled with readline support, or something?
>>
>> Thanks very much,
>> Laura Creighton
>>
>>
>
>It's a recent change (3.4), use the argument -S if you want the old 
>behaviour
>
>https://docs.python.org/3/library/site.html#rlcompleter-config
>
>Vincent

Thank you very, very much.

Laura

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


Re: __next__ and StopIteration

2015-02-10 Thread Ethan Furman
On 02/09/2015 08:46 PM, Chris Angelico wrote:
> 
> class Grid:
> blah blah
> 
> def __iter__(self):
> for row in range(self._rows):
> for col in range(self._cols):
> if self._grid[row][col]:
> yield self._grid[row][col]

I strongly suggest you remove the

  if self._grid[row][col]:

line.

Best case scenario: the entire grid is blank, and iterating through it does 
nothing.

Worst case scenario:  only some elements evaluate as False, so your loop 
doesn't execute the full number of times; i.e.
with a grid of 4x5 with 7 blank cells you get 13 iterations -- probably not 
what was expected.

--
~Ethan~



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: __next__ and StopIteration

2015-02-10 Thread Ian Kelly
On Tue, Feb 10, 2015 at 9:44 AM, Ethan Furman  wrote:
> On 02/09/2015 08:46 PM, Chris Angelico wrote:
>>
>> class Grid:
>> blah blah
>>
>> def __iter__(self):
>> for row in range(self._rows):
>> for col in range(self._cols):
>> if self._grid[row][col]:
>> yield self._grid[row][col]
>
> I strongly suggest you remove the
>
>   if self._grid[row][col]:
>
> line.
>
> Best case scenario: the entire grid is blank, and iterating through it does 
> nothing.
>
> Worst case scenario:  only some elements evaluate as False, so your loop 
> doesn't execute the full number of times; i.e.
> with a grid of 4x5 with 7 blank cells you get 13 iterations -- probably not 
> what was expected.

Depends on what the expected behavior is -- is every grid position
something that should be included in the iteration, or are we looking
at elements of a container where some possible locations may be empty?
You don't expect a dict iteration to yield empty buckets, for example.

I have some code that looks similar to this, which is an iterator for
a chess board that yields the contained pieces. It doesn't really make
sense in that case to yield empty squares.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: __next__ and StopIteration

2015-02-10 Thread Chris Kaynor
On Tue, Feb 10, 2015 at 12:30 AM, Ian Kelly  wrote:
>
> On Mon, Feb 9, 2015 at 5:59 PM, Chris Kaynor  wrote:
> > On Mon, Feb 9, 2015 at 4:42 PM, Steven D'Aprano
> >  wrote:
> >> so that's an excellent sign that doing so is best practice, but it should
> >> not be seen as *required*. After all, perhaps you have good reason for
> >> wanting your iterable class to only be iterated over once.
> >
> > In fact, there is one in the stdlib, the "file" object, which has a
> > __iter__ which returns self. The code below shows this,
>
> Fair point. I suppose that's because the file paradigm itself has a
> concept of current position that can't easily be abstracted away.

That is basically my thought as well. It would be possible to seek
around the file while iterating (seek to the current iteration
position, read, then seek back to the previous location), however that
would slow down iteration for little practical gain. It would also
require locking and possibly introduce odd corner cases.

>
> > The "file" object is also an example of this. It is technically a
> > broken iterator according to the docs:
> >
> > Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600
> > 32 bit (Intel)] on win32
> > Type "help", "copyright", "credits" or "license" for more information.
>  f = open("d:/test.txt")
>  iter(f) is f
> > True
>  for l in f:
> > ... print(l)
> > ...
> > line 1
> >
> > line 2
> >
> > line 3
> >
>  for l in f:
> > ... print(l)
> > ...
>  f.seek(0)
> > 0
>  for l in f:
> > ... print(l)
> > ...
> > line 1
> >
> > line 2
> >
> > line 3
> >
>  next(f)
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > StopIteration
>  f.seek(0)
> > 0
>  next(f) # This should throw StopIteration as it has previously thrown 
>  StopIteration.
> > 'line 1\n'
>
> IIRC the docs also warn that mixing file iteration with other file
> methods results in undefined or broken behavior. Maybe that's only for
> Python 2 files, however.


>From the 2.7.9 docs 
>(https://docs.python.org/2/library/stdtypes.html#file.next):
> As a consequence of using a read-ahead buffer, combining next() with other 
> file methods (like readline()) does not work right. However, using seek() to 
> reposition the file to an absolute position will flush the read-ahead buffer.

So it explicitly states that seek, the method I used, should work
fine. I could not find any similar text in the 3.4 docs.

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


Re: drawing with the mouse with turtle

2015-02-10 Thread solarteclark
excuse me :) i know this somewhat disscussion was still on the past few years 
way back 2010 can i still ask about something? :) what syntax or coding will i 
use if i wanted to do multiple strokes of the mouse? 
because the [turtle.ondrag(turtle.goto)] that you have suggested have really 
helped but what if i want to write more strokes on different left clicks? like 
i want to draw 2 lines, like some syntax or code that enables me to add more or 
just reset the other line and make more or replace it? can you help me :) 
please :D

i know i'm just some random stranger but please help me :D
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: __next__ and StopIteration

2015-02-10 Thread Ethan Furman
On 02/10/2015 08:53 AM, Ian Kelly wrote:
> On Tue, Feb 10, 2015 at 9:44 AM, Ethan Furman  wrote:
>> On 02/09/2015 08:46 PM, Chris Angelico wrote:
>>>
>>> class Grid:
>>> blah blah
>>>
>>> def __iter__(self):
>>> for row in range(self._rows):
>>> for col in range(self._cols):
>>> if self._grid[row][col]:
>>> yield self._grid[row][col]
>>
>> I strongly suggest you remove the
>>
>>   if self._grid[row][col]:
>>
>> line.
>>
>> Best case scenario: the entire grid is blank, and iterating through it does 
>> nothing.
>>
>> Worst case scenario:  only some elements evaluate as False, so your loop 
>> doesn't execute the full number of times; i.e.
>> with a grid of 4x5 with 7 blank cells you get 13 iterations -- probably not 
>> what was expected.
> 
> Depends on what the expected behavior is -- is every grid position
> something that should be included in the iteration, or are we looking
> at elements of a container where some possible locations may be empty?
> You don't expect a dict iteration to yield empty buckets, for example.
> 
> I have some code that looks similar to this, which is an iterator for
> a chess board that yields the contained pieces. It doesn't really make
> sense in that case to yield empty squares.

Cool, thanks for the correction.

--
~Ethan~



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Varable parsing error with python

2015-02-10 Thread Denis McMahon
On Tue, 10 Feb 2015 18:39:42 +1100, Chris Angelico wrote:

> On Tue, Feb 10, 2015 at 6:30 PM, OmPs  wrote:
>> def _getPackgeVersion(xmlfile, p):
>> package = str(p)
>> if isinstance(fpmdict["application"]["package"], list):
>> for i in fpmdict["application"]["package"]:
>> if i["@name"] == p:
>> _pkgVersion = i["version"]
>> else:
>> _pkgversion = fpmdict["application"]["package"]["version"]
>> return _pkgVersion
> 
> One of your branches doesn't have a return statement in it, so Python
> just returns None. You may want to unindent that return statement one
> level.

Even if he unindents the return, it will still return None if it doesn't 
find an i such that i["@name"] == p, as _pkgVersion only gets set if such 
a match is found.

Could this be cause by eg a string case match issue? Perhaps:

if i["@name"].lower() == p.lower():

would be a better comparison to use?

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: list indices must be integers, not tuple

2015-02-10 Thread Chris Angelico
On Wed, Feb 11, 2015 at 2:51 AM, Dave Angel  wrote:
> You're right of course. I didn't notice the meaning of one-tuple; I took
> Mark's comment as if he had said:
>
> If you can show me a  one tuple anywhere ...

Ah, yeah. I see the ambiguity. This is the downside of being so fluent
in Typo - sometimes you run into false cognates :)

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


Taming the verbosity of ipython tracebacks

2015-02-10 Thread John Ladasky
Hi folks,

I'm running Python 3.4.0, and ipython3 1.2.1, on Ubuntu Linux 14.04 64-bit.

Whenever I execute code from within ipython which triggers an exception -- any 
exception -- I get a page full of information.  The exceptions in my code 
trigger exceptions within ipython.

Every error message looks like this:



ERROR: Internal Python error in the inspect module.
Below is the traceback from this internal error.

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 
2821, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
  File "", line 1, in 
  
<< MY ERRONEOUS CODE, AND THE EXCEPTION IT GENERATED, ARE PRINTED HERE >>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/IPython/core/interactiveshell.py", line 
1713, in showtraceback
stb = value._render_traceback_()
AttributeError: 'NameError' object has no attribute '_render_traceback_'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/IPython/core/ultratb.py", line 759, in 
structured_traceback
records = _fixed_getinnerframes(etb, context, tb_offset)
  File "/usr/lib/python3/dist-packages/IPython/core/ultratb.py", line 242, in 
_fixed_getinnerframes
records  = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
  File "/usr/lib/python3.4/inspect.py", line 1332, in getinnerframes
framelist.append((tb.tb_frame,) + getframeinfo(tb, context))
  File "/usr/lib/python3.4/inspect.py", line 1292, in getframeinfo
filename = getsourcefile(frame) or getfile(frame)
  File "/usr/lib/python3.4/inspect.py", line 583, in getsourcefile
if getattr(getmodule(object, filename), '__loader__', None) is not None:
  File "/usr/lib/python3.4/inspect.py", line 629, in getmodule
os.path.realpath(f)] = module.__name__
AttributeError: 'FakeModule' object has no attribute '__name__'

Unfortunately, your original traceback can not be constructed.



When I run the same script directly from the Linux shell, I get a tidy 
traceback which tells me exactly what I want, and nothing more.  But then, 
obviously, I lose the interactive ipython shell's capabilities.

I would like to get rid of all that fluff surrounding my ipython error message. 
 I'm not sure what the purpose of the inspect module is, or what FakeModule is. 
 I wonder whether I have failed to install something correctly.  Any advice is 
appreciated!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Taming the verbosity of ipython tracebacks

2015-02-10 Thread Chris Angelico
On Wed, Feb 11, 2015 at 5:53 AM, John Ladasky
 wrote:
> I'm running Python 3.4.0, and ipython3 1.2.1, on Ubuntu Linux 14.04 64-bit.
>

That's  nice recent Python, but I just tried installing ipython using
pip3, and got version 2.4.1, and was unable to reproduce your
scenario. Is it possible you're having problems due to the version
mismatch? Can you upgrade your ipython?

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


Re: Taming the verbosity of ipython tracebacks

2015-02-10 Thread John Ladasky
On Tuesday, February 10, 2015 at 11:00:32 AM UTC-8, Chris Angelico wrote:
> On Wed, Feb 11, 2015 at 5:53 AM, John Ladasky
>  wrote:
> > I'm running Python 3.4.0, and ipython3 1.2.1, on Ubuntu Linux 14.04 64-bit.
> >
> 
> That's  nice recent Python, but I just tried installing ipython using
> pip3, and got version 2.4.1, and was unable to reproduce your
> scenario. Is it possible you're having problems due to the version
> mismatch? Can you upgrade your ipython?
> 
> ChrisA

Thank you Chris, that did the trick.  I now have ipython 2.4.1 as well, and my 
tracebacks are behaving.  Ubuntu's repository apparently has an outdated 
version of ipython.  

Also, a heads-up: the pip3 utility does not recognize a package named ipython3, 
the name that Ubuntu expects.  The package name reverts to plain-old ipython.  
This name conflict might cause problems for someone who wants to run ipython 
with Py2 -- while that isn't me, it may affect some of you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Taming the verbosity of ipython tracebacks

2015-02-10 Thread Albert-Jan Roskam


- Original Message -

> From: Chris Angelico 
> To: 
> Cc: "python-list@python.org" 
> Sent: Tuesday, February 10, 2015 8:00 PM
> Subject: Re: Taming the verbosity of ipython tracebacks
> 
> On Wed, Feb 11, 2015 at 5:53 AM, John Ladasky
>  wrote:
>>  I'm running Python 3.4.0, and ipython3 1.2.1, on Ubuntu Linux 14.04 
> 64-bit.
>> 
> 
> That's  nice recent Python, but I just tried installing ipython using
> pip3, and got version 2.4.1, and was unable to reproduce your
> scenario. Is it possible you're having problems due to the version
> mismatch? Can you upgrade your ipython?


Huh? What's pip3? I thought pip works on Python 2 and 3?
https://pypi.python.org/pypi/pip/. I always install everything with the pip of 
my system python, e.g. for Python 3.4 I would do sudo python3.4 $(which pip) 
install somepackage. Are there any benefits of having multiple pips (except in 
virtualenvs)?

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


Re: Taming the verbosity of ipython tracebacks

2015-02-10 Thread John Ladasky
On Tuesday, February 10, 2015 at 11:34:12 AM UTC-8, Albert-Jan Roskam wrote:
> - Original Message -
> 
> > From: Chris Angelico 
> > To: 
> > Cc: "python-list@python.org" 
> > Sent: Tuesday, February 10, 2015 8:00 PM
> > Subject: Re: Taming the verbosity of ipython tracebacks
> > 
> > On Wed, Feb 11, 2015 at 5:53 AM, John Ladasky
> >  wrote:
> >>  I'm running Python 3.4.0, and ipython3 1.2.1, on Ubuntu Linux 14.04 
> > 64-bit.
> >> 
> > 
> > That's  nice recent Python, but I just tried installing ipython using
> > pip3, and got version 2.4.1, and was unable to reproduce your
> > scenario. Is it possible you're having problems due to the version
> > mismatch? Can you upgrade your ipython?
> 
> 
> Huh? What's pip3? I thought pip works on Python 2 and 3?
> https://pypi.python.org/pypi/pip/. I always install everything with the pip 
> of my system python, e.g. for Python 3.4 I would do sudo python3.4 $(which 
> pip) install somepackage. Are there any benefits of having multiple pips 
> (except in virtualenvs)?
> 
> Regards,
> Albert-Jan

Albert-Jan, on my Ubuntu system, pip and pip3 are two different utilities.  
Anything that I install with pip is linked to my Python 2 interpreter; 
likewise, pip3 links to Python 3.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: TypeError: list indices must be integers, not tuple

2015-02-10 Thread Dave Angel

On 02/10/2015 01:48 PM, Chris Angelico wrote:

On Wed, Feb 11, 2015 at 2:51 AM, Dave Angel  wrote:

You're right of course. I didn't notice the meaning of one-tuple; I took
Mark's comment as if he had said:

If you can show me a  one tuple anywhere ...


Ah, yeah. I see the ambiguity. This is the downside of being so fluent
in Typo - sometimes you run into false cognates :)

ChrisA



If somebody were still doing py-quote-of-the-week, I'd nominate that 
sentence:


This is the downside of being so fluent
in Typo - sometimes you run into false cognates :)

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


Re: Varable parsing error with python

2015-02-10 Thread Dave Angel

On 02/10/2015 01:24 PM, Denis McMahon wrote:

On Tue, 10 Feb 2015 18:39:42 +1100, Chris Angelico wrote:


On Tue, Feb 10, 2015 at 6:30 PM, OmPs  wrote:

 def _getPackgeVersion(xmlfile, p):
 package = str(p)
 if isinstance(fpmdict["application"]["package"], list):
 for i in fpmdict["application"]["package"]:
 if i["@name"] == p:
 _pkgVersion = i["version"]
 else:
 _pkgversion = fpmdict["application"]["package"]["version"]
 return _pkgVersion


One of your branches doesn't have a return statement in it, so Python
just returns None. You may want to unindent that return statement one
level.


Even if he unindents the return, it will still return None if it doesn't
find an i such that i["@name"] == p, as _pkgVersion only gets set if such
a match is found.


But if _pkgVersion weren't set, he'd be getting UnboundLocalError 
exception, not a None value.





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


Re: Taming the verbosity of ipython tracebacks

2015-02-10 Thread Mark Lawrence

On 10/02/2015 19:27, Albert-Jan Roskam wrote:



- Original Message -


From: Chris Angelico 
To:
Cc: "python-list@python.org" 
Sent: Tuesday, February 10, 2015 8:00 PM
Subject: Re: Taming the verbosity of ipython tracebacks

On Wed, Feb 11, 2015 at 5:53 AM, John Ladasky
 wrote:

  I'm running Python 3.4.0, and ipython3 1.2.1, on Ubuntu Linux 14.04

64-bit.




That's  nice recent Python, but I just tried installing ipython using
pip3, and got version 2.4.1, and was unable to reproduce your
scenario. Is it possible you're having problems due to the version
mismatch? Can you upgrade your ipython?



Huh? What's pip3? I thought pip works on Python 2 and 3?
https://pypi.python.org/pypi/pip/. I always install everything with the pip of 
my system python, e.g. for Python 3.4 I would do sudo python3.4 $(which pip) 
install somepackage. Are there any benefits of having multiple pips (except in 
virtualenvs)?

Regards,
Albert-Jan



On Windows under C:\Python34\Scripts I have pip.exe, pip3.exe and 
pip3.4.exe.  I believe that they are identical.


--
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


Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Skip Montanaro
I know this is way off-topic for this group, but I figured if anyone
in the online virtual communities I participate in would know the
answer, the Pythonistas would... Google has so far not been my friend
in this realm.

One of the things I really like about my Skype keyboard (and likely
other "soft" keyboards on Android) is that when you hold down a "key"
for a brief moment, a little mini keyboard pops up, from which you can
easily choose various accented variants and other symbols. For
instance, If I press and hold the "d" key, I see these choices (ignore
the capitalization of the first letter - my mistake sending a text
message to myself from my phone, and I can't seem to convert it to
lower case):   Đ|¦&dðď

While I'm a touch typist, I almost never use auto-repeat, which is the
"binding" of held keys in most environments (curse you, IBM and your
Selectric!). These days I find my self needing accented characters
much more frequently than key repeat (C-u 2 5 - suffices in Emacs to
bat out 25 hyphens). Being an American with an American keyboard, I
haven't the slightest idea how to type any accented characters or
common symbols using the many modifier keys on my keyboard, and no key
caps display what the various options are. And I'm getting kind of
tired of going to Google and searching for "degree symbol". :-/

Is there an X11 or Mac extension/program/app/magic thing which I can
install in either environment to get this kind of functionality? I'm
thinking that if you hold down a key for the auto-repeat interval,
instead of the key repeat thing making all sorts of duplicates, a
little window would pop up over/near the insertion point, which I can
navigate with the arrow keys, then hit RET to accept or ESC (or
similar) to cancel. It need not be perfect. It might (for example)
only work in certain environments (Chrome, Emacs, vim, Firefox).
Anyplace to start. It need even be written in Python (though that
would be cool.) I think that once something like this caught hold, it
would fairly quickly take over from the dark lords of auto-repeat.

Thx,

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


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Ethan Furman
On 02/10/2015 01:05 PM, Skip Montanaro wrote:

> [request for alternate function when key is held down]

Not exactly what you asked for, but here's how to combine characters in Vim:

  http://vim.wikia.com/wiki/Entering_special_characters

Hopefully somebody knows about a pop-up window type thingie [1].

--
~Ethan~

[1] Yes, that's the technical name for it ;)  okay, okay, not really.



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Laura Creighton
I'm using this:
http://michel.staelens.pagesperso-orange.fr/clavier/index_GB.htm#
to get cyrillic.  Not sure the other alternatives will get you what
you want -- my keyboard is rather well loaded with accented letters
from the get-go.

Laura

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


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Tim Chase
On 2015-02-10 15:05, Skip Montanaro wrote:
> For instance, If I press and hold the "d" key, I see these choices
> (ignore the capitalization of the first letter - my mistake sending
> a text message to myself from my phone, and I can't seem to convert
> it to lower case):   Đ|¦&dðď
> 
> I haven't the slightest idea how to type any accented characters or
> common symbols using the many modifier keys on my keyboard
> 
> Is there an X11 or Mac extension/program/app/magic thing which I can
> install in either environment to get this kind of functionality?

While it's not exactly a hold-down-get-a-menu, I opt for changing my
(otherwise-useless) caps-lock key to an X compose key:

  $ setxkbmap -option compose:caps

I can then hit caps-lock followed by what are generally intuitive
sequences.  For your first one, that would be "capital-D minus".  I'm
not sure what the other characters are supposed to be, so I'm not
sure how to find them.  But é is "compose, e, apostrophe", ñ is
"compose, n, tilde", the degree sign is "compose, o, o", the € is
"compose, E, equals", etc. There are loads of these documented in (on
my machine, where my locale is en_US.UTF-8)
/usr/share/X11/locale/en_US.UTF-8/Compose

Some of them are a little less intuitive, though the majority of the
time I can just guess them (I'd never typed "Đ" before, but guessed
and was right). Otherwise I search that above file.

This also has the advantage that it should work in every X
application, including Unicode-aware terminal applications (in
Unicode-aware terminals).  Adding some sort of press-and-hold UI
would limit it to those applications that chose to support it (or
even *could* support it).

> While I'm a touch typist, I almost never use auto-repeat, which is
> the "binding" of held keys in most environments

I agree, as vi/vim makes it easy to insert multiples of the same
character (or characters) akin to what you describe in Emacs.

-tkc



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


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Chris Angelico
On Wed, Feb 11, 2015 at 8:33 AM, Laura Creighton  wrote:
> I'm using this:
> http://michel.staelens.pagesperso-orange.fr/clavier/index_GB.htm#
> to get cyrillic.  Not sure the other alternatives will get you what
> you want -- my keyboard is rather well loaded with accented letters
> from the get-go.

That looks a lot more general than what I use:

https://github.com/Rosuav/shed/blob/master/translit.pike

The code's a bit messy, largely because the human languages involved
are complex, but broadly, here's the plan:

Mode 1: Reversible transliteration. In any of several modes (Cyrillic
(Russian, Ukrainian, and Serbian variants), Korean, Elder Futhark, and
Greek), it converts the input ASCII text into a non-ASCII script, and
back again. Normally I use that to key in text that I can't otherwise
type, but I can also copy and paste the other script and check it.
Some of them also support diacriticals, as per the other mode.

Mode 2: Latin-only mode. Fairly simple: the 'diacriticals' function
just transforms some backslash escapes into individual Unicode
characters, usually the combining ones, and then performs an NFC
normalization on the resulting string. So, for instance (using Python
string literal format; in actual usage, these would be single
backslashes):

Input: "\\!Sue\\'ltalo!"
Step 1: "\u00A1Sue\u0301ltalo!"
Step 2:"\u00A1Sue\u0301ltalo!"
Step 3: "\u00A1Su\u00E9ltalo!"
Displayed text: ¡Suéltalo!

In usage, it's pretty simple. You key in a letter, then you hit
backslash and a (usually mnemonically-appropriate) symbol, and it
combines in an appropriate diacritical mark. There are a few oddities
in the transformation table (for instance, "i\." produces a dotless i,
but "I\." produces a dotted I; and "\-" produces a combining macron,
unless it follows a D or d, in which case it produces a crossed D), so
if you want to adapt this for your own use, you may want to throw out
some of the transformations. But if you only occasionally have need of
these kinds of letters, it may be easiest to just keep this handy, key
in what you want, and then clipboard it to whatever you want to work
with.

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


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Dave Angel

On 02/10/2015 04:05 PM, Skip Montanaro wrote:

I know this is way off-topic for this group, but I figured if anyone
in the online virtual communities I participate in would know the
answer, the Pythonistas would... Google has so far not been my friend
in this realm.

One of the things I really like about my Skype keyboard (and likely
other "soft" keyboards on Android) is that when you hold down a "key"
for a brief moment, a little mini keyboard pops up, from which you can
easily choose various accented variants and other symbols. For
instance, If I press and hold the "d" key, I see these choices (ignore
the capitalization of the first letter - my mistake sending a text
message to myself from my phone, and I can't seem to convert it to
lower case):   Đ|¦&dðď

While I'm a touch typist, I almost never use auto-repeat, which is the
"binding" of held keys in most environments (curse you, IBM and your
Selectric!). These days I find my self needing accented characters
much more frequently than key repeat (C-u 2 5 - suffices in Emacs to
bat out 25 hyphens). Being an American with an American keyboard, I
haven't the slightest idea how to type any accented characters or
common symbols using the many modifier keys on my keyboard, and no key
caps display what the various options are. And I'm getting kind of
tired of going to Google and searching for "degree symbol". :-/

Is there an X11 or Mac extension/program/app/magic thing which I can
install in either environment to get this kind of functionality? I'm
thinking that if you hold down a key for the auto-repeat interval,
instead of the key repeat thing making all sorts of duplicates, a
little window would pop up over/near the insertion point, which I can
navigate with the arrow keys, then hit RET to accept or ESC (or
similar) to cancel. It need not be perfect. It might (for example)
only work in certain environments (Chrome, Emacs, vim, Firefox).
Anyplace to start. It need even be written in Python (though that
would be cool.) I think that once something like this caught hold, it
would fairly quickly take over from the dark lords of auto-repeat.

Thx,

Skip



On Ubuntu 14.04, you can get a character map from the bar at the top. 
In my case, the icon is labeled "En" standing for English.  I thought it 
was pretty dumb, till I realized if you click on it, then choose 
"Character", it gives you a selectable set of characters, which can then 
be copied to clipboard, etc.


It's a mouse thing, so it's not what you ask, but it is a start.





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


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Laura Creighton
In a message of Tue, 10 Feb 2015 15:29:00 -0600, Tim Chase writes:
>While it's not exactly a hold-down-get-a-menu, I opt for changing my
>(otherwise-useless) caps-lock key to an X compose key:
>
>  $ setxkbmap -option compose:caps
>
>I can then hit caps-lock followed by what are generally intuitive
>sequences.  For your first one, that would be "capital-D minus".  I'm
>not sure what the other characters are supposed to be, so I'm not
>sure how to find them.  But é is "compose, e, apostrophe", ñ is
>"compose, n, tilde", the degree sign is "compose, o, o", the € is
>"compose, E, equals", etc. There are loads of these documented in (on
>my machine, where my locale is en_US.UTF-8)
>/usr/share/X11/locale/en_US.UTF-8/Compose
>
>Some of them are a little less intuitive, though the majority of the
>time I can just guess them (I'd never typed "Đ" before, but guessed
>and was right). Otherwise I search that above file.
>
>This also has the advantage that it should work in every X
>application, including Unicode-aware terminal applications (in
>Unicode-aware terminals).  Adding some sort of press-and-hold UI
>would limit it to those applications that chose to support it (or
>even *could* support it).
>
>> While I'm a touch typist, I almost never use auto-repeat, which is
>> the "binding" of held keys in most environments
>
>I agree, as vi/vim makes it easy to insert multiples of the same
>character (or characters) akin to what you describe in Emacs.
>
>-tkc

Wow.  US keyboards do not come with a 'compose' key, then?  It just
never occurred to me that Skip might be missing one.

Oh, goodness gracious then, go with this solution.  Much better than
mine --though the one I pointed at is great should you suddenly need
to type something in cyrillic while at a non-cyrillic keyboard.

Laura

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


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Grant Edwards
On 2015-02-10, Laura Creighton  wrote:

> Wow.  US keyboards do not come with a 'compose' key, then?

Nope.

> It just never occurred to me that Skip might be missing one.

I always configure one of my "extra" keys (windows-key, menu-key,
right-ctrl, etc.) as compose. But, I use it infrequenty enough that
it's probably rather amusing watching me try to find it via trial and
error.

-- 
Grant Edwards   grant.b.edwardsYow! I own seven-eighths of
  at   all the artists in downtown
  gmail.comBurbank!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tabs and the Python3 console

2015-02-10 Thread Steven D'Aprano
Laura Creighton wrote:

> I have the debian version of python3 installed here.
> 
> Python 3.4.2 (default, Nov 13 2014, 07:01:52)
> [GCC 4.9.2] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 
> 
> But I cannot seem to type a tab here:
> 
 def fn(**kw):
> ...
> 
> (I type a tab here, and get a beep.  If I type a tab again I get:
> 
> Display all 178 possibilities? (y or n)
> ArithmeticError(chr(
> AssertionError( class
> AttributeError( classmethod(
> BaseException(  compile(
> BlockingIOError(complex(
> BrokenPipeError(continue
> 
> ...
> 
> Do I need a python3 enabled with readline support, or something?


The good news is that after many, many years of supporting tab completion,
Python 3.4 finally enables it by default.

The bad news is that its handling of the tab key is fundamentally broken.

There are a couple of tasks on the bug tracker dealing with this. I'm not
able to search for them right now, but you may be able to find them: there
is a task to enable tab completion by default, which I expect is closed by
now, and (if memory serves me correctly) a second, open, task to fix the
tab-for-indentation issue.

As an alternative, you could try my tab completion and history module:

http://code.google.com/p/tabhistory/

I've been using it on Linux for about three or four years, and although I
don't promise it is bug-free, it shouldn't blow up your computer :-)

You can read an announcement here:

http://code.activestate.com/lists/python-list/672898/

Feedback from Mac and Windows users is very, very welcome.



-- 
Steven

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


function inclusion problem

2015-02-10 Thread vlyamtsev
I defined function Fatalln in "mydef.py" and it works fine if i call it from 
"mydef.py", but when i try to call it from "test.py" in the same folder:
import mydef
...
Fatalln "my test"
i have NameError: name 'Fatalln' is not defined
I also tried include('mydef.py') with the same result...
What is the right syntax?
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: function inclusion problem

2015-02-10 Thread sohcahtoa82
On Tuesday, February 10, 2015 at 3:38:12 PM UTC-8, vlya...@gmail.com wrote:
> I defined function Fatalln in "mydef.py" and it works fine if i call it from 
> "mydef.py", but when i try to call it from "test.py" in the same folder:
> import mydef
> ...
> Fatalln "my test"
> i have NameError: name 'Fatalln' is not defined
> I also tried include('mydef.py') with the same result...
> What is the right syntax?
> Thanks

It would help us help you a lot of you copy/paste your code from both mydef.py 
and test.py so we can see exactly what you're doing.

Don't re-type what you entered, because people (Especially new programmers) are 
prone to either making typos or leaving out certain things because they don't 
think they're important.  Copy/Paste the code from the two files and then 
copy/paste the error you're getting.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Varable parsing error with python

2015-02-10 Thread Steven D'Aprano
OmPs wrote:

> On 10 Feb 2015 13:59, "OmPs"  wrote:

>> Tried that as well getting the same error.
> 
> I feel its something to do with variable substitution.

Python doesn't do variable substitution. At least not the way I think of it.
What do you mean by "variable substitution"?

Instead of "feeling" what the problem is, let's do some old-fashioned
debugging. Start by reading through the code, and in your head (or on
paper) trace through the possible lines that may be reached. The
_getPackgeVersion function has only 11 lines, it isn't hard. Here is your
function again:


def _getPackgeVersion(xmlfile, p):
package = str(p)
if isinstance(fpmdict["application"]["package"], list):
for i in fpmdict["application"]["package"]:
if i["@name"] == p:
_pkgVersion = i["version"]
else:
_pkgversion = fpmdict["application"]["package"]["version"]
return _pkgVersion


I can immediately see four problems:

(1) One branch of the "if isinstance" fails to return. So if the function
takes that branch, it will finish the loop, then exit the if...else clause,
then hit the end of the function and return None.

(2) Sometimes that branch may fail to set the _pkgVersion variable at all,
if none of the "@name" keys equal p.

(3) The other branch fails to set the _pkgVersion variable. Python is
case-sensitive, so _pkgversion and _pkgVersion are different variables.

(4) Your package variable is never used.

I don't know how to fix problem #2 since I don't know what behaviour would
be useful to you. So I'll just leave that for you. I can fix problems #1 #3
and #4:

def _getPackgeVersion(xmlfile, p):
if isinstance(fpmdict["application"]["package"], list):
for i in fpmdict["application"]["package"]:
if i["@name"] == p:
_pkgVersion = i["version"]
else:
_pkgVersion = fpmdict["application"]["package"]["version"]
return _pkgVersion


Now we can see that if _getPackgeVersion still returns None, the only way it
can do so is if the "version" key is set to have None as a value.

Are you sure that there is a "version" key set?



I can see another problem, earlier in your code:


for i in doc.get("application").get("instance", None):
...


That does not do what you expect. If there is no "instance" key, the second
get will return None, which is not iterable:

py> for i in None:
... pass
...
Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'NoneType' object is not iterable




-- 
Steven

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


Re: function inclusion problem

2015-02-10 Thread Steven D'Aprano
vlyamt...@gmail.com wrote:

> I defined function Fatalln in "mydef.py" and it works fine if i call it
> from "mydef.py", but when i try to call it from "test.py" in the same
> folder: import mydef ...
> Fatalln "my test"
> i have NameError: name 'Fatalln' is not defined
> I also tried include('mydef.py') with the same result...
> What is the right syntax?
> Thanks


Preferred:

import mydef
mydef.Fatalln("my test")



Also acceptable:


from mydef import Fatalln
Fatalln("my test")





-- 
Steven

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


Re: function inclusion problem

2015-02-10 Thread Michael Torrie
On 02/10/2015 04:38 PM, vlyamt...@gmail.com wrote:
> I defined function Fatalln in "mydef.py" and it works fine if i call it from 
> "mydef.py", but when i try to call it from "test.py" in the same folder:
> import mydef
> ...
> Fatalln "my test"
> i have NameError: name 'Fatalln' is not defined
> I also tried include('mydef.py') with the same result...
> What is the right syntax?

Almost.

Try this:

mydef.Fatalln()

Unless you import the symbols from your mydef module into your program
they have to referenced by the module name.  This is a good thing and it
helps keep your code separated and clean.  It is possible to import
individual symbols from a module like this:

from mydef import Fatalln

Avoid the temptation to import *all* symbols from a module into the
current program's namespace.  Better to type out the extra bit.
Alternatively you can alias imports like this

import somemodule.submodule as foo

Frequently this idiom is used when working with numpy to save a bit of
time, while preserving the separate namespaces.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: function inclusion problem

2015-02-10 Thread Ian Kelly
On Tue, Feb 10, 2015 at 4:38 PM,   wrote:
> I defined function Fatalln in "mydef.py" and it works fine if i call it from 
> "mydef.py", but when i try to call it from "test.py" in the same folder:
> import mydef
> ...
> Fatalln "my test"
> i have NameError: name 'Fatalln' is not defined
> I also tried include('mydef.py') with the same result...
> What is the right syntax?

import mydef
mydef.Fatalin("my test")

or

from mydef import Fatalin
Fatalin("my test")
-- 
https://mail.python.org/mailman/listinfo/python-list


line_profiler: what am I doing wrong?

2015-02-10 Thread Neal Becker
I inserted 
@profile
def run(...)

into a module-level global function called 'run'.  Something is very wrong here.
1. profile results were written before anything even ran
2. profile is not defined?

 kernprof -l ./test_unframed.py --lots --of --args ...

Wrote profile results to test_unframed.py.lprof
Traceback (most recent call last):
  File "/home/nbecker/.local/bin/kernprof", line 9, in 
load_entry_point('line-profiler==1.0', 'console_scripts', 'kernprof')()
  File "/home/nbecker/.local/lib/python2.7/site-packages/kernprof.py", line 
221, 
in main
execfile(script_file, ns, ns)
  File "./test_unframed.py", line 721, in 
@profile
NameError: name 'profile' is not defined



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


Re: function inclusion problem

2015-02-10 Thread sohcahtoa82
On Tuesday, February 10, 2015 at 3:38:12 PM UTC-8, vlya...@gmail.com wrote:
> I defined function Fatalln in "mydef.py" and it works fine if i call it from 
> "mydef.py", but when i try to call it from "test.py" in the same folder:
> import mydef
> ...
> Fatalln "my test"
> i have NameError: name 'Fatalln' is not defined
> I also tried include('mydef.py') with the same result...
> What is the right syntax?
> Thanks

If you only do `import mydef`, then it creates a module object called `mydef` 
which contains all the global members in mydef.py.  When you want to call a 
function from that module, you need to specify that you're calling a function 
from that module by putting the module name followed by a period, then the 
function.  For example:

mydef.Fatalln("my test")

If you wanted to be able to call Fatalln without using the module name, you 
could import just the Fatalln function:

from mydef import Fatalln
Fatalln("my test")

If you had a lot of functions in mydef.py and wanted to be able to access them 
all without that pesky module name, you could also do:

from mydef import *

However, this can often be considered a bad practice as you're polluting your 
global name space, though can be acceptable in specific scenarios.

For more information, check https://docs.python.org/3/tutorial/modules.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: function inclusion problem

2015-02-10 Thread Laura Creighton
In a message of Tue, 10 Feb 2015 15:38:02 -0800, vlyamt...@gmail.com writes:
>I defined function Fatalln in "mydef.py" and it works fine if i call it from 
>"mydef.py", but when i try to call it from "test.py" in the same folder:
>import mydef
>...
>Fatalln "my test"
>i have NameError: name 'Fatalln' is not defined
>I also tried include('mydef.py') with the same result...
>What is the right syntax?
>Thanks
>-- 
>https://mail.python.org/mailman/listinfo/python-list

from mydef import Fatalln

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


Re: line_profiler: what am I doing wrong?

2015-02-10 Thread Ethan Furman
On 02/10/2015 04:06 PM, Neal Becker wrote:
> I inserted 
> @profile
> def run(...)
> 
> into a module-level global function called 'run'.  Something is very wrong 
> here.
> 1. profile results were written before anything even ran
> 2. profile is not defined?
> 
>  kernprof -l ./test_unframed.py --lots --of --args ...
> 
> Wrote profile results to test_unframed.py.lprof
> Traceback (most recent call last):
>   File "/home/nbecker/.local/bin/kernprof", line 9, in 
> load_entry_point('line-profiler==1.0', 'console_scripts', 'kernprof')()
>   File "/home/nbecker/.local/lib/python2.7/site-packages/kernprof.py", line 
> 221, 
> in main
> execfile(script_file, ns, ns)
>   File "./test_unframed.py", line 721, in 
> @profile
> NameError: name 'profile' is not defined

I'm going to guess that writing the profile results is in a try/finally -- so 
first you see the results being written,
then the exception that triggered.

--
~Ethan~



signature.asc
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Peter Pearson
On Tue, 10 Feb 2015 15:05:47 -0600, Skip Montanaro wrote:
[snip]
> One of the things I really like about my Skype keyboard (and likely
> other "soft" keyboards on Android) is that when you hold down a "key"
> for a brief moment, a little mini keyboard pops up, from which you can
> easily choose various accented variants and other symbols. 
[snip]
> (C-u 2 5 - suffices in Emacs to
> bat out 25 hyphens). Being an American with an American keyboard, I
> haven't the slightest idea how to type any accented characters or
> common symbols using the many modifier keys on my keyboard, and no key
> caps display what the various options are. And I'm getting kind of
> tired of going to Google and searching for "degree symbol". :-/
[snip]

Again, not what you asked for, but since you use Emacs . . . Are you
aware of Emacs's control-backslash ("toggle-input-method") command?
If I'm going to be writing French or Spanish, I hit control-backslash
and type "latin-prefix".  Then, until I hit control-backslash again,
"'e" becomes é, "~n" becomes ñ, '"o' becomes ö, and many other
not-too-hard-to-remember things.  Many other "input methods" are
available for other languages.

It's actually reminiscent of how Spanish typewriters used to work,
with an accent key that didn't advance the carriage.

-- 
To email me, substitute nowhere->runbox, invalid->com.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: function inclusion problem

2015-02-10 Thread Laura Creighton
In a message of Wed, 11 Feb 2015 01:06:00 +0100, Laura Creighton writes:
>In a message of Tue, 10 Feb 2015 15:38:02 -0800, vlyamt...@gmail.com writes:
>>I defined function Fatalln in "mydef.py" and it works fine if i call it from 
>>"mydef.py", but when i try to call it from "test.py" in the same folder:
>>import mydef
>>...
>>Fatalln "my test"
>>i have NameError: name 'Fatalln' is not defined
>>I also tried include('mydef.py') with the same result...
>>What is the right syntax?
>>Thanks
>>-- 
>>https://mail.python.org/mailman/listinfo/python-list
>
>from mydef import Fatalln
>

Also, please be warned.  If you use a unix system, or a linux
system.  There are lots of problems you can get into if you
expect something named 'test' to run your code.  Because they
already have one in their shell, and that one wins, and so ...
well, test.py is safe.  But if you rename it as a script and call
it the binary file test ...

Bad and unexpected things happen.

Name it 'testme' or something like that.  Never have that problem again.
:)

Been there, done that!
Laura

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


Re: line_profiler: what am I doing wrong?

2015-02-10 Thread Neal Becker
Ethan Furman wrote:

> On 02/10/2015 04:06 PM, Neal Becker wrote:
>> I inserted
>> @profile
>> def run(...)
>> 
>> into a module-level global function called 'run'.  Something is very wrong
>> here. 1. profile results were written before anything even ran
>> 2. profile is not defined?
>> 
>>  kernprof -l ./test_unframed.py --lots --of --args ...
>> 
>> Wrote profile results to test_unframed.py.lprof
>> Traceback (most recent call last):
>>   File "/home/nbecker/.local/bin/kernprof", line 9, in 
>> load_entry_point('line-profiler==1.0', 'console_scripts', 'kernprof')()
>>   File "/home/nbecker/.local/lib/python2.7/site-packages/kernprof.py", line
>>   221,
>> in main
>> execfile(script_file, ns, ns)
>>   File "./test_unframed.py", line 721, in 
>> @profile
>> NameError: name 'profile' is not defined
> 
> I'm going to guess that writing the profile results is in a try/finally -- so
> first you see the results being written, then the exception that triggered.
> 
> --
> ~Ethan~

I believe you are suggesting the apparent out-of-order is due to try/finally, 
but kernprof is supposed to inject 'profile' into the global namespace, so 
@profile should be defined - I don't know why it isn't working.

-- 
-- Those who don't understand recursion are doomed to repeat it

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


Re: line_profiler: what am I doing wrong?

2015-02-10 Thread Steven D'Aprano
Neal Becker wrote:

> I inserted
> @profile
> def run(...)
> 
> into a module-level global function called 'run'.  Something is very wrong
> here. 1. profile results were written before anything even ran
> 2. profile is not defined?

Well, is it defined? Where does it come from?

If you defined it yourself, it needs to be defined before you can use it.
This won't work:


@profile
def run(...)

def profile(func): ...


Swap the order of profile and run and it should work. (Give or take any
additional bugs in your code.)


If you've imported it from an external module, how did you import it?


import some_module

@some_module.profile
def run(...)


should work. So will this:


from some_module import profile

@profile
def run(...)


But this won't:


import some_module

@profile
def run(...)


and will fail with NameError, exactly as you are experiencing.




-- 
Steven

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


Re: line_profiler: what am I doing wrong?

2015-02-10 Thread Neal Becker
Steven D'Aprano wrote:

> Neal Becker wrote:
> 
>> I inserted
>> @profile
>> def run(...)
>> 
>> into a module-level global function called 'run'.  Something is very wrong
>> here. 1. profile results were written before anything even ran
>> 2. profile is not defined?
> 
> Well, is it defined? Where does it come from?
> 
> If you defined it yourself, it needs to be defined before you can use it.
> This won't work:
> 
> 
> @profile
> def run(...)
> 
> def profile(func): ...
> 
> 
> Swap the order of profile and run and it should work. (Give or take any
> additional bugs in your code.)
> 
> 
> If you've imported it from an external module, how did you import it?
> 
> 
> import some_module
> 
> @some_module.profile
> def run(...)
> 
> 
> should work. So will this:
> 
> 
> from some_module import profile
> 
> @profile
> def run(...)
> 
> 
> But this won't:
> 
> 
> import some_module
> 
> @profile
> def run(...)
> 
> 
> and will fail with NameError, exactly as you are experiencing.
> 
> 
> 
> 

To quote from https://pypi.python.org/pypi/line_profiler/

$ kernprof -l script_to_profile.py
kernprof will create an instance of LineProfiler and insert it into the 
__builtins__ namespace with the name profile. It has been written to be used as 
a decorator, so in your script, you decorate the functions you want to profile 
with @profile.

@profile
def slow_function(a, b, c):
...

I've used it before (maybe 1 year ago), don't know why it isn't working now.
-- 
-- Those who don't understand recursion are doomed to repeat it

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


Re: line_profiler: what am I doing wrong?

2015-02-10 Thread Steven D'Aprano
Neal Becker wrote:


> To quote from https://pypi.python.org/pypi/line_profiler/
> 
> $ kernprof -l script_to_profile.py
> kernprof will create an instance of LineProfiler and insert it into the
> __builtins__ namespace with the name profile. 

Ewww What a Ruby-esque interface, that makes me sad :-( And what if you
have your own profile global name?

And *wrong* too. `__builtins__` is a private CPython implementation detail.
The way to monkey-patch the built-ins in Python 2 is to inject the object
into `__builtin__` (no s), or `builtins` in Python 3. Seeing as
line_profiler is written in C, perhaps the author (Robert Kern) doesn't
care about supporting Jython or IronPython, but there may be Python
implementations (PyPy perhaps?) which can run C code but don't have
__builtins__.


In any case, it sounds like it isn't working. Try creating this simple file:

# demo.py
print(profile)  # Does profile actually get injected into the builtins?


then running it:

kernprof -l demo.py


If that still gives a NameError, you have a bug in kernprof. Or possibly you
have broken it -- perhaps you are accidentally shadowing one of its modules
with a module of your own?



-- 
Steven

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


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Rustom Mody
On Wednesday, February 11, 2015 at 2:36:23 AM UTC+5:30, Skip Montanaro wrote:
> I know this is way off-topic for this group, but I figured if anyone
> in the online virtual communities I participate in would know the
> answer, the Pythonistas would... Google has so far not been my friend
> in this realm.
> 
> One of the things I really like about my Skype keyboard (and likely
> other "soft" keyboards on Android) is that when you hold down a "key"
> for a brief moment, a little mini keyboard pops up, from which you can
> easily choose various accented variants and other symbols. For
> instance, If I press and hold the "d" key, I see these choices (ignore
> the capitalization of the first letter - my mistake sending a text
> message to myself from my phone, and I can't seem to convert it to
> lower case):   Đ|¦&dðď
> 
> While I'm a touch typist, I almost never use auto-repeat, which is the
> "binding" of held keys in most environments (curse you, IBM and your
> Selectric!). These days I find my self needing accented characters
> much more frequently than key repeat (C-u 2 5 - suffices in Emacs to
> bat out 25 hyphens). Being an American with an American keyboard, I
> haven't the slightest idea how to type any accented characters or
> common symbols using the many modifier keys on my keyboard, and no key
> caps display what the various options are. And I'm getting kind of
> tired of going to Google and searching for "degree symbol". :-/
> 
> Is there an X11 or Mac extension/program/app/magic thing which I can
> install in either environment to get this kind of functionality? I'm
> thinking that if you hold down a key for the auto-repeat interval,
> instead of the key repeat thing making all sorts of duplicates, a
> little window would pop up over/near the insertion point, which I can
> navigate with the arrow keys, then hit RET to accept or ESC (or
> similar) to cancel. It need not be perfect. It might (for example)
> only work in certain environments (Chrome, Emacs, vim, Firefox).
> Anyplace to start. It need even be written in Python (though that
> would be cool.) I think that once something like this caught hold, it
> would fairly quickly take over from the dark lords of auto-repeat.
> 
> Thx,
> 
> Skip

Nice question – I too await an answer.
Was amused when gmail offered facilities to type devanagari.
After using for a while found it way too clever for my taste and found emacs'
itrans input method better — emacs is slightly dumb, gmail is way too clever.

Here is (Yuri Khan's answers) about changing Xorg keyboard maps:

https://groups.google.com/forum/#!searchin/gnu.emacs.help/Yuri$20X$20Rusi/gnu.emacs.help/yesOU0m0vIE/CEvhlRZZY6kJ

Here is a rather neat general collection of compose settings:
https://github.com/rrthomas/pointless-xcompose¹

> And I'm getting kind of tired of going to Google and searching for "degree 
> symbol". :-/


Yeah…  More to add to your question than to answer: my recent blog post:
blog.languager.org/2015/01/unicode-and-universe.html

Towards the end there are multi-levels of input methods.
It would be good to work out in greater detail the intermediate levels between
"google for degree symbol" and "type degree symbol on keyboard"

¹ He does not explain how to setup compose though the whole point of 
pointless(!) is to use it.

$ setxkbmap -option compose:menu  # set compose to menu (Windows-menu)
$ setxkbmap -option compose:rwin  # to rwin
$ setxkbmap -option compose:ralt  # to ralt (the usual AltGr)
$ setxkbmap -query# examine current settings
$ setxkbmap -option   # No option -- turns off all options

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


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Ned Deily
In article 
,
 Skip Montanaro  wrote:

> I know this is way off-topic for this group, but I figured if anyone
> in the online virtual communities I participate in would know the
> answer, the Pythonistas would... Google has so far not been my friend
> in this realm.
> 
> One of the things I really like about my Skype keyboard (and likely
> other "soft" keyboards on Android) is that when you hold down a "key"
> for a brief moment, a little mini keyboard pops up, from which you can
> easily choose various accented variants and other symbols. For
> instance, If I press and hold the "d" key, I see these choices (ignore
> the capitalization of the first letter - my mistake sending a text
> message to myself from my phone, and I can't seem to convert it to
> lower case):   –|õ&d©£ď
> 
> While I'm a touch typist, I almost never use auto-repeat, which is the
> "binding" of held keys in most environments (curse you, IBM and your
> Selectric!). These days I find my self needing accented characters
> much more frequently than key repeat (C-u 2 5 - suffices in Emacs to
> bat out 25 hyphens). Being an American with an American keyboard, I
> haven't the slightest idea how to type any accented characters or
> common symbols using the many modifier keys on my keyboard, and no key
> caps display what the various options are. And I'm getting kind of
> tired of going to Google and searching for "degree symbol". :-/
> 
> Is there an X11 or Mac extension/program/app/magic thing which I can
> install in either environment to get this kind of functionality? I'm
> thinking that if you hold down a key for the auto-repeat interval,
> instead of the key repeat thing making all sorts of duplicates, a
> little window would pop up over/near the insertion point, which I can
> navigate with the arrow keys, then hit RET to accept or ESC (or
> similar) to cancel. It need not be perfect. It might (for example)
> only work in certain environments (Chrome, Emacs, vim, Firefox).
> Anyplace to start. It need even be written in Python (though that
> would be cool.) I think that once something like this caught hold, it
> would fairly quickly take over from the dark lords of auto-repeat.

On OS X, the system provides both a "Character Viewer" (which allows the 
selection of any Unicode character and a "Keyboard Viewer" (which allows 
you to see the keyboard key mappings as keys and modifiers are pressed).  
Both can be enabled from System Preferences (System Preferences -> 
Keyboard -> Keyboard on current 10.10 systems).  As of OS X 10.7 (I 
believe), there are also now popup menus that appear when various keys 
are held down that show accented variants of the character (this is 
similar to what iOS on the iPhone and iPad provide).   Unfortunately, 
this doesn't work with some applicatons that do not use the full 
built-in text system; the Tk implementations on OS X are such 
applications so the popups don't work with Tkinter apps like IDLE.  Nor 
does it work with X11 apps.

-- 
 Ned Deily,
 n...@acm.org

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


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Steven D'Aprano
Rustom Mody wrote:

> $ setxkbmap -query# examine current settings

Alas, that does not appear to work in Debian squeeze:

steve@runes:~$ setxkbmap -query
Error!   Option "-query" not recognized

Or Centos.

What are you using?


-- 
Steve

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


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Chris Angelico
On Wed, Feb 11, 2015 at 3:10 PM, Steven D'Aprano
 wrote:
> Rustom Mody wrote:
>
>> $ setxkbmap -query# examine current settings
>
> Alas, that does not appear to work in Debian squeeze:
>
> steve@runes:~$ setxkbmap -query
> Error!   Option "-query" not recognized
>
> Or Centos.
>
> What are you using?

Works for me on Debian Wheezy. Either it's a version difference (I
don't have any Squeeze machines any more, we're all on Wheezy or
Jessie), or there's some additional package that I have installed
here.

Mind you, I have no idea what I'm looking at.

rosuav@sikorsky:~$ setxkbmap -query
rules:  evdev
model:  pc105
layout: us

I guess that means I have a 105-key PC keyboard in en_US layout, but
what 'evdev' means I would have to go manpage digging to find out.

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


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Rustom Mody
On Wednesday, February 11, 2015 at 9:40:50 AM UTC+5:30, Steven D'Aprano wrote:
> Rustom Mody wrote:
> 
> > $ setxkbmap -query# examine current settings
> 
> Alas, that does not appear to work in Debian squeeze:
> 
> steve@runes:~$ setxkbmap -query
> Error!   Option "-query" not recognized
> 
> Or Centos.
> 
> What are you using?

$ dpkg -S setxkbmap
x11-xkb-utils: /usr/bin/setxkbmap
[and some doc stuff]

So...

$ aptitude show x11-xkb-utils|grep Version
Version: 7.7+1

[which is probably what you need to know]

To answer more literally:
Just now this is a debian testing running xfce
I believe this works also on ubuntu 14.10
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Chris Angelico
On Wed, Feb 11, 2015 at 3:23 PM, Rustom Mody  wrote:
> $ aptitude show x11-xkb-utils|grep Version
> Version: 7.7+1
>
> [which is probably what you need to know]

Tip: Getting version info can be done less spammily with apt-cache policy.

rosuav@sikorsky:~$ apt-cache policy x11-xkb-utils
x11-xkb-utils:
  Installed: 7.7~1
  Candidate: 7.7~1
  Version table:
 *** 7.7~1 0
500 http://ftp.au.debian.org/debian/ wheezy/main amd64 Packages
100 /var/lib/dpkg/status

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


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Rustom Mody
On Wednesday, February 11, 2015 at 9:50:15 AM UTC+5:30, Chris Angelico wrote:
> On Wed, Feb 11, 2015 at 3:10 PM, Steven D'Aprano wrote:
> > Rustom Mody wrote:
> >
> >> $ setxkbmap -query# examine current settings
> >
> > Alas, that does not appear to work in Debian squeeze:
> >
> > steve@runes:~$ setxkbmap -query
> > Error!   Option "-query" not recognized
> >
> > Or Centos.
> >
> > What are you using?
> 
> Works for me on Debian Wheezy. Either it's a version difference (I
> don't have any Squeeze machines any more, we're all on Wheezy or
> Jessie), or there's some additional package that I have installed
> here.

This xkb stuff seems to be (surprisingly) in development -- if only the
docs kept pace!

eg My impression is that ubuntus prior to 11.x did not have apl keyboard
Somewhere around 11/12 or after this works

setxkbmap -layout "us,apl" -option "grp:switch"
after that
abcdefghijklmnopqrstuvwxyz
produces
⍺⊥∩⌊∊_∇∆⍳∘'⎕|⊤○*?⍴⌈~↓∪⍵⊃↑⊂
when chorded with R-Alt

If that looks gibberish see that keyboard:
http://xahlee.info/kbd/creating_apl_keyboard_layout.html

Replace the 'apl' in the setxkb by 'gr'
and you will see more familiar territory
αβψδεφγηιξκλμνοπ;ρστθωςχυζ
ΑΒΨΔΕΦΓΗΙΞΚΛΜΝΟΠ:ΡΣΤΘΣΧΥΖ

Of course for it to work the alternate should be working.
eg right now on my box:

$ setxkbmap -query
rules:  evdev
model:  pc104
layout: us,gr
options:grp:switch,compose:menu

which shows gr as alternate
and the grp:switch (whatever that means)

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


GDAL installation

2015-02-10 Thread Leo Kris Palao
Hi Python Users,

I currently installed the Python 2.7.9 and installed the GDAL package.
First, I tried to install GDAL using PIP but it throws an error - I cannot
remember the exact error message. So, I install it using easy_install
command. But when I import the package I am getting this message, which I
really don't understand.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\lpalao>python
> Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)]
> on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import gdal
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "C:\Python27\Python2.7.9\lib\site-packages\gdal.py", line 2, in
> 
> from osgeo.gdal import deprecation_warn
>   File "C:\Python27\Python2.7.9\lib\site-packages\osgeo\__init__.py", line
> 21, in 
> _gdal = swig_import_helper()
>   File "C:\Python27\Python2.7.9\lib\site-packages\osgeo\__init__.py", line
> 17, in swig_import_helper
> _mod = imp.load_module('_gdal', fp, pathname, description)
> ImportError: DLL load failed: The specified module could not be found.
> >>>


Thanks in advance,
-Leo
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Kushal Kumaran
Skip Montanaro  writes:

> I know this is way off-topic for this group, but I figured if anyone
> in the online virtual communities I participate in would know the
> answer, the Pythonistas would... Google has so far not been my friend
> in this realm.
>
> One of the things I really like about my Skype keyboard (and likely
> other "soft" keyboards on Android) is that when you hold down a "key"
> for a brief moment, a little mini keyboard pops up, from which you can
> easily choose various accented variants and other symbols. For
> instance, If I press and hold the "d" key, I see these choices (ignore
> the capitalization of the first letter - my mistake sending a text
> message to myself from my phone, and I can't seem to convert it to
> lower case):   Đ|¦&dðď
>
> While I'm a touch typist, I almost never use auto-repeat, which is the
> "binding" of held keys in most environments (curse you, IBM and your
> Selectric!). These days I find my self needing accented characters
> much more frequently than key repeat (C-u 2 5 - suffices in Emacs to
> bat out 25 hyphens). Being an American with an American keyboard, I
> haven't the slightest idea how to type any accented characters or
> common symbols using the many modifier keys on my keyboard, and no key
> caps display what the various options are. And I'm getting kind of
> tired of going to Google and searching for "degree symbol". :-/
>
> Is there an X11 or Mac extension/program/app/magic thing which I can
> install in either environment to get this kind of functionality? I'm
> thinking that if you hold down a key for the auto-repeat interval,
> instead of the key repeat thing making all sorts of duplicates, a
> little window would pop up over/near the insertion point, which I can
> navigate with the arrow keys, then hit RET to accept or ESC (or
> similar) to cancel. It need not be perfect. It might (for example)
> only work in certain environments (Chrome, Emacs, vim, Firefox).
> Anyplace to start. It need even be written in Python (though that
> would be cool.) I think that once something like this caught hold, it
> would fairly quickly take over from the dark lords of auto-repeat.
>

For very, very occasional use in emacs, there's C-x 8 RET (insert-char).

From it's documentation:

Interactively, prompt for CHARACTER.  You can specify CHARACTER in
one of these ways:

- As its Unicode character name, e.g. "LATIN SMALL LETTER A".
  Completion is available; if you type a substring of the name
  preceded by an asterisk `*', Emacs shows all names which include
  that substring, not necessarily at the beginning of the name.

- As a hexadecimal code point, e.g. 263A.  Note that code points in
  Emacs are equivalent to Unicode up to 10 (which is the limit
  of the Unicode code space).

- As a code point with a radix specified with #, e.g. #o21430
  (octal), #x2318 (hex), or #10r8984 (decimal).

For your "degree symbol" example, I did C-x 8 RET, then typed in
*degree, and emacs found some matches, resulting in this: °

-- 
regards,
kushal
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Rustom Mody
On Wednesday, February 11, 2015 at 11:55:19 AM UTC+5:30, Kushal Kumaran wrote:
> Skip Montanaro  writes:
> 
> > I know this is way off-topic for this group, but I figured if anyone
> > in the online virtual communities I participate in would know the
> > answer, the Pythonistas would... Google has so far not been my friend
> > in this realm.
> >
> > One of the things I really like about my Skype keyboard (and likely
> > other "soft" keyboards on Android) is that when you hold down a "key"
> > for a brief moment, a little mini keyboard pops up, from which you can
> > easily choose various accented variants and other symbols. For
> > instance, If I press and hold the "d" key, I see these choices (ignore
> > the capitalization of the first letter - my mistake sending a text
> > message to myself from my phone, and I can't seem to convert it to
> > lower case):   Đ|¦&dðď
> >
> > While I'm a touch typist, I almost never use auto-repeat, which is the
> > "binding" of held keys in most environments (curse you, IBM and your
> > Selectric!). These days I find my self needing accented characters
> > much more frequently than key repeat (C-u 2 5 - suffices in Emacs to
> > bat out 25 hyphens). Being an American with an American keyboard, I
> > haven't the slightest idea how to type any accented characters or
> > common symbols using the many modifier keys on my keyboard, and no key
> > caps display what the various options are. And I'm getting kind of
> > tired of going to Google and searching for "degree symbol". :-/
> >
> > Is there an X11 or Mac extension/program/app/magic thing which I can
> > install in either environment to get this kind of functionality? I'm
> > thinking that if you hold down a key for the auto-repeat interval,
> > instead of the key repeat thing making all sorts of duplicates, a
> > little window would pop up over/near the insertion point, which I can
> > navigate with the arrow keys, then hit RET to accept or ESC (or
> > similar) to cancel. It need not be perfect. It might (for example)
> > only work in certain environments (Chrome, Emacs, vim, Firefox).
> > Anyplace to start. It need even be written in Python (though that
> > would be cool.) I think that once something like this caught hold, it
> > would fairly quickly take over from the dark lords of auto-repeat.
> >
> 
> For very, very occasional use in emacs, there's C-x 8 RET (insert-char).

For slightly more frequent use (emacs-users)

1. Find a symbol such as ° maybe using google and paste it into emacs
   Does it exist in tex input method? To find out
2. Turn on tex input method (in some buffer) ie
   C-x RET C-\ and give tex (or whatever
3. C-u C-x = will tell info about the char. In particular it says:
   To input type \degree in tex input method

I guess for diacritical marks one could use one of the latin-n input methods

The above applied to á and latin-2-postfix says that á can be input with
a'

M-x describe-input-method will tell you others like

 +-+--
  acute  |'| a' -> á
  ogonek |,| a, -> ą
  diaeresis  |"| a" -> ä
  circumflex |^| a^ -> â
  breve  |~| a~ -> ă
  cedilla|,| c, -> ç
  caron  |~| c~ -> č
  dbl. acute |:| o: -> ő
  ring   |.| u. -> ů
  dot|.| z. -> ż
  stroke |/| d/ -> đ
  others |/| s/ -> ß
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Wildly OT: pop-up virtual keyboard for Mac or Linux?

2015-02-10 Thread Marko Rauhamaa
Kushal Kumaran :

> For very, very occasional use in emacs, there's C-x 8 RET (insert-char).

Emacs to the rescue, as usual.

I use emacs for all of my typing needs. If I stray on a Web form, I end
up cussing at the browser whenever I instinctively hit a C-n, C-a or C-s
(or, yesterday, C-w).

As for typing "special" characters, I have written a .Xmodmap file that
rebinds my keyboard for various languages I use regularly. Then, I have
this text file that contains specimens for many other useful characters.


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