Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread eryksun
On Fri, Aug 10, 2012 at 6:10 PM, Martin A. Brown  wrote:
>
>  : values = {'a':'d', 'b':'e', 'c':'f', 'd':'g', 'e':'h', 'f':'i', 'g':'j',
>  : 'h':'k', 'i':'l', 'j':'m', 'k':'n', 'l':'o', 'm':'p', 'n':'q', 'o':'r',
>  : 'p':'s', 'q':'t', 'r':'u', 's':'v', 't':'w', 'u':'x', 'v':'y', 'w':'z',
>  : 'x':'a', 'y':'b', 'z':'c', 'A':'D', 'B':'E', 'C':'F', 'D':'G', 'E':'H',
>  : 'F':'I', 'G':'J', 'H':'K', 'I':'L', 'J':'M', 'K':'N', 'L':'O', 'M':'P',
>  : 'N':'Q', 'O':'R', 'P':'S', 'Q':'T', 'R':'U', 'S':'V', 'T':'W', 'U':'X',
>  : 'V':'Y', 'W':'Z', 'X':'A', 'Y':'B', 'Z':'C'}
>
> This sort of thing always catches my eye, and I think to myself
> 'Are there any tools or libraries in this language that I could use
> to generate this, instead of writing out this repetitive data
> structure?'
>
> Here's what I did for my own amusement and possibly of benefit to
> you.  There are probably better solutions out there for your Caesar
> cipher enjoyment, but I hope you may find this helpful.
>
>   # -- This code should create a dictionary that should look like the
>   #one above, but you can create it on the fly with a different
>   #value for the shift.  You could also use a different alphabet.
>   #
>   def generate_caesar_cipher(alphabet,shift):
>   offset = shift - len(alphabet)
>   cipheralpha = ''.join((alphabet[offset:], alphabet[0:offset]))
>   return dict(zip(alphabet,cipheralpha))
>
>   caesar_shift = 3
>
>   values = dict()
>   values.update(generate_caesar_cipher(string.ascii_letters,caesar_shift))

Close, but you're rotating the lower and uppercase letters together.
In the original they're separate. Here's a different approach using
itertools:

from itertools import islice, cycle
from string import ascii_lowercase, ascii_uppercase

def make_caesar_cipher(alphabet=ascii_lowercase, shift=3):
return dict(zip(alphabet, islice(cycle(alphabet), shift, None)))

values = make_caesar_cipher()
values.update(make_caesar_cipher(ascii_uppercase))
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread Wayne Werner

On Fri, 10 Aug 2012, Dave Angel wrote:


On 08/10/2012 03:53 PM, Joel Goldstick wrote:



The clue was actually in his code.  See his shebang line -- he's using
Python 3.  So the error is on the data that the user inputs.
The other clue, that I noticed, was that his innermost error was on line
1, "called" from input().
Anyway, the cure is to use raw_input() everywhere instead.


Or alternatively, if you want to write forward-looking code:

try:
input = raw_input
except NameError:
pass # since we're using python 3+

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


Re: [Tutor] Multipage Tiff to PDF

2012-08-10 Thread Steven D'Aprano

On 11/08/12 06:05, Stuart van Zee wrote:


I need to write a simple app that will convert a folder of multi-page tiff files
to PDFs. I was hoping to be able to write a simple, one button Tkinter app to do
this because the people who need to run this job a few times a day are basically
unskilled. My initial idea was to use PIL, but as far as I can tell PIL doesn't
handle multi-page tiffs and also doesn't handle the G4 encoding.

I would appreciate if someone were to point me in the right direction.



https://duckduckgo.com/html/?q=python%20multi%20page%20tiff
http://www.google.com.au/search?q=python+multipage+tiff

http://pypi.python.org/pypi/tiffany/

Is that enough of a pointer? If not, you will need to give us more information 
about
your general level of Python knowledge.



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


Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread Martin A. Brown

Hello,

 : #!/usr/bin/env python3
 : 
 : import random
 : values = {'a':'d', 'b':'e', 'c':'f', 'd':'g', 'e':'h', 'f':'i', 'g':'j',
 : 'h':'k', 'i':'l', 'j':'m', 'k':'n', 'l':'o', 'm':'p', 'n':'q', 'o':'r',
 : 'p':'s', 'q':'t', 'r':'u', 's':'v', 't':'w', 'u':'x', 'v':'y', 'w':'z',
 : 'x':'a', 'y':'b', 'z':'c', 'A':'D', 'B':'E', 'C':'F', 'D':'G', 'E':'H',
 : 'F':'I', 'G':'J', 'H':'K', 'I':'L', 'J':'M', 'K':'N', 'L':'O', 'M':'P',
 : 'N':'Q', 'O':'R', 'P':'S', 'Q':'T', 'R':'U', 'S':'V', 'T':'W', 'U':'X',
 : 'V':'Y', 'W':'Z', 'X':'A', 'Y':'B', 'Z':'C'}

This sort of thing always catches my eye, and I think to myself  
'Are there any tools or libraries in this language that I could use 
to generate this, instead of writing out this repetitive data 
structure?'

