Re: [Tutor] shlex.split if there is an apostrophe in the string?

2011-01-07 Thread Steven D'Aprano
Emile van Sebille wrote: On 1/7/2011 11:22 AM Sean Carolan said... I'm practicing manipulating data with a text file. I'm trying to use shlex.split to break up each line, Is there a reason not to use split directly? for line in fin: words = line.split() shlex.split was specifically writ

Re: [Tutor] shlex.split if there is an apostrophe in the string?

2011-01-07 Thread Steven D'Aprano
Sean Carolan wrote: [...] YOU don't know about me without you have read a book by the name of The How can I get shlex.split to ignore single apostrophes such as the one above? >>> shlex.split("The Doctor's bow ties are cool, and Amy's uniform is hot.") ['The', 'Doctors bow ties are cool, an

Re: [Tutor] range function and floats?

2011-01-07 Thread Steven D'Aprano
Wayne Werner wrote: On Wed, Jan 5, 2011 at 4:59 PM, Steven D'Aprano wrote: Wayne Werner wrote: I never said rounding errors - I said "pesky floating point errors". When Which ARE rounding errors. They're *all* rounding errors, caused by the same fundamental issue --

Re: [Tutor] Named-value formatting fails

2011-01-08 Thread Steven D'Aprano
There's a shorter answer and a longer answer to this question. The shorter answer is here. The longer answer will follow. Tim Johnson wrote: I'm using 2.6.5 on ubuntu 10.04. I'm evaluating a very large string using a named-value formatting scheme. The process fails with the following error mess

Re: [Tutor] Named-value formatting fails

2011-01-08 Thread Steven D'Aprano
A more detailed response. Tim Johnson wrote: I'm using 2.6.5 on ubuntu 10.04. I'm evaluating a very large string using a named-value formatting scheme. The process fails with the following error message: """not enough arguments for format string""" I'd take that as a fairly straightforward err

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-08 Thread Steven D'Aprano
tee chwee liong wrote: hi, i have a sampledata as below. Pls refer to output, if found -1, how to list out all the Lane number? And if there is no -1, print PASS. My code is as below section. thanks tcl76 sampledata Platform: PC Tempt : 25 TAP0 :0 TAP1 :1 ++

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-08 Thread Steven D'Aprano
Please excuse the double post, I had a problem with my email program. tee chwee liong wrote: hi, i have a sampledata as below. Pls refer to output, if found -1, how to list out all the Lane number? And if there is no -1, print PASS. My code is as below section. Code###

Re: [Tutor] Open a text file, read and print pattern matching

2011-01-09 Thread Steven D'Aprano
tee chwee liong wrote: hi, there is error when running the code: Traceback (most recent call last): File "C:/Python25/myscript/log/readfile9.py", line 5, in port, channel, lane, eyvt = line.split() ValueError: need more than 2 values to unpack the error is due to below line code: port, cha

Re: [Tutor] __init__() - is it required?

2011-01-09 Thread Steven D'Aprano
Corey Richardson wrote: Do all classes need an __init__() method? I have classes that look much like this one starts out: class GenerateXML(object): """Defines methods to be inherited for StaticXML and AnimationXML""" def __init__(self): pass I would rather not do that. Code wit

Re: [Tutor] Named-value formatting fails

2011-01-09 Thread Steven D'Aprano
Tim Johnson wrote: * Steven D'Aprano [110108 19:46]: A more detailed response. Dear me... messing with globals and locals. That's always a bad sign. But let's assume this is that one time in 100 that it is actually justified... if localvals is None:

Re: [Tutor] Try except really better than if?

2011-01-09 Thread Steven D'Aprano
Karim wrote: Hello all, I am using more and more try except statement. But I discussed with a very experienced C++ programmer. And he told me that at least in C++ using too many try -catch statements are making the code slower. And it should does the same for python (C implementation). He

Re: [Tutor] Try except really better than if?

2011-01-10 Thread Steven D'Aprano
Karim wrote: Thank you Steven, Modulok and Alan for your precious and detailed explanations! I understood that I must not overuse try-except statement and usually when the exception could happen exceptionally. By the way I have this piece of code using elementTree standard module and accord

Re: [Tutor] Try except really better than if?

