Re: [Tutor] Don't understand this class/constructor call syntax

2011-07-24 Thread Steven D'Aprano
dave wrote: Thank you for the two explanations. I think I have a good idea of what is going on now with the arguments and keyword arguments. My only remaining question is the pad_for_usrp argument. The default value is True so I thought it was a boolean and couldn't have anything to do with th

Re: [Tutor] Basic program question

2011-07-24 Thread Steven D'Aprano
Alexander Quest wrote: Hello- I am running Python v 3.1.1. As an exercise, I wrote a simple coin flipper program, where the computer flips a coin 100 times and then prints out the number of heads and tails. My program crashes immediately if I run it normally through the command line, but if I go

Re: [Tutor] Running Python in script vs. Idle

2011-07-24 Thread Steven D'Aprano
brandon w wrote: I wrote this in Idle and ran it in Idle and it worked fine. [...] Then I try to run it from a script in Gnome-terminal and it does not run. I do not get output. I have to add print. to get any output like this: [...] What is the difference? This is what was confusing me befo

Re: [Tutor] Running Python in script vs. Idle

2011-07-24 Thread Steven D'Aprano
brandon w wrote: Thank you. I understand that this ( x = 1+2 ) assigns a variable to "x" and will not print in Idle, but how would I get the 'class' that I created to run from the script like it does in Idle? Will I have to put print before everything I have to print? Yes. If you want someth

Re: [Tutor] Don't understand this class/constructor call syntax

2011-07-24 Thread Steven D'Aprano
dave wrote: I was dimly aware of the functioning of booleans, but I see now that it doesn't specify an actual boolean type. Still, the code confuses me. Is the usage of pad_for_usrp consistent with it being treated as a boolean? Why would the entire self reference be transmitted then? Parame

Re: [Tutor] Don't understand this class/constructor call syntax

2011-07-26 Thread Steven D'Aprano
dave wrote: Is it even possible to replace the implicit self argument of the initializer by passing something else? If so, what would be the syntax. Yes, by calling an "unbound method". Consider this class: class MyClass: def func(self, x): return x+1 When you run this code,

Re: [Tutor] Object Management

2011-07-27 Thread Steven D'Aprano
Alexander wrote: Hello everyone. I'm having trouble wrapping my mind around a project I'm working on. My goal is to create a program that manages (allows its users to manipulate, search by criteria and edit) objects. There is one type of object, for example I'll say it's a car. This is called

Re: [Tutor] shlex parsing

2011-07-27 Thread Steven D'Aprano
Karim wrote: Hello All, I would like to parse this TCL command line with shlex: '-option1 [get_rule A1 B2] -option2 $VAR -option3 TAG' And I want to get the splitted list: ['-option1', '[get_rule A1 B2]', '-option2', '$VAR', '-option3', 'TAG'] Then I will gather in tuple 2 by 2 the argume

Re: [Tutor] Assigning range

2011-07-27 Thread Steven D'Aprano
Alexander Quest wrote: Does anyone know how to assign a certain numerical range to a variable, and then choose the number that is the middle of that range? For example, I want to assign the variable "X" a range between 1 and 50, and then I want to have the middle of that range (25) return with so

Re: [Tutor] Is it bad practise to write __all__ like that

2011-07-28 Thread Steven D'Aprano
Karim wrote: Hello, __all__ = 'api db input output tcl'.split() Yes, it's lazy, no it is not bad practice. I wouldn't do it myself, but I wouldn't object if somebody else did it. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe

Re: [Tutor] Sum files' size

2011-07-28 Thread Steven D'Aprano
Susana Iraiis Delgado Rodriguez wrote: I want to get the size of 3 files. I already completed this step. Then I need to sum the 3 results I got. In order to do it I have the next code: [...] #Finally I want to sum the 3 terms: total = kb+kb2+kb3 But the output I got is : 15.5KB108.0bytes169.0b

Re: [Tutor] Running files from command prompt

2011-07-28 Thread Steven D'Aprano
Alexander Quest wrote: To clarify, the particular file that was giving me trouble was the basic "hello world" file. The original code on line 29 read as such: print 'Hello', name When I ran "C:\google-python-exercises> python hello.py, it gave me an error on that line (line 29), but when I change

Re: [Tutor] About the Mailing List

