Re: [Tutor] namespaces

2010-05-30 Thread Evert Rol
Hi Robert > This code generates the message “UnboundLocalError: local variable 'doubles' > referenced before assignment” (line: if d[0] == d[1] and doubles == 2:) > > http://pastebin.com/mYBaCfj1 > > I think I have a fair picture of what it means but I would be very happy if > someone co

Re: [Tutor] matmolplot

2010-06-01 Thread Evert Rol
Sorry, forgot to reply-to-all previously. > Hi, > > I am trying to make plot using following code: > --- > for i in range(len(l2)): > plt.axvline(x=l1[i], ymin=0, ymax=l2[i], linewidth=2, color='r') axvline uses the [0, 1] range for it coordinates, not the coordinates set by the y-a

Re: [Tutor] re.sub() query

2010-06-20 Thread Evert Rol
> Is it possible to solve the below, w/o making a re object? > a > 'Mary Had a Little Lamb' p=re.compile('l',re.I) re.sub(p,'-',a) > 'Mary Had a -itt-e -amb' > > I cannot figure how to se re.I w/o involving p. Would this work? >>> re.sub('(?i)l', '-', a) See http://docs.python.o

Re: [Tutor] Getting an object's attributes

2010-06-26 Thread Evert Rol
> I have an object to which I dynamically add attributes. My question is how I > can inspect and display them at run-time? > > Class a(): >pass > > Obj1 = a() > > Obj1.name = "Bob" > Obj1.age = 45 First off, a few suggestions: - you probably mean 'class', not 'Class' (sorry, but it's just

Re: [Tutor] Problems installing

2010-06-30 Thread Evert Rol
> I just downloaded Python 2.6.5 onto my windows vista laptop. I am attempting > to install "escript version 3: Solution of Partial Differential Equations > (PDE) using Finite Elements (FEM)." I downloaded the files and manually > placed them in their appropriately place on my computer according

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Evert Rol
x = 2034 x/2 > 1017.0 print(x/2) > 1e+15 > > I was expecting, in fact needing, 117 or 117.0 > > 1e+15 is unsatisfactory. Am I forced to use the decimal module? Can't you use string formatting? Eg: >>> print("{0:15.0f}".format

Re: [Tutor] Problems with subtraction!

2010-07-07 Thread Evert Rol
> The second number should be negative ( I WANT it to be negative). For example: > > print (0 - t[4])*(t[3] - t[5]) , (0 - t[5])*(t[2] - t[4]) gives : > > -30895 -935636 > > And in the python shell: > > >>> -30895 -935636 > -966531 No, because you have to *subtract* the second answer from

Re: [Tutor] "expected an indented block" (see attached)

2010-07-22 Thread Evert Rol
> Attached is a file. When I run the program it is part of, I get an > error that says: > line 62: IndentationError: expected an indented block. This function: def fromString(self, str): #creates a Craft object from the string #end class Craft Is completely empty (the comment lines are disca

Re: [Tutor] "expected an indented block" (see attached)

2010-07-22 Thread Evert Rol
>> (also consider using four spaces for indentation, which I've also found much >> clearer. Have a read through PEP 8; has a lot of interesting tidbits. > > Did you read the rest of his post? He's using a screen reader for a > reason; he can't *see* the code. visual means of structuring code like

Re: [Tutor] nested list help

2010-07-27 Thread Evert Rol
> Suppose i have this nested list: > > >>> x > [['NM100', 3, 4, 5, 6, 7], ['NM100', 10, 11, 12, 13], ['NM200', 15, 16, 17]] > >>> for i in x: > ... print i > ... > ['NM100', 3, 4, 5, 6, 7] > ['NM100', 10, 11, 12, 13] > ['NM200', 15, 16, 17] > >>> > > how do i obtain from the above the followi

Re: [Tutor] subprocess output

2010-07-28 Thread Evert Rol
> #!/usr/bin/env python > import subprocess > import sys > > dom = sys.argv[1] > switch = sys.argv [2] > answer = subprocess.call("whois " + dom, shell=True) > > Execute the above (whatever.py -example.com -a1) prints the entire WHOIS > output, but I just want it saved to the variable 'answer', n

Re: [Tutor] Order Of Operations Question

2010-07-28 Thread Evert Rol
Sorry, forgot to reply-to-all: I don't know the book nor the exercise, but see my comments interspersed in the code, and a few general remarks at the bottom > From a practice exercise in Building Skills In Python page 64 I'm > working on How Much Does The Atmosphere Weigh? Part 1: > To check it

Re: [Tutor] A Django Beginner View Question

2010-07-29 Thread Evert Rol
Consider using the django-users Google group for typical Django questions (unless you figure they're really about Python). Will likely get you better or more answers. Anyway: > Hi > > I am building my first Django site which has a lot of effectively 'static' > pages where I just want to make t

Re: [Tutor] Simple Python Program

2010-07-31 Thread Evert Rol
> Can anyone tell me how to fix the errors I am getting if possible? I'm quite > new and so confused... You're not telling us what the errors are. If you'd like us help to debug your program, best is to provide information about how you run it, and what output you're getting. Not just the progr

Re: [Tutor] Help with Import Error problems

2010-08-01 Thread Evert Rol
> Hi. Good day. > > I am having an import error problem. Last week, I was following this site: > http://sites.google.com/site/spatialpython/processing-aster-with-python-numpy-and-gdal. > I was able to make the python script run on the terminal. But this week, it > was throwing some error. >

Re: [Tutor] Help with Import Error problems

2010-08-01 Thread Evert Rol
> I got it back working. But it was with some stroke of luck. And I dont know > the explanation. > > I installed the latest source of GEOS (as suggested by someone from the gdal > channel). Then i tried the script. It gave me a different import error. > > ImportError: libgeos-3.3.0.so: cannot

Re: [Tutor] sys.exit help

2010-08-01 Thread Evert Rol
> I was wondering how can I change sys.exit so if you use command line to run > the program. it prompts a message asking if the user wants to exit instead of > automatically just exiting? Just write a wrapper exit() function around sys.exit that does that. You don't want to change the sys.exit f

Re: [Tutor] Menu not working properly

2010-08-02 Thread Evert Rol
> My problem is choice 3. Exit, if you select no or put an invalid answer... It > will run menu1... but then it runs > name = raw_input ("Enter your character name. ") > print "Your character name is:", name > > How can i make it so it prints menu1 like normal... then asks you to enter >

Re: [Tutor] Menu not working properly

2010-08-02 Thread Evert Rol
> Hello Evert Rol, > Thank you for the menu help, I have completed it with great > success... There is 1 more problem I am currently having, and when I fix it > my program will be completed. If you are interested in helping me with this > last stretch, I will be great

Re: [Tutor] sys.exit help

2010-08-02 Thread Evert Rol
(replying to the full list; hope that was intended.) >>> I was wondering how can I change sys.exit so if you use command line to run >>> the program. it prompts a message asking if the user wants to exit instead >>> of automatically just exiting? >> >> Just write a wrapper exit() function aroun

Re: [Tutor] global exception handling?

2010-08-02 Thread Evert Rol
> A week or two back I asked this list about how to deal with SQLite database > errors like 'database is locked'. Since then I figured out one way to > reproduce that error (*see p.s. below if anyone is interested). I can also > then catch the error with a try/except block and prevent it from

Re: [Tutor] access class through indexing?

2010-08-04 Thread Evert Rol
> Hi all, > Further to my questions about overriding builtin methods earlier, how > would I make a class able to be accessed and changed using index > notation? For example, take the following: > deck=CardPile(52) #creates a new deck of cards > print(len(deck)) #prints 52, thanks to my __len__ func

Re: [Tutor] access class through indexing?

2010-08-04 Thread Evert Rol
>>> Further to my questions about overriding builtin methods earlier, how >>> would I make a class able to be accessed and changed using index >>> notation? For example, take the following: >>> deck=CardPile(52) #creates a new deck of cards >>> print(len(deck)) #prints 52, thanks to my __len__ func

Re: [Tutor] access class through indexing?

2010-08-04 Thread Evert Rol
On 4 Aug 2010, at 23:28 , Alex Hall wrote: > On 8/4/10, Evert Rol wrote: >>>>> Further to my questions about overriding builtin methods earlier, how >>>>> would I make a class able to be accessed and changed using index >>>>> notation? For exa

Re: [Tutor] os.urandom()

2010-08-07 Thread Evert Rol
> > > using Vista, Python 3.1: > import os os.urandom(6) > b'\xd1\xfc\xb0\x14\xeaL' > > So what is this output? What in ascii? What in hex? Do those > questions even make sense? It returns just what it says in

Re: [Tutor] Need help understanding output...

2010-08-11 Thread Evert Rol
> I'm learning Python and I'm currently facing an issue with a small script I'm > writing. > > I need to generate a list of 30 numbers randomly chosen from 1, 2, 3, 4, 5 & > 6. However, I cannot have more than 2 numbers which are the same next to each > other. I came up with the following (Plea

Re: [Tutor] string conversion according to the terminal

2010-08-12 Thread Evert Rol
> Hey- suppose we have a file name-"my file number" > if we want to execute it into the terminal it would be like - my\ file\ number > > so wondering is there any one in the python that change the enter string into > the terminal string one- > like if user enter the file name with path- "my file

Re: [Tutor] string conversion according to the terminal

2010-08-12 Thread Evert Rol
> a = "my file number" > a.replace(' ', '\\ ') >> 'my\\ file\\ number' > > What if a has more than 1 space between words? Then I think this would > be a safer way. > print "\\ ".join("my file number".split()) > my\ file\ number If those spaces are in the actual filename, you'll wa

Re: [Tutor] string conversion according to the terminal

2010-08-12 Thread Evert Rol
> Ok. I appreciate ur response and its gud somewhat... But we dont have only > space=" " . this '\' rules also applies to '(' ')' and all that stuff also... > so i was looking for the builtin function that fully converts it... Is there > any one?? This may depend on your system, but generally,

Re: [Tutor] is it possible to call a setter property during class instantiation?

2010-08-12 Thread Evert Rol
> Does anyone know if it's possible to call a property setter inside of a > class's init method? Below is a code sample of what I'm trying to do. Just a quick guess: > class Question(object); replace the semi-colon with a colon (I assume it's just a typo, since you don't get an error for th

Re: [Tutor] Using Django with TortoiseSVN (overwriting files)

2010-08-16 Thread Evert Rol
> We have a project at work where myself and a co-developer are setting up > Django. Our version control software of choice is TortoiseSVN. > > When doing a project update from SVN, it pulls the server version to the > local project. When checking code in, it overwrites the server version of the

Re: [Tutor] reading from 2 file output to 1

2010-08-17 Thread Evert Rol
> I am trying to read from 2 CSV files, where first 4 ([0,1,2,3]) > columns are read from 'file1' and 3 columns ([1,2,3]) from 'file2' and > write them into a 3rd file 'file3', 7 columns string. The data is > Numeric values both, +ve and -ve. > > this is how i was trying. > >

Re: [Tutor] Getting confusing NameError

2010-08-18 Thread Evert Rol
> This is my first mail to this list so firstly thank you for reading and > apologies in advance for any noob mistakes i may have inadvertantly made:). > Ive only started learning python as my first programming language and its all > going well so far, working my way through a couple of books on

Re: [Tutor] Need help understanding output...

2010-08-18 Thread Evert Rol
On 18 Aug 2010, at 13:21 , Laurens Vets wrote: > On 8/12/2010 1:26 AM, Steven D'Aprano wrote: >> On Thu, 12 Aug 2010 07:04:15 am Laurens Vets wrote: >> >>> I need to generate a list of 30 numbers randomly chosen from 1, 2, 3, >>> 4, 5& 6. However, I cannot have more than 2 numbers which are the

Re: [Tutor] flow problem with a exercise

2010-08-21 Thread Evert Rol
> In [39]: t = 3 > > In [40]: round((t-32)/1.8) > Out[40]: -16.0 > > In [41]: t = 3.0 > > In [42]: round((t-32)/1.8) > Out[42]: -16.0 > > Works fine for me. > > Correct, > But I see one wierd thing. > > round ((42-32)/1.8) gives a output -16.0 but (42-32)/1.8) gives also -16.0 > I was expe

Re: [Tutor] check the terminal keyword

2010-08-21 Thread Evert Rol
> i m making a app in which i launch application using os.system("input from > user"). I want to check whether the input entered by the user matches with > the exact keyword in terminal or not. > like i want to launch vlc so user should provide me input as " vlc" in order > to launch the app jus

Re: [Tutor] prime test problem

2010-08-21 Thread Evert Rol
> Hello, > > I know. > I have read them all I believe but I can't see how I can convert the algebra > to a working programm. And if you just search Google for "Python prime number algorithm"? Perhaps it's cheating, so you'll have to try and fully understand the code first before you run it (

Re: [Tutor] prime test problem

2010-08-21 Thread Evert Rol
> Hello, > > I tried it with this simple programm > > def is_prime(n): > x=2 > while x <= int(n**0.5)+1: > if n % x == 0: > return False If your while condition is True, you get into the loop. Inside the loop, however, you never change anything t

Re: [Tutor] FW: find() problem

2010-08-24 Thread Evert Rol
> > > def find(strng, ch, start, step=1): > > > index = start > > The problem lies here, if you do a print on index, it never gets past > > the first index of the number, so > > your while loop below goes into an infinite loop. > > > > For example: > > find('starfruit','t',0) <- First time wil

Re: [Tutor] FW: find() problem

2010-08-24 Thread Evert Rol
> > > > > def find(strng, ch, start, step=1): > > > > > index = start > > > > The problem lies here, if you do a print on index, it never gets past > > > > the first index of the number, so > > > > your while loop below goes into an infinite loop. > > > > > > > > For example: > > > > find('starfru

Re: [Tutor] FW: find() problem

2010-08-24 Thread Evert Rol
> I found it. Good. Few generic comments nonetheless, just for the fun of it ;-). > This one does the trick : > > def find(strng, ch, start, step=1): > index=start > while 0 <= index < len(strng): > if strng[index] == ch: > return index > index += step >

Re: [Tutor] FW: find() problem

2010-08-24 Thread Evert Rol
>>> I found it. >> >> Good. >> Few generic comments nonetheless, just for the fun of it ;-). >> >>> This one does the trick : >>> >>> def find(strng, ch, start, step=1): >>> index=start >>> while 0 <= index < len(strng): >>> if strng[index] == ch: >>> return index >>> index += step >>> return -