Here's what I did for my own amusement and possibly of benefit to 
you.  There are probably better solutions out there for your Caesar 
cipher enjoyment, but I hope you may find this helpful.

  # -- This code should create a dictionary that should look like the
  #one above, but you can create it on the fly with a different
  #value for the shift.  You could also use a different alphabet.
  #
  def generate_caesar_cipher(alphabet,shift):
  offset = shift - len(alphabet)
  cipheralpha = ''.join((alphabet[offset:], alphabet[0:offset]))
  return dict(zip(alphabet,cipheralpha))
  
  caesar_shift = 3
  
  values = dict()
  values.update(generate_caesar_cipher(string.ascii_letters,caesar_shift))

One other thing to consider is that you can use the underutilized 
function 'translate' from the string module.  The 'maketrans' 
function creates a translation table and the 'translate' function 
applies that to input.

  def alt_trans(plain_alpha,shift):
  offset = shift - len(plain_alpha)
  cipher_alpha = ''.join((plain_alpha[offset:], plain_alpha[0:offset]))
  return string.maketrans(plain_alpha,cipher_alpha)
  
  plaintext = 'Alea iacta est.'
  shift_cipher = alt_trans(string.ascii_letters, caesar_shift)
  ciphertext = string.translate(plaintext,shift_cipher)

Enjoy Python!

-Martin

-- 
Martin A. Brown
http://linux-ip.net/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread Bod Soutar
>>
> OK, I have put it back into Python 2.7, and now I get:
>
> Traceback (most recent call last):
>   File "crypto.py", line 27, in 
> encrypt()
>   File "crypto.py", line 7, in encrypt
> textInputE.list()
> AttributeError: 'str' object has no attribute 'list'

Would it be a strange conclusion to come to that perhaps the object type of
textInputE doesn't have an attribute 'list'?

>>> help(str)

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


Re: [Tutor] The exec command and namespaces

2012-08-10 Thread Jerry Hill
On Fri, Aug 10, 2012 at 4:44 PM, Jaidev Deshpande
 wrote:
> Hi,
>
> Supposed I have a string containing a python script and I exec that script.
>
> Is there a way to keep track of the variables that this exec() command 
> creates?

Sure.  You can provide the dictionaries that exec will use for globals
and locals.  So, something like this might get you started:


>>> my_globals = {}
>>> my_locals = {}
>>> exec "favorite_color = 'blue'" in my_globals,my_locals
>>> print(my_locals)

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


[Tutor] The exec command and namespaces

2012-08-10 Thread Jaidev Deshpande
Hi,

Supposed I have a string containing a python script and I exec that script.

Is there a way to keep track of the variables that this exec() command creates?

Say,

>>> s = 'for i in range(10):\n\tprint i\n\n'
>>> exec(s)
0
1
2
3
4
5
6
7
8
9

Is there a way to ascertain that the variable 'i' was created through
the exec function? I'm looking for a way to identify all python
variables that a given exec call creates.

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


Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread Dave Angel
On 08/10/2012 04:02 PM, Selby Rowley Cannon wrote:


> OK, I have put it back into Python 2.7, and now I get:
> Traceback (most recent call last):
>   File "crypto.py", line 27, in 
> encrypt()
>   File "crypto.py", line 7, in encrypt
> textInputE.list()
> AttributeError: 'str' object has no attribute 'list'
>
What did you intend with that line?  Even if there were such a method,
it's unlikely that it does anything useful, and you do nothing with its
return value.


-- 

