Re: [Tutor] appending/updating values dict key value pairs

2013-06-23 Thread Sivaram Neelakantan
On Sun, Jun 23 2013,Alan Gauld wrote:


[snipped 21 lines]

> But we normally call methods via the object instance rather than the
> class so simplifying this further we get:
>
> b['a'].append('c')
>

Thanks for the detailed explanation.

I've sort of used a dict of this sort {'a': [1,2,'fff'] } in my
programs and I've noticed that I've got to unpack the list with
hardcoded list positions when I retrieve the value of a key.

I think I'd be better off, if I did something of

{'a' : ['foo': 1, 'bar':2, 'offset': 'fff'] }

wouldn't that be better from a maintainability POV?  Are there any
examples of such?  Or is there a 'struct' option for python?  I don't
want to use OO methods for now.


 sivaram
 -- 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] appending/updating values dict key value pairs

2013-06-23 Thread Steven D'Aprano

On 23/06/13 19:42, Sivaram Neelakantan wrote:

On Sun, Jun 23 2013,Alan Gauld wrote:


[snipped 21 lines]


But we normally call methods via the object instance rather than the
class so simplifying this further we get:

b['a'].append('c')



Thanks for the detailed explanation.

I've sort of used a dict of this sort {'a': [1,2,'fff'] } in my
programs and I've noticed that I've got to unpack the list with
hardcoded list positions when I retrieve the value of a key.

I think I'd be better off, if I did something of

{'a' : ['foo': 1, 'bar':2, 'offset': 'fff'] }



That won't work; you need to make the inner value a dict using {}, not a list 
using [].


wouldn't that be better from a maintainability POV?  Are there any
examples of such?  Or is there a 'struct' option for python?  I don't
want to use OO methods for now.


Python doesn't have structs in the sense you mean. (But see below for 
alternatives.) There is a struct module for working with low-level C-style 
bytes, ints, doubles etc. but that's not what you want.

In this case, you can stick with nested dicts:

{'a' : {'foo': 1, 'bar':2, 'offset': 'fff'}}


It may be less typing if you use this format:

{'a': dict(foo=1, bar=2, offset='fff'),
 'b': dict(foo=2, bar=6, offset='fe0'),
 'c': dict(foo=4, bar=9, offset='d02'),
 }


Instead of working with dicts, it isn't very hard to create your own 
struct-like class:


class MyStruct(object):
def __init__(self, foo, bar, offset):
self.foo = foo
self.bar = bar
self.offset = offset


A little tedious, but it only needs to be done once, then:

{'a': MyStruct(1, 2, 'fff'),
 'b': MyStruct(2, 6, 'fe0'),
 'c': MyStruct(4, 9, 'd02'),
 }

The advantage is that you can both read and write the attributes:

s = MyStruct(4, 9, 'd02')
s.foo = 42
print(s.bar)


A third alternative is namedtuple, from the collections module.


from collections import namedtuple

MyStruct = namedtuple('MyStruct', 'foo bar offset')
s = MyStruct(4, 9, 'd02')
print(s.bar)


The advantage here is that namedtuple automatically includes extra "polish", 
such as printing nicely. The only negative is that namedtuples are immutable: once 
created, you cannot modify them, you have to create a new one:

# this doesn't work
s.foo = 42
# instead do this:
s = MyStruct(42, s.bar, s.offset)


This is deliberate, not a bug. But if you can live with that limitation of 
namedtuples, then they are the recommended way to get the equivalent of a 
Pascal record or C struct. Otherwise just create a quick little class as needed.


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] appending/updating values dict key value pairs

2013-06-23 Thread eryksun
On Sun, Jun 23, 2013 at 5:42 AM, Sivaram Neelakantan
 wrote:
> I've sort of used a dict of this sort {'a': [1,2,'fff'] } in my
> programs and I've noticed that I've got to unpack the list with
> hardcoded list positions when I retrieve the value of a key.
>
> I think I'd be better off, if I did something of
>
> {'a' : ['foo': 1, 'bar':2, 'offset': 'fff'] }
>
> wouldn't that be better from a maintainability POV?  Are there any
> examples of such?  Or is there a 'struct' option for python?  I don't
> want to use OO methods for now.

The correct syntax is a dict of dicts:

{'a': {'foo': 1, 'bar': 2, 'offset': 'fff'}}

A dict is something of a resource hog, and it's unordered. Use it as
the container because it's mutable and lookups are fast, but for the
values consider using a namedtuple. It has a smaller footprint, and
it's ordered.

from collections import namedtuple

Record = namedtuple('Record', 'foo bar offset')

You can initialize an instance using either positional or keyword arguments:

data = {
'a': Record(1, 2, 0xfff),
'b': Record(foo=3, bar=4, offset=0xaaa),
}

Access the fields by index or attribute:

>>> a = data['a']; a[0], a[1], a[2]
(1, 2, 4095)

>>> b = data['b']; b.foo, b.bar, b.offset
(3, 4, 2730)

A tuple is immutable, so modifying a field requires a new tuple. Use
the _replace method:

>>> data['b'] = data['b']._replace(offset=0xbbb)

>>> b = data['b']; b.foo, b.bar, b.offset
(3, 4, 3003)


If you're curious, it's easy to see how namedtuple works:

>>> Record = namedtuple('Record', 'foo bar offset', verbose=True)
class Record(tuple):
'Record(foo, bar, offset)'

__slots__ = ()

_fields = ('foo', 'bar', 'offset')

def __new__(_cls, foo, bar, offset):
'Create new instance of Record(foo, bar, offset)'
return _tuple.__new__(_cls, (foo, bar, offset))
...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] random.choice() problem

2013-06-23 Thread Dave Angel

On 06/23/2013 02:18 AM, Jack Little wrote:

I am trying to use random.choice for a text based game. I am using windows 7, 
64-bit python. Here is my code:

