Re: [Tutor] Mixing generator expressions with list definitions

2007-04-18 Thread Ed Singleton
On 4/18/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: > > I would like to be able to do something along the lines of: > > > >>>> my_list = [1, 2, x for x in range(3,6), 6] > > > > However this doesn't work. Is there any

[Tutor] Mixing generator expressions with list definitions

2007-04-18 Thread Ed Singleton
I would like to be able to do something along the lines of: >>> my_list = [1, 2, x for x in range(3,6), 6] However this doesn't work. Is there any way of achieving this kind of thing? I tried: >>> my_list = [1, 2, *(x for x in range(3,6)), 6] which also doesn't work. I wrote a quick function

[Tutor] Unicode problems

2006-08-29 Thread Ed Singleton
I've been having unicode problems in python on Mac OS 10.4. I googled for it and found a good page in Dive Into Python that I thought might help (http://www.diveintopython.org/xml_processing/unicode.html). I tried following the instructions and set my default encoding using a sitecustomize.py, bu

Re: [Tutor] how to *really* copy a list

2006-04-28 Thread Ed Singleton
On 28/04/06, John Fouhy <[EMAIL PROTECTED]> wrote: > On 28/04/06, kevin parks <[EMAIL PROTECTED]> wrote: > > In most case you are fine operating on the list in place and altering the > > existing list. In some cases you want your code to stop molesting your poor > > mutables and really honestly sin

Re: [Tutor] Regex across multiple lines

2006-04-27 Thread Ed Singleton
On 26/04/06, Liam Clarke <[EMAIL PROTECTED]> wrote: > Hi Frank, just bear in mind that the pattern: > > patObj = re.compile(".*", re.DOTALL) > > will match > > >This is my title > > > But, it'll also match > > >This is my title > > Some content here > > Another title; not going to

Re: [Tutor] Looping over lists of objects

2006-04-24 Thread Ed Singleton
On 24/04/06, Etrade Griffiths <[EMAIL PROTECTED]> wrote: > Hi > > just feeling my way into Python with a small app that reads data from > file, creates objects using that data, stores the objects in a list, loops > over the list doing comparison tests to filter out various objects. Here is > a

Re: [Tutor] Tutor FAQ?

2006-04-22 Thread Ed Singleton
> Yep, I'm volunteering. Forgive my ignorance, but I couldn't seem to figure > out how to edit/add pages to http://pyfaq.infogami.com/. The tutorial wiki > has the edit, but the pyfaq page doesn't. I am logged in using my reddit > login. I don't think the FAQ is open to public editing yet. I'm no

Re: [Tutor] Tutor FAQ?

2006-04-21 Thread Ed Singleton
On 21/04/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: > > If anyone here > > has ideas for questions that get asked a lot (like "How do I write a > > program that prints a word backwards") then just posting them in this > > thr

Re: [Tutor] Tutor FAQ?

2006-04-21 Thread Ed Singleton
On 20/04/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Mike Hansen wrote: > > I'd like to send a big Thank You to Danny, Alan, Kent and others(whos names > > escape me) for being such an asset to the Python community by relentlessly > > answering questions on the tutor list.(Do these guys sleep? Th

[Tutor] Force a value to int

2006-04-13 Thread Ed Singleton
Is there a particular way to force a value to be an int by either converting it with int() or returning a default value. I've ended up writing my own function to do it, but it seems like the kind of thing that would be built-in somewhere. Ed ___ Tutor m

Re: [Tutor] Database Connectivity

2006-04-11 Thread Ed Singleton
On 11/04/06, Kaushal Shriyan <[EMAIL PROTECTED]> wrote: > Hi ALL > > How do i connect my python program to MySQL DB or Oracle DB or can you > please specify the URL which gives a detailed explanation on this. SQLObject is your best bet: http://www.sqlobject.org/ If you're using MySQL, you will ne

Re: [Tutor] Emailid

2006-04-11 Thread Ed Singleton
On 11/04/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Kaushal Shriyan wrote: > > Hi All > > > > I am a ardent fan of python can I have email address for me > > I mean For example for me it would be > > > > [EMAIL PROTECTED] > > I don't know how you get a python.org mailing address but I'm sure it'

Re: [Tutor] failing to learn python