2011-01-10 Thread Steven D'Aprano
Alan Gauld wrote: However, using exceptions like if/else blocks is bad practice. I'm afraid I disagree strongly with that! You need to use them like a commit in SQL - to protect a whole block of code. Putting try/except around every line of code defeats the purpose, wrap atomic blocks of cod

Re: [Tutor] question regarding regular expression compile

2011-01-13 Thread Steven D'Aprano
Luke Paireepinart wrote: No. Did you try that? It doesn't evn look like valid python code to me. You want a single string with the r before it, not 3 separate strings. The line of code in question is: test = re.compile('MAT file (billing|carrier|log|util)' r'\\' '\d{8} deleted') If

Re: [Tutor] (no subject)

2011-01-13 Thread Steven D'Aprano
lmho...@jacks.sdstate.edu wrote: Hello All, I am having an issue with lists and am not sure where to go from here any advice appreciated. I colored the areas of concern. blue my comments purple example of output red area area concerned You may have coloured the text before you sent it, but the

Re: [Tutor] Object/Class Beginner Questions

2011-01-14 Thread Steven D'Aprano
Ben Ganzfried wrote: Hey guys, I'm using a tutorial geared for a 2.x version of Python and I am currently using Python 3.1-- so it is possible that my confusion has to do with different notations between them. But in any case, here is what I have: My questions are the following: 1) Why is th

Re: [Tutor] how to print random number multiply

2011-01-14 Thread Steven D'Aprano
walter weston wrote: I have mostly studied python and now I'm ready to start writing code. I want to print random numbers a certain ammount of times I am using the code import random print (random.random()) I tried bind the print statement to a variable and when I call x for example I

Re: [Tutor] color of "print" function

2011-01-14 Thread Steven D'Aprano
Bill DeBroglie wrote: Hello all, I don't have a problem per se, but have noticed something that I'd like to figure out... Sometimes the "print" function appears orange for me, sometimes it appears purple. Why does this happen and what's the difference anyway? Can you explain the context?

Re: [Tutor] When I print random.random

2011-01-14 Thread Steven D'Aprano
walter weston wrote: when I print random.random() it always returns a float why is this? how do I change it to a whole number? Because random.random() is defined to always return a float between 0 and 1. That's what it does. If you want a random whole number, you can call random.randint or

Re: [Tutor] defining functions and classes

2011-01-15 Thread Steven D'Aprano
Brett Murch wrote: I keep getting a syntax error on calling it. any ideas on what I'm doing wrong? Should we *guess*, or would you like to share with us the actual error you are getting? My guess is that you're not getting a syntax error at all, you're getting a NameError that Skills is no

Re: [Tutor] Python on Ubuntu 10.10?

2011-01-15 Thread Steven D'Aprano
Sean Carolan wrote: Bite the bullet and learn how to use vim; you won't regret it. There's a steep learning curve at first but once you get the hang of it you'll be coding like a boss. Well, I don't know about you, but I've worked for a number of bosses over the years and only one of them cou

Re: [Tutor] Explain to me Initializing

2011-01-15 Thread Steven D'Aprano
walter weston wrote: Please explain to me what initializing is,like when you _init_ a function or class . what is _init_ and what does it really do ? do you need it? Do you know how it is when you get in a car, and turn the key in the ignition, and change into gear, and only then the car is

Re: [Tutor] What is __weakref__ ?

2011-01-17 Thread Steven D'Aprano
Karim wrote: Hello, I am wondering what is this special class attribut. I know __dict__, slots. I use slots = [] when I want to use a read only class. (1) slots = [] doesn't do anything special. You have misspelled __slots__. (2) Classes don't become read only just because you add __slots_

Re: [Tutor] Why super does not work !

2011-01-17 Thread Steven D'Aprano
Karim wrote: Hello, I implemented Observer DP on a listbox (Tkinter) as follows and I don't understand why super() is not working and Observable.__init__(self) is working, cf below: You seem to be confused about your class design. On the one hand, you inherit from Listbox, but then you *a

Re: [Tutor] Convert an IP address from binary to decimal

2011-01-18 Thread Steven D'Aprano
Tom Lin wrote: > Hi guys, > > Please help me with this: We don't do homework. We'll give you some hints but not do the work. > Convert an IP address from binary string to decimal format.There are > some preconditions: > 1.IP address is in the form of '10010001100'.32 bits with no dot. >

Re: [Tutor] Why super does not work !

