Re: Abuse of the object-nature of functions?

2006-07-11 Thread Simon Forman
Simon Forman wrote: Carl J. Van Arsdall wrote: Hrmms, well, here's an interesting situation. So say we wanna catch most exceptions but we don't necessarily know what they are going to be. For example, I have a framework that executes modules (python functions), the framework wraps each

Re: function that modifies a string

2006-07-10 Thread Simon Forman
placid wrote: quick hack def thefunc(s): return s = || + s + def thefunc(s): return s = || + s + SyntaxError: invalid syntax -- http://mail.python.org/mailman/listinfo/python-list

Re: function that modifies a string

2006-07-10 Thread Simon Forman
greenflame wrote: Jason wrote: There /are/ a few hacks which will do what you want. However, if you really need it, then you probably need to rethink your program design. Remember, you can't change a string since a string is immutable! You can change a variable to bind to another

Re: type comparison and wxpython

2006-07-10 Thread Simon Forman
borris wrote: ive been trying to do a test for type with wxpython objects like passing in a wx.TextCtrl into def XXX(obj) if type(obj) is type(self.Button) I have to make an object self.Button to get its type. as I tried is type(wx.Button) which didnt work. type(wx.Button) would

Re: Error type for shelve.open()

2006-07-10 Thread Simon Forman
[EMAIL PROTECTED] wrote: I reported the bug to python.org and apparently it has already been fixed in the latest SVN build :). Awesome! Open Source at work! :D -- http://mail.python.org/mailman/listinfo/python-list

Re: Global except condition

2006-07-10 Thread Simon Forman
Ernesto wrote: Within the scope of one Python file (say myFile.py), I'd like to print a message on ANY exception that occurs in THAT file, dependent on a condition. Here's the pseudocode: if anyExceptionOccurs(): if myCondition: print Here's my global exception message

Re: Full splitting of a file's pathname

2006-07-10 Thread Simon Forman
BartlebyScrivener wrote: I don't know if it's standard, but why not just: dir = './foo/bar/moo/lar/myfile.txt' dir.split('/') ['.', 'foo', 'bar', 'moo', 'lar', 'myfile.txt'] rd There's also os.path.sep, from the docs: The character used by the operating system to separate pathname

Re: check uploaded file's file size?

2006-07-08 Thread Simon Forman
h3m4n wrote: i have a short script that allows users to upload files, but when i try to check for a valid filesize (using fileitem) i get '-1' i can't find information about using filesize anywhere. any ideas? code: form = cgi.FieldStorage() fileitem = form[datafile] print

Re: Inheritance error: class Foo has no attribute bar

2006-07-08 Thread Simon Forman
crystalattice wrote: I've finally figured out the basics of OOP; I've created a basic character creation class for my game and it works reasonably well. Now that I'm trying to build a subclass that has methods to determine the rank of a character but I keep getting errors. I want to redefine

Re: Error type for shelve.open()

2006-07-07 Thread Simon Forman
[EMAIL PROTECTED] wrote: I tried what you said and it looked like maybe AttributeError, but that didn't work either. This code snippet: import shelve from traceback import format_exc try: db = shelve.open(meh, r) except: print format_exc() Gave me this output: Traceback (most

Re: how can I avoid abusing lists?

2006-07-07 Thread Simon Forman
Thomas Nelson wrote: I have this code: type1 = [0] type2 = [0] type3 = [0] map = {0:type1, 1:type1, 2:type3, 3:type1, 4:type2} # the real map is longer than this def increment(value): map[value][0] += 1 increment(1) increment(1) increment(0) increment(4) #increment will

Re: Idea/request for new python mailing list/newsgroup.

2006-07-07 Thread Simon Forman
Kenneth McDonald wrote: Would a mailing list and newsgroup for python contributions be of interest? I currently have a module which is built on top of, and is ... I'd very much likes a ML/newsgroup wherein potential python contributors could * Post alphas/betas and seek feedback. * Request

Re: how can I avoid abusing lists?

