Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-09 Thread Lie Ryan
On 1/10/2010 11:23 AM, Eric Pavey wrote: I should add (that as I understand it), when you do a 'from foo import blah', or 'from foo import *', this is doing a /copy/ (effectively) of that module's attributes into the current namespace. Doing "import foo" or "import foo as goo" is keeping a /refe

Re: [Tutor] samples on sort method of sequence object.

2010-01-13 Thread Lie Ryan
On 01/14/10 06:56, Hugo Arts wrote: > On Wed, Jan 13, 2010 at 8:21 PM, Stefan Behnel wrote: >> Hugo Arts, 13.01.2010 15:25: >>> >>> Here is my solution for the general case: >>> >>> from itertools import groupby >>> def alphanum_key(string): >>>t = [] >>>for isdigit, group in groupby(strin

Re: [Tutor] Searching in a file

2010-01-14 Thread Lie Ryan
On 01/14/10 10:29, Hugo Arts wrote: > On Thu, Jan 14, 2010 at 12:05 AM, Alan Gauld > wrote: >> > >> > I prefer the next() approach. > Rightfully so. IMO, The while loop with readline is basically the C > version of that, for the poor people who don't have iterators. I would often prefer while lo

Re: [Tutor] Confirmation about __init__()

2010-01-17 Thread Lie Ryan
On 01/17/10 16:42, Robert wrote: > I have read quite a bit in the past 2 months, ( I have also looked at codes) > At this point, I think I understand well what __init__() is and does - > But, I have yet to see this *specifically* spelled out about the the > __init__ method for a Class; > > It is O

Re: [Tutor] The magic parentheses

2010-01-23 Thread Lie Ryan
On 01/24/10 17:14, David Hutto wrote: > Hi, > > This is my first post to the list, so tell me if I'm posting incorrectly. > > I'm creating a script, http://python.codepad.org/mHyqbJ2z that gives the area > of two circles, based on their radius, and displays the difference between > the two resu

Re: [Tutor] The magic parentheses

2010-01-24 Thread Lie Ryan
On 01/24/10 19:17, David Hutto wrote: > Thanks > for the solutions and the quick responses. I just removed the variable > and used print, I thought they would be considered the same whether as > a variable, or as a direct line, guess not. > what is equivalent: print (a, b, c) and x = a, b, c pr

Re: [Tutor] The magic parentheses

2010-01-25 Thread Lie Ryan
Do you know python's object model? A lot of these things will make much more sense once you do: http://effbot.org/zone/python-objects.htm ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailma

Re: [Tutor] multiply and sum two lists with list comprehension?

2010-01-28 Thread Lie Ryan
On 01/28/10 17:22, Muhammad Ali wrote: > Hi, > > I am multipliying two lists so that each of list As elements get multiplied > to the corresponding list Bs. Then I am summing the product. > > For example, A= [1, 2, 3] and B=[2, 2, 2] so that I get [2, 4, 6] after > multiplication and then sum it

Re: [Tutor] Reading large bz2 Files

2010-02-19 Thread Lie Ryan
On 02/19/10 23:42, Norman Rieß wrote: > Hello, > > i am trying to read a large bz2 file with this code: > > source_file = bz2.BZ2File(file, "r") > for line in source_file: > print line.strip() > > But after 4311 lines, it stoppes without a errormessage. The bz2 file is > much bigger though.

Re: [Tutor] Reading large bz2 Files

2010-02-19 Thread Lie Ryan
On 02/20/10 07:42, Lie Ryan wrote: > On 02/19/10 23:42, Norman Rieß wrote: >> Hello, >> >> i am trying to read a large bz2 file with this code: >> >> source_file = bz2.BZ2File(file, "r") >> for line in source_file: >> print line.s

Re: [Tutor] Reading large bz2 Files

2010-02-19 Thread Lie Ryan
On 02/20/10 07:49, Norman Rieß wrote: > Am 19.02.2010 21:42, schrieb Lie Ryan: >> On 02/19/10 23:42, Norman Rieß wrote: >> >>> Hello, >>> >>> i am trying to read a large bz2 file with this code: >>> >>> source_file = bz2.BZ2File(file

Re: [Tutor] webmail client for pop3 in python

2010-02-23 Thread Lie Ryan
On 02/24/10 13:53, Kirk Bailey wrote: > Anyone knoow of a good python Webmail client in python for my windows > notebook? what do you mean by "python webmail client"? Could you elaborate? If you want to send email programmatically, use the smtplib module if the server supports SMTP.

Re: [Tutor] Strange list behaviour in classes

2010-02-23 Thread Lie Ryan
On 02/24/10 10:27, C M Caine wrote: > Thanks all (again). I've read the classes tutorial in its entirety > now, the problem I had didn't seem to have been mentioned at any point > explicitly. I'm still a fairly inexperienced programmer, however, so > maybe I missed something in there or maybe this

Re: [Tutor] wHY

2010-02-27 Thread Lie Ryan
Why? That's a good philosophical question... hmm... why? Hmm ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to use pydoc

2010-02-27 Thread Lie Ryan
On 02/27/10 00:31, Ricardo Aráoz wrote: > Checked the manuals on pydoc and wanted to try it. Must certainly be > doing something wrong but I can't figure what. Here's my session : The pydoc command works from your system shell (e.g. bash), not python shell; if you want to get help inside python's

Re: [Tutor] Any Tutor there ? Removing redundant parameters in a models file having include files.

2010-02-28 Thread Lie Ryan
On 03/01/10 01:12, Alan Gauld wrote: > >> def getLines(file): >> """Get the content of a file in a lines list form.""" >> f = open(file, 'r') >> lines = f.readlines() >> f.close() >> return lines > > I'm not sure these functions add enough value to ghave them. I';d > probably just use >

Re: [Tutor] Any Tutor there ? Removing redundant parameters in a models file having include files.

2010-02-28 Thread Lie Ryan
On 03/01/10 02:49, Karim Liateni wrote: > Lie Ryan wrote: >> On 03/01/10 01:12, Alan Gauld wrote: >> >>>> def getLines(file): >>>> """Get the content of a file in a lines list form.""" >>>> f =

Re: [Tutor] Over-riding radians as default for trig calculations

2010-03-01 Thread Lie Ryan
On 03/01/10 06:39, AG wrote: > After importing the math module and running > > math.cos( x ) > > the result is in radians. > > Is there a way of setting this so that it results in degrees? I don't > want to over-ride this permanently for my Python settings, so am happy > to specifically do it p

Re: [Tutor] Why is the max size so low in this mail list?

2010-03-02 Thread Lie Ryan
On 03/02/2010 04:13 AM, Wayne Watson wrote: > See Subject. 40K here, but other Python lists allow for larger (total) > sizes. I don't know, I've never realized it; that's an indication that the 40K limit is reasonable, at least to me. What did you get for posting >40K mails? Is your mail bounced?

Re: [Tutor] object representation

2010-03-05 Thread Lie Ryan
On 03/05/2010 12:45 PM, Steven D'Aprano wrote: > E.g. a trie needs six pointers just to represent the single > key "python": > > '' -> 'p' -> 'y' -> 't' -> 'h' -> 'o' -> 'n' > > while a hash table uses just one: > > -> 'python' You can argue that had trie beed used as the datatype, there will

Re: [Tutor] Problems with iterations and breaking loops.

2010-03-17 Thread Lie Ryan
On 03/18/2010 02:02 AM, Karjer Jdfjdf wrote: > I'm having problems with iterations and loops.. So I'm curious about the > best Python-way to do iterations of lists (in if, while etc statements) > and breaking of loops. "Best" is a relative term to the current context of the problem. What is best f

Re: [Tutor] Tutorial executable from python script.

2010-03-21 Thread Lie Ryan
On 03/21/2010 06:00 AM, Karim Liateni wrote: > > Hello Alan, > > In fact, I want to be sure the users can run it on every machine in our > network. > Especially, I want to be able to run it on Solaris 5.8 with python 1.5 > (Unix machine). > I wanted to know if I could make some custom executable

Re: [Tutor] Tutorial executable from python script.

2010-03-21 Thread Lie Ryan
On 03/21/2010 08:51 PM, Karim Liateni wrote: > > Hello Lie, > > Thanks for your advices. > > To have correct updates from ITs is really a true pain. The network > is worldwide in our company. I found issues having decent version. > On my local workstation I have Python v1.5, on compute farm LSF

Re: [Tutor] Prime numbers

2010-03-28 Thread Lie Ryan
On 03/28/2010 09:57 PM, yd wrote: > It's not homework i just want to be able to convert my algorithm into > good code, and the only way to do that is by actually writing it. I'm > just writing it to learn how it's done. In most cases, when: 1) the code is effective (i.e. it always gives correct an

Re: [Tutor] Need some help on "How to Think Like a Computer Scientist: Learning with Python" exercise

2010-03-30 Thread Lie Ryan
On 03/31/2010 04:00 AM, Yahoo Mail wrote: > Hello All, > > I am competely new in Python programming. When i reading Chapter 4 in > "How to Think Like a Computer Scientist: Learning with Python" , > I am stuck in the exercise 4. > > Here is the question: > > Enter the following expressions int

Re: [Tutor] Remote access from Windows PC to a Linux box

2010-03-30 Thread Lie Ryan
On 03/31/2010 03:29 AM, Mike Baker wrote: > Hi, > > I'm trying to connect to a Linux box from my Windows machine and execute > a series of commands - (ls, pwd, cat 'somefile', etc...). I'm using > Putty to do the ssh and have set up with Putty's Pagent agent to allow > me to enter a passphrase

Re: [Tutor] Simple bank account oriented object

2010-03-30 Thread Lie Ryan
On 03/31/2010 01:26 PM, Marco Rompré wrote: > > Please help me i think im on the right track but i need some guidance in > the dark. lol And what's your question? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: ht

Re: [Tutor] simple search and replace...

2010-04-03 Thread Lie Ryan
On 04/01/10 06:51, ALAN GAULD wrote: > But if it's fixed patterns you can either do a replace() > in a loop over your patterns: > > for pat in ['PID','OBR',.] > h7string = h7string.replace('\n'+pat, h7string) > > Or even build a regex that does it all in one. > (But the regex could get co

Re: [Tutor] constructor

2010-04-04 Thread Lie Ryan
On 04/05/10 04:11, Shurui Liu (Aaron Liu) wrote: > But the result I got from computer is like this: > A new critter has been born! > A new critter has been born! > > Hi. I'm an instance of class Critter. > > Hi. I'm an instance of class Critter. Because you tell it to do it in that order: cr

Re: [Tutor] Menu data from file

2010-04-04 Thread Lie Ryan
On 04/05/10 08:54, Alan Gauld wrote: > Thats right you will need to parse the data to convert it into the > format you want. > This is one reason you might find it easier to use XML for storing the data > and use a tool like ElementCTree to parse it. s/ElementCTree/ElementTree/? _

Re: [Tutor] Menu data from file

2010-04-05 Thread Lie Ryan
On 04/05/10 17:39, Neven Goršić wrote: > Thank you for mentioning the possible options. > I already use option where I import .py module, > but I run into troubles when making executable with py2exe. Maybe you should elaborate what problems you're experiencing with py2exe? Probably we can solve th

Re: [Tutor] Menu data from file

2010-04-05 Thread Lie Ryan
On 04/06/10 08:05, Neven Goršić wrote: > OK, I will describe my "case". > > I use menu date stored in list "shape" in file CMFlowData.py in the same > directory as my main program x.py. In the beginning of the program I > have command: > > import CMFlowData > > and everything works fine till I m

Re: [Tutor] Re Problems with creating XML-documents

2010-04-15 Thread Lie Ryan
On 04/15/10 16:03, Karjer Jdfjdf wrote: > When I try to parse the outputfile it creates different errors such as: >* ExpatError: not well-formed (invalid token): That error message is telling you that you're not parsing an XML file, merely an XML-like file. > Basically it ususally has somethi

Re: [Tutor] Loop comparison

2010-04-16 Thread Lie Ryan
On 04/16/10 16:50, Ark wrote: > Hi everyone. > A friend of mine suggested me to do the next experiment in python and Java. > > It's a simple program to sum all the numbers from 0 to 10. > > result = i = 0 > while i < 10: > result += i > i += 1 > print result > Are you su

Re: [Tutor] the binary math "wall"

2010-04-20 Thread Lie Ryan
On 04/21/10 02:58, Lowell Tackett wrote: > I'm running headlong into the dilemma of binary math representation, with > game-ending consequences, e.g.: > Never use float for representing numbers, use float to represent a "magnitude", do not rely on the exact representation of the number itself.

Re: [Tutor] Binary search question

2010-04-24 Thread Lie Ryan
On 04/24/10 23:39, Robert Berman wrote: >> -Original Message- >> From: tutor-bounces+bermanrl=cfl.rr@python.org [mailto:tutor- >> bounces+bermanrl=cfl.rr@python.org] On Behalf Of Alan Gauld >> Sent: Friday, April 23, 2010 7:41 PM >> To: tutor@python.org >> Subject: Re: [Tutor] Binar

Re: [Tutor] For loop breaking string methods

2010-04-27 Thread Lie Ryan
On 04/27/10 12:19, Dave Angel wrote: > Note also that if you insert or delete from the list while you're > looping, you can get undefined results. That's one reason it's common > to build a new loop, and just assign it back when done. Example would > be the list comprehension you showed earlier.

Re: [Tutor] How can I display my float as a string???

2010-04-27 Thread Lie Ryan
On 04/28/10 12:35, Marco Rompré wrote: > Here is my code, I need to display my float value as a string. > > item.set_prix str(float(prix)) print prix ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.pyt

Re: [Tutor] Using Regex to produce text

2010-04-28 Thread Lie Ryan
On 04/29/10 01:32, m...@doctors.net.uk wrote: > While some patterns are infinite, other's aren't (e.g. The example I gave). How should the regex engine know about that? > Using a subset of Regex syntax to produce a set of strings has the > advantage of using a well understood and documented for

Re: [Tutor] blackjack game

2010-04-29 Thread Lie Ryan
On 04/30/10 06:23, Shurui Liu (Aaron Liu) wrote: > # Blackjack > # From 1 to 7 players compete against a dealer > > > Here is the code of this game. I want to change some part of them. > 1. Since I don't know what part of code is "responsible" for the > number of cards, so I don't know how to ad

Re: [Tutor] python list, right! but concretely?

2010-05-02 Thread Lie Ryan
On 05/02/10 15:49, spir ☣ wrote: > Hello, > > Is there anywhere some introduction material to the implementation of python > lists > (or to fully dynamic and flexible sequences, in general)? > More precisely, I'd like to know what kind of base data-structure is used > (linked list, dynamic arra

Re: [Tutor] Newbie & Unittest ...

2010-05-06 Thread Lie Ryan
On 05/06/10 10:37, Damon Timm wrote: > Hi - am trying to write some unit tests for my little python project - > I had been hard coding them when necessary here or there but I figured > it was time to try and learn how to do it properly. > > This test works, however, it only runs as *one* test (whi

Re: [Tutor] Question about Python being object oriented

2010-05-08 Thread Lie Ryan
On 05/09/10 02:19, Tino Dai wrote: > Hi Everybody, > > My friend and I were having a disagreement about Python. Has Python > always been an OO language or was it at one point a procedural language like > C? Thanks! AFAIK Python has always been a mixed paradigm language. You can write fully O

Re: [Tutor] Unable to run Programs on WINXP using Python3

2010-05-12 Thread Lie Ryan
On 05/12/10 13:31, Sivapathasuntha Aruliah wrote: > Hi > I thank you for your prompt response. I am using WINXP. Possibly programs > written for Python 3 may not work in Python2 as informed by you due to > syntax unmatch. Very unlikely. If python is told to execute a faulty script (or even arb

Re: [Tutor] Find Elements in List That Equal A Specific Value

2010-05-12 Thread Lie Ryan
On 05/13/10 03:58, Su Chu wrote: > Hi there, > > I am new to Python. I am attempting to either define a "which" statement or > to find a method that already exists to do this sort of operation. > > My problem is as follows: > I have three lists, one with unique values (list 1), one a sequence of

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Lie Ryan
On 05/21/10 20:17, Neven Goršić wrote: > Hi! > > I run into Python error in rounding and not know how to predict when it will > occur in order to prevent wrong result. That's because it's floating point number. > What can I do to assure accurate result? Use decimal module to do precise control

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Lie Ryan
On 05/22/10 01:30, Neven Goršić wrote: > Thanks! > It's pity that Python has such unreliable functions so you never know in > advanced when you will hit new one ... Well, it's not Python but the machine. Floating point number is not Real numbers; there are certain limitations imposed by physical l

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-23 Thread Lie Ryan
On 05/22/10 22:32, Steven D'Aprano wrote: > On Sat, 22 May 2010 07:16:20 am wesley chun wrote: >> correct, it is a floating point issue regardless of language.. it's >> not just Python. you cannot accurately represent repeating fractions >> with binary digits (bits). more info specific to Python he

Re: [Tutor] SENTINEL, & more

2010-05-29 Thread Lie Ryan
On 05/29/10 18:29, spir ☣ wrote: > Hello, > > > from the thread: "class methods: using class vars as args?" > > On Sat, 29 May 2010 11:01:10 +1000 Steven D'Aprano > wrote: > >> On Fri, 28 May 2010 07:42:30 am Alex Hall wrote: >>> Thanks for all the explanations, everyone. This does make sense,

Re: [Tutor] class methods as static methods?

2010-05-29 Thread Lie Ryan
On 05/30/10 05:49, Alex Hall wrote: > Hi all, > In Battleship, I have a weapons.py file, currently with just one > missile type (a Harpoon anti-ship missile). This Harpoon class defines > a getImpactCoords method, which returns all coordinates on the map > that it will hit. I would like to not inst

Re: [Tutor] OOP clarification needed

2010-06-03 Thread Lie Ryan
On 06/03/10 01:37, Jim Byrnes wrote: > >>> some older procedural languages I always end up becoming confused by >>> the large number of built in methods. >> >> C is one of the simplest procedural languages around >> and yet it comes with a huge library of functions (several >> hundred in some case

Re: [Tutor] backreferences - \0

2010-06-06 Thread Lie Ryan
On 06/06/10 19:36, Payal wrote: > On Sun, Jun 06, 2010 at 06:26:18PM +1000, Steven D'Aprano wrote: >> Two things. Firstly, the Python regex engine numbers backreferences from >> 1, not 0, so you need \1 and not \0. > > Thank for the mail, but i am still not getting it. e.g. > > In first sub I e

Re: [Tutor] while loops causing python.exe to crash on windows

2010-06-06 Thread Lie Ryan
On 06/07/10 11:08, Alex Hall wrote: > On 6/6/10, bob gailer wrote: >> On 6/6/2010 8:44 PM, Alex Hall wrote: >>> -- >>> Have a great day, >>> Alex (msg sent from GMail website) >>> mehg...@gmail.com;http://www.facebook.com/mehgcap >>> >>> >> What is your question? >> >> >> -- >> Bob Gailer >> 919-6

Re: [Tutor] Doubts galore.

2010-06-10 Thread Lie Ryan
On 06/11/10 01:14, prasad rao wrote: > Hi > > def cript(doc=None,data =None): >if doc==None and data==None:doc=sys.agv1 >elif doc: > data=open(doc,'r').read() > data_c= binascii.hexlify(data) >else:data_c= binascii.hexlify(data) >if doc: > q=tempfile.Tempor

Re: [Tutor] Linux webcam libraries?

2010-06-13 Thread Lie Ryan
On 06/13/10 04:22, Wayne Werner wrote: > Hi, > > I want to do something like this: > http://www.kulturblog.com/2007/11/marshie-attacks-halloween-interactive-driveway-activity/ > > I want to be able to grab a webcam image via python. So I'm curious if > anyone has had any experience/luck in this p

Re: [Tutor] string encoding

2010-06-17 Thread Lie Ryan
On 06/18/10 06:41, Rick Pasotto wrote: > I'm using BeautifulSoup to process a webpage. One of the fields has a > unicode character in it. (It's the 'registered trademark' symbol.) When > I try to write this string to another file I get this error: > > UnicodeEncodeError: 'ascii' codec can't encode

Re: [Tutor] string encoding

2010-06-18 Thread Lie Ryan
On 06/18/10 14:21, Rick Pasotto wrote: >> Remember, even if your terminal display is restricted to ASCII, you can >> still use Beautiful Soup to parse, process, and write documents in UTF-8 >> and other encodings. You just can't print certain strings with print. > > I can print the string fine. It

Re: [Tutor] Confirm that Python 2.6 ftplib does not support Unicode file names? Alternatives?

2010-06-24 Thread Lie Ryan
On 06/24/10 02:10, pyt...@bdurham.com wrote: > Can someone confirm that Python 2.6 ftplib does *NOT* support > Unicode file names? Or must Unicode file names be specially > encoded in order to be used with the ftplib module? > I don't know the specifics about ftplib, however I believe in most fil

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-29 Thread Lie Ryan
On 06/29/10 19:48, Richard D. Moores wrote: > On Tue, Jun 29, 2010 at 01:06, Alan Gauld wrote: >> "Richard D. Moores" wrote >> You log into Gmail and your browser downloads the Gmail page; >>> >>> Yes, of course. But I'm always logged into Gmail. >> >> But it is still continually downloading

Re: [Tutor] (no subject)

2010-06-30 Thread Lie Ryan
On 07/01/10 02:20, Aaron Chambers wrote: > I'm new to Python, and wanted to start messing around with it, but the > computer I'm using is running Windows 7, so is there a version of Python > that's compatible with 7? Yes. ___ Tutor maillist - Tutor@py

Re: [Tutor] "x and y" means "if x is false, then x, else y"??

2010-07-22 Thread Lie Ryan
On 07/05/10 22:23, Adam Bark wrote: > > I should add that this is how something like: > > if x != y: > do_something() > > works, if expects a True or False (this isn't always true but works for > comparison operators expressions such as this). > "if" expects an expression that can be con

Re: [Tutor] Idea for a 'Weekly Python Tips' mailing list

2010-08-06 Thread Lie Ryan
On Fri, 6 Aug 2010 17:19:46 +0100, Ian Ozsvald wrote: Recently I've started to follow a couple of email lists that send me regular tip emails, I've found them to be rather nice - an easy to read tip that comes every week that I can digest when I'm ready and I can reference afterwards. In th

Re: [Tutor] Word to Sound

2010-08-08 Thread Lie Ryan
On Sat, 07 Aug 2010 11:43:25 -0400, Chris King wrote: How do you convert a string into a sound object. Do you mean as in text-to-speech or playing byte string that contain sound data in a certain encoding to the speaker? ___ Tutor maillist -

Re: [Tutor] Trouble with sys.path.append

2010-08-08 Thread Lie Ryan
aug dawg gmail.com> writes: > > Earlier today, I tried to add a folder to my PYTHONPATH. When > I tried sys.path.app('location/of/folder'), the command successfully > executed it, but then when I did sys.path to check to see if it was > now in my PYTHONPATH, it was not there. Does anyone know wha

Re: [Tutor] changing list index start

2010-09-10 Thread Lie Ryan
On 09/11/10 07:36, Rance Hall wrote: > I'm using the following function style I found on the net to create > menus for a command line python script: > > It works well, but the first item is the list is item 0. This is > normal in most computing situations, but because this index is part of > the

Re: [Tutor] changing list index start

2010-09-11 Thread Lie Ryan
On 09/11/10 23:25, Rance Hall wrote: > On Fri, Sep 10, 2010 at 6:14 PM, Lie Ryan wrote: >> On 09/11/10 07:36, Rance Hall wrote: > > > >> In most cases in Python, you would almost never need to reference the >> list's index directly since python makes it e

Re: [Tutor] recursive problem

2010-09-11 Thread Lie Ryan
On 09/12/10 04:01, Walter Prins wrote: > I guess the question to ask/consider is: How can be establish whether a > particular object supports a particular interface/set of behaviours that > we require? E.g. how do we most pythonically check whether some object > "walks like a list" and "quacks lik

Re: [Tutor] recursive problem

2010-09-11 Thread Lie Ryan
On 09/12/10 03:18, Steven D'Aprano wrote: > Or you could do this: > > if do_this_will_succeed() and do_that_will_succeed() \ > and do_something_else_will_succeed(): > do_this() > do_that() > do_something_else() > else: > do_error() > > But that hasn't done anything to prevent race

Re: [Tutor] tree problem

2010-09-12 Thread Lie Ryan
On 09/12/10 21:15, Roelof Wobben wrote: > > > Hello, > > I have this problem. > > Write a program named litter.py that creates an empty file named trash.txt in > each subdirectory of a directory tree given the root of the tree as an > argument (or the current directory as a default). By de

Re: [Tutor] "Overloading" methods

2010-09-17 Thread Lie Ryan
On 09/17/10 00:22, Vince Spicer wrote: > > > Well I can't comment on right or wrong I would think creating a simple > class with a __call__ method is a little more pythonic. I think even more pythonic is to use closure: def create_setpattern(type_): def f(self, pattern, parameter):

Re: [Tutor] plotting pixels

2010-09-18 Thread Lie Ryan
> It appears that the Tk canvas widget does not support simply > plotting a pixel. However, I can plot a line only one pixel long. > I wonder why they do not simply provide the pixel plot primitive? I > have seen very many graphics packages that do this and I have always >

Re: [Tutor] What are "singletons" good for?

2010-09-18 Thread Lie Ryan
On 09/19/10 02:50, Knacktus wrote: > Hey all, > > the usual explanation for the usage of a Singleton goes like this: > > "Use a singleton if you want to make sure, that only one instance of a > class exists." > > But now I ask myself: Why should I call the constructor of a class more > than once

Re: [Tutor] plotting pixels

2010-09-19 Thread Lie Ryan
On 09/19/10 09:39, ALAN GAULD wrote: >> It appears that the Tk canvas widget does not support simply plotting > a pixel. > > Correct, and I agree it seems odd, but in practice drawing either lines or > ovals of one-pixel do the equivalent job - albeit a little more slowly. More slowly and takes

Re: [Tutor] super.__init__() arguments

2010-09-27 Thread Lie Ryan
On 09/27/10 09:45, Jojo Mwebaze wrote: > Hey Tutor, > > Seems a small issue but this has been playing for a while now, what am i > doing wrong here? > super() without argument only works for Python 3. In Python 2.x, you have to pass to super your class name and your class instance, i.e.: Class

Re: [Tutor] list comprehension, efficiency?

2010-09-27 Thread Lie Ryan
On 09/28/10 13:57, Bill Allen wrote: > I can now see that quite a bit of the code I write dealing with lists > can be done with list > comprehensions. My question is this, is the list comprehension styled > code generally > more efficient at runtime? If so, why? Yes, because the looping in list

Re: [Tutor] Scripting-Puzzle Pirates

2010-10-24 Thread Lie Ryan
On 10/24/10 15:33, Nathan Finney wrote: > Hey, > > So I got bored of having to do a repeated task on this game, YPP Puzzle > Pirates and I was wondering if it was possible to script it. Even if you can (hint: no, you can't), most games consider writing scripts to do tasks as botting, i.e. cheat

Re: [Tutor] What's the best way to model an unfair coin?

2010-10-24 Thread Lie Ryan
On 10/25/10 02:46, Jose Amoreira wrote: > On Sunday, October 24, 2010 01:18:52 pm Alan Gauld wrote: > >> In pseudo code: >> >> def coinToss(prob = 0.5): >> rand = random() >> if rand >= prob: return True >> else: return False >> >> print "Heads" if coinToss(6/11) else "Tails" >> > > T

Re: [Tutor] What does "TypeError: 'int' object is not iterable" mean?

2010-10-24 Thread Lie Ryan
On 10/23/10 01:19, David Hutto wrote: > If I understand what i just said correctly, it just means it tells the > string what type to convert from when placing it into the final > result. basically, when doing this %-interpolation, python does this: ("NEW LOW: %%.%sf at %%s" % i) % (lowz, time

Re: [Tutor] decorators (the "at" sign)?

2010-10-26 Thread Lie Ryan
On 10/26/10 13:46, Alex Hall wrote: > Hi all, > Now that I am able to run the source code of an open source > application I hope to one day help develop, I am trying to understand > how it works. One thing I keep seeing is an at sign followed by a > word, usually (maybe always) immediately preceedi

Re: [Tutor] os.listdir for symbolic links?

2010-10-27 Thread Lie Ryan
On 10/28/10 06:57, Sean Carolan wrote: > Is there an easy way to find the target of a symbolic link on a Linux > system with python? I'm looking for something like the output of the > bash command: "ls -l" you're looking for >>> os.path.realpath('/bin/uncompress') '/bin/gunzip'

Re: [Tutor] Picking up citations

2009-02-10 Thread Lie Ryan
On Mon, 09 Feb 2009 14:42:47 -0800, Marc Tompkins wrote: > Aha! My list of "magic words"! > (Sorry for the top post - anybody know how to change quoting defaults in > Android Gmail?) > --- www.fsrtechnologies.com > > On Feb 9, 2009 2:16 PM, "Dinesh B Vadhia" > wrote: > > Kent /Emmanuel > > I

Re: [Tutor] Simple PassGen

2009-02-10 Thread Lie Ryan
On Tue, 10 Feb 2009 09:43:18 -0500, python wrote: > Kent, > >> Except they are not equivalent when you want to print more than one >> thing. ... >> Python 2.6: >> In [1]: print(3, 4) >> (3, 4) > > I'm running Python 2.6.1 (32-bit) on Windows XP. > > I don't get the tuple-like output that you ge

Re: [Tutor] Simple PassGen

2009-02-11 Thread Lie Ryan
On Wed, Feb 11, 2009 at 2:26 AM, wrote: > > > Are you sure it isn't python 3.x you're playing with? The reason why > simple print function "works" in python 2.x is because of a syntactical > coincidence, it is still a 100% statement. > > Yes, I'm sure :) I restarted IDLE and pasted my session out

Re: [Tutor] url parsing

2009-02-15 Thread Lie Ryan
On Sun, 15 Feb 2009 14:22:09 +0100, Andre Engels wrote: > What is 'new' in your solution? Apart from that, the following looks > simpler: > url = "http://this/is/my/url/to/parse"; parts = url.split('/') sol = '/'.join(parts[:-1]) sol > 'http://this/is/my/url/to' do you want somethi

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-16 Thread Lie Ryan
On Sun, 2009-02-15 at 21:29 +0100, tutor-requ...@python.org wrote: > Do you know about sequence unpacking? In an assignment statement, when > the right side is a sequence, the left side can be a list of variables > of the same length as the sequence. Then each sequence element is > assigned to one

Re: [Tutor] Reading a Text File with tkFileDialog, askopenfilename+enumerate

2009-02-16 Thread Lie Ryan
On Mon, 2009-02-16 at 09:38 -0500, bob gailer wrote: > Lie Ryan wrote: > > On Sun, 2009-02-15 at 21:29 +0100, tutor-requ...@python.org wrote: > > > > > >> Do you know about sequence unpacking? In an assignment statement, when > >> the right side is a s

Re: [Tutor] Add readline capabilities to a Python build 2.6 on Ubuntu

2009-02-17 Thread Lie Ryan
On Mon, 16 Feb 2009 22:34:23 -0700, Eric Dorsey wrote: > Greetings Tutor: > I've managed to install Python 2.6 on my Ubuntu VM from source, however, > it looks as though I missed something important along the way. My 2.6 > interpreter does not have readline support (example: I cant hit up arrow >

Re: [Tutor] Proxies/Interceptors for file-like objects

2009-02-19 Thread Lie Ryan
On Thu, 19 Feb 2009 20:12:57 +1100, Oxymoron wrote: > Thanks for the answers everyone. > > Denis, I wish to wrap an already open file handle basically, so simply > extending and overriding doesn't help - my proxy won't be instantiated > like a file, just used like one and if not intercepting I ne

Re: [Tutor] KeyError: 'DEFAULT'

2009-02-19 Thread Lie Ryan
On Thu, 19 Feb 2009 11:45:52 -0800, Marc Tompkins wrote: > Don't use reserved words as variable names! str, set is built-in function not reserved words. Reserved words are like if, for, from, as (see the whole list type keywords in help() ) Nevertheless, it is a bad idea to use built-in funct

Re: [Tutor] calling user defined function

2009-02-24 Thread Lie Ryan
On Sun, 22 Feb 2009 22:21:22 +0100, roberto wrote: > hello > i have a question which i didn't solved yet: i can define a function > using the text editor provided by IDLE 3.0; then i'd like to call this > function from the python prompt > > but when i try to do it, python warns me that function d

Re: [Tutor] Passing perimeters in dictionary values?

2009-02-24 Thread Lie Ryan
On Tue, 24 Feb 2009 18:26:29 -0500, Kent Johnson wrote: > On Tue, Feb 24, 2009 at 5:13 PM, nathan virgil > wrote: >> I'm not familiar with lambdas yet, and I don't think this book will >> introduce me to them; they aren't listed in the index, anyway. Nobody remembers partial? from functools imp

Re: [Tutor] String to list conversion

2009-02-24 Thread Lie Ryan
> name like "foo" to be changed Nitpick: "foo" is a string, not a name... ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Add readline capabilities to a Python build 2.6 on Ubuntu

2009-02-25 Thread Lie Ryan
On Thu, 19 Feb 2009 09:27:34 +0300, زياد بن عبدالعزيز الباتلي wrote: > On Wed, 18 Feb 2009 20:19:56 -0700 > Eric Dorsey wrote: >> I did an aptitute install of ibreadline5-dev and then did ./configure >> and make again, and still don't have any functionality to be able to >>

Re: [Tutor] Add readline capabilities to a Python build 2.6 on Ubuntu

2009-02-25 Thread Lie Ryan
On Wed, 2009-02-25 at 22:23 -0700, Eric Dorsey wrote: > Thanks for all your continued insights on this. I'm going to > investigate the .configure log, as well as look around at other > readline packages.. But, noob question, did you just go into something > like synaptic to find out what readline t

Re: [Tutor] how to instantiate a class

2009-02-25 Thread Lie Ryan
On Thu, 26 Feb 2009 12:38:27 +0530, Abhishek Kumar wrote: > hello list, > You need to read through the tutorial first: http://docs.python.org/ tutorial/ If there are still things you don't understand, please ask again. As for your question, here is a sample useless python code: class MyClass(

Re: [Tutor] how to instantiate a class

2009-02-25 Thread Lie Ryan
On Thu, 26 Feb 2009 12:38:27 +0530, Abhishek Kumar wrote: > hello list, > You need to read through the tutorial first: http://docs.python.org/ tutorial/ If there are still things you don't understand, please ask again. As for your question, here is a sample useless python code: class MyClass(

Re: [Tutor] format a file

2009-02-26 Thread Lie Ryan
Try thinking what happens when you do this: line = 'this is a rellly long line\n' first = line[:20] second = line[20:] print first print second . . . . . . . . . . Have you got it? The first would contain "this is a re" and the second "llly long linee

Re: [Tutor] re Format a file

2009-02-26 Thread Lie Ryan
On Fri, 27 Feb 2009 09:59:40 +0530, prasad rao wrote: > def myform(s): > import os > so=open(s) > d=os.path.dirname(s)+os.sep+'temp.txt' > de=open(d,'w') > for line in so: > while len(line)>60: > item=line[60:] > try: > a

Re: [Tutor] What does the L at the end of a number means?

2009-02-28 Thread Lie Ryan
Nuno Hespanhol wrote: > Hi. > I have started learning phyton today! > I was playing around with some large numbers (fibonacci series) > and noticed that in some large calculations results have an "L" at the > end of a number. > Does this L stands for Large? Is there any way to disable this feature,

Re: [Tutor] Tutor Digest, Vol 61, Issue 3

2009-03-02 Thread Lie Ryan
Daniele wrote: >> From: W W >> Subject: Re: [Tutor] modular program > >>> Where can I find some "best practices" for writing modular programs? >>> I thought about a txt file containing function calls that my program will >>> parse and execute in order, or is it better just to execute every .py fi

  1   2   3   4   >