Re: [Tutor] Okay, something's funky

2005-03-19 Thread Kent Johnson
Jacob S. wrote: Hi everyone. Very simple set up for the problem, strange problem. class Deck: def __init__(self): self.cards = [] for suit in range(4): for rank in range(1,14): self.cards.append(Card(suit,rank)) def __str__(self): for card in sel

Re: [Tutor] program for creation of unique objects

2005-03-20 Thread Kent Johnson
Brainerd HeadFat wrote: Hi, I'm having trouble trying to figure out how to create multiple objects that contain duplicate entries that can be uniquely identified within a Tkinter GUI. I want a user to define an item and then define multiple characteristics about that item, save a dictionary o

Re: [Tutor] Why is this not an error?

2005-03-20 Thread Kent Johnson
Hameed U. Khan wrote: This else is the part of the for loop. And the statements in this else will be executed if your for loop will complete all of its iterations. if you want this else with 'if' statement then remove the for loop. Or if you want the for loop to be part of the if then indent the

Re: [Tutor] print command

2005-03-21 Thread Kent Johnson
Shitiz Bansal wrote: Now this is so basic, i am feeling sheepish asking about it. I am outputting to the terminal, how do i use a print command without making it jump no newline after execution, which is the default behaviour in python. To clarify: print 1 print 2 print 3 I want output to be 123

Re: [Tutor] automatically extending PYTHONPATH?

2005-03-21 Thread Kent Johnson
You can create a .pth file in site-packages. See these links for details: http://docs.python.org/inst/search-path.html#SECTION00041 http://bob.pythonmac.org/archives/2005/02/06/using-pth-files-for-python-development/ As Liam suggested, you can walk the dir yourself and modify sys.pa

Re: [Tutor] automatically extending PYTHONPATH?

2005-03-21 Thread Kent Johnson
Kent Johnson wrote: As Liam suggested, you can walk the dir yourself and modify sys.path. The walk code could be in a site-customize.py file in site-packages so it will be run automatically every time Python starts up. Oops, as Brian correctly pointed out, the correct file name is

Re: [Tutor] OT - SQL methodology.

