[Tutor] Documenting a Module

2010-09-13 Thread Michael Powe
Hello, Are there any tools for documenting a module other than Sphinx? Apparently, I need a full-blown dev box with Visual Studio installed to get Sphinx up, due to the dependency on Jinja, which comes source-only and requires VC. I wrote a module, I'd like to produce a decent document of its

Re: [Tutor] Documenting a Module

2010-09-13 Thread r...@schoenian-online.de
Hi Michael,   I can recommend epydoc. You can find it here:  http://epydoc.sourceforge.net/ It's a nice tool and you should have no problems with the installation.   Ralf       Michael Powe hat am 13. September 2010 um 11:54 geschrieben: > Hello, > > Are there any tools for documenting a module

Re: [Tutor] exceptions problem

2010-09-13 Thread Francesco Loffredo
On 11/09/2010 20.43, bob gailer wrote: On 9/11/2010 12:12 PM, Roelof Wobben wrote: ... You can't. I made that comment in the context of the OPs function: def readposint(): x = raw_input("Please enter a positive integer :") try: if (int(x)<0 or (float(x) - int(x)> 0)): raise(ValueError) except

Re: [Tutor] classmethod, staticmethod functions (decorator related)

2010-09-13 Thread Steven D'Aprano
On Mon, 13 Sep 2010 12:29:07 pm Huy Ton That wrote: > Hm, thanks guys; I just had to verify I was thinking sanely about it. > I am going to pick up classmethods next. Do any of you have common > design patterns for the usage. They are just items I haven't > integrated in my coding, and I want to be

Re: [Tutor] exceptions problem

2010-09-13 Thread Steven D'Aprano
On Mon, 13 Sep 2010 08:55:46 pm Francesco Loffredo wrote: > I don't like this rough behaviour of int(), spitting out an > exception if given a legitimate string representation of a float. Can > some of you Tutors explain me why it must be so? The int() function behaves as a constructor, producing

[Tutor] wierd replace problem

2010-09-13 Thread Roelof Wobben
Hello, I have this string called test with the contents of 'het is een wonder \\TIS' Now I want to get rid of the \\ so I do this : test2 = test.replace ('\\', '') And I get at the python prompt this answer : 'het is een wonder TIS' So that's right. Now I try the same in a IDE with this progr

Re: [Tutor] exceptions problem

2010-09-13 Thread Francesco Loffredo
First, *THANK YOU!* for your clear and thorough explaination, Steven. On 13/09/2010 13.59, Steven D'Aprano wrote: On Mon, 13 Sep 2010 08:55:46 pm Francesco Loffredo wrote: I don't like this rough behaviour of int(), spitting out an exception if given a legitimate string representation of a floa

Re: [Tutor] wierd replace problem

2010-09-13 Thread Michael Powe
Hello, In your script, you need to escape each backslash, in order to have it come out correctly to the interpreter. IOW, in the shell, '\\' is what is being processed. But in your script, you want to send '\\' to the shell, and in order to do that, you have to escape each backslash, or ''.

Re: [Tutor] Documenting a Module

2010-09-13 Thread Michael Powe
On Mon, Sep 13, 2010 at 12:03:27PM +0200, r...@schoenian-online.de wrote: > > Hi Michael, > ?? > I can recommend epydoc. You can find it here: > ??http://epydoc.sourceforge.net/??It's a nice tool and you should have no > problems > with the installation. > ?? > Ralf > ?? > ?? > ?? Thank you, muc

Re: [Tutor] classmethod, staticmethod functions (decorator related)

2010-09-13 Thread Huy Ton That
Thank you all, I was taking a look at the module decimal.py as you cited, and it makes sense now. Looks very useful to make tools without having to instantiate anything. On Mon, Sep 13, 2010 at 7:05 AM, Steven D'Aprano wrote: > On Mon, 13 Sep 2010 12:29:07 pm Huy Ton That wrote: > > Hm, thanks g