2011-01-18 Thread Steven D'Aprano
Alan G wrote: Steven D'Aprano pearwood.info> writes: fact that multiple inheritance itself is often the wrong thing to use, and even when it is right, it is often tricky to get it right. To put it another way: don't use multiple inheritance unless you have to, there are better

Re: [Tutor] Convert an IP address from binary to decimal

2011-01-18 Thread Steven D'Aprano
Tom Lin wrote: > But one precondition is not to use int(string, base). How would you > implement the conversion? It's not hard. You have two choices: each character of the string represents a bit, and should be either a "0" or a "1" (anything else is an error). In which case its numeric value is

Re: [Tutor] OOP question

2011-01-18 Thread Steven D'Aprano
Ben Ganzfried wrote: Hey guys, I'm trying to get a version of Roulette working and I had a quick question. There's a quick answer and long answer. The quick answer is, you have to refer to self.odds, not just odds. The long answer is below: Here is my code: [...] Now whenever I try to ca

Re: [Tutor] Why super does not work !

2011-01-18 Thread Steven D'Aprano
Steven D'Aprano wrote: Alan G wrote: Or use a language where MI is the normal and idiomatic way to do things because the language assumes it and so it just works. There are very few such languages but Lisp is one :-) I'm sorry, but I don't believe you :/ That's a

Re: [Tutor] What is __weakref__ ?

2011-01-18 Thread Steven D'Aprano
Karim wrote: Same thing I don't know what to do with this object weakref :-[ as I don't know its meaning. That was my true question in fact; http://mindtrove.info/python-weak-references/ http://www.doughellmann.com/PyMOTW-ja/weakref/index.html -- Steven _

Re: [Tutor] Decoding from strange symbols

2011-01-19 Thread Steven D'Aprano
Oleg Oltar wrote: Hi, I am trying to decode a string I took from file: [...] How do I convert this to something human readable? In general, you can't unless you know the encoding. A file filled with arbitrary bytes could be anything. However, you can sometimes guess the encoding, either b

Re: [Tutor] How to plot graph?

2011-01-19 Thread Steven D'Aprano
tee chwee liong wrote: hi all, i installed matplotlib, numpy and scipy. i tried to run attached script to learn how it plot a grph but got error as below: If you're having problems with numpy and scipy, you will probably get more help from a specialist numpy mailing list. -- Steven __

Re: [Tutor] list of tutors for python

2011-01-21 Thread Steven D'Aprano
bruce wrote: Hi guys. Please don't slam me!! I'm working on a project, looking for a pretty good number of pythonistas. Trying to find resources that I should look to to find them, and thought I would try here for suggestions. I'm sorry, I don't understand what your question is. If you're loo

Re: [Tutor] Exercise suggestions

2011-01-22 Thread Steven D'Aprano
Elwin Estle wrote: I seem to remember that Python (is it supposed to be capitalized? Official logo is in lower case) The official logo of Apple doesn't even have an "A" in it, but we don't spell the company "pple" :) By long-standing convention and practice, the programming language is s

Re: [Tutor] Help on RE

2011-01-22 Thread Steven D'Aprano
tee chwee liong wrote: thanks for making me understand more on re. re is a confusing topic as i'm starting on python. I quote the great Jamie Zawinski, a world-class programmer and hacker: Some people, when confronted with a problem, think 'I know, I'll use regular expressions." Now th

Re: [Tutor] What is a semantic error?

2011-01-23 Thread Steven D'Aprano
Richard D. Moores wrote: But could someone give me a clearcut example of a semantic error? And a definition that delineates semantic errors from syntax errors. "Semantics" relates to the *meaning* of words, sentences or programs. In common English, we might say this sentence has a few grammati

Re: [Tutor] Telephone app

2011-01-23 Thread Steven D'Aprano
bob gailer wrote: On 1/23/2011 4:04 PM, David Hutto wrote: [...] I guess you want to take the line that comes to you from your local telco, stick something computer-wise between it and an ordinary analog phone, so the computer can receive and process the caller id from an incoming call, and a

Re: [Tutor] Not understanding a bit of code behavior

2011-01-25 Thread Steven D'Aprano
Bill Allen wrote: Ok, I have definately verified this to myself. The following works perfectly and is a little easier to understand. In this version, I am plainly modifying my parts_list iterator thus producing the effect of an iterator that is growing over the course of the operation of the c