2006-07-07 Thread Simon Forman
Tim Chase wrote: You'll notice that the OP's code had multiple references to the same counter (0, 1, and 3 all mapped to type1) The OP's method was about as good as it gets. One might try to D'oh! Didn't notice that. Yeah, Thomas, if you really do want more than type code (i.e. key to

Re: how can I avoid abusing lists?

2006-07-07 Thread Simon Forman
Thomas Nelson wrote: Thanks to everyone who posted. First, I don't think my question was clear enough: Rob Cowie, Ant, Simon Forman, [EMAIL PROTECTED], and Jon Ribbens offered solutions that don't quite work as-is, because I need multiple values to map to a single type. Tim Chase and Bruno

Re: Tkinter problem

2006-07-07 Thread Simon Forman
Jim Anderson wrote: I'm running Kubuntu a derivative of Debian Linux. I'm using Python 2.4 and tcl/tk 8.4. I'm running Tkinter programs and they were running about a month ago. When I tried them again yesterday, I got the following message: python ~/prog/python/iodef/iodef.py Traceback

Re: 2 problems

2006-07-07 Thread Simon Forman
[EMAIL PROTECTED] wrote: Hello,Im using Python 2.4.2 and I'm starting a few very basic programs,but theres two problems I've not found the answers for. My first problem is I need code that will count the number of letters in a string and return that number to a variable. Do you mean like this

Re: searching for strings (in a tuple) in a string

2006-07-06 Thread Simon Forman
manstey wrote: Hi, I often use: a='yy' tup=('x','yy','asd') if a in tup: ... but I can't find an equivalent code for: a='xfsdfyysd asd x' tup=('x','yy','asd') if tup in a: ... I can only do: if 'x' in a or 'yy' in a or 'asd' in a: ... but then I can't make the if

Re: looping question 4 NEWB

2006-07-06 Thread Simon Forman
[EMAIL PROTECTED] wrote: manstey: is there a faster way of implementing this? Also, does the if clause increase the speed? I doubt the if increases the speed. The following is a bit improved version: # Original data: data = 'asdfbasdf' find = (('a', 'f'), ('s', 'g'), ('x', 'y')) #

Re: Activate a daemon several times a day

2006-07-06 Thread Simon Forman
Yves Glodt wrote: Hi, I have a daemon which runs permanently, and I want it to do a special operation at some specifiy times every day, consider this configfile extract: [general] runat=10:00,12:00 What would be the easiest and most pythonic way to do this? Something like this

Re: Activate a daemon several times a day

2006-07-06 Thread Simon Forman
Yves Glodt wrote: while True: if now(hours) in runat: act() sleep(60) sleep(10) Note that, if now(hours) *is* in runat, this loop will sleep 70 seconds, not 60. It probably doesn't matter. -- http://mail.python.org/mailman/listinfo/python-list

Re: Very practical question

2006-07-06 Thread Simon Forman
madpython wrote: ... self.b=Tkinter.Button(root,txt=Button,command=self.doSmth).pack() self.l=Tkinter.Label(root,txt=default).pack() def doSmth(self): var=globals()[m].__dict__[progLogic].func(some input) self.l.config(txt=var) self.l.update_idletasks() ...

Re: problems with midi programming in python

2006-07-05 Thread Simon Forman
Not related to your actual question, but note: if len(result) == 0: empty lists test as False, so this can just be if not result: and result[len(result)-1] -= 128 you can index lists with negative ints, backwards from the end of the list, so this can be

Re: Error type for shelve.open()

2006-07-05 Thread Simon Forman
[EMAIL PROTECTED] wrote: I wanted to write the following code: import shelve try: db = shelve.open(file, r) except SomeError: print Oh no, db not found Only, I'm not sure what SomeError should be. I tried error, anydbm.error, shelve.open.anydb.error, etc. but can't find it. Things

Re: use var to form name of object

