Re: integer and string compare, is that correct?

2010-01-10 Thread Dan Bishop
On Jan 10, 10:34 am, Nobody nob...@nowhere.com wrote: Hellmut Weber wrote: being a causal python user (who likes the language quite a lot) it took me a while to realize the following:   max = '5'   n = 5   n = max False Section 5.9 Comparison describes this. Can someone give me

Re: Converting a float to a formatted outside of print command

2009-11-23 Thread Dan Bishop
On Nov 23, 3:15 pm, stephen_b redplusbluemakespur...@gmail.com wrote: I'd like to convert a list of floats to formatted strings. The following example raises a TypeError: y = 0.5 x = '.1f' % y You meant: x = '%.1f' % y -- http://mail.python.org/mailman/listinfo/python-list

Re: 3.x and 2.x on same machine (is this info at Python.org??)

2009-11-12 Thread Dan Bishop
On Nov 12, 1:52 pm, rantingrick rantingr...@gmail.com wrote: Hello, Currently i am using 2.6 on Windows and need to start writing code in 3.0. I cannot leave 2.x yet because 3rd party modules are still not converted. So i want to install 3.0 without disturbing my current Python2.x. What i'm

Re: My own accounting python euler problem

2009-11-08 Thread Dan Bishop
On Nov 8, 4:43 am, Ozz notva...@wathever.com wrote: Hi, My first question is: 1. given a list of invoives I=[500, 400, 450, 200, 600, 700] and a check Ch=600 how can I print all the different combinations of invoices that the check is possibly cancelling Incidentally, I'm currently

Re: Pythonic list/tuple/dict layout?

2009-01-25 Thread Dan Bishop
On Jan 25, 2:18 am, Akira Kitada akit...@gmail.com wrote: Hi, There is more than one way to write a list/tuple/dict in Python, and actually different styles are used in standard library. As a hobgoblin of little minds, I rather like to know which style is considered Pythonic in the

Re: PySqlite - division of real numbers without decimal fractions

