Re: [Tutor] (no subject)

2010-05-11 Thread Dave Angel
it belongs. Sivapathasuntha Aruliah wrote: Dave Thank you very much for your response. I think I have problem with both Python23 & Python31. Please help. Python23 : The program works but programs written by Mark Summerfield in his book Programming in Python3 does not work. Python 31: When

Re: [Tutor] First steps for C++/Qt developers

2010-05-12 Thread Dave Angel
M. Bashir Al-Noimi wrote: humm, you confused me I'm still a newbie and I don't know anything about differences between C++ & python even I couldn't understand you. How C++ is a static language !??!! In C++, every variable is declared, and the type of that variable is static over its

Re: [Tutor] Find Elements in List That Equal A Specific Value

2010-05-12 Thread Dave Angel
Su Chu wrote: Hi there, I am new to Python. I am attempting to either define a "which" statement or to find a method that already exists to do this sort of operation. My problem is as follows: I have three lists, one with unique values (list 1), one a sequence of values that are not necessarily

Re: [Tutor] raw_input a directory path

2010-05-12 Thread Dave Angel
Spencer Parker wrote: Here is the code: http://dpaste.com/hold/193862/ It still isn't working for me. I don't see it hitting the first for loop or even the second one. It runs without an error at all. I am inputing the directory as: \\Documents\ and\ Settings

Re: [Tutor] Design Question: File Object used everywhere

2010-05-14 Thread Dave Angel
Jan Jansen wrote: Hi there, I'm working on a code to read and write large amounts of binary data according to a given specification. In the specification there are a lot of "segments" defined. The segments in turn have defintions of datatypes and what they represent, how many of some of the d

Re: [Tutor] Help

2010-05-15 Thread Dave Angel
she haohao wrote: > Hi, > > I have some questions that I am unable to figure out. > > Let say I have a file name peaks.txt. > > Chr17 9 4.5 5.5 > chr10 6 9 3.5 4.5 > chr1 10 6 2.5 4.4 > > Question is how can i sort the fi

Re: [Tutor] Help