2005-03-22 Thread Kent Johnson
Liam Clarke wrote: Hi, This is a SQL query for the advanced db gurus among you (I'm looking at Kent...) Uh oh, you're in trouble if you think I'm an "advanced db guru" :-) After I've run an insert statement, should I get the new primary key (it's autoincrementing) by using PySQLite's cursor.lastr

Re: [Tutor] Very Newbie

2005-03-22 Thread Kent Johnson
Terry Johnson wrote: Hey to the tutors. I am a newbie of course about the only background is some old qbasic and very little c and perl. I have been wanting to write my own Web Server Program and when I saw a few times mentioned around python about it I am starting to check into it. If the is anyo

Re: [Tutor] Looking for a Pythonic way to pass variable number of lists to zip()

2005-03-22 Thread Kent Johnson
Shidai Liu wrote: On Mon, 21 Mar 2005 22:51:31 -0800, Sean Perry <[EMAIL PROTECTED]> wrote: arg_list = [] # fill up arg_list zipped = zip(*arg_list) I met a similar question. what if one has L = [[1,2],[3,4]], K = [100, 200] What do you want to do with these lists? How to 'zip' a List like [[1,2,10

Re: [Tutor] Python cgi doesn't get data from html form as expected

2005-03-22 Thread Kent Johnson
Vicki Stanfield wrote: I don't see anything in that page that changes what I am doing. I can get rid of everything that has to do with retrieving data from cgi-FieldStorage, and the code executes fine although I get a blank page. I have revised the code somewhat, but the initial problem of cgi.Fiel

Re: [Tutor] Looking for a Pythonic way to pass variable

2005-03-22 Thread Kent Johnson
C Smith wrote: On Tuesday, Mar 22, 2005, at 05:01 America/Chicago, [EMAIL PROTECTED] wrote: I met a similar question. what if one has L = [[1,2],[3,4]], K = [100, 200] How to 'zip' a List like [[1,2,100], [3,4,200]]? I would do something like: ### for i in range(len(L)): L[i].append(K[i]) ### O

Re: [Tutor] CGI script to create an XML document from an HTML form

2005-03-22 Thread Kent Johnson
Gabriel Farrell wrote: I've been looking around at various resources such as the Python/XML Howto[2], some of the articles by Uche Ogbuji[3], and elsewhere, and frankly I'm a little overwhelmed by the many seemingly overlapping methods. Which one would the wise tutors recommend for my situation? I

Re: [Tutor] Livewires Help

2005-03-22 Thread Kent Johnson
[EMAIL PROTECTED] wrote: Does python tutor cover livewires w.s help? We will try to answer any questions except direct homework questions. Do you have a specific question or problem? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/ma

Re: [Tutor] .readlines() condensing multiple lines

2005-03-22 Thread Kent Johnson
Liam Clarke wrote: Worse come to worse, you could always do - x = file(myFile, 'r').read() listX = x.split('\r') This will leave the \n in the strings. Reading with universal newlines is a better solution. Kent ___ Tutor maillist - Tutor@python.org ht

Re: [Tutor] .readlines() condensing multiple lines

2005-03-23 Thread Kent Johnson
Liam Clarke wrote: Oh right, From his email, I got the impression he was getting a list like - [[abc\rdef\rghi\r]] We really need a clarification of what is in the original file and what results he is getting. My impression is that it is mixed line endings so the result of readlines is multiple s

Re: [Tutor] Livewires Help

2005-03-23 Thread Kent Johnson
Alan Gauld wrote: The official tutor only covers core Python, not even Tkinter. But I believe there is a separate LiveWires tutor somewhere, although I've never used LiveWires personally. In fact, although I've seen it mentioned here several times I confess I don't even know what LiveWires is! I

Re: [Tutor] blocking user access

2005-03-23 Thread Kent Johnson
Diana Hawksworth wrote: Hi! I need help on blocking user access to a message box - for example, the program could provide an answer to an input. At the moment, the user has access to - and can type into - that "answer" space. How do I prevent that from happening please? It sounds like you want

Re: [Tutor] List comprehensions

2005-03-23 Thread Kent Johnson
Liam Clarke wrote: Hi, Is there a way to apply multiple actions within one list comprehension? i.e. instead of a = [] for i in x: i.pop(3) g = [ int(item) for item in i] a.append(g) You can nest list comps. Except for the pop, the above can be written a = [ [ int(item) for item in

Re: [Tutor] List comprehensions

2005-03-23 Thread Kent Johnson
Liam Clarke wrote: Is there any guides to this (possibly obtuse) tool? http://docs.python.org/tut/node7.html#SECTION00714 http://www.amk.ca/python/2.0/index.html#SECTION00060 Kent ___ Tutor maillist - Tutor@python.org htt

Re: [Tutor] Getting error that calendar is underfined when importing calendar module

2005-03-23 Thread Kent Johnson
The cgi is importing itself when you 'import calendar'. Try renaming your calendar.py to something else like calendar-cgi.py Kent Vicki Stanfield wrote: Hi all. I am using Python 2.4 on a Slackware Linux box and am having a problem importing the calendar module into a program that I am writing. T

Re: [Tutor] .readlines() condensing multiple lines

2005-03-23 Thread Kent Johnson
Mike Hall wrote: On Mar 23, 2005, at 3:17 AM, Kent Johnson wrote: Anyway, Mike, it seems clear that your file has line endings in it which are not consistent with the default for your OS. If reading with universal newlines doesn't solve the problem, please let us know what OS you are ru

Re: [Tutor] Passing data from html to py

2005-03-23 Thread Kent Johnson
Vicki Stanfield wrote: I have one last question on this particular script. I am using the following line to print out the post data: for key in form: print "%s: %s" % (key, form[key].value) The difficulty is that sometimes you have a single value and sometimes you have a list. If yo

Re: [Tutor] blocking user access

2005-03-24 Thread Kent Johnson
Diana Hawksworth wrote: Liam, I am using IDLE - and Tkinter, John and Liam. I have been working through the book "Python Programming" by Michael Dawson. One of his programs calls for the entry of a password, then reveals a message. What I would like to do is make the Text widget that reveals the

Re: [Tutor] Changing a class into a subclass

2005-03-24 Thread Kent Johnson
Max Noel wrote: On Mar 24, 2005, at 18:07, Ismael Garrido wrote: Hello. I have a program that saves/loads to/from XML. I have a main class Building, and a subclass House(Building). When I save the code I instruct each object to save itself to XML (using ElementTree), so House adds itself to the

Re: [Tutor] Changing a class into a subclass

2005-03-24 Thread Kent Johnson
Alan Gauld wrote: But if you want an OOP approach thre are some things to try. First you can create a BuildingFactory class that has a single instance (or indeed no instances because you could use a static method... or get really fancy and create a meta-class!). or make it a static method of Build

Re: [Tutor] Defining functions

2005-03-24 Thread Kent Johnson
John Carmona wrote: Hi there, I have written (well almost as I copied some lines from an existing example) this little programme - part of an exercise. def print_options(): print "--" print "Options:" print "1. print options" print "2. calcu

Re: [Tutor] Changing a class into a subclass

2005-03-24 Thread Kent Johnson
Ismael Garrido wrote: But there's something that I couldn't understand. In the following code, my guess would be that "I'm back from the death" would never get printed... but it is... and twice! Why? It's printed every time B.pong() is called, just as "Pong" is. You print each one twice - no mys

Re: [Tutor] Trying to use MySQLdb.cursor

2005-03-25 Thread Kent Johnson
Vicki Stanfield wrote: I finally gave up and used MySQLdb to connect to my database. It connects okay, and returns data, but now I have a new question. I use the code below to print the data returned from my query, but I would like to make labels at the top of the columns. How do I do this dynamica

Re: [Tutor] Defining functions

2005-03-25 Thread Kent Johnson
Michael Dunn wrote: Something I've always wondered: if input() is so dangerous, why is it there? What valid uses does it have in the wild? It's a mistake planned to be removed in Python 3.0, the "hypothetical future release of Python that can break backwards compatibility with the existing body of

Re: [Tutor] max. range of list

2005-03-25 Thread Kent Johnson
jrlen balane wrote: how many is the maximum member can a list have??? According to this thread http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/2ddae82bb2c1b871/e00b7903bc887a73 the number of element in a list is stored in an int, so most likely the hard limit is 2**31-1. T

Re: [Tutor] a shorter way to write this

2005-03-25 Thread Kent Johnson
jrlen balane wrote: basically, i'm going to create a list with 96 members but with only one value: list1[1,1,1,1...,1] is there a shorter way to write this one??? [1] * 96 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tut

Re: [Tutor] re question

2005-03-26 Thread Kent Johnson
I don't know why this isn't working for you but this worked for me at a DOS console: >>> s='850hPa±' >>> s '850hPa\xf1' >>> import re >>> re.sub('\xf1', '*', s) '850hPa*' >>> import sys >>> sys.stdout.encoding 'cp437' and also in IDLE with a different encoding: >>> s='850hPa±' >>> s '850hPa\

Re: [Tutor] Using python to write games

2005-03-26 Thread Kent Johnson
David Holland wrote: Is there any material anyone knows about how to use pure python without pygame to write games ? The reason for asking, is that although pygame is good it has the disadvantage of that your users must have pygame. It is also harder to create a stand alone .exe with python ? Wha

Re: [Tutor] Re: Dates and databases, and blobs and Python.

2005-03-26 Thread Kent Johnson
Lee Harr wrote: I have heard a lot of really good things about SQLObject: http://sqlobject.org/ However, that requires a more full-featured database, like postgresql. According to the docs SQLObject supports SQLite: http://sqlobject.org/docs/SQLObject.html#requirements Kent

Re: [Tutor] Why cant I return more than once here?

2005-03-26 Thread Kent Johnson
gerardo arnaez wrote: Hi all, I am working a simple function and want it return a a float a list and a dictionary But it seems that I can only use return once in the function cant see to figure out why I can return more than once? Thanks for the help! 'return' does two things - it specifies what

Re: [Tutor] Defining functions

2005-03-27 Thread Kent Johnson
- print is just being changed to a function (instead of a statement), it's not going away entirely. But for complete future compatibility I guess you would avoid it. - I don't think you will ever get the prompt as part of the input unless the user actually types it - You can strip the trailing new

Re: [Tutor] Running a python script from another python script

2005-03-27 Thread Kent Johnson
M.Sinan ORUN wrote: Hello, I am a newbee in python and trying to make a small script for my school project . I try to run a python cgi script from another phyton script as a result of an action . What is the neccesary command for this action and is there a special class have to be imported for

Re: [Tutor] re question

2005-03-27 Thread Kent Johnson
Jacob S. wrote: Kent -- when pulling out just the numbers, why go to the trouble of splitting by "," first? Good question. It made sense at the time :-) Here is another way using re.findall(): >>> import re >>> s='Std Lvl: 850hPa, 1503m, 16.8C, 15.7C, 205 @ 11kts' >>> re.findall(r'[\d\.]

Re: [Tutor] unhashable objects (unrelated to previous topic)

2005-03-27 Thread Kent Johnson
Orri Ganel wrote: Thanks to Jeff and John Fouhy . . . However, my question now is: can I treat Nodes sometimes the same and sometimes not? I want to treat Nodes whose cargo is the same the same everywhere *except* in a dictionary, because I want the user to be able to use LinkedList in a broader wa

Re: [Tutor] How and where to use pass and continue

2005-03-27 Thread Kent Johnson
Kevin wrote: Ok I have another question now I noticed that at the tope of a while loop there will be somthing like this: test = None while test != "enter": test = raw_input("Type a word: ") if test == "enter": break what is the purpose of test = None ? Otherwise you

Re: [Tutor] If elif not working in comparison

2005-03-28 Thread Kent Johnson
gerardo arnaez wrote: Hi all, I am trying to get a value dependant on initial vlaue inputed Depending on the value, I want the functiont to return a percentage For some reason, It seems to skip the first if state and just print out the 1st elif not sure what is going. Are you sure you are passing a

Re: [Tutor] An attribute error problem

2005-03-28 Thread Kent Johnson
Kevin wrote: Hi, I fond this game on the internet I was able to fix most of the errors that it was giving and it will now start up ok. However when you try to enter a name to login to the game it will crash and give this: in sServer.py line 42, in removeConnection self._descriptors.remove(conn.

Re: [Tutor] An attribute error problem

2005-03-28 Thread Kent Johnson
Kevin wrote: Nope it will still give the same Attribute error. Please post the entire error including the stack trace and the whole error message. Copy and paste the whole thing, don't transcribe it. Kent On Mon, 28 Mar 2005 13:50:07 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote:

Re: [Tutor] If elif not working in comparison

2005-03-28 Thread Kent Johnson
Sean Perry wrote: gerardo arnaez wrote: On Mon, 28 Mar 2005 09:27:11 -0500, orbitz <[EMAIL PROTECTED]> wrote: Floats are inherintly inprecise. So if thigns arn't working like you expect don't be surprised if 0.15, 0.12, and 0.1 are closer to the same number than you think. Are you telling me th

Re: [Tutor] An attribute error problem

2005-03-28 Thread Kent Johnson
uple' object has no attribute '_fd' On Mon, 28 Mar 2005 14:06:49 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: Kevin wrote: Nope it will still give the same Attribute error. Please post the entire error including the stack trace and the whole error message. Copy and paste t

Re: [Tutor] An attribute error problem

2005-03-29 Thread Kent Johnson
Kevin wrote: Well I just noticed somthing about the entire sServer.py file. All the code under each def is not indented sServer.py mixes tabs and spaces for indentation. If you view it in an editor that indents 8 spaces for a tab it is fine. You might be interested in the reindent.py and untabify

Re: [Tutor] If elif not working in comparison

2005-03-29 Thread Kent Johnson
Brian van den Broek wrote: Sean Perry said unto the world upon 2005-03-29 03:48: Kent Johnson wrote: Not without using round. Have *NO* faith in floating points. This is especially true when you are creating the decimals via division and the like. Can you be more specific about what kinds of

Re: [Tutor] HTML form post to Python script, without server

2005-03-29 Thread Kent Johnson
Bill Kranec wrote: Hello, This might be slightly OT, but I hope I can get a few pointers. Is it possible to have an HTML form pass values to a Python script on a local computer, and execute that script? (I'm running Win XP, if that matters.) You have to have a server process running. It can be on

Re: [Tutor] A very simple socket server question

2005-03-29 Thread Kent Johnson
Kevin wrote: I figured out how to create a very simple socket server. Though this socket server does exactly nothing special. I can however get it to send only one line of data back to the telnet client. You need two nested loops - an outer loop to accept the connection and an inner loop to proces

Re: [Tutor] Float precision untrustworthy~~~

2005-03-30 Thread Kent Johnson
Jacob S. wrote: I've already deleted the recent thread-- But sometimes I agree with he who said that you can't trust floats at all. The scientific theory suggests that if an output is not what it should be, then the hypothesis is untrue. In this case, the hypothesis is the fact that float division

Re: [Tutor] Calendar module

2005-03-30 Thread Kent Johnson
John Carmona wrote: Hi guys, I have typed this programme from the Josh Cogliati manual - import calendar year = input("Type in the year number: ") calendar.prcal(year) I get this error message Traceback (most recent call last): File "C:/P

Re: [Tutor] Launching a file browser

2005-03-30 Thread Kent Johnson
Mike Hall wrote: I looked over the global module index and the closest thing I could find relating to my os (osx) was EasyDialogs, which has a few functions pertaining to this, "AskFileForOpen()" being one. Calling any function within EasyDialogs however yields an Apple Event error: AE.AEIntera

Re: [Tutor] Sorting more than one list

2005-03-30 Thread Kent Johnson
Diego Galho Prestes wrote: Hi! I need to sort 4 lists but I need that they make the "sort together". I'll sort just one but when I change the position of the items of the 1st list I have to change the positions of the other 3 lists. Can I do this just using the sort() method of the list object? You

Re: [Tutor] Cryptography Toolkit

2005-03-31 Thread Kent Johnson
Mark Thomas wrote: Does anyone have some examples on the use of A.M. Kuchling's Python Cryptography Toolkit? I've tried his examples but get "AttributeError" and "TypeError". What I'm trying to do is encrypt/decrypt a file. I'm using Python 2.3 on xp pro. If you post your code and the complete erro

Re: [Tutor] a FIFO with fixed capacity?

2005-03-31 Thread Kent Johnson
Marcus Goldfish wrote: Danny, Thanks for the informative response. After I sent the email I realized that a circular buffer is a FIFO with fixed capacity, and that is what I want to implement. I think I recall seeing a recipe in the Python Cookbook (1st). If you or anyone else know of other recip

Re: [Tutor] I am puzzled - help needed

2005-03-31 Thread Kent Johnson
You are just a little confused about imports. If I >>> import time then the name 'time' is bound to the time module: >>> time The time() function is an attribute of the time module: >>> time.time >>> time.time() 1112296322.9560001 Alternatively, I can import the time function directly: >>> f

Re: [Tutor] I am puzzled - help needed

2005-03-31 Thread Kent Johnson
John Carmona wrote: It is WORKING NOW!! You can imagine how long I have spent on that, but I have learnt so much. Many thanks to all the people that have helped me, you will probably see me around asking a zillion other (very basics) questions. Congratulations! I have one^H^H^Htwo small notes be

Re: [Tutor] Sorting more than one list

2005-04-01 Thread Kent Johnson
Max Noel wrote: On Apr 1, 2005, at 09:59, Alan Gauld wrote: Since the data are obviously related (since you need to keep them linked), I'd be inclined to merge the lists into a list of tuples merged = [(a,b,c,d) for a in l1 for b in l2 for c in l3 for d in l4] Then you can sort 'merged' and it shou

Re: [Tutor] Cryptography Toolkit

2005-04-01 Thread Kent Johnson
(xored) Kent Mark Thomas wrote: On Thu, 31 Mar 2005 09:14:03 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: If you post your code and the complete error message including the stack trace we may be able to help. Kent Thanks Ken I'm getting closer to making this work using the

Re: [Tutor] Re: If elif not working in comparison

2005-04-04 Thread Kent Johnson
gerardo arnaez wrote: Hi all. I would like to post the very small py files I have written while doing this. Would anyone object. I think at most there be 20 lines of code all the files put together. I woul dlike to hear some crituqe on them That's no problem, for 20 lines just put it in the body o

Re: [Tutor] using the enter key

2005-04-04 Thread Kent Johnson
Diana Hawksworth wrote: > At the moment I have some user input tied to a button that allows the input to be "submitted" and then an answer is supplied. How can I get rid of this submit button, and have the user just press the "enter" key and have the same result happen? How is the user interfac

Re: [Tutor] using the enter key

2005-04-05 Thread Kent Johnson
, as Bernard has suggested, or do I need another piece of code that refers to the Enter key? Thanks. Diana ----- Original Message - From: "Kent Johnson" <[EMAIL PROTECTED]> Cc: Sent: Tuesday, April 05, 2005 7:20 AM Subject: Re: [Tutor] using the enter key Diana Hawksworth wrote:

Re: [Tutor] one line code

2005-04-05 Thread Kent Johnson
Pierre Barbier de Reuille wrote: [EMAIL PROTECTED] a écrit : This is a perfect opportunity to give the reminder that the conversion functions are also types that can be used more transparently for such Neat I didn't know\ that. How dioes Python equate a function object to a type? Is it hard wired?

Re: [Tutor] pickle in unicode format

2005-04-05 Thread Kent Johnson
BRINER Cedric wrote: hi, I have this dictionnary : a={'partition': u'/export/diskH1/home_evol/ricquebo', 'rsmFirstname': u'Fran\xe7ois', 'rsmLastname': u'Ricquebourg', 'size': u'8161222.0', 'size_max': '1'} and I'd like to *serialize* it with pickle and that the output format will be of type un

Re: [Tutor] pickle in unicode format

2005-04-05 Thread Kent Johnson
Kent Johnson wrote: BRINER Cedric wrote: unicode(pickle.dumps(a)) doesn't work ! pickle.dumps() doesn't return a value, it puts the data into 'a' which must be a file-like object. Oops, pickle.dumps() does return a value and the parameter is the object to be pickled. I even

Re: [Tutor] str.split and quotes

2005-04-06 Thread Kent Johnson
Marilyn Davis wrote: Hi Tutors, I need a little help with this, if anyone has the time and inclination: s = 'Hi "Python Tutors" please help' s.split() ['Hi', '"Python', 'Tutors"', 'please', 'help'] I wish it would leave the stuff in quotes in tact: ['Hi', '"Python Tutors"', 'please', 'help'] You c

Re: [Tutor] database access to MSSQL

2005-04-06 Thread Kent Johnson
Ryan Davis wrote: Does anyone know of a decent way to access a SQL Server 2000 database? I make heavy use of SQL Server from Jython using Microsoft's JDBC driver. This works great if it is an option for you. Otherwise if your client is on Windows take a look at adodbapi. I have just played around

Re: [Tutor] comparison function/built-in needed

2005-04-06 Thread Kent Johnson
joe_schmoe wrote: Greetings I am attempting to compare the items in two lists across two criteria - membership and position. For example: list_a = [ 0, 4, 3, 6, 8 ] list_b = [ 1, 8, 4, 6, 2 ] Membership = There are 3 items that are common to both lists, that is 3 items in list_a have membership

Re: [Tutor] regular expression question

2005-04-07 Thread Kent Johnson
D Elliott wrote: I wonder if anyone can help me with an RE. I also wonder if there is an RE mailing list anywhere - I haven't managed to find one. I'm trying to use this regular expression to delete particular strings from a file before tokenising it. I want to delete all strings that have a fu

Re: [Tutor] Help with classes

2005-04-07 Thread Kent Johnson
Kevin wrote: I am fooling around with classes and I was trying to create a very small one player text adventure. I made a class called commands here it is: class Commands: def __init__(self): pass def quiting(self): sys.exit() def look(self): print "\nNot working

Re: [Tutor] csv module not raising exception properly

2005-04-07 Thread Kent Johnson
David Rock wrote: I am trying to catch an exception from the csv module but it doesn't seem to be generating a proper exception because I don't seem to be able to catch it. Here is what I am doing: for inputline in fileinput.input(args): try: input = csv.reader([inputline],

Re: [Tutor] str.split and quotes

2005-04-08 Thread Kent Johnson
Marilyn Davis wrote: Is there a reason to prefer one over the other? Is one faster? I compiled my regular expression to make it quicker. The only way to know which is faster is to time them both. The timeit module makes it pretty easy to do this. Here is a simple example of using timeit for a d

Re: [Tutor] OO newbie

2005-04-08 Thread Kent Johnson
Alan Gauld wrote: this exemple will also works if you replace the: super(C,self).__init__( *args, **kw) by dict.__init__(self, *args, **kw) but I do not understand this dict.__init_... call. Shouldn't you call the super class constructor?? super is just a convenience feature added to make Python s

Re: [Tutor] Support

2005-04-08 Thread Kent Johnson
Alberto Troiano wrote: I tried the code below but the image gets messed up: import Image im=Image.open("auto.jpg") im.show() ###This is to show the image so you can see it m=im.tostring() ima=Image.fromstring("RGB",im.size,m)###I tried also with F,RGBA and L mode instead of RGB maybe ima=Image.fro

Re: [Tutor] Re: Recursive list checking

2005-04-08 Thread Kent Johnson
Jeffrey Maitland wrote: joe_schmoe writes: Dear Pythonites I am looking for a more elegant solution to a piece of code that is too unwieldy and reptitive. The purpose of the code is for a new addition to a list to check whether it is a duplicate of a list element already a member of that list, a

Re: [Tutor] Support

2005-04-08 Thread Kent Johnson
Alberto Troiano wrote: Thanks Apparently it worked but one question do What kind of data is the return of the function tostring() It's a string Can i put it in a blob type of a databaseor maybe in a longtext?? I would try longtext. Kent ___ Tutor

Re: [Tutor] str.split and quotes

2005-04-09 Thread Kent Johnson
[EMAIL PROTECTED] wrote: I was glad to see your post showing how to run a list of functions through the timer. That's a nice way to do it! You better slip some square brackets into your definition of d though: d = dict( [((i,i,i), i) for i in range(1000)]) In Python 2.4 they are not nee

Re: [Tutor] str.split and quotes

2005-04-09 Thread Kent Johnson
Alberto Troiano wrote: Sorry to bother you that much. I know I have a lot to learn yet but I hope you can teach me. I see that someone posted something about running functions with a timer. How can I do this??? You can use the timeit module, see my recent post for an example. You can also use ti

Re: [Tutor] How can I suspend...

2005-04-09 Thread Kent Johnson
Go to the address at the bottom of this email. Unsubscribe. When you return, re-subscribe. Kent John Carmona wrote: I am off to sunny Spain for the next 2 weeks and I would like to suspend the emailing from Python.tutor for that period. Could someone put me in the right direction on how to do th

Re: [Tutor] import.... (Joseph Q.)

2005-04-09 Thread Kent Johnson
Joseph Quigley wrote: I don't think I have said it already, but I'll say it again just incase :-), I'm new to python. I started Feb. this year. import is handy. But my questions are: is there a type of unimport or something to unload a module? This is not normally needed. Foo: What's it good for

Re: [Tutor] quicksort using list comprehension

2005-04-09 Thread Kent Johnson
I think you have to return a value when len(t) <= 1. You don't return anything which means you return None which can't be added to a list. Kent Logesh Pillay wrote: I'm trying to program quicksort using list comprehension. The following gives me a type mismatch error for "+". def qsort (t): i

Re: [Tutor] Re: Help with classes (Joseph Q.)

2005-04-09 Thread Kent Johnson
Joseph Quigley wrote: class Message: def init(self, p = 'Hello world'): self.text = p def sayIt(self): print self.text m = Message() m.init() m.sayIt() m.init('Hiya fred!') m.sayIt() This is OK but a more conventional usage is to write an __init__() method. This is sometimes called a

Re: [Tutor] Support

2005-04-09 Thread Kent Johnson
Alberto Troiano wrote: Hey dudes This code worked fine The one you gave me worked as well but when I wanteed to store it in the database it says that the packet was too large Whit this code it doesn't complain but now I don't know how to retrieve the image I retrieve it like this: db=MySQLdb.c

Re: [Tutor] Re: import.... (Joseph Q.)

2005-04-10 Thread Kent Johnson
Joseph Quigley wrote: > Well, I'm importing a custom module, and I can't loop back to the module I imported (the modules are different modes of the program. Someone suggested classes, but I have no idea how to use them. I'm not sure I understand you, but it sounds like you have two versions of a

Re: [Tutor] problems with doctest: apparent interferance between tests (LONG)

2005-04-10 Thread Kent Johnson
As John Ridley suggests, you have to balance creation and deletion of Wall_clock instances. But unfortunately del wc does not necessarily call Wall_clock.__del__() immediately. See below for more... Brian van den Broek wrote: def check_point(self, check_point_name = None): '''Creates

Re: [Tutor] problems with doctest: apparent interferance between tests (LONG)

2005-04-10 Thread Kent Johnson
Brian van den Broek wrote: I've not fully grokked the doctest code (which I delved into after Lee Harr suggested I do so), but I would have thought that each doctest had its own copy of the Wall_clock class from copying globals. But here, I surely have more work to do myself :-) doctest makes a sha

Re: [Tutor] Sorting of files based on filesize

2005-04-11 Thread Kent Johnson
This is a hard problem. It is a version of the "0-1 knapsack problem" - googling for that might give you some ideas. Kent Klas Marteleur wrote: Hi Some of my harddrives are getting full and i would like to burn the files to some cheep DVD's. Filesizes range from lets say 1Mb to 1Gb. Ofcourse i

Re: [Tutor] str.split and quotes

2005-04-11 Thread Kent Johnson
Alberto Troiano wrote: Thanks Kent but now I need you to explain me the code :( That code won't work for you. It is for timing how long it takes to do something, not for generating repeated events. To give you a graphic example how can make this function to run every 5 seconds def foo(): pr

Re: [Tutor] Tk code problem (Joseph Q.)

2005-04-12 Thread Kent Johnson
Joseph Quigley wrote: Hi, It seems that whenever I click the QUIT button the TK windows freezes, then I have to CTRL-ALT-DEL to be able to shut it down. Here's the code (its not mine though): It works if you run from the command line instead of inside IDLE. I thought IDLE was supposed to be able

Re: [Tutor] Python starting books

2005-04-12 Thread Kent Johnson
Alexis wrote: Hi, i would like to know if someone could recommend me some books to get started not only the first book to read but if possible a few to continue learning also. If you have some programming background I recommend "Learning Python". "Python Cookbook" is an excellent intermediate-leve

Re: [Tutor] sorting a list of dictionaries

2005-04-13 Thread Kent Johnson
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, December 09, 2004 12:19 PM To: tutor@python.org Subject: Re: [Tutor] sorting a list of dictionaries On 9 Dez 2004, [EMAIL PROTECTED] wrote: I have a list of dictionaries, each representing info about a

Re: [Tutor] Python backwards program

2005-04-13 Thread Kent Johnson
Jim and Laura Ahl wrote: Thanks for the encouragement, here is what I have so far. word=raw_input("Enter a Word or string:") print word print word[::-1] raw_input("\n\nPress the enter key to exit.") In the print word [::-1] line it gives me this message (sequence index must be an integer) Wha

Re: [Tutor] Odd problem with variable substitution and command execution

2005-04-13 Thread Kent Johnson
Robert, Andrew wrote: Hi Everyone, I am trying to do an MQ inquiry but I am having mixed results. If I do the command direct via a print statement like the one below, it works, print 'Queue Description:\t' , q.inquire(CMQC.MQCA_Q_DESC) When I try to cycle through an array of command line supplied k

Re: [Tutor] _winreg problems enumerating

2005-04-14 Thread Kent Johnson
Gallagher Timothy-TIMOTHYG wrote: am new to python and want to learn this language. I am having troubles finding examples and tutorials for use on windows boxes. I do most of my stuff in perl and php but want better socket support, so I am giving python a try. I am writing a script to connect to

Re: [Tutor] i need to see a var from any where in my app - im clueless

2005-04-14 Thread Kent Johnson
pxlpluker wrote: i want to read a global (OPTIONS) from file1 from a class method (func1) in file2 but i cant see the OPTION from func1 -- #file1.py import file2 import sys OPTION = sys.argv[1:] pass a=global2.class1() Presumably you mean file2.class1() h

Re: [Tutor] How to calculate pi with another formula?

2005-04-14 Thread Kent Johnson
Dick Moores wrote: Now to my new question. I have an artist friend who knows an artist who needs pi expressed in base 12. I don't know how many digits he needs, but I think he'll take what he can get. Is there a way to use math.log(x, base) with the decimal module to accomplish this? Or is ther

Re: [Tutor] (no subject)

2005-04-14 Thread Kent Johnson
Jim and Laura Ahl wrote: >>> 'my test string'[-1:-4:-1] 'gni' >>> When I do this it tells me that the sequence index must be an integer. What is that telling me and how do I fix that? Jim It's telling you that it doesn't support "extended slicing" - indexes with three components. Upgrade to Py

Re: [Tutor] Re: Recursion....what are the best situations to use it?

2005-04-14 Thread Kent Johnson
[EMAIL PROTECTED] wrote: I've seen a couple of nice tutorials on recursion, and a lot of awful ones. The latter always trot out the fibonacci and factorial examples for some reason. And that's about it! The good ones showed me how to trace through recursive calls and gave me practical examples(t

Re: [Tutor] high score lists

2005-04-14 Thread Kent Johnson
R. Alan Monroe wrote: Anyone have some good beginning ideas/references to creating a high score list and storing scores in a simple python game? (if there's something in the pygames module, or a simpler python way). I'm mod'ing a space invaders-type game and would like to add a high score list :)

Re: [Tutor] sorting a list of dictionaries

2005-04-15 Thread Kent Johnson
PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent Johnson Sent: Wednesday, April 13, 2005 3:52 AM Cc: tutor@python.org Subject: Re: [Tutor] sorting a list of dictionaries -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, December 09, 2004 12:19 PM

<    7   8   9   10   11   12   13   14   15   16   >