Learning Python : >>> import math doesn't work ?

2007-11-18 Thread pdlemper
Have carefully installed Python 2.5.1 under XP in dir E:\python25 .
ran   set path = %path% ; E:\python25
Python interactive mode works fine for simple arithmetic .
Then tried >>>  import math
>>>  x = sqrt(100)
   Get errorName error : name 'sqrt' is not defined
Same thing with sin(x) .
I'm unable to find "math" , "sqrt" , or "sin" anywhere in lib , Libs
or include directories .
The Tutorial does not clear this up .
Please help.Thanks  Dave [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Failure of running a second script in same interactive session

2009-04-20 Thread pdlemper
When I open python.exe to the console or "interactive window" and
import/run a script I am frustrated trying to import and run another
script in the same session.  eg I run the script alphasort once fine :
>>> import alphasort < it runs >
When its finished I then try to run the same or another script without
exiting the session.
>>> import script2
Now one of 4 things happen
1, it runs ( rarely )
2. the console repeats the prompt and echos the name of the script
without running it
>>> import script2 < nothing further happens >
3. the console repeats just the prompt
>>>
4. After the above rarely the system locks up requiring the
3-finger-salute. Perhaps this occurs when I repeatedly try to
   run another script.

I am running Python 3.0 under Windows XP with Windows updates.
To run another script I have to exit python.exe with ctrl-Z [return]
and call it up again, either directly from Windows or from a 
shortcut.
Is this usual behavior ?  This is my first experience with a scripting
language and it is frustrating to have to exit and return to the
console every time.  Thanks for any comments, Dave Lemper
--
http://mail.python.org/mailman/listinfo/python-list


Apple Mac OS X 10.6 support & compatability with Python 3 ?

2009-12-16 Thread pdlemper
I've been given a MAC AIR laptop with OS X 10.6 "Snow Leopard". 
On my desktop I dual boot with XP - Ubuntu and have Python on both.
Unfortunately all my Python programs are written on Windows XP and
I heavily rely on WConio for console I/O.
Called Apple tech support. The technician had never heard of Python,
ascertained the MAC AIR does not come preloaded with Python and 
did not know if Python 3 would run under OS X 10.6. This was "beyond"
their expertise.
Does anyone have experience with OS X ? Could I use WConio in a 
Windows emulator ?  I have no experience with MACs and am debating
whether to send this back before opening.  
 Thanks. Dave WB3DWE
-- 
http://mail.python.org/mailman/listinfo/python-list


Python interactive terminal in Ubuntu Linux : some keys fouled up

2010-01-06 Thread pdlemper
Have recently moved from XP to Ubuntu Linux.
Successfully installed Python 3.1.1 in the Ubuntu 9.04
release on my desktop.
Problem is the python interactive terminal  >>> .
Many of the keys now do not work.
eg pressing left-arrow yields  ^[[D
right-arrow ^[[C
Home  ^[OH
Del  ^[[3~
up-arrow^[[A  
  
Frustrating as I use all these , esp  up-arrow to
repeat recent lines.  Found the same thing on 
my sons MacBook.

This is not mentioned in two recent Python books
or one on Ubuntu. Nor could I found help on the www.

Is there any work-around  ?  Should I just forget 
the python prompt >>>   ?  

Thanks, [email protected]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: interactive terminal in Ubuntu Linux : libreadline5-dev works only in Python 2.6 not 3.1

2010-01-09 Thread pdlemper
On Sat, 9 Jan 2010 13:27:07 -0800 (PST), casevh 
wrote:

>
>Did you recompile Python 3.1.1 after installing libreadline5-dev?
>
>(From the Python 3.1.1 directory. Your options to configure may vary.)
>
>make distclean
>./configure --prefix=/usr/local --with-computed-gotos --with-wide-
>unicode
>make
>make altinstall
>
>casevh

Thanks so much for your help . . . but I'm going backwards, probably
due to my inadequate knowledge of Linux.

Ran the above vebatim, except had to do  sudo make install.
Python recompiled and the system appears to be in same path/dir as
before :  /home/dave/python31/Python-3.1.1
Called up interactive prompt  >>>  with  $ python3 , as before.

Problems :
1. prompt keys remain fouled up as before.
2. will not import  random  module, either from prompt or
from any of my prewritten modules.  Get ImportError 
   /usr/local/lib/Python3.1/lib-dynload/_collections.so :
undefined symbol : PyUnicode UCS4_FromString
Some other modules will import : math , sys, os
3. Some of my pre-existing modules will not run : have
  not checked them all, but apparently those with random.
4. Attempted to read my modules with gedit.  Pulls them
  up but refuses to save :  could not save file
  /usr/local/lib/python3.1/dlmodules/Ackermann.py
   You do not have permission necessary to save file.
  This is same path my modules were in before the
  recompile and the dir I made for them. Had no trouble 
  saving them previously.

If no fix available, I'll reinstall from the Python-3.1.1 that 
I extracted from the tarball , and go back to XP for a while  : (

Dave WB3DWE   [email protected] 
-- 
http://mail.python.org/mailman/listinfo/python-list


Python Imaging Library available for Python 3.1 ? Fractals

2010-06-05 Thread pdlemper
On the site
http://code.activestate.com/recipes/langs/python/
there are several scripts for fractals.  See page five.
These begin
from PIL import Image

This fails in my python 3.1.2

Google reveals PIL is Python Imaging Library from
pythonware.com
According to their website PIL is not available beyond 2.6  : (

Do I need a full GUI like tkinter to image a fractal ( on my
python 3.1.2 )  ?Is there any simpler option ?
Thanks,   Dave WB3DWE
-- 
http://mail.python.org/mailman/listinfo/python-list


Is it possible to use multidimensional arrays ?

2009-06-06 Thread pdlemper
All attempts have failed.

import WConio
import array

screen = array.array('H',[0]*75,[0]*24) 
  ERR  array takes at most 2 arguments

screen = array.array('H',[0]*75[0]*24)
TypeErr  int object is unsubscriptable

screen = array.array('H',[0]*75)('H',[0]*24) 
 ERR  object is not callable

screen - array.array('H',[0]*75*24)
Goes through but results are, of course, unacceptable 
On-line docs and Programming in Python 3 are no help.
Should I give up on arrays and use lists, or go to NumPy ? Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


frustrating failure of 'break' statement ( novice )

2009-06-13 Thread pdlemper
In my programs the 'break' fails to work.  I've studied the docs for
3.0 and Programming in Python, neither of which are illuminating.
Simplest example :

while True :
num = int(input())
print(num)
if num == 0 :
break

print('done')


SyntaxError : invalid syntax( pointing to end of break )
This happens whether the 'break' is put on same line as the
conditional, flush with while, flush with if, or appropriately
indented 4 spaces.  
 " I saw the number 4 in gold " -Guido
  with apologies to Wm Carlos Williams
-- 
http://mail.python.org/mailman/listinfo/python-list


Persistent failure of 'break' statement ( novice )

2009-06-13 Thread pdlemper
Thanks Mark & Rhodri.  Neither works.

I'm using Notepad2 as editor.  Don't use the tab. Each space
counted with spacebar & recounted.  Rewrote the block from
scratch as new script and eliminated the print line in the loop.
Now no error message, but it will go on forever despite repeatedly
entering 0.  Have to get out with ctrl-c . 

while True :
num = int(input())
if num == 0 :
break

print('done')

   Frusting: I'm missing something fundamental. Dave WB3DWE
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Persistent failure of 'break' statement ( novice )

2009-06-13 Thread pdlemper
On Sat, 13 Jun 2009 19:03:38 -0700 (PDT), John Machin
 wrote:

>On Jun 14, 10:20 am, [email protected] wrote:
>
>> Now no error message, but it will go on forever despite repeatedly
>> entering 0.  Have to get out with ctrl-c .    
>
>>            Frusting: I'm missing something fundamental. Dave WB3DWE
>
>After you hit the zero key, do you hit the Enter key?
>
>If the answer is yes, then our crystal balls have proved useless.
>You'll have to supply some meaningful detail. If you are pasting your
>script into a Python interactive prompt, stop doing that, save your
>script as a file, and run it from the command line.
>
>Here's a script for you to use. It has some diagnostic print() calls
>in it so that we can see what is going wrong.
>
>8<- cut here
>import sys
>print(sys.version)
>assert sys.version.startswith('3.')
>while True :
>text = input('Enter a number -> ')
>print('You entered', ascii(text))
>if text != "0":
>print('That is NOT the digit zero!')
>num = int(text)
>print('Value:', num)
>if num == 0:
>break
>print('done')
>8<- cut here
>
>And when you run it, copy the outout and paste it into your return
>message/posting, like I've done below:
>
>[I called my copy break_fail.py]
>
>C:\junk>\python30\python break_fail.py
>3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)]
>Enter a number -> 9
>You entered '9'
>That is NOT the digit zero!
>Value: 9
>Enter a number -> 0
>You entered '0'
>Value: 0
>done
>
>C:\junk>
>
>Hoping this helps,
>John


John : Hitting Enter solved it.  Thanks so much.  I was treating
input() as getch() or getche() .   Dave WB3DWE
-- 
http://mail.python.org/mailman/listinfo/python-list


Can module tell if running from interpreter vs Windows command line ?

2009-07-15 Thread pdlemper
The WConio console module produces different colors, sometimes quite
different, when run from Windows command line vs from Python
interpreter >>> .  A good foregnd/backgnd combination under one
may be unreadable under the other  : (
I'm using Python 3.0 with the corresponding WConio on XP.
Is there any way for the module to detect under which it has been 
started ?Thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can module tell if running from interpreter vs Windows command line ?

2009-07-15 Thread pdlemper
On Wed, 15 Jul 2009 19:07:18 -0500, [email protected] wrote:

>The WConio console module produces different colors, sometimes quite
>different, when run from Windows command line vs from Python
>interpreter >>> .  A good foregnd/backgnd combination under one
>may be unreadable under the other  : (
>I'm using Python 3.0 with the corresponding WConio on XP.
>Is there any way for the module to detect under which it has been 
>started ?Thanks
Thanks Alex   It worked :

   import sys
   
   hasattr(sys, 'ps1')   yields True when started from interpreter >>>
and False run from Windows command line
Dave WB3DWE
-- 
http://mail.python.org/mailman/listinfo/python-list


gamma approximation : what is module cmath and where is it located ?

2009-07-29 Thread pdlemper
The following numerical approximation for Euler's Gamma function
is found in http://en.wikipedia.org/wiki/Lanczos_approximation

from cmath import *
 
# Coefficients used by the GNU Scientific Library
g = 7
p = [0.80993, 676.5203681218851, -1259.1392167224028,
 771.32342877765313, -176.61502916214059, 12.507343278686905,
 -0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7]
 
def gamma(z):
z = complex(z)
# Reflection formula
if z.real < 0.5:
return pi / (sin(pi*z)*gamma(1-z))
else:
z -= 1
x = p[0]
for i in range(1, g+2):
x += p[i]/(z+i)
t = z + g + 0.5
return sqrt(2*pi) * t**(z+0.5) * exp(-t) * x


This works in Python 3.0
  
But I can't figure out where it gets "cmath".Searching the Python 
directory reveals no more than a test_cmath.  The only cmath I can find
is a header file in another directory  turboc++\Borland\include\

dir(cmath) reveals 23 functions overlapping the 37 functions of
the math module.

What is cmath, where did it come from and how does it differ from
the standard math module  ?

Dave WB3DWE
   I saw the number 4 in silver,  Guido
 (apologies to Wm Carlos Williams)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gamma approximation : what is module cmath and where is it located ?

2009-07-29 Thread pdlemper
On Wed, 29 Jul 2009 21:36:31 -0700 (PDT), Carl Banks
 wrote:

>On Jul 29, 9:24 pm, [email protected] wrote:
>> What is cmath, where did it come from and how does it differ from
>> the standard math module  ?
>
>What happened when you did a keyword search for "cmath" in the Python
>library documentation?
>
>What happened when you entered "python cmath" in Google?
>
>
>Carl Banks

Thanks Carl & Chris.  I've read the Python doc 10.3 and now understand
its for complex arithmetic. 
I've used python a few months and expected to find cmath seperately
sort of as a " header file".  A text search failed.  I now understand
its in the Python Standard Library, which I assume is that big file
Python30\LIBS\libpython30.aAnd this is not readable as text.
Dave
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble with complex numbers

2009-08-05 Thread pdlemper
On Wed, 05 Aug 2009 08:18:55 -0700, Scott David Daniels
 wrote:

>I think it explained in the complex math area, but basically EE types
>use j, math types use i for exactly the same thing.  Since i is so
>frequently and index in CS, and there is another strong convention,
>why not let the EE types win?
>
>--Scott David Daniels
>[email protected]

   i represents current Dave WB3DWE
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: compare dictionaries

2010-09-07 Thread pdlemper
On Tue, 7 Sep 2010 12:46:36 -0700 (PDT), Baba 
wrote:

>level: beginner
>
>word= 'even'
>dict2 = {'i': 1, 'n': 1, 'e': 1, 'l': 2, 'v': 2}
>
>i want to know if word is entirely composed of letters in dict2
>
>my approach:
>step 1 : convert word to dictionary(dict1)
>
>step2:
>for k in dict1.keys():
>   if k in dict2:
>if dict1[k] != dict2[k]:
>   return False
>   return True
>   return False
>return True
>

Assign letters to their corresponding primes with the
following function -

def alphaprime(c) :
if c == 'a' return 2
elif c == 'b' return 3
elif c == 'c' return 5
...
elif c == 'y' return 97
elif c == 'z' return 101
else : return 0

Using above calculate a composite for the letters in the
dictionary.  Of course begin with 1 and multiply by the
associated prime for each letter and repeat for each
recurrence of that letter.  Call this dictionarycomposite.

Do the same for the word, parsing sequentially and
multiplying by the prime for each letter. Call this
wordcomposite.

Now if 
  dictionarycomposite  %  wordcomposite == 0
the word can be spelled with the letters in the dictionary.

I used this in a word game : works fast.
The  Fundamental Theorum of Arithmetic  may apply.
Dave WB3DWE
-- 
http://mail.python.org/mailman/listinfo/python-list