DaveA

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


Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread Dave Angel
On 08/10/2012 03:53 PM, Joel Goldstick wrote:
> On Fri, Aug 10, 2012 at 3:33 PM, Selby Rowley Cannon
>  wrote:
>>> 
>> #!/usr/bin/env python3
>>
>> import random
>> values = {'a':'d', 'b':'e', 'c':'f', 'd':'g', 'e':'h', 'f':'i', 'g':'j',
>> 'h':'k', 'i':'l', 'j':'m', 'k':'n', 'l':'o', 'm':'p', 'n':'q', 'o':'r',
>> 'p':'s', 'q':'t', 'r':'u', 's':'v', 't':'w', 'u':'x', 'v':'y', 'w':'z',
>> 'x':'a', 'y':'b', 'z':'c', 'A':'D', 'B':'E', 'C':'F', 'D':'G', 'E':'H',
>> 'F':'I', 'G':'J', 'H':'K', 'I':'L', 'J':'M', 'K':'N', 'L':'O', 'M':'P',
>> 'N':'Q', 'O':'R', 'P':'S', 'Q':'T', 'R':'U', 'S':'V', 'T':'W', 'U':'X',
>> 'V':'Y', 'W':'Z', 'X':'A', 'Y':'B', 'Z':'C'}
>> def encrypt():
>> textInputE = input('Please enter the text you wish to encrypt: ')
>> textInputE.list()
>> for Eletter in textInputE.list():
>> try:
>> print (values[Eletter])
>> except KeyError:
>> print ('Sorry, that input couldn\'t be parsed as text. Try
>> again.')
>> input('Press Enter')
>> def decrypt():
>> textInputD = input('Please enter the numbertext you wish to decrypt')
>> textInputD.list()
>> for Dletter in textInputD.list():
>> try:
>> print (values[Dletter])
>> except KeyError:
>> print ('Sorry, that input couldn\'t be parsed as numbertext from
>> our cipher. Please try again.')
>> input('Press Enter')
>>
>> while True:
>> EorD = input('Encrypt or Decrypt: ')
> so are you sure the line above is really what you have in your code?
> check the quotes
The clue was actually in his code.  See his shebang line -- he's using
Python 3.  So the error is on the data that the user inputs.
The other clue, that I noticed, was that his innermost error was on line
1, "called" from input().
Anyway, the cure is to use raw_input() everywhere instead.

>> 
>>
>> Thanks, I am not quite used to this client yet. The next error is:
>>
>> Traceback (most recent call last):
>>   File "crypto.py", line 25, in 
>> EorD = input('Encrypt or Decrypt: ')
>>   File "", line 1, in 
>> NameError: name 'Encrypt' is not defined
>>
>
>


-- 

DaveA

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


[Tutor] Multipage Tiff to PDF

2012-08-10 Thread Stuart van Zee



I need to write a simple app that will convert a folder of multi-page tiff files to PDFs.  I was hoping to be able to write a simple, one button Tkinter app to do this because the people who need to run this job a few times a day are basically unskilled.  My initial idea was to use PIL, but as far as I can tell PIL doesn't handle multi-page tiffs and also doesn't handle the G4 encoding.I would appreciate if someone were to point me in the right direction.s  







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


Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread Selby Rowley Cannon

On 10/08/12 20:53, Joel Goldstick wrote:

On Fri, Aug 10, 2012 at 3:33 PM, Selby Rowley Cannon
 wrote:

On 10/08/12 20:07, Joel Goldstick wrote:

On Fri, Aug 10, 2012 at 2:57 PM, Selby Rowley Cannon
 wrote:

On 10/08/12 18:17, Joel Goldstick wrote:

On Fri, Aug 10, 2012 at 1:05 PM, Selby Rowley Cannon
 wrote:

I have written a small application to encrypt some text. The script
looks
fine to me, but it won't run and I can't figure out why. I have
attached
it,
if anyone knows why it doesn't work please let me know!


What do you mean 'it won't run'?  Do you get an error with Traceback?

I glanced at your code, and your dictionary ends like this: , 'X':'A',
'Y':'B', 'Z':'C',

There is no closing brace

OK,

File "./crypto.py", line 6
  def encrypt():
^
SyntaxError: invalid syntax


First, don't reply to me, reply to the group.  That might mean
choosing reply all.

So, your first problem is that the dictionary isn't closed.  This is
causing the error at line 6

fix that and find your next error.  It looks like there are lots of them

With such a small file you would do better to just post the code
directly.  That way if people see problems they can point them out in
the body of the reply

good luck

#!/usr/bin/env python3

import random
values = {'a':'d', 'b':'e', 'c':'f', 'd':'g', 'e':'h', 'f':'i', 'g':'j',
'h':'k', 'i':'l', 'j':'m', 'k':'n', 'l':'o', 'm':'p', 'n':'q', 'o':'r',
'p':'s', 'q':'t', 'r':'u', 's':'v', 't':'w', 'u':'x', 'v':'y', 'w':'z',
'x':'a', 'y':'b', 'z':'c', 'A':'D', 'B':'E', 'C':'F', 'D':'G', 'E':'H',
'F':'I', 'G':'J', 'H':'K', 'I':'L', 'J':'M', 'K':'N', 'L':'O', 'M':'P',
'N':'Q', 'O':'R', 'P':'S', 'Q':'T', 'R':'U', 'S':'V', 'T':'W', 'U':'X',
'V':'Y', 'W':'Z', 'X':'A', 'Y':'B', 'Z':'C'}
def encrypt():
 textInputE = input('Please enter the text you wish to encrypt: ')
 textInputE.list()
 for Eletter in textInputE.list():
 try:
 print (values[Eletter])
 except KeyError:
 print ('Sorry, that input couldn\'t be parsed as text. Try
again.')
 input('Press Enter')
def decrypt():
 textInputD = input('Please enter the numbertext you wish to decrypt')
 textInputD.list()
 for Dletter in textInputD.list():
 try:
 print (values[Dletter])
 except KeyError:
 print ('Sorry, that input couldn\'t be parsed as numbertext from
our cipher. Please try again.')
 input('Press Enter')

while True:
 EorD = input('Encrypt or Decrypt: ')

so are you sure the line above is really what you have in your code?
check the quotes


 if EorD == 'Encrypt' or EorD == 'encrypt':
 encrypt()
 elif EorD == 'Decrypt' or EorD == 'decrypt':
 decrypt()
 else:
 print('Encrypt or Decrypt?')

Thanks, I am not quite used to this client yet. The next error is:

Traceback (most recent call last):
   File "crypto.py", line 25, in 
 EorD = input('Encrypt or Decrypt: ')
   File "", line 1, in 
NameError: name 'Encrypt' is not defined





OK, I have put it back into Python 2.7, and now I get:
Traceback (most recent call last):
  File "crypto.py", line 27, in 
encrypt()
  File "crypto.py", line 7, in encrypt
textInputE.list()
AttributeError: 'str' object has no attribute 'list'


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


Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread Joel Goldstick
On Fri, Aug 10, 2012 at 3:33 PM, Selby Rowley Cannon
 wrote:
> On 10/08/12 20:07, Joel Goldstick wrote:
>>
>> On Fri, Aug 10, 2012 at 2:57 PM, Selby Rowley Cannon
>>  wrote:
>>>
>>> On 10/08/12 18:17, Joel Goldstick wrote:

 On Fri, Aug 10, 2012 at 1:05 PM, Selby Rowley Cannon
  wrote:
>
> I have written a small application to encrypt some text. The script
> looks
> fine to me, but it won't run and I can't figure out why. I have
> attached
> it,
> if anyone knows why it doesn't work please let me know!
>
 What do you mean 'it won't run'?  Do you get an error with Traceback?

 I glanced at your code, and your dictionary ends like this: , 'X':'A',
 'Y':'B', 'Z':'C',

 There is no closing brace
>>>
>>> OK,
>>>
>>>File "./crypto.py", line 6
>>>  def encrypt():
>>>^
>>> SyntaxError: invalid syntax
>>>
>> First, don't reply to me, reply to the group.  That might mean
>> choosing reply all.
>>
>> So, your first problem is that the dictionary isn't closed.  This is
>> causing the error at line 6
>>
>> fix that and find your next error.  It looks like there are lots of them
>>
>> With such a small file you would do better to just post the code
>> directly.  That way if people see problems they can point them out in
>> the body of the reply
>>
>> good luck
>
> #!/usr/bin/env python3
>
> import random
> values = {'a':'d', 'b':'e', 'c':'f', 'd':'g', 'e':'h', 'f':'i', 'g':'j',
> 'h':'k', 'i':'l', 'j':'m', 'k':'n', 'l':'o', 'm':'p', 'n':'q', 'o':'r',
> 'p':'s', 'q':'t', 'r':'u', 's':'v', 't':'w', 'u':'x', 'v':'y', 'w':'z',
> 'x':'a', 'y':'b', 'z':'c', 'A':'D', 'B':'E', 'C':'F', 'D':'G', 'E':'H',
> 'F':'I', 'G':'J', 'H':'K', 'I':'L', 'J':'M', 'K':'N', 'L':'O', 'M':'P',
> 'N':'Q', 'O':'R', 'P':'S', 'Q':'T', 'R':'U', 'S':'V', 'T':'W', 'U':'X',
> 'V':'Y', 'W':'Z', 'X':'A', 'Y':'B', 'Z':'C'}
> def encrypt():
> textInputE = input('Please enter the text you wish to encrypt: ')
> textInputE.list()
> for Eletter in textInputE.list():
> try:
> print (values[Eletter])
> except KeyError:
> print ('Sorry, that input couldn\'t be parsed as text. Try
> again.')
> input('Press Enter')
> def decrypt():
> textInputD = input('Please enter the numbertext you wish to decrypt')
> textInputD.list()
> for Dletter in textInputD.list():
> try:
> print (values[Dletter])
> except KeyError:
> print ('Sorry, that input couldn\'t be parsed as numbertext from
> our cipher. Please try again.')
> input('Press Enter')
>
> while True:
> EorD = input('Encrypt or Decrypt: ')

so are you sure the line above is really what you have in your code?
check the quotes

> if EorD == 'Encrypt' or EorD == 'encrypt':
> encrypt()
> elif EorD == 'Decrypt' or EorD == 'decrypt':
> decrypt()
> else:
> print('Encrypt or Decrypt?')
>
> Thanks, I am not quite used to this client yet. The next error is:
>
> Traceback (most recent call last):
>   File "crypto.py", line 25, in 
> EorD = input('Encrypt or Decrypt: ')
>   File "", line 1, in 
> NameError: name 'Encrypt' is not defined
>



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


Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread Dave Angel
On 08/10/2012 03:33 PM, Selby Rowley Cannon wrote:
> On 10/08/12 20:07, Joel Goldstick wrote:
>> On Fri, Aug 10, 2012 at 2:57 PM, Selby Rowley Cannon
>>  wrote:
>>> On 10/08/12 18:17, Joel Goldstick wrote:
 On Fri, Aug 10, 2012 at 1:05 PM, Selby Rowley Cannon
  wrote:
> I have written a small application to encrypt some text. The
> script looks
> fine to me, but it won't run and I can't figure out why. I have
> attached
> it,
> if anyone knows why it doesn't work please let me know!
>
 What do you mean 'it won't run'?  Do you get an error with Traceback?

 I glanced at your code, and your dictionary ends like this: , 'X':'A',
 'Y':'B', 'Z':'C',

 There is no closing brace
>>> OK,
>>>
>>>File "./crypto.py", line 6
>>>  def encrypt():
>>>^
>>> SyntaxError: invalid syntax
>>>
>> First, don't reply to me, reply to the group.  That might mean
>> choosing reply all.
>>
>> So, your first problem is that the dictionary isn't closed.  This is
>> causing the error at line 6
>>
>> fix that and find your next error.  It looks like there are lots of them
>>
>> With such a small file you would do better to just post the code
>> directly.  That way if people see problems they can point them out in
>> the body of the reply
>>
>> good luck
> #!/usr/bin/env python3
>
> import random
> values = {'a':'d', 'b':'e', 'c':'f', 'd':'g', 'e':'h', 'f':'i',
> 'g':'j', 'h':'k', 'i':'l', 'j':'m', 'k':'n', 'l':'o', 'm':'p',
> 'n':'q', 'o':'r', 'p':'s', 'q':'t', 'r':'u', 's':'v', 't':'w',
> 'u':'x', 'v':'y', 'w':'z', 'x':'a', 'y':'b', 'z':'c', 'A':'D',
> 'B':'E', 'C':'F', 'D':'G', 'E':'H', 'F':'I', 'G':'J', 'H':'K',
> 'I':'L', 'J':'M', 'K':'N', 'L':'O', 'M':'P', 'N':'Q', 'O':'R',
> 'P':'S', 'Q':'T', 'R':'U', 'S':'V', 'T':'W', 'U':'X', 'V':'Y',
> 'W':'Z', 'X':'A', 'Y':'B', 'Z':'C'}
> def encrypt():
> textInputE = input('Please enter the text you wish to encrypt: ')
> textInputE.list()
> for Eletter in textInputE.list():
> try:
> print (values[Eletter])
> except KeyError:
> print ('Sorry, that input couldn\'t be parsed as text. Try
> again.')
> input('Press Enter')
> def decrypt():
> textInputD = input('Please enter the numbertext you wish to decrypt')
> textInputD.list()
> for Dletter in textInputD.list():
> try:
> print (values[Dletter])
> except KeyError:
> print ('Sorry, that input couldn\'t be parsed as
> numbertext from our cipher. Please try again.')
> input('Press Enter')
>
> while True:
> EorD = input('Encrypt or Decrypt: ')
> if EorD == 'Encrypt' or EorD == 'encrypt':
> encrypt()
> elif EorD == 'Decrypt' or EorD == 'decrypt':
> decrypt()
> else:
> print('Encrypt or Decrypt?')
>
> Thanks, I am not quite used to this client yet. The next error is:
>
> Traceback (most recent call last):
>   File "crypto.py", line 25, in 
> EorD = input('Encrypt or Decrypt: ')
>   File "", line 1, in 
> NameError: name 'Encrypt' is not defined
>

Did you play with the script as it stands now? Did you try typing things
other than Encrypt at the input prompt?  You'll notice that the error
message is complaining about what YOU typed as the user.

Looks like you're running Python 3 code on a Python 2 system.  If you're
running Python 2, you want to use raw_input() which gets a string,
rather than input(), which tries to evaluate an expression.


-- 

DaveA

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


Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread Selby Rowley Cannon

On 10/08/12 20:07, Joel Goldstick wrote:

On Fri, Aug 10, 2012 at 2:57 PM, Selby Rowley Cannon
 wrote:

On 10/08/12 18:17, Joel Goldstick wrote:

On Fri, Aug 10, 2012 at 1:05 PM, Selby Rowley Cannon
 wrote:

I have written a small application to encrypt some text. The script looks
fine to me, but it won't run and I can't figure out why. I have attached
it,
if anyone knows why it doesn't work please let me know!


What do you mean 'it won't run'?  Do you get an error with Traceback?

I glanced at your code, and your dictionary ends like this: , 'X':'A',
'Y':'B', 'Z':'C',

There is no closing brace

OK,

   File "./crypto.py", line 6
 def encrypt():
   ^
SyntaxError: invalid syntax


First, don't reply to me, reply to the group.  That might mean
choosing reply all.

So, your first problem is that the dictionary isn't closed.  This is
causing the error at line 6

fix that and find your next error.  It looks like there are lots of them

With such a small file you would do better to just post the code
directly.  That way if people see problems they can point them out in
the body of the reply

good luck

#!/usr/bin/env python3

import random
values = {'a':'d', 'b':'e', 'c':'f', 'd':'g', 'e':'h', 'f':'i', 'g':'j', 
'h':'k', 'i':'l', 'j':'m', 'k':'n', 'l':'o', 'm':'p', 'n':'q', 'o':'r', 
'p':'s', 'q':'t', 'r':'u', 's':'v', 't':'w', 'u':'x', 'v':'y', 'w':'z', 
'x':'a', 'y':'b', 'z':'c', 'A':'D', 'B':'E', 'C':'F', 'D':'G', 'E':'H', 
'F':'I', 'G':'J', 'H':'K', 'I':'L', 'J':'M', 'K':'N', 'L':'O', 'M':'P', 
'N':'Q', 'O':'R', 'P':'S', 'Q':'T', 'R':'U', 'S':'V', 'T':'W', 'U':'X', 
'V':'Y', 'W':'Z', 'X':'A', 'Y':'B', 'Z':'C'}

def encrypt():
textInputE = input('Please enter the text you wish to encrypt: ')
textInputE.list()
for Eletter in textInputE.list():
try:
print (values[Eletter])
except KeyError:
print ('Sorry, that input couldn\'t be parsed as text. Try 
again.')

input('Press Enter')
def decrypt():
textInputD = input('Please enter the numbertext you wish to decrypt')
textInputD.list()
for Dletter in textInputD.list():
try:
print (values[Dletter])
except KeyError:
print ('Sorry, that input couldn\'t be parsed as numbertext 
from our cipher. Please try again.')

input('Press Enter')

while True:
EorD = input('Encrypt or Decrypt: ')
if EorD == 'Encrypt' or EorD == 'encrypt':
encrypt()
elif EorD == 'Decrypt' or EorD == 'decrypt':
decrypt()
else:
print('Encrypt or Decrypt?')

Thanks, I am not quite used to this client yet. The next error is:

Traceback (most recent call last):
  File "crypto.py", line 25, in 
EorD = input('Encrypt or Decrypt: ')
  File "", line 1, in 
NameError: name 'Encrypt' is not defined

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


Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread Joel Goldstick
On Fri, Aug 10, 2012 at 2:57 PM, Selby Rowley Cannon
 wrote:
> On 10/08/12 18:17, Joel Goldstick wrote:
>>
>> On Fri, Aug 10, 2012 at 1:05 PM, Selby Rowley Cannon
>>  wrote:
>>>
>>> I have written a small application to encrypt some text. The script looks
>>> fine to me, but it won't run and I can't figure out why. I have attached
>>> it,
>>> if anyone knows why it doesn't work please let me know!
>>>
>> What do you mean 'it won't run'?  Do you get an error with Traceback?
>>
>> I glanced at your code, and your dictionary ends like this: , 'X':'A',
>> 'Y':'B', 'Z':'C',
>>
>> There is no closing brace
>
> OK,
>
>   File "./crypto.py", line 6
> def encrypt():
>   ^
> SyntaxError: invalid syntax
>

First, don't reply to me, reply to the group.  That might mean
choosing reply all.

So, your first problem is that the dictionary isn't closed.  This is
causing the error at line 6

fix that and find your next error.  It looks like there are lots of them

With such a small file you would do better to just post the code
directly.  That way if people see problems they can point them out in
the body of the reply

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


Re: [Tutor] Recursive optimization function, binary tree

2012-08-10 Thread Steven D'Aprano

On 10/08/12 21:44, Roman Vashkevich wrote:

Alright, this may sound like a dumb stupid question.
I am testing a recursive optimization function that builds a binary tree.
I started a hand simulation but the amount of manual work grows exponentially 
with the amount of function frames.
Is there a graphical testing tool for such a task?


This is not a dumb stupid question. It is an advanced question.

This is a mailing list for questions about learning the Python language, not 
general Python-related questions or questions about advanced code testing 
tools. If you are lucky, *maybe* somebody can answer the question if you give 
more detail about what you want -- give as an example of your function, the 
expected input, and the expected output, and perhaps we can give you some ideas.

Otherwise, try on the main Python mailing list, python-l...@python.org, also 
available as a Newsgroup comp.lang.python.



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


Re: [Tutor] Script won't run for no apparent reason

2012-08-10 Thread Joel Goldstick
On Fri, Aug 10, 2012 at 1:05 PM, Selby Rowley Cannon
 wrote:
> I have written a small application to encrypt some text. The script looks
> fine to me, but it won't run and I can't figure out why. I have attached it,
> if anyone knows why it doesn't work please let me know!
>
What do you mean 'it won't run'?  Do you get an error with Traceback?

I glanced at your code, and your dictionary ends like this: , 'X':'A',
'Y':'B', 'Z':'C',

There is no closing brace
-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Script won't run for no apparent reason

2012-08-10 Thread Selby Rowley Cannon
I have written a small application to encrypt some text. The script 
looks fine to me, but it won't run and I can't figure out why. I have 
attached it, if anyone knows why it doesn't work please let me know!
#!/usr/bin/env python3

import random
values = {'a':'d', 'b':'e', 'c':'f', 'd':'g', 'e':'h', 'f':'i', 'g':'j', 'h':'k', 'i':'l', 'j':'m', 'k':'n', 'l':'o', 'm':'p', 'n':'q', 'o':'r', 'p':'s', 'q':'t', 'r':'u', 's':'v', 't':'w', 'u':'x', 'v':'y', 'w':'z', 'x':'a', 'y':'b', 'z':'c', 'A':'D', 'B':'E', 'C':'F', 'D':'G', 'E':'H', 'F':'I', 'G':'J', 'H':'K', 'I':'L', 'J':'M', 'K':'N', 'L':'O', 'M':'P', 'N':'Q', 'O':'R', 'P':'S', 'Q':'T', 'R':'U', 'S':'V', 'T':'W', 'U':'X', 'V':'Y', 'W':'Z', 'X':'A', 'Y':'B', 'Z':'C',

def encrypt():
textInputE = input('Please enter the text you wish to encrypt: ')
textInputE.list()
for Eletter in textInputE.list():
try:
print (values[Eletter])
except KeyError:
print ('Sorry, that input couldn\'t be parsed as text. Try again.')
input('Press Enter')
def decrypt():
textInputD = input('Please enter the numbertext you wish to decrypt')
textInputD.list()
for Dletter in textInputD.list():
try:
print (values[Dletter])
except KeyError:
print ('Sorry, that input couldn\'t be parsed as numbertext from our cipher. Please try again.')
input('Press Enter')

while True:
EorD = input('Encrypt or Decrypt: ')
if EorD == 'Encrypt' or EorD == 'encrypt':
encrypt()
elif EorD == 'Decrypt' or EorD == 'decrypt':
decrypt()
else:
print('Encrypt or Decrypt?')
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help--- opening csv in different functions

2012-08-10 Thread Alan Gauld

On 10/08/12 11:02, leon zaat wrote:

I am trying to fill a file.


I assume you mean create a file? Or overwrite an existing one?
Or append to an existing one. There isn't really a concept of filling a 
file, they just keep getting bigger until you ruin out of space.
(There are some filesystems that support creating fixed size files but 
they are very marginal cases)




The seems to work, but after 200.00 entries i got the message that
opening is not allowed.
What i am doing wrong?


You shouldn't be continually opening the file... And when you do you 
should be sure to close it again as soon as possible.



Is there a way to open the file once.


Yes that's usually what you would do.
Open it, collect your data and write it out (either as you collect
it or all at once as you prefer) then close the file.


When i  didn't open it in the first part, it said it couldn't find the
file.


Not sure what that means but if you haven't created it any attempt to 
read it will fail. But your code was way too long for me to be bothered 
reading through, sorry.


--
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] Confusion with Python, Bash and Command Prompt

2012-08-10 Thread William R. Wing (Bill Wing)
On Aug 10, 2012, at 12:20 AM, Steven D'Aprano  wrote:

> 

[byte]

> That is not Python's doing. That is the shell, and so it depends
> entirely on your choice of operating system and shell. It works on Unix,
> Linux and probably Mac OS, but not on Windows.
> 

Yes, it definitely does work on Mac OS-X as well.

-Bill

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


Re: [Tutor] Recursive optimization function, binary tree

2012-08-10 Thread bob gailer

On 8/10/2012 7:44 AM, Roman Vashkevich wrote:

Alright, this may sound like a dumb stupid question.
I am testing a recursive optimization function that builds a binary tree.
I started a hand simulation but the amount of manual work grows exponentially 
with the amount of function frames.
Is there a graphical testing tool for such a task?

Perhaps - but I'd need more details.

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


[Tutor] Recursive optimization function, binary tree

2012-08-10 Thread Roman Vashkevich
Alright, this may sound like a dumb stupid question.
I am testing a recursive optimization function that builds a binary tree.
I started a hand simulation but the amount of manual work grows exponentially 
with the amount of function frames.
Is there a graphical testing tool for such a task?

RV

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


Re: [Tutor] help--- opening csv in different functions

2012-08-10 Thread Dave Angel
On 08/10/2012 06:02 AM, leon zaat wrote:
> I am trying to fill a file. 
> When i am start the leading fuction the file schould be overwriting the , 
> probarly, existing csv file.
> Accoording from keys from different keys in my sql files, information is 
> collected and written in a other function.
>
> I tried something like this 
> 
> class BAGExtractPlus(wx.Frame):
> ..
> 
> #--
> # schrijven van de records
> 
> #--
> def schrijfExportRecord(self,identificatie, hoofdadres, 
> verblijfobjectgeometrie, dag):
> 
> ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wa')
>
> verblijfhoofd = csv.writer(ofile, delimiter=',',
>
> quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
> sql1="";
> sql1="Select huisnummer, huisletter, huisnummertoevoeging, postcode, 
> gerelateerdeopenbareruimte  from nummeraanduiding "
> sql1a= "where aanduidingrecordinactief<> 'J' and"
> hsql1=" einddatum > '" +  dag + "' and identificatie = '" + 
> hoofdadres + "'";
> sql1= sql1 + sql1a + hsql1;
> num= database.select(sql1);
> for row in num:
> huisnummer=row[0];
> huisletter=row[1];
> huisnummertoevoeging=row[2];
> postcode=row[3];
> gerelateerdeopenbareruimte=row[4];
> sql2="Select openbareruimtenaam, gerelateerdewoonplaats  from 
> openbareruimte where aanduidingrecordinactief<> 'J'"
> sql2= sql2 + "and  einddatum > '" +  dag + "' and identificatie = 
> '" +  gerelateerdeopenbareruimte + "'";
> opn=database.select(sql2);
> for row in database.select(sql2):
> openbareruimtenaam=row[0];
> gerelateerdewoonplaats=row[1];
> sql3="Select woonplaatsnaam  from woonplaats where 
> aanduidingrecordinactief<> 'J'"
> sql3= sql3 + "and  einddatum > '" +  dag + "' and 
> identificatie = '" +  gerelateerdewoonplaats + "'";
> wpl=database.select(sql3);
> for row in wpl:
> woonplaatsnaam=row[0];
> newrow=[identificatie, verblijfobjectgeometrie, 
> huisnummer, huisletter, huisnummertoevoeging, postcode,openbareruimtenaam, 
> woonplaatsnaam];
> verblijfhoofd.writerow(newrow);
>
> del wpl[:];
> del opn[:];
> del num[:];
>  
> 
> #--
> # Exporteer benodigde gegevens
> 
> #--
> def ExportBestanden(self, event):
> 
> ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wb')
> verblijfhoofd = csv.writer(ofile, delimiter=',',
> quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
> dag=str(datetime.date.today());
> sql4="Select adresseerbaarobjectnevenadres.identificatie, 
> adresseerbaarobjectnevenadres.nevenadres from adresseerbaarobjectnevenadres 
> where aanduidingrecordinactief<> 'J' order by 
> adresseerbaarobjectnevenadres.identificatie"
> neven= database.select(sql4);
> for row in neven: 
> nidentificatie=row[0];
> nevenadres=row[1];
>
> sql="Select identificatie, hoofdadres, ligplaatsgeometrie  from 
> ligplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "' 
> and identificatie = '"+ nidentificatie + "'"
> lig= database.select(sql);
> for row in lig:
> hoofdadres=nevenadres;
> identificatie=row[0];
> verblijfobjectgeometrie=row[2];
> self.schrijfExportRecord(identificatie, hoofdadres, 
> verblijfobjectgeometrie, dag)
> sql="Select identificatie, hoofdadres, verblijfsobjectgeometrie  from 
> verblijfsobject where aanduidingrecordinactief<> 'J' and einddatum >'" + dag 
> + "' and identificatie = '"+ nidentificatie + "'"
> vbo= database.select(sql);
> for row in vbo:
> hoofdadres=row[1];
> identificatie=row[0];
> verblijfobjectgeometrie=row[2];
> self.schrijfExportRecord(identificatie, hoofdadres, 
> verblijfobjectgeometrie, dag)
> sql="Select identificatie, hoofdadres, standplaatsgeometrie  from 
> standplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "' 
> and identificatie = '"+ nidentificatie + "'"
> stand= database.select(sql);
> for row in stand:
> hoofdadres=nevenadres;
> identificatie=row[0];
> verblijfobjectgeometrie=row[2];
> self.schrijfExportRecord(identificatie, hoofdadres, 
> verblijfobje

[Tutor] help--- opening csv in different functions

2012-08-10 Thread leon zaat

I am trying to fill a file. 
When i am start the leading fuction the file schould be overwriting the , 
probarly, existing csv file.
Accoording from keys from different keys in my sql files, information is 
collected and written in a other function.

I tried something like this 

class BAGExtractPlus(wx.Frame):
..

#--
# schrijven van de records

#--
def schrijfExportRecord(self,identificatie, hoofdadres, 
verblijfobjectgeometrie, dag):

ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wa')

verblijfhoofd = csv.writer(ofile, delimiter=',',

quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
sql1="";
sql1="Select huisnummer, huisletter, huisnummertoevoeging, postcode, 
gerelateerdeopenbareruimte  from nummeraanduiding "
sql1a= "where aanduidingrecordinactief<> 'J' and"
hsql1=" einddatum > '" +  dag + "' and identificatie = '" + hoofdadres 
+ "'";
sql1= sql1 + sql1a + hsql1;
num= database.select(sql1);
for row in num:
huisnummer=row[0];
huisletter=row[1];
huisnummertoevoeging=row[2];
postcode=row[3];
gerelateerdeopenbareruimte=row[4];
sql2="Select openbareruimtenaam, gerelateerdewoonplaats  from 
openbareruimte where aanduidingrecordinactief<> 'J'"
sql2= sql2 + "and  einddatum > '" +  dag + "' and identificatie = 
'" +  gerelateerdeopenbareruimte + "'";
opn=database.select(sql2);
for row in database.select(sql2):
openbareruimtenaam=row[0];
gerelateerdewoonplaats=row[1];
sql3="Select woonplaatsnaam  from woonplaats where 
aanduidingrecordinactief<> 'J'"
sql3= sql3 + "and  einddatum > '" +  dag + "' and identificatie 
= '" +  gerelateerdewoonplaats + "'";
wpl=database.select(sql3);
for row in wpl:
woonplaatsnaam=row[0];
newrow=[identificatie, verblijfobjectgeometrie, huisnummer, 
huisletter, huisnummertoevoeging, postcode,openbareruimtenaam, woonplaatsnaam];
verblijfhoofd.writerow(newrow);

del wpl[:];
del opn[:];
del num[:];
 

#--
# Exporteer benodigde gegevens

#--
def ExportBestanden(self, event):

ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wb')
verblijfhoofd = csv.writer(ofile, delimiter=',',
quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
dag=str(datetime.date.today());
sql4="Select adresseerbaarobjectnevenadres.identificatie, 
adresseerbaarobjectnevenadres.nevenadres from adresseerbaarobjectnevenadres 
where aanduidingrecordinactief<> 'J' order by 
adresseerbaarobjectnevenadres.identificatie"
neven= database.select(sql4);
for row in neven: 
nidentificatie=row[0];
nevenadres=row[1];

sql="Select identificatie, hoofdadres, ligplaatsgeometrie  from 
ligplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "' and 
identificatie = '"+ nidentificatie + "'"
lig= database.select(sql);
for row in lig:
hoofdadres=nevenadres;
identificatie=row[0];
verblijfobjectgeometrie=row[2];
self.schrijfExportRecord(identificatie, hoofdadres, 
verblijfobjectgeometrie, dag)
sql="Select identificatie, hoofdadres, verblijfsobjectgeometrie  from 
verblijfsobject where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + 
"' and identificatie = '"+ nidentificatie + "'"
vbo= database.select(sql);
for row in vbo:
hoofdadres=row[1];
identificatie=row[0];
verblijfobjectgeometrie=row[2];
self.schrijfExportRecord(identificatie, hoofdadres, 
verblijfobjectgeometrie, dag)
sql="Select identificatie, hoofdadres, standplaatsgeometrie  from 
standplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "' 
and identificatie = '"+ nidentificatie + "'"
stand= database.select(sql);
for row in stand:
hoofdadres=nevenadres;
identificatie=row[0];
verblijfobjectgeometrie=row[2];
self.schrijfExportRecord(identificatie, hoofdadres, 
verblijfobjectgeometrie, dag)
del stand[:];
del vbo[:];
del lig[:];
del neven[:];
sql="Select identificatie, hoofdadres, ligplaatsgeometrie  from 
ligplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "'"
  

Re: [Tutor] Confusion with Python, Bash and Command Prompt

2012-08-10 Thread Steven D'Aprano

On 10/08/12 15:35, Modulok wrote:

...

My Question:
Is it true that doing that is as same as doing #!/usr/bin/env python
on Unix? Because I think that the matter of shebang is limited to Bash
and Windows don't have a bash, it has a Command Prompt. And I don't
think such thing happens in Windows.


It has nothing directly do with bash. It has to do with the operating system's
'program loader'.


Correction noted, thank you.


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