Re: [Tutor] quoting and escaping

2009-01-13 Thread Kent Johnson
On Tue, Jan 13, 2009 at 6:09 PM, Jon Crump wrote: > I've got strings like this: > > s = """[{"title" : "Egton, Yorkshire", "start" : new Date(1201,1,4), > "description" : "Hardy's long name: Egton, Yorkshire.
"}, > {"title" : "Guilsborough, Yorkshire", "start" : new Date(1201,1,5), > "descrip

Re: [Tutor] Date comparison across time zones

2009-01-13 Thread Mark Tolonen
"frenc1z 1z" wrote in message news:7b60d8a80901130845s30842deeuba55afec99285...@mail.gmail.com... Hello, I'm a novice python (python 2.6.1) user with the following problem. Never though this was going to be so difficult :-). I would like to compare some dates (date+time really). The dates a

Re: [Tutor] Sys.stdin Question

2009-01-13 Thread John Fouhy
2009/1/14 Damon Timm : > On Tue, Jan 13, 2009 at 8:55 PM, Steve Willoughby wrote: >> This is playing a dangerous game, though, of introducing a race condition. >> Is there nothing on the standard input RIGHT NOW because the source on >> the other end of the pipe hasn't managed to generate anythin

Re: [Tutor] Sys.stdin Question

2009-01-13 Thread Steve Willoughby
On Tue, January 13, 2009 17:59, Damon Timm wrote: > ... then, I guess, I can just have it do an if statement that asks: if > args[0] == "-" then ... blah. I may do that ... the script, itself, Look at the fileinput module. If you're looking at the command line for a list of filenames, which may

Re: [Tutor] Sys.stdin Question

2009-01-13 Thread Damon Timm
On Tue, Jan 13, 2009 at 8:28 PM, Alan Gauld wrote: > The way other Unix style programs deal with this is to write the code > to read from a general file and if you want to use stdin provide an > argument of '-': That's a good idea, actually -- I hadn't thought of that. Although I use that "-" a

Re: [Tutor] Sys.stdin Question

2009-01-13 Thread Steve Willoughby
On Tue, January 13, 2009 17:45, John Fouhy wrote: > 2009/1/14 Damon Timm : >> This works when I do have something coming via stdin ... but if I run >> the script without piping something first ... it just sits there (I >> assume, waiting for some stdin) ... This is playing a dangerous game, though

Re: [Tutor] Sys.stdin Question

2009-01-13 Thread John Fouhy
2009/1/14 Damon Timm : > This works when I do have something coming via stdin ... but if I run > the script without piping something first ... it just sits there (I > assume, waiting for some stdin) ... > > How do I tell it: if there is no stdin, just move on? This might work: import select, sys

Re: [Tutor] Sys.stdin Question