def lvl2():
 print "COMMANDER: Who should you train with?"
 trn=random.choice(1,2)
 if trn==1:
 lvl2_1()
 print "Squad One!"
 elif trn==2:
 lvl2_2()
 print "Squad Nine!"





Here is my error:

  File "C:\Users\Jack\Desktop\python\skye.py", line 20, in lvl2
 trn=random.choice(1,2)
TypeError: choice() takes exactly 2 arguments (3 given)








You don't say what version of Python you're using, but I'll assume 2.7

Steven's answer is correct, but here's another option:

trn = random.randint(1,2)

Here, the 1 and 2 are separate arguments delimiting a range of integer 
values.  Note that it includes both end points, unlike the xrange function.


Alternatively, you could use

trn = random.randrange(1,3)


To make the above clearer, suppose you wanted an int value between 1 and 
20, inclusive.   You could do that at least four ways:


trn = random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 
16, 17, 18, 19, 20])


trn = random.choice(range(1, 21))

trn = random.randint(1, 20)

trn = random.randrange(1, 21)




--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] random.choice() problem

2013-06-23 Thread Peter Otten
Dave Angel wrote:

> On 06/23/2013 02:18 AM, Jack Little wrote:
>> I am trying to use random.choice for a text based game. I am using
>> windows 7, 64-bit python. Here is my code:
>>
>> def lvl2():
>>  print "COMMANDER: Who should you train with?"
>>  trn=random.choice(1,2)
>>  if trn==1:
>>  lvl2_1()
>>  print "Squad One!"
>>  elif trn==2:
>>  lvl2_2()
>>  print "Squad Nine!"

>> Here is my error:
>>
>>   File "C:\Users\Jack\Desktop\python\skye.py", line 20, in lvl2
>>  trn=random.choice(1,2)
>> TypeError: choice() takes exactly 2 arguments (3 given)

> Steven's answer is correct, but here's another option:
> 
> trn = random.randint(1,2)
> 
> Here, the 1 and 2 are separate arguments delimiting a range of integer
> values.  Note that it includes both end points, unlike the xrange
> function.

Here's yet another option: if you move the print statements into the 
lvl2_...() functions you can simplify your code by choosing the function 
directly:

>>> import random
>>> def level2_1():
... # ...
... print "Squad One!"
... 
>>> def level2_2():
... # ...
... print "Squad Nine!"
... 
>>> def level2():
... print "COMMANDER: Who should you train with?"
... level2_x = random.choice([level2_1, level2_2])
... level2_x()
... 
>>> level2()
COMMANDER: Who should you train with?
Squad One!
>>> level2()
COMMANDER: Who should you train with?
Squad Nine!
>>> level2()
COMMANDER: Who should you train with?
Squad Nine!


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] appending/updating values dict key value pairs

2013-06-23 Thread Sivaram Neelakantan
On Sun, Jun 23 2013,Steven D'Aprano wrote:

> On 23/06/13 19:42, Sivaram Neelakantan wrote:

[snipped 28 lines]

> Python doesn't have structs in the sense you mean. (But see below
> for alternatives.) There is a struct module for working with
> low-level C-style bytes, ints, doubles etc. but that's not what you
> want.
>
> In this case, you can stick with nested dicts:
>
> {'a' : {'foo': 1, 'bar':2, 'offset': 'fff'}}
>
>
> It may be less typing if you use this format:
>
> {'a': dict(foo=1, bar=2, offset='fff'),
>  'b': dict(foo=2, bar=6, offset='fe0'),
>  'c': dict(foo=4, bar=9, offset='d02'),
>  }
>
>
> Instead of working with dicts, it isn't very hard to create your own
> struct-like class:
>
>
> class MyStruct(object):
> def __init__(self, foo, bar, offset):
> self.foo = foo
> self.bar = bar
> self.offset = offset
>
>
> A little tedious, but it only needs to be done once, then:
>
> {'a': MyStruct(1, 2, 'fff'),
>  'b': MyStruct(2, 6, 'fe0'),
>  'c': MyStruct(4, 9, 'd02'),
>  }
>
> The advantage is that you can both read and write the attributes:
>
> s = MyStruct(4, 9, 'd02')
> s.foo = 42
> print(s.bar)
>
>
> A third alternative is namedtuple, from the collections module.
>
>
> from collections import namedtuple
>
> MyStruct = namedtuple('MyStruct', 'foo bar offset')
> s = MyStruct(4, 9, 'd02')
> print(s.bar)
>
>
> The advantage here is that namedtuple automatically includes extra
> "polish", such as printing nicely. The only negative is that
> namedtuples are immutable: once created, you cannot modify them, you
> have to create a new one:
>
> # this doesn't work
> s.foo = 42
> # instead do this:
> s = MyStruct(42, s.bar, s.offset)
>
>
> This is deliberate, not a bug. But if you can live with that
> limitation of namedtuples, then they are the recommended way to get
> the equivalent of a Pascal record or C struct. Otherwise just create
> a quick little class as needed.

Thank you for explaining the options, I'd probably go with namedtuple
as it seems to match my needs and I don't want to work on OO/Classes
for now.  I'll read up on the documentation for namedtuple.

 sivaram
 -- 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] appending/updating values dict key value pairs

2013-06-23 Thread Sivaram Neelakantan
On Sun, Jun 23 2013,eryksun  wrote:


[snipped 14 lines]