2006-07-05 Thread Simon Forman
gel wrote: snip class testclass: import wmi import time global d_software global l_notepad global d_licence_numbers d_licence_numbers = {notepad.exe:1, Adobe:1} l_notepad =[] d_software = {notepad.exe:[[],[]], Adobe:[[],[]]} Wow! For a second there I

Re: ascii character - removing chars from string

2006-07-04 Thread Simon Forman
not think it means what you think it means. -Inigo Montoya, The Princess Bride -bruce -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Simon Forman Sent: Monday, July 03, 2006 7:17 PM To: python-list@python.org Subject: Re: ascii character

finding items that occur before or after an item in lists

2006-07-04 Thread Simon Forman
I've got a function that I'd like to improve. It takes a list of lists and a target element, and it returns the set of the items in the lists that appear either before or after the target item. (Actually, it's a generator, and I use the set class outside of it to collect the unique items, but

Re: Sudoko solver

2006-07-04 Thread Simon Forman
Rony Steelandt wrote: Hi all, I wonder if somebody had a Sudoko solver written in Python ? Rony Dude, there's like a million of them. Try Sudoko solver Python in google. I wrote one myself based on Knuth's Dancing Links algorithm and using Tkinter for the gui. I'll send it to you or post

Re: finding items that occur before or after an item in lists

2006-07-04 Thread Simon Forman
Simon Forman wrote: I've got a function that I'd like to improve. It takes a list of lists and a target element, and it returns the set of the items in the lists that appear either before or after the target item. (Actually, it's a generator, and I use the set class outside of it to collect

Re: Classes and global statements

2006-07-03 Thread Simon Forman
Sheldon wrote: Hi, I have a series of classes that are all within the same file. Each is called at different times by the main script. Now I have discovered that I need several variables returned to the main script. Simple, right? I thought so and simply returned the variables in a tuple:

Re: xpath question

2006-07-03 Thread Simon Forman
[EMAIL PROTECTED] wrote: bruce wrote: is there anyone with XPath expertise here? i'm trying to figure out if there's a way to use regex expressions with an xpath query? i've seen references to the ability to use regex and xpath/xml, but i'm not sure how to do it... i have a situation

Re: list comprehension

2006-07-03 Thread Simon Forman
[EMAIL PROTECTED] wrote: I woulkdn't interate at the same time. zip takes two lists, and makes a single list of tuples, not the other way around. The easilest solution is feed_list = [ix.url for ix in feeds_list_select] feed_id = [ix.id for ix in feeds_list_select] The zip built-in

Re: ascii character - removing chars from string

2006-07-03 Thread Simon Forman
bruce wrote: hi... i'm running into a problem where i'm seeing non-ascii chars in the parsing i'm doing. in looking through various docs, i can't find functions to remove/restrict strings to valid ascii chars. i'm assuming python has something like valid_str = strip(invalid_str) where

Re: sending binary data over sockets

2006-07-03 Thread Simon Forman
Grant Edwards wrote: On 2006-07-03, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: My problem now, is that I need to send certain binary data over a socket. That is, I want to make some bytes, and stuff them in a TCP packet, send them down the pipe, and then listen for a response. ... In my

Re: ascii character - removing chars from string

2006-07-03 Thread Simon Forman
bruce wrote: hi... update. i'm getting back html, and i'm getting strings like foo nbsp; which is valid HTML as the 'nbsp;' is a space. , n, b, s, p, ; Those are all ascii characters. i need a way of stripping/removing the 'nbsp;' from the string the nbsp; needs to be treated as a

Re: Dictionary .keys() and .values() should return a set [with Python 3000 in mind]

2006-07-02 Thread Simon Forman
Nick Vatamaniuc wrote: Robert Kern wrote: [EMAIL PROTECTED] wrote: The same thing goes for the values(). Here most people will argue that ... This part is pretty much a non-starter. Not all Python objects are hashable. ... Also, I may need keys to map to different objects that happen

Re: xpath question

2006-07-02 Thread Simon Forman
bruce wrote: hi is there anyone with XPath expertise here? i'm trying to figure out if there's a way to use regex expressions with an xpath query? i've seen references to the ability to use regex and xpath/xml, but i'm not sure how to do it... i have a situation where i have something

Re: xpath question

2006-07-02 Thread Simon Forman
bruce wrote: simon.. you may not.. but lot's of people use python and xpath for html/xml functionality.. check google python xpath... later.. ... i have a situation where i have something like: /html/table//[EMAIL PROTECTED]'foo'] is it possible to do soomething like [EMAIL

Re: how to stop python...

2006-07-02 Thread Simon Forman
bruce wrote: hi... perl has the concept of die. does python have anything similar. how can a python app be stopped? the docs refer to a sys.stop.. but i can't find anything else... am i missing something... thanks -bruce What you want is sys.exit() See:

Re: Newb Tkinter Question: Object has no attribute 'tk'

2006-06-30 Thread Simon Forman
python programming newb wrote: Hi all, first post. I'm new to python and tkinter. I'm trying to write a program that opens the root window with a button that then opens a toplevel window that then has it's own widgets. I can get the new toplevel window to open but none of the widgets

Re: list comprehension

2006-06-30 Thread Simon Forman
a wrote: hi simon thanks for your reply You're most welcome what if i want to do this feed_list=[] feed_id=[] for ix in feeds_list_select: global feeds_list global feeds_id

Re: list comprehension

2006-06-30 Thread Simon Forman
Bruno Desthuilliers wrote: Andy Dingley [EMAIL PROTECTED] wrote: Simon Forman wrote: There's more to it, but that's the basic idea. This much I knew, but _why_ and _when_ would I choose to use list comprehension (for good Python style), rather than using a simple traditional loop

Re: Bug reporting impossible

2006-06-29 Thread Simon Forman
Nick Maclaren wrote: ... Create a file called 'stdin' in your current directory containing 'print Oh, yeah?\n' and then import a module that doesn't exist. Don't include the single quotes. Why would you have a file named 'stdin' in your current directory? ~Simon --

Re: Bug reporting impossible

2006-06-29 Thread Simon Forman
Nick Maclaren wrote: In article [EMAIL PROTECTED], Simon Forman [EMAIL PROTECTED] writes: | Nick Maclaren wrote: | ... | Create a file called 'stdin' in your current directory containing | 'print Oh, yeah?\n' and then import a module that doesn't exist. | Don't include the single quotes

Re: list comprehension

2006-06-29 Thread Simon Forman
a wrote: can someone tell me how to use them thanks basically, a list comprehension is just like a for loop, if you wrote it out the long way it would be something like this: results = [] for var in some_iterable: if some condition: results.append(some expression) The list

Re: How to get indices of a two dimensional list

2006-06-29 Thread Simon Forman
[EMAIL PROTECTED] wrote: I have a list x = [0] * 2 x = x * [2] You're certainly not doing that. x = [0] * 2 x = x * [2] Traceback (most recent call last): File stdin, line 1, in ? TypeError: can't multiply sequence by non-int And even if you *do* do what it looks like you think you

Re: Building Web Site Using Python

2006-06-28 Thread Simon Forman
Roman wrote: I am new to python. I am looking to read in a 12mb csv file, parse it, generate web pages, summarize on a column and make drop down bottons. Where would I be able to find sample code that does something similar to this? Also, I know that microsoft has put out .net beta

Re: Building Web Site Using Python

2006-06-28 Thread Simon Forman
Roman wrote: I am new to python. I am looking to read in a 12mb csv file, parse it, generate web pages, summarize on a column and make drop down bottons. Where would I be able to find sample code that does something similar to this? Also, I know that microsoft has put out .net beta

Re: Module executed twice when imported!

2006-06-28 Thread Simon Forman
Michael Abbott wrote: It seems to be an invariant of Python (insofar as Python has invariants) that a module is executed at most once in a Python session. I have a rather bizzare example that breaks this invariant: can anyone enlighten me as to what is going on? --- test.py --- import

Re: for and while loops

2006-06-28 Thread Simon Forman
[EMAIL PROTECTED] wrote: i was wondering if anyone could point me to some good reading about the for and while loops i am trying to write some programs Exercise 1 Write a program that continually reads in numbers from the user and adds them together until the sum reaches 100. Write another

Re: TypeError: Cannot create a consistent method resolution order (MRO) for bases object

2006-06-26 Thread Simon Forman
[EMAIL PROTECTED] wrote: What are the reason one would get this error: TypeError: Cannot create a consistent method resolution order (MRO) for bases object ?? I can provide the code if needed Yes, do that. That's an amazing error. ~Simon --

Re: break the loop in one object and then return

2006-06-26 Thread Simon Forman
Alex Pavluck wrote: I am trying to write the following code to block up evaluation and prompting for entering new information. However, when I break the loop in one object and then return it does not start at the beginning again but rather at the point where it exited. Can someone look at

Re: HTTP server

2006-06-25 Thread Simon Forman
placid wrote: Simon Forman wrote: ... For what you're asking about you'd probably want to use the CGIHTTPRequestHandler from the CGIHTTPServer module instead. Check out http://docs.python.org/lib/module-CGIHTTPServer.html This is what i was after, thanks for the tip. You're welcome

Re: HTTP server

2006-06-25 Thread Simon Forman
placid wrote: Simon Forman wrote: ... The file was named test.cgi. I changed it too test.py and it worked Awesome! Glad to hear it. ... Thanks for the help. I got it to work now. You're welcome. I'm glad I could help you. :-D Peace, ~Simon -- http://mail.python.org/mailman

Re: HTTP server

2006-06-24 Thread Simon Forman
placid wrote: Hi all, Ive been reading about creating a HTTP server like the one pydoc creates (and studying pydoc source code). What i want to know, is it possible to create server that creates a webpage with hyperlinks that communicate back to the HTTP server, where each link accessed

Re: tkinter modifying multiple widgets with one scrollbar

2006-06-24 Thread Simon Forman
spohle wrote: hi how can i modify multiple widgets with one scrollbar ? thanks in advance sven If you're using Tkinter check out: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52266 Peace, ~Simon -- http://mail.python.org/mailman/listinfo/python-list

Re: Help req: Problems with MySQLdb

2006-06-23 Thread Simon Forman
Bruno Desthuilliers wrote: Simon Forman wrote: rodmc wrote: ... except: print A database connection error has occurred How can you assert it is a database connection error ? assert database connection in error (just kidding) I was really just leaving as much of the OP's code

Re: python + postgres psql + os.popen

2006-06-22 Thread Simon Forman
damacy wrote: hello, everyone. ... this works well. however, it does not show me any warning nor error messages if there is one. for example, i am trying to create a table which already exists in the database, it should show me a warning/error message saying there already is one present in

Re: Feed wxComboBox with dictionary/hash

2006-06-22 Thread Simon Forman
Roland Rickborn wrote: Hi folks, ... As the subject says, I'd like to feed a wx.ComboBox with a dictionary/hash. According to the posting of Stano Paska (wxComboBox combobox, 20 Jul. 2004), there seems to be a way to do this: You must use something like combo.Append('aaa', 'a')

Re: OverflowError: math range error...

2006-06-22 Thread Simon Forman
Sheldon wrote: Hi, I have a written a script that will check to see if the divisor is zero before executing but python will not allow this: if statistic_array[0:4] 0.0: statistic_array[0,0:4] = int(multiply(divide(statistic_array[0,0:4],statistic_array \ [0,4]),1.0))/100.0 Does

Re: Help req: Problems with MySQLdb

2006-06-22 Thread Simon Forman
rodmc wrote: Hi, Thanks for your email. Well I am kind of new to exceptions in Python, but here is the code used below, as you can see it is somewhat basic. Is there a way to display more information about the exception? Best, rod Use the traceback module (See

<    1   2   3   4   5