2009-01-13 Thread Alan Gauld
"Damon Timm" wrote $ ls -la | myscript.py cli_input = sys.stdin.read() if cli_input: print "I piped this in:", cli_input This works when I do have something coming via stdin ... but if I run the script without piping something first ... it just sits there (I assume, waiting for some std

Re: [Tutor] Gamma distribution function

2009-01-13 Thread Alan Gauld
"culpritNr1" wrote I tried the scipy function. I don't understand it. Try reading about it here: http://numpy.sourceforge.net/numdoc/HTML/numdoc.htm It explains the output format. I believe it applies to the scipy version as well as the numpy. The python documentation on this functionali

[Tutor] Sys.stdin Question

2009-01-13 Thread Damon Timm
Hi - am writing a script to send myself email messages from the command line ... I want to have the option be able to input the message body via a pipe so I can easily shoot emails to myself (like from: ls, cat, df, du, mount, etc) ... what i want to be able to do is: $ ls -la | myscript.py and i

Re: [Tutor] quoting and escaping

2009-01-13 Thread Steve Willoughby
On Tue, January 13, 2009 16:12, John Fouhy wrote: > (or, heck, get rid of eval.. do you really need it?) As a general comment, especially for beginning to intermediate programmers, the answer to "do you need eval()" is usually "not really." There's almost always a better, easier and more straight

Re: [Tutor] quoting and escaping

2009-01-13 Thread John Fouhy
2009/1/14 Jon Crump : b = """{"aKey" : "a value with \"literal quotes\" in it"}""" eval(b) > > Traceback (most recent call last): > File "", line 1, in > File "", line 1 >{"aKey" : "a value with "literal quotes" in it"} > ^ > SyntaxError: invalid s

Re: [Tutor] quoting and escaping

2009-01-13 Thread Steve Willoughby
On Tue, January 13, 2009 15:09, Jon Crump wrote: > All, > > Something I don't understand (so what else is new?) about quoting and > escaping: > s = """ "some" \"thing\" """ s > ' "some" "thing" ' Correct. Note that """ ... """ is just a string constant the same as "..." is, with the exc

[Tutor] quoting and escaping

2009-01-13 Thread Jon Crump
All, Something I don't understand (so what else is new?) about quoting and escaping: s = """ "some" \"thing\" """ s ' "some" "thing" ' I've got strings like this: s = """[{"title" : "Egton, Yorkshire", "start" : new Date(1201,1,4), "description" : "Hardy's long name: Egton, Yorkshire.

[Tutor] Fwd: Gamma distribution function

2009-01-13 Thread Jervis Whitley
-- Forwarded message -- From: Jervis Whitley Date: Wed, Jan 14, 2009 at 9:26 AM Subject: Re: [Tutor] Gamma distribution function To: culpritNr1 On Wed, Jan 14, 2009 at 9:11 AM, culpritNr1 wrote: > > The python documentation on this functionality is extremely poor. Look > >>>

Re: [Tutor] Gamma distribution function

2009-01-13 Thread culpritNr1
I just figured it out myself. This is how to do it both the naive and the efficient way, respectively: >>> import math >>> from scipy import factorial >>> lam = 1 >>> k = 2 >>> math.exp(-lam) * lam**k / factorial(k) 0.18393972058572117 >>> from scipy import stats >>> stats.poisson.pmf(2,1) arra

Re: [Tutor] Gamma distribution function

2009-01-13 Thread Kent Johnson
On Tue, Jan 13, 2009 at 5:11 PM, culpritNr1 wrote: > > Hi Jarvis, > > I tried the scipy function. I don't understand it. Look, if you go to > http://en.wikipedia.org/wiki/Poisson_Distribution wiki's Poisson > distribution documentation you'll find that this is the naive way to > compute a Poisson

Re: [Tutor] power of 2.718282

2009-01-13 Thread Kent Johnson
On Tue, Jan 13, 2009 at 5:09 PM, Marc Tompkins wrote: > Apparently nothing at all is wrong with it: > C:\Python25\Lib>python timeit.py -s "import math" "x=math.exp(10)" > 100 loops, best of 3: 0.678 usec per loop > > C:\Python25\Lib>python timeit.py -s "from math import e" "x=e**10" > 100

Re: [Tutor] Gamma distribution function

2009-01-13 Thread culpritNr1
Hi Jarvis, I tried the scipy function. I don't understand it. Look, if you go to http://en.wikipedia.org/wiki/Poisson_Distribution wiki's Poisson distribution documentation you'll find that this is the naive way to compute a Poisson probability mass function >>> lam = 1 >>> k = 2 >>> math.exp(

Re: [Tutor] power of 2.718282

2009-01-13 Thread Marc Tompkins
On Tue, Jan 13, 2009 at 1:39 PM, Alan Gauld wrote: > I would appreciate a low level solution because I have to iteratively call >> that computation millions of times. Anything more efficient than >> 2.718182**10 may be good. >> > > Umm, what's wrong with > > from math import e # more precision th

Re: [Tutor] Gamma distribution function

2009-01-13 Thread Jervis Whitley
On Wed, Jan 14, 2009 at 8:27 AM, culpritNr1 wrote: > > > there some kind of random.poisson()? > > Thank you, > > culpritNr1 > > Hello try the scipy library: >>> from scipy import stats >>> lamb = 10 >>> stats.distributions.poisson.rvs(lamb, loc=0) array([5]) >>> stats.distributions.poisson.rvs(la

Re: [Tutor] python3.0 and tkinter on ubuntu 8.10

2009-01-13 Thread Robert Berman
Vern, Thanks for this post. While I do not need Python 3.0 at the moment and have no problem waiting for it to become the default for Ubuntu, I am glad it is not so glaring a problem as some, including me, thought it might be. Would you object if I posted your post to any of the still open thr

Re: [Tutor] python3.0 and tkinter on ubuntu 8.10

2009-01-13 Thread spir
Le Tue, 13 Jan 2009 16:02:48 -0500, Vern Ceder a écrit : > Hi, > > I have Python 3.0/Tkinter/IDLE working fine on Ubuntu 8.10, but it takes > a certain amount of fiddling. > > 1. Make sure the stock Ubuntu Python 3.0 package is not installed > > 2. download the Python 3.0 source from python.o

Re: [Tutor] power of 2.718282

2009-01-13 Thread Alan Gauld
"culpritNr1" wrote I would appreciate a low level solution because I have to iteratively call that computation millions of times. Anything more efficient than 2.718182**10 may be good. Umm, what's wrong with from math import e # more precision than 2.718182 print e**10 e**10 is shorter

Re: [Tutor] python3.0 and tkinter on ubuntu 8.10

2009-01-13 Thread Emad Nawfal (عماد نوفل)
On Tue, Jan 13, 2009 at 4:02 PM, Vern Ceder wrote: > Hi, > > I have Python 3.0/Tkinter/IDLE working fine on Ubuntu 8.10, but it takes a > certain amount of fiddling. > > 1. Make sure the stock Ubuntu Python 3.0 package is not installed > > 2. download the Python 3.0 source from python.org > > 3. i

Re: [Tutor] Date comparison across time zones

2009-01-13 Thread Alan Gauld
"frenc1z 1z" wrote I'm a novice python (python 2.6.1) user with the following problem. Never though this was going to be so difficult :-). Timezones are devilishly difficult to do if you need to be complete. If you are only dealing with the Western world then its not so bad and most librari

[Tutor] Gamma distribution function

2009-01-13 Thread culpritNr1
Hello All, OK. This time a less trivial question. Is there a function to enable us sample from a Poisson distribution? There is random.uniform, random.normalvariate(), random.expovariate()... Is there some kind of random.poisson()? Thank you, culpritNr1 -- View this message in context: ht

Re: [Tutor] A list of input arguments

2009-01-13 Thread Alan Gauld
"Kent Johnson" wrote Is there any way to list the input arguments without listing them inside the function's parentheses? No, because the function expects 3 arguments so you must pass it 3. You can use *args to pass multiple arguments in a list. For example, In [2]: values = [1, 2, 3] In

Re: [Tutor] python3.0 and tkinter on ubuntu 8.10

2009-01-13 Thread Vern Ceder
Hi, I have Python 3.0/Tkinter/IDLE working fine on Ubuntu 8.10, but it takes a certain amount of fiddling. 1. Make sure the stock Ubuntu Python 3.0 package is not installed 2. download the Python 3.0 source from python.org 3. install the following packages: build-essential libsqlite3-dev li

Re: [Tutor] python3.0 and tkinter on ubuntu 8.10

2009-01-13 Thread Emad Nawfal (عماد نوفل)
On Tue, Jan 13, 2009 at 3:30 PM, Robert Berman wrote: > Emad, > > A number of people in the Ubuntu community have attempted to work with > Python3.0 under Ubuntu 8.10 and almost all have found it to be a frustrating > and painful experience with some having disastrous consequences. I was > looki

Re: [Tutor] python3.0 and tkinter on ubuntu 8.10

2009-01-13 Thread Robert Berman
Emad, A number of people in the Ubuntu community have attempted to work with Python3.0 under Ubuntu 8.10 and almost all have found it to be a frustrating and painful experience with some having disastrous consequences. I was looking for the latest discussion thread on this issue in the Ubuntu

[Tutor] python3.0 and tkinter on ubuntu 8.10

2009-01-13 Thread Emad Nawfal (عماد نوفل)
Hi Tutors,I have downloaded Python3.0 and started playing with it. I like it because of the utf-8 default encoding, but I'm having trouble importing tkinter. I get the following: >>> import turtle Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.0/turtle.py",

Re: [Tutor] Date comparison across time zones

2009-01-13 Thread Martin Walsh
frenc1z 1z wrote: > Hello, > I would like to compare some dates (date+time really). The dates all > have the following RFC2822 format: > > Eg. is d1 < d2? > d1 = "Tue, 13 Jan 2009 03:27:29 -0800" > d2 = "Tue, 13 Jan 2009 02:40:00 -0600" > > My thinking is that I first need to make these two dat

Re: [Tutor] power of 2.718282

2009-01-13 Thread Adam Bark
According to a quick interactive session and the timeit module it's quicker to do 2.71828**10 than using math.exp, I'm guessing cos of the function call. >>> t=timeit.Timer("2.718282**10") >>> t.repeat() [0.073765993118286133, 0.066617012023925781, 0.06807398796081543] >>> t=timeit.Timer("math.exp

Re: [Tutor] power of 2.718282

2009-01-13 Thread culpritNr1
Thanks Marc and Kent and all. math.exp() is what I was looking for. culpritNr1 -- View this message in context: http://www.nabble.com/power-of-2.718282-tp21441385p21441787.html Sent from the Python - tutor mailing list archive at Nabble.com. ___ Tu

Re: [Tutor] power of 2.718282

2009-01-13 Thread Kent Johnson
On Tue, Jan 13, 2009 at 1:19 PM, culpritNr1 wrote: > > Hello All, > > It such a simple question, but because of that, googling for an answer just > pulls the wrong results. > > How do I compute a power of e in Python? > > Say I need 2.718282 to the 10th. In R for example, I just do exp(10). impor

Re: [Tutor] power of 2.718282

2009-01-13 Thread Marc Tompkins
On Tue, Jan 13, 2009 at 10:19 AM, culpritNr1 wrote: > > How do I compute a power of e in Python? > > Say I need 2.718282 to the 10th. In R for example, I just do exp(10). > > I would appreciate a low level solution because I have to iteratively call > that computation millions of times. Anything m

[Tutor] power of 2.718282

2009-01-13 Thread culpritNr1
Hello All, It such a simple question, but because of that, googling for an answer just pulls the wrong results. How do I compute a power of e in Python? Say I need 2.718282 to the 10th. In R for example, I just do exp(10). I would appreciate a low level solution because I have to iteratively c

Re: [Tutor] Date comparison across time zones

2009-01-13 Thread Kent Johnson
On Tue, Jan 13, 2009 at 11:45 AM, frenc1z 1z wrote: > I would like to compare some dates (date+time really). The dates all have > the following RFC2822 format: > > Eg. is d1 < d2? > d1 = "Tue, 13 Jan 2009 03:27:29 -0800" > d2 = "Tue, 13 Jan 2009 02:40:00 -0600" > > Been trying to parse these date

[Tutor] Date comparison across time zones

2009-01-13 Thread frenc1z 1z
Hello, I'm a novice python (python 2.6.1) user with the following problem. Never though this was going to be so difficult :-). I would like to compare some dates (date+time really). The dates all have the following RFC2822 format: Eg. is d1 < d2? d1 = "Tue, 13 Jan 2009 03:27:29 -0800" d2 = "Tue

Re: [Tutor] Python and Abaqus

2009-01-13 Thread Kent Johnson
On Tue, Jan 13, 2009 at 8:42 AM, jzq wrote: > hi,I need your help. > Could you give me some examples about the using of python in abaqus? > Thanks a lot. I'm not sure there is anyone on this list who knows abaqus, previous questions have come up pretty dry. We can help with the python part... Go

Re: [Tutor] Python and Abaqus

2009-01-13 Thread jzq
hi,I need your help. Could you give me some examples about the using of python in abaqus? Thanks a lot. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] traceback

2009-01-13 Thread A.T.Hofkamp
spir wrote: Hello, is there a way to read an exception's traceback? Cannot find it in object attributes. [dir() shows no traceback, __dict__ is empty.] You should be able to do that with the traceback module. Sincerely, Albert ___ Tutor maillist

[Tutor] traceback

2009-01-13 Thread spir
Hello, is there a way to read an exception's traceback? Cannot find it in object attributes. [dir() shows no traceback, __dict__ is empty.] t = "a" try: print t[1] except IndexError, e: print e print repr(e) print dir(e) print e. __dict__ print e.a

Re: [Tutor] A list of input arguments

2009-01-13 Thread Kent Johnson
On Tue, Jan 13, 2009 at 6:32 AM, Mr Gerard Kelly wrote: > My only other question is, does there exist a convenient way to unpack a > collection of variable length? > > If you know that there are 3 elements in the collection, you can specify: > > play_for(waves(chord[0],chord[1],chord[2]),500) > >

Re: [Tutor] A list of input arguments

2009-01-13 Thread Kent Johnson
On Tue, Jan 13, 2009 at 4:16 AM, Alan Gauld wrote: > "Mr Gerard Kelly" wrote >> Is there any way to list the input arguments without listing them inside >> the function's parentheses? > > No, because the function expects 3 arguments so you must pass it 3. > That is the contract (or interface) th

Re: [Tutor] HOW DO I PYTHONIZE A BASICALLY BASIC PROGRAM?

2009-01-13 Thread Kent Johnson
On Mon, Jan 12, 2009 at 9:20 PM, bob gailer wrote: > for natnum in range(1000): > if not (natnum % 3 or natnum % 5): # adds 1 if divisible by 3 and/or 5 > cume += 1 > if not natnum % 15: # remove one of the ones if divisible by 15 > cume -= 1 This subtraction is not needed because the mult

Re: [Tutor] A list of input arguments

2009-01-13 Thread Mr Gerard Kelly
Many thanks for your helpful answer Alan. My only other question is, does there exist a convenient way to unpack a collection of variable length? If you know that there are 3 elements in the collection, you can specify: play_for(waves(chord[0],chord[1],chord[2]),500) But then if you want to cha

Re: [Tutor] A list of input arguments

2009-01-13 Thread Alan Gauld
"Mr Gerard Kelly" wrote I have a problem with understanding how lists, strings, tuples, number types and input arguments all interact with each other. OK, they are all different types. Some of them take a single value (sometimes known as a scalar type) and others take a collection of values