2010-05-15 Thread Dave Angel
(You forgot to post to the list. Normally, you can just do a reply-all to get both the list, and the person who last responded. You also top-posted, rather than putting your new message at the end. I'll now continue at the end.) she haohao wrote: > I am stuck because i dont know how do i extract a

Re: [Tutor] PYTHON 3.1

2010-05-18 Thread Dave Angel
(Please don't top-post. Add your comments to the end of the portion you're quoting.) Dipo Elegbede wrote: thanks a lot. i was almost going to abandon this python again out of frustration. i have done it before but with you guys around, it would never happen again. i have a pdf version of pyt

Re: [Tutor] Unit testing command-line options from argparse or optparse

2010-05-19 Thread Dave Angel
Serdar Tumgoren wrote: Hello all, Does anyone have advice for writing unit tests against variables set by command-line options? I have a program I'd like to run in either "debug" or "live" mode, with various settings associated with each. Below is some pseudo-code that shows what I'd like to do

Re: [Tutor] 2d list index inverting?

2010-05-26 Thread Dave Angel
Hugo Arts wrote: On Wed, May 26, 2010 at 3:13 AM, Alex Hall wrote: Hello all, I have a 2d list being used for a battleship game. I have structured the program so that it uses a grid class, which implements this array along with a bunch of other methods and vars. For example, to get at the to

Re: [Tutor] parse text file

2010-06-03 Thread Dave Angel
Colin Talbert wrote: You are so correct. I'd been trying numerous things to read in this file and had deleted the code that I meant to put here and so wrote this from memory incorrectly. The code that I wrote should have been: import bz2 input_file = bz2.BZ2File(r'C:\temp\planet-latest.osm

Re: [Tutor] Misc question about scoping

2010-06-04 Thread Dave Angel
Alan Gauld wrote: flag = True if (smoeValue or another) else False is different to flag = someValue or another Which was why I thought it worth pointing out that the if/else could be used. I'd prefer the form: flag = not not (someValue or another) if I needed real True or False resul

Re: [Tutor] Misc question about scoping

2010-06-04 Thread Dave Angel
Hugo Arts wrote: On Fri, Jun 4, 2010 at 1:23 PM, Dave Angel wrote: I'd prefer the form: flag =ot not (someValue or another) That's a construct you might commonly find in languages like C, but I don't think it's very pythonic. If you want to convert your

Re: [Tutor] no. of references

2010-06-08 Thread Dave Angel
Payal wrote: Hi, If I have a list (or a dict), is there any way of knowing how many other variables are referencing the same object? With warm regards, -Payal Depends on what you mean by variables. Try sys.getrefcount(mylist) Naturally, the count will be one higher than you expect. And

Re: [Tutor] Extract from file

2010-06-09 Thread Dave Kuhlman
ally, if you are sure that there are no commas inside of quotes in your input data. However, it seems that you are dealing with a CSV (comma separated values) file. Python has a module for that. See: http://docs.python.org/library/csv.html That module might help you write safer code. --

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Dave Angel
Ken G. wrote: I have been working on this problem for several days and I am not making any progress. I have a group of 18 number, in ascending order, within a list. They ranged from 1 to 39. Some numbers are duplicated as much as three times or as few as none. I started with one list conta

Re: [Tutor] Looking for duplicates within a list

2010-06-11 Thread Dave Kuhlman
o o See http://docs.python.org/library/functions.html#enumerate - Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] What's the catch with ZopeDB?

2010-06-11 Thread Dave Kuhlman
it on top of several different relational database engines, for example, PostgreSQL, MySQL, sqlite3, etc. See: http://docs.djangoproject.com/en/1.2/#the-model-layer http://www.djangobook.com/en/2.0/chapter05/ - Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman ___

Re: [Tutor] New to Programming

2010-06-12 Thread Dave Angel
Kaushal Shriyan wrote: Hi, I am absolutely new to programming language. Dont have any programming experience. Can some one guide me please. is python a good start for novice. Thanks, Kaushal Like nearly all questions, the answer is "it depends." Mainly, it depends on what your goal is.

Re: [Tutor] string encoding

2010-06-18 Thread Dave Angel
Rick Pasotto wrote: I can print the string fine. It's f.write(string_with_unicode) that fails with: UnicodeEncodeError: 'ascii' codec can't encode characters in position 31-32: ordinal not in range(128) Shouldn't I be able to f.write() *any* 8bit byte(s)? repr() gives: u"Realtors\\xc2\\xae"

Re: [Tutor] Question

2010-06-19 Thread Dave Angel
Alan Gauld wrote: "Independent Learner" wrote ~I was wondering if I should try to learn 2 programming languages at once, Python and C++. No, no no! If it had been a different pair I might have said try it. But C++ is one of the most difficult, complex and difficult programming lamnguages ou

Re: [Tutor] Time

2010-06-22 Thread Dave Angel
Ahmed AL-Masri wrote: Hi, I would calculate the running time of my simulation code. any one know how to do that? example def demo(): ### the starting point of time should be 0 f.simulate(data) ### the end of the class so need to find the time in Sec.? #

Re: [Tutor] Repeat function until...

2010-06-23 Thread Dave Angel
Steven D'Aprano wrote: On Wed, 23 Jun 2010 10:29:11 pm Nethirlon . wrote: Hello everyone, I'm new at programming with python and have a question about how I can solve my problem the correct way. Please forgive my grammar, English is not my primary language. I'm looking for a way to repeat

Re: [Tutor] Use flag to exit? (OT - PEP 8 Gripe)

2010-06-25 Thread Dave Angel
Richard D. Moores wrote: On Fri, Jun 25, 2010 at 09:48, Emile van Sebille wrote: On 6/25/2010 9:08 AM Steve Willoughby said... On 25-Jun-10 08:23, Emile van Sebille wrote: On 6/25/2010 1:33 AM ALAN GAULD said... Copy and pasting is a PITA. Why would you

Re: [Tutor] Use flag to exit? (OT - PEP 8 Gripe)

2010-06-25 Thread Dave Angel
Richard D. Moores wrote: On Fri, Jun 25, 2010 at 23:08, Dave Angel wrote: Do you activate Quick-Edit mode in your DOS box? Once you have that on, it's not much of a pain to copy and paste, as long as what you're copying fits a rectangle. Yes, it's on. I agree that

Re: [Tutor] Use flag to exit? (OT - PEP 8 Gripe)

2010-06-26 Thread Dave Angel
Richard D. Moores wrote: On Fri, Jun 25, 2010 at 23:42, Dave Angel wrote: Richard D. Moores wrote: On Fri, Jun 25, 2010 at 23:08, Dave Angel wrote: Do you activate Quick-Edit mode in your DOS box? Once you have that on, it's not much of a pain to copy and paste, as lo

Re: [Tutor] the ball needs a kick...

2010-07-06 Thread Dave Angel
Schoap D wrote: Hi, I'm doing the exercises here: chapter 8 http://www.openbookproject.net/thinkCSpy/ch08.html Now I have added another paddle to the pong game. So far so good, but the ball isn't moving anymore and I am not able to fix it... Any comments, tips, feedback? Thanks in advance, ht

Re: [Tutor] extract a submatrix

2010-07-12 Thread Dave Angel
Bala subramanian wrote: Friends, Excuse me if this question is not appropriate for this forum. I have a matrix of size 550,550. I want to extract only part of this matrix say first 330 elements, i dnt need the last 220 elements in the matrix. is there any function in numpy that can do this kind

Re: [Tutor] Help

2010-07-13 Thread Dave Angel
Dipo Elegbede wrote: I was trying to write a code that prints prime numbers between 1 and 20. I have by myself seen that something is wrong with my code and also my brain. Could anyone be kind enough to tell me what to do Where I am confused is how to test for other numbers without one and

Re: [Tutor] Global name not found, though clearly in use

2010-07-14 Thread Dave Angel
Corey Richardson wrote: The entirety of my (incomplete and buggy) code is now available here: http://pastebin.com/QTNmKYC6 .. Hmm..If I add a few debugging lines like that into my code, I get this: Starting program In class Hangman done defs in class eWordEntryBox defined Exception in Tki

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-17 Thread Dave Angel
Richard D. Moores wrote: That's the goal of the latest version of my script at . The best I've been able to do so far is a file with 800 million digits. But it seems the writing of 800 million digits is the limit for the amount of memory my laptop has (4 GB

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-18 Thread Dave Angel
Richard D. Moores wrote: On Sat, Jul 17, 2010 at 18:01, Steven D'Aprano wrote: import random def random_digits(n): "Return n random digits with one call to random." return "%0*d" % (n, random.randrange(10**n)) Thanks for implementing what I was suggesting, using zero-fill for

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-18 Thread Dave Angel
Steven D'Aprano wrote: On Sun, 18 Jul 2010 08:30:05 pm Richard D. Moores wrote: What do you mean, "couldn't handle"? Couldn't handle 800 million of what? Obviously not bytes, because your laptop *can* handle well over 800 million bytes. It has 4GB of memory, after all :) This is just

Re: [Tutor] Calculating and returning possible combinations of elements from a given set

2010-07-27 Thread Dave Angel
ZUXOXUS wrote: Oh, I think i got it: for prod in itertools.product('ABC', 'ABC'): print(prod) ('A', 'A') ('A', 'B') ('A', 'C') ('B', 'A') ('B', 'B') ('B', 'C') ('C', 'A') ('C', 'B') ('C', 'C') Thank you very much!! 2010/7/28 ZUXOXUS You're top-posting, which loses all the

Re: [Tutor] Calculating and returning possible combinations of elements from a given set

2010-07-28 Thread Dave Angel
ZUXOXUS wrote: 2010/7/28 Dave Angel Your latest version gets the product of two. But if you want an arbitrary number, instead of repeating the iterable ('ABC' in your case), you can use a repeat count. That's presumably what you were trying to do in your earlier incantation.

Re: [Tutor] Calculating and returning possible combinations of elements from a given set

2010-07-28 Thread Dave Angel
ZUXOXUS wrote: My doubt now is whether I can change the way python show the combinations. I mean, here's what python actually does: for prod in itertools.product('abc', repeat=3): print(prod) ('a', 'a', 'a') ('a', 'a', 'b') ('a', 'a', 'c') ('a', 'b', 'a') ('a', 'b', 'b') ('a', '

Re: [Tutor] Order Of Operations Question

2010-07-28 Thread Dave Angel
David Hutto wrote: I'll probably ending up reading something about it later in the book, but as a quick question, why does: 5e18 =5**18 False int(5e18) =int(5**18) False 1.01325e5 =1.01325**5 False The 999e44 notation is intended to be similar t

Re: [Tutor] Making a sound

2010-07-31 Thread Dave Angel
Michael Bernhard Arp S wrote: Greetings, programs. How do I create a sound from python? I'm thinking along the line of generating a sinus wave where I can control the frequency and duration. I want to produce a string of sounds based on a character string. Probabl

Re: [Tutor] Writing scripts and apps for Internet consumption

2010-07-31 Thread Dave Angel
Eric Hamiter wrote: On Sat, Jul 31, 2010 at 4:48 PM, bob gailer wrote: Please post that code, and the URL you use to invoke it. test.py: this works on my laptop but not on the server http://pastebin.com/ChjUzLRU test-working.py: this works on both laptop & server http://pastebin

Re: [Tutor] access class through indexing?

2010-08-04 Thread Dave Angel
Alex Hall wrote: On 8/4/10, Evert Rol wrote: That depends how you create the Pile of 52 cards: list(52) also doesn't generate 52 (random) items. If you override __init__ to accept an integer that generates the cards for you, this should work. Here is my init, not half as pretty as you

Re: [Tutor] Reading every 5th line

2010-08-08 Thread Dave Angel
nitin chandra wrote: Hello Everyone, I am to make a small programme for a friend of mine where i am to start reading from 14th (string) from a file and then read every 5th row. ie. in 1st read it reads the 14 row in a File, write to an OUTPUT-1 file Next reads 19th row, write to the OUTPUT-1 f

Re: [Tutor] word_probles.py

2010-08-08 Thread Dave Angel
Shurui Liu wrote: Okay. I am using WinXP, Python 3.1 on my workstation. And this is the Python version information I got from putty.exe: Python 2.5.4 (r254:67916, Apr 13 2009, 18:09:11) [GCC 4.2.1 20070719 [FreeBSD]] on freebsd7 You cannot use the same python source on 2.5 as you do in 3.1

Re: [Tutor] os.urandom()

2010-08-09 Thread Dave Angel
Richard D. Moores wrote: On Sun, Aug 8, 2010 at 08:11, bob gailer wrote: On 8/8/2010 1:57 AM, Richard D. Moores wrote: How were we supposed to know that all the hexes have 2 digits? In version 2.6.5 Language Reference 2.4.1 - String literals: \xhh Character with hex value

Re: [Tutor] Reading every 5th line

2010-08-09 Thread Dave Angel
nitin chandra wrote: This may help you get started. FileNames ="FileName01", "FileName02", ..., "FileName24"] for File in FileNames: List =pen(File, 'r').readlines() for Start in [[14, "%s-1" % File], [15,"%s-2" % File]]: OutList =] for Line in range(Start[0]-1, 3024, 5):

