Re: [Tutor] Naming conventions

2005-01-28 Thread Kent Johnson
Terry Carroll wrote: On Wed, 26 Jan 2005, Sean Perry wrote: And now, for the pedant in me. I would recommend against naming functions with initial capital letters. In many languages, this implies a new type (like your Water class). so CombineWater should be combineWater. I hate hate hate hate hat

Re: [Tutor] Naming conventions

2005-01-28 Thread Kent Johnson
Terry Carroll wrote: On Fri, 28 Jan 2005, Kent Johnson wrote: Separating with underscores is quite common in the Python community, actually it is the preferred spelling for library modules. So maybe you should adopt that, just to reduce the confusion when your code does have an encounter with the

Re: [Tutor] Diffing two files.

2005-01-28 Thread Kent Johnson
You don't really say what you are trying to accomplish. Do you want to identify the common text, or find the pieces that differ? If the common text is always the same and you know it ahead of time, you can just search the lines of each file to find it. If you need to identify the common part, d

Re: [Tutor] Diffing two files.

2005-01-29 Thread Kent Johnson
anks again John Ertl Simplified example of a text files. Sldfsdf Sdfsdfsf Sdfsdfsdfwefs Sdcfasdsgerg Vsadgfasgdbgdfgsdf -Beginning flag This Text Should be The Same in the other file. -Ending flag Sdfsdfsdfsd Sdfsdfsdfasd Sdfsadfsdf Sdfsadfasdf Sdfsdfasd Sdfasdf s -Original Message- From: Kent Joh

Re: [Tutor] Naming conventions (was: Should this be a list comprehension or something?

2005-01-29 Thread Kent Johnson
iguessthereisnooptionleftexcepttorunwordstogetherwithoutanykindofbreakatall thatshouldannoyeveryoneequally Kent Liam Clarke wrote: Just please_don't_use_underscores. They_make_my_eyes_go_funny_, _and_code_hard_to_read_in_my_opinion. _u_n_d_e_r_s_c_o_r_e_s_ _a_r_e__u_g_l_y_ I got out of the ha

Re: Fwd: [Tutor] Control flow

2005-01-29 Thread Kent Johnson
Bob Gailer wrote: At 04:43 AM 1/29/2005, Liam Clarke wrote: < erk, to the list, to the List!> if ( bad_weather =='y' ): # ask user only if weather is bad. b = input ( "Weather is really bad, still go out to jog?[y/n]" ) if b == 'y': go_jogging() Anyone else notice that he's never gon

Re: [Tutor] carriage return on windows

2005-01-29 Thread Kent Johnson
It seems to work fine in Win2k command shell; try this: >>> import time >>> time.sleep(1) >>> for i in range(9): ... print 'i is', i, '\r', ... time.sleep(1) I get all the output on one line. Kent Jacob S. wrote: I don't think that's what he wants. I think he wants to *overwrite* what's i

Re: [Tutor] Ports / sockets?

2005-01-30 Thread Kent Johnson
Liam Clarke wrote: Hi, I was reading an article about 'honeytrapping' ports to slow down port scanners, and it made reference to Perl, but I was wondering, how feasible in Python is a script that waits for requests to (normally unused) ports, and then malforms a response to those requests? This i

Re: [Tutor] rounding

2005-01-30 Thread Kent Johnson
The round function will do what you want though not quite what you say you want :-) >>> round(15., -1) 20.0 >>> round(15.5, -1) 20.0 >>> round(14, -1) 10.0 15.34 will round to 20, not 10, which is the closest multiple of 10. Kent Kim Branson wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1

Re: [Tutor] Append function

2005-01-30 Thread Kent Johnson
zip() is your friend. It turns rows into columns and columns into rows. I think this will do what you want, assuming all the first columns are identical (no missing rows in any files), the row values are separated by spaces or tabs, and all the data will fit in memory: def readColumns(filePath):

Re: [Tutor] Dividing 1 by another number ?

2005-01-30 Thread Kent Johnson
Brandon wrote: PI = 3.14 Incidentally the math module has a more accurate value for pi: >>> import math >>> math.pi 3.1415926535897931 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Using exec with dict

2005-01-30 Thread Kent Johnson
André Roberge wrote: I have a "robot" that can do some actions like "move()" and "turn_left()". I can program this robot using python like this: .def move_and_turn(): .move() .turn_left() . .def draw_square(): .for i in range(4): .move_and_turn() . .draw_square()