> The correct syntax is a dict of dicts:
>
> {'a': {'foo': 1, 'bar': 2, 'offset': 'fff'}}
>
> A dict is something of a resource hog, and it's unordered. Use it as
> the container because it's mutable and lookups are fast, but for the
> values consider using a namedtuple. It has a smaller footprint, and
> it's ordered.
>
> from collections import namedtuple
>
> Record = namedtuple('Record', 'foo bar offset')
>
> You can initialize an instance using either positional or keyword arguments:
>
> data = {
> 'a': Record(1, 2, 0xfff),
> 'b': Record(foo=3, bar=4, offset=0xaaa),
> }
>
> Access the fields by index or attribute:
>
> >>> a = data['a']; a[0], a[1], a[2]
> (1, 2, 4095)
>
> >>> b = data['b']; b.foo, b.bar, b.offset
> (3, 4, 2730)
>
> A tuple is immutable, so modifying a field requires a new tuple. Use
> the _replace method:
>
> >>> data['b'] = data['b']._replace(offset=0xbbb)
>
> >>> b = data['b']; b.foo, b.bar, b.offset
> (3, 4, 3003)
>
>
> If you're curious, it's easy to see how namedtuple works:
>
> >>> Record = namedtuple('Record', 'foo bar offset', verbose=True)
> class Record(tuple):
> 'Record(foo, bar, offset)'
>
> __slots__ = ()
>
> _fields = ('foo', 'bar', 'offset')
>
> def __new__(_cls, foo, bar, offset):
> 'Create new instance of Record(foo, bar, offset)'
> return _tuple.__new__(_cls, (foo, bar, offset))

[snipped 6 lines]

Thanks for the explanation, I'd go with namedtuple as recommended.

 sivaram
 -- 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How convert an int to a string

2013-06-23 Thread Jim Byrnes

On 06/22/2013 06:24 PM, Dave Angel wrote:

On 06/22/2013 07:03 PM, Jim Byrnes wrote:

On 06/22/2013 05:10 PM, David Rock wrote:

* Jim Byrnes  [2013-06-22 16:01]:

I need to convert a series of digits like 060713 to a string so I can
make it look like a date 06-07-13.

  >>> a = 060713
  >>> a[:2]
Traceback (most recent call last):
File "", line 1, in 
TypeError: 'int' object has no attribute '__getitem__'
  >>> b = str(a)
  >>> b[:2]
'25'
  >>> b
'25035'
  >>>

I was confused at first but then realized that the  0  makes it
octal. I
thought str() would do it but it didn't. Reading about str() it
talks of
string representation.  So how can I convert it to a true string I can
slice and build my date look a like?


Is there a requirement to store them as numbers in the first place?  Why
not just store them as a string?

a = '060713'



Yes. I am scripting data entry in a spreadsheet.  I can enter the 6
numbers


Six digits, not numbers.


quite rapidly using the number pad but entering the " - "'s to
make it look like a date slows me down.  So I thought I would let python
do that for me.



I don't have any experience with using Rxlorg to script the Gemdaddy
spreadsheet program.  Maybe if you actually got specific, somebody would
have familiarity with the ones you're using.


It is Calligrsheets.  I didn't mention it because I was focused on the 
python error message I was seeing.  Python version is 2.7.3.



Most likely all you have to do is specify with the spreadsheet that the
user is to enter a string.  If it makes some sort of assumption that
strings cannot start with a digit, then it's just broken.


I can set the cell contents as text or numeric and I can extract the 
info either as a string or an int.  Each method gives it own error.  The 
code is short so I will post it.


def regionChanged(regions):
""" In column A. Converts data entered as mmddyy to mm-dd-yy """
myCell = viewer.selection()
print myCell
if myCell[0] - 1 == 1:
#cell_value = sheet.text(myCell[0] - 1, myCell[1])  #[1]
cell_value = sheet.value(myCell[0] - 1, myCell[1])  #[2]
print 'Type is ', type(cell_value)
cell_value = cell_value[:2] + '-' + cell_value[2:4] + '-' + 
cell_value[4:]
print 'Cell value is ', cell_value
cell_name = sheet.cellName(myCell[0] - 1, myCell[1])
writer.setCell(cell_name)
writer.setValue(cell_name, cell_value)
viewer.setSelection([2, myCell[1], 1, 1])

[1]  cell_value will always be a string.
[2]  cell_value will be a string or a long depending on cell type.

Here is the output from the terminal. Note: Kross is the plugin that 
enables Python scripting.



### code from [1], cell type = text ###
Kross: "PythonScript::Constructor."
Kross: "PythonScript::execute"
Kross: "PythonScript::execute result=None"
[2, 5, 1, 1]
Type is  
Cell value is  06-25-13
Kross: "PythonInterpreter::extractException:
"
Kross: "PythonExtension::proxyhandler Had exception on line -1:
invalid literal for int() with base 10: '06-25-13'
"
ValueError: invalid literal for int() with base 10: '06-25-13'
Kross: "PythonScript::Destructor."


### code from [2], cell type = text ###
Kross: "PythonScript::Constructor."
Kross: "PythonScript::execute"
Kross: "PythonScript::execute result=None"
[2, 5, 1, 1]
Type is  
Cell value is  06-25-13
Kross: "PythonInterpreter::extractException:
"
Kross: "PythonExtension::proxyhandler Had exception on line -1:
invalid literal for int() with base 10: '06-25-13'
"
ValueError: invalid literal for int() with base 10: '06-25-13'
Kross: "PythonScript::Destructor."


### code [1], cell type = numeric ###
Kross: "PythonScript::Constructor."
Kross: "PythonScript::execute"
Kross: "PythonScript::execute result=None"
[2, 5, 1, 1]
Type is  
Cell value is  06-25-13
Kross: "PythonInterpreter::extractException:
"
Kross: "PythonExtension::proxyhandler Had exception on line -1:
invalid literal for int() with base 10: '06-25-13'
"
ValueError: invalid literal for int() with base 10: '06-25-13'
Kross: "PythonScript::Destructor."



### code [2], cell type numeric ###
Kross: "PythonScript::Constructor."
Kross: "PythonScript::execute"
Kross: "PythonScript::execute result=None"
[2, 5, 1, 1]
Type is  
Kross: "PythonInterpreter::extractException:
  File 
"file:///home/jfb/.kde/share/apps/sheets/scripts/enter_invoices.py", 
line 38, in regionChanged

"
TypeError: 'long' object has no attribute '__getitem__'
Kross: "PythonScript::Destructor."


Regards,  Jim

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unix Environment variables