Re: [Tutor] The trap of the year

2011-01-25 Thread Steven D'Aprano
Karim wrote: Hello All, Just to share on rageous bug I encounter where 2 lists which "should" to be different (same id) because hold by different instances of the same class are not in fact DIFFERENT, see below: I think you are confused. If the two lists have the same ID, they should be th

Re: [Tutor] The trap of the year

2011-01-25 Thread Steven D'Aprano
Karim wrote: Hello Bob, I know this fact for function but in this case this is not a function but a constructor method of a class. Methods *are* functions. (Technically, they are lightweight wrappers around functions.) They are treated exactly the same by Python. The "constructor method" _

Re: [Tutor] The trap of the year

2011-01-25 Thread Steven D'Aprano
Corey Richardson wrote: To be pedantic, a method _is_ a function, just under the umbrella of a class, with it's parent object being passed to it. To be even more pedantic, a method object is a wrapper (technically, a descriptor) around a function object. It's also slightly different between

Re: [Tutor] ideas for a simple program

2011-01-25 Thread Steven D'Aprano
ian douglas wrote: With an Email address like "hacker0100", your best bet might be to do what we told another user just a few days ago: Ha ha, it's funny how different people interpret email addresses differently. *I* look at an email address "hacker0100" and think "wannabe". No offense Walte

Re: [Tutor] class question

2011-01-25 Thread Steven D'Aprano
Elwin Estle wrote: Is it better to have one large sort of "do it all" class, or break the larger class up into smaller classes? Yes. Or no. It's impossible to answer that question definitively without knowing more about what "it all" is. But I can give some general advice: * Python isn't

Re: [Tutor] class question

2011-01-25 Thread Steven D'Aprano
Corey Richardson wrote: On 01/25/2011 06:26 PM, Elwin Estle wrote: Is it better to have one large sort of "do it all" class, or break the larger class up into smaller classes? If you're just learning, go ahead and make a 'do it all' class. Don't do it later in your growth as a programmer tho

Re: [Tutor] ideas for a simple program

2011-01-25 Thread Steven D'Aprano
walter weston wrote: can I have some good ideas for simple programs, What are you interested in? Find something you like to do, and write a program to help you do it. Interested in maths? Write a program to generate prime numbers, or to search for amicable numbers. Look at Project Euler, a

Re: [Tutor] ideas for a simple program

2011-01-25 Thread Steven D'Aprano
walter weston wrote: can I have some good ideas for simple programs Some more ideas... Take a built-in Python command, and try to duplicate it in pure Python. E.g.: # Untested. def my_len(obj): # Like Python's len() function, only slower. try: return obj.__len__() excep

Re: [Tutor] sorted question

2011-01-25 Thread Steven D'Aprano
It't me wrote: Hi all, I'm learning Python with Google's Python class Ik have a question about the following code: = def sort(var): return var[-1] #returns the last character of var Why is the function called "sort" when it doesn't sort? Why not call it "run

Re: [Tutor] class question

2011-01-26 Thread Steven D'Aprano
Elwin Estle wrote: --- On Wed, 1/26/11, Alan Gauld wrote: From: Alan Gauld Subject: Re: [Tutor] class question To: tutor@python.org Date: Wednesday, January 26, 2011, 1:10 PM Is this really a series of different types of casting or a single Workpiece going through a sequence of Actions each

Re: [Tutor] Facebook

2011-01-27 Thread Steven D'Aprano
Luke Paireepinart wrote: And what have you tried? What libs are you using? Which part is confusing you? Surely it is the part Christopher says... getting an access token? I wonder whether he has read this? http://developers.facebook.com/docs/authentication/?_fb_noscript=1 (which is the first

Re: [Tutor] ascii codec cannot encode character

2011-01-27 Thread Steven D'Aprano
Alex Hall wrote: Hello again: I have never seen this message before. I am pulling xml from a site's api and printing it, testing the wrapper I am writing for the api. I have never seen this error until just now, in the twelfth result of my search: UnicodeEncodeError: 'ASCII' codec can't encode ch

Re: [Tutor] getting binary file from website with custom header

2011-01-28 Thread Steven D'Aprano
Alex Hall wrote: I keep getting an error 403, which the api defines as a bad login attempt. This could mean anything. Perhaps your password is wrong. Perhaps your username is wrong. Perhaps the website is sniffing the user-agent and refusing to allow Python to connect. Try setting the user-