Re: [Tutor] os.urandom()

2010-08-09 Thread Dave Angel
Steven D'Aprano wrote: On Mon, 9 Aug 2010 07:23:56 pm Dave Angel wrote: Big difference between 2.x and 3.x. In 3.x, strings are Unicode, and may be stored either in 16bit or 32bit form (Windows usually compiled using the former, and Linux the latter). That's an internal st

Re: [Tutor] os.urandom()

2010-08-09 Thread Dave Angel
Steven D'Aprano wrote: On Mon, 9 Aug 2010 11:51:34 pm you wrote: (Context: Python 3.x, where strings are unicode.) repr() returns the string representation, not the byte representation. Try this: That's what I was missing. Somehow I assumed it was converting to byte strings. I

Re: [Tutor] os.urandom()

2010-08-10 Thread Dave Angel
Steven D'Aprano wrote: On Tue, 10 Aug 2010 02:24:00 pm Dave Angel wrote: Any suggestions how to fix the Windows console to interpret utf8? I don't know about Windows, but under Linux there is a menu command for most xterms that let you set it. Googling led me to this pa

Re: [Tutor] Performance list vs. deque for [-1]

2010-08-12 Thread Dave Angel
Knacktus wrote: Hi everyone, I'm wondering what's the fastet datatype in python to lookup the last element in an ordered collection. I know about lists, of course, and read about deques. As I understand deques have better performance for popping and adding elements, but I didn't understand wh