2011-07-28 Thread Steven D'Aprano
Jordan wrote: How do I see what in the mailing list has already been responded too, before it sends me the digest? For instance I wanted to respond to one of the questions, but seeing that the time was almost two hours ago. I am sure someone has already responded. Where could I check to see if th

Re: [Tutor] Urllib Problem

2011-07-29 Thread Steven D'Aprano
George Anonymous wrote: I am trying to make a simple programm with Python 3,that tries to open differnet pages from a wordlist and prints which are alive.Here is the code: from urllib import request fob=open('c:/passwords/pass.txt','r') x = fob.readlines() for i in x: urllib.request.openurl('

Re: [Tutor] Reading .gz files

2011-07-29 Thread Steven D'Aprano
Hanlie Pretorius wrote: [code] import gzip f1 = 'GSMaP_MVK+.20050101.00.0.1deg.hourly.v484.gz' f2 = ''text.txt.gz' if1 = gzip.open(f1, 'rb') if2 = gzip.open(f2,'rb') try: print if1.read() print 'done with f1' print if2.read() print 'done with f2' finally: if1.close() if2.close

Re: [Tutor] Reading .gz files

2011-07-29 Thread Steven D'Aprano
Oh, I forgot to say something else... Hanlie Pretorius wrote: f1 = 'GSMaP_MVK+.20050101.00.0.1deg.hourly.v484.gz' f2 = ''text.txt.gz' if1 = gzip.open(f1, 'rb') if2 = gzip.open(f2,'rb') try: print if1.read() print 'done with f1' Once you've read the file once, the file pointer is at the

Re: [Tutor] How to make tkMessage function to have duration

2011-07-30 Thread Steven D'Aprano
Emeka wrote: Hello All, Say I have the below(code), I would want the message to last say 30 seconds and afterwards disappear. I won't want the user to be the one to enable it to disappear. Basically, what I want is to be able to show the user some message , and after some seconds, the mess

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Steven D'Aprano
Sandip Bhattacharya wrote: Generally, converting slashes manually should be kept at a minimum. You should be using library functions as much as possible. The experts here can correct me here, but this is a roundabout way I would be doing this: str.replace('\\', '/') is a perfectly fine library

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Steven D'Aprano
Richard D. Moores wrote: File "c:\P32Working\untitled-5.py", line 2 return path.replace('\', '/') ^ SyntaxError: EOL while scanning string literal Others have already told you how to solve the immediate problem (namely, escape the backslash), but I'd like to

Re: [Tutor] How to replace the '\'s in a path with '/'s?

2011-07-31 Thread Steven D'Aprano
Sergey wrote: Gotcha! http://pymon.googlecode.com/svn/tags/pymon-0.2/Internet/rsync.py 231-239 strings ## code ## def convertPath(path): # Convert windows, mac path to unix version. separator = os.path.normpath("/") if separator != "/": path = re.sub(re.e

Re: [Tutor] Accessing Specific Dictionary items

2011-08-01 Thread Steven D'Aprano
Mike Nickey wrote: The input being used is through pygeoip. Using this I am pulling the data by IP and from what I am reading this populates as a dictionary. Here is some of the output that I can show currently [{'city': 'Buena Park', 'region_name': 'CA', 'area_code': 714}, {'city': 'Wallingford

Re: [Tutor] When to use def __init__ when making a class?

2011-08-02 Thread Steven D'Aprano
brandon w wrote: I have two questions: 1) When should I use "def __init__(self):" when I create a class? Whenever you need something to happen when you create an instance. 2) Would these two classes have the same effect? Technically, no, but in practice, you would find it hard to see th

Re: [Tutor] Puzzled again

2011-08-03 Thread Steven D'Aprano
path with forward slashes. By Steven D'Aprano 07/31/2011 on Tutor list >>> path = r'C:\Users\Dick\Desktop\Documents\Notes\College Notes.rtf' Are you aware that this is not a raw string? It's wrapped inside another non-raw string, so it is merely a sub

Re: [Tutor] Puzzled again

2011-08-03 Thread Steven D'Aprano
Steven D'Aprano wrote: Richard D. Moores wrote: Puzzled again. Why the error. Line 36 is the line just above "import os.path". I have many other functions in mycalc.py with examples formatted exactly the same way. def convertPath(path): """ Given a path

Re: [Tutor] Puzzled again

2011-08-03 Thread Steven D'Aprano
Richard D. Moores wrote: But here's a try using the regular command line: C:\Windows\System32>python Python 3.2.1 (default, Jul 10 2011, 20:02:51) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. from mycalc import convertPath Traceba

Re: [Tutor] Using .po translation file

2011-08-03 Thread Steven D'Aprano
Григор Колев wrote: Hi. Some one help me. Haw can I use .po translation file for my program. This is not a standard part of Python. Is this a django thing? You should ask on a django forum. -- Steven ___ Tutor maillist - Tutor@python.org To

Re: [Tutor] Puzzled again

2011-08-03 Thread Steven D'Aprano
Richard D. Moores wrote: I wrote before that I had pasted the function (convertPath()) from my initial post into mycalc.py because I had accidentally deleted it from mycalc.py. And that there was no problem importing it from mycalc. Well, I was mistaken (for a reason too tedious to go into). Ther

Re: [Tutor] commandline unable to read numbers?

2011-08-06 Thread Steven D'Aprano
Robert Sjoblom wrote: I have a quite odd problem, and I've come across it before but probably ignored it at the time because I had other concerns. I've tried googling for the answer but haven't really come closer to solving it. This is what happens: C:\[path]\nester>C:\Python32\python.ex e setup.

Re: [Tutor] commandline unable to read numbers? (Steven D'Aprano)

2011-08-07 Thread Steven D'Aprano
Robert Sjoblom wrote: [...] > Have you tried just pressing enter without entering anything? Yes, and it goes back to "We need to know who you are, so please choose either:" The setup.py in question is the distutils.core one (from distutils.core import setup). It sounds like Peter Otten has t

Re: [Tutor] Missing in web.py and nosetests

2011-08-08 Thread Steven D'Aprano
李龑 wrote: Hi all, I'm new in python and is learning about testing my little web.py app with nosetests. When the app is running in the web browser, it's ok. And the terminal returns something like "127.0.0.1:51936 - - [08/Aug/2011 23:00:37] "HTTP/1.1 GET /hello" - 200 OK" But when I'm trying to

Re: [Tutor] Missing in web.py and nosetests

2011-08-08 Thread Steven D'Aprano
李龑 wrote: Thanks Steven. Sorry for trying to discuss nose or templates here :( No need to be sorry, it isn't forbidden, but you may have more success asking help elsewhere. Do you actually have a template called "hello_form"? If not, then my *guess* is that this is an *error* (even though

Re: [Tutor] Reprojection tool for vector datasets

2011-08-09 Thread Steven D'Aprano
Helen Brown wrote: I am such a novice at this but I have gotten to a place where I am stuck. The attachment is what I have done so far but it also has an error for indentation. I will be working on that to. I have place comment as to what I want the modules to do but that is as far as I can go. C

Re: [Tutor] precision?

2011-08-09 Thread Steven D'Aprano
Shwinn Ricci wrote: When comparing a given value with a database of values, but allowing for freedom due to variation at say, the thousandth digit, how does one generalize the precision to this degree? I don't want to truncate, so is there a round() function that takes into account what decimal p

Re: [Tutor] converting string to float

2011-08-10 Thread Steven D'Aprano
Shwinn Ricci wrote: however, I want to convert position to a floating point number, as the actual cell value is in the form of X.XXX (where X = digits). When I try float(position) I get a ValueError saying that the string could not be converted to a float. What am I doing wrong? Inspect the st

Re: [Tutor] visualizing a point on a 3-dimensional surface

2011-08-10 Thread Steven D'Aprano
Shwinn Ricci wrote: Say I have a point that I want to visualize by placing a small marker there on the surface of an object. However, what if it's a 3-dimensional object? Would you just use a 3-D coordinate system and then use a rotatable camera script to wheel around and get a better view of the

Re: [Tutor] Where to direct non-language questions?

2011-08-13 Thread Steven D'Aprano
Michael Scharf wrote: Sent: Friday, August 12, 2011 3:54 PM Hi List, I'm am not quite at the point of needing this, but where would I go to ask a question like "Why is the OpenCalais Python API not returning all fields when I do x or y" or "Has anyone built their own Python API for OpenCalais"

Re: [Tutor] Python

2011-08-13 Thread Steven D'Aprano
Jon wrote: Could you link me to some beginners tutorials/idle codes thank you. http://duckduckgo.com/?q=python+beginners+tutorial (Check out the very first link provided.) -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or cha

Re: [Tutor] Add lines to middle of text file

2011-08-13 Thread Steven D'Aprano
Wolf Halton wrote: Is there a way to add text to an arbitrary place in a text file? If you are using the OpenVMS operating system, or a VAX computer, then yes. The operating system natively supports inserting data into the middle of a file. If you are using Windows, Linux, Unix, Mac OS (cl

Re: [Tutor] (no subject)

2011-08-14 Thread Steven D'Aprano
je.rees e-mail wrote: I would like this script to only have a choice of one these. I'm not sure how to do it. My example would be when someone types Good next to print how I want it to reply Thats nice. Anyone know how and if I am making more mistakes point them out please. Consider this examp

Re: [Tutor] which version do i have and how do i change it

2011-08-16 Thread Steven D'Aprano
Connor Merritt wrote: So i installed python 2.7.1 on my linux and i bought a book that requires python 3 so installed python 3, and i used terminal and typed in python -V and it said 2.7.1 how do i get it to be 3 (i tried deleting it but i couldn't what should i do?) At the terminal, type pytho

Re: [Tutor] Standard way to create debian packages for python programs?

2011-08-18 Thread Steven D'Aprano
Mac Ryan wrote: Although it's years I program with python, I never distributed my software with packages (I never created *any* packages in my life, indeed). This is a mailing list for learning the programming Python, not on how to built Debian packages. You will probably get better answers

Re: [Tutor] Best way to store and access a fixed coordinate list

2011-08-18 Thread Steven D'Aprano
David Crisp wrote: Hello, I have a large grid of numbers 100 * 100 I then randomly select an X and Y to act as a "centre" point. I have a list of numbers which are coordinate offsets which are then applied to the centre point as per: X = (-2,2),(-4,2),(4,2),(2,2) (The list is about 200 coor

Re: [Tutor] file fetcher class object through http

2011-08-19 Thread Steven D'Aprano
Artie Ziff wrote: Hello.. I like reading different people's implementations of python as it helps me decide what is necessary vs what is not. Essentially, I want to write a class that finds, and downloads a file from a web server. Such tools already exist, although they may not be written

Re: [Tutor] file fetcher class object through http

2011-08-19 Thread Steven D'Aprano
Oh, I forgot to mention... Artie Ziff wrote: Essentially, I want to write a class that finds, and downloads a file from a web server. [...] mostly, I am looking for a smart class implementation that has well-considered API and method choices. Have you looked at the code in the Python stand

Re: [Tutor] Modules and Python tutorial by S. Thurlow - opinions please

2011-08-20 Thread Steven D'Aprano
Lisi wrote: I have got myself well and truly bogged down. I need to change the angle from which I am looking. I only have a short while left for now in which to make some sort of progress with Python. What do people think of: http://www.sthurlow.com/python/ Is it reasonably accurate and th

Re: [Tutor] How have I transgressed??

2011-08-21 Thread Steven D'Aprano
Lisi wrote: I have just received the following.* In what way have I transgressed? I apologise to you all - but as I mentioned, I had been stuck for weeks and am running out of time. And I certainly tried to help myself - I just didn't succeed! Anyhow, if someone will tell me in what way I ha

Re: [Tutor] Where is sys.py?

2011-08-21 Thread Steven D'Aprano
Lisi wrote: If sys.py is a file, it must be somewhere; but I can't find it. Where is it? I would like to look at it. Others have already answered this, but consider how you might explore the answer at the interactive interpreter: >>> import os >>> os.__file__ '/usr/lib/python2.5/os.pyc' >>

Re: [Tutor] Please help understanding unittest fixtures

2011-08-21 Thread Steven D'Aprano
D. Guandalino wrote: Suppose I have this TestCase class. class C(TestCase): def setUp(): # very time consuming and resources intensive stuffs. pass def test_A(self): pass def test_B(self): pass def test_C(self): pass The unittest docs says: Each i

Re: [Tutor] Please explain TypeError

2011-08-21 Thread Steven D'Aprano
D. Guandalino wrote: class C(object): ... def __init__(self): ... pass ... C(1) Traceback (most recent call last): File "", line 1, in TypeError: __init__() takes exactly 1 argument (2 given) I'm having hard times understanding why a TypeError is raised here. Could you exp

Re: [Tutor] Where is sys.py?

2011-08-22 Thread Steven D'Aprano
Lisi wrote: By "envelope" I meant container, because I was afraid of misusing the correct technical terms. I am still very confused by the terminology. Having been told that modules, functions and methods are just different names for the same thing, that commands are really also the same thi

Re: [Tutor] Python Speech

2011-08-23 Thread Steven D'Aprano
Christopher King wrote: Hello Tutors, I need help with text to speech and or speech to text. I know of two packages, but they require win32, which I can't get to work. The Win32 package was filled with pyd's and no py's..Could some one tell me how to get win32 to work or a package that doesn'

Re: [Tutor] eval func with floating...

2011-08-23 Thread Steven D'Aprano
Christopher King wrote: if c: print *eval("float(%s)"%a)* else: print "error! please use -defined operators-!" I would use a assert statement for more readability, like so. *try: assert c* *except AssertionError: print "error! please use -defined operators-!"* else: *pri

Re: [Tutor] eval func with floating...

2011-08-23 Thread Steven D'Aprano
Christopher King wrote: If the user ever sees an AssertionError, your code is buggy. Well you saw that I caught the AssertionError, so the user wouldn't technically see it. For the other stuff, I didn't know the etiquette for assertion It's not etiquette, it is the actual way assert works.

Re: [Tutor] Tutorials on csv module??

2011-08-24 Thread Steven D'Aprano
Khalid Al-Ghamdi wrote: Hi everyone, can anyone point me to a good tutorial on using the csv module? Search engines are a wonderful thing. http://duckduckgo.com/?q=python+csv+tutorial also, is there a module that can help me check data in a excel file other than the csv module? http://du

Re: [Tutor] Confirmation if command worked

2011-08-25 Thread Steven D'Aprano
Christian Witts wrote: if child.exitstatus and child.exitstatus == 0: success = True else: success = False There is never any need to write Python code that looks like that. (Or in any other language I'm familiar with either.) Anything of the form: if some_conditio

Re: [Tutor] help with a class

2011-08-25 Thread Steven D'Aprano
John wrote: Thanks for the feedback. I wasn't aware about the assert usage not being intended for production code. That's not quite true. There is nothing wrong with using asserts in production code. The important thing is to use them *properly*. Asserts are for checking your internal program

Re: [Tutor] Raw input query (?)

2011-08-25 Thread Steven D'Aprano
Lisi wrote: I copied and ran the following script: [...] What extra should I have done because the variable value came from the keyboard, and why is it different from the first example? You can investigate this yourself: >>> a = 12 >>> a = raw_input("please type 12") please type 12 12 >>> a

Re: [Tutor] Confirmation if command worked

2011-08-25 Thread Steven D'Aprano
Steven D'Aprano wrote: if some_condition: flag = True else: flag = False is better written as: flag = some_condition Actually, that's a slight over-simplification. some_condition may not actually be a bool. If you don't mind flag also being a non-bool, that

Re: [Tutor] String encoding

2011-08-25 Thread Steven D'Aprano
Prasad, Ramit wrote: I don't know what they are from but they are both the same value, one in hex and one in octal. 0xC9 == 0311 As for the encoding mechanisms I'm afraid I can't help there! Nice catch! Yeah, I am stuck on the encoding mechanism as well. I know how to encode/decode...but not

Re: [Tutor] help with 'organization'

2011-08-25 Thread Steven D'Aprano
John wrote: I know a code example might help, so I try to show it here (my code I'm afraid is too complex and ugly at the moment). You can see the it fails because MyTools doesn't have 'this' attribute... Then give it one. class MyTools: Add an initialisation method: def __init__(self

Re: [Tutor] String encoding

2011-08-26 Thread Steven D'Aprano
Prasad, Ramit wrote: Think about it this way... if I gave you a block of data as hex bytes: 240F91BC03...FF90120078CD45 and then asked you whether that was a bitmap image or a sound file or something else, how could you tell? It's just *bytes*, it could be anything. Yes, but if you give me da

Re: [Tutor] Can't find error :-(

2011-08-28 Thread Steven D'Aprano
Lisi wrote: For future reference, how would I set about changing the encoding for just one character or file? I don't really want to change the encoding I use system wide. You can set the encoding for the entire source file with an encoding line like: # -*- coding: utf-8 -*- This MUST be

Re: [Tutor] Still stuck - but a bit further on.

2011-08-28 Thread Steven D'Aprano
Lisi wrote: [...] Type the Name - leave blank to finishLisi You have no space in the name. It is "Lisi". Type the Street, Town, Phone. Leave blank to finishth, rc, 123457 Type the Name - leave blank to finish Which name to display?(blank to finish) Lisi Here you have a space at the start

Re: [Tutor] Sorting list of tuples in two passes

2011-08-28 Thread Steven D'Aprano
Dayo Adewunmi wrote: It works when I use your example, but I don't understand why it won't work when I use 4-element tuples instead of 2: What makes you say it doesn't work? It looks like it works to me: >>>l = [('wascas','aaa','fdvdfv', 1), ('rtgdsf','bbb','trfg', 1), ('addwe','ccc','esd',

Re: [Tutor] Auto-detecting of Python version - wrong!

2011-08-29 Thread Steven D'Aprano
Elisha Rosensweig wrote: I'm trying to use easy_install on my Mac to get the Python networx package. On my machine I have installed version 2.5 AND 2.6 of Python. However, wehn I try to install this package, I get: Hi Elisha, This list is for beginners trying to learning Python the language,

Re: [Tutor] Loops and matrices'

2011-08-29 Thread Steven D'Aprano
Alan Gauld wrote: On 30/08/11 00:26, Emile van Sebille wrote: delta_temp(i,j) = (LS_JULY_11(i,j) - LS_JULY_11(i,j-1))/TIME_STEP delta_temp access and assignment likely wants to be expressed with brackets rather than parens. And for those not speaking the US variant of English that'll be squ

Re: [Tutor] Tutor Digest, Vol 90, Issue 97

2011-08-29 Thread Steven D'Aprano
Lisi wrote: On Monday 29 August 2011 18:01:44 Cranky Frankie wrote: I'm sorry you were offended by my posts. If others were as well let me know and I'll unsubscribe immediately. Post in the singular. I could not, and can not, I'm afraid, see the point in writing such a long panegyric about P

Re: [Tutor] urllib2 issue getting realm

2011-08-31 Thread Steven D'Aprano
Johan Geldenhuys wrote: Hi everybody, I am trying to use a very simple piece of code to get the realm from different HTTPS URLs. This realm is essential for successful authentication on the HTTPS session. What happens if you paste https://192.168.10.191/axis-cgi/jpg/image.cgi?resolution=1280

Re: [Tutor] meaning of % in: if n % x == 0:

2011-08-31 Thread Steven D'Aprano
Hugo Arts wrote: n % y == 0 if n is divisible by y. This is useful in factoring prime numbers If you find a way to factor *prime numbers*, you're doing something wrong. :) (By definition, a prime number has no factors apart from itself and one, which are trivial.) You mean, factorising n

Re: [Tutor] Is there a test for hashability?

2011-09-01 Thread Steven D'Aprano
Richard D. Moores wrote: I'm trying to write a general test for hashability. How can I test if an object has both a __hash__() method and an __eq__() method? Just because an object has a __hash__ method doesn't mean it is guaranteed to be hashable. The method might (deliberately, or acciden

Re: [Tutor] Is there a test for hashability?

2011-09-01 Thread Steven D'Aprano
Richard D. Moores wrote: Thanks, James, from your ideas I've come up with this function as a general test for hashibility of any object: def is_hashable(object): try: if hash(object): return True except TypeError: return False No need for the "if hash" test,

Re: [Tutor] Is there a test for hashability?

2011-09-01 Thread Steven D'Aprano
On Fri, Sep 02, 2011 at 12:17:48PM +1000, Steven D'Aprano wrote: > Richard D. Moores wrote: > >Thanks, James, from your ideas I've come up with this function as a > >general test for hashibility of any object: > > > >def is_hashable(object):

Re: [Tutor] openpyxl

2011-09-01 Thread Steven D'Aprano
On Thu, Sep 01, 2011 at 05:55:04PM -0700, Helen Brown wrote: > Will someone share with me  a link where I can download subject in order for > my script to run? Any assistance will help! Did you try googling for it? http://duckduckgo.com/?q=openpyxl http://www.bing.com/search?q=openpyxl http://au

Re: [Tutor] how obsolete is 2.2?

2011-09-08 Thread Steven D'Aprano
c smith wrote: Also, am I correct in thinking that 3.0 will always be called 3.0 but will change over time and will always include experimental features, while 2.x will gradually increase the 'x' and the highest 'x' will indicate the most current, stable release? No, I'm afraid you are wrong.

Re: [Tutor] need advice about a dictionary ({})

2011-09-08 Thread Steven D'Aprano
Richard D. Moores wrote: But I'd like to put the lines of the dictionary in a text file so that I can add key/value items to it by writing to it with another script. If you expect human beings (yourself, or possibly even the user) to edit the text file, then you should look at a human-writabl

Re: [Tutor] a quick Q: built-in method pop of list object at 0x7f8221a22cb0>

2011-09-08 Thread Steven D'Aprano
lina wrote: Hi, what does the 0x7f8221a22cb0 mean here? the computer physical address. That's the ID of the list object, converted to hexadecimal. Every object in Python gets a unique (for the life of the object) ID. In CPython, the version you are using, that ID happens to be the memory

Re: [Tutor] a quick Q: what does the "collapse" mean?

2011-09-08 Thread Steven D'Aprano
lina wrote: Hi, I failed to understand the "collpase" meaning in a string. can someone give me a simple example? Sorry, I don't understand what you mean. Can you give context? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe

Re: [Tutor] throwing exception across modules?

2011-09-08 Thread Steven D'Aprano
James Hartley wrote: This is more a design question. One lesson C++ programmers might learn is that throwing exceptions from within library code is fraught with problems because the internals of exception handling were spelled out in the C++ standard. This manifests Do you mean "weren't spell

Re: [Tutor] a quick Q: what does the "collapse" mean?

2011-09-08 Thread Steven D'Aprano
lina wrote: one example: def info(object, spacing=10, collapse=1): """Print methods and docs strings. Take modules, class, list, dictionary, or strong.""" methodList = [e for e in dir(object) if callable(getattr(object, e))] processFunc = collapse and (lambda s: " ".join(s.spli

Re: [Tutor] a quick Q: what does the "collapse" mean?

2011-09-08 Thread Steven D'Aprano
lina wrote: collapse the text means? destory the text? make it collapse? Collapse runs of spaces into a single space. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/l

Re: [Tutor] Flat is better than Nested

2011-09-08 Thread Steven D'Aprano
Ryan Strunk wrote: Hello everyone, I am still learning to program by writing this boxing game. I'm running into a problem with how to organize data. My current setup looks something like this: """This feels incredibly disgusting to me.""" You might find it a little less disgusting with the app

Re: [Tutor] _init_() arguments

2011-09-09 Thread Steven D'Aprano
Stu Rocksan wrote: class Complex: def _init_(self, realpart, imagpart) Special methods in Python have TWO underscores at the beginning and end. You need to call it __init__ rather than _init_. Also, are you aware that Python already includes a built-in complex type? >>> comp

Re: [Tutor] Get a single random sample

2011-09-09 Thread Steven D'Aprano
kitty wrote: I'm new to python and I have read through the tutorial on: http://docs.python.org/tutorial/index.html which was really good, but I have been an R user for 7 years and and am finding it difficult to do even basic things in python, for example I want to import my data (a tab-delimited

Re: [Tutor] Get a single random sample

2011-09-09 Thread Steven D'Aprano
Peter Otten wrote: Steven D'Aprano wrote: # Get ten random samples, sampling with replacement. samples = [random.choice(subset) for i in range(10)] That may include subset items more than once. Hence the "sampling with replacement" comment. Use the aptly named rando

Re: [Tutor] Unusual pathfile

2011-09-13 Thread Steven D'Aprano
Susana Iraiis Delgado Rodriguez wrote: Hi! I just want to look the pathfile like this: C:\Python26 instead of C:/\Python26, I feel the loop repeats its walking with this pathfile structure. About the indention for the code, I tried my best to make it clear ande neat. But the mi e-mail editor it's

Re: [Tutor] Unusual pathfile

2011-09-13 Thread Steven D'Aprano
Susana Iraiis Delgado Rodriguez wrote: I think I've received many complains for my questions and messages Please don't be upset! We're not angry at your, and we are trying to help you. In English, we have a saying: "Give a man a fish, and you feed him for one day. Teach a man how to catch

Re: [Tutor] If statement optimization

2011-09-16 Thread Steven D'Aprano
bod...@googlemail.com wrote: Hi, In a normal if,elif,elif,...,else statement, are the conditions checked in a linear fashion? Yes. I am wondering if I should be making an effort to put the most likely true condition at the beginning of the block Probably not. The amount of time used in

Re: [Tutor] string formatting

2011-09-17 Thread Steven D'Aprano
Matthew Pirritano wrote: But I have very large blocks of text and I thought there was another way like X = "sky" Y = "blue" "the %(X)s is %(Y)s" Unless you use the string formatting operator %, strings containing "%" are just strings. Large or small, the way you do string formatting is with

Re: [Tutor] why is this so?

2011-09-18 Thread Steven D'Aprano
Khalid Al-Ghamdi wrote: Hi All, why is this so? type('love') "love" is str False The "is" operator tests for object identity. The line "love" is str tests whether the instance "love" is the same object as the class str. Obviously that is not the case. You might be thinking of an "i

Re: [Tutor] iretator.send

2011-09-19 Thread Steven D'Aprano
Christopher King wrote: Is there any syntax that uses the send method of an iterator? No. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How it is better than java

2011-09-19 Thread Steven D'Aprano
Ashish Gaonker wrote: My obvious thinking is : Java being compiled language , must be faster then a interpreted language. There are three misunderstandings with that statement. Firstly: Languages are neither "compiled" or "interpreted". Languages are syntax and grammar. Implementations ar

Re: [Tutor] string formatting

2011-09-19 Thread Steven D'Aprano
Wayne Werner wrote: On Mon, Sep 19, 2011 at 1:11 PM, wrote: Is there any additional overhead of using the locals() or format(locals()) instead of a tuple? - the format option is a double function call so I would expect that to be considerably slower Using the following code and timeit, it a

Re: [Tutor] quick data structures question

2011-09-21 Thread Steven D'Aprano
Fred G wrote: Hey guys, I want to write a short script that takes from an input excel file w/ a bunch of rows and columns. The two columns I'm interested in are "high gains" and "genes." I want the user to write: Which genes are associated with gains over 20%? Depending on your requiremen

Re: [Tutor] List of Classes with a dictionary within the Class.

2011-09-21 Thread Steven D'Aprano
Mukund Chavan wrote: Hi, I was trying to get a list of Class Objects. The Class itself has string fields and a dictionary that is initialized as a part of the "__init__" No it doesn't. It has a dictionary that is initialised *once*, when the class is defined. From that point on, every instan

Re: [Tutor] Running .py files in shell

2011-09-22 Thread Steven D'Aprano
Robert Layne wrote: Well everybody, sorry for the incomplete sentences and overall poor English but I wanted to make this simple to read and understand for someone who is completely inexperienced in any sort of programming, Generally speaking, incomplete sentences and overall poor English mak

Re: [Tutor] How it is better than java

2011-09-22 Thread Steven D'Aprano
Mac Ryan wrote: On Tue, 20 Sep 2011 10:27:12 +1000 Steven D'Aprano wrote: There are three misunderstandings with that statement. [snip] There's also JPype, which claims to give full access to Java libraries in Python. Now: this was one of the best write-ups on the subject I rea

Re: [Tutor] range question

2011-09-22 Thread Steven D'Aprano
Joel Knoll wrote: Given a range of integers (1,n), how might I go about printing them in the following patterns: 1 2 3 4 ... n2 3 4 5 ... n 13 4 5 6 ... n 1 2 etc., e.g. for a "magic square". So that for the range (1,5) for example I would get 1 2 3 42 3 4 13 4 1 24 1 2 3 I'm not sure what

Re: [Tutor] password loop

2011-09-23 Thread Steven D'Aprano
ADRIAN KELLY wrote: Can anyone help me with the programme below; i hope you can see what i am trying to do, if i enter the wrong password the loop goes on forever and if i enter the right one nothing is printed... i am a newbieall comments welcome thanks adrian p

Re: [Tutor] How it is better than java

2011-09-23 Thread Steven D'Aprano
Alan Gauld wrote: Apart from trolling the list what do you hope to gain from this post? Be fair -- there's no evidence that Ashish Gaonker was insincere about his question or trying to stir up trouble. It is a very common misapprehension that "language Foo is faster than language Bar", and

Re: [Tutor] execute a function

2011-09-26 Thread Steven D'Aprano
Sajjad wrote: Hello forum, It has been two days that i have started with python and i am stuck with the following simple issue: i have created a python file and inside the file i have defined a function as follows: def greeting():

<    5   6   7   8   9   10   11   12   13   14   >