Re: [Tutor] Accessing a secured webpage

2011-01-28 Thread Steven D'Aprano
Karim wrote: Hello, I want to create a client to access a webpage. But when I access it interactively there is a dialog box which ask for login and password. You should read this: http://www.voidspace.org.uk/python/articles/authentication.shtml or this French translation: http://www.void

Re: [Tutor] getting binary file from website with custom header

2011-01-28 Thread Steven D'Aprano
A few more comments... Alex Hall wrote: Hello, I am continuing to work on that api wrapper... I never realized how little I know about urllib/urllib2! The idea of downloading from the api is pretty easy: give it a url and a password and it gives you the book. Here is a quote from the api documen

Re: [Tutor] Accessing a secured webpage

2011-01-28 Thread Steven D'Aprano
David Hutto wrote: You should read this: http://www.voidspace.org.uk/python/articles/authentication.shtml Void Space...You mean like the one between your ears...badumpchee. Apologies I couldn't resist. I'm sure you really could have, if you tried *wink* Michael Foord of Voidspace is a hig

Re: [Tutor] getting binary file from website with custom header

2011-01-28 Thread Steven D'Aprano
Alex Hall wrote: Sorry. http://api.bookshare.org. Hmmm, I get: 403 Developer Inactive so that's no help to me. However, I did find this: http://developer.bookshare.org/docs/Home/ [quote] For user authenticated services, the user's username will be passed in via the for parameter in the en

Re: [Tutor] getting binary file from website with custom header

2011-01-29 Thread Steven D'Aprano
Alex Hall wrote: What makes you think you should use the *hex* digest of the password, rather than some other format? Honestly, it seemed the logical choice, and the api docs to not say anything except to md5Sum() the password. I have tried it with and without the hexdigest() and nothing change

Re: [Tutor] Python and Tuples

2011-01-30 Thread Steven D'Aprano
Becky Mcquilling wrote: I'm fairly new to python and I am trying to do some math with tuples. If I have a tuple: t =( (1000, 2000), (2, 4), (25, 2)) I want to loop through and print out the results of the multiplying the two Start with a basic loop through the objects in the tuple: >>> t = (

Re: [Tutor] decimal module and precision

2011-01-31 Thread Steven D'Aprano
Richard D. Moores wrote: Python 3.1 The decimal module continues to puzzle me from time to time. Here's one of those. I want to use Alex Martelli's factory function as much as possible. Turns out it has a problem with precision in addition and multiplication.

Re: [Tutor] search list with regex

2011-01-31 Thread Steven D'Aprano
Alan Gauld wrote: "Elwin Estle" wrote parse various text files and my standard method is to slurp the whole thing up into a string variable, then break it up into a list that I can then work on If you read it with readlines() Python will do all of that for you... Very true, and it's a go

Re: [Tutor] search list with regex

2011-01-31 Thread Steven D'Aprano
Elwin Estle wrote: Tcl's list search command has the option to search for a list element that matches a given regex. Is there something similar in python? Not using regexes. If not, it seems like it should be fairly trivial for me to write my own (just wondering if I would be re-inventing t

Re: [Tutor] Help with range of months spanning across years

2011-02-02 Thread Steven D'Aprano
ian douglas wrote: It bugs me that so many people are quick to jump on the "we wont' do your homework" bandwagon -- I was accused of the same thing when I posted a question to the list myself. I've been programming professionally for many years but learning Python in my spare time... I sent th

Re: [Tutor] Help with range of months [was Tutor Digest, Vol 84, Issue 8]

2011-02-02 Thread Steven D'Aprano
Hi Nevins, I don't think I've seen you post here before. Welcome to the list! Before answering your comment (see below), I have to give you a gentle wrap on the knuckles. It's considered impolite to: (1) reply to a digest without changing the subject line from "Tutor Digest" to something mor

Re: [Tutor] RE module is working ?

2011-02-03 Thread Steven D'Aprano
Karim wrote: Hello, I am trying to subsitute a '""' pattern in '\"\"' namely escape 2 consecutives double quotes: You don't have to escape quotes. Just use the other sort of quote: >>> print '""' "" * *In Python interpreter:* $ python Python 2.7.1rc1 (r271rc1:86455, Nov 16 2010, 21:5

