Re: Strange behavior of int()

2006-01-29 Thread Dan Bishop
Brian wrote: > Hello, > > Can someone tell me what I am doing wrong in this code. > > If I create a file change.py with the following contents: > > def intTest(M, c): > r = M > for k in c: > print 'int(r/k) = ', int(r/k), 'r =', r, 'k =', k, 'r/k > =', r/k >

Re: simple math question

2006-02-11 Thread Dan Bishop
Paul Rubin wrote: > John Salerno <[EMAIL PROTECTED]> writes: > > Can someone explain to me why the expression 5 / -2 evaluates to -3, > > especially considering that -2 * -3 evaluates to 6? > > > > I'm sure it has something to do with the negative number and the > > current way that the / operator

Re: Python 3000 deat !? Is true division ever coming ?

2006-02-18 Thread Dan Bishop
Magnus Lycka wrote: > Gregory Piñero wrote: > > I knew about that approach. I just wanted less typing :-( > > It's enough to introduce one float in the mix. > 1.*a/b or float(a)/b if you don't want one more > multiplication. That doesn't work if either a or b is a Decimal. What *could* work is

Re: Python Challenge ahead [NEW] for riddle lovers

2005-04-30 Thread Dan Bishop
Shane Hathaway wrote: > pythonchallenge wrote: > > For the riddles' lovers among you, you are most invited to take part > > in the Python Challenge, the first python programming riddle on the net. > > > > You are invited to take part in it at: > > http://www.pythonchallenge.com > > That was pretty

Re: Python Challenge ahead [NEW] for riddle lovers

2005-04-30 Thread Dan Bishop
Dan Bishop wrote: > Shane Hathaway wrote: > > pythonchallenge wrote: > > > For the riddles' lovers among you, you are most invited to take > part > > > in the Python Challenge, the first python programming riddle on the > net. > > > > >

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-01 Thread Dan Bishop
Roel Schroeven wrote: > Dan Bishop wrote: > > > Dan Bishop wrote: > > > > Correction: Now I'm stuck on Level 11. I think I'm supposed to do > > something with the pixels in the image, but what? > > Me too. I've tried making different image

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-02 Thread Dan Bishop
Dan Christensen wrote: > Reinhold Birkenfeld <[EMAIL PROTECTED]> writes: > > > Dan Christensen wrote: > >> Roel Schroeven <[EMAIL PROTECTED]> writes: > >> > >>> There's no level 12 yet though. > >> > >> Now there's a 12 and a 13 (at least!). > > > > Anyone solved 12? Hints? > > **hint below** > > L

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-02 Thread Dan Bishop
John Hazen wrote: > * Dan Bishop <[EMAIL PROTECTED]> [2005-05-02 21:09]: > > Dan Christensen wrote: > > > Reinhold Birkenfeld <[EMAIL PROTECTED]> writes: > > > > > > > Dan Christensen wrote: > > > >> Roel Schroeven <[EMAIL

Re: control precision for str(obj) output?

2005-05-03 Thread Dan Bishop
Bo Peng wrote: > Dear list, > > I have enjoyed the convenience to output any object with str(obj) for a > while. However, I get long output for things like str([0.0002]) in my > output (which bothers my users more than me though). I also do not > understand why the following is happening: > > >>>

Re: control precision for str(obj) output?

2005-05-03 Thread Dan Bishop
Andrew Dalke wrote: > Mike Meyer wrote: > > Someone want to tell me the procedure for submitting FAQ entries, so I > > can do that for this? > > You mean more than what already exists at > http://www.python.org/doc/faq/general.html#why-are-floating-point-calculations-so-inaccurate > > which has a l

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-04 Thread Dan Bishop
Martijn Pieters wrote: > Martijn Pieters wrote: > > I haven't figured this one out yet either. Rather frustrating really. > > All the hints I've been given so far is to remember the solution for > > level 12. > > A, that was devious! I found it finally, how evil that was! I really > fell for i

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-05 Thread Dan Bishop
James Carroll wrote: > Och! Thanks for the hint! I actually guessed the answer of who to > phone earlier in the day, but didn't have the capitolization > correct... Damn! Great riddles! I found the answer with a brute-force search (using /usr/share/dict/words). -- http://mail.python.org/mail

Re: How to detect a double's significant digits

2005-05-05 Thread Dan Bishop
Fredrik Lundh wrote: > "mrstephengross" wrote: > > > >But, assuming you have your numbers as strings, I would suggest > > looking > > at str.split() and len(). > > > > Well, the numbers are in fact stored as numbers, so string processing > > won't work. > > if they're not strings, your question is

Re: Python Pseudo-Switch

2005-05-07 Thread Dan Bishop
James Stroud wrote: > Hello All, > > Because of my poorly designing a database, I have recently found it necessary > to explore the wonders of the Python pseudo-switch: > > do_case = { "A" : lambda x: x["bob"], > "B" : lambda x: x["carol"], > "C" : lambda x: "Ted", >

Re: Inverse confusion about floating point precision

2005-05-09 Thread Dan Bishop
Skip Montanaro wrote: > I understand why the repr() of float("95.895") is "95.8949996". > What I don't understand is why if I multiply the best approximation to > 95.895 that the machine has by 1 I magically seem to get the lost > precision back. To wit: > > % python > Python 2

Re: Python Args By Reference

2005-05-10 Thread Dan Bishop
Joseph Garvin wrote: > ncf wrote: > > >Hello all, I was wondering if there was any way to pass arguments > >(integer and such) by reference (address of), rather than by value. > > > >Many thanks in advance. > > > > All mutable types in python are passed by reference automatically. More accurately:

Re: Python Args By Reference

2005-05-10 Thread Dan Bishop
ncf wrote: > As I fail to see how an array could be used in this (my own > stupidity?), would you have any such example? For reference, I'm trying > to translate this: http://www.cr0.net:8040/code/crypto/sha256/ (Inside > sha256_process). > > Once again, thanks for the patience, I'm still picking u

Re: windows directories for curr user

2005-05-10 Thread Dan Bishop
flamesrock wrote: > Hi, > > Short, maybe newbish question: Is there a python method for finding out > who the current user is in the OS module? > > On older windows machines the directory I'm interested in is just > "c://my documents", but how do I walk to the current users my documents > folder?

Re: replace text in unicode string

2005-05-14 Thread Dan Bishop
Svennglenn wrote: > I'm having problems replacing text in a > unicode string. > Here's the code: > > # -*- coding: cp1252 -*- > > titel = unicode("ä", "iso-8859-1") > print titel > print type(titel) > > titel.replace("ä", "a") > > When i run this program I get this error: > > titel.replace("ä",

Re: Byte-operations.

2005-05-19 Thread Dan Bishop
Dave Rose wrote: > I hope someone can please help me. A few months ago, I found a VBS file, > MonitorEDID.vbs on the internet. ...[snip]... > Anyway, the functions from VBS I don't know how to translate to Python are: > > #location(0)=mid(oRawEDID(i),0x36+1,18) > #location(1)=mid(o

Re: Comparing 2 similar strings?

2005-05-19 Thread Dan Bishop
Steven D'Aprano wrote: > On Thu, 19 May 2005 14:09:32 +1000, John Machin wrote: > > > None of the other approaches make the mistake of preserving the first > > letter -- this alone is almost enough reason for jettisoning soundex. > > Off-topic now, but you've made me curious. > > Why is this a bad

Re: how to convert string to list or tuple

2005-05-29 Thread Dan Bishop
Simon Brunning wrote: > On 5/26/05, flyaflya <[EMAIL PROTECTED]> wrote: > > a = "(1,2,3)" > > I want convert a to tuple:(1,2,3),but tuple(a) return ('(', '1', ',', > > '2', ',', '3', ')') not (1,2,3) > > Short answer - use eval(). > > Long answer - *don't* use eval unless you are in control of the

Re: Binary numbers

2005-06-07 Thread Dan Bishop
Douglas Soares de Andrade wrote: > Hi ! > > How to work with binary numbers in python ? Is there a way to print a number > in its binary form like we do with oct() or hex() ? > > Im doing a project that i have to work with binaries and i tired of convert > numbers to string all the time to perform

Re: Annoying behaviour of the != operator

2005-06-08 Thread Dan Bishop
Mahesh wrote: > No, why should Python assume that if you use != without supplying a > __ne__ that this is what you want? Because every single time I've used __ne__, that *is* what I want. > Without direction it will compare > the two objects which is the default behavior. It's also the default b

Re: Annoying behaviour of the != operator

2005-06-08 Thread Dan Bishop
Mahesh wrote: > I understand that what makes perfect sense to me might not make perfect > sense to you but it seems a sane default. When you compare two objects, > what is that comparision based on? In the explicit is better than > implicit world, Python can only assume that you *really* do want to

Re: Decimal Places Incorrect

2005-06-08 Thread Dan Bishop
Tom Haddon wrote: > Hi Folks, > > When I run: > > print "%0.2f" % ((16160698368/1024/1024/1024),) > > I get 15.00 > > I should be getting 15.05. Can anyone tell me why I'm not? Because you forgot to use "from __future__ import division". -- http://mail.python.org/mailman/listinfo/python-list

Re: Is pyton for me?

2005-06-09 Thread Dan Bishop
Mark de+la+Fuente wrote: > I need to write simple scripts for executing command line functions. Up till > now I've used C-Shell scripts for this, but I'm looking for a better > alternative. And I keep reading about how "easy" it is to program with > python. > > Unfortunately after reading "divein

Re: Annoying behaviour of the != operator

2005-06-10 Thread Dan Bishop
Steven D'Aprano wrote: ... > If you were to ask, "which is bigger, 1+2j or 3+4j?" then you > are asking a question about mathematical size. There is no unique answer > (although taking the absolute value must surely come close) and the > expression 1+2j > 3+4j is undefined. > > But if you ask "whic

Re: can this be implemented?

2007-06-02 Thread Dan Bishop
On Jun 2, 6:54 pm, greenflame <[EMAIL PROTECTED]> wrote: > First I should start with some introductory comments. > > When I first learned about programming, I started with BASIC, QBASIC > to be more accurate. While I was at that stage, I learned about the > INPUT command. I used it abundantly. > >

Re: int vs long

2007-06-02 Thread Dan Bishop
On Jun 2, 9:30 pm, jay <[EMAIL PROTECTED]> wrote: > I was reading in a book that the 'int' type can store whole numbers > up to 32 bits. I'm not exactly sure what that means, but got me > wondering, what's the largest number you can store as an 'int' before > you need to switch over to 'long'? sy

Re: int vs long

2007-06-03 Thread Dan Bishop
On Jun 2, 11:55 pm, kaens <[EMAIL PROTECTED]> wrote: > On 02 Jun 2007 20:18:02 -0700, Paul Rubin > > <"http://phr.cx"@nospam.invalid> wrote: > > Dan Bishop <[EMAIL PROTECTED]> writes: > > > Note that recent versions of Python automatically promot

Re: *Naming Conventions*

2007-06-03 Thread Dan Bishop
On Jun 3, 11:03 pm, Thorsten Kampe <[EMAIL PROTECTED]> wrote: > Okay, > > I hear you saying 'not another naming conventions thread'. I've read > through Google and the 'naming conventions' threads were rather > *spelling conventions* threads. > > I'm not interested in camelCase versus camel_case or

Re: lists - append - unique and sorted

2007-06-06 Thread Dan Bishop
On Jun 6, 10:26 am, rhXX <[EMAIL PROTECTED]> wrote: > hi, > > can i append a item to a list using criterias: > > - UNIQUE - if there already exist don't append > > and/or > > - SORTED - INSERT in the correct place using some criteria? > > tks in advance If you don't need the list to be sorted unti

Re: Integer division

2007-06-07 Thread Dan Bishop
On Jun 7, 8:30 pm, Some Other Guy <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Hello all, > > I have two integers and I want to divide one by another, and want to > > get an integer result which is the higher side whenever the result is > > a fraction. > > 3/2 => 1 # Usual behavior >

Re: matrix class

2007-06-12 Thread Dan Bishop
On Jun 12, 7:31 pm, DarrenWeber <[EMAIL PROTECTED]> wrote: > Below is a module (matrix.py) with a class to implement some basic > matrix operations on a 2D list. Some things puzzle me about the best > way to do this (please don't refer to scipy, numpy and numeric because > this is a personal progr

Re: How can I 'compound' streams?

2007-06-27 Thread Dan Bishop
On Jun 27, 7:40 pm, XiaQ <[EMAIL PROTECTED]> wrote: > I need to build a stream that writes to stdout and a file at the same > time. Is there already a function in the Python library to do this? class FileAndStdout(file): def write(self, data): file.write(self, data) sys.stdout

Re: 16bit hash

2007-06-27 Thread Dan Bishop
On Jun 27, 12:11 pm, Robin Becker <[EMAIL PROTECTED]> wrote: > Josiah Carlson wrote: > > Robin Becker wrote: > >> Is the any way to get an efficient 16bit hash in python? > > > hash(obj)&65535 > > > - Josiah > > yes I thought of that, but cannot figure out if the internal hash really > distribute

Re: Questions about input lines (maximum length and continuation)

2007-07-03 Thread Dan Bishop
On Jul 3, 10:41 pm, Robert Dodier <[EMAIL PROTECTED]> wrote: > Hello, > > I'm planning to write a program which automatically generates > Python code. > > (1) Is there a limit on the length of a line in a Python program? No. > (2) From what I understand, symbols, operators, and numbers > cannot b

Re: Where is the syntax for the dict() constructor ?!

2007-07-05 Thread Dan Bishop
On Jul 5, 10:19 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > Neil Cerutti <[EMAIL PROTECTED]> wrote: > > Besides, a string is an excellent epresentation for a zip code, > > since arithmetic upon them is unthinkable. > > Absolutely! Excel, unless you remedied that later with a column > operation,

Re: Learning Basics

2007-07-08 Thread Dan Bishop
On Jul 8, 12:10 pm, Brad <[EMAIL PROTECTED]> wrote: > So I've been studying python for a few months (it is my first foray > into computer programming) and decided to write my own little simple > journaling program. It's all pretty basic stuff but I decided that I'd > learn more from it if more expe

Re: Pass by reference or by value?

2007-07-13 Thread Dan Bishop
On Jul 13, 2:10 pm, Robert Dailey <[EMAIL PROTECTED]> wrote: > Hi, > > I noticed in Python all function parameters seem to be passed by > reference. This means that when I modify the value of a variable of a > function, the value of the variable externally from the function is > also modified. Pyt

Re: Semantics of file.close()

2007-07-16 Thread Dan Bishop
On Jul 16, 6:35 pm, [EMAIL PROTECTED] wrote: > Hello, > > I'm a Python beginner and I'm trying to open, write and close a file > in a > correct manner. I've RTFM, RTFS, and I've read this > thread:http://groups.google.ca/group/comp.lang.python/browse_thread/thread/7... > > I still cannot figure ou

Re: In a dynamic language, why % operator asks user for type info?

2007-07-16 Thread Dan Bishop
On Jul 16, 7:10 pm, Karthik Gurusamy <[EMAIL PROTECTED]> wrote: > Hi, > > The string format operator, %, provides a functionality similar to the > snprintf function in C. In C, the function does not know the type of > each of the argument and hence relies on the embedded % > specifier to guide itse

Re: a=0100; print a ; 64 how to reverse this?

2007-07-17 Thread Dan Bishop
On Jul 17, 7:40 am, mosi <[EMAIL PROTECTED]> wrote: > Thank you, > this is great, > I thought that this should be standard in python 2.4 or 2.5 or in some > standard library (math ???) > Didn`t find anything. The bin() function is slated to be added to the next version of Python. Why there isn't

Re: Permutations with generators

2007-07-20 Thread Dan Bishop
On Jul 21, 12:42 am, Pablo Torres <[EMAIL PROTECTED]> wrote: > Hey guys! > For the last couple of days, I've been fighting a war against > generators and they've beaten the crap out of me several times. What I > want to do is implement one that yields every possible permutation of > a given sequenc

Re: How do I tell the difference between the end of a text file, and an empty line in a text file?

2007-05-16 Thread Dan Bishop
On May 16, 4:47 pm, walterbyrd <[EMAIL PROTECTED]> wrote: > Python's lack of an EOF character is giving me a hard time. > > I've tried: > > - > s = f.readline() > while s: > . > . > s = f.readline() > > > and > > --- > s = f.readline() > while s != '' > . > . > s = f.readline() > -

Re: A newbie question

2007-05-21 Thread Dan Bishop
On May 21, 6:04 pm, "wang frank" <[EMAIL PROTECTED]> wrote: > Hi, > > I am trying to write a python class with a new data type such as: > class Cc14: >def __init__(self, realpart, imagpart): > self.r=realart > self.i=imagpart > >def __add__(self,x):

Re: 0 == False but [] != False?

2007-05-24 Thread Dan Bishop
On May 24, 1:59 am, Tim Roberts <[EMAIL PROTECTED]> wrote: ... > False is just a constant. 0, (), '', [], and False are all constants that > happen to evaluate to a false value in a Boolean context, but they are not > all the same. > > As a general rule, I've found code like "if x == False" to be

Re: conditionally creating functions within a class?

2007-05-26 Thread Dan Bishop
On May 25, 7:44 pm, kaens <[EMAIL PROTECTED]> wrote: > So, I have a class that has to retrieve some data from either xml or > an sql database. > This isn't a problem, but I was thinking "hey, it would be cool if I > could just not define the functions for say xml if I'm using sql", so > I did some

Re: Newbie: Struggling again 'map'

2007-05-26 Thread Dan Bishop
On May 26, 4:54 am, mosscliffe <[EMAIL PROTECTED]> wrote: > I thought I had the difference between 'zip' and 'map' sorted but when > I try to fill missing entries with something other than 'None'. I do > not seem to be able to get it to work - any pointers appreciated. > > Richard > > lista = ['a1'

Re: printing list, is this a bug?

2007-05-26 Thread Dan Bishop
On May 25, 3:55 pm, William Chang <[EMAIL PROTECTED]> wrote: > Is the different behavior between __repr__ and __str__ intentional > when it comes to printing lists? Basically I want to print out a list > with elements of my own class, but when I overwrite __str__, __str__ > doesn't get called but i

Re: automatic type conversion for comparison operators

2007-07-26 Thread Dan Bishop
On Jul 26, 6:22 pm, Russ <[EMAIL PROTECTED]> wrote: > I posted a message on this several days ago, but it apparently got > lost > in googlespace, so I'll try it again. > > I recently discovered a bug in my code that apparently resulted from > the automatic conversion of a function pointer to an int

Re: question about math module notation

2007-07-26 Thread Dan Bishop
On Jul 26, 3:59 pm, Paul Rubin wrote: > brad <[EMAIL PROTECTED]> writes: > > Ah yes, that works too... thanks. I've settled on doing it this way: > > print int(math.pow(2,64)) > > I like the added parenthesis :) > > I was surprised to find that gives an exact (integer, no

Re: automatic type conversion for comparison operators

2007-07-26 Thread Dan Bishop
On Jul 26, 8:04 pm, Russ <[EMAIL PROTECTED]> wrote: > Dan Bishop wrote: > > BTW, are you a former Pascal programmer? > > No. Why do you ask? [The code snippet I wrote was made up to get a > point across. I > did not actually use that function name in my code.] I just ha

Re: bias in random.normalvariate??

2007-08-03 Thread Dan Bishop
On Aug 3, 10:38 pm, [EMAIL PROTECTED] wrote: > I'm a Python newbie and certainly no expert on statistics, but my wife > was taking a statistics course this summer and to illustrate that > sampling random numbers from a distribution and taking an average of > the samples gives you a random number as

Re: beginner whitespace question

2007-08-09 Thread Dan Bishop
On Aug 9, 6:47 pm, eggie5 <[EMAIL PROTECTED]> wrote: > I keep getting an error for line 7, what's wrong with this? > > from django.db import models > > class Poll(models.Model): > question = models.CharField(max_length=200) > pub_date = models.DateTimeField('date published') > > def

Re: beginner whitespace question

2007-08-09 Thread Dan Bishop
On Aug 9, 7:02 pm, eggie5 <[EMAIL PROTECTED]> wrote: > On Aug 9, 4:52 pm, Dan Bishop <[EMAIL PROTECTED]> wrote: > > > On Aug 9, 6:47 pm, eggie5 <[EMAIL PROTECTED]> wrote: > > > > I keep getting an error for line 7, what's wrong with this? > >

Re: beginner whitespace question

2007-08-09 Thread Dan Bishop
On Aug 9, 8:28 pm, James Stroud <[EMAIL PROTECTED]> wrote: > eggie5 wrote: > > But this still isn't valid: > > > from django.db import models > > > class Poll(models.Model): > >question = models.CharField(max_length=200) > >pub_date = models.DateTimeField('date published') > > > def __u

Re: beginner, idomatic python 2

2007-08-23 Thread Dan Bishop
On Aug 23, 10:21 pm, "bambam" <[EMAIL PROTECTED]> wrote: > Would someone like to suggest a replacement for this? This is a > function that returns different kinds of similar objects, depending > on what is asked for. PSP and PWR are classes. I don't really > want to re-write the calling code very

Re: Does shuffle() produce uniform result ?

2007-08-25 Thread Dan Bishop
On Aug 24, 2:38 am, tooru honda <[EMAIL PROTECTED]> wrote: > Hi, > > I have read the source code of the built-in random module, random.py. > After also reading Wiki article on Knuth Shuffle algorithm, I wonder if > the shuffle method implemented in random.py produces results with modulo > bias. > >

Re: unsigned integer?

2007-03-10 Thread Dan Bishop
On Mar 10, 11:32 am, "Jack" <[EMAIL PROTECTED]> wrote: > This is a naive question: > > "%u" % -3 > > I expect it to print 3. But it still print -3. > > Also, if I have an int, I can convert it to unsigned int in C: >int i = -3; >int ui = (unsigned int)i; > > Is there a way to do this in Pyt

Re: unsigned integer?

2007-03-10 Thread Dan Bishop
On Mar 10, 11:50 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > "Jack" <[EMAIL PROTECTED]> wrote: > > This is a naive question: > > > "%u" % -3 > > > I expect it to print 3. But it still print -3. > > Internally it uses the C runtime to format the number, but if the number > you ask it to print unsi

Re: Formatted Input

2007-03-10 Thread Dan Bishop
On Mar 10, 1:29 pm, "Deep" <[EMAIL PROTECTED]> wrote: > Hi all, > I am a newbie to python > I have an input of form > space > ie. > 4 3 > how can i assign these numbers to my variables?? n1, n2 = map(int, raw_input().split()) -- http://mail.python.org/mailman/listinfo/python-list

Re: Signed zeros: is this a bug?

2007-03-11 Thread Dan Bishop
On Mar 11, 9:31 am, "Mark Dickinson" <[EMAIL PROTECTED]> wrote: > I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC, > in case it's relevant.) > > >>> x, y = 0.0, -0.0 > >>> x, y > (0.0, 0.0) > >>> x, y = -0.0, 0.0 > >>> x, y > > (-0.0, -0.0) > > I would have expected y to be -0.0

Re: newb: Python Floating Point

2007-03-15 Thread Dan Bishop
On Mar 15, 6:09 pm, "johnny" <[EMAIL PROTECTED]> wrote: > When I do the following, rounding to 2 decimal places doesn't seem to > work. I should get 0.99 : In binary, 0.99 is the recurring fraction 0.11 010111101000 010111101000 010111101000 Thus, it can't be exactly

Re: TypeError: 'int' object is not callable

2007-03-22 Thread Dan Bishop
On Mar 22, 6:54 pm, [EMAIL PROTECTED] wrote: > I'm trying to test a few different approaches to displaying pages via > Cherrypy and I'm not having much luck. Here is my code so far: > > import sys, cherrypy, html > > class Root: > @cherrypy.expose > def index(self, pageid = None):

Re: Calling private base methods

2007-04-12 Thread Dan Bishop
On Apr 12, 3:02 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > "7stud" <[EMAIL PROTECTED]> wrote: > > On Apr 12, 5:04 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > >> "7stud" <[EMAIL PROTECTED]> wrote: > >> > On Apr 12, 2:47 am, "Jorgen Bodde" <[EMAIL PROTECTED]> wrote: > >> >> Is it possible to cal

Re: Simple integer comparison problem

2007-04-14 Thread Dan Bishop
On Apr 14, 10:19 am, [EMAIL PROTECTED] wrote: > Hi! > I ran in problem with simple exercise. I'm trying to get program to > return grade when given points but no matter what, I always get F. > > def grader(): > print "Insert points: " > points = raw_input('> ') > int(points) > >

Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-14 Thread Dan Bishop
On Apr 14, 10:55 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > The FORTRAN family had started as 1-based (F95, and Ada, now allow > for each array to have its own "base" => x : array (-10..10) of float). > Pascal, I forget... Pascal allows arbitrary array bases. It's where Ada got t

Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-15 Thread Dan Bishop
On Apr 15, 6:06 pm, "Beliavsky" <[EMAIL PROTECTED]> wrote: > On Apr 14, 10:12 pm, "Paddy" <[EMAIL PROTECTED]> wrote: > > > > > So the running count is: > > Ayes to the left: VB compatibility. > > Nays to the right: QuadIO, Perl, Dijkstra paper. > > > The nays have it! > > One-based indexing

Re: subclass of integers

2007-09-14 Thread Dan Bishop
On Sep 14, 9:30 am, Mark Morss <[EMAIL PROTECTED]> wrote: > I would like to construct a class that includes both the integers and > None. I desire that if x and y are elements of this class, and both > are integers, then arithmetic operations between them, such as x+y, > return the same result as

Re: A short question about non-ascii characters in list

2007-09-16 Thread Dan Bishop
On Sep 17, 12:08 am, js <[EMAIL PROTECTED]> wrote: > >>> print u"äöü" > äöü > >>> print [u"äöü"] > > [u'\xe4\xf6\xfc'] > > Python seems to treat non-ASCII chars in a list differently from the > one in the outside of a list. > I think this behavior is so inconvenient and actually makes debugging > w

Re: delineating by comma where commas inside quotation marks don't count

2007-10-24 Thread Dan Bishop
On Oct 24, 8:56 pm, "Junior" <[EMAIL PROTECTED]> wrote: > I want to open a text file for reading and delineate it by comma. I also > want any data > surrounded by quotation marks that has a comma in it, not to count the > commas inside the > quotation marks Use the csv module. -- http://mail.py

Re: Proposal: Decimal literals in Python.

2007-10-27 Thread Dan Bishop
On Oct 27, 10:27 am, Paul Hankin <[EMAIL PROTECTED]> wrote: > On Oct 27, 3:09 pm, MRAB <[EMAIL PROTECTED]> wrote: > > > > > On Oct 27, 12:12 am, Ben Finney <[EMAIL PROTECTED]> > > wrote:> Matimus <[EMAIL PROTECTED]> writes: > > > > The trailing L [for 'long' literals] is going away in Python 3.0. >

Re: Summarizing data by week

2007-01-09 Thread Dan Bishop
On Jan 9, 1:57 pm, "Mike Orr" <[EMAIL PROTECTED]> wrote: > What's the best way to summarize data by week? I have a set of > timestamped records, and I want a report with one row for each week in > the time period, including zero rows if there are weeks with no > activity. I was planning to use IS

Re: dot operations

2007-01-11 Thread Dan Bishop
On Jan 11, 10:21 am, "Steven W. Orr" <[EMAIL PROTECTED]> wrote: > On Thursday, Jan 11th 2007 at 11:41 +0100, quoth robert: > > =>[EMAIL PROTECTED] wrote:=>> Hi, > =>> Frequently I get to do like this: > =>> a = (1, 2, 3, 4) # some dummy values > =>> b = (4, 3, 2, 1) > =>> import operator > =>> c =

Re: Boilerplate in rich comparison methods

2007-01-13 Thread Dan Bishop
On Jan 13, 12:52 am, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > I'm writing a class that implements rich comparisons, and I find myself > writing a lot of very similar code. If the calculation is short and > simple, I do something like this: > > class Parrot: > def __eq__(self, other): >

Re: HTML Calendar code

2007-01-13 Thread Dan Bishop
On Jan 13, 11:35 am, Kajsa Anka <[EMAIL PROTECTED]> wrote: > Before I re-invent something I would like to ask if there exists some code > that can be used for create the HTML code for a calendar which I then can > include on a web page. > > The module in the standard library can create a calendar b

Re: indentation in python

2007-01-13 Thread Dan Bishop
On Jan 13, 8:49 pm, "lee" <[EMAIL PROTECTED]> wrote: > Can anyone tell me the basics about indentation in python..how we > use it in loops and constructs..etc It's just like indentation in other languages, except that it's syntactically required. -- http://mail.python.org/mailman/listinf

Re: How can I write code using FP

2007-01-16 Thread Dan Bishop
On Jan 16, 9:18 pm, "kernel1983" <[EMAIL PROTECTED]> wrote: > In Function Program,Language can use like this: > > define a function: > f = lambda x,y:x,y > > then we use f to define another function: > f2 = f(1) > the f2 should equal to: > f2=lambda y:1,y > > we should be able call f2 with one para

Re: import from future

2007-01-28 Thread Dan Bishop
On Jan 28, 1:25 am, "lee" <[EMAIL PROTECTED]> wrote: > what are the things that we can do with import from future usage.i > heard its very interesting..thanks Now that nested_scopes and generators are no longer optional, the only thing left is "from __future__ import division", which make

Re: Calculating future dates

2007-02-01 Thread Dan Bishop
On Feb 1, 6:51 pm, "Toine" <[EMAIL PROTECTED]> wrote: > Hello, > > I'm new to Python so please bare with me... > > I need to calculate a date that is exactly 31 days from the current > date in -MM-DD format. I know that date.today() returns the > current date, but how can I add 31 days to this

Re: Does Python have equivalent to MATLAB "varargin", "varargout", "nargin", "nargout"?

2007-02-18 Thread Dan Bishop
On Feb 18, 12:58 pm, [EMAIL PROTECTED] wrote: > Thank you in advance for your response. > Dmitrey The Python equivalent to "varargin" is "*args". def printf(format, *args): sys.stdout.write(format % args) There's no direct equivalent to "varargout". In Python, functions only have one return

Re: Is type object an instance or class?

2007-02-26 Thread Dan Bishop
On Feb 26, 8:00 pm, "JH" <[EMAIL PROTECTED]> wrote: > Hi > > I found that a type/class are both a subclass and a instance of base > type "object". > > It conflicts to my understanding that: > > 1.) a type/class object is created from class statement > 2.) a instance is created by "calling" a class

Re: How to use cmp() function to compare 2 files?

2007-02-26 Thread Dan Bishop
On Feb 26, 10:09 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi, > > i have 2 files which are different (1 line difference): > $ diff groupresult20070226190027.xml groupresult20070226190027-2.xml > 5c5 > < x:22 y:516 w:740 h:120 area: > --- > > > x:22 y:516 w:740 h:1202 area: > > But when

Re: os.system and quoted strings

2007-02-27 Thread Dan Bishop
On Feb 27, 9:16 am, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Tue, 27 Feb 2007 06:24:41 -0800, svata wrote: ... > > import time > > import os > > > dir = "C:\\Documents and Settings\\somepath\\" > > I believe that Windows will accept forward slashes as directory > separators, so you can write

Re: bug in modulus?

2006-04-23 Thread Dan Bishop
[EMAIL PROTECTED] wrote: > Hmmm. I understand. I'd suggest that someone just drop a link from the > Library reference manual as the divmod entry over there seems to > contradict it. > > """ > divmod(a, b) > > Take two (non complex) numbers as arguments and return a pair of > numbers consisting of t

Re: ending a string with a backslash

2006-05-01 Thread Dan Bishop
John Salerno wrote: > I have this: > > subdomain = raw_input('Enter subdomain name: ') > > path = r'C:\Documents and Settings\John Salerno\My Documents\My > Webs\1and1\johnjsalerno.com\' + subdomain > > Obviously the single backslash at the end of 'path' will cause a > problem, and escaping it with

Re: Converting floating point to string in non-scientific format

2006-05-01 Thread Dan Bishop
Madhusudhanan Chandrasekaran wrote: > Hi all: > > When I try to convert a float variable into string via repr() or str() > function, i get the value as is, i.e '0.1e-7' in IEEE 754 format. > Instead how can force the created string to represent the floating > point in non-scientific fashion (non IE

Re: returning none when it should be returning a list?

2006-05-01 Thread Dan Bishop
Edward Elliott wrote: [in reponse to some prime-number code] > 5. you can do better than checking every odd number (next+2) to find the > next prime, but I'm too tired to look into it right now. it may require > more complex machinery. You only need to check the prime numbers up to sqrt(n). If y

Re: NaN handling

2006-05-06 Thread Dan Bishop
Ivan Vinogradov wrote: > > > > NaNs are handled. > > Throwing an exception would be nice in regular Python (non-scipy). > > This works to catch NaN on OSX and Linux: > > # assuming x is a number > if x+1==x or x!=x: > #x is NaN x != x works, but: >>> x = 1e100 >>> x + 1 == x True -- http

Re: python rounding problem.

2006-05-09 Thread Dan Bishop
Grant Edwards wrote: ... > Did they actually have 60 unique number symbols and use > place-weighting in a manner similar to the arabic/indian system > we use? The Bablyonians did use a place-value system, but they only had two basic numerals: a Y-like symbol for 1 and a <-like symbol for ten. Thes

Re: python rounding problem.

2006-05-09 Thread Dan Bishop
Grant Edwards wrote: > On 2006-05-09, Dan Bishop <[EMAIL PROTECTED]> wrote: > > Grant Edwards wrote: > > ... > >> Did they actually have 60 unique number symbols and use > >> place-weighting in a manner similar to the arabic/indian system > >> we us

Re: Decimal and Exponentiation

2006-05-19 Thread Dan Bishop
Tim Peters wrote: ... > Wait <0.3 wink>. Python's Decimal module intends to be a faithful > implementation of IBM's proposed standard for decimal arithmetic: > > http://www2.hursley.ibm.com/decimal/ > > Last December, ln, log10, exp, and exponentiation to non-integral > powers were added to th

Why can't timedeltas be divided?

2006-05-24 Thread Dan Bishop
If I try to write something like: num_weeks = time_diff / datetime.timedelta(days=7) I get: TypeError: unsupported operand type(s) for /: 'datetime.timedelta' and 'datetime.timedelta' Of course, one could extend the timedelta class to implement division, def _microseconds(self):

Re: Optional code segment delimiter?

2007-12-29 Thread Dan Bishop
On Dec 29, 12:41 pm, Matt Nordhoff <[EMAIL PROTECTED]> wrote: > xkenneth wrote: > > Is it possible to use optional delimiters other than tab and colons? > > > For example: > > > if this==1 { > > print this > > } > > > > Heheheh.. Wow! I

Re: Is there a string function to trim all non-ascii characters out of a string

2007-12-31 Thread Dan Bishop
On Dec 31, 2:20 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hi, > > Is there a string function to trim all non-ascii characters out of a > string? > Let say I have a string in python (which is utf8 encoded), is there a > python function which I can convert that to a string which composed o

Re: Basic inheritance question

2008-01-06 Thread Dan Bishop
On Jan 5, 4:53 am, Bjoern Schliessmann wrote: > [EMAIL PROTECTED] wrote: > > Jeroen Ruigrok van der Werven wrote: > >> self.startLoc = start > >> self.stopLoc = stop > > > Thanks! Of course it should. Old Java habits die slowly. > > That's not really a Java habit. In Java and C++, personally I lik

Re: Reducing types

2008-02-10 Thread Dan Bishop
On Feb 10, 1:19 pm, [EMAIL PROTECTED] wrote: > For me Python is useful to write code that gives *correct* results, > allowing me to write it in a short & simple way, with quick debugging > cycles (and for other purposes, like to write dynamic code, to use it > as glue language to use libraries, to

Re: Solve a Debate

2008-02-15 Thread Dan Bishop
On Feb 15, 10:24 am, nexes <[EMAIL PROTECTED]> wrote: > Alright so me and my friend are having argument. > > Ok the problem we had been asked a while back, to do a programming > exercise (in college) > That would tell you how many days there are in a month given a > specific month. > > Ok I did my

<    1   2   3   >