Re: [Tutor] wierd replace problem

2010-09-13 Thread bob gailer
On 9/13/2010 8:19 AM, Roelof Wobben wrote: Hello, I have this string called test with the contents of 'het is een wonder \\TIS' Now I want to get rid of the \\ so I do this : test2 = test.replace ('\\', '') And I get at the python prompt this answer : 'het is een wonder TIS' So that's right.

[Tutor] wierd replace problem

2010-09-13 Thread Roelof Wobben
> From: rwob...@hotmail.com > To: bgai...@gmail.com > Subject: RE: [Tutor] wierd replace problem > Date: Mon, 13 Sep 2010 15:19:12 + > > > > > >> Date: Mon, 13 Sep 2010 11:07:19 -0400 >> From: bgai...@gmail.com

[Tutor] Fwd: RE: wierd replace problem

2010-09-13 Thread bob gailer
Forwarding to the list. Date: Mon, 13 Sep 2010 11:07:19 -0400 From: bgai...@gmail.com To: tutor@python.org Subject: Re: [Tutor] wierd replace problem On 9/13/2010 8:19 AM, Roelof Wobben wrote: Hello, I h

[Tutor] Serial communication ...

2010-09-13 Thread Markus Hubig
Hi @all! I'm about to write a class for serial communication on Win32 and Linux which provides a method called "talk" to send something over the serial line, wait for the answer and returns it. My problem is, that I don't know how long the answer will be (ok max 260 bytes but most answers are much

Re: [Tutor] wierd replace problem

2010-09-13 Thread Michael Powe
On Mon, Sep 13, 2010 at 12:19:23PM +, Roelof Wobben wrote: > > Hello, > > I have this string called test with the contents of 'het is een wonder \\TIS' > > Now I want to get rid of the \\ so I do this : test2 = test.replace ('\\', '') > And I get at the python prompt this answer : 'het is e

Re: [Tutor] Documenting a Module

2010-09-13 Thread Michael Powe
On Mon, Sep 13, 2010 at 12:03:27PM +0200, r...@schoenian-online.de wrote: > > Hi Michael, > I can recommend epydoc. You can find it here: > ??http://epydoc.sourceforge.net/??It's a nice tool and you should > have no problems with the installation. > Ralf Hello, I just want to follow up that ep

Re: [Tutor] wierd replace problem

2010-09-13 Thread Roelof Wobben
Date: Mon, 13 Sep 2010 12:17:47 -0400 From: mich...@trollope.org To: tutor@python.org Subject: Re: [Tutor] wierd replace problem On Mon, Sep 13, 2010 at 12:19:23PM +, Roelof Wobben wrote: > > Hello, > > I have this string called test with the conten

Re: [Tutor] wierd replace problem

2010-09-13 Thread Joel Goldstick
On Mon, Sep 13, 2010 at 12:37 PM, Roelof Wobben wrote: > > > > > Date: Mon, 13 Sep 2010 12:17:47 -0400 > From: mich...@trollope.org > To: tutor@python.org > Subject: Re: [Tutor] wierd replace problem > > > On Mon, Sep 13, 2010 at 12:19:23PM +, Roelof W

[Tutor] wierd replace problem

2010-09-13 Thread Roelof Wobben
> From: rwob...@hotmail.com > To: joel.goldst...@gmail.com > Subject: RE: [Tutor] wierd replace problem > Date: Mon, 13 Sep 2010 16:45:28 + > > > > > >> Date: Mon, 13 Sep 2010 12:42:56 -0400 >> From: joel.goldst...@gma

Re: [Tutor] wierd replace problem

2010-09-13 Thread Roelof Wobben
> From: rwob...@hotmail.com > To: tutor@python.org > Date: Mon, 13 Sep 2010 16:46:09 + > Subject: [Tutor] wierd replace problem > > > > > >> From: rwob...@hotmail.com >> To: joel.goldst...@gmail.com >> Subject:

Re: [Tutor] classmethod, staticmethod functions (decorator related)

2010-09-13 Thread Alan Gauld
"Huy Ton That" wrote I was taking a look at the module decimal.py as you cited, and it makes sense now. Looks very useful to make tools without having to instantiate anything. Thats not a good way to think of them. Doing things without instantiating is usually better done by a function.

Re: [Tutor] wierd replace problem

2010-09-13 Thread Alan Gauld
"Roelof Wobben" wrote Now I want to get rid of the \\ so I do this : test2 = test.replace ('\\', '') And I get at the python prompt this answer : 'het is een wonder TIS' So that's right. OK,. Thats replacing a double slash in the data for line in file: line2 = line.replace ("\\","")

Re: [Tutor] wierd replace problem

2010-09-13 Thread bob gailer
On 9/13/2010 12:58 PM, Roelof Wobben wrote: The orginal text can be found here : http://openbookproject.net/thinkcs/python/english2e/resources/ch10/alice_in_wonderland.txt There are no \ in that text! -- Bob Gailer 919-636-4239 Chapel Hill NC

Re: [Tutor] wierd replace problem

2010-09-13 Thread Roelof Wobben
> To: tutor@python.org > From: alan.ga...@btinternet.com > Date: Mon, 13 Sep 2010 18:28:46 +0100 > Subject: Re: [Tutor] wierd replace problem > > > "Roelof Wobben" wrote > >> Now I want to get rid of the \\ so I do this : test2 = test.replace >> ('\\', ''

Re: [Tutor] wierd replace problem

2010-09-13 Thread bob gailer
On 9/13/2010 1:50 PM, Roelof Wobben wrote: [snip] hello Alan, Your right. Then it prints like this "'tis Which is not right. It must be tis. So the replace does not what it supposed to do. Sorry but I am now more confused. After discovering no \ in the text file now you seem to have have a n

Re: [Tutor] wierd replace problem

2010-09-13 Thread Joel Goldstick
On Mon, Sep 13, 2010 at 2:08 PM, bob gailer wrote: > On 9/13/2010 1:50 PM, Roelof Wobben wrote: > > [snip] > > hello Alan, >> >> Your right. Then it prints like this "'tis >> Which is not right. It must be tis. >> So the replace does not what it supposed to do. >> >> Sorry but I am now more co

[Tutor] FW: wierd replace problem

2010-09-13 Thread Roelof Wobben
> From: rwob...@hotmail.com > To: bgai...@gmail.com > Subject: RE: [Tutor] wierd replace problem > Date: Mon, 13 Sep 2010 18:19:43 + > > > > > >> Date: Mon, 13 Sep 2010 14:08:46 -0400 >> From: bgai...@gmail.co

[Tutor] FW: wierd replace problem

2010-09-13 Thread Roelof Wobben
> From: rwob...@hotmail.com > To: joel.goldst...@gmail.com > Subject: RE: [Tutor] wierd replace problem > Date: Mon, 13 Sep 2010 18:23:36 + > > > > > >> Date: Mon, 13 Sep 2010 14:18:36 -0400 >> From: joel.goldst...@gma

Re: [Tutor] Serial communication ...

2010-09-13 Thread Markus Hubig
On Mon, Sep 13, 2010 at 6:10 PM, André da Palma wrote: > Last year i was working with serial communication as well and there is > already a library for python, i guess it's pySerial. Try to google it, > perhaps it can be useful for you. Yes you're totally right! And that's the package im using

[Tutor] What's the best way to ask forgiveness here?

2010-09-13 Thread Brian Jones
I've been coding Python long enough that 'asking forgiveness instead of permission' is my first instinct, but the resulting code is sometimes clumsy, and I wonder if someone can suggest something I'm missing, or at least validate what's going on here in some way. What I'm trying to do is write a f

Re: [Tutor] Serial communication ...

2010-09-13 Thread Adam Bark
On 13/09/10 16:36, Markus Hubig wrote: Hi @all! I'm about to write a class for serial communication on Win32 and Linux which provides a method called "talk" to send something over the serial line, wait for the answer and returns it. My problem is, that I don't know how long the answer will b

Re: [Tutor] Serial communication ...

2010-09-13 Thread Emile van Sebille
On 9/13/2010 8:36 AM Markus Hubig said... Hi @all! I'm about to write a class for serial communication on Win32 and Linux which provides a method called "talk" to send something over the serial line, wait for the answer and returns it. My problem is, that I don't know how long the answer will be

Re: [Tutor] What's the best way to ask forgiveness here?

2010-09-13 Thread Emile van Sebille
On 9/13/2010 11:31 AM Brian Jones said... I've been coding Python long enough that 'asking forgiveness instead of permission' is my first instinct, but the resulting code is sometimes clumsy, and I wonder if someone can suggest something I'm missing, or at least validate what's going on here in s

Re: [Tutor] Serial communication ...

2010-09-13 Thread Markus Hubig
On Mon, Sep 13, 2010 at 8:33 PM, Adam Bark wrote: > Ideally you would send a specific ending packet and you read one byte at a > time until the > right sequence comes up. Alternatively you could have the first byte as a > length indicator. > Oh my dear! You're damn right! The protocol im impleme

Re: [Tutor] What's the best way to ask forgiveness here?

2010-09-13 Thread Adam Bark
On 13/09/10 19:31, Brian Jones wrote: I've been coding Python long enough that 'asking forgiveness instead of permission' is my first instinct, but the resulting code is sometimes clumsy, and I wonder if someone can suggest something I'm missing, or at least validate what's going on here in som

Re: [Tutor] What's the best way to ask forgiveness here?

2010-09-13 Thread Evert Rol
> I've been coding Python long enough that 'asking forgiveness instead of > permission' is my first instinct, but the resulting code is sometimes clumsy, > and I wonder if someone can suggest something I'm missing, or at least > validate what's going on here in some way. > > What I'm trying to

Re: [Tutor] What's the best way to ask forgiveness here?

2010-09-13 Thread Brian Jones
Thanks for the replies so far. One thing that's probably relevant: once a directory is created, I can expect to write a couple of hundred files to it, so doing a 'try os.makedirs' right off the bat strikes me as coding for the *least* common case instead of the *most* common (which is that the dire

Re: [Tutor] What's the best way to ask forgiveness here?

2010-09-13 Thread davidheiserca
I suggest something like: try: os.makedirs(path) except: pass open("%s/%s" % (path, filename), 'w').write(filedata) - Original Message - From: "Emile van Sebille" To: Sent: Monday, September 13, 2010 11:56 AM Subject: Re: [Tutor] What's the best way to ask forgiveness here?

Re: [Tutor] FW: wierd replace problem

2010-09-13 Thread Roelof Wobben
> Date: Mon, 13 Sep 2010 15:31:08 -0400 > Subject: Re: [Tutor] FW: wierd replace problem > From: joel.goldst...@gmail.com > To: rwob...@hotmail.com > > > > On Mon, Sep 13, 2010 at 2:24 PM, Roelof Wobben >> wrote: > > > > >

Re: [Tutor] What's the best way to ask forgiveness here?

2010-09-13 Thread Adam Bark
On 13/09/10 20:12, Brian Jones wrote: Thanks for the replies so far. One thing that's probably relevant: once a directory is created, I can expect to write a couple of hundred files to it, so doing a 'try os.makedirs' right off the bat strikes me as coding for the *least* common case instead of

[Tutor] input problem

2010-09-13 Thread ANKUR AGGARWAL
Suppose i am taking input or various variables like a=raw_input("...") //hello b=raw_input("")//hi c=raw_input("...")//hello d=raw_input("..")//hello but i want to run a common function when input is hello so instead of if a=="hello": fun() then aga

Re: [Tutor] input problem

2010-09-13 Thread christopher . henk
ANKUR AGGARWAL wrote on 09/13/2010 04:45:41 PM: > Suppose i am taking input or various variables like > a=raw_input("...") //hello > b=raw_input("")//hi > c=raw_input("...")//hello > d=raw_input("..")//hello > but i want to run a common function when

Re: [Tutor] input problem

2010-09-13 Thread James Mills
On Tue, Sep 14, 2010 at 6:45 AM, ANKUR AGGARWAL wrote: > Suppose i am taking input or various variables like > a=raw_input("...") //hello > b=raw_input("")//hi > c=raw_input("...")//hello > d=raw_input("..")//hello > but i want to run a common functi

Re: [Tutor] FW: wierd replace problem

2010-09-13 Thread bob gailer
On 9/13/2010 2:21 PM, Roelof Wobben wrote: From: rwob...@hotmail.com To: bgai...@gmail.com Subject: RE: [Tutor] wierd replace problem Date: Mon, 13 Sep 2010 18:19:43 + I suggest you give a clear, complete and correct problem statement. Right now

Re: [Tutor] wierd replace problem

2010-09-13 Thread Steven D'Aprano
On Tue, 14 Sep 2010 04:18:36 am Joel Goldstick wrote: > How about using str.split() to put words in a list, then run strip() > over each word with the required characters to be removed ('`") Doesn't work. strip() only removes characters at the beginning and end of the word, not in the middle:

Re: [Tutor] wierd replace problem

2010-09-13 Thread Joel Goldstick
On Mon, Sep 13, 2010 at 6:41 PM, Steven D'Aprano wrote: > On Tue, 14 Sep 2010 04:18:36 am Joel Goldstick wrote: > > > How about using str.split() to put words in a list, then run strip() > > over each word with the required characters to be removed ('`") > > > Doesn't work. strip() only removes ch

Re: [Tutor] FW: wierd replace problem

2010-09-13 Thread Steven D'Aprano
On Tue, 14 Sep 2010 08:05:33 am bob gailer wrote: > > 3.Write a program called alice_words.py that creates a text file > > named alice_words.txt containing an alphabetical listing of all the > > words found in alice_in_wonderland.txt together with the number of > > times each word occurs. The firs

Re: [Tutor] wierd replace problem

2010-09-13 Thread Steven D'Aprano
On Tue, 14 Sep 2010 09:08:24 am Joel Goldstick wrote: > On Mon, Sep 13, 2010 at 6:41 PM, Steven D'Aprano wrote: > > On Tue, 14 Sep 2010 04:18:36 am Joel Goldstick wrote: > > > How about using str.split() to put words in a list, then run > > > strip() over each word with the required characters to

Re: [Tutor] What's the best way to ask forgiveness here?

2010-09-13 Thread Steven D'Aprano
On Tue, 14 Sep 2010 05:07:03 am Evert Rol wrote: > Note 2: the directory can exist, but not have write access to your > process. So between the try-except for creating a directory and the > try-except for creating a file, you may put in a try-except for > chmod. If some application tried changing

Re: [Tutor] What's the best way to ask forgiveness here?

2010-09-13 Thread Steven D'Aprano
On Tue, 14 Sep 2010 04:31:00 am Brian Jones wrote: > I've been coding Python long enough that 'asking forgiveness instead > of permission' is my first instinct, but the resulting code is > sometimes clumsy, and I wonder if someone can suggest something I'm > missing, or at least validate what's goi

Re: [Tutor] What's the best way to ask forgiveness here?

2010-09-13 Thread Steven D'Aprano
On Tue, 14 Sep 2010 05:12:12 am Brian Jones wrote: > Thanks for the replies so far. One thing that's probably relevant: > once a directory is created, I can expect to write a couple of > hundred files to it, so doing a 'try os.makedirs' right off the bat > strikes me as coding for the *least* commo

[Tutor] How to numerically sort strings that start with numbers?

2010-09-13 Thread Pete O'Connell
theList = ["21 trewuuioi","3zxc","134445"] print sorted(theList) Hi, the result of the sorted list above doesn't print in the order I want. Is there a straight forward way of getting python to print ['3zxc','21 trewuuioi','134445'] rather than ['134445', '21 trewuuioi', '3zxc']? Any help would be

Re: [Tutor] How to numerically sort strings that start with numbers?

2010-09-13 Thread Adam Bark
On 14/09/10 01:11, Pete O'Connell wrote: theList = ["21 trewuuioi","3zxc","134445"] print sorted(theList) Hi, the result of the sorted list above doesn't print in the order I want. Is there a straight forward way of getting python to print ['3zxc','21 trewuuioi','134445'] rather than ['134445',

Re: [Tutor] How to numerically sort strings that start with numbers?

2010-09-13 Thread David Hutto
On Mon, Sep 13, 2010 at 9:11 PM, Adam Bark wrote: > On 14/09/10 01:11, Pete O'Connell wrote: >> >> theList = ["21 trewuuioi","3zxc","134445"] >> print sorted(theList) >> >> Hi, the result of the sorted list above doesn't print in the order I >> want. Is there a straight forward way of getting pyth

Re: [Tutor] How to numerically sort strings that start with numbers?

2010-09-13 Thread Adam Bark
On 14/09/10 02:24, Pete O'Connell wrote: Hi I don't actaully need the list printed reversed, I need it printed from smallest number to largest Just sorting gives you the list from smallest to largest. For example: # theList = ["21 trewuuioi","374zxc","13447"] print sorted(theL

[Tutor] If/elif/else when a list is empty

2010-09-13 Thread aeneas24
Hi, I'm parsing IMDB movie reviews (each movie is in its own text file). In my script, I'm trying to extract genre information. Movies have up to three categories of genres--but not all have a "genre" tag and that fact is making my script abort whenever it encounters a movie text file that doe

Re: [Tutor] If/elif/else when a list is empty

2010-09-13 Thread Vince Spicer
On Mon, Sep 13, 2010 at 9:58 PM, wrote: > Hi, > > I'm parsing IMDB movie reviews (each movie is in its own text file). In my > script, I'm trying to extract genre information. Movies have up to three > categories of genres--but not all have a "genre" tag and that fact is making > my script abort

Re: [Tutor] If/elif/else when a list is empty

2010-09-13 Thread James Mills
On Tue, Sep 14, 2010 at 1:58 PM, wrote: > rgenre = re.split(r';', rf.info["genre"]) # When movies have genre First question. Why are you not using an XML parser (it looks like your IMDB data files _are_ XML). e.g: elementree (in the standard library). >    else len(rgenre)<1: # I was hoping thi

Re: [Tutor] If/elif/else when a list is empty

2010-09-13 Thread aeneas24
Hi Vince, Thanks very much for the one-line version--unfortunately, I still get errors. The overall script runs over every text file in a directory, but as soon as it hits a text file without a tag, it gives this error: Traceback (most recent call last): File "C:\Users\tylersc\Desktop\Tyle

Re: [Tutor] If/elif/else when a list is empty

2010-09-13 Thread Vince Spicer
Tyler, This is a simple error the KeyError is caused because the key isn't in the dictionary http://docs.python.org/library/exceptions.html#exceptions.KeyError and easy fix you can either check for the key prior to using or use the get method 1) rgenre = re.split(r';', rf.info["genre"]) if "genre

Re: [Tutor] If/elif/else when a list is empty

2010-09-13 Thread James Mills
On Tue, Sep 14, 2010 at 2:46 PM, wrote: >    rgenre = re.split(r';', rf.info["genre"]) > KeyError: 'genre' Use something like this: if "genre" in rf.info: rgenre = re.split(..., ...) else: # ... no genre cheers James -- -- James Mills -- -- "Problems are solved by method"