Re: [Tutor] byte array conversion question

2011-02-03 Thread Steven D'Aprano
Bill Allen wrote: I have found that there are a couple of ways to convert a byte array to a string in Python. Is there any advantage or disadvantage to either method? my_bytes = b'this is a test' str(my_bytes,'utf-8') yields 'this is a test' my_bytes.decode('utf-8';) yeilds 'this is a tes

Re: [Tutor] print "Hello, World!"

2011-02-03 Thread Steven D'Aprano
Doug Marvel wrote: [...] I am hoping for a link to a somewhat comprehensive online resource that explains from the beginning in English, plain English, as this is the only language I speak. Something to get my foot in the door would be awesome. Another very important resource to use is the Pyth

Re: [Tutor] RE module is working ?

2011-02-03 Thread Steven D'Aprano
Karim wrote: *Indeed what's the matter with RE module!?* You should really fix the problem with your email program first; Thunderbird issue with bold type (appears as stars) but I don't know how to fix it yet. A man when to a doctor and said, "Doctor, every time I do this, it hurts. What sh

Re: [Tutor] best practice: throw exception or set a flag?

2011-02-03 Thread Steven D'Aprano
Alex Hall wrote: Hi all, I am wondering what the best way to do the following would be: throw an exception, or always return an object but set an error flag if something goes wrong? Raise an exception. Error flags are an anti-pattern -- a software idiom that you should not follow. The probl

Re: [Tutor] 'Installing' Python at runtime? (Civilization)

2011-02-03 Thread Steven D'Aprano
Alan Gauld wrote: "C.Y. Ruhulessin" wrote When I load up Civilization IV, a Firaxis game, the loading screen tells me "Loading Python". However, I can't seem to find out where it installs python It probably doesn't actually install Python it is simply loading the interpreter into memory.

Re: [Tutor] Roulette Unit Test Questions

2011-02-05 Thread Steven D'Aprano
Ben Ganzfried wrote: Hey, I'm having a lot of confusion getting the unit test working for one of my classes for the Roulette bot I'm working on and would greatly appreciate any advice or help. [...] Here is my Bin class: from Outcome import * class Bin: def __init__(self, *outcomes):

Re: [Tutor] nested loops

2011-02-07 Thread Steven D'Aprano
Alan Gauld wrote: "Wayne Werner" wrote You probably want to add a sentinel to break out of the outer loops too: I don't think you want to break out of *any* of the loops. Otherwise you will skip testing combinations. In your example, the first time you set highscore and alignment, you break

Re: [Tutor] PyS60 request

2011-02-07 Thread Steven D'Aprano
Dipo Elegbede wrote: Hello Everybody, I am working on a little project centered on PyS60, developing applications for symbian phones. Before I start asking questions pertaining to that, I would like to first clarify if it is appropriate to post such questions here. This is a mailing list abou

Re: [Tutor] JES Jython

2011-02-07 Thread Steven D'Aprano
Eun Koo wrote: Hi I have a problem in JES getting a solution to a function. Is there a way you guys can help? Probably not. This is a mailing list about learning the language Python, not specific to JES (whatever that is!) under Jython. If JES has a support forum dedicated to it, you should

Re: [Tutor] function help

2011-02-07 Thread Steven D'Aprano
Ashley F wrote: ok...here's the function I've written so far. def padWithGaps(seq): for letter in seq: letter="-" line=len(seq) dashline=line*letter return dashline I don't think that's a useful function. It seems to do a HUGE amount of work that just keeps get

Re: [Tutor] zipfile error message

2011-02-08 Thread Steven D'Aprano
Eric Stevens wrote: Hi: I am relatively new to Python and have been recently trying to experiment with its zipfile capabilities. However, everytime I try to open a zip ( using method zipfile.ZipFile(open('zipfile.zip','r')) ) I continue to get an error message that states:error: unpack requires

Re: [Tutor] Splitting a string

2011-02-08 Thread Steven D'Aprano
tee chwee liong wrote: hi all, i have a function which returns a string. for eg: X='101110'. i want to search for 0 and highlight the location. i am thinking of defining X as a list. but how can i split 101110 as there are no spaces in between? i'm thinking if i can put it into a list: X=['1','0

Re: [Tutor] Converting From Unicode to ASCII!!