2013-06-23 Thread Anu Bhagat
Hi I am fairly new to python. I will greatly appreciate if some one can 
tell me how set up environment variables from a python script.


Thanks in advance.

Anu
--
Nothing is impossible, the word itself says 'I'm possible'. Audrey Hepburn

Anu Bhagat
SETI Institute
189 North Bernardo Street
Mountain View, CA 94043-5203
Phone : 650.960.4592
Fax : 650.960.5830
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python 2 or 3?

2013-06-23 Thread Andrew Cooper
Dear Pythoners,
Sorry I am completely new to this but so far as I can see there are two 
versions of Python, version 2 (which is more established and has much more 
support) and version 3 which is relatively new.
As a beginner, which of the versions (2 or 3) would it be advisable to start 
with first?
I suspect version 2, but I would like to hear that from experienced Python 
users.
Many thanks,
Andy Cooper___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to find descendants recursively?

2013-06-23 Thread Fábio Santos
On Sun, Jun 16, 2013 at 6:20 PM, Timo  wrote:
> I have a datafile which is parsed by an external library, I'm having trouble
> creating a hierarchical structure of the data.
>
> This is what I got so far:
>
> items = get_items() # returns a generator
> for item in items:
> print(item)
> children = get_children(item) # also returns a generator
> for child in children:
> print("--", child)
>
> This is fine as it will get the children for each parent item. I can't seem
> to figure out how to go further and get the chidren of the children and so
> on.
>
> Thanks.
>

Use recursion to sort this out. Recursion is the technique of calling
the same function you are in, and it's very useful for tree traversal
problems like this one.

def recurse_items(items, dash_count=0):
for item in items:
print(('-' * dash_count) + str(item))
children = get_children(item) # also returns a generator
if children:
recurse_items(children, dash_count + 1)

recurse_items(items)

I added a "dash_count" to the mix, so you can see an example of how to
keep track of the level you are in on the tree.

Hope I was of some help. Cheers!

--
Fábio Santos
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python error

2013-06-23 Thread Jack Mcgarry
Hello ,I am contacting you because I have this bug with my python that
needs solving.  You see i coded this program when i was learning to do
graphical coding (still am) and i was using pygame, you may be familiar
with this program it is called skier. i clicked "run module" and ran skier
but when it ran this error came up: Traceback (most recent call last):
  File "C:\Python27\skier1.py", line 1, in 
import pygame, sys, random
  File "C:\Python27\pygame\__init__.py", line 95, in 
from pygame.base import *
ImportError: DLL load failed: %1 is not a valid Win32 application.

my computer is 64bit and windows 7 im using python 2.7 (64bit)

can you help?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Data persistence problem

2013-06-23 Thread Fábio Santos
On 21 Jun 2013 07:36, "Arijit Ukil"  wrote:
>
> I have following random number generation function
>
> def rand_int ():
> rand_num = int(math.ceil (random.random()*1000))
> return rand_num
>
> I like to make the value of rand_num (return of rand_int) static/
unchanged after first call even if it is called multiple times. If x=
 rand_int () returns 45 at the first call, x should retain 45 even in
multiple calls.
> Pls help.
>

Use a variable.

_the_num = random.randint(..)
def rand_int():
return _the_num
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 2 basic problems

2013-06-23 Thread John Harris
Hi Charles,

I have added some comments below explaining why you are not getting the
results you expect:

>>> 4+4
8

The above is an expression, when you hit enter python will evaluate it and give
the answer.

>>> 3+3=4
SyntaxError: can't assign to operator
>>> 3=1
SyntaxError: can't assign to literal
>
I thought the last 2 lines should return False

This is an assignment statement, the single '=' means when you hit enter
python will try to set the value of one side to the other. Hence the
assignment error. Instead try:

>>> 3+3==4
False
>>> 3==1
False




lot=('1'+'6'+'8')
print(lot)
a=open("acc","w")
a.write(lot)
a.close
b=open("acc","r")
b.read()
print (b)
b.close


returns
>>>
168

>>>

Firstly your .close methods need to have parens to actually call the
method. So instead of a.close we need a.close()

Then your b.read() line will work, I get the output '168' when I call
b.read().

Lastly, the line b = open("acc", "r") creates a new file object (b). From
the docs: "Open a file, returning an object of the file type."
Therefore when you print(b) python will call the __repr__() method of the
file object which is why you see the line .

John
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] looking for volunteers with testing simple python program

2013-06-23 Thread Lukas Nemec

Hello,

I changed some simple python client/server chatroom recipe
to include RSA keypair based encryption and signature verification

because I'm sick of someone spying on my conversations on FB and similar.

Here is the code:

https://github.com/lunemec/python-chat

If anyone is interrested in trying the software - mostly bughunting and 
improvements


please run these commands after downloading the source codes:

cd client
|openssl genrsa -out your_cert_name.pem -des3 4096
||openssl rsa -pubout -in yourt_cert_name.pem -passin 
pass:"yourpassword" -out your_chatroom_nick.pub


## After this step, please send me your_chatroom_nick.pub file, it 
should have the same name.pub as you want to use in the chatroom, 
otherwise we can't decrypt your messages


# if you don't have pycrypt, then sudo pip install pycrypto
python client.py your_chatroom_nick nemec.lu 3490 
your_cert_name.pem yourpassword


Now we should be able to chat :)

Enjoy, and please don't kill me for writing here :)

Lukas

|
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help with Python in ArcGIS 10.1!

2013-06-23 Thread Jacobs, Teri (CDC/NIOSH/DSHEFS) (CTR)
Hi,


I have a command line to spread geoprocessing operations across multiple 
processes to speed up performance. However, I do not know how to import the 
command line (or at least import it properly) in Python 2.7.2. Here's the 
script example given on ArcGIS 10.1 Help:



import arcpy

# Use half of the cores on the machine.
arcpy.env.parallelProcessingFactor = "50%"

