Re: [Tutor] help with HTMLParseError

2005-02-18 Thread Kent Johnson
Peter Kim wrote: I'm using HTMLParser.py to parse XHTML and invalid tag is throwing an exception. How do I handle this? My understanding is that HTMLParser is not very forgiving of badly formed HTML. You might want to look at alternatives. Here are a few: http://www.crummy.com/software/BeautifulS

Re: [Tutor] Trying out Tkinter with problems

2005-02-19 Thread Kent Johnson
Adam Cripps wrote: Secondly, when I try to exit the app, the quit button doesn't kill the root, window, but just the widgets. How do I reference the root window and all, instead of just exiting the widgets? Try self.quit() instead of self.destroy()

Re: [Tutor] Instance into another instance

2005-02-20 Thread Kent Johnson
Ismael Garrido wrote: The idea of the class is to be able to create a "tree". Where each node can have subnodes, which in turn can have their subnodes... Are you creating a tree to represent XML data? There are many packages available that do this. You might want to look at ElementTree which is o

Re: [Tutor] dictionary dispatch for object instance attributes question

2005-02-20 Thread Kent Johnson
Liam Clarke wrote: Hi, just an expansion on Brian's query, is there a variant of getattr for instance methods? i.e. class DBRequest: def __init__(self, fields, action): self.get(fields) def get(self, fields): print fields Instead of self.get in _init__, the value of

Re: Fwd: [Tutor] Create list of IPs