2011-02-08 Thread Steven D'Aprano
Nevins Duret wrote: A good friend of mine locked herself out of her computer and forgot her password. I pretty much scoured the internet as a resource only to hit a brick wall. I tried using ophcrack version 2.3.1 in order to obtain the password and felt completely at home being that it was

Re: [Tutor] Splitting a string

2011-02-09 Thread Steven D'Aprano
tee chwee liong wrote: hi all, the code works: s='00101' found = False for i,c in enumerate(s): if c == '0': print 'Lane fail',i found = True if not found: print 'All lanes PASS No, it doesn't work. You haven't sufficiently tested it. It tells lies: >>> s='111

Re: [Tutor] System Monitoring

2011-02-09 Thread Steven D'Aprano
de Haan wrote: Hi, Im fairly new to programming in python, and have a question. Im looking to build a program that monitor's certain things on my Linux system. for instance disk space. What is the best way to monitor a Linux server without using to much resources? Why reinvent the wheel? What

Re: [Tutor] System Monitoring

2011-02-09 Thread Steven D'Aprano
de Haan wrote: On Wed, Feb 9, 2011 at 12:18 PM, Steven D'Aprano wrote: de Haan wrote: Hi, Im fairly new to programming in python, and have a question. Im looking to build a program that monitor's certain things on my Linux system. for instance disk space. What is the best way to

Re: [Tutor] System Monitoring

2011-02-09 Thread Steven D'Aprano
Sean Carolan wrote: Hi, Im fairly new to programming in python, and have a question. Im looking to build a program that monitor's certain things on my Linux system. for instance disk space. What is the best way to monitor a Linux server without using to much resources? Should I execute shell comm

Re: [Tutor] process and modify a list of strings, in place

2011-02-10 Thread Steven D'Aprano
John Martinetti wrote: Hello - I'm a novice programmer, not even amateur level and I need some help with developing an algorithm to process a list of strings. I hope this list is tolerant of n00bs, if not, please let me know and I'll take this elsewhere. Hi John! This list is specifically for

Re: [Tutor] Python + Sound

2011-02-11 Thread Steven D'Aprano
Corey Richardson wrote: Hello Tutors, I'm working on a small script that compresses a file, sends it through the telephone, and then receives and decompresses the file on the other end. The compression is the easy part. The transmission is the hard part. If anyone has worked with sound before, w

Re: [Tutor] How to group data?

2011-02-13 Thread Steven D'Aprano
tee chwee liong wrote: hi, i'm using Python 2.5 and Win XP. i want to extract the last column of the attached text file and group 128 characters to each row. want the result to look like: Did you have to flood us with the ENTIRE text file? Please show some respect! Next time, just show us

Re: [Tutor] How to group data?

2011-02-14 Thread Steven D'Aprano
tee chwee liong wrote: modified the code to be but it didnt print out anything: That is because your list of values is empty. You have to collect the values, like your previous code did. *Then* process them. In the code below, you try to process values before you have any. from __future_

Re: [Tutor] Higher-Order Function Examples

2011-02-14 Thread Steven D'Aprano
Carla Jenkins wrote: Hello everyone: I am new to Python and am looking for higher-order function programming examples. The programming codes do not feature the corresponding equation so I am lost. Please help me. The first thing you need to understand is the difference between *code* and *da

Re: [Tutor] Higher-Order Function Examples

2011-02-14 Thread Steven D'Aprano
Steven D'Aprano wrote: An example might help. Back in the old days, before Python had a sum() function, the easiest way to add up a list of numbers was to use reduce and a small function to add two numbers: def add(x, y): return x+y total = filter(add, [2, 4, 5, 9, 1]) Ar

Re: [Tutor] Higher-Order Function Examples

2011-02-14 Thread Steven D'Aprano
Walter Prins wrote: 2011/2/14 Rafael Durán Castañeda Could we consider sorted as an high order function? sorted_list = sorted(list_strings, key = str.lower) No because sorted() returns a list as a result. A higher order function produces another function as a result, or takes one or more

Re: [Tutor] regex questions

2011-02-17 Thread Steven D'Aprano
Albert-Jan Roskam wrote: Hello, I have a couple of regex questions: 1 -- In the code below, how can I match the connecting words 'van de' , 'van der', etc. (all quite common in Dutch family names)? You need to step back a little bit and ask, what is this regex supposed to accomplish? What i