2008-11-06 Thread Dan Bishop
On Nov 6, 3:46 pm, Astley Le Jasper [EMAIL PROTECTED] wrote: I've been getting errors recently when using pysqlite. I've declared the table columns as real numbers to 2 decimal places (I'm dealing with money), but when doing division on two numbers that happen to have no decimal fractions, the

Re: Anyone in the Houston / College Station / Austin area? Looking to do some sprints / joint projects.

2008-11-02 Thread Dan Bishop
On Nov 1, 10:35 pm, xkenneth [EMAIL PROTECTED] wrote: All,    I'm in Houston/College Station/Austin quite often and I'm looking for other coders to do some joint projects with, share experiences, or do some sprints. Let me know if you're interested. Regards, Ken I live in Houston. What

Re: why in returns values for array and keys for dictionary

2008-08-25 Thread Dan Bishop
On Aug 25, 9:57 pm, alex23 [EMAIL PROTECTED] wrote: On Aug 26, 10:49 am, ++imanshu [EMAIL PROTECTED] wrote:     Wouldn't it be nicer to have 'in' return values (or keys) for both arrays and dictionaries. Arrays and Dictionaries looked so similar in Python until I learned this difference.

Re: How to make xss safe strings

2008-08-20 Thread Dan Bishop
On Aug 20, 10:10 pm, Roopesh [EMAIL PROTECTED] wrote: Hi, How can I make a string XSS safe? Will simply .replace('','lt;').replace('','gt;') do the work? Or are there some other issues to take into account?. Is there already a function in python which will do this for me. For HTML, use

Re: random numbers according to user defined distribution ??

2008-08-06 Thread Dan Bishop
On Aug 6, 8:26 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Wed, 06 Aug 2008 15:02:37 -0700, Alex wrote: Hi everybody, I wonder if it is possible in python to produce random numbers according to a user defined distribution? Unfortunately the random module does not

Re: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Dan Bishop
On Aug 3, 9:02 am, CNiall [EMAIL PROTECTED] wrote: I am very new to Python (I started learning it just yesterday), but I have encountered a problem. I want to make a simple script that calculates the n-th root of a given number (e.g. 4th root of 625--obviously five, but it's just an example

Re: Odd math related issue.

2008-07-21 Thread Dan Bishop
On Jul 21, 3:52 am, Fredrik Lundh [EMAIL PROTECTED] wrote: Robert Rawlins wrote: I’ve got what seems to me to be a totally illogical math issue here which I can’t figure out. Take a look at the following code:         /self/.__logger.info(/%i / %i/ % (bytes_transferred,

Re: Cyclic imports

2008-06-26 Thread Dan Bishop
On Jun 26, 10:40 pm, James [EMAIL PROTECTED] wrote: Hi all, I'm looking for some advice dealing with cyclic, cross-package imports. I've created the following demo file structure: ./a/__init__.py ./a/a.py ./b/__init__.py ./b/b.py ./main.py a.py imports a class from b.py and vice versa,

Re: newb question on strings

2008-06-24 Thread Dan Bishop
On Jun 24, 4:04 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Are you trying to escape for a regular expression? Just do re.escape(). print re.escape('Happy') Happy print re.escape(Frank's Diner) Frank\'s\ Diner If you're escaping for URLs, there's urllib2.quote(), for a command

Re: Weird local variables behaviors

2008-06-20 Thread Dan Bishop
On Jun 20, 7:32 pm, Matt Nordhoff [EMAIL PROTECTED] wrote: Sebastjan Trepca wrote: Hey, can someone please explain this behavior: The code: def test1(value=1):     def inner():         print value     inner() def test2(value=2):     def inner():         value = value    

Re: At long last...

2008-06-19 Thread Dan Bishop
On Jun 19, 9:24 pm, Carl Banks [EMAIL PROTECTED] wrote: On Jun 19, 10:17 pm, Terry Reedy [EMAIL PROTECTED] wrote: Carl Banks wrote: Tuples will have an index method in Python 2.6. I promise I won't indiscriminately use tuples for homogenous data. Honest.  Scout's honor.  Cross my

Re: advanced listcomprehenions?

2008-06-18 Thread Dan Bishop
On Jun 18, 4:42 pm, cirfu [EMAIL PROTECTED] wrote: I am wondering if it is possible to write advanced listcomprehensions. For example: Write a program that prints the numbers from 1 to 100. But for multiples of three print Fizz instead of the number and for the multiples of five print Buzz.

Re: Does '!=' equivelent to 'is not'

2008-06-16 Thread Dan Bishop
On Jun 16, 10:29 pm, pirata [EMAIL PROTECTED] wrote: I'm a bit confusing about whether is not equivelent to != if a != b:   ... if a is not b:   ... What's the difference between is not and != or they are the same thing? is not is the logical negation of the is operator, while != is the

Re: numpy: handling float('NaN') different in XP vs. Linux

2008-06-13 Thread Dan Bishop
On Jun 13, 10:45 pm, John [H2O] [EMAIL PROTECTED] wrote: I have a script: from numpy import float OutD=[] v=['3','43','23.4','NaN','43'] OutD.append([float(i) for i in v[1]]) On linux: Python 2.5.1 (r251:54863, Mar  7 2008, 04:10:12) [GCC 4.1.3 20070929 (prerelease) (Ubuntu

Re: PEP on breaking outer loops with StopIteration

2008-06-09 Thread Dan Bishop
On Jun 9, 8:07 pm, Kris Kowal [EMAIL PROTECTED] wrote: I had a thought that might be pepworthy.  Might we be able to break outer loops using an iter-instance specific StopIteration type? This is the desired, if not desirable, syntax::     import string     letters = iter(string.lowercase)  

Re: line continuation for lines ending in and or or

2008-06-04 Thread Dan Bishop
On Jun 4, 10:09 pm, Russ P. [EMAIL PROTECTED] wrote: I've always appreciated Python's lack of requirement for a semi-colon at the end of each line. I also appreciate its rules for automatic line continuation. If a statement ends with a +, for example, Python recognizes that the statement

Re: decorators when?

2008-05-28 Thread Dan Bishop
On May 27, 7:32 pm, Kam-Hung Soh [EMAIL PROTECTED] wrote: David C. Ullrich wrote: What version added decorators (using the @decorator syntax)? (Is there a general way I could have found out the answer myself?) Is there a somthing such that from __future__ import something will make

Re: Hungarian Notation

2008-05-27 Thread Dan Bishop
On May 27, 12:28 am, inhahe [EMAIL PROTECTED] wrote: Does anybody know of a list for canonical prefixes to use for hungarian notation in Python?  Not that I plan to name all my variables with hungarian notation, but just for when it's appropriate. pnWe vUse adjHungarian nNotation prepAt nWork,

Re: related to python

2008-05-21 Thread Dan Bishop
On May 21, 9:34 pm, salil_reeves [EMAIL PROTECTED] wrote: develop a function called standardise_phrase to convert the user's input to a standard form for subsequent processing. This involves: 1. removing all inter-word punctuation, which for our purposes is assumed to consist only of commas

Re: related to python

2008-05-21 Thread Dan Bishop
On May 21, 9:34 pm, salil_reeves [EMAIL PROTECTED] wrote: develop a function called standardise_phrase to convert the user's input to a standard form for subsequent processing. This involves: 1. removing all inter-word punctuation, which for our purposes is assumed to consist only of commas

Re: Struct usage and varying sizes of h, l, etc

2008-05-20 Thread Dan Bishop
On May 20, 5:59 pm, Robert Kern [EMAIL PROTECTED] wrote: Ethan Furman wrote: Greetings, I'm looking at the struct module for binary packing of ints and floats.   The documentation refers to C datatypes.  It's been many years since I looked at C, but I seem to remember that the data type

Re: Keeping two lists aligned after processing

2008-05-11 Thread Dan Bishop
On May 11, 1:22 am, philly_bob [EMAIL PROTECTED] wrote: I have a population of five algorithms. Each Alg has a method, Alg.accuracy(), which calculates its accuracy. Running the accuracy method on each Alg, I end up with a list of accuracies like [0.75, 0.10, 0.45, 0.80, 0.45] Now I want to

Re: Mathematics in Python are not correct

2008-05-08 Thread Dan Bishop
On May 8, 6:14 pm, Luis Zarrabeitia [EMAIL PROTECTED] wrote: On Thursday 08 May 2008 06:54:42 pm [EMAIL PROTECTED] wrote: The problem is that Python parses -123**0 as -(123**0), not as (-123)**0. Actually, I've always written it as (-123)**0. At least where I'm from, exponentiation takes

Re: How can I add spaces where ever I have capital letters?

2008-05-08 Thread Dan Bishop
On Thu, May 8, 2008 at 9:12 PM, John Schroeder [EMAIL PROTECTED] wrote: I have a string (which I got from the names of my classes) and I would like to print out my CamelCase classes as titles. I would like it to do this: my_class_name = ModeCommand ## Do some magic here

Re: range with variable leading zeros

2008-05-08 Thread Dan Bishop
On May 8, 10:42 pm, yhvh [EMAIL PROTECTED] wrote: I want to generate a range with variable leading zeros x = [0010, 0210] You do realize that this is octal, right? padding = len(x[1]) len is undefined for integers. Perhaps you meant len(str(x[1])). for j in range(x[0], x[1]):     print

Re: We have string.isdigit(), why not string.isNumber()?

2008-04-30 Thread Dan Bishop
On Apr 30, 7:56 pm, MooMaster [EMAIL PROTECTED] wrote: N00b question alert! I did a search for isdigit() in the group discussion, and it didn't look like the question had been asked in the first 2 pages, so sorry if it was... The manual documentation says: isdigit( ) Return true if all

Re: A small and very basic python question

2008-04-27 Thread Dan Bishop
On Apr 27, 5:26 pm, Dennis [EMAIL PROTECTED] wrote: Dennis wrote: Could anyone tell me how this line of code is working: filter(lambda x: x in string.letters, text) I understand that it's filtering the contents of the variable text and I know that lambda is a kind of embedded function.

Re: How do I say Is this a function?

2008-04-26 Thread Dan Bishop
On Apr 26, 6:17 pm, John Henry [EMAIL PROTECTED] wrote: How do I determine is something a function? For instance, I don't want to relying on exceptions below: def f1(): print In f1 def f3(): print In f3 def others(): print In others for i in xrange(1,3): fct =

Re: Is 2006 too old for a book on Python?

2008-04-25 Thread Dan Bishop
On Apr 25, 8:16 am, jmDesktop [EMAIL PROTECTED] wrote: Hi, I wanted to buy a book on Python, but am concerned that some of them are too old. One I had come to after much research was Core Python by Wesley Chun. I looked at many others, but actually saw this one in the store and liked it.

Re: Curious relation

2008-04-23 Thread Dan Bishop
On Apr 23, 11:51 pm, Greg J [EMAIL PROTECTED] wrote: I was reading the programming Reddit tonight and came across this (http://reddit.com/info/6gwk1/comments/): ([1]2)==True True [1](2==True) True [1]2==True False Odd, no? So, can anyone here shed light on this one? A long time

Re: Explicit variable declaration

2008-04-22 Thread Dan Bishop
On Apr 22, 7:39 pm, Filip Gruszczyński [EMAIL PROTECTED] wrote: Hello everyone! It is my first message on this list, therefore I would like to say hello to everyone. I am fourth year student of CS on the Univeristy of Warsaw and recently I have become very interested in dynamically typed

Re: Java or C++?

2008-04-21 Thread Dan Bishop
On Apr 21, 5:26 pm, Jorgen Grahn [EMAIL PROTECTED] wrote: On Mon, 21 Apr 2008 06:14:08 -0700 (PDT), NickC [EMAIL PROTECTED] wrote: On Apr 15, 1:46 pm, Brian Vanderburg II [EMAIL PROTECTED] wrote: This will automatically call the constructors of any contained objects to initialize the

Re: Alternate indent proposal for python 3000

2008-04-21 Thread Dan Bishop
On Apr 21, 4:01 am, Paul Boddie [EMAIL PROTECTED] wrote: On 21 Apr, 00:54, Dan Bishop [EMAIL PROTECTED] wrote: We wouldn't even need that. Just a new source encoding. Then we could write: # -*- coding: end-block -*- [...] Someone at EuroPython 2007 did a lightning talk showing

Re: Checking if a text file is blank

2008-04-20 Thread Dan Bishop
On Apr 20, 1:04 am, [EMAIL PROTECTED] wrote: Greetings! I've just started learning python, so this is probably one of those obvious questions newbies ask. Is there any way in python to check if a text file is blank? What I've tried to do so far is: f = file(friends.txt,

Re: Alternate indent proposal for python 3000

2008-04-20 Thread Dan Bishop
On Apr 20, 11:42 am, Matthew Woodcraft [EMAIL PROTECTED] wrote: Christian Heimes [EMAIL PROTECTED] wrote: I feel that including some optional means to block code would be a big step in getting wider adoption of the language in web development and in general. I do understand though, that

Re: how to remove \n in the list

2008-04-14 Thread Dan Bishop
On Apr 14, 10:55 pm, Yves Dorfsman [EMAIL PROTECTED] wrote: Gabriel Genellina wrote: En Mon, 14 Apr 2008 01:41:55 -0300, reetesh nigam l=['5\n', '2\n', '7\n', '3\n', '6\n'] how to remove \n from the given list l is is very poor name... I'll use lines instead: lines[:] =

Re: about the ';'

2008-04-13 Thread Dan Bishop
On Apr 13, 10:33 pm, Penny Y. [EMAIL PROTECTED] wrote: I saw many python programmers add a ';' at the end of each line. As good style, should or should not we do coding with that? That's just because their fingers are stuck in C mode. The recommended style is NOT to use unnecessary semicolons.

Re: str(bytes) in Python 3.0

2008-04-12 Thread Dan Bishop
On Apr 12, 9:29 am, Carl Banks [EMAIL PROTECTED] wrote: On Apr 12, 10:06 am, Kay Schluehr [EMAIL PROTECTED] wrote: On 12 Apr., 14:44, Christian Heimes [EMAIL PROTECTED] wrote: Gabriel Genellina schrieb: On the last line, str(x), I would expect 'abc' - same as str(x, 'ascii')

Re: Recommended from __future__ import options for Python 2.5.2?

2008-04-12 Thread Dan Bishop
On Apr 12, 1:41 pm, Malcolm Greene [EMAIL PROTECTED] wrote: Is there any consensus on what from __future__ import options developers should be using in their Python 2.5.2 applications? Is there a consolidated list of from __future__ import options to choose from? Just look inside the

Re: text adventure game problem

2008-04-08 Thread Dan Bishop
On Apr 8, 8:01 pm, [EMAIL PROTECTED] wrote: okay, I'm having this one problem with a text adventure game. It's kind of hard to explain, but I'll do my best. [code] def prompt_kitchen(): global gold gold_taken = False while True: prompt_kit = raw_input('') if

Re: Newbie: How to pass a dictionary to a function?

2008-04-07 Thread Dan Bishop
On Apr 7, 10:54 pm, BonusOnus [EMAIL PROTECTED] wrote: How do I pass a dictionary to a function as an argument? The same way you pass any other argument. # Say I have a function foo... def foo (arg=[]): It's generally a bad idea to use [] as a default argument. x = arg['name'] y =

Re: id functions of ints, floats and strings

2008-04-05 Thread Dan Bishop
On Apr 5, 9:30 pm, Steve Holden [EMAIL PROTECTED] wrote: In fact all you can in truth say is that a is b -- a == b You can't even guarantee that. inf = 1e1000 nan = inf / inf nan is nan True nan == nan False -- http://mail.python.org/mailman/listinfo/python-list

Re: sine in python

2008-04-03 Thread Dan Bishop
On Apr 3, 6:09 pm, [EMAIL PROTECTED] wrote: On Apr 3, 11:58 pm, Astan Chee [EMAIL PROTECTED] wrote: Hi, I have a math function that looks like this sin (Theta) = 5/6 How do I find Theta (in degrees) in python? I am aware of the math.sin function, but is there a reverse? maybe a sine

Re: regarding memoize function

2008-04-03 Thread Dan Bishop
On Apr 3, 6:33 pm, [EMAIL PROTECTED] wrote: I saw example of memoize function...here is snippet def memoize(fn, slot): def memoized_fn(obj, *args): if hasattr(obj, slot): return getattr(obj, slot) else: val = fn(obj, *args)

Re: Stuck in a loop

2008-03-31 Thread Dan Bishop
On Mar 31, 8:22 pm, [EMAIL PROTECTED] wrote: I wrote a simple algorithm and it keeps getting stuck in a loop. I guess I'm just to tired to figure it out: compcount=[5,4,2,2] suitrank=[0,0,0,0] trump=2 l,lt=0,0 while l4: while lt4: if l==trump: l+=1 if

Re: Question about overloading of binary operators

2008-03-31 Thread Dan Bishop
On Mar 31, 5:03 pm, gigs [EMAIL PROTECTED] wrote: Raj Bandyopadhyay wrote: Hi Here's a simple class example I've defined # class myInt(int): def __add__(self,other): return 0 print 5 + myInt(4) #prints 9 print myInt(4) + 5 #prints 0

Re: Why prefer != over for Python 3.0?

2008-03-30 Thread Dan Bishop
On Mar 30, 5:40 am, Torsten Bronger [EMAIL PROTECTED] wrote: Hallöchen! Bjoern Schliessmann writes: Lie wrote: Ah yes, that is also used (I completely forgot about that one, my math's aren't that sharp anymore) and I think it's used more frequently than . Where did you read that (I

Re: Why prefer != over for Python 3.0?

2008-03-30 Thread Dan Bishop
On Mar 29, 12:34 pm, Lie [EMAIL PROTECTED] wrote: On Mar 29, 5:55 pm, [EMAIL PROTECTED] wrote: I don't know if this is the right place to discuss the death of in Python 3.0, or if there have been any meaningful discussions posted before (hard to search google with '' keyword), but why

Re: Why prefer != over for Python 3.0?

2008-03-29 Thread Dan Bishop
On Mar 29, 6:08 am, Paul Rubin http://[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] writes: I don't know if this is the right place to discuss the death of in Python 3.0, or if there have been any meaningful discussions posted before (hard to search google with '' keyword), but why would

Re: counting using variable length string as base

2008-03-27 Thread Dan Bishop
On Mar 27, 1:15 am, Grimsqueaker [EMAIL PROTECTED] wrote: Hi, I'm fairly new to Python and to this list. I have a problem that is driving me insane, sorry if it seems simple to everyone, I've been fighting with it for a while. :)) I want to take a variable length string and use it as a base

Re: Why does python behave so? (removing list items)

2008-03-26 Thread Dan Bishop
On Mar 26, 5:12 pm, Thomas Dybdahl Ahle [EMAIL PROTECTED] wrote: On Wed, 2008-03-26 at 23:04 +0100, Michał Bentkowski wrote: Why does python create a reference here, not just copy the variable? Python, like most other oo languages, will always make references for =, unless you work on native

Re: python hash() function

2008-03-25 Thread Dan Bishop
On Mar 25, 9:22 pm, Terry Reedy [EMAIL PROTECTED] wrote: Alvin Delagon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | Hello, | | hash(foobar) | -1969371895 | | Anyone can explain to me how the hash() function in python does its work? A | link to its source could help me a

Re: NameError: name 'guess' is not defined

2008-03-22 Thread Dan Bishop
On Mar 22, 10:44 am, Diez B. Roggisch [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] schrieb: I am very new to both programming and Pyhton and while trying to do some practice using A byte of python an Error pops up on the IDLE shell. I am using windows XP. PLease see below. while running:

Re: Immutable and Mutable Types

2008-03-17 Thread Dan Bishop
Bernard Lim wrote: Hi, I'm reading the Python Reference Manual in order to gain a better understanding of Python under the hood. On the last paragraph of 3.1, there is a statement on immutable and mutable types as such: paraphrase Depending on implementation, for immutable types,

Re: String To List

2008-03-17 Thread Dan Bishop
On Mar 17, 1:15 am, Girish [EMAIL PROTECTED] wrote: I have a string a = ['xyz', 'abc'].. I would like to convert it to a list with elements 'xyz' and 'abc'. Is there any simple solution for this?? Thanks for the help... eval(a) will do the job, but you have to be very careful about using that

Re: Convert int to float

2008-03-15 Thread Dan Bishop
On Mar 15, 4:43 pm, Guido van Brakel [EMAIL PROTECTED] wrote: Hello I have this now: def gem(a): g = sum(a) / len(a) return g print gem([1,2,3,4]) print gem([1,10,100,1000]) print gem([1,-2,3,-4,5]) It now gives a int, but i would like to see floats. How can integrate

Re: no more comparisons

2008-03-13 Thread Dan Bishop
On Mar 13, 7:38 pm, Alan Isaac [EMAIL PROTECTED] wrote: Mark Dickinson wrote: Sorting tuples, where the second item in the tuple should have the opposite ordering to the first is going to be a bit of a pain. Or even worse, where the ordering of the second item depends on the value of the

Re: no more comparisons

2008-03-12 Thread Dan Bishop
On Mar 12, 6:52 pm, Alan Isaac [EMAIL PROTECTED] wrote: Paul Rubin wrote: The cmp option should not be removed. However, requiring it to be specified as a keyword parameter instead of just passed as an unlabelled arg is fine. Sure; I would have no problem with that. But that is not

Re: Regarding coding style

2008-03-08 Thread Dan Bishop
On Mar 8, 1:31 pm, Grant Edwards [EMAIL PROTECTED] wrote: ... rant What I really can't stand are the pointy-haired comment blocks at the beginnings of C/C++ functions that do things like tell you the name and return type of the function and list the names and types of the parameters. Gee,

Re: Why , not '''?

2008-03-05 Thread Dan Bishop
On Mar 5, 7:24 pm, Matt Nordhoff [EMAIL PROTECTED] wrote: Steven D'Aprano wrote: Surely it would depend on the type of text: pick up any random English novel containing dialogue, and you're likely to find a couple of dozen pairs of quotation marks per page, against a few apostrophes.

Re: How about adding rational fraction to Python?

2008-02-29 Thread Dan Bishop
On Feb 29, 12:55 am, Dennis Lee Bieber [EMAIL PROTECTED] wrote: On Thu, 28 Feb 2008 10:39:51 -, Steven D'Aprano [EMAIL PROTECTED] declaimed the following in comp.lang.python: By that logic, we should see this: len(a string) '8' Why? len() is a function that /counts/ the

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

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: 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: 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: Basic inheritance question

2008-01-06 Thread Dan Bishop
On Jan 5, 4:53 am, Bjoern Schliessmann usenet- [EMAIL PROTECTED] 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++,

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 of only

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 } http://timhatch.com/projects/pybraces/ Heheheh.. Wow! I never thought of

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. Yes. On the other

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

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 work harder. Is this

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

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

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? from django.db import models class Poll(models.Model

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 __unicode__(self):

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

Re: question about math module notation

2007-07-26 Thread Dan Bishop
On Jul 26, 3:59 pm, Paul Rubin http://[EMAIL PROTECTED] 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, not

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 have a hypothesis that former Pascal

Re: Permutations with generators

2007-07-21 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 sequence (I

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 a

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

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 %char specifier to guide itself

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

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

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, would

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 be broken

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)

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 distributes the bits

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

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

  1   2   3   >