I tried typing it into the command line but nothing happened. Instructions 
would be much appreciated!!!

Teri A. Jacobs
Geography Fellow
Surveillance Branch/DSHEFS/NIOSH/CDC
513-841-4338
w...@cdc.gov

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unix Environment variables

2013-06-23 Thread Amit Saha
Hello,

On Tue, Jun 18, 2013 at 9:58 AM, Anu Bhagat  wrote:
> Hi I am fairly new to python. I will greatly appreciate if some one can tell
> me how set up environment variables from a python script.
>
> Thanks in advance.

You can use the 'os' module. This is the document for Python 2 [1].
That should help you retrieving/setting environment variables.

[1] http://docs.python.org/2/library/os.html#os.environ

Best,
Amit.

>
> Anu
> --
> Nothing is impossible, the word itself says 'I'm possible'. Audrey Hepburn
>
> Anu Bhagat
> SETI Institute
> 189 North Bernardo Street
> Mountain View, CA 94043-5203
> Phone : 650.960.4592
> Fax : 650.960.5830
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



--
http://echorand.me
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Need help appending data to a logfile

2013-06-23 Thread Lukáš Němec

Dne 17. 6. 2013 20:17, Dave Angel napsal(a):

On 06/17/2013 01:36 PM, Matt D wrote:

Hey,
I wrote some simple code to write data to a logfile and it works pretty
well (thanks guys).  Now my problem is that every time i run the program
the old logfile.txt is overwritten.  I need to be able to stop and start
the program without overwriting, or losing, the old data.  here is the
relavent code:

  #  central part of the program
  #  lays out the GUI panel
  #  omitted lots for our purposes here
  Class panel(wx.Panel):

 #  open a file named "logfile.txt" in "w" writing mode.
 #  this will create the file if it doesn't exist.
 self.logfile = open('logfile.txt', 'w')

  # Updates the TextCtrl field values
  # and logs TextCtrl field values
  def update(self, field_values):

 #logger code---
 #first write the CURRENT date/time