2005-02-20 Thread Kent Johnson
Liam Clarke wrote: Hi, you could save yourself some hassle and do minipstr = '1.0.0.1' maxipstr = '1.0.15.16' minip = map(int, minipstr.split('.')) maxip = map(int, maxipstr.split('.')) iplist = [] for a in range(minip[2], maxip[2]+1): ... if a < maxip[2]: ... for b in range(minip[

Re: Fwd: [Tutor] Create list of IPs

2005-02-20 Thread Kent Johnson
[EMAIL PROTECTED] wrote: Liam Clarke wrote: [ snip ] - increment an IP. This is the hardest part. Why? An ip (V4) is just an 32bit integer :-) The problem arises from the representation. Use something like "http://pynms.sourceforge.net/ipv4.html"; to switch between the various representations.

Re: [Tutor] Instance into another instance

2005-02-20 Thread Kent Johnson
Ismael Garrido wrote: Kent Johnson wrote: Are you creating a tree to represent XML data? There are many packages available that do this. You might want to look at ElementTree which is one of the easiest to use. In fact, even if you aren't trying to represent XML you might find Elemen

Re: [Tutor] Initializing with a call like: someClass.open("someFile")?

2005-02-21 Thread Kent Johnson
Christian Meesters wrote: Hi My cryptic subject is perhaps not sufficient - I'll try to make it a little better: Assume you'd like to write something like: import someClass x = someClass.open("someFile") Here '.open' should read in the data and initialize the instance - with or without calling __

Re: [Tutor] Help debuging a small program

2005-02-21 Thread Kent Johnson
Mark Kels wrote: Hi list ! Here is a small port scanner I made to practice sockets and GUI programming ( WARNING: the program crash when scan button is clicked): How far does it get? How do you know? I would put some debug print statements in. Also you should call sk.close() in the else clause of

Re: [Tutor] database programming

2005-02-21 Thread Kent Johnson
Liam Clarke wrote: PS Anyone know if there's a way to get a list of tables in a DB? I've got the pragma to get a list of columns in a table, but just in the off chance... AFAIK there is no standard way to do this - it is different for each database. For SQLite, see this FAQ: http://www.sqlite.org/

Re: [Tutor] design?--having subclassed methods add logic in the middel of class methods

2005-02-21 Thread Kent Johnson
Brian van den Broek wrote: Hi all, I am still building my toolset for working with treepad files. (This is the one all my recent posts concerning Node classes have been about.) I am exploring ways of having the methods of a sub-class insert additional logic into their version of a class's method

Re: [Tutor] More Advanced Calculator.

2005-02-21 Thread Kent Johnson
. Sm0kin'_Bull wrote: With your helps i managed to program Advanced Calculator. But, I want to change(or add) some to it. 1. How can i /n/n result bit? I tired.. but, I can't You can use the print command to print your results. You can give print a list of values and it will print them separated w

Re: [Tutor] Method/subclass

2005-02-22 Thread Kent Johnson
Liam Clarke wrote: Hi all, I'm working on my first object-based-from-the-ground-up project, and I have some queries. http://www.rafb.net/paste/results/lDUmWS78.html Here are my two classes here. For each different function, search, edit, view, etc. a different SQL operation will take place, and a d

Re: [Tutor] subclassing list -- slicing doesn't preserve type

2005-02-22 Thread Kent Johnson
Brian van den Broek wrote: Hi all, I'm trying to figure out how to subclass the list built-in. .>>> class my_list(list): def __init__(self, sequence=None): list.__init__(self, sequence) self.spam = 1 .>>> mine = my_list((1,2,3,4)) .>>> mine.append(42) .>>>

Re: [Tutor] Help debuging a small program

2005-02-22 Thread Kent Johnson
Mark Kels wrote: On Mon, 21 Feb 2005 13:21:35 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: How far does it get? How do you know? I would put some debug print statements in. Also you should call sk.close() in the else clause of scan(). Finally, I don't think you will see any output in

Re: [Tutor] killing a thread

2005-02-22 Thread Kent Johnson
Max Noel wrote: On Feb 22, 2005, at 23:08, Bill Mill wrote: If I recall correctly, there is not a direct way. Instead, you're going to want to have your worker thread check a queue it shares with the parent every so often to see if the supervisor thread has sent a "quit" message to it. Peace Bill M

Re: [Tutor] Method/subclass

2005-02-23 Thread Kent Johnson
Liam Clarke wrote: I'm not sure I understand your response fully, so I've described how I would do this in accordance with my understandinf of the method described above. Any feedback/corrections are gratefully welcomed. But first, a wee bit of explanation. As I said, this is very sketchy. I've ru

Re: [Tutor] UnicodeDecodeError

2005-02-23 Thread Kent Johnson
Michael Lange wrote: Hello list, I've encountered an (at least for me) weird error in the project I'm working on (see the traceback below). Unfortunately there are several of my application's modules involved, so I cannot post all of my code here. I hope I can explain in plain words what I'm doin

Re: [Tutor] threads

2005-02-23 Thread Kent Johnson
Shitiz Bansal wrote: Hi, I am trying to build a traffic network simulator using python, for my degree project. I need to run at least 5-6000 cars simultaneously.I wanted to run each car in a separate thread. However , after about 400 threads i am unable to create new threads. There does seem to be

Re: [Tutor] threads

2005-02-23 Thread Kent Johnson
Shitiz Bansal wrote: Hi, Googling for my problem i found the following page: http://gnosis.cx/publish/programming/charming_python_b7.html It doesnt make much sense to me.It seems that the author is implementing a series of routines rather than running them sumultaneously as threads are supposed to

Re: [Tutor] UnicodeDecodeError

2005-02-23 Thread Kent Johnson
Michael Lange wrote: now it looks like the total confusion seems to clear up (at least partially). After some googling it seems to me that the best bet is to use unicode strings exclusively. I think that is a good plan. When I set the unicode flag in gettext.install() to 1 the gettext strings are

Re: [Tutor] Unicode issues

2005-02-24 Thread Kent Johnson
Michael Lange wrote: I *thought* I would have to convert the user input which might be any encoding back into byte string first How are you getting the user input? Is it from the console or from a GUI? I think the best strategy is to try to keep all your strings as Unicode. Unicode is the only en

Re: [Tutor] Print text position problems when using triple quotes

2005-02-24 Thread Kent Johnson
Bill Mill wrote: class foo: def bar(self): Sorry, I forgot that if it's in the module, you should declare prompt1 as global by using "global prompt1" right here. print prompt1 % (var1, var2, var3) No, you only need the global statement if you want to assign to a global variable. Read-on

Re: [Tutor] Unicode issues

2005-02-24 Thread Kent Johnson
Michael Lange wrote: Ok, user input must be checked whether it's unicode or not and if necessary be decoded to unicode with system encoding. For internal operations I should then use only unicode strings and if I need to print something to stdout I must encode it again with system encoding, righ

Re: [Tutor] Recursive Tkinter buttons

2005-02-24 Thread Kent Johnson
Adam Cripps wrote: I'm trying to create recursive Tkinter buttons with: for i in range(0,10): print i buttonlabel = "field " +str(i) button[i] = Button (text=buttonlabel) button[i].grid(c

Re: [Tutor] Recursive Tkinter buttons

2005-02-25 Thread Kent Johnson
Adam Cripps wrote: button = [] for i in range(0,10): print i buttonlabel = "field " +str(i) button[i].append = Button (text=buttonlabel) button[i].grid(column=3, row = i+3

Re: [Tutor] OT SQL (but through Python...)

2005-02-25 Thread Kent Johnson
Liam Clarke wrote: Hi, Hope I don't annoy anyone by asking this here, if I do, let me know. When you're doing a SQL select statement, what would be better? Say you're searching by name, should I do - j = cx.execute j('select * from foo where first == %s and last == %s') % (a,b) q = cx.fetchall(

Re: [Tutor] OT SQL (but through Python...)

2005-02-25 Thread Kent Johnson
Liam Clarke wrote: Hi, Well thanks Kent, after a bit of puzzlement I feel like I'm getting it. Pysqlite takes care of correct quotation marks for me, but it's only good for parameters. Right, you still hard-code the rest of the query. so to generate 'select * from foo if A = "Bat"' I can hand cx

Re: [Tutor] Functions Calling Functions

2005-02-25 Thread Kent Johnson
Luke Jordan wrote: Hi - I'm working on a command-line game. Is there anything wrong with having each 'chapter' of the game be a function that links to other chapters by calling them? I only ask because when a recent traceback returned about 40 lines worth of error message, I realized that the fun

Re: [Tutor] Functions Calling Functions

2005-02-25 Thread Kent Johnson
Kent Johnson wrote: I would use a central dispatcher. Each chapter function could return a token indicating which chapter is next, or it could return the actual next chapter function. Look here for an *extensive* example of this style: http://homepage.mac.com/spkane/python/paranoia.py Kent

Re: [Tutor] Newbie simple question

2005-02-25 Thread Kent Johnson
Valone, Toren W. wrote: I need to know how to read the next line while in the "for line in" loop. Readline does not read the next line (I watched it in debug) I think it has something to do with the for line loop but I have not found any documentation in the doc's or tutor for any functions for lin

Re: [Tutor] How to read unicode strings from a binary file and display them as plain ascii?

2005-03-01 Thread Kent Johnson
R. Alan Monroe wrote: I started writing a program to parse the headers of truetype fonts to examine their family info. But I can't manage to print out the strings without the zero bytes in between each character (they display as a black block labeled 'NUL' in Scite's output pane) I tried: stuf

Re: [Tutor] Criticism / Suggestions

2005-03-01 Thread Kent Johnson
Bill Kranec wrote: Hello, So I think that I've 'completed' my first real Python program, and I would appreciate any constructive criticism you all could offer. The program deals with a question that my Dad asked me awhile ago, which was "If twelve people want to divide into teams of two and pla

[Tutor] Re: Help- Simple recursive function to build a list

2005-03-02 Thread Kent Johnson
actuary77 wrote: Kent Johnson wrote: >>> def rec(n,alist=[]): ... _nl=alist[:] ... print n,_nl ... if n == 0: ... print n,_nl ... return _nl ... else: ... _nl=_nl+[n] ... return rec(n-1,_nl) ... >>> _nl = rec(4) 4 [] 3 [4

Re: [Tutor] Threaded persistance?

2005-03-02 Thread Kent Johnson
Gwyn Evans wrote: Hi, New to Python, but with Java background I'm interested in comments/suggestions for something I'm trying... I've got a series of events (basically a dictionary of a few key:value pairs) which I'd like to forward onto a web service. That should be no problem, but I'm inves

Re: [Tutor] Better Search and replace method

2005-03-02 Thread Kent Johnson
Ron Nixon wrote: I'm trying to figure out a better solution to do multiple search and replaces in a text file without having to type: import re s = open('filename') re.sub('vaule1','value2',s) re.sub('vaule3','value4',s) etc I've tried putting all the vaules in a list and doing the replace, but c

Re: [Tutor] slow html generation code

2005-03-02 Thread Kent Johnson
Danny Yoo wrote: It also makes it easier to see a possible bug in the code: the last few lines in the 'for' loop look suspicious: ## txt = textile(tmp) + '' t = Template(txt) s = t.safe_substitute(title='Web-siter: %s' % i[:-5]) output = open(page, 'w') o

Re: [Tutor] Criticism / Suggestions

2005-03-03 Thread Kent Johnson
Bill Kranec wrote: Hi Kent, - The above code depends on roundlist which is not even defined anywhere in the module (just shown in the comment). This suggests again that the init code from the comment should be part of Tournament, and roundlist should be an attribute of Tournament. For a class t

Re: [Tutor] Criticism / Suggestions

2005-03-03 Thread Kent Johnson
Bill Kranec wrote: Hi Kent, First off, thank you so much for the suggestions! They have helped clarify some of the concepts I've been struggling with lately ( mostly object - related ones ). I have been teaching myself Python in my spare time for the last few months, and have no previous progr

Re: [Tutor] Newbie question.

2005-03-04 Thread Kent Johnson
Adriaan Louw wrote: I want to learn python as quick as possible, for web programming at first, and applications later on. Any leads? There are many tutorials available, see http://www.python.org/doc/Intros.html for one list. I have an xp windows and ms office machine. (I'm considering linux, bu

Re: [Tutor] Re: Q & A

2005-03-04 Thread Kent Johnson
Chelan Farsight wrote: Okay this is a real question I have and I am not trying to defend the actions of Mr. Chui. I simply wanted to make sure that I have joined the right list. Are we allowed to ask total n00b questions on this list? Yes, this list is specifically for total n00bs and other beg

Re: [Tutor] (no subject)

2005-03-04 Thread Kent Johnson
Kevin wrote: Hello all. I have just completed my very first python program just a simple number guessing. I would like for someone to try it out if they could and let me know how I did with it and where I could have improved apon it. There are t files main.py and defs.py I second Brian's comments a

Re: [Tutor] Problem with IntVar() - Oops! Here's the code.

2005-03-04 Thread Kent Johnson
There seem to be quite a few problems with this code... Ronnie Betzen wrote: #! /usr/bin/env python import Tkinter should be from Tkinter import * class timer: def __init__(self): The next line needs to be after the line 'self.top = Tk()' so Tkinter is initialized when the variable is c

Re: [Tutor] returning table elements with Beautiful Soup

2005-03-04 Thread Kent Johnson
Bill Kranec wrote: Hi, I'm trying to use Beautiful Soup to scrape some data out of an HTML table. I can do this using table = soup("td", {'class' : 'yfnc_tabledata1' }) table[0].string.strip() OK, table is a list of Tags, the first one has a 'string' attribute. However, if I try for entry in tab

Re: [Tutor] Cataloging Web Page Information

2005-03-04 Thread Kent Johnson
Anderson wrote: Hello, I currently have access to a webpage that has information that I'd like to put into a CSV (comma seperated value) spreadsheet. Its frontend is a form; you fill the form out by entering some text and selecting the appropriate option from a drop down menu, and then you press th

Re: [Tutor] (no subject)

2005-03-05 Thread Kent Johnson
Jacob S. wrote: while 1: play = raw_input("What is your choice? ") if play in options.keys():## This makes sure that the user input is one of our options 'if play in options' is preferable. options.keys() returns a list of keys that will be searched sequentially. options is a dict w

Re: [Tutor] Linked List

2005-03-05 Thread Kent Johnson
Shitiz Bansal wrote: I could not understand what you exactly mean. In order to explain wat my problem is, here is an example code. Its not exactly what I am doing, I am using multiple threads and a rather complicated code so try and understand the sense rather than the code itself. myls=range(50)

Re: [Tutor] Linked List

2005-03-05 Thread Kent Johnson
Stéphane Brunet wrote: Kent Johnson wrote: What Jacob is saying is, one common way to deal with this is to make a copy of the list and iterate over that while changing the original list. Your sample would look like this: Hi, And what if the list is *really* big ? Don't you loose much

Re: [Tutor] MySQLdb error while inserting records

2005-03-06 Thread Kent Johnson
Victor Bouffier wrote: Hi all, I consider myself fairly proficient with SQL, but I'm still getting the hang of the MySQL API. I am working through the examples in "Open Source Web Development with LAMP: Using Linux, Apache, MySQL, Perl, and PHP" by James Lee and Brent Ware, and trying to make th

Re: [Tutor] Intro for interfacing with Microsoft Access?

2005-03-06 Thread Kent Johnson
Tony Meyer wrote: Does anyone know of any online resource that explains how to interface to Microsoft Access via Python, where the intended audience is someone who knows Python, but not the Microsoft innards? These two pages are quite good:

Re: [Tutor] help

2005-03-06 Thread Kent Johnson
Gregory Sexton wrote: Does sp1 and sp2 in Wwindows XP block certain python commands? I haven't heard of any; is there a command you are having trouble with? Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] help

2005-03-06 Thread Kent Johnson
Gregory Sexton wrote: Is there a forum for the complete beginning Python student? Yes, this is it. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] help

2005-03-07 Thread Kent Johnson
Gregory Sexton wrote: Thanks for the help! Sorry for the trivial questions, but I guess we all have to start somewhere. Beginning python student, OS Windows XP,using Python 2.4. Also novice to programming. I cant get the "/a" command to work. I don't know what the "/a" command is, please gi

Re: ****SPAM(11.8)**** Re: [Tutor] returning table elements with Beautiful Soup

2005-03-07 Thread Kent Johnson
Bob Gailer wrote: At 06:20 AM 3/5/2005, Alan Gauld wrote: > > I'm trying to use Beautiful Soup to scrape some data out of an HTML > > table. I can do this using A new one on me, but Beautiful Soup looks very interesting. I've just downloaded it. From where? My Google search does not help. Actua

Re: [Tutor] getting a webpage via python

2005-03-08 Thread Kent Johnson
Paul Tremblay wrote: Is there a simple way to get a web page with python? I have done no network programming with python before. My router (a Linksys 54G model) stores the IP/MAC addresss in a web page. There is no way for me to access them except through the web. Righ now, I am using this code

Re: [Tutor] getting a webpage via python

2005-03-08 Thread Kent Johnson
Paul Tremblay wrote: This is giving me 401 error, authorization required. Here's what I have: auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password('realm', '127.0.0.1', 'myname', 'password') opener = urllib2.build_opener(auth_handler) # ...and install it globally so it can be use

Re: [Tutor] getting a webpage via python

2005-03-08 Thread Kent Johnson
Paul Tremblay wrote: So I just make a file called /etc/router_passwords and include something like WRT54G username password Then parse the file, and supply the info to the password handler? This is easy to do, and I guess it is secure. No, it's not secure at all. In either case (password in the

Re: [Tutor] HELP: subclass of int

2005-03-08 Thread Kent Johnson
Shidai Liu wrote: Hi all, I'll sum up a question as following: def int5(): '''return 5''' return 5 class my_int(int): def __init__(self): self.id = int5() int.__init__(self, self.id) # FIXME: this line doesn't work the above code act like this: I = my_int() I 0 I want i

Re: [Tutor] working with new classes

2005-03-09 Thread Kent Johnson
Sean Perry wrote: C Smith wrote: ### class Ring(list): def __init__(self, l): self[:] = l self._zero = 0 def turn(self, incr=1): self._zero+=incr def __getitem__(self, i): return self[(i-self._zero)%len(self)] l=Ring(range(10)) print l l.turn(5) pr

Re: [Tutor] getting a webpage via python

2005-03-09 Thread Kent Johnson
Kent Johnson wrote: Paul Tremblay wrote: So I just make a file called /etc/router_passwords and include something like WRT54G username password Then parse the file, and supply the info to the password handler? This is easy to do, and I guess it is secure. The book "Foundations of Python Ne

Re: [Tutor] regular expression question

2005-03-09 Thread Kent Johnson
Mike Hall wrote: A simple example will show what I mean: >>> import re >>> x = re.compile(r"(A) | (B)") >>> s = "X R A Y B E" >>> r = x.sub("13", s) >>> print r X R 13Y13 E ...so unless I'm understanding it wrong, "B" is supposed to be ignored if "A" is matched, yet I get both matched. I get

Re: [Tutor] working with new classes

2005-03-09 Thread Kent Johnson
C Smith wrote: Alternatively, the list class can be appended with helpers like 'turn' and 'segment' which can actually turn the "ring" and remove a piece from it without worrying about the endpoint: ### >>> class ring(list): def turn(self, incr=1): incr%=len(self) self[:]

Re: [Tutor] simple question on pywin

2005-03-10 Thread Kent Johnson
Stefan Elwesthal wrote: If I run it from within PythonWin it's all swell, i get my loginbox, and a messageBox handles me corrct data entries (from an ODBC source) The dialog box is a feature of PythonWin, not Python. If I run it from Dos... i get the Dos dialogs with isn't really what I wanted for

Re: [Tutor] cyclically rotate a seq

2005-03-11 Thread Kent Johnson
kevin parks wrote: Hi folks, I am trying to cyclically rotate a seq until it reached the beginning stage again. I would like to be able to rotate in both directions and using any arbitrary interval. I think the code is correct but I have a few suggestions below. #!/usr/bin/env python import sys i

Re: [Tutor] Can you get python to force a number to remain 32 bit instead of autoconverting to type 'long'?

2005-03-11 Thread Kent Johnson
R. Alan Monroe wrote: I tried to convert this pseudocode function IntNoise(32-bit integer: x) x = (x<<13) ^ x; return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 7fff) / 1073741824.0); end IntNoise function from this website http://freespace.virgin.net/hugo.elias/models

Re: [Tutor] Whats so good about OOP ?

2005-03-12 Thread Kent Johnson
Mark Kels wrote: Hi list ! I want to know whats so great in OOP... I have learned some of it, but I don't understand why everybody like it so much... - One of the great challenges in programming is managing complexity. A program of any size is too complex to hold in your brain all at once. Techniq

Re: [Tutor] help

2005-03-13 Thread Kent Johnson
[EMAIL PROTECTED] wrote: * ok i have learned that on the python shell or new window you can type in..>>>print "hello world"...and the output is ..'hello world'.. or you can put in anything realy and it say it back to you.is this a program or what and what is the purpose of this can yo

Re: [Tutor] creating a tab delimited filename

2005-03-13 Thread Kent Johnson
jrlen balane wrote: what does a tab delimited filename mean? how am i going to make this? also how does it differs from space delimited, csv, and others? I think you probably mean "tab-delimited file", not "filename". A tab-delimited file is similar to a space-delimited file. It is typically a rec

Re: [Tutor] command for clearing user screen input

2005-03-13 Thread Kent Johnson
Gopinath V, ASDC Chennai wrote: HI all, I'm trying a series of inputs ...i need to get the screen cleared after every 5 inputs...can any 1 tell me how do I do it Presuming you are using some kind of console window, you can do something like print '\n' * 50 Anything fancier is platform dependen

Re: [Tutor] funny behaviour

2005-03-14 Thread Kent Johnson
Jacob Abraham wrote: Dear Tutors, A class was created to extend timedelta to add and subtract months. Simple doctests that simply create an instance of the class failed. Could someone please explain this really funny behaviour. timedelta is an immutable class (its instances have fixed values tha

Re: [Tutor] re help

2005-03-14 Thread Kent Johnson
Ron Nixon wrote: The following program takes text data like this: Jimi Hendrix 2100 South Ave Seattle, WA 55408 and changes it to this Jimi Hendrix, 2100 South Ave,Seattle,WA,55488 and writes it to a file. Hameed has shown you one solution. I would like to point out that if you plan to read this

[Tutor] CGI authentication

2005-03-14 Thread Kent Johnson
There was a question on this list recently about how to authenticate users of a web server from a simple CGI script. I just came across a module that might help: http://www.voidspace.org.uk/python/logintools.html Kent ___ Tutor maillist - Tutor@python

Re: [Tutor] how to read from a txt file

2005-03-14 Thread Kent Johnson
jrlen balane wrote: this is what i get after running this on IDLE: import sys data_file = open('C:/Documents and Settings/nyer/Desktop/nyer.txt', 'r') data = data_file.readlines() def process(list_of_lines): data_points = [] for line in list_of_lines: try: tempLine = i

Re: [Tutor] how to read from a txt file

2005-03-14 Thread Kent Johnson
) except TypeError: print "Non numeric character in line", line continue #Breaks, and starts with next line data_points.append(tempLine) return data_points This line was moved left four spaces #### now it is not par

Re: [Tutor] how to read from a txt file

2005-03-14 Thread Kent Johnson
jrlen balane wrote: ok, i've done what sir Kent just said, my fault... but an error still occurs: Traceback (most recent call last): File "C:\Python23\practices\opentxtprintlngnew.py", line 18, in -toplevel- print process(data) File "C:\Python23\practices\opentxtprintlngnew.py", line 10, in

Re: [Tutor] big numbers

2005-03-15 Thread Kent Johnson
Robert Storey wrote: This book is a few years old and was written for Python version 1.5, and of course I'm using version 2.3, so I'm just wondering if this whole issue of big numbers is now being handled automatically? Yes, it is. There have been many changes to Python since 1.5; when you are comf

Re: [Tutor] How do you use pydoc?

2005-03-15 Thread Kent Johnson
[EMAIL PROTECTED] wrote: * I have read but don't under stand how to use pydoc. here what i read can't figer out how to use it. One way to use pydoc is to start up a mini web server that delivers module documentation. On Windows, start the server with Start / Programs / Python / Module Docs.

Re: [Tutor] creating a tab delimited filename

2005-03-15 Thread Kent Johnson
jrlen balane wrote: so for example, i have 5 arrays, i can do this (is this correct): data1[1,2,3,4,5 (and so on)] data2[1,2,3,4,5 (and so on)] data3[1,2,3,4,5 (and so on)] data4[1,2,3,4,5 (and so on)] data5[1,2,3,4,5 (and so on)] datas = [data1, data2, data3, data4, data5] for data in datas: l

Re: [Tutor] unicode type on cgi script

2005-03-15 Thread Kent Johnson
BRINER Cedric wrote: python-2.3 apache2 hi, I'm trying to use unicode function into a cgi script with no success. # cedric.py--- #!/usr/bin/python import os,sys import cgi import cgitb; cgitb.enable() print "Content-Type: text/html\ "+os.linesep+"\ "+os.linesep+"hipo'potame" sys.stdout.flus

Re: [Tutor] Port 43 whois.ripe.net

2005-03-15 Thread Kent Johnson
Øyvind wrote: Hello. I need to query the whois at Ripe.net. It tells me to connect to port 43. I have found a description how to connect with .Net. http://www.aspheute.com/english/2825.asp I am not very familiar with network protocols, but assume this will be no big problem with Python. Can som

Re: [Tutor] FTP retrieve

2005-03-15 Thread Kent Johnson
Øyvind wrote: I have opened an FTP connection, and use the following to download a logfile: f = open('c:///web.log','w') ftp.retrlines('RETR ex050202.log', f.write) I have also tried with f.writelines. It works, but not as well as I would like. All the \n's are removed. How can I download an exact

Re: [Tutor] unicode type on cgi script

2005-03-15 Thread Kent Johnson
BRINER Cedric wrote: print uses sys.stdout.encoding to encode unicode strings. You can check what this is in your cgi with import sys print sys.stdout.encoding didn't know I think it will work to explicitly encode the unicode string in the encoding you want for the web page. Try print content.enc

Re: [Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Kent Johnson
Ron Nixon wrote: Thanks to all who replied to my post earlier on re's. I'm still preplexed by why re.search and re.match works in the code below, but not re.findall. re.findall is suppose to return all non-voerlapping occurances of the pattern that matches in this example, but it returns errors. L

Re: [Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Kent Johnson
Liam Clarke wrote: On Tue, 15 Mar 2005 17:09:50 +, Max Noel <[EMAIL PROTECTED]> wrote: re.findall returns a list object (as the error message says). Use name = x[1] instead. (and be careful, numbering starts from 0, so this code may contain a Kenobi error). Kenobi as in Obi Wan? or may

Re: [Tutor] How to delete a class instance

2005-03-16 Thread Kent Johnson
Shitiz Bansal wrote: Hi, How do i delete a class instance in a function running within itself? All the instances of the class are stored in a list, and they need to be deleted after executing their function. However since the list is dynamic, there is no way to know the exact position of the instan

Re: Fwd: [Tutor] creating a tab delimited filename

2005-03-16 Thread Kent Johnson
Max Noel wrote: Forwarding to the list -- please use Reply to All. Begin forwarded message: From: jrlen balane <[EMAIL PROTECTED]> Date: March 16, 2005 04:13:40 GMT To: Max Noel <[EMAIL PROTECTED]> Subject: Re: [Tutor] creating a tab delimited filename Reply-To: jrlen balane <[EMAIL PROTECTED]> why

Re: [Tutor] How to delete a class instance

2005-03-16 Thread Kent Johnson
Shitiz Bansal wrote: No, this list is not a linked list. Since mu original code is rather huge, I am presenting the relevant snippet. queue=[] def genpassenger(num,destination,queue=queue): for i in range(num): newpass=passenger(destination) queue.append(newpass) newpass

Re: [Tutor] How to delete a class instance

2005-03-16 Thread Kent Johnson
Shitiz Bansal wrote: In the code you have shown, I don't see any need for the queue. Just create the thread and start it. I don't think you have to keep a reference to it. I'm not sure, but I think the thread will be garbage collected when it completes. (Can anyone else confirm this?) This does

Re: [Tutor] Re: Convert doesn't work... I'm stumped

2005-03-16 Thread Kent Johnson
Jacob S. wrote: Ahh... I found that out today. A little more rest, I guess. As for unit testing, I've seen it used, but I've never implemented it. I've tried doc string testing with doctest, but I find I can do better just using the interactive interpreter. I think one way to use doctest is to cop

Re: [Tutor] stopping greedy matches

2005-03-16 Thread Kent Johnson
Mike Hall wrote: Liam, "re.compile("in (.*?)\b")" will not find any match in the example string I provided. I have had little luck with these non-greedy matchers. "in (.*?)\b" will match against "in " because you use .* which will match an empty string. Try "in (.+?)\b" (or "(?<=\bin)..+?\b" )to

Re: [Tutor] creating a tab delimited filename

2005-03-17 Thread Kent Johnson
C Smith wrote: Here's an example that cycles through 3 number, 0, 1, and 2: ### >>> j=0 >>> for i in range(10): .. print j .. j = (j+1)%3 .. 0 1 2 0 1 2 0 1 2 0 ### A nice way to do this is with itertools.cycle(): >>> import itertools >>> cyc = itertools.cycle(range(3)) >>> for i in range

Re: [Tutor] cyclically rotate a seq

2005-03-17 Thread Kent Johnson
kevin parks wrote: Hi folks, I am trying to cyclically rotate a seq until it reached the beginning stage again. I would like to be able BTW collections.deque supports most list methods and rotate(): http://docs.python.org/lib/module-collections.html Kent __

Re: [Tutor] How to delete a class instance

2005-03-17 Thread Kent Johnson
Kent Johnson wrote: Shitiz Bansal wrote: In the code you have shown, I don't see any need for the queue. Just create the thread and start it. I don't think you have to keep a reference to it. I'm not sure, but I think the thread will be garbage collected when it completes. (

Re: [Tutor] Unreadable code explanation

2005-03-17 Thread Kent Johnson
Mark Kels wrote: Hi list. I have downloaded some code from useless python that was writen buy a guy named Sammy Mannaert. The code should show that python can be unreadable, and it really is... Can anyone explain to me how does this thing works ?? Here is the code (it prints "python readable ?"):

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Kent Johnson
Mike Hall wrote: On Mar 16, 2005, at 8:32 PM, Kent Johnson wrote: "in (.*?)\b" will match against "in " because you use .* which will match an empty string. Try "in (.+?)\b" (or "(?<=\bin)..+?\b" )to require one character after the space. Another wo

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Kent Johnson
Mike Hall wrote: On Mar 17, 2005, at 11:11 AM, Kent Johnson wrote: The first one matches the space after 'in'. Without it the .+? will match the single space, then \b matches the *start* of the next word. I think I understand. Basically the first dot advances the pattern forward i

Re: [Tutor] subclassing across multiple modules

2005-03-17 Thread Kent Johnson
Brian van den Broek wrote: A schematic of what I have (with fake names for ease of example) is a base module Toolkit.py and I want to write a module Application.py which specializes the behaviour of the Toolkit.py classes. (I'm using old-style classes, but don't feel committed to that choice.)

Re: [Tutor] primes

2005-03-17 Thread Kent Johnson
Max Noel wrote: #!/usr/bin/env python import math import timeit def primeConcise(limit): return [2] + [x for x in xrange(3, limit, 2) if not [y for y in [2] + range(3,x,2) if x%y==0]] def primeConciseOptimized(limit): return [2] + [x for x in xrange(3, limit, 2) if not [y for y in [2] +

Re: [Tutor] subclassing across multiple modules

2005-03-18 Thread Kent Johnson
Brian van den Broek wrote: Kent Johnson said unto the world upon 2005-03-17 20:44: The multiple inheritance from MyNode and Toolkit.NodeX is a smell. I guess you do this because you want to override methods of Toolkit.Node as well as Toolkit.NodeX, or add methods to both MyNode1 and MyNode2? I

Re: [Tutor] how to initialize a class with arbitrary argument list from a file?

2005-03-18 Thread Kent Johnson
Christian Meesters wrote: Hi How can I initialize a class like this from a file: class Some: def __init__(self,data,axis,**kwargs): pass 'data' and 'axis' should be lists of floats. Meta data can be passed to kwargs like 'name="name",date="2/3/05",...'. Right now the return value of my

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