2006-04-11 Thread Ed Singleton
On 10/04/06, Payal Rathod <[EMAIL PROTECTED]> wrote: > Hi, > I am trying to learn Python seriously for almost 2 months but have not > gotten far at all. Infact, it seems I have not understood even the basic > concepts itself. I know some shell, sed and awk programming. > I have tried reading Learni

Re: [Tutor] Program for outputing the letter backward

2006-03-30 Thread Ed Singleton
On 29/03/06, Hoffmann <[EMAIL PROTECTED]> wrote: > --- John Fouhy <[EMAIL PROTECTED]> wrote: > > > On 29/03/06, Hoffmann <[EMAIL PROTECTED]> wrote: > > > vehicle='car' > > > index = vehicle[-1] #the last letter > > > index_zero = vehicle[0] #the first letter > > > > > > while index >= index

Re: [Tutor] Dynamically naming functions

2006-03-27 Thread Ed Singleton
On 26/03/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: > > How does one go about creating functions, classes, or callable objects > > when you don't know their name in advance? (For example you want to > > read their names in from a text file or

Re: [Tutor] Opening .py files in firefox

2006-03-21 Thread Ed Singleton
On 20/03/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > If the browser tries to execute the script you will need to go to > > the file types setting in the browser and set .py to plain-text. > > > > This is what I need to do ... but, after looking at all the options > > (within tools->Options), I st

Re: [Tutor] Converting String to Datetime

2006-03-15 Thread Ed Singleton
time.strptime(mytime, time_format))) Ed On 15/03/06, Ed Singleton <[EMAIL PROTECTED]> wrote: > I seem to have a lot of questions today. Sorry. > > How can I convert a string in the format "%Y-%m-%d %H:%M:%S" into a > datetime object? > > I can work out

[Tutor] Converting String to Datetime