self.logfile.write('%s,'%(str(strftime("%Y-%m-%d %H:%M:%S",
gmtime()
# loop through each of the TextCtrl objects
for k,v in self.fields.items():
 #get the value of the current TextCtrl field
 f = field_values.get(k, None)
if f:
 #output the value with trailing comma
self.logfile.write('%s,'%(str(f)))
self.logfile.write('\n')
#end logger code 

In addition to not deleting the old data, it would be awesome to have
some sort of wxPython widget that would give the user the ability to
'save as', or name and save the file, from the GUI panel.
Thanks!



Clearly you didn't absorb or act on much of the advice from the last 
time.  So this time I'll just give you a brief hint.


Don't use write mode when opening the file.  Find the docs on open(), 
and see what other choices there are.




Or even better, use python moto, dont re-invent the wheel, so use built 
in library logging, read the docs for it, or if you want, I can send you 
some examples how to work it, it takes some time to figure out properly...

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python error

2013-06-23 Thread Alexander
On Wed, Jun 19, 2013 at 11:58 AM, Jack Mcgarry <
iliketurtles...@googlemail.com> wrote:

> Hello ,I am contacting you because I have this bug with my python that
> needs solving.  You see i coded this program when i was learning to do
> graphical coding (still am) and i was using pygame, you may be familiar
> with this program it is called skier. i clicked "run module" and ran skier
> but when it ran this error came up: Traceback (most recent call last):
>   File "C:\Python27\skier1.py", line 1, in 
> import pygame, sys, random
>   File "C:\Python27\pygame\__init__.py", line 95, in 
> from pygame.base import *
> ImportError: DLL load failed: %1 is not a valid Win32 application.
>
> my computer is 64bit and windows 7 im using python 2.7 (64bit)
>
> can you help?
>
>
yes submit your code

> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Alexander Etter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] EXE Problem

2013-06-23 Thread Lukas Nemec

Do Win+R
type: cmd
hit enter.

in the opened cmd write cd C:/where/you/have/the/exe (you can move it to 
C: for simplicity)


and run it from there

it will not close this time, and you can see the debugging info.

Enjoy.



On 06/19/2013 08:50 AM, Jack Little wrote:
I compiled a program in python, but the second I open it, there is a 
flash of the error, but then the cmd window closes.



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help

2013-06-23 Thread Antonio Zagheni
Hi there,

I am a begginer in Python.

I did a function that returns a string and I want to copy this to the clipboard.

I have tried a lot of suggestions found at Google but nothing works properly.

Is there an easy way to do that?

I am using Python 2.7 and Windows 7.

Thanks a lot.

Antonio Zagheni.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Unix Environment variables

2013-06-23 Thread Steve Willoughby
Note, however, that changing environment variables only affects the environment 
of your script and it's child processes. Once your script exits, the original 
shell you called it from is NOT changed.

Sent from my iPad

On 2013/6/23, at 14:35, Amit Saha  wrote:

> Hello,
> 
> On Tue, Jun 18, 2013 at 9:58 AM, Anu Bhagat  wrote:
>> Hi I am fairly new to python. I will greatly appreciate if some one can tell
>> me how set up environment variables from a python script.
>> 
>> Thanks in advance.
> 
> You can use the 'os' module. This is the document for Python 2 [1].
> That should help you retrieving/setting environment variables.
> 
> [1] http://docs.python.org/2/library/os.html#os.environ
> 
> Best,
> Amit.
> 
>> 
>> Anu
>> --
>> Nothing is impossible, the word itself says 'I'm possible'. Audrey Hepburn
>> 
>> Anu Bhagat
>> SETI Institute
>> 189 North Bernardo Street
>> Mountain View, CA 94043-5203
>> Phone : 650.960.4592
>> Fax : 650.960.5830
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
> 
> 
> 
> --
> http://echorand.me
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] looking for volunteers with testing simple python program

2013-06-23 Thread Alexander
On Mon, Jun 17, 2013 at 10:17 AM, Lukas Nemec  wrote:

>  Hello,
>
> I changed some simple python client/server chatroom recipe
> to include RSA keypair based encryption and signature verification
>
> because I'm sick of someone spying on my conversations on FB and similar.
>
> Here is the code:
>
> https://github.com/lunemec/python-chat
>
> If anyone is interrested in trying the software - mostly bughunting and
> improvements
>
> please run these commands after downloading the source codes:
>
> cd client
> openssl genrsa -out your_cert_name.pem -des3 4096
> openssl rsa -pubout -in yourt_cert_name.pem -passin
> pass:"yourpassword" -out your_chatroom_nick.pub
>
> ## After this step, please send me your_chatroom_nick.pub file, it should
> have the same name.pub as you want to use in the chatroom, otherwise we
> can't decrypt your messages
>
> # if you don't have pycrypt, then sudo pip install pycrypto
> python client.py your_chatroom_nick nemec.lu 3490 your_cert_name.pem
> yourpassword
>
> Now we should be able to chat :)
>
> Enjoy, and please don't kill me for writing here :)
>
> Lukas
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
I guess this is for testing, but I have a question. If somebody sends you
their .pub file (email or otherwise over internet), and a villainous third
party intercepts that .pub file, will they be able to decrypt the data sent
over this program?
Thanks.



-- 
Alexander
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Just flushed the queue hence the old mails.

2013-06-23 Thread Alan Gauld


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help

2013-06-23 Thread eryksun
On Thu, Jun 20, 2013 at 6:10 PM, Antonio Zagheni  wrote:
>
> I am a begginer in Python.
> I did a function that returns a string and I want to copy this to the 
> clipboard.
> I have tried a lot of suggestions found at Google but nothing works properly.
> Is there an easy way to do that?
> I am using Python 2.7 and Windows 7.

It's simple to access the clipboard with Tkinter:

>>> from Tkinter import Tk, TclError
>>> root = Tk()
>>> root.withdraw()
''
>>> root.clipboard_clear()

>>> root.clipboard_append('eggs ')
>>> root.clipboard_append('and spam')
>>> root.clipboard_get()
'eggs and spam'

>>> root.clipboard_clear()
>>> try: root.clipboard_get()
... except TclError as e: print e
...
CLIPBOARD selection doesn't exist or form "STRING" not defined
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with Python in ArcGIS 10.1!

2013-06-23 Thread bob gailer

On 6/17/2013 10:26 AM, Jacobs, Teri (CDC/NIOSH/DSHEFS) (CTR) wrote:


Hi,


Hi - welcome to the tutor list. Be aware that we are a few volunteers.

Your question is one very long line. Please in future ensure it is 
wrapped so we don't have to scroll.


I have wrapped it here.


I have a command line

What is a "command line"?

to spread geoprocessing operations across multiple processes
to speed up performance. However, I do not
know how to import the command line (or at least import it properly)
in Python 2.7.2. Here's the script example given on ArcGIS 10.1 Help:
  
import arcpy


# Use half of the cores on the machine.

arcpy.env.parallelProcessingFactor = "50%"

I tried typing it


What is "it". You show 3 lines of code above. Do you mean all 3 lines?


into the command line


What is "the command line"? Do you mean Command Prompt or Python shell?


but nothing happened.


What did you expect?
Did you hit enter after each line?
Did the cursor move to the next line?
Did you get another prompt?
What did the prompt look like?

I think you get the idea - you need to tell us more, since we did not 
watch you try the above.


--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 2 or 3?

2013-06-23 Thread wolfrage8765
Personally. I say 3, because support for external modules is growing every day 
and only a few major modules remain, like twisted.  But 3 will soon be the 
standard so start to learn on it now and you will not need to transition latter 
when 3 replaces 2 as the standard.  I currently use 3 and only miss twisted.

Sent from my android device.

-Original Message-
From: Andrew Cooper 
To: "tutor@python.org" 
Sent: Sun, 23 Jun 2013 5:31 PM
Subject: [Tutor] Python 2 or 3?

Dear Pythoners,
Sorry I am completely new to this but so far as I can see there are two 
versions of Python, version 2 (which is more established and has much more 
support) and version 3 which is relatively new.
As a beginner, which of the versions (2 or 3) would it be advisable to start 
with first?
I suspect version 2, but I would like to hear that from experienced Python 
users.
Many thanks,
Andy Cooper___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 2 or 3?

2013-06-23 Thread Mark Lawrence

On 17/06/2013 22:06, Andrew Cooper wrote:

Dear Pythoners,
Sorry I am completely new to this but so far as I can see there are two
versions of Python, version 2 (which is more established and has much
more support) and version 3 which is relatively new.
As a beginner, which of the versions (2 or 3) would it be advisable to
start with first?
I suspect version 2, but I would like to hear that from experienced
Python users.
Many thanks,
Andy Cooper



Version 3 unless you must use a library that's not yet ported, as it 
saves you porting your code at a later date.


--
"Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green." Snooker 
commentator 'Whispering' Ted Lowe.


Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How convert an int to a string

2013-06-23 Thread Dave Angel

On 06/23/2013 12:43 PM, Jim Byrnes wrote:

On 06/22/2013 06:24 PM, Dave Angel wrote:

On 06/22/2013 07:03 PM, Jim Byrnes wrote:

On 06/22/2013 05:10 PM, David Rock wrote:

* Jim Byrnes  [2013-06-22 16:01]:

I need to convert a series of digits like 060713 to a string so I can
make it look like a date 06-07-13.

  >>> a = 060713
  >>> a[:2]
Traceback (most recent call last):
File "", line 1, in 
TypeError: 'int' object has no attribute '__getitem__'
  >>> b = str(a)
  >>> b[:2]
'25'
  >>> b
'25035'
  >>>

I was confused at first but then realized that the  0  makes it
octal. I


In Python source code.  But the date number is being entered into the 
spreadsheet, so the leading zero means no such thing.  It also means no 
such thing when a strictly Python program does something like:

x = int(raw_input())
This is why context is so important.


thought str() would do it but it didn't. Reading about str() it
talks of
string representation.  So how can I convert it to a true string I can
slice and build my date look a like?


Is there a requirement to store them as numbers in the first place?
Why
not just store them as a string?

a = '060713'



Yes. I am scripting data entry in a spreadsheet.  I can enter the 6
numbers


Six digits, not numbers.


quite rapidly using the number pad but entering the " - "'s to
make it look like a date slows me down.  So I thought I would let python
do that for me.



I don't have any experience with using Rxlorg to script the Gemdaddy
spreadsheet program.  Maybe if you actually got specific, somebody would
have familiarity with the ones you're using.


It is Calligrsheets.


I can't find any such thing.  Do you perhaps mean Calligra Sheets, at 
http://www.calligra.org/sheets/ ???  If so, I'm having trouble finding 
any information on the internet about scripting it, in Python or 
otherwise.  It is available on Ubuntu's "Software Centre," but the only 
review was rather negative.


Using what to interface to it?  I'll assume that's what's called Kross 
below.  I'll also have to make wild guesses about the available 
functions and methods that Kross gives you.  Like do you have to use 
writer.setValue() for both ints and strings, or does it have separate 
function calls?  Does it have one for setting dates?  Perhaps string is 
the wrong type entirely.


I can't find any information on the web about scripting Calligra.  If 
there's no installed help either, I'd find something with better docs.



 I didn't mention it because I was focused on the
python error message I was seeing.  Python version is 2.7.3.


But you don't have a Python error message.  It's missing the most 
important parts, the traceback.  Something has intercepted that 
exception and printed only a summary.  And specified a line number of 
negative-one, which isn't reasonable either.


If the try/except is your own, then either fix the display or 
temporarily disable the try.


If the try/except is in the "Kross" code, and you have access to it, 
then see what it looks like in the appropriate place.





Most likely all you have to do is specify with the spreadsheet that the
user is to enter a string.  If it makes some sort of assumption that
strings cannot start with a digit, then it's just broken.


I can set the cell contents as text or numeric and I can extract the
info either as a string or an int.  Each method gives it own error.  The
code is short so I will post it.

def regionChanged(regions):
 """ In column A. Converts data entered as mmddyy to mm-dd-yy """
 myCell = viewer.selection()
 print myCell


This prints a list of ints.  What are they meaning?


 if myCell[0] - 1 == 1:
 #cell_value = sheet.text(myCell[0] - 1, myCell[1])  #[1]
 cell_value = sheet.value(myCell[0] - 1, myCell[1])  #[2]
 print 'Type is ', type(cell_value)
 cell_value = cell_value[:2] + '-' + cell_value[2:4] + '-' +
cell_value[4:]
 print 'Cell value is ', cell_value


Save yourself some trouble, and use  repr(cell_value).  That way you'll 
see the type (indirectly) and the value all at once.  For example, if 
it's a string, this will simply add quotes to the output, making it 
clear that it's a string.



 cell_name = sheet.cellName(myCell[0] - 1, myCell[1])
 writer.setCell(cell_name)
 writer.setValue(cell_name, cell_value)
 viewer.setSelection([2, myCell[1], 1, 1])

[1]  cell_value will always be a string.
[2]  cell_value will be a string or a long depending on cell type.


What are [1] and [2] referring to here, and in the comments below?  Is 
it somehow related to the myCell[0] above that you're sort-of testing 
for ==2?


Here is the output from the terminal. Note: Kross is the plugin that
enables Python scripting.


### code from [1], cell type = text ###
Kross: "PythonScript::Constructor."
Kross: "PythonScript::execute"
Kross: "PythonScript::execute result=None"
[2, 5, 1, 1]
Type is  
Cell value is  06-25-13
Kross: "PythonInterpreter:

Re: [Tutor] Need help appending data to a logfile

2013-06-23 Thread Dave Angel

On 06/17/2013 02:20 PM, Lukáš Němec wrote:





Or even better, use python moto, dont re-invent the wheel, so use built
in library logging, read the docs for it, or if you want, I can send you
some examples how to work it, it takes some time to figure out properly...


But what he's doing has nothing to do with logging.  He's just using 
that word.




--
DaveA
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 2 or 3?

2013-06-23 Thread DragonDon
Week, not an experienced user per se, the more important thing is to just
start.

I can say this, the vast majority of online python classes use v2.  So, if
you have never programmed before, like myself, then 2 is going to be what
you will learn.  Learning to upgrade later is no big deal and I doubt you
will immediately be writing programs that will need to be converted. I
learned that there are a few tricks in regards to this 2/3 difference like:

# adjust for Python 2 or 3
import sys
if sys.version[0] >= ’3′:
getUserInput = input
else:
getUserInput = raw_input

But theses are only stop-gap measures maybe?

It really depends on why you arelearning python i think.

DragonDon
On Jun 24, 2013 6:33 AM, "Andrew Cooper" 
wrote:

> Dear Pythoners,
> Sorry I am completely new to this but so far as I can see there are two
> versions of Python, version 2 (which is more established and has much more
> support) and version 3 which is relatively new.
> As a beginner, which of the versions (2 or 3) would it be advisable to
> start with first?
> I suspect version 2, but I would like to hear that from experienced Python
> users.
> Many thanks,
> Andy Cooper
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question about python for web

2013-06-23 Thread Dat Huynh
Dear all,

I have a very simple question about running a simple web application with
apache on MacOS.

Step 1: Copy the file mod_wsgi.so from the link
http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-macosx106-ap22py26-3.3.so
into the folder "/usr/libexec/apache2"


Step 2: Add the following line:

  LoadModule wsgi_module libexec/apache2/mod_wsgi.so
into the file "/etc/apache2/httpd.conf"


Step 3: Edit a file "test.py" as below and copy the file to the folder
"/Library/WebServer/Documents".

#!usr/bin/python
print "Content-type: text/html"
print
print ""
print ""
print ""
print "Test Page"
print ""

When I type the following url "http://localhost/test.py"; on my browser, I
see exactly the content of the file, NOT the text "Test Page" only.

I think I miss something in the procedure.
What should I do to make my browser process the received HTML data?

Thank you very much.

Sincerely,
Dat.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] "farkadoodle" or: unique global names, was Re: Data persistence problem

