Re: Integration with java

2005-01-18 Thread Dan Bishop
Istvan Albert wrote: Joachim Boomberschloss wrote: the code is already written in Python, using the standard libraries and several extension modules One thing to keep in mind is that Jython does not integrate CPython, instead it understands python code directly. So if you have a C

Re: python/cgi/html bug

2005-01-18 Thread Dan Bishop
Dfenestr8 wrote: Hi. I've written a cgi messageboard script in python, for an irc chan I happen to frequent. Bear with me, it's hard for me to describe what the bug is. So I've divided this post into two sections: HOW MY SCRIPTS WORKS, and WHAT THE BUG IS. ... The problem is when

Re: pure python code to do modular-arithmetic unit conversions?

2005-01-21 Thread Dan Bishop
Dan Stromberg wrote: Is there already a pure python module that can do modular-arithmetic unit conversions, like converting a huge number of seconds into months, weeks... Use the divmod function. SECONDS_PER_MONTH = 2629746 # 1/4800 of 400 Gregorian years def convert_seconds(seconds):

Re: string.atoi and string.atol broken?

2005-01-25 Thread Dan Bishop
Peter Otten wrote: Mike Moum wrote: s.atoi('4',3) should result in 11 s.atoi('13',4) should result in 31 s.atoi('12',4) should result in 30 s.atoi('8',4) is legitimate, but it generates an error. Is this a bug, or am I missing something obvious? You and atoi() seem to

Re: Converting strings to dates

2005-02-04 Thread Dan Bishop
Chermside, Michael wrote: I'm trying to convert a string back into a datetime.date. First I'll create the string: Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import time, datetime a_date =

Re: Questions about mathematical signs...

2005-02-06 Thread Dan Bishop
Jeff Epler wrote: On Sun, Feb 06, 2005 at 12:26:30PM -0800, administrata wrote: Hi! I'm programming maths programs. And I got some questions about mathematical signs. ... 2. Inputing fractions like (a / b) + (c / d), It's tiring work too. Can it be simplified? Because of the rules of

Re: negative integer division

2005-02-08 Thread Dan Bishop
Mark Jackson wrote: Imbaud Pierre [EMAIL PROTECTED] writes: integer division and modulo gives different results in c and python, when negative numbers are involved. take gdb as a widely available c interpreter print -2 /3 0 for c, -1 for python. more amazing, modulos of negative

Re: goto, cls, wait commands