Re: [Tutor] UTF-8 character

2010-08-12 Thread Dave Angel
Evidenca B d.o.o. wrote: Hi. I have a problem. I am making pa program which, makes a .txt document, the problem is in my language have special character like this: č,š,ž. They don t appear in aschi code, but you can find them in UTF-8 code. So wen I wont to save with writelines a string with

Re: [Tutor] Question about Dictionaries

2010-08-16 Thread Dave Angel
Chorn, Guillaume wrote: Hi All, I know that I can look up the value for a particular key in a dictionary, but can I look up the key associated with a particular value? I understand that this could be problematic from the standpoint of multiple keys having the same value, but even then I feel li

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

2010-08-18 Thread Dave Angel
Laurens Vets wrote: Yes of course :) That's a typo on my part. I came up with the following which I think works as well? import random reeks = [] for i in range(60): temp = [random.randint(1, 6)] while reeks[-2:-1] == reeks[-1:] == temp: temp = [random.randint(1, 6)] if reeks.

Re: [Tutor] List comprehension for dicts?

2010-08-19 Thread Dave Angel
(You top-posted, so now I have to delete the older part) Vince Spicer wrote: Hey you can use list comprehension here age_dict = { 'pete': 42, 'ann': 25, 'carl': 30, 'amanda': 64 } you can create a dict from a list of tuples and you can access the dict as a list of tuples by accessing its items