Re: [Tutor] urgent help required! invalid syntax

2011-02-18 Thread Steven D'Aprano
lim chee siong wrote: > > > Hi, > I was writing a module for the black-scholes pricing model in python, but I > keep getting this error message: > Traceback (most recent call last): File "", line 1, in File > "C:\Python26\lib\blackscholes.py", line 25d2=d1-v*sqrt(t) Please COPY A

Re: [Tutor] regex questions

2011-02-18 Thread Steven D'Aprano
Albert-Jan Roskam wrote: So the raw string \b means means "ASCII backspace". Is that another way of saying that it means 'Word boundary'? No. Python string literals use backslash escapes for special characters, similar to what many other computer languages, including C, do. So when you typ

Re: [Tutor] dict['_find']

2011-02-19 Thread Steven D'Aprano
Max Niederhofer wrote: Hello all, first post, please be gentle. I'm having serious trouble finding an alternative for the deprecated find module for dictionaries. What find module for dictionaries? The code (from Zed Shaw's Hard Way, exercise 40) goes something like this. Hope indentation

Re: [Tutor] creating classes while coding

2011-02-21 Thread Steven D'Aprano
Bill Allen wrote: I know that Python not only supports OOP, but is fundamentally OOP in its design. Just in using the language and standard library, that much becomes obvious. However, I do wonder a bit about the practice I have seen of some Python programmers to implement relatively short bi

Re: [Tutor] creating classes while coding

2011-02-21 Thread Steven D'Aprano
Bill Allen wrote: That raises my next question. Under what sort of programming circumstances does it make sense? "It" being object oriented programming. OO is good for encapsulation and code-reuse. One good sign you should consider a class is if you start building up many global variables.

Re: [Tutor] subprocessor startup error

2011-02-23 Thread Steven D'Aprano
anulavidyalaya wrote: I have a problem when openning python (GUI) , There is a message "IDLE's subprocessor didn't make connection." Google is your friend. http://www.google.co.uk/search?hl=en&q=IDLE%27s+subprocess+didn%27t+make+connection (By the way, don't re-type error messages, if you ca

Re: [Tutor] licensing python work?

2011-02-24 Thread Steven D'Aprano
Wayne Werner wrote: If you don't care how people use it at all, just release your code into the public domain, then it doesn't matter how they use it. That's actually not as easy as it sounds. It depends where you are. In some jurisdictions, such as the USA, it's hard to put work into the pub

Re: [Tutor] Convert string to long

2011-02-24 Thread Steven D'Aprano
tee chwee liong wrote: hi, is there a way to convert from string to long? my_string = "1234" my_long = long(my_string) We're happy to help you, but you should make some effort to help yourself. Have you worked through the Python tutorial? Don't just *read* it, actually follow the instruct

Re: [Tutor] having difficulty installing python

2011-02-24 Thread Steven D'Aprano
Neven Dragojlovic wrote: Please can someone help me? I am trying to install python 2.5.4 on MacBookPro running on OS10.6.6, This is a mailing list for beginners to programming Python, not a general Python mailing list. It's quite likely that nobody here knows enough about installing softwar

Re: [Tutor] Display all field of a listuples

2011-02-24 Thread Steven D'Aprano
Alex Hall wrote: On 2/24/11, Christopher Brookes wrote: Hi i would like to display all the field of my powerAll like this : Choose a power : Froid devorant : Embrase lenemi et le feu bruler Flammes infernales : 'Gele lenemi sur place - class Character(): def Ch

Re: [Tutor] Display all field of a listuples

2011-02-24 Thread Steven D'Aprano
Christopher Brookes wrote: class Power: def __init__(self, name, desc): self.name = name self.desc = desc powerAll = [ Power('Flammes infernales' , 'Embrase lenemi et le feu bruler'), Power('Froid devorant', 'Gele lenemi sur place')] im *WANT to display this* : Froid d

Re: [Tutor] accessing another system's environment

2011-02-25 Thread Steven D'Aprano
Alan Gauld wrote: Anything you can do locally you can do on the remote machine with a combination of ssh, rsh, rlogin, telnet etc. I'd like to remove a CD from the CD drive, and replace it with a different disk. Being difficult just for the sake of it-ly y'rs, -- Steven _

<    2   3   4   5   6   7   8   9   10   11   >