2006-03-15 Thread Ed Singleton
I seem to have a lot of questions today. Sorry. How can I convert a string in the format "%Y-%m-%d %H:%M:%S" into a datetime object? I can work out how to convert it to a time object by: import time timestring = "2005-09-01 12:30:09" time_format = "%Y-%m-%d %H:%M:%S" mytime = time.strptime(time

Re: [Tutor] Passing Dictionaries to Functions

2006-03-15 Thread Ed Singleton
s when you don't know what they're called is a bit of a stumbling block sometimes. Maybe a page that very briefly summarises the 'unsearchable' with links to fuller descriptions? Ed On 15/03/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: > >

[Tutor] Passing Dictionaries to Functions

2006-03-15 Thread Ed Singleton
If I have a dictionary: mydict{'var1':"a", 'var2':"b"} and I want to pass it to a function as: myfunc(var1="a", var2="b") How would I do it? Thanks Ed ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Using Beautiful Soup to extract tag names

2006-03-14 Thread Ed Singleton
As always Kent, you're amazing. That will do perfectly. (Though the ElementTree documentation seems a bit difficult to get through. I'm sure I'll get through it eventually). Thanks Ed On 14/03/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: &

[Tutor] Using Beautiful Soup to extract tag names

2006-03-14 Thread Ed Singleton
I have (unfortunately) received some data in XML format. I need to use it in Python, preferably as a list of dictionaries. The data is a flat representation of a table, in the style: Some Data Some Data ... Some Data Some Data ... and so on (where tablename is always the same in one file).

Re: [Tutor] Dynamically naming functions

2006-03-14 Thread Ed Singleton
On 13/03/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > For website, I can't really see how I can not have a dynamic > > structure. There's no way I'm writing a function for each "folder". > > Hmm, this may be a CherryPie concept thing but the vast majority > of websites do not have dynamic structu

Re: [Tutor] Dynamically naming functions

2006-03-13 Thread Ed Singleton
On 13/03/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: > > On 10/03/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > > > >>Ed Singleton wrote: > >>>I want to use this in a few different places. For example Faces, the > >>&g

Re: [Tutor] Dynamically naming functions

2006-03-13 Thread Ed Singleton
On 10/03/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > How does one go about creating functions, classes, or callable objects > > when you don't know their name in advance? (For example you want to > > read their names in from a text file or database). > > First point, names of functions are no dif

Re: [Tutor] Dynamically naming functions

2006-03-13 Thread Ed Singleton
On 10/03/06, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: > > How does one go about creating functions, classes, or callable objects > > when you don't know their name in advance? (For example you want to > > read their names in from a text file or

[Tutor] Dynamically naming functions

2006-03-10 Thread Ed Singleton
How does one go about creating functions, classes, or callable objects when you don't know their name in advance? (For example you want to read their names in from a text file or database). I want to use this in a few different places. For example Faces, the Python Project Management Planner Tool

Re: [Tutor] Another try at Python's selfishness

2006-02-04 Thread Ed Singleton
On 04/02/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > I have to say that as a newbie, it took me quite a while to get my > > head around that extra parameter (self). > > That's OK, its true of most folks, even non newbies! > It is one area where Python is different to most languages > who hide the

Re: [Tutor] Another try at Python's selfishness

2006-02-03 Thread Ed Singleton
On 3 Feb 2006 03:59:10 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > I still see "newbie-friendliness" as a > > MAJOR plus for Python -- it increases the chance that users > > of your software will become contributors. > > Yes, I 100% agree to that point! > But the point is, the current s

Re: [Tutor] Newbie question re. Functions

2006-02-01 Thread Ed Singleton
On 31/01/06, Jon Moore <[EMAIL PROTECTED]> wrote: > Improve the function ask_number() so that the function can be called with a > step value. Make the default value of step 1. > > The function looks like this: > > def ask_number(question, low, high): > """Ask for a number within the range""" >

Re: [Tutor] How can I make a python script go directory by directory and excecute on files of choice

2006-01-11 Thread Ed Singleton
On 11/01/06, Liam Clarke <[EMAIL PROTECTED]> wrote: > Hi Srinivas - > > For walking a directory, you can use os.walk() or os.path.walk(), but > I prefer the path module here - > http://www.jorendorff.com/articles/python/path/. The Path module is excellent, but it's walk still doesn't take into acc

Re: [Tutor] List-question

2005-12-19 Thread Ed Singleton
On 19/12/05, Ed Singleton <[EMAIL PROTECTED]> wrote: > On 19/12/05, Øyvind <[EMAIL PROTECTED]> wrote: > > I have one function that finds some values. Then I want that function to > > find new values based on the values it found first. However, by just > > loo

Re: [Tutor] List-question

2005-12-19 Thread Ed Singleton
On 19/12/05, Øyvind <[EMAIL PROTECTED]> wrote: > I have one function that finds some values. Then I want that function to > find new values based on the values it found first. However, by just > looping, it starts on an eternal job. > > As illustrated in: > >>> list = [1,2,3] > >>> list2 = list > >

Re: [Tutor] Accessing next and previous items during iteration

2005-12-19 Thread Ed Singleton
On 18/12/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: > > Is it possible to access the next and previous items during an iteration? > > This just came up on c.l.python. Bengt Richter has a nice generator-based > solution. > http://groups.google

[Tutor] Accessing next and previous items during iteration

2005-12-16 Thread Ed Singleton
Is it possible to access the next and previous items during an iteration? I want to use it to iterate through html files in a folder and add links in to the next and previous pages. For example for page in folder: #add link to previous page #add link to next page I'm currently using: p

Re: [Tutor] Modifying Source Code while Program is Running

2005-11-26 Thread Ed Singleton
On 26/11/05, Alan Gauld <[EMAIL PROTECTED]> wrote: > >> point. Classes express behaviour, the data is only there to support > >> the behaviour. Thats why methods are polymorphic but not attributes. > > > >If classes express behaviour, then what expresses the structure of the > > data? > > Why do yo

Re: [Tutor] Modifying Source Code while Program is Running

2005-11-26 Thread Ed Singleton
On 26/11/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: > >>>This immediately seemed to me to be a case for classes. > >>>You provide a way for a user to create a new class by > >>>subclassing the page class (from their point of view

Re: [Tutor] Modifying Source Code while Program is Running

2005-11-26 Thread Ed Singleton
On 25/11/05, Alan Gauld <[EMAIL PROTECTED]> wrote: > > Hi Ed, > > This is a longish response because you are raising some > very interesting (and deep) issues from a computer science > point of view. > > > Well, self-modifying isn't inherently necessary. What I guess I > > really need is persisten

Re: [Tutor] Modifying Source Code while Program is Running

2005-11-26 Thread Ed Singleton
On 25/11/05, Alan Gauld <[EMAIL PROTECTED]> wrote: > > Just had a quick look at Smalltalk, and at first glance the overview > > of the ideas behind it seems amazing, but the language seems quite > > ugly, and it seems to be very IDE led. > > Adherents will defend its simplicity but I confess I stru

Re: [Tutor] Modifying Source Code while Program is Running

2005-11-25 Thread Ed Singleton
On 25/11/05, Ismael Garrido <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: > > >I want to create a small simple CMS for my website. Users will be > >able to add and edit basic pages. Pages can have sub-pages (no need > >for folders cause a folder and an inde

Re: [Tutor] Modifying Source Code while Program is Running

2005-11-25 Thread Ed Singleton
On 24/11/05, Alan Gauld <[EMAIL PROTECTED]> wrote: > There are many ways of doing this, few of them very nice IMHO. > > > without having to restart the program? Is it feasible to get a > > program to change it's own source code while it is running? > > Yes, you can overwrite an existing module the

Re: [Tutor] Modifying Source Code while Program is Running

2005-11-25 Thread Ed Singleton
On 24/11/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: > > Is it feasible to change a program's source code whilst it is running > > without having to restart the program? Is it feasible to get a > > program to change it's own source

Re: [Tutor] Modifying Source Code while Program is Running

2005-11-24 Thread Ed Singleton
On 24/11/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: > > Is it feasible to change a program's source code whilst it is running > > without having to restart the program? Is it feasible to get a > > program to change it's own source

[Tutor] Modifying Source Code while Program is Running

2005-11-24 Thread Ed Singleton
Is it feasible to change a program's source code whilst it is running without having to restart the program? Is it feasible to get a program to change it's own source code while it is running? For example, if you have a web server such as CherryPy that will (hopefully) be running for months at a

Re: [Tutor] Inheriting from parent object

2005-11-22 Thread Ed Singleton
Thanks for this. I hadn't really considered that I would have to explicitly store parent/child relationships. Having been browsing for something else, I came across this page about Unifying types and classes: http://www.python.org/2.2.3/descrintro.html >From it, it looks like I could do somethin

Re: [Tutor] Newb ?

2005-11-17 Thread Ed Singleton
These both work (though neither is very graceful). text = "hello" message = "" for i in range(len(text)): message = message + text[(len(text)-i-1)] print message lst = list(text) newstr = "" for item in text: newstr += (lst.pop()) print newstr On 16/11/05, Chad Everett <[EMAIL

[Tutor] Inheriting from parent object

2005-11-14 Thread Ed Singleton
I want to create a property that will inherit it's value from the same property in it's parent object, but will check it's parent's propety everytime it is called. But that can be over-ridden, and I don't have to know what the objects parent is. For example: object.x = 3 object.subobject.x = inh

Re: [Tutor] Rename files with numbers

2005-11-01 Thread Ed Singleton
The best free app I've found for this is MusicBrainz [www.musicbrainz.com]. This has a huge database of obsessively correct details of albums which can be formatted in anyway you choose. It can automatically recognise which song an MP3 is! This is a similar script I wrote to renumber files in se

Re: [Tutor] Rename files with numbers

2005-11-01 Thread Ed Singleton
Sorry, wrong list. Many apologies. Ed On 01/11/05, Ed Singleton <[EMAIL PROTECTED]> wrote: > The best free app I've found for this is MusicBrainz [www.musicbrainz.com]. > > This has a huge database of obsessively correct details of albums > which can be formatted in any

[Tutor] OT - Re: Can anyone help me?

2005-10-28 Thread Ed Singleton
You can actually increase your chance of winning in the English lottery. If two many tickets win a prize in one draw, the lowest prize (£10 for three numbers) is not paid out. Also the jackpot is shared between all the winning tickets (6 numbers) some sets of numbers like 1,2,3,4,5,6 are chosen b

[Tutor] Passing Functions or Code as Parameters

2005-10-27 Thread Ed Singleton
How can I pass a block of code to a function for it to perform within itself? For example, I wrote a small function that recurses through a directory structure but keeps a track of the depth: from path import path def traverse(directory, depth=0): thedir = path(directory) for item in the

Re: [Tutor] Question about an re

2005-10-27 Thread Ed Singleton
OR tests for the truth of the first thing then the truth of the second. The first part of your OR is always true, so it doesn't test the second. What you really want to do is look for a digit and then look for more digits or a slash and some more digits. So: : \d(\d+|/\d+) but this is easier b

[Tutor] Fwd: Saving command line keyed input?

2005-10-21 Thread Ed Singleton
A quick tip for the Windows command line. Ctrl-C, Ctrl-A etc don't work, neither does right-clicking (menu-click). However, right-clicking does work on the blue title bar. Right-click on the blue title bar and then go down to Edit and then you can Select All. Then right-click on the blue title

Re: [Tutor] htmllib

2005-10-05 Thread Ed Singleton
You're like some kind of god! That's exactly what I need. Thanks Ed On 05/10/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > Ed Singleton wrote: > > I want to dump a html file into a python object. Each nested tag > > would be a sub-object, attributes would be pro

[Tutor] htmllib

2005-10-05 Thread Ed Singleton
I want to dump a html file into a python object. Each nested tag would be a sub-object, attributes would be properties. So that I can use Python in a similar way to the way I use JavaScript within a web page. I looked at htmllib, but the documentation seems quite limited, and as far as I can tel

Re: [Tutor] find data in html file

2005-09-28 Thread Ed Singleton
On 27/09/05, lmac <[EMAIL PROTECTED]> wrote: > Hi there, > i have a base-question. If i want to read some kind of data out of a line > which i know the start-tag and the end-tag in an html-file how do i > recognize > if it's more than one line ? > > Example: > > Some textlinktext . DATA et

[Tutor] Remaking Vim in Python (was Python Editors)

2005-09-23 Thread Ed Singleton
I'd like a little advice on whether I'm being really stupid here. Having researched editors and stuff, I've not quite found what I'm looking for, though Vim comes close (except that it's extremely difficult to work out what to do with it). My instinct was to try and write a small program similar

Re: [Tutor] Python Editors (particualrly Vim)

2005-09-22 Thread Ed Singleton
the word you're typing based on what you've already written in the file. I've also been trying SPE and that looks to be the most pleasing editor so far. It's also written in Python (AFAICT) which will probably have benefits in the future. Ed On 21/09/05, Ed Singleton <[EMAI

Re: [Tutor] Python Editors (particualrly Vim)

2005-09-21 Thread Ed Singleton
in the help > manual that comes with it (:h) or at vim.org. > > gsf > > [1] http://www.dgp.toronto.edu/~mjmcguff/learn/vim/folding.txt > [2] http://www.vim.org/tips/tip.php?tip_id=83 > > > On Wed, Sep 21, 2005 at 02:00:20PM +0100, Ed Singleton wrote: > > I've bee

[Tutor] Python Editors (particualrly Vim)

2005-09-21 Thread Ed Singleton
I've been trying to decide which editor to use to edit Python (on Windows mostly). My wishlist of features would be: - automatic code formatting (indentation etc) - collapsible code (to collapse def's etc) - automatic code coloring (that's easily changeable) - auto-completion of namespaces - easy

Re: [Tutor] Multiple Simultaneous Loops

2005-09-15 Thread Ed Singleton
Wonderful, thank you all of you. zip, enumerate, and count seem to do everything I want, though I do think for f, x in bunch_of_files, range(z): is a little more intuitive than for f, x in zip(bunch_of_files, range(z)): Thanks Ed On 15/09/05, Kent Johnson <[EMAIL PROTECTED]> wrote

[Tutor] Multiple Simultaneous Loops

2005-09-15 Thread Ed Singleton
I roughly want to be able to do: for f, x in bunch_of_files, range(z): so that x iterates through my files, and y iterates through something else. Is this something I can do? If so, what would be the best way to create a range of indeterminate length? If not, is there a nice way I can do it, r

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

2005-06-22 Thread Ed Singleton
> 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've already printed > > rather than print again? ___

[Tutor] Changing what you've already printed

2005-06-22 Thread Ed Singleton
Is it possible (and easy) to change something you've already printed rather than print again? For example, if I'm making a little noughts and crosses game and I print the board: | | | | ___|___|___ | | | | ___|___|___ | | | | | | Then the c