Re: [Tutor] flow problem with a exercise

2010-08-19 Thread Dave Angel
Roelof Wobben wrote: def is_odd(argument): uitkomst=is_even(argument) return uitkomst You forgot to indent the return statement to match the other statement(s) in the function. DaveA ___ Tutor maillist - Tutor@python.org To un

Re: [Tutor] flow problem with a exercise

2010-08-21 Thread Dave Angel
You need to figure out how to get your email program to do quoting. As it stands, there's no good way to tell what part of the following message was from you, and what part was from wayne, or maybe others. Probably all you need to do is to do a reply-all to the message, and it'll mark the ex

Re: [Tutor] exercise problem

2010-08-27 Thread Dave Angel
(Don't top-post, it loses all the context) Roelof Wobben wrote: Hello, Now I have this : def add_vectors(u, v): """ >>> add_vectors([1, 0], [1, 1]) [2, 1] >>> add_vectors([1, 2], [1, 4]) [2, 6] >>> add_vectors([1, 2, 1], [1, 4, 3]) [2, 6, 4]

Re: [Tutor] exercise problem

2010-08-27 Thread Dave Angel
Roelof Wobben wrote: Date: Fri, 27 Aug 2010 14:27:34 -0400 From: da...@ieee.org To: rwob...@hotmail.com CC: alan.ga...@btinternet.com; tutor@python.org Subject: Re: [Tutor] exercise problem The other problem is you're confusing the variables inside the function with the ones declared outside

Re: [Tutor] project euler prime factorization problem

2010-08-29 Thread Dave Angel
Steven D'Aprano wrote: On Mon, 30 Aug 2010 05:31:00 am bob gailer wrote: My current reasoning was something of this sort: Find all the factors of a number, then reduce them to just the prime factors Very inefficient. IMHO the proper way is to generate a list of all the prime numbers

Re: [Tutor] Giving a name to a function and calling it, rather than calling the function directly

2010-09-04 Thread Dave Angel
lists wrote: Hi folks, I'm new to Python, I'm working my way through some intro books, and I have a question that I wonder if someone could help me with please? This is my attempt at solving an exercise where the program is supposed to flip a coin 100 times and then tell you the number of heads

Re: [Tutor] iterating over less than a full list

2010-09-04 Thread Dave Angel
Bill Allen wrote: Say I have and iterable called some_stuff which is thousands of items in length and I am looping thru it as such: for x in some_stuff etc... However, what if I want only to iterate through only the first ten items of some_stuff, for testing purposes. Is there a concise

Re: [Tutor] iterating over less than a full list

2010-09-05 Thread Dave Angel
Bill Allen wrote: Thanks to everyone who replied. Some of the methods presented where some I had thought of, others were new to me. Particularly, I did not realize I could apply a slice to a list. The for x in some_stuff[:value] form worked very well for my purposes. I can also see I need

Re: [Tutor] Multiple versions of python and paths problems

2010-09-06 Thread Dave Angel
On 2:59 PM, Dominique wrote: = but it's really not fun working with this bloody windows console where cut and paste is impossible... Cut and paste work fine in a Windows DOS console. Using Properties, the Options tab, turn on Quick-Edit mode. Once you've done that, you can select a recta

Re: [Tutor] how to create a persistent dictionary w/ cpickle?

2010-09-08 Thread Dave Angel
On 2:59 PM, Carter Danforth wrote: Hi, I'm trying to a create a basic addressbook for practice. I'm using a dictionary with cpickle, though I'm not sure how to persistently store each instance in the dictionary. Below is the code I have so far. If I run it once and add a contact and the details

Re: [Tutor] exceptions problem

2010-09-10 Thread Dave Angel
On 2:59 PM, Roelof Wobben wrote: Now I thought this would work:def readposint(): x = raw_input("Please enter a positive integer :") try: x = int(x) and x> 0 except: print x , "is not a positive integer. Try again." return False return Truey = rea

Re: [Tutor] hashlib problems

2010-09-10 Thread Dave Angel
On 2:59 PM, Rance Hall wrote: Im wanting to use the builtin hashlib functions to encrypt passwords before storing them in a database. According to documentation on the python.org site it should be as simple as import hashlib hashname = hashlib.sha234 (or whatever other hash method you want

Re: [Tutor] exceptions problem

2010-09-11 Thread Dave Angel
On 2:59 PM, Roelof Wobben wrote: Hello Bob, Oke, I try to fish. When I do x="a" y=nt(x) Then I get ValueError. When I do x= 1.2 y=int(x) No exception is raised. But when I do then x = I get a false. When I now do float(x) - int(x) I get 1.2 - 1 =.2 and that's greater then 0 Because one

Re: [Tutor] forcing hashlib to has string variables

2010-09-12 Thread Dave Angel
On 2:59 PM, Rance Hall wrote: Everybody knows you don't store plain text passwords in a database, you store hashes instead consider: userpass = getpass.getpass("User password? ") encuserpass = hashlib.md5() encuserpass.update(userpass) del userpass Now the documentation clearly states th

Re: [Tutor] forcing hashlib to has string variables

2010-09-12 Thread Dave Angel
On 2:59 PM, Rance Hall wrote: Luke: On python3.1 I get the following error using your (untested) two line snippet: TypeError: Unicode-objects must be encoded before hashing If I add the b back into the mix, I get a hash with no error messages. But I still can't quite figure out how to get th

Re: [Tutor] quick speed question

2010-09-16 Thread Dave Angel
On 2:59 PM, C.T. Matsumoto wrote: 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? Thanks, T dict is not a good name

Re: [Tutor] pure function problem

2010-09-24 Thread Dave Angel
On 2:59 PM, Roelof Wobben wrote: From: st...@pearwood.info On Fri, 24 Sep 2010 06:20:25 am Roelof Wobben wrote: time =ijd() [...] print time(uitkomst) Why are you calling time as a function, when it is a tijd instance? Hello Steve, I found t

Re: [Tutor] Issues In Terminal

2010-09-26 Thread Dave Angel
On 2:59 PM, Bill DeBroglie wrote: No, I meant that you should edit your .py file and add #!/usr/bin/env python as the first line, THEN try to run it. BINGO! Right now what's happening is that you're handing a line of Python script to the shell and asking it to run it; the shell is tellin

Re: [Tutor] class method problem

2010-09-27 Thread Dave Angel
On 2:59 PM, Roelof Wobben wrote: Hello, Fine that you are in a arque But can we come back to my problem. How can I take care that test2 can be initialized. Roelof You had this code, and got the following error: class zoeken() : pass def __len__(self): return 0 def __st

Re: [Tutor] dynamic arrays?

2010-09-27 Thread Dave Angel
On 2:59 PM, Alex Hall wrote: On 9/27/10, Brian Jones wrote: On Mon, Sep 27, 2010 at 11:32 AM, Alex Hall wrote: Hi all, 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

Re: [Tutor] generating independent random numbers

2010-09-27 Thread Dave Angel
On 2:59 PM, Steven D'Aprano wrote: On Tue, 28 Sep 2010 08:55:36 am Carter Danforth wrote: class Date: c = random.randint(16,30) y = random.randint(0,99) month = random.randint(1,12) Here's your problem: you are creating a class where all the attributes (called "members" in som

Re: [Tutor] question

2010-09-28 Thread Dave Angel
On 2:59 PM, Roelof Wobben wrote: Hello, Im now studying this page : http://openbookproject.net/thinkcs/python/english2e/ch16.html But I don't get it why aces are now lower then deuces in the cmp function. Roelof Why would you be surprised that aces are lower than deuces? If aces are

Re: [Tutor] filling 2d array with zeros

2010-09-28 Thread Dave Angel
On 2:59 PM, Alex Hall wrote: On 9/28/10, Steven D'Aprano wrote: PyPy is a version of Python written in Python. It has an incredible mission: to eventually produce versions of Python which are faster than pure C, despite being written in Python itself. Although they have a long, long way to

Re: [Tutor] question

2010-09-28 Thread Dave Angel
ce of spades is higher than a deuce of hearts. It's only within the same suit that an ace is "less than" a deuce. DaveA Hello Dave, In some games in the Netherlands Aces can have a value of 11 or 1 . So if Aces are 11 then Deuces is lesser then Aces. Can I say that the

Re: [Tutor] generating independent random numbers

2010-09-28 Thread Dave Angel
On 9/28/2010 5:11 PM, Carter Danforth wrote: Thanks for the replies, Dave and Joel. The reason I'm not just using the time or datetime modules for a random date is because it's restricted to 1970-2038; I'm pulling dates from 1600-3099. Thanks a lot for the pointer about the leap

Re: [Tutor] generating independent random numbers

2010-09-29 Thread Dave Angel
On 9/28/2010 5:11 PM, Carter Danforth wrote: Thanks for the replies, Dave and Joel. The reason I'm not just using the time or datetime modules for a random date is because it's restricted to 1970-2038; I'm pulling dates from 1600-3099. Thanks a lot for the pointer about the leap

Re: [Tutor] generating independent random numbers

2010-09-29 Thread Dave Angel
On 9/29/2010 9:17 PM, Carter Danforth wrote: On Wed, Sep 29, 2010 at 1:53 PM, Dave Angel wrote: On 9/28/2010 5:11 PM, Carter Danforth wrote: Thanks for the replies, Dave and Joel. The reason I'm not just using the time or datetime modules for a random date is because it's res

Re: [Tutor] generating independent random numbers

2010-09-29 Thread Dave Angel
On 2:59 PM, Dave Angel wrote: On 9/29/2010 9:17 PM, Carter Danforth wrote: On Wed, Sep 29, 2010 at 1:53 PM, Dave Angel wrote: On 9/28/2010 5:11 PM, Carter Danforth wrote: Thanks for the replies, Dave and Joel. The reason I'm not just using the time or datetime modules for a r

Re: [Tutor] Mutable Properties

2010-09-30 Thread Dave Angel
On 2:59 PM, Chris King wrote: On 9/30/2010 8:43 PM, Steven D'Aprano wrote: What problem are you trying to solve? There is likely another way to solve it. (Not necessarily an easy way, but we'll see.) So I'll have to create my own object which modifies each method to fire off the set me

Re: [Tutor] cgi help

2010-10-06 Thread Dave Angel
On 2:59 PM, Dipo Elegbede wrote: here is the code: http://pastebin.com/K2Fxq6ac kindly help me figure out my mistake. It is supposed to return a table of environmental variables but it returns only the header and a blank page. thanks Care to define "return" ? How are you running this cod

Re: [Tutor] list of dict question

2010-10-10 Thread Dave Angel
On 2:59 PM, Alan Gauld wrote: "Francesco Loffredo" wrote did, Roelof's code would work perfectly, and you could store in a list all the subsequent changes of a dictionary without calling them with different names. You don;'t need dfifferent names. Provided the name creates a new object ins

Re: [Tutor] Ide To use? Other extras to install?

2010-10-11 Thread Dave Kuhlman
ee the recent thread on IDEs. Here is a comparison of Python IDEs: http://www.infoworld.com/d/developer-world/infoworld-review-nine-fine-python-development-tools-374 This is a multi-page article. The subsequence pages give some details about each IDE. - Dave -- Dave Kuhlman http://www.rexx.com

Re: [Tutor] Hiding Superclass Methods

2010-10-11 Thread Dave Kuhlman
> inheritance. It's a good technique. And, it's called delegation. For more on delegation, see this: http://en.wikipedia.org/wiki/Delegation_(programming) Also see Alan's message in this same thread. - Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman

Re: [Tutor] If/else in Python 2.6.5 vs. Python 2.4.3

2010-10-11 Thread Dave Angel
On 2:59 PM, aenea...@priest.com wrote: Hi, I have code that works fine when I run it on Python 2.6.5, but I get an "invalid syntax" error in Python 2.4.3. I'm hoping you can help me fix it. The line in question splits a chunk of semi-colon separated words into separate elements. rgenre = re

Re: [Tutor] Converting from unicode to nonstring

2010-10-15 Thread Dave Angel
On 2:59 PM, David Hutto wrote: Ok, Let me restate and hopefully further clarify. 1. I have a field for a wxpython app using matplotlib to display 2. I have a sqlite3 db which I'm retrieving information from 3. The sqlitle data is returned as unicode: u'field' 4. The portion of the matplotlib

Re: [Tutor] 'module' object has no attribute (setting a class attribute)

2010-10-16 Thread Dave Angel
On 2:59 PM, Tim Johnson wrote: My intention is to set a class attribute so that any number of instantiations will have this value. the module is tmpl.py. the class is tmpl. if from the script I do this: import tmpl tmpl.tmpl.templatepath = kbLib.templatepath I get error message: 'module' obje

Re: [Tutor] updating a Csv file

2010-10-20 Thread Dave Angel
On 2:59 PM, Albert-Jan Roskam wrote: Hi all, How can I update a csv file? I've written the code below, but it does not work ("Error: line contains NULL byte"). I've never tried opening a file in read and write mode (r+) at the same time before, so I suspect that this is the culprit. Should I

Re: [Tutor] Problem with python

2010-10-20 Thread Dave Kuhlman
ecursive structures like trees is trivial with a recursive function or method. Keep in mind that this code is well behaved only when the data structure we apply it to has a reasonable maximum depth. Hope this example helps. - Dave # =

Re: [Tutor] What does "TypeError: 'int' object is not iterable" mean?

2010-10-23 Thread Dave Angel
On 2:59 PM, Richard D. Moores wrote: It's great to have you chime in, Steven. I do wish you would stop pulling your punches, however. ;) On Fri, Oct 22, 2010 at 17:23, Steven D'Aprano wrote: On Sat, 23 Oct 2010 12:42:50 am Richard D. Moores wrote: So I wrote a function: def float2n_decimals

Re: [Tutor] Problems with partial string matching

2010-10-24 Thread Dave Angel
On 2:59 PM, Josep M. Fontana wrote: Hi, As I said in another message with the heading "Using contents of a document to change file names", I'm trying to learn Python "by doing" and I was working on a little project where I had to change the names I run this and I don't get any errors. The name

Re: [Tutor] What is random.triangular() used for

2010-10-24 Thread Dave Angel
On 2:59 PM, Richard D. Moores wrote: On Sun, Oct 24, 2010 at 13:29, Emile van Sebille wrote: From people who would know found at http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.triangular.html """The triangular distribution is often used in ill-defined problems where the u

Re: [Tutor] Problem Passing VARs to Python from PHP & capturing return string

2010-10-27 Thread Dave Angel
On 2:59 PM, Roy Hinkelman wrote: I am posting here as well as a PHP list since I am now getting an odd python error. Rance: Thanks for the note. I get the same error with system or exec or passthru Now, this is very strange. I made the command line string more explicit, and now it recognizes

Re: [Tutor] (no subject)

2010-10-30 Thread Dave Angel
On 2:59 PM, Alan Gauld wrote: "Steven D'Aprano" wrote is actually being executed. There are very few programming tasks harder than trying to debug code that doesn't actually contain any bugs, or contains bugs different from the ones you are seeing, because the code you are actually executin

Re: [Tutor] Problems with partial string matching

2010-11-01 Thread Dave Angel
On 11/1/2010 8:48 AM, Josep M. Fontana wrote: Thanks a lot Dave and Joel, You call re.sub(), but don't do anything with the result. Where do you call os.rename() ? Yes, indeed, as you suggested what was missing was the use of os.rename() to apply the substitution to the actual file

Re: [Tutor] Problems with partial string matching

2010-11-01 Thread Dave Angel
On 11/1/2010 1:53 PM, Josep M. Fontana wrote: Hi Dave, On Mon, Nov 1, 2010 at 2:38 PM, Dave Angel wrote: (You top-posted, so I had to remove the out-of-order earlier portion.) I've not tried to run the code, but I think I can see the problem. Since you never assign 'year' in

Re: [Tutor] scope, visibility?

2010-11-01 Thread Dave Angel
On 2:59 PM, Samuel de Champlain wrote: I am learning python. To practice, I am coding a hangman application in pyGTK. Here are my imports: import pygtk pygtk.require('2.0') import gtk import random Here is my main class: class PenduGTK: Inside the class is a method with a bit of code: d

Re: [Tutor] Math: integers to a fractional power

2010-11-15 Thread Dave Angel
On 2:59 PM, Matthew Denaburg wrote: Hi, OK, so I have a question for you math people: I am trying to solve a quartic equation (Ax^4 + Bx^3 + Cx^2 + Dx + E) using Ferrari's Method, which I found on Wikipedia at this location. I'm using Python 3.1.2 (on Mac OS X 10.6, in case th

Re: [Tutor] While Loops: Coin Flip Game :p:

2010-11-15 Thread Dave Angel
When I run this code (I'm also a noob) I get this result:- [evaluate lines 1-22 from untitled-1.py] The number of heads was 73 The number of tails was 100 Press the enter key to exit. # Surely, if flipping a single coin 100 times your total number of heads and tails should add up to 100 # not

<    1   2   3   4   5   6   7   8   9   10   >