[Tutor] Re: A simpler mousetrap

2004-12-16 Thread Wolfram Kraus
Liam Clarke wrote: Hi all, I'm writing some code, and I want to take a given path + filename, and change the file extension to *.bak. In doing so, (entirely internal this function), I am assuming - That the file will always have an extension Thathe extension will vary But, it will follow the gene

[Tutor] OT: list as newsgroup (was: Please submit to tutor list: dictionary update prob)

2005-01-20 Thread Wolfram Kraus
Jacob S. wrote: Hi everyone, sent this on to the list as told to. cc to eri to verify my sending to list... ;-) Jacob dear jacob, sorry to send this to you but if you may, kindly send to tutor list as im no longer subscribed. my problem is in the update dict portion: it just doesnt update regardle

[Tutor] Re: Unique Items in Lists

2005-01-27 Thread Wolfram Kraus
Brian van den Broek wrote: [...] Hi Srini, for the task of finding out which items are repeated and how many times, I'd do this: def dups_in_list_report(a_list): '''Prints a duplication report for a list.''' items_dict = {} for i in a_list: if i in items_dict: ite

[Tutor] Re: Unique Items in Lists

2005-01-27 Thread Wolfram Kraus
Chad Crabtree wrote: Ok you got me thinking. I used the same thing I posted before but created a one liner that as a side affect makes adict like before. [adict.__setitem__(x,adict.get(x,0)+1) for x in l] I think it's kinda funny and ugly, ohh and not particuarly clear about what it does. Uhh

[Tutor] Re: Presentation

2005-02-01 Thread Wolfram Kraus
Paul Hartley wrote: [...] When I was a member of the Forth Interest Group in the USA we learned that Forth was used on the buggy that went to mars, that it started life controlling huge radio telescopes which only had 4k (yes 4k) of memory for both language and application. Well, the rover used For

[Tutor] Re: how to separate hexadecimal

2005-02-02 Thread Wolfram Kraus
jrlen balane wrote: i have a 4 digit hex number (2 bytes) and i want to separate it into 2 digit hex (1 byte each) meaning i want to get the upper byte and the lower byte since i am going to add this two. how am i going to do this? should i treat it just like a normal string? please help, thanks. e

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

2005-02-03 Thread Wolfram Kraus
Alan Gauld wrote: [...] 1) I'll use Perl for the regex stuff from now on, Perl is obviously built for this. Yes, or PHP. Both have RE baked in. Beware! Overcome the temptation! Try this: http://kodos.sourceforge.net/ HTH ;-) Wolfram ___ Tutor maillist -

[Tutor] Re: print out lines that start with a word

2005-02-09 Thread Wolfram Kraus
Ron Nixon wrote: Can anyone tell me what I've done wrong in this script. I'm trying to get only the lines that start with "This" for a text file. Here's what I wrote: import re f = open('c:/lines.txt').readlines() for line in f: match = re.search('^This',f) if line == match:

[Tutor] Re: print out lines that start with a word

2005-02-09 Thread Wolfram Kraus
Liam Clarke wrote: regexes are common across a lot of languages, even Java has them. Though the pain that would be I daren't not imagine. So the syntax is familiar, whereas string methods may not be. But IMHO string methods are (more) explicit and readable, the name tells you what the method is

[Tutor] Re: print out lines that start with a word

2005-02-09 Thread Wolfram Kraus
Liam Clarke wrote: x= ["Dude", 'How is it going man', ' '] print x ['Dude', 'How is it going man', ' '] j=[] for item in x: ... if re.search('\S+',item): ... j.append(item) print j ['Dude', 'How is it going man'] What about: x= ["Dude", 'How is it going man', ' ']

[Tutor] Re: print out lines that start with a word

2005-02-09 Thread Wolfram Kraus
Damn! C&P-bug here to! Is this a virus? ;-) print [w for w in j.split() if words[0] == '*' and words[-1] == '*'] Should be: print [w for w in j.split() if w[0] == '*' and w[-1] == '*'] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman

[Tutor] Re: print out lines that start with a word

2005-02-09 Thread Wolfram Kraus
Liam Clarke wrote: print [w for w in j.split() if w[0] == '*' and w[-1] == '*'] Wouldn't that only work if it was bug *car* jeff? I can imagine bug*car*jeff would throw it. Cheers, Liam Clarke x = 'bug*car*jeff*foo*bar' [x.split('*')[a] for a in range(1,len(x.split('*')), 2)] When you mix * and

[Tutor] Re: Trivia program.

2005-02-16 Thread Wolfram Kraus
. Sm0kin'_Bull wrote: Hi, I got a problem with this program. name = raw_input("Hi. What's your name? ") called = name * 5 called = ' '.join([name]*5) print "\nIf a small child were trying to get your attention, " \ "your name would become:" print called When i input the name like "John G

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

2005-02-17 Thread Wolfram Kraus
Brian van den Broek wrote: jrlen balane said unto the world upon 2005-02-17 02:41: [...] data_file = open('C:/Documents and Settings/nyer/Desktop/nyer.txt', 'r') [...] The immediate one, due to my advice, is that each line of your file ends with a newline character ('\n'). So, you cannot call int

[Tutor] Re: Method/subclass

2005-02-22 Thread Wolfram Kraus
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

[Tutor] Re: one line code

2005-04-04 Thread Wolfram Kraus
Christian Meesters wrote: Hi Yesterday night I was thinking about the following problem: I do have a list like l = ['1','2','3','abc','','4'] - for instance like a list one could get from a file import with the csv module (which is where my 'problem' comes from). Now I would like to generate the fo

Re: [Tutor] Text Directly to Screen?

2005-05-06 Thread Wolfram Kraus
Aaron Elbaz wrote: > Hi, > > My question has to do with outputting text. > > Normally, you ouput to a console or a gui...but for my task, a hack > might be needed.. > > What I want to do is output text *directly* to the screen. And if > possible, restrict the window area to specific dimensions (

Re: [Tutor] all methods in a module

2005-05-27 Thread Wolfram Kraus
Johan Meskens CS3 jmcs3 wrote: > hello > > import random print random.setstate.__doc__ > > Restore internal state from object returned by getstate(). > > > my question is > " how can i loop through all the methods in a module > and print out their '__doc__' content ? > > fo

Re: [Tutor] File Input of "Objects"

2005-06-01 Thread Wolfram Kraus
Chuck Allison wrote: > Hello tutor, > > I notice that with 'print >> f' one can print the string > representation of objects to a file. Is there a corresponding input > facility that parses through a file creating objects? I can't find > one. In the meantime, I did this: > > f = open

Re: [Tutor] Changing what you've already printed

2005-06-22 Thread Wolfram Kraus
Curses might help you: http://docs.python.org/lib/module-curses.html Take a look at the Demo-directory which is included in the Python source-package. There is a curses subdir in it which might get you started. HTH, Wolfram Ed Singleton wrote: > Is it possible (and easy) to change something you

Re: [Tutor] Why is this error showing up? (Original Message: (Tutor) What's wrong with this code?) Ignore previous post.

2005-07-07 Thread Wolfram Kraus
You wrote filename == raw_input("Filename to load: ") instead of filename = raw_input("Filename to load: ") HTH, Wolfram Nathan Pinno wrote: > Hi all, > > Here's one of the messages that pops up: > > Traceback (most recent call last): > File "D:\password.py", line 77, in ? > filename ==

Re: [Tutor] maximum recursion depth exceeded !

2005-07-07 Thread Wolfram Kraus
Mohammad Moghimi wrote: > Hi there > I wrote a recursive function a got this error how can I increase > maximum recursion depth. And what is its default value? > -- Mohammad > do you Python?!! Start your python interpreter and: >>> import sys >>> sys.getrecursionlimit() 1000 >>> help(sys.setr

Re: [Tutor] generating documentation for a module

2005-07-07 Thread Wolfram Kraus
Mike Hansen wrote: > Is there a utility that generates documentation for your python > modules/scripts/programs based on their doc strings that looks similar to the > library documentation on the python web site? > > What do you use to generate documentation for your python > modules/scripts/pr

Re: [Tutor] maximum recursion depth exceeded !

2005-07-07 Thread Wolfram Kraus
Alan G wrote: >> Start your python interpreter and: >> > import sys sys.getrecursionlimit() >> 1000 > help(sys.setrecursionlimit) > > > Ooh, that's nice. When did the ability to tweak it programmatically > appear? Or has it always been there and I've just never noticed? It isn't in the

Re: [Tutor] Directory or File ?

2005-08-02 Thread Wolfram Kraus
Damien wrote: > Hi all, > I want to know if a file is a directory or a simple file. > I have done a little ugly script : > # i is my filename, os is imported > old = os.getcwd() > try: > chdir(i) > is_dir = True > except: > is_dir = False > os.chdir(old) > return is_dir > > But maybe t

Re: [Tutor] n.isalnum() is failing

2007-07-03 Thread Wolfram Kraus
Use isdigit instead of isalnum. HTH, Wolfram On 03.07.2007 09:51, Terry wrote: > Hi! > > I am running Python 2.5, and I have an IF statement in the below program > that does not seem > to be doing it's job. The program simply acquires a range of years from > the user and prints out > all the lea

Re: [Tutor] Joining non strings in to string

2005-10-28 Thread Wolfram Kraus
Eddie S wrote: > Hi, > I have a list containing numbers. I want to join this list in to a > string which I can then output. The problem is I cant seem to join > list of non-string items in to a string. > > My list looks something like: > > list = [5,7,20,19,49,32] > > I could loop through the li

Re: [Tutor] dont understand this error MySQLdb

2005-12-14 Thread Wolfram Kraus
nephish wrote: > hey there, > i am using the MySQLdb module and i keep getting this error, it doesnt > offer much in the way of explanation > > _mysql_exceptions.InterfaceError: (0, '') > > does anyone know what this means ? > > thanks > I think you should better post in the Mysql for Python fo

Re: [Tutor] Codehelp: confused by the output in IDLE

2005-12-16 Thread Wolfram Kraus
vikas mohan wrote: > Hi again! > > The following is a piece of code that I have written: > > def funcA(x): # function describiing the oddness or eveness of an x number > if x%2 == 0: > print x, "is even" > else: > print x, "is odd" > > def funcB(y): # function describiing the odd

Re: [Tutor] Links for programming using MySQL

2006-01-19 Thread Wolfram Kraus
John Joseph wrote: > Hi I wanted to try out python with MySQL databases , I would like > to get info about the link to sites , which gives you examples on how > to do python programming by using MySQL database Please guide > Thanks Joseph John > > Try this one: http://sourceforge.net/docman/

Re: [Tutor] Indexing in a series for a newbie

2006-01-19 Thread Wolfram Kraus
Jon Moore wrote: > Hello > > I need some help for a program I am writing as a newbie to Python. > > I have created a series: > > WORDS = ("python", "program", "code", "xylophone") > > and then assigned one of them randomly to the variable 'word': > > word = random.choice(WORDS) > > I know tha

Re: [Tutor] [newbie alert] why can't I find a function that gives me the sign of an integer?

2006-01-27 Thread Wolfram Kraus
Rinzwind wrote: > In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0. > I searched on the web for a bit but sgn and sign give me way too many > discussions about Decimals. python.org with > numbers/digits doesn't tell about a function. > > Maybe Python us

Re: [Tutor] [newbie alert] why can't I find a function that gives me the sign of an integer?

2006-01-27 Thread Wolfram Kraus
Rinzwind wrote: > In basic I can use SGN to get back -1, 0, +1 if a number is <0, 0, >0. > I searched on the web for a bit but sgn and sign give me way too many > discussions about Decimals. python.org with > numbers/digits doesn't tell about a function. > > Maybe Python us

Re: [Tutor] Todays Learning Python Question From a Newbie ;)

2006-02-02 Thread Wolfram Kraus
Jon Moore wrote: [...] > Thanks to André, there is a way to win every time if you take the first > move (see below), so there MUST be a whole in the computers stratergy! > Based on what we all know about the game, I would say that you can not > make it so that the computer can win every time,

Re: [Tutor] unable to insert data into database

2006-02-17 Thread Wolfram Kraus
Servando Garcia wrote: > Hello to all > I have been trying to insert data into a database using MySQLdb > with no success. I have no idea why this script is not working. I took > it from a tutorial from DEV Shed. > > #!/usr/bin/python > import MySQLdb > # connect > db = MySQLdb.connect(host

Re: [Tutor] unable to insert data into database

2006-02-17 Thread Wolfram Kraus
Wolfram Kraus wrote: > Servando Garcia wrote: > >>Hello to all >>I have been trying to insert data into a database using MySQLdb >>with no success. I have no idea why this script is not working. I took >>it from a tutorial from DEV Shed. >> >>#!/u

Re: [Tutor] need to automate connection

2006-04-25 Thread Wolfram Kraus
Payal Rathod wrote: > On Tue, Apr 25, 2006 at 06:59:29PM +1200, Liam Clarke wrote: > >>Hi Payal, >> >>I see you're connecting to an smtp server Any particular reason yoou >>can't use smtplib? >>http://www.python.org/doc/current/lib/module-smtplib.html > > > Because I don't know it exists :) > >

Re: [Tutor] Nested list comprehensions

2006-05-15 Thread Wolfram Kraus
Kent Johnson wrote: > John Fouhy wrote: > >>On 15/05/06, Kent Johnson <[EMAIL PROTECTED]> wrote: >> >>>You can come pretty close with generators, though it hurts to think >>>about what is actually going on behind the scenes here: >>> >>>In [1]: import itertools >>> >>>In [2]: def fibs(): >>>..

Re: [Tutor] partial string matching in list comprehension?

2006-05-26 Thread Wolfram Kraus
doug shawhan wrote: > I have a series of lists to compare with a list of exclusionary terms. > > > > junkList =["interchange", "ifferen", "thru"] > > The comparison lists have one or more elements, which may or may not > contain the junkList elements somewhere within: > > l = ["My skull hurt

Re: [Tutor] partial string matching in list comprehension?

2006-05-26 Thread Wolfram Kraus
Kent Johnson wrote: > Wolfram Kraus wrote: > >>doug shawhan wrote: >> >>>I have a series of lists to compare with a list of exclusionary terms. >>> >>> >>> >>>junkList =["interchange", "ifferen", "thru"

Re: [Tutor] [tutor] debug process

2006-06-12 Thread Wolfram Kraus
[EMAIL PROTECTED] schrieb: > Hello, > > Is there a way to debug (trace) the python code line by line? > > emily > Hi emily! You can use The Python Debugger or pdb, see: http://www.python.org/doc/2.4.2/lib/module-pdb.html HTH, Wolfram ___ Tutor mail

Re: [Tutor] about copy.copy

2006-07-18 Thread Wolfram Kraus
On 18.07.2006 09:58, linda.s wrote: > But in the following example, a/b/c change and it looks like there is > no difference. a=[[1,2,3], [4,5,6]] b=a c=copy.copy(a) a[0][0]='a' a > [['a', 2, 3], [4, 5, 6]] b > [['a', 2, 3], [4, 5, 6]] c > [['a', 2, 3], [4, 5, 6]]

Re: [Tutor] more rps

2006-08-15 Thread Wolfram Kraus
On 15.08.2006 08:42, Christopher Spears wrote: > Here is the latest version of my Rock, Paper, Scissors > game: > > #!/usr/bin/python > > import random > random.seed() > > class Human: > def __init__(self): > self.points = 0 > self.choice = " " >

Re: [Tutor] how to wirte code In python :str = (a>b?"Yes":"NO")

2007-02-16 Thread Wolfram Kraus
On 16.02.2007 08:01, xiufeng liu wrote: > Hi, all, > > In python if there is any similar way like in Java, or C++ to express > the following: > str = (a>b?"Yes":"NO") > > > thanks! In Python 2.5 you can do the following (untested): str = "Yes" if a>b else "No" See: http://docs.python.org/what

Re: [Tutor] hypotenuse

2008-03-14 Thread Wolfram Kraus
Am 14.03.2008 09:40, Alan Gauld schrieb: >>> Why can you not use something like: >>> >> hypotenuse = hyp_squared**1/2 > > And for completeness that could also be written: > > hypotenuse = pow(hyp_squared,1/2) > > Again, without the need to import math. > But beware of the integer divison in

Re: [Tutor] Strip?

2008-04-30 Thread Wolfram Kraus
Am 30.04.2008 16:18, Hansen, Mike schrieb: strip( s[, chars]) Return a copy of the string with leading and trailing characters removed. If chars is omitted or None, whitespace characters are removed. If given and not None, chars must be a string; the characters in the string will be

Re: [Tutor] String Replacement question

2008-05-21 Thread Wolfram Kraus
Am 21.05.2008 11:35, Faheem schrieb: Hi all, How do I replace the same value multiple times without repeating the same variable name/value repeatedly? for ex. some = 'thing' print '%s %s %s %s' % (some,some,some,some) in this case, my question is how do i replace "% (some,some,some)" wit

Re: [Tutor] help for building tui?

2008-07-03 Thread Wolfram Kraus
Am 04.07.2008 08:33, Dong Li schrieb: Hi, everyone If I want to create a text user interface for my application, is there any existed module to facilitate such building? Yes, there is curses: http://docs.python.org/lib/module-curses.html http://www.amk.ca/python/howto/curses/ HTH, Wolfram

Re: [Tutor] what does the "@" operator mean?

2008-12-17 Thread Wolfram Kraus
Am 16.12.2008 02:03, Alan Gauld schrieb: "Marc Tompkins" wrote If you're just starting out in Python, decorators can be hard to get your head around... I've been using Python for oover 10 years and still find decorators hard to get my head around! :-) I confess I'm not a fan, they go again