2005-02-11 Thread Dan Bishop
Harlin wrote: No goto needed. If this makes no sense (which it may not if all you've been exposed to is BASIC) it wouldn't be a bad idea to Google why you should never use a goto statement. GOTO isn't even needed in QBasic (except for ON ERROR GOTO). --

Re: Python in Makefile Question

2005-02-11 Thread Dan Bishop
Efrat Regev wrote: Hello, I'd like to ask a question concerning a python script in a makefile. Suppose I have a C++ project (sorry for raising this in a Python newsgroup), with some makefile for it. Before compiling the code, I'd like to check that there are no C++ convention violations

Re: check if object is number

2005-02-11 Thread Dan Bishop
Steven Bethard wrote: Is there a good way to determine if an object is a numeric type? Generally, I avoid type-checks in favor of try/except blocks, but I'm not sure what to do in this case: def f(i): ... if x i: ... The problem is, no error will be

Re: For American numbers

2005-02-13 Thread Dan Bishop
Nick Craig-Wood wrote: Peter Hansen [EMAIL PROTECTED] wrote: Only for hard drive manufacturers, perhaps. For the rest of the computer world, unless I've missed a changing of the guard or something, kilo is 1024 and mega is 1024*1024 and so forth... Yes. Unless you work in the

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: 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: 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: 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: 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: (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: 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: Python-Help ( Mean,Median Mode)

2004-12-05 Thread Dan Bishop
Alfred Canoy [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]... Hello, I revised my source code. It was doing great but I'm having problem listing all the numbers that I'd input. How can I input all the numbers that I selected? The source code and the output below:

Re: results of division

2004-12-09 Thread Dan Bishop
Brad Tilley wrote: Hello, What is the proper way to limit the results of division to only a few spaces after the decimal? I don't need rocket-science like precision. Here's an example: If your only complaint is that it's ugly to display 17 digits, then use the % operator to display however

Re: BASIC vs Python

2004-12-17 Thread Dan Bishop
Peter Otten wrote: Peter Hickman wrote: Mike Meyer wrote: BASIC as implented by Microsoft for the Apple II and the TRS 80 (among others) is simply the worst programming language I have ever encountered. Assembler was better - at least you had recursion with assembler. Basic has

Re: while 1 vs while True

2004-12-12 Thread Dan Bishop
Timothy Fitz wrote: [ http://www.python.org/moin/PythonSpeed ] Starting with Py2.3, the interpreter optimizes 'while 1' to just a single jump. In contrast while True takes several more steps. While the latter is preferred for clarity, time-critical code should use the first form. Out of

Re: newbie question

2004-12-19 Thread Dan Bishop
David Wurmfeld wrote: I am new to python; any insight on the following would be appreciated, even if it is the admonition to RTFM (as long as you can direct me to a relevant FM) http://www.python.org/doc/ Is there a standard approach to enumerated types? I could create a dictionary with a

Re: A rational proposal

2004-12-20 Thread Dan Bishop
Mike Meyer wrote: John Roth [EMAIL PROTECTED] writes: Mike Meyer [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] PEP: XXX Title: A rational number module for Python ... Rationals will mix with all other numeric types. When combined with an integer type, that integer will

Re: list Integer indexing dies??

2004-12-23 Thread Dan Bishop
Jeff Shannon wrote: Ishwor wrote: On Thu, 23 Dec 2004 13:33:16 -0300, Batista, Facundo [EMAIL PROTECTED] wrote: [Ishwor] #- What should 035[0] cough up? Be carefull it should #- #- 035[0] #- 3 # my own opinion. why 3? The reason we get 3 and not 0 here is the *fact* that

Re: String backslash characters

2004-12-23 Thread Dan Bishop
PD wrote: Hello, I am new to python, but i am quite curious about the following. suppose you had print '\378' which should not work because \377 is the max. then it displays two characters (an 8 and a heart in my case...). What else does'nt quite make sense is that if this is an octal

Re: A Revised Rational Proposal

2004-12-26 Thread Dan Bishop
Mike Meyer wrote: This version includes the input from various and sundry people. Thanks to everyone who contributed. mike PEP: XXX Title: A rational number module for Python ... Implicit Construction - When combined with a floating type - either complex or float

Re: A Revised Rational Proposal

2004-12-26 Thread Dan Bishop
Mike Meyer wrote: This version includes the input from various and sundry people. Thanks to everyone who contributed. mike PEP: XXX Title: A rational number module for Python ... Implementation == There is currently a rational module distributed with Python, and a

Re: A Revised Rational Proposal

2004-12-26 Thread Dan Bishop
Dan Bishop wrote: Mike Meyer wrote: This version includes the input from various and sundry people. Thanks to everyone who contributed. mike PEP: XXX Title: A rational number module for Python ... Implementation == There is currently a rational module

Re: A Revised Rational Proposal

2004-12-26 Thread Dan Bishop
Steven Bethard wrote: Dan Bishop wrote: Mike Meyer wrote: PEP: XXX I'll be the first to volunteer an implementation. Very cool. Thanks for the quick work! For stdlib acceptance, I'd suggest a few cosmetic changes: No problem. Implementation of rational arithmetic. from

Re: Calling Function Without Parentheses!

2005-01-02 Thread Dan Bishop
Kamilche wrote: What a debug nightmare! I just spent HOURS running my script through the debugger, sprinkling in log statements, and the like, tracking down my problem. I called a function without the ending parentheses. I sure do WISH Python would trap it when I try to do the following:

Re: else condition in list comprehension

2005-01-09 Thread Dan Bishop
Luis M. Gonzalez wrote: Hi there, I'd like to know if there is a way to add and else condition into a list comprehension. I'm sure that I read somewhere an easy way to do it, but I forgot it and now I can't find it... for example: z=[i+2 for i in range(10) if i%2==0] what if I want i

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

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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: rounding problem

2005-02-23 Thread Dan Bishop
tom wrote: On Wed, 23 Feb 2005 19:04:47 -0600, Andy Leszczynski wrote: It is on Windows, Linux, Python 2.3: [GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2 Type help, copyright, credits or license for more information. a=1.1 a 1.1001 ... Is it normal?

Re: function with a state

2005-03-09 Thread Dan Bishop
[EMAIL PROTECTED] wrote: Xah Lee [EMAIL PROTECTED] wrote: is it possible in Python to create a function that maintains a variable value? Yes. There's no concept of a 'static' function variable as such, but there are many other ways to achieve the same thing. globe=0; def myFun():

Re: Why is lower() deprecated and how should I replace it?

2005-03-13 Thread Dan Bishop
gf gf wrote: I read that lower() is deprecated. Unfortunately, I can't find the preferred way of lowercasing a string. What is it? Instead of string.lower(s), use s.lower() -- http://mail.python.org/mailman/listinfo/python-list

Re: Python scope is too complicated

2005-03-20 Thread Dan Bishop
jfj wrote: Max wrote: Yeah, I know. It's the price we pay for forsaking variable declarations. But for java programmers like me, Py's scoping is too complicated. Please explain what constitutes a block/namespace, and how to refer to variables outside of it. Some may disagree, but for

Re: html tags and python

2005-03-25 Thread Dan Bishop
Kane wrote: If I understand what you are asking then Python CGI are a poor solution. It would be easy to have one page ask for the month, click submit, then have a second page ask for the exact date. Easy; but terrible design. An improvement is to just have the dropdown listbox go from 1

Re: tree data structure

2005-03-25 Thread Dan Bishop
vivek khurana wrote: Hi! all i am a new member on this list. I have to implement tree data structure using python. How it can be done in python. Is there an existing data structure which can be used as tree? Tuples can be used as trees: you can let them represent (data, left_child,

Re: Little Q: how to print a variable's name, not its value?

2005-03-28 Thread Dan Bishop
[EMAIL PROTECTED] wrote: No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two vars, along with their names. I could easily do this: print myPlace = %s,

Re: Combining digit in a list to make an integer

2005-04-01 Thread Dan Bishop
Harlin Seritt wrote: I have the following: num1 = ['1', '4', '5'] How can I combine the elements in num1 to produce an integer 145? int(''.join(num1)) -- http://mail.python.org/mailman/listinfo/python-list

Re: Combining digit in a list to make an integer

2005-04-01 Thread Dan Bishop
Harlin Seritt wrote: If anyone has time, would you mind explaining the code that Dan Bishop was so kind as to point out to me: int(''.join(num1)) This worked perfectly for me, however, I'm not sure that I understand it very well. join(...) S.join(sequence) - string Return a string

Re: string goes away

2005-04-03 Thread Dan Bishop
John J. Lee wrote: Duncan Booth [EMAIL PROTECTED] writes: [...] str.join(sep, list_of_str) [...] Doesn't work with unicode, IIRC. u .join([What's, the, problem?]) uWhat's the problem? -- http://mail.python.org/mailman/listinfo/python-list

Re: sorting a list and counting interchanges

2005-04-06 Thread Dan Bishop
Paul Rubin wrote: John Machin [EMAIL PROTECTED] writes: ... 3. Of what practical use (or even esoteric academic interest) is the parity of the number of interchanges? It is of considerable interest in combinatorics. The group of even permutations on N elements is called the alternating

Re: curious problem with large numbers

2005-04-08 Thread Dan Bishop
Chris Fonnesbeck wrote: I have been developing a python module for Markov chain Monte Carlo estimation, in which I frequently compare variable values with a very large number, that I arbitrarily define as: inf = 1e1 Don't forget that you can write your own Infinity. (Warning: Buggy

Re: Compute pi to base 12 using Python?

2005-04-13 Thread Dan Bishop
Dick Moores wrote: I need to figure out how to compute pi to base 12, to as many digits as possible. I found this reference, http://mathworld.wolfram.com/Base.html, but I really don't understand it well enough. How many stars are in *? You probably answered 25. This

Re: Compute pi to base 12 using Python?

2005-04-13 Thread Dan Bishop
Dick Moores wrote: Dan Bishop wrote at 04:07 4/13/2005: ... For a floating-point number x, the representation with d decimal places count be found by taking the representation of int(round(x * radix ** d)) and inserting a . d places from the right. But I'm sorry, but I can't follow you. I do

Re: Compute pi to base 12 using Python?

2005-04-13 Thread Dan Bishop
Scott David Daniels wrote: Roy Smith wrote: In article [EMAIL PROTECTED], Dan Bishop [EMAIL PROTECTED] wrote: But there's no reason other than tradition why you should arrange them into groups of 10. Well, it is traditional for people to have 10 fingers :-) Other fun things

Re: trouble using \ to escape %

2005-04-15 Thread Dan Bishop
Lucas Machado wrote: I'm writing a python script that modifies the smb.conf file, and i need to write the characters '%U' in the file. I tried making a string like so: str1 = [%s%s]\n\tpath = /mnt/samba/%s%s/\%U % (list[0], list[1], list[0], list[1]) but i keep getting: TypeError: not

Re: Why Python does *SLICING* the way it does??

2005-04-21 Thread Dan Bishop
[EMAIL PROTECTED] wrote: What languages besides Python use the Python slicing convention? Java uses it for the substring method of strings. In C starting at 0 may be justified because of the connection between array subscripting and pointer arithmetic, but Python is a higher-level language

Re: Why Python does *SLICING* the way it does??

2005-04-21 Thread Dan Bishop
Antoon Pardon wrote: Op 2005-04-21, Steve Holden schreef [EMAIL PROTECTED]: [EMAIL PROTECTED] wrote: ... Along the same lines, I think the REQUIREMENT that x[0] rather than x[1] be the first element of list x is a mistake. At least the programmer should have a choice, as in Fortran or

Re: Variables

2005-04-23 Thread Dan Bishop
Richard Blackwood wrote: Steven Bethard wrote: Richard Blackwood wrote: Indeed, this language is math. My friend says that foo is a constant and necessarily not a variable. If I had written foo = raw_input(), he would say that foo is a variable. Then what does he say if you

Re: creating very small types

2005-04-27 Thread Dan Bishop
Michael Spencer wrote: andrea wrote: I was thinking to code the huffman algorithm and trying to compress something with it, but I've got a problem. How can I represent for example a char with only 3 bits?? I had a look to the compression modules but I can't understand them much... ... I

Re: Python Challenge ahead [NEW] for riddle lovers

2005-04-30 Thread Dan Bishop
darren kirby wrote: quoth the Shane Hathaway: 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

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

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-01 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. You are invited to take part in it at: http://www.pythonchallenge.com

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-03 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 PROTECTED] writes: There's no level 12 yet though. Now there's a 12 and a 13

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-04 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 link to an

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 it too,

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

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

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, D : lambda x:

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.3.4 (#12,

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: (1) All

Re: Python Args By Reference

2005-05-11 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 up on

Re: windows directories for curr user

2005-05-11 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? path =

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(ä, a) UnicodeDecodeError:

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

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 like this

Re: Floating point bug?

2008-02-16 Thread Dan Bishop
On Feb 14, 8:10 pm, Zentrader [EMAIL PROTECTED] wrote: That's a misconception. The decimal-module has a different base (10 instead of 2), and higher precision. But that doesn't change the fact that it will expose the same rounding-errors as floats do - just for different numbers.

Re: Critique of first python code

2008-02-16 Thread Dan Bishop
On Feb 8, 7:30 pm, Zack [EMAIL PROTECTED] wrote: [snip] The generators you show here are interesting, and it prodded me on how to add tuples but at the moment (I'm a python newbie) the generator seems less readable to me than the alternative. After some input from Scott David Daniels I

Re: How about adding rational fraction to Python?

2008-02-27 Thread Dan Bishop
On Feb 26, 11:21 pm, Mark Dickinson [EMAIL PROTECTED] wrote: On Feb 26, 11:55 pm, Paul Rubin http://[EMAIL PROTECTED] wrote: So use: return sum(number_list) / float(len(number_list)) That makes it somewhat more explicit what you want. Otherwise But that fails for a list of Decimals...

Re: call by reference howto????

2008-02-27 Thread Dan Bishop
On Feb 27, 6:02 pm, Tamer Higazi [EMAIL PROTECTED] wrote: Hi! Can somebody of you make me a sample how to define a function based on call by reference ??? I am a python newbie and I am not getting smart how to define functions, that should modify the variable I passed by reference. You

  1   2   3   >