Re: [Tutor] Newbie struggling with Tkinter/canvas tags

2005-01-31 Thread Kent Johnson
Danny Yoo wrote: Oh! Never mind; this can be a lot simpler. According to the "Gotchas" section of: http://tkinter.unpythonic.net/wiki/Widgets/Canvas the items in a Canvas are actually not object instances themselves, but integers. I made an assumption that canvas items were object instances,

Re: [Tutor] Newbie struggling with Tkinter/canvas tags

2005-01-31 Thread Kent Johnson
Kent Johnson wrote: Note that Python 2.4 has set built-in with the name 'set'. To be compatible with both you could write try: set except NameError: from sets import Set as set Clarification: you don't _have_ to do this to be compatible with 2.4. The sets module is in both 2.

Re: [Tutor] help with regexps/filename parsing

2005-01-31 Thread Kent Johnson
This works: names = [ 'XFree86-ISO8859-15-75dpi-fonts-4.3.0-78.EL.i386.rpm', #(Note the EL embedded in name) 'xfig-3.2.3d-12.i386.rpm', #(standard naming) 'rhel-ig-ppc-multi-zh_tw-3-4.noarch.rpm', 'perl-DateManip-5.42a-0.rhel3.noarch.rpm', 'openoffice.org-style-gnome-1.1.0-16.9.EL.

Re: [Tutor] Newbie struggling with Tkinter/canvas tags

2005-01-31 Thread Kent Johnson
Danny Yoo wrote: Now I've just got to work out how to tag a list of id's... There doesn't seem to be a way to tag a known id, it has to be tagged by reference from an id above or below which seems odd! Hi Glen, Have you tried the addtag_withtag() method? It looks like it should be able to do wh

Re: [Tutor] Dictionary Nesting

2005-01-31 Thread Kent Johnson
jhomme wrote: Hi, If I want to put a dictionary in a dictionary, does the syntax for assigning and getting at the stuff in the inner dictionary look something like this: outer_dictionary[inner_dictionary][key] = 'value' > ? If inner_dictionary is the key to outer_dictionary, then that is right. Fo

Re: [Tutor] carriage return on windows

2005-01-31 Thread Kent Johnson
Victor Rex wrote: I played around with this output issue and I love the way it works. Now, how do you do this in *nix? I tried the same approach and I get a blank line for 5 seconds (or whatever number of cycles you have on your example) and the a final line with the last value of the iterable. I

Re: [Tutor] Presentation

2005-02-01 Thread Kent Johnson
Eric Raymond's "Why Python?" essay is a classic: http://pythonology.org/success&story=esr Bruce Eckel's "Why I love Python" presentation is here: http://64.78.49.204/pub/eckel/LovePython.zip This page has lots of links you might be interested in: http://www.ferg.org/python_presentations/index.html

Re: [Tutor] Better structure?

2005-02-01 Thread Kent Johnson
Danny Yoo wrote: On Mon, 31 Jan 2005, Jacob S. wrote: ### Pseudocode commandDispatchTable = {'clear' : clearCommand 'quit' : quitCommand 'remove' : removeCommand 'return' : returnCommand 'gatl'

Re: [Tutor] Matching with beginning of the line in the character set

2005-02-01 Thread Kent Johnson
Smith, Jeff wrote: I want to match a string which is preceeded by a space or occurs at the beginning of the line. I also don't want to catch the preceeding character as a group. I have found both of the following to work re.compile('(?:^|\s)string') re.compile('(?:\A|\s)string') H

Re: [Tutor] Matching with beginning of the line in the character set

2005-02-01 Thread Kent Johnson
s sense that it works for \w and \s, which are just shortcuts for sets of characters themselves, but not for \A which is something different. Kent Thanks, Jeff BTW, I was using raw strings although I forgot to put that in. -Original Message----- From: Kent Johnson [mailto:[EMAIL PROTECTED]

Re: [Tutor] Append function

2005-02-01 Thread Kent Johnson
You seem to be giving a path to a directory rather than a single file. Also you are putting it in the wrong place, you should edit the allFiles list. Kent kumar s wrote: Hi Kent, Thank you for your suggestion. I keep getting IOError permission denied every time I try the tips that you provided

Re: [Tutor] permutations, patterns, and probability

2005-02-01 Thread Kent Johnson
kevin parks wrote: Greetings, I am working on a program to produce patterns. What would like is for it to exhaustively produce all possible permutations of a sequence of items but for each permutation produce variations, and also a sort of stutter based on probability / weighted randomess. Let

Re: [Tutor] permutations, patterns, and probability

2005-02-01 Thread Kent Johnson
kevin parks wrote: Tremendously helpful One question though. How can i pluck a unique item from my exhaustive list of permutations without repeats making sure that each one is used once? Like filling a bag, shaking it, and then picking from the bag and removing that item from the bag so it i

Re: [Tutor] How to sum rows and columns of a matrix?

2005-02-02 Thread Kent Johnson
Liam Clarke wrote: There's a specific package for arrays http://www.stsci.edu/resources/software_hardware/numarray that implements array mathematics. I use it for pixel map manipulation in pygame, so it's relatively fast. Here is one way to do what you want using numarray: >>> import numarray Cr

Re: [Tutor] How to sum rows and columns of a matrix?

2005-02-02 Thread Kent Johnson
Kent Johnson wrote: Liam Clarke wrote: There's a specific package for arrays http://www.stsci.edu/resources/software_hardware/numarray that implements array mathematics. I use it for pixel map manipulation in pygame, so it's relatively fast. Here is one way to do what you want usin

Re: [Tutor] Better structure?

2005-02-02 Thread Kent Johnson
I would at least introduce some functions. For example each case of your command handling loop could be broken out into a separate function. If there is a lot of shared state between the functions then make them all class methods and put the shared state in the class. Maybe all the drawing comman

Re: [Tutor] Better structure?

2005-02-02 Thread Kent Johnson
Jacob S. wrote: Try writing the code to do what lstrip actually does - its much harder. So the library includes the more difficult function and lets you code the easy ones. def lstrip(string,chars=' ') string = list(string) t = 0 for x in string: if x in chars: string.re

Re: [Tutor] Re: Are you allowed to shoot camels? [kinda OT]

2005-02-03 Thread Kent Johnson
Patrick Hall wrote: Beware! Overcome the temptation! Try this: http://kodos.sourceforge.net/ While I have no problem personally with Perl or PHP, I'll second the recommendation for kodos -- it's very useful for learning to use regexes in Python. Or, if you don't have Qt available, use the regular

Re: [Tutor] got it

2005-02-03 Thread Kent Johnson
alieks laouhe wrote: i came up with z=0 while z<= 2*pi: z=z+pi/6 print z z=z+pi/6 I don't think you're quite there. You are incrementing by pi/6 twice in the loop, so the printed values will differ by pi/3. And the first value printed will be pi/6, not 0. Where are you getting the value of p

Re: [Tutor] variation of Unique items question

2005-02-04 Thread Kent Johnson
You need to reset your items_dict when you see an hg17 line. Here is one way to do it. I used a class to make it easier to break the problem into functions. Putting the functions in a class makes it easy to share the header and counts. class Grouper: ''' Process a sequence of strings of the f

Re: [Tutor] Hex to Str

2005-02-04 Thread Kent Johnson
Use the hex() function to convert an integer to a hex string representation: >>> hex(54) '0x36' >>> hex(0x54) '0x54' or for more control use %x string formatting: >>> '%x' % 54 '36' >>> '%04X' % 0xab '00AB' etc. Kent Tamm, Heiko wrote: Hello, I like to know, if it's possible to convert a Hex

Re: [Tutor] Hex to Str - still an open issue

2005-02-04 Thread Kent Johnson
You might be interested in these: http://groups-beta.google.com/group/comp.lang.python/msg/c2cb941ea70dcdad http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/111286 Kent Tamm, Heiko wrote: Thank you, Pierre, But I'm looking for a solution to convert a Hex number into binary, decimal, interge

Re: [Tutor] Hex to Str - still an open issue

2005-02-04 Thread Kent Johnson
Please give us an example of what you would like to do since we don't seem to understand. Imagine there is a function that does exactly what you want and show how you would use it and what results you would get. Repeating the same question is not likely to get a better answer, just more guesses

Re: [Tutor] Re: variation of Unique items question

2005-02-04 Thread Kent Johnson
I will give some credit to you for asking a clear question. You included - a clear description of what you want to do - sample data - desired results - code that attempts to solve the problem When all of these are present I am much more likely to respond. The first three elements especially make a

Re: [Tutor] arrays

2005-02-04 Thread Kent Johnson
Numeric is an add-on module, not part of the standard distribution. You have to download it and install it. (I'm surprised your tutorial doesn't point that out!) Numeric is still in use but there is a newer version called numarray. You can read about them both here: http://www.pfdubois.com/numpy/

Re: [Tutor] Hex to Str - still an open issue

2005-02-05 Thread Kent Johnson
Liam, I think you misunderstand what endianness is. Big-endian and little-endian refer to the way a number is stored as bytes in the underlying memory of the computer. This is not something you generally need to worry about in a Python program. For example, consider the number 0x12345678. On most

Re: [Tutor] A problem with a Tkinter program (using the text widget)

2005-02-05 Thread Kent Johnson
Mark Kels wrote: Hi all. Whats wrong here ?? : from Tkinter import * def p_text(): print text.get() root=Tk() text=Text(root).pack() pack() doesn't return a value. You have to do text = Text(root) text.pack() I've been bitten by this one more than once myself :-( Kent button=Button(root,text="C

Re: [Tutor] freeze

2005-02-05 Thread Kent Johnson
Shitiz Bansal wrote: Hi, Do exe files generated by py2run on linux???i thought it was only for windows. py2exe makes Windows executables only. http://starship.python.net/crew/theller/py2exe/ Kent Shitiz --- "Jacob S." <[EMAIL PROTECTED]> wrote: My two bits. 1) Download py2exe found here http://py2

Re: [Tutor] Hex to Str - still an open issue

2005-02-06 Thread Kent Johnson
Liam Clarke wrote: 4 is 001 (on a continuum of 2^0 to 2^n), but using the above approach we get 100. ?? 4 (decimal) is 100 (binary). Not because of how the conversion algorithm works, but because that is how we write numbers. The least-significant digit is always the rightmost digit. 001 is 1 in

Re: [Tutor] Iterating over multiple lists- options

2005-02-07 Thread Kent Johnson
Tony Cappellini wrote: I'm trying to generate an HTML table, from multiple lists. There are 4 lists total, each of which *may* have a different length from the other lists. Each list has been stored in a master dictionary. North=[Bill, Bob, Sue, Mary] South=['Tim', ''Tom', 'Jim', 'John', 'Carl',

Re: [Tutor] where do we use acquisition ?

2005-02-07 Thread Kent Johnson
chandrasekhar cherukuri wrote: I completely understood what is acquisition. I don't :-) Can you tell us what you mean by acquisition? I see Zope has something called acquisition; I can't think of anything by that name in standard Python... Kent Now can some one explain me where it is useful and

Re: [Tutor] where do we use acquisition ?

2005-02-07 Thread Kent Johnson
mailing list. Kent --- Kent Johnson <[EMAIL PROTECTED]> wrote: chandrasekhar cherukuri wrote: I completely understood what is acquisition. I don't :-) Can you tell us what you mean by acquisition? I see Zope has something called acquisition; I can't think of anything by that name

Re: [Tutor] calling subroutines into program

2005-02-07 Thread Kent Johnson
Karen, Put all of your code into a function, maybe called import_cobra(). The function should take the path to the basic.out file as a parameter and return the array of data. So it will look something like this: def import_cobra(basicPath): cobra_xy_file = open(basicPath) # All the same c

Re: [Tutor] calling subroutines into program

2005-02-07 Thread Kent Johnson
Liam Clarke wrote: example of (1): - #this part of the program reads the file basin.out (the data we want to analyze) and changes its contents to the array arr_xy #layout of basin.out: #1 -950.0010.00 200> this line contains start

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-07 Thread Kent Johnson
Bob Gailer wrote: At 07:14 AM 2/7/2005, Smith, Jeff wrote: Alan, No use beating this dead horse...I guess that's why there are so many languages in the first place. Different people are comfortable with different things. (I did warn you that I like both Lisp and Prolog and only wish I had more of

Re: [Tutor] calling subroutines into program

2005-02-07 Thread Kent Johnson
r: invalid literal for int(): 950.00 >>> int('-950.00') Traceback (most recent call last): File "", line 1, in ? ValueError: invalid literal for int(): -950.00 Kent On Mon, 07 Feb 2005 09:36:02 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: No, because list[

Re: [Tutor] manipulating a file

2005-02-07 Thread Kent Johnson
Reed L. O'Brien wrote: I want to read the httpd-access.log and remove any oversized log records I quickly tossed this script together. I manually mv-ed log to log.bak and touched a new logfile. running the following with print i uncommented does print each line to stdout. but it doesn't write

Re: [Tutor] Iterating over multiple lists- options

2005-02-07 Thread Kent Johnson
Tony Cappellini wrote: I havne't seen Kent's reply yet- will have to look when I get home from work. But I 've found some inconsistnacies with map, depending on which order the args were passed in. If the shorter list was passed to map first, as in map(shortlist, longerlist), it behaved one way. Th

Re: [Tutor] Match on current line and next line. Possible?

2005-02-08 Thread Kent Johnson
Tom Tucker wrote: Hello! How can I instruct Python to match on the current line and the next line? BROKEN EXAMPLE (discussion) ## file = open('/somefile','r').readlines() for line in file: match_one = re.search('^Python', line) match_two = re.search('^\tBLAH', li

Re: [Tutor] Match on current line and next line. Possible?

2005-02-08 Thread Kent Johnson
Hmm, this would be a good use of itertools.tee() (Python 2.4 only): import itertools iter1, iter2 = itertools.tee(open('/somefile', 'r')) iter2.next() for line, next_line in izip(iter1, iter2): ... Kent Pierre Barbier de Reuille wrote: MMmh ... one way to do that : Py> file_content = open('/somef

Re: [Tutor] Printing columns of data

2005-02-08 Thread Kent Johnson
Kooser, Ara S wrote: Hello all, I am writing a program to take a data file, divide it up into columns and print the information back with headers. The data files looks like this 0.0 -3093.44908 -3084.59762 387.6432926.38518 0.3902434E+00 -0.6024320E-04 0.4529416E-05 1.0 -3

Re: [Tutor] help with refactoring needed -- which approach is morePythonic?

2005-02-10 Thread Kent Johnson
Alan Gauld wrote: The main change in refactoring is moving it to OOP. I have a method that serves as the entry point for parsing the files. Not an object? If you are thinking terms of what the methods do its probably not OOP... I would expect to see an object for the File, another for the Header,

Re: [Tutor] Perl Symbology

2005-02-10 Thread Kent Johnson
Python 2.4 includes a string.Template class which does much the same thing as Itpl.itpl(): >>> from string import Template >>> s, n, r = '0', 12, 3.4 >>> x = Template("$s $n $r") >>> x.substitute(locals()) '0 12 3.4' If you want to bundle this up in a pp() function you have to do some magic to

Re: [Tutor] Perl Symbology

2005-02-10 Thread Kent Johnson
Bill Mill wrote: Kent, On Thu, 10 Feb 2005 13:43:21 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: Python 2.4 includes a string.Template class which does much the same thing as Itpl.itpl(): I just didn't want to give an answer that only works in python 2.4, and one furthermore which

Re: [Tutor] Data storage, SQL?

2005-02-11 Thread Kent Johnson
Liam Clarke wrote: Hi, I'm looking to create a prog that will store disparate bits of info all linked together, i.e. address details for a person, transaction records, specific themes, and the ability to search by certain criteria, so I'm pretty sure I want a database. Can anyone recommend a usef

Re: [Tutor] Data storage, SQL?

2005-02-11 Thread Kent Johnson
Kent Johnson wrote: SQL is a standardized language for giving commands to databases. Most (all?) industrial-strength databases use SQL as their command language. (DB-API is actually a wrapper around SQL - it standardizes the API to issue a SQL command and read the results.) SQL is kind of a

Re: [Tutor] default argument frustration

2005-02-11 Thread Kent Johnson
Brian van den Broek wrote: At first, I ended up with every single node being a copy of the first one processed. A bit of weeping later, I realized that this is from the feature [?] of Python that default arguments are evaluated just once. (Note the comment added above.) FOR THE LOVE OF MIKE ca

Re: [Tutor] Data storage, SQL?

2005-02-11 Thread Kent Johnson
Kent Johnson wrote: I don't know any good on-line resources for learning SQL The Wikipedia entry for SQL has links to quite a few tutorials: http://en.wikipedia.org/wiki/Sql Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/ma

Re: [Tutor] help with refactoring needed -- which approach is morePythonic?

2005-02-11 Thread Kent Johnson
Brian van den Broek wrote: Alan Gauld said unto the world upon 2005-02-10 02:58: Pseudo code: class Body: def __init__(self,content): self.contents = contents self.nodes = [] def parse(self): for line in self.contents:

Re: [Tutor] help with refactoring needed -- which approach ismorePythonic?

2005-02-11 Thread Kent Johnson
Alan Gauld wrote: (And to pick up on someone else's question this is why you should put in a __del__ to tidy up the Node list when Body is destructed - otherwise you get circular references which can cause memory leaks by confusing the garbage collector! CPython has been able to GC cycles since ver

Re: [Tutor] Negative IF conditions

2005-02-11 Thread Kent Johnson
Mark Brown wrote: Hi, I'm a newbie and was wondering which of these IF conditions is better structure: 1. if not os.path.exists('filename'): I prefer the above. 2. if os.path.exists('filename') == False: They both work so if one preferred over the other? Note that in Python in general, 'not

Re: [Tutor] Negative IF conditions

2005-02-11 Thread Kent Johnson
Bob Gailer wrote: At 01:38 PM 2/11/2005, Kent Johnson wrote: Note that in Python in general, 'not x' and 'x == False' are not equivalent; 'not x' will be true for many more values than just False. For example not 0 not 0.0 not [] not {} are all True. Oops. 0

Re: [Tutor] elementtree, lists, and dictionaries

2005-02-12 Thread Kent Johnson
If you iterate over the author nodes you can check the user name and password of each in turn. Not tested code! def authenticateAuthor(author, password): authorxml = 'author.xml' path = os.path.join(xml, authorxml) if not os.path.exists(path): return False, False else:

Re: [Tutor] help with refactoring needed -- which approach is more Pythonic?

2005-02-12 Thread Kent Johnson
Brian van den Broek wrote: Kent Johnson said unto the world upon 2005-02-11 11:34: In general I think this is a bad design. I try to avoid telling components about their parents in any kind of containment hierarchy. If the component knows about its parent, then the component can't be reus

Re: [Tutor] Idle needles

2005-02-12 Thread Kent Johnson
Brian van den Broek wrote: But the multiple copies of pythonw seems key, and also the sort of thing that better Python minds than most seem to accept they have to live with too: Make sure you read the next message in the thread w

Re: [Tutor] Larger program organization

2005-02-12 Thread Kent Johnson
Ryan Davis wrote: I'm starting to make a code-generation suite in python, customized to the way we ASP.NET at my company, and I'm having some trouble finding a good way to organize all the code. I keep writing it, but it feels more and more spaghetti-ish every day. Organize your code into packa

Re: [Tutor] Downloading from http

2005-02-12 Thread Kent Johnson
Mark Kels wrote: On Sat, 12 Feb 2005 09:25:10 -0500, Jacob S. <[EMAIL PROTECTED]> wrote: urllib or urllib2 or maybe httplib maybe? urlopen( url[, data]) I'm sorry, but I didn't understood a thing (maybe its because of my bad english, and mybe its because I'm just dumb :). Anyway, can you giv

Re: [Tutor] Re: Data storage, SQL?

2005-02-13 Thread Kent Johnson
Liam Clarke wrote: ...So, trying to get this straight - if I were going to use SQLite, what would I actually download from http://www.sqlite.org/sqlite.html ? SQLite itself does not use / interface with Python. So you would download the appropriate version of SQLite for your platform from http://

Re: [Tutor] what is wrong with this?

2005-02-13 Thread Kent Johnson
Liam Clarke wrote: Yup, that's what I was after, the full error message. >self.grid1.CreateGrid(100,6) val = gridc.wxGrid_CreateGrid(self, *_args, **_kwargs) try this self.grid1.CreateGrid(self, 100, 6) I'm pretty sure you have to explicitly pass self. No, that's not it. There is an asymmetry be

Re: [Tutor] cross platform gui

2005-02-13 Thread Kent Johnson
Liam Clarke wrote: I would recommend wxPython, it seems to be cross platform. Pythoncard is an easy to use wrapper around wxPython, and for some stuff you have to revert back to wxPython code. I can't on QT, and Tkinter is getting a bit old these days (imao.) AFAIK they should all be cross-platform

Re: [Tutor] Pickling

2005-02-13 Thread Kent Johnson
Johan, The problem is in your class V. You have class V: a=[] def add(self, s): self.a.append(s) The problem is that 'a' is a *class* variable, not an instance variable. The correct way to define V is like this: class V: def __init__(self): self.a=[] # Now 'a

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

2005-02-13 Thread Kent Johnson
Brian van den Broek wrote: Since you files are quite short, I'd do something like: data_file = open(thedata.txt, 'r') # note -- 'r' not r data = data_file.readlines() # returns a list of lines def process(list_of_lines): data_points = [] for line in list_of_lines: data_points

Re: ****SPAM(7.4)**** Re: ****SPAM(11.2)**** [Tutor] Larger program organization

2005-02-13 Thread Kent Johnson
Bob Gailer wrote: At 03:21 PM 2/12/2005, Brian van den Broek wrote: [snip] > I am curious about Bob's "Whenever you find yourself writing > an if statement ask whether this would be better handled by subclasses." class A: ... class A1(A); def foo(self, ...): statements to process object of

Re: [Tutor] what is wrong with this?

2005-02-13 Thread Kent Johnson
seems to be no problem at all when you run the whole program (MDIParentframe). but as i attempt to open this ChildFrame in designer mode, the error occurs. by the way, i tried Sir Liam's suggestion but the error is still there: On Sun, 13 Feb 2005 08:12:11 -0500, Kent Johnson <[EMAIL PROTECT

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

2005-02-13 Thread Kent Johnson
Brian van den Broek wrote: Kent Johnson said unto the world upon 2005-02-13 14:04: Brian van den Broek wrote: Since you files are quite short, I'd do something like: data_file = open(thedata.txt, 'r') # note -- 'r' not r data = data_file.readlines() # returns a

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

2005-02-13 Thread Kent Johnson
jrlen balane wrote: and this line: data_points.append(int(line)) this would turn the string back to an integer, am i right? Yes. and on this one: data_points = [ int(line) for line in data_file ] this did not use any read(), is this already equal to readline()? so this would already store

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

2005-02-13 Thread Kent Johnson
Brian van den Broek wrote: YAGNI is a slogan of the Extreme and/or Agile programming community. Stands for You Aren't Going to Need It. The idea is, if you are thinking of doing something other than (another slogan) `the simplest thing that could possibly work' -- don't. The rational for complicati

Re: [Tutor] error message

2005-02-13 Thread Kent Johnson
Ron Nixon wrote: I'm dping something very simple in RE. Lets say I'm trying to match an American Phone number I write the code this way and try to match it: import re string = 'My phone is 410-995-1155' pattern = r'\d{3}-\d{3}-\d{4}' re.match(pattern,string).group() Use re.search(). re.match() only

Re: [Tutor] Tweaking list comprehensions

2005-02-13 Thread Kent Johnson
Liam Clarke wrote: Hello, I am fine tuning list comprehensions (at least my understandng thereof), and I'm not near a Python interpreter at the moment, so I was wondering if someone could tell me if I did OK - def approachA(files): isHTML = [] for filename in files:

Re: [Tutor] error message

2005-02-13 Thread Kent Johnson
Jacob S. wrote: Dive into Python, an excellent tutorial has a case study on this very same topic. The biggest problem that nobody has mentioned yet is the fact that group() will not have anything unless you explicitly tell it to group it. group() defaults to returning group 0 which is the whole

Re: [Tutor] Tweaking list comprehensions

2005-02-13 Thread Kent Johnson
Kent Johnson wrote: Liam Clarke wrote: Hello, I am fine tuning list comprehensions (at least my understandng thereof), and I'm not near a Python interpreter at the moment, so I was wondering if someone could tell me if I did OK - def approachA(files): isHTML = [] for filename in

Re: [Tutor] Value Error solved. Another question

2005-02-14 Thread Kent Johnson
Ron Nixon wrote: Ignore my first posting. Here's what I'm trying to do. I want to extract headlines from a newspaper's website using this code. It works, but I want to match the second group in (.*) and print that out. Sugguestions import urllib, re pattern = re.compile(""" href="(.*)">(.*)""", re.

Re: [Tutor] Re: Tutor Digest, Vol 12, Issue 71

2005-02-14 Thread Kent Johnson
Lobster wrote: That is a good tip and seems to be the place I need to look - not really quite sure what I am looking at in the help docs I also have the complication of having to use is it "C:\\" - two back slashes? I am trying to get a wikipedia directed search that will load firefox and search fo

Re: [Tutor] Is an executable available?

2005-02-14 Thread Kent Johnson
Stuart Murdock wrote: Hi I am working from within python and want to know the best way to know if a certain package is installed for use on my machine. I want to know from within python that a specific executable file is on my path where I could actually run the command from a prompt in a system

Re: [Tutor] SQL Datetimes

2005-02-15 Thread Kent Johnson
Danny Yoo wrote: On Mon, 14 Feb 2005, Bill Kranec wrote: I'm using Kinterbasdb to access a Firebird database through Python, and when I retrieve a row with a datetime value, I get a tuple like: >>> myCursor.execute( 'SELECT * FROM table' ) >>> for row in myCursor.fetchall(): print row (, 'v

Re: [Tutor] DB design

2005-02-15 Thread Kent Johnson
I don't think you can do exactly that. But SQL does have powerful capabilities to do selects on multiple tables at once. It's called a 'join' and it is very common. For examples suppose you have a customer database with a Customer table: cust_id cust_name 111 Liam Clarke

Re: [Tutor] count words

2005-02-15 Thread Kent Johnson
Ryan Davis wrote: Here's one way to iterate over that to get the counts. I'm sure there are dozens. ### x = 'asdf foo bar foo' counts = {} for word in x.split(): ... counts[word] = x.count(word) ... counts {'foo': 2, 'bar': 1, 'asdf': 1} ### The dictionary takes care of duplicates. If you are

Re: [Tutor] RE help

2005-02-15 Thread Kent Johnson
Try it with non-greedy matches. You are matching everything from the first in one match. Also I think you want to escape the . before (you want just paragraphs that end in a period?) pattern = re.compile("""(.*?)\.""", re.DOTALL) Kent Ron Nixon wrote: Trying to scrape a newspaper site for arti

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

2005-02-16 Thread Kent Johnson
Brian van den Broek wrote: My Node class defines a _parse method which separates out the node header, and sends those lines to a _parse_metadata method. This is where the elif chain occurs -- each line of the metadata starts with a tag like "dt=" and I need to recognize each tag and set the appr

Re: [Tutor] best way to scrape html

2005-02-16 Thread Kent Johnson
You might find these threads on comp.lang.python interesting: http://tinyurl.com/5zmpn http://tinyurl.com/6mxmb Peter Kim wrote: Which method is best and most pythonic to scrape text data with minimal formatting? I'm trying to read a large html file and strip out most of the markup, but leaving the

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

2005-02-16 Thread Kent Johnson
Kent Johnson wrote: Another way to do this is to use dispatch methods. If you have extra processing to do for each tag, this might be a good way to go. I'm going to assume that your data lines have the form 'tag=data'. Then your Node class might have methods that look like th

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

2005-02-16 Thread Kent Johnson
Brian van den Broek wrote: As for the code smell thing, I have a follow-up question. I now get the point of the type-based conditional being a smell for classes. (I get it due to a previous thread that an over-enthusiastic inbox purge prevents me from citing with certainty, but I think it was Bi

Re: [Tutor] Larger program organization

2005-02-16 Thread Kent Johnson
Terry Carroll wrote: On Fri, 11 Feb 2005, Bob Gailer wrote: Whenever you find yourself writing an if statement ask whether this would be better handled by subclasses. Whenever you find yourself about to write a global statement, consider making the variables properties of a class. Bob -- Brian

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

2005-02-17 Thread Kent Johnson
Brian van den Broek wrote: So, sorry, I don't know what's wrong with the code you sent me, and I fear that if I tried to work it out, I'd do more damage. I yield the floor as I am off to write "Don't post untested code 1000 times. for i in range(1000): print "Don't post untested code" (tested,

Re: [Tutor] (no subject)

2005-02-17 Thread Kent Johnson
Kevin Hine wrote: Hello I'm very new to python but need to write a script to update a single geodatabase table in arcview9 from several dbf files. If I can do this I can then use windows scheduled tasks to up date the tables automatically. The field names in the dbs files are or can be slightly

Re: [Tutor] Class in a class

2005-02-17 Thread Kent Johnson
Luis N wrote: Does it make sense to do this: In [2]: class AB: ...: pass ...: In [3]: a = AB() In [4]: a Out[4]: <__main__.AB instance at 0x8428bec> In [5]: class BC: ...: def __init__(self, foo): ...: self.foo = foo In [6]: b = BC(a) In [7]: b.foo Out[7]: <__main__.AB i

Re: [Tutor] Problem in making calulator

2005-02-17 Thread Kent Johnson
. Sm0kin'_Bull wrote: No-one answered question So, I e-mail it again Help me please I wrote this to add 2 numbers... print "Please input data" number1 = int(raw_input(" ")) number2 = int(raw_input("+ ")) total = number1 + number2 print total raw_input("") I want to make output like this... 1 + 1 =

Re: [Tutor] Class in a class

2005-02-18 Thread Kent Johnson
Liam Clarke wrote: Hi Kent, So the layering is GUI - user interaction Application functionality CbDao - application-specific database access DbAccess - generic database access, easy to use JDBC connection - raw database access, not so easy to use This sounds a lot like what I'm aiming for in a

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