Re: [Tutor] can this be done easerly

2010-08-30 Thread Evert Rol
> For a exerise I made this one :" > > import string > def extract_words(s): > """ > >>> extract_words('Now is the time! "Now", is the time? Yes, now.') > ['now', 'is', 'the', 'time', 'now', 'is', 'the', 'time', 'yes', 'now'] > >>> extract_words('she tried to curtsey as she

Re: [Tutor] nested functions

2010-09-04 Thread Evert Rol
> hello, > i have to plug two functions b() and c() inside another one a(); > i wonder if the code defining b and c must be in the same text file of > a or it is possible to import b and c somehow, hence giving the code a > neater appearance Definitely! Read through http://docs.python.org/tutorial

Re: [Tutor] for loop results into list

2010-09-05 Thread Evert Rol
> Hello all, > > I'm having a little problem figuring out how to accomplish this simple task. > I'd like to take a list of 6 numbers and add every permutation of those > numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1 + 1 +1 > then 1 + 1 + 1 +2 etc. until reaching 6 + 6 +

Re: [Tutor] for loop results into list

2010-09-05 Thread Evert Rol
>>> I'm having a little problem figuring out how to accomplish this simple >>> task. I'd like to take a list of 6 numbers and add every permutation of >>> those numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + 1 >>> + 1 +1 then 1 + 1 + 1 +2 etc. until reaching 6 + 6 + 6 + 6. U

Re: [Tutor] for loop results into list

2010-09-05 Thread Evert Rol
> > I'm having a little problem figuring out how to accomplish this simple > task. I'd like to take a list of 6 numbers and add every permutation of > those numbers in groups of four. For example for 1, 2, 3, 4, 5, 6 add 1 + > 1 + 1 +1 then 1 + 1 + 1 +2 etc. until reaching 6 + 6

Re: [Tutor] for loop results into list

2010-09-05 Thread Evert Rol
On 5 Sep 2010, at 22:31 , Micheal Beatty wrote: > On 09/05/2010 03:16 PM, Evert Rol wrote: >>>>>>> I'm having a little problem figuring out how to accomplish this simple >>>>>>> task. I'd like to take a list of 6 numbers and add every permu

Re: [Tutor] Python command calls the wrong version!

2010-09-07 Thread Evert Rol
> Dear Python Tutors, > > I am new to Python, having perviously used IDL for all my scripts. I was > hoping to use Python and so I have just downloaded and installed version 2.6 > using the mac installer. That all went fine. > > I then opened up X11, all fine. > > Then I typed in >python > >

Re: [Tutor] sort problem

2010-09-08 Thread Evert Rol
> I have this : > > def sort_sequence(seq): > """ > >>> sort_sequence([3, 4, 6, 7, 8, 2]) > [2, 3, 4, 6, 7, 8] > >>> sort_sequence((3, 4, 6, 7, 8, 2)) > (2, 3, 4, 6, 7, 8) > >>> sort_sequence("nothappy") > 'ahnoppty' > """ >if type(seq) == type([]):

Re: [Tutor] slicing a string

2010-09-08 Thread Evert Rol
>> But remember that you can make it simpler if you simply don't specify >> the start and end points: >> > 'hello'[::-1] >> 'olleh' >> > > While I know that idiom works, I haven't really found an explanation > as to *why* it works that way. > > For a string S: > * Using range, you need ran

Re: [Tutor] Exception Handling and Stack traces

2010-09-10 Thread Evert Rol
> I can't work out how to suppress stacktrace printing when exceptions > are thrown. > > I want the thrown exception to pass a message on the console, just > like Java does when I catch an exception and print e.getMessage(). > > I tried some of the examples of controlling traceback through the >

Re: [Tutor] Exception Handling and Stack traces

2010-09-10 Thread Evert Rol
>>> I can't work out how to suppress stacktrace printing when exceptions >>> are thrown. >> >> [snip rant] >> >> It might have been a good idea to read a tutorial like >> >> http://docs.python.org/tutorial/errors.html#handling-exceptions > >> or ask before you got annoyed enough to write that r

Re: [Tutor] Trapping HTTP Authentication Failure

2010-09-10 Thread Evert Rol
> My script to call a web service authenticates. Sorry, but where is the (full) script? I missed an attachment or (preferably) a link. > I would like to be > able to trap an exception if the authentication fails. The script > loops over a list of dates and I don't want it to retry for every

Re: [Tutor] smtp connection problem --- socket error 10061

2010-09-10 Thread Evert Rol
> I could not connect with gmail smtp server in Vista 32( worked ok in XP 32). > Both vista and xp have same anti-virus software. > smtplib.SMTP("smtp.gmail.com",587) > > Traceback (most recent call last): > File "", line 1, in >smtplib.SMTP("smtp.gmail.com",587) > File "C:\Program F

Re: [Tutor] Trapping HTTP Authentication Failure

2010-09-11 Thread Evert Rol
>>> My script to call a web service authenticates. > >> Sorry, but where is the (full) script? I missed an attachment or >> (preferably) a link. > > Hello, > > Sorry, the verb of the sentence is "authenticates," as in, "My script > ... authenticates." Sorry, misread that. Although code does

Re: [Tutor] Trapping HTTP Authentication Failure

2010-09-11 Thread Evert Rol
>> I'm not sure what you're exactly doing here, or what you're getting, >> but I did get curious and dug around urllib2.py. Apparently, there is >> a hardcoded 5 retries before the authentication really fails. So any >> stack trace would be the normal stack trace times 5. Not the 30 you >> mentio

Re: [Tutor] tree problem

2010-09-12 Thread Evert Rol
> Write a program named litter.py that creates an empty file named trash.txt in > each subdirectory of a directory tree given the root of the tree as an > argument (or the current directory as a default). > > So I change the example to this : > > def traverse(path, s='.\n', f=0, d=0): > path2f

Re: [Tutor] What's the best way to ask forgiveness here?

2010-09-13 Thread Evert Rol
> I've been coding Python long enough that 'asking forgiveness instead of > permission' is my first instinct, but the resulting code is sometimes clumsy, > and I wonder if someone can suggest something I'm missing, or at least > validate what's going on here in some way. > > What I'm trying to

Re: [Tutor] re.findall parentheses problem

2010-09-14 Thread Evert Rol
> I have a regex that matches dates in various formats. I've tested the regex > in a reliable testbed, and it seems to match what I want (dates in formats > like "1 Jan 2010" and "January 1, 2010" and also "January 2008"). It's just > that using re.findall with it is giving me weird output. I

Re: [Tutor] what happened to the cards module

2010-09-15 Thread Evert Rol
> I downloaded Python 2.6.6 for windows but I can't access the "Cards" module > for playing card games. > > Did it get renamed? If so, how can I find it? I don't think there's a Cards module in the standard library. At least, I've never seen it, nor can I find any mention about it on the python

Re: [Tutor] selecting elements from dictionary

2010-09-15 Thread Evert Rol
> using: > > for key, value in xdic.items(): > if 1 in value and 2 in value or 3 in value: > print key > > > also print keys that have values such as [1,2,3]. > > In cases where there is [1,2,3] and [1,2] also reported. > > How can I extract those keys that have values only [1,2]

Re: [Tutor] what happened to the cards module

2010-09-15 Thread Evert Rol
saw this, and if it's useful and usable to you. And I certainly don't know what you mean by a card playing framework: do you mean (library) code, which language, what "card game"? Evert > Thanks. > > John Soares > jsoa...@safe-mail.net > > Ori

Re: [Tutor] quick speed question

2010-09-16 Thread Evert Rol
> Hello Tutors, > > I was just wondering if you have a dictionary key is it faster to do: > > if dict['key'] == 'foo': >... > > or is this faster: > > if 'foo' in dict['key']: >... > > Or is there any difference and I'm chasing ghosts? The latter: they are not the same: >>> d = {'key

Re: [Tutor] Function behavior

2010-09-16 Thread Evert Rol
> I am unclear on the behavior of using a function. Below is a short code I > wrote to print an amount out after inputting the number of match. > > # TEST Function.py > > def change(amount): >if match == 1: >amount = 0 >if match == 2: >amount = 0 >if match == 3: >

Re: [Tutor] robots question

2010-09-16 Thread Evert Rol
> As a exercise from this book ( Thinking like a computer scientist ) I have to > make this programm on this > page(http://openbookproject.net/thinkcs/python/english2e/ch12.html) > Exercise 11 > > # > # robots.py > # > from gasp import * Argh! Is that really in the book? Bad book, bad. You c

Re: [Tutor] Bus Error with matplotlib

2010-09-17 Thread Evert Rol
> Hi, I have been trying to install matplotlib for python on my mac which is > running snow leopard. The installation appeared to go well until I tried the > following > >> python import matplotlib import matplotlib.pyplot > Bus error >> > > It is very annoying, I have posted the err

Re: [Tutor] trouble with a small Tkinter example

2010-09-21 Thread Evert Rol
> I'm having trouble with this small example program: > > http://en.literateprograms.org/Bresenham%27s_line_algorithm_%28Python%29 > > When I run it, I only get a blank grey window. I'm running Python 2.6 under > Windows XP. > > If there's a problem with the code, I can't see it... it seems lik

Re: [Tutor] input and raw input

2010-09-25 Thread Evert Rol
> any one have an idea about how we can input many number in the one time and > change it to list. > for example: > > a=input("Enter the number of your class in the school:") # the number can > be enter as: 12,13,14 or 12 13 14 with a space in between. > > now how I can put these numbers

Re: [Tutor] Tutor Digest, Vol 79, Issue 134

2010-09-25 Thread Evert Rol
> I started seting up django. the only issue I am having is that all > instructions seem to assume that I am on linux.Don't suppose there are any > good instructions for those on a windows based system. Firstly: please don't reply to an unrelated message, but start a new one (with a proper subj

Re: [Tutor] input and raw input

2010-09-25 Thread Evert Rol
> > any one have an idea about how we can input many number in the one time and > > change it to list. > > for example: > > > > a=input("Enter the number of your class in the school:") # the number > > can be enter as: 12,13,14 or 12 13 14 with a space in between. > > > > now how I can put th

Re: [Tutor] dynamic arrays?

2010-09-27 Thread Evert Rol
> One thing I have never much liked about Python is its need for > specifically sized arrays and lack of a dynamic, array-like data > structure. For example, the following fails with a "list assignment > index out of range" error: > > a=[] > i=0 > for l in open("file.txt", "r"): > a[i]=l > i+=1

Re: [Tutor] function with multiple checks

2010-09-27 Thread Evert Rol
> I've got a small function that I'm using to check whether a password is of a > certain length and contains mixed case, numbers and punctuation. > > Originally I was using multiple "if re.search" for the patterns but it looked > terrible so I've read up on list comprehensions and it's slightly

Re: [Tutor] unittest testing order...

2010-09-27 Thread Evert Rol
>> List, >> >> When using the unittest module, tests are run in alphanumeric order. >> What's the suggested way of specifying a test order? > > There isn't one. It shouldn't matter what order the tests run, no test > should *rely* on another test. > > (Although of course, if one test fails, a

Re: [Tutor] pyMVPA and OSError

2010-09-28 Thread Evert Rol
Hi, > I am very much new to python, and thus I am likely to feel stupid about > asking. But I need to get past this to continue with my work. > I need pyMVPA module to run some analysis on fMRI data, but as a start I want > to at first play around with the sample data provided on pyMVPA websit

Re: [Tutor] function error

2010-09-28 Thread Evert Rol
>> It seems that ur turtle.position doesn't return a list because of this when >> indexing is done on that u get this kind of error. >> --nitin > > it seemed to me that kind of error but then i found that it was a > list, as expected: > > $ type(turtle.position()) > $ > $ abs(turtle.position()[

Re: [Tutor] Problems install Python

2010-09-29 Thread Evert Rol
> I had just download PeGreSQL, unzip and installed it, but I have a problem > such as: > > phuong...@ubuntu:~/PyGreSQL-4.0$ python setup.py build > sh: pg_config: not found > Traceback (most recent call last): > File "setup.py", line 94, in > pg_include_dir = pg_config('includedir') > F

Re: [Tutor] function error

2010-09-29 Thread Evert Rol
>> Perhaps if you provide the full traceback from the error (assuming you're >> still getting this >error); tracebacks generally show the offending code as >> well. It may be something that's >simply overlooked but shows in the >> traceback. >> >> > > here it is: > > TypeError

Re: [Tutor] inheritance problem

2010-09-30 Thread Evert Rol
Hi Roelof, > Im following this page : > http://openbookproject.net/thinkcs/python/english2e/ch17.html I just checked this, and it appears you've copied this example fine. > class Deck: >def __init__(self): >self.cards = [] >for suit in range(4): >for rank in

Re: [Tutor] Networking

2010-10-02 Thread Evert Rol
> Dear Tutors, > I have attached my 2 programs for networking. It uses socket and > SocketServer, but it just simplifies it even more. The problem is it won't > work. The Client raises the error, (with trace back) > Traceback (most recent call last): > File "G:\My Dropbox\My Dropbox\Chris\N

Re: [Tutor] specifying precision with scientific notation

2010-10-05 Thread Evert Rol
> I want to print scientific numbers with a specified number of decimal places. > However, I want the number printed to be dynamically determined by the data. > Example: > >> a = 0.00762921383941 >> ea = 0.000830132912068 >> a / ea > 9.190352205653852 > > By default, I will print the uncertai

Re: [Tutor] pymssql and encoding

2010-10-07 Thread Evert Rol
> >>> print customerName > ImmobiliŠre (whatever) > >>> customerName > 'Immobili\x8are (whatever)' > > There should be a small E with a grave accent (è) instead of the capital S > with a caron (Š) I'm getting. > > I've tried applying various encodings, but to no avail: > > When executed from

Re: [Tutor] wrap methods for logging purposes

2010-10-07 Thread Evert Rol
> I used a the recipe (http://aspn.activestate.com/ASPN/Coo.../Recipe/198078) > used to wrap methods for logging purposes. logging classes. But it does seem > to work well with classes inherit form other classes - i get recursion > errors! > > Here is an example of the classes .. > > class

Re: [Tutor] Non-ASCII

2010-10-07 Thread Evert Rol
> I'm going through an online tutorial for Jython (www.jython.org). I can't > find a place to ask a question on that site so I thought I'd try here. I > believe the code is supposed to traverse a directory, identifying file types. > The script is failing with the following message: > > File ""

Re: [Tutor] Rounding a Python float to the nearest half integer

2010-10-08 Thread Evert Rol
> I realise that one cannot have a half integer :) I meant how would one round > off to the first decimal nearest to either 0.5, or a whole number. > > Ugh...does anyone get what I'm trying to articulate? :) Multiply by 2, round(), divide by 2? > > On Fri, Oct 8, 2010 at 2:51 PM, Sithembewena

Re: [Tutor] Rounding a Python float to the nearest half integer

2010-10-08 Thread Evert Rol
> @Evert, I didn't figure out that your response was a solution, thought it was > a question. Must be coffee time :P > > I tried it and, for instance, the rounded value (9) / 2 gave me 4.0 Couldn't > get it until I noticed that @Joel divided the roudned figure by a decimal > 2.0. That gave 4.5,

Re: [Tutor] OpenMP

2010-10-09 Thread Evert Rol
> Hi, > I have searched about how to use openMP using python and I couldn't fine any > helpful info. anyone can help me on this. No openMP, but iPython could do what you want (parallel and some distributed computing): http://ipython.scipy.org/doc/stable/html/ Evert > > My idea is that to

Re: [Tutor] Multiple regex replacements, lists and for.

2010-10-12 Thread Evert Rol
> I'm new to python and inexperienced in programming but I'm trying hard. > I have a shell script that I'm converting over to python. > Part of the script replaces some lines of text. > I can do this in python, and get the output I want, but so far only using sed. > Here's an example script: > > i

Re: [Tutor] urllib problem

2010-10-12 Thread Evert Rol
> I have this program : > > import urllib > import re > f = > urllib.urlopen("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=6";) > inhoud = f.read() > f.close() > nummer = re.search('[0-9]', inhoud) > volgende = int(nummer.group()) > teller = 1 > while teller <= 3 : > url = "

Re: [Tutor] Writing elements of an array to a file using CSV module

2010-10-14 Thread Evert Rol
> I have a numpy array ('data') that is the result of reading a netCDF > file, and it typically looks like this: > > array([ 0., 0., 0., 0.], dtype=float32) > > > I want to write this, after a date and time, to a CSV file, so the CSV > file would have the entry: > >2000-02-01,09:00,0.0,0

Re: [Tutor] Writing elements of an array to a file using CSV module

2010-10-14 Thread Evert Rol
umber > - > > I tried the other suggestion on the list (posted by Alan Gould), > namely to replace the %f formatting string with %s in the > write.writerow statement: > - > writer.writerow( ( file_details[0], file_details[1], str(data[0]) ) ) > - > > Thi

Re: [Tutor] Networking

2010-10-14 Thread Evert Rol
Hi Chris, Bit hard to comment on the actual code, as it was in attachments, but the important bit is here: class Handler(SocketServer.BaseRequestHandler): #the handler '''A handler which calls %s in the handle method.'''%handle_func def handle(self): #the handle method

Re: [Tutor] Networking

2010-10-14 Thread Evert Rol
>>> But what if I want it to serve one client, go to another and then go back. >>> How does that work? > > You do some I/O multi-plexing or multi-processing/threading. > > You might want to do some reading on this. The very last example on http://docs.python.org/library/socketserver.html may he

Re: [Tutor] What's the best way to model an unfair coin?

2010-10-24 Thread Evert Rol
> What's the best way to model an unfair coin? > > This is one way to do it, I suppose: Create a list containing only > 'H's and 'T's. If you want the coin to have the probability of a head > to be 6/11, > > ['H', 'H', 'H', 'H', 'H', 'H', 'T', 'T', 'T', 'T', 'T'] > > is the list to use. Use rand

Re: [Tutor] What's the best way to model an unfair coin?

2010-10-24 Thread Evert Rol
> Btw, to be pedantic, 1/e is not an irrational number, just a real number. i/e > would be. My bad: irrational != imaginary. And real = irrational. Things are definitely a bit rusty... ___ Tutor maillist - Tutor@python.org To unsubscribe or change s

Re: [Tutor] What's the best way to model an unfair coin?

2010-10-24 Thread Evert Rol
> Actually, I used the unfair coin model as the simplest example of the > kind of thing I want to do -- which is to model the USD->Yen exchange > rate. I want the next quote to vary in a controlled random way, by > assigning probabilities to various possible changes in the rate. See >

Re: [Tutor] possible to run a python script from non-cgi?

2010-10-30 Thread Evert Rol
> FYI: I am working in a linux environment with python 2.6.5 > am an experienced web developer with 8 years in python, but > :) I have never tried this trick before: > > I note that with the right .htaccess file, I can run a php file, > from a non-cgi location. > Example: On my machine, my wwwroot

Re: [Tutor] scope, visibility?

2010-11-01 Thread Evert Rol
> Here is my main class: > > class PenduGTK: > > Inside the class is a method with a bit of code: > > def masque(chaine,liInd=0): > > i = 0 > lenght = len(chaine) > > The offending line is the one with len(chaine) > > Here are the error messages: > > penduGTK.py > Trace

Re: [Tutor] How to copy file from a source, I do not know the source file name, Only path to the src directory I know

2010-11-09 Thread Evert Rol
> Hi All > I am trying our "Python" . > My aim is to copy a file to a location and later removing the > file.I had written a small script which works.It works only if I > specify the source file name. I would like to make it work in a > scenario in which I do not know the name of the source fil

Re: [Tutor] How to copy file from a source, I do not know the source file name, Only path to the src directory I know

2010-11-09 Thread Evert Rol
rinciple) OS-agnostic. Also, if you use 'os.listdir(src)', why not use src again when assigning ffname? Cheers, Evert > print ffname > #shutil.copy(ffname,dst2) > shutil.move(ffname,dst3) > " > > > On Tue, Nov 9, 2010 at 4:38 PM, Evert Rol

  1   2   >