2013-06-23 Thread Jim Mooney
On 22 June 2013 19:24, Steven D'Aprano  wrote:

> * If you assign to a name (e.g. "spam = 42") anywhere inside the body of a
> function, then that name is treated as a local variable, which is a fast
> lookup.
>
> * Otherwise, it is treated as unknown scope, and Python will search nesting
> functions (if any), globals, and finally builtins for the name.

What about class variables instead of globals?, I put this in the my
lazy typer module, maker.py, which works fine to persist the numbers
between function calls so I can increment them:

class count:
dict = list = set = tuple = 0

then I use count.dict += 1 , etc.

Would that restrict python from an upward search, or am I dreaming?

And yes, I got rid of the Basic-style names D1, D2. The program now
converts numbers to human-names up to  dict_ninety_nine = , for
instance.  And no, I didn't type ninety_nine dictionary entries to do
that. I'm too lazy a typer  ;')

-- 
Jim
Resistance is futile, but running away is often surprisingly effective.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How convert an int to a string

2013-06-23 Thread Jim Byrnes

On 06/23/2013 06:50 PM, Dave Angel wrote:

On 06/23/2013 12:43 PM, Jim Byrnes wrote:

On 06/22/2013 06:24 PM, Dave Angel wrote:

On 06/22/2013 07:03 PM, Jim Byrnes wrote:

On 06/22/2013 05:10 PM, David Rock wrote:

* Jim Byrnes  [2013-06-22 16:01]:

I need to convert a series of digits like 060713 to a string so I can
make it look like a date 06-07-13.

  >>> a = 060713
  >>> a[:2]
Traceback (most recent call last):
File "", line 1, in 
TypeError: 'int' object has no attribute '__getitem__'
  >>> b = str(a)
  >>> b[:2]
'25'
  >>> b
'25035'
  >>>

I was confused at first but then realized that the  0  makes it
octal. I


In Python source code.  But the date number is being entered into the
spreadsheet, so the leading zero means no such thing.  It also means no
such thing when a strictly Python program does something like:
 x = int(raw_input())
This is why context is so important.


thought str() would do it but it didn't. Reading about str() it
talks of
string representation.  So how can I convert it to a true string I
can
slice and build my date look a like?


Is there a requirement to store them as numbers in the first place?
Why
not just store them as a string?

a = '060713'



Yes. I am scripting data entry in a spreadsheet.  I can enter the 6
numbers


Six digits, not numbers.


quite rapidly using the number pad but entering the " - "'s to
make it look like a date slows me down.  So I thought I would let
python
do that for me.



I don't have any experience with using Rxlorg to script the Gemdaddy
spreadsheet program.  Maybe if you actually got specific, somebody would
have familiarity with the ones you're using.


It is Calligrsheets.


I can't find any such thing.  Do you perhaps mean Calligra Sheets, at
http://www.calligra.org/sheets/ ???  If so, I'm having trouble finding
any information on the internet about scripting it, in Python or
otherwise.  It is available on Ubuntu's "Software Centre," but the only
review was rather negative.



Yes it is Calligra Sheets, that was a typo.  It is a fork of what used 
to be the KDE app kspread. Documentation is sparse that's why it has 
taken me this long to make any progress at all. Here are a couple of the 
more usefull links.


http://techbase.kde.org/Development/Tutorials/KSpread_Scripting
http://kross.dipe.org/dox/kspread.html#a00013


Using what to interface to it?  I'll assume that's what's called Kross
below.  I'll also have to make wild guesses about the available
functions and methods that Kross gives you.  Like do you have to use
writer.setValue() for both ints and strings, or does it have separate
function calls?  Does it have one for setting dates?  Perhaps string is
the wrong type entirely.


Yes Kross enables the python scripting. From the docs:

bool setValue(QVariant value, bool parse=true) [slot]

Set the value of the current cell.

value

The value that should be set.
parse

If this is true, the default, then the value got parsed to look for 
the type else we assume the value has the correct type.


true if the value was set successful else false is returned.

I take this to mean that it checks the under lying format of the cell 
and then supplies the value in that format. As to dates I haven't tried 
one.  I actually don't need or want a true date format.  I'm not going 
to do any date math or anything. I am just looking for some 
representation that looks like mm-dd-yy.



I can't find any information on the web about scripting Calligra.  If
there's no installed help either, I'd find something with better docs.


Well after a lot of searching and working with them I came the 
conclusion that Calligra Sheets was the best alternative available for 
python scripting in the Linux world.





 I didn't mention it because I was focused on the
python error message I was seeing.  Python version is 2.7.3.


But you don't have a Python error message.  It's missing the most
important parts, the traceback.  Something has intercepted that
exception and printed only a summary.  And specified a line number of
negative-one, which isn't reasonable either.

If the try/except is your own, then either fix the display or
temporarily disable the try.


It is not.  I pasted in all my code.


If the try/except is in the "Kross" code, and you have access to it,
then see what it looks like in the appropriate place.


It is open source but I think it is C++ so doubt my looking at it would 
help me much.





Most likely all you have to do is specify with the spreadsheet that the
user is to enter a string.  If it makes some sort of assumption that
strings cannot start with a digit, then it's just broken.


I can set the cell contents as text or numeric and I can extract the
info either as a string or an int.  Each method gives it own error.  The
code is short so I will post it.

def regionChanged(regions):
 """ In column A. Converts data entered as mmddyy to mm-dd-yy """
 myCell = viewer.selection()
 print myCell


This