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 until you're

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 promote the results of integer arithmetic to long if necessary, so

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: 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. Ok so

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'?

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', 'a2']

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 if I

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 a bad

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() --- In both

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: snip 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 would also Python

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) if 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 the

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 call a private base method? I

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: 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: 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 in the first case, and 0.0

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 Python? def

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 unsigned is negative it

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 one number space another number 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: 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 that as:

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 object. A

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 I use the cmp()

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 value.

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 result?

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 makes the /

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 parameter:f2(2)

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 but I

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. --

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 = map(operator.add, a, b)

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 ISO weeks

Re: Maths error

2007-01-08 Thread Dan Bishop
On Jan 8, 3:30 pm, Rory Campbell-Lange [EMAIL PROTECTED] wrote: (1.0/10.0) + (2.0/10.0) + (3.0/10.0) 0.60009 6.0/10.0 0.59998 Is using the decimal module the best way around this? (I'm expecting the first sum to match the second). Probably not. Decimal

Re: Dividing integers...Convert to float first?

2007-01-05 Thread Dan Bishop
On Jan 5, 11:47 am, Thomas Ploch [EMAIL PROTECTED] wrote: Jonathan Smith schrieb: Thomas Ploch wrote: [EMAIL PROTECTED] schrieb: I'm still pretty new to Python. I'm writing a function that accepts thre integers as arguments. I need to divide the first integer by te second integer, and

Re: pow() works but sqrt() not!?

2007-01-04 Thread Dan Bishop
On Jan 4, 10:00 am, siggi [EMAIL PROTECTED] wrote: Thanks for that, too! Would be interesting to learn how these different algorithms [for pow] influence the precision of the result!? For an integer (i.e., int or long) x and a nonnegative integer y, x**y is exact: 101 ** 12

Re: What is proper way to require a method to be overridden?

2007-01-04 Thread Dan Bishop
On Jan 4, 11:57 pm, belinda thom [EMAIL PROTECTED] wrote: ... So, back to my question: is a catalog of standard python errors available? I've looked on the python site but had no success. [name for name in dir(__builtins__) if name.endswith('Error')] ['ArithmeticError', 'AssertionError',

Re: Iterate through list two items at a time

2007-01-02 Thread Dan Bishop
On Jan 2, 7:57 pm, Dave Dean [EMAIL PROTECTED] wrote: Hi all, I'm looking for a way to iterate through a list, two (or more) items at a time. Basically... myList = [1,2,3,4,5,6] I'd like to be able to pull out two items at a time... def pair_list(list_): return [list_[i:i+2] for i

Re: Fall of Roman Empire

2006-12-24 Thread Dan Bishop
Dec 20, 10:36 am, Felix Benner [EMAIL PROTECTED] wrote: static int main(int argc, char **argv) { char *god_name; if (argc) god_name = argv[1]; else god_name = YHWH; metaPower God = getGodByName(god_name); universe

Re: automatically grading small programming assignments

2006-12-14 Thread Dan Bishop
On Dec 14, 8:36 pm, Brian Blais [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Then on your PC you can run a script that loads each of such programs, and runs a good series of tests, to test their quality... What happens if someone-- perhaps not even someone

Re: Dive Into Java?

2006-10-09 Thread Dan Bishop
On Oct 9, 11:40 am, Bjoern Schliessmann [EMAIL PROTECTED] wrote: Diez B. Roggisch wrote: ... because [Java] wanted to be new and good but took over much of C++'s syntax and made it even weirder, Even weirder? Care to explain?Example: int spam = 5; but String eggs = new String(); The

Re: Automatic import PEP

2006-10-06 Thread Dan Bishop
On Sep 22, 10:09 pm, Connelly Barnes [EMAIL PROTECTED] wrote: Hi, I wrote the 'autoimp' module [1], which allows you to import lazy modules: from autoimp import * (Import lazy wrapper objects around all modules; lazy modules will turn into normal modules when

Re: printing variables

2006-10-05 Thread Dan Bishop
On Oct 5, 9:47 pm, [EMAIL PROTECTED] wrote: hi say i have variables like these var1 = blah var2 = blahblah var3 = blahblahblah var4 = var5 = . bcos all the variable names start with var, is there a way to conveniently print those variables out... eg print var* ?? i don't want

Re: Hands on Documentation for Python methods and Library

2006-10-04 Thread Dan Bishop
On Oct 4, 11:54 pm, Wijaya Edward [EMAIL PROTECTED] wrote: Hi, One can do the following with Perl $ perldoc -f chomp $ perldoc -f function_name or $ perldoc List::MoreUtils $ perldoc Some::Module Can we do the same thing in Python? You can use the help() function at the Python

Re: Resuming a program's execution after correcting error

2006-09-28 Thread Dan Bishop
Sheldon wrote: Hi. Does anyone know if one can resume a python script at the error point after the error is corrected? I have a large program that take forever if I have to restart from scratch everytime. The error was the data writing a file so it seemed such a waste if all the data was

Re: does anybody earn a living programming in python?

2006-09-27 Thread Dan Bishop
Paul Boddie wrote: George Sakkis wrote: [Oslo, Norway short of 300-500 Java developers] Um, how many of these lots of Java developers looking for work live in, or are willing to relocate to, Oslo? Well, I really meant to say that the lots of Java developers I've seen actually are in

Re: A critique of cgi.escape

2006-09-26 Thread Dan Bishop
Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Fredrik Lundh wrote: Max M wrote: It also makes the escaped html harder to read for standard cases. and slows things down a bit. (cgi.escape(s, True) is slower than cgi.escape(s), for reasons that are obvious for anyone

Re: A critique of cgi.escape

2006-09-25 Thread Dan Bishop
Fredrik Lundh wrote: Jon Ribbens wrote: Making cgi.escape always escape the '' character would not break anything, and would probably fix a few bugs in existing code. Yes, those bugs are not cgi.escape's fault, but that's no reason not to be helpful. It's a minor improvement with no

Re: trouble using \ as a string

2006-08-20 Thread Dan Bishop
OriginalBrownster wrote: Hi there... I'm still pretty new to turbogears. but i have gotten pretty familiar with it i'm just trying to clear something up, i'm having a difficult time using \ when declaring a string expression such as tempname=\..it says that the line is single qouted. i

Re: what is the keyword is for?

2006-08-15 Thread Dan Bishop
Sybren Stuvel wrote [on the difference between is and ==]: Obviously a is b implies a == b, Not necessarily. a = b = 1e1000 / 1e1000 a is b True a == b False -- http://mail.python.org/mailman/listinfo/python-list

Re: what is the keyword is for?

2006-08-15 Thread Dan Bishop
Steve Holden wrote: daniel wrote: Martin v. Löwis wrote: [...] For some objects, change the object is impossible. If you have a = b = 3 then there is no way to change the object 3 to become 4 (say); integer objects are immutable. So for these, to make a change, you really have to

Re: range() is not the best way to check range?

2006-07-19 Thread Dan Bishop
Paul Boddie wrote: John Machin wrote: On 19/07/2006 1:05 AM, Dan Bishop wrote: xrange already has __contains__. As pointed out previously, xrange is a function and one would not expect it to have a __contains__ method. Well, you pointed out that range is a function, but xrange

Re: range() is not the best way to check range?

2006-07-18 Thread Dan Bishop
Paul Boddie wrote: Yes, he wants range to return an iterator, just like xrange more or less does now. Given that xrange objects support __getitem__, unlike a lot of other iterators (and, of course, generators), adding __contains__ wouldn't be much of a hardship. Certainly, compared to other

Re: range() is not the best way to check range?

2006-07-17 Thread Dan Bishop
[EMAIL PROTECTED] wrote: it seems that range() can be really slow: ... if i in range (0, 1): This creates a 10,000-element list and sequentially searches it. Of course that's gonna be slow. -- http://mail.python.org/mailman/listinfo/python-list

Re: question about what lamda does

2006-07-17 Thread Dan Bishop
[EMAIL PROTECTED] wrote: Hey there, i have been learning python for the past few months, but i can seem to get what exactly a lamda is for. It defines a function. f = lambda x, y: expression is equivalent to def f(x, y): return expression Note that lambda is an expression while def is a

Re: range() is not the best way to check range?

2006-07-17 Thread Dan Bishop
Leif K-Brooks wrote: [EMAIL PROTECTED] wrote: or is there an alternative use of range() or something similar that can be as fast? You could use xrange: [EMAIL PROTECTED]:~$ python -m timeit -n1 1 in range(1) 1 loops, best of 3: 260 usec per loop [EMAIL PROTECTED]:~$ python

Re: How to truncate/round-off decimal numbers?

2006-06-20 Thread Dan Bishop
MTD wrote: The system cannot accurately represent some integers, Er, I meant FLOATS. Doh. You were also right the first time. But it only applies to integers with more than 53 bits. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python is fun (useless social thread) ;-)

2006-06-15 Thread Dan Bishop
John Salerno wrote: So out of curiosity, I'm just wondering how everyone else came to learn [Python] I first heard about Python in the footnotes for Bruce Eckels' book Thinking in Java, which I had bought for a Java course I took in 2000. Eventually, I decided to take a look at python.org, and

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: 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 the

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. These

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 use? The Bablyonians did use a place-value system

Re: NaN handling

2006-05-06 Thread Dan Bishop
Ivan Vinogradov wrote: snip 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 --

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 a

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 IEEE

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

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 their

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 def

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 is

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 r =

Re: On Numbers

2006-01-15 Thread Dan Bishop
Alex Martelli wrote: Paul Rubin http://[EMAIL PROTECTED] wrote: Mike Meyer [EMAIL PROTECTED] writes: I'd like to work on that. The idea would be that all the numeric types are representations of reals with different properties that make them appropriate for different uses. 2+3j?

Re: Converting milliseconds to human time

2006-01-06 Thread Dan Bishop
Harlin Seritt wrote: I would like to take milliseconds and convert it to a more human-readable format like: 4 days 20 hours 10 minutes 35 seconds Is there something in the time module that can do this? I havent been able to find anything that would do it. The datetime module has something

Re: double underscore attributes?

2005-12-10 Thread Dan Bishop
[EMAIL PROTECTED] wrote: ... Every time I use dir(some module) I get a lot of attributes with double underscore, for example __add__. Ok, I thought __add__ must be a method which I can apply like this ... I tried help(5.__add__) but got SyntaxError: invalid syntax That's because the

Re: new in programing

2005-12-09 Thread Dan Bishop
Cameron Laird wrote: ... for hextuple in [(i, j, k, l, m, n) for i in range(1, lim + 1) \ for j in range (1, lim + 2) \ for k in range (1, lim + 3) \ for l in range (1, lim + 4) \ for m in range (1, lim + 5) \ for n in range (1, lim +

Re: what's wrong with lambda x : print x/60,x%60

2005-12-05 Thread Dan Bishop
[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: and, as you just found out, a rather restrictive one at that. In part because Python's designers failed to make print a function or provide an if-then-else expression.

Re: Python riddle

2005-12-05 Thread Dan Bishop
kyle.tk wrote: SPE - Stani's Python Editor wrote: I know that this code is nonsense, but why does this print 'Why?' a = 1 if a 2: try: 5/0 except: raise else: print 'why?' last time i checked this should print 'why?' I have no idea how you got it

Re: How to execute an EXE via os.system() with spaces in the directory name?

2005-12-04 Thread Dan Bishop
[EMAIL PROTECTED] wrote: I am trying to run an exe within a python script, but I'm having trouble with spaces in the directory name. ... So, it looks to me like the space in the path for the argument is causing it to fail. Does anyone have any suggestions that could help me out? Does

Re: Death to tuples!

2005-11-27 Thread Dan Bishop
Mike Meyer wrote: It seems that the distinction between tuples and lists has slowly been fading away. What we call tuple unpacking works fine with lists on either side of the assignment, and iterators on the values side. IIRC, apply used to require that the second argument be a tuple; it now

Re: (newbie) N-uples from list of lists

2005-11-23 Thread Dan Bishop
[EMAIL PROTECTED] wrote: Hello, i think it could be done by using itertools functions even if i can not see the trick. i would like to have all available n-uples from each list of lists. example for a list of 3 lists, but i should also be able to handle any numbers of items (any len(lol))

Re: user-defined operators: a very modest proposal

2005-11-22 Thread Dan Bishop
Steve R. Hastings wrote: I have been studying Python recently, and I read a comment on one web page that said something like the people using Python for heavy math really wish they could define their own operators. The specific example was to define an outer product operator for matrices.

Re: Underscores in Python numbers

2005-11-20 Thread Dan Bishop
Roy Smith wrote: Steven D'Aprano [EMAIL PROTECTED] wrote: That's a tad unfair. Dealing with numeric literals with lots of digits is a real (if not earth-shattering) human interface problem: it is hard for people to parse long numeric strings. There are plenty of ways to make numeric

Re: Floating numbers and str

2005-11-09 Thread Dan Bishop
Grant Edwards wrote: On 2005-11-09, Tuvas [EMAIL PROTECTED] wrote: I would like to limit a floating variable to 4 signifigant digits, when running thorugh a str command. Sorry, that's not possible. Technically, it is. class Float4(float): ...def __str__(self): ... return

Re: Most efficient way of storing 1024*1024 bits

2005-11-02 Thread Dan Bishop
Tor Erik Sønvisen wrote: Hi I need a time and space efficient way of storing up to 6 million bits. The most space-efficient way of storing bits is to use the bitwise operators on an array of bytes: import array class BitList(object): def __init__(self, data=None): self._data =

Re: Why the nonsense number appears?

2005-10-31 Thread Dan Bishop
Steve Horsley wrote: Ben O'Steen wrote: On Mon, October 31, 2005 10:23, Sybren Stuvel said: Ben O'Steen enlightened us with: Using decimal as opposed to float sorts out this error as floats are not built to handle the size of number used here. They can handle the size just fine. What

Re: Question About Logic In Python

2005-09-18 Thread Dan Bishop
James H. wrote: Greetings! I'm new to Python and am struggling a little with and and or logic in Python. Since Python always ends up returning a value and this is a little different from C, the language I understand best (i.e. C returns non-zero as true, and zero as false), is there anything

Re: why no arg, abs methods for comlex type?

2005-08-05 Thread Dan Bishop
Terry Reedy wrote: Daniel Schüle [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] ... unfortunately there is no arg method to get the angle of the complex number I agree that this is a deficiency. I would think .angle() should be a no-param method like .conjugate(), though its

Re: Comparison of functions

2005-07-31 Thread Dan Bishop
Steven D'Aprano wrote: On Sat, 30 Jul 2005 16:43:00 +, Adriano Varoli Piazza wrote: If you want to treat numbers as strings, why not convert them before sorting them? Because that changes the object and throws away information. I think he meant doing something like - lst = ['2+2j',

Re: consistency: extending arrays vs. multiplication ?

2005-07-23 Thread Dan Bishop
Soeren Sonnenburg wrote: Hi all, Just having started with python, I feel that simple array operations '*' and '+' don't do multiplication/addition but instead extend/join an array: a=[1,2,3] b=[4,5,6] a+b [1, 2, 3, 4, 5, 6] instead of what I would have expected: [5,7,9] To get what

Re: goto

2005-07-18 Thread Dan Bishop
rbt wrote: On Mon, 2005-07-18 at 12:27 -0600, Steven Bethard wrote: Hayri ERDENER wrote: what is the equivalent of C languages' goto statement in python? Download the goto module: http://www.entrian.com/goto/ And you can use goto to your heart's content. And to the horror of

Re: Inconsistency in hex()

2005-07-12 Thread Dan Bishop
Steven D'Aprano wrote: hex() of an int appears to return lowercase hex digits, and hex() of a long uppercase. hex(75) '0x4b' hex(75*256**4) '0x4BL' By accident or design? Apart from the aesthetic value that lowercase hex digits are ugly, should we care? It would also be nice

Re: Create datetime instance using a tuple.

2005-07-06 Thread Dan Bishop
Qiangning Hong wrote: On 6 Jul 2005 02:01:55 -0700, Negroup [EMAIL PROTECTED] wrote: Hi, all. I would like to know if it is possible to create a datetime instance using a tuple instead of single values. I mean: from datetime import datetime t = (1, 2, 3) dt = datetime(t)

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Dan Bishop
Devan L wrote: Here's a couple of examples from my own code: # from a Banzhaf Power Index calculator # adds things that aren't numbers return reduce(operator.add, (VoteDistributionTable({0: 1, v: 1}) for v in electoral_votes)) return sum([VoteDistributionTable({0:1, v:1} for v in

Re: precision problems in base conversion of rational numbers

2005-07-05 Thread Dan Bishop
Brian van den Broek wrote: Hi all, I guess it is more of a maths question than a programming one, but it involves use of the decimal module, so here goes: As a self-directed learning exercise I've been working on a script to convert numbers to arbitrary bases. It aims to take any of whole

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Dan Bishop
Devan L wrote: Claiming that sum etc. do the same job is the whimper of someone who doesn't want to openly disagree with Guido. Could you give an example where sum cannot do the job(besides the previously mentioned product situation? Here's a couple of examples from my own code: # from a

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 which should

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 diveintopython

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: 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 some

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 source of the

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) #

<    1   2   3   >