[...]
>> In [19]: def simple_integral(func,a,b,dx = 0.001):
>> : return sum(map(lambda x:dx*x, func(arange(a,b,dx
>
> Do you mean
>
> def simple_integral(func,a,b,dx = 0.001):
> return dx * sum(map(func, arange(a,b,dx)))
>
yes, this should be faster :)
--
http://mail.pyth
my fault
In [31]: simple_integral(lambda x:sinc(x/pi), -1000, 1000)
Out[31]: 3.14046624406611
--
http://mail.python.org/mailman/listinfo/python-list
Hello,
In [19]: def simple_integral(func,a,b,dx = 0.001):
: return sum(map(lambda x:dx*x, func(arange(a,b,dx
:
In [20]: simple_integral(sin, 0, 2*pi)
Out[20]: -7.5484213527594133e-08
ok, can be thought as zero
In [21]: simple_integral(sinc, -1000, 1000)
Out[21]: 0.999797
> {:} for empty dict and {} for empty set don't look too much atrocious
> to me.
this looks consistent to me
--
http://mail.python.org/mailman/listinfo/python-list
[...]
>>> In Python 3.0, this looks like::
>>>
>>> s = {1,2,3}
>>
>> jepp, that looks not bad .. as in a mathe book.
>> the only disadvantage I see, that one may confuse it with a dict.
>
> Perhaps with a very cursory inspection. But the lack of any ':'
> characters is a pretty quick clue-in
Steven Bethard schrieb:
> Schüle Daniel wrote:
>> Hello,
>>
>> lst = list((1,2,3))
>> lst = [1,2,3]
>>
>> t = tupel((1,2,3))
>> t = (1,2,3)
>>
>> s = set((1,2,3))
>> s = ...
>>
>> it would be nice feature to have builti
faulkner schrieb:
> On Feb 14, 11:55 am, Schüle Daniel <[EMAIL PROTECTED]> wrote:
>> Hello,
>>
>> lst = list((1,2,3))
>> lst = [1,2,3]
>>
>> t = tupel((1,2,3))
>> t = (1,2,3)
>>
>> s = set((1,2,3))
>> s = ...
>>
>
Hello,
lst = list((1,2,3))
lst = [1,2,3]
t = tupel((1,2,3))
t = (1,2,3)
s = set((1,2,3))
s = ...
it would be nice feature to have builtin literal for set type
maybe in P3 .. what about?
s = <1,2,3>
Regards, Daniel
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
[...]
> No, that's actually wrong. What version of numpy are you using? With a recent
> SVN checkout of numpy, I get the correct answer:
>
> In [3]: roots([1,0,0])
> Out[3]: array([ 0., 0.])
In [17]: import sys, numpy
In [18]: sys.version
Out[18]: '2.5 (r25:51908, Sep 23 2006, 01:23:14) \
Hello NG,
given this call to roots funtion from pylab
In [342]: roots([0,2,2])
Out[342]: array([-1.])
as far as I understand it [a0,a1,a2] stands for a0+a1*x+a2*x^2
in the above case it yields 2x^2+2x = 2x(1+x)
and the roots are 0 and -1
I am wondering why roots function gives me only the -1
se
Gabriel Genellina schrieb:
Gabriel Genellina schrieb:
> On 7 dic, 22:53, Schüle Daniel <[EMAIL PROTECTED]> wrote:
>
>> In [38]: f = [lambda:i for i in range(10)]
>> In [39]: ff = map(lambda i: lambda : i, range(10))
>> In [40]: f[0]()
>> Out[40]: 9
>> In
Hello snakes :)
In [38]: f = [lambda:i for i in range(10)]
In [39]: ff = map(lambda i: lambda : i, range(10))
In [40]: f[0]()
Out[40]: 9
In [41]: f[1]()
Out[41]: 9
In [42]: ff[0]()
Out[42]: 0
In [43]: ff[1]()
Out[43]: 1
I don't understand why in the first case f[for all i in 0..9]==9
what is diff
Hello,
I came up with this algorithm to generate all permutations
it's not the best one, but it's easy enough
# lst = list with objects
def permute3(lst):
tmp = []
lenlst = len(lst)
def permute(perm, level):
if level == 1:
tmp.append(perm)
return
Hello all,
I didn't found more appropriate news group for
this question, please let me know if there is ng with
regular expression as its main topic
I am trying to construct a case where a greedy and
non greedy operation produce different result.
I dont see the difference between 'a??b' and 'a?b'
Hello,
first question
In [117]: cmp("ABC",['A','B','C'])
Out[117]: 1
against what part of the list is the string "ABC" compared?
second question
In [119]: class X(object):
.: pass
.:
In [120]: X() < X()
Out[120]: True
In [121]: X() < X()
Out[121]: False
In [122]: X() < X
correction :)
> class Graph:
> settings = {
> "NumNodes" : 10,
> "MinNodes" : 2,
> "MaxNodes" : 5
> }
> def randomizeEdges(self,
> lowhigh = (settings["MinNodes"], settings["MaxNodes"])):
of course this should be
Graph.settings["MinNodes"], Graph.sett
[EMAIL PROTECTED] schrieb:
>> cnt = 1
>> def foo():
>> global cnt
>> cnt += 1
>> return cnt
>>
>> def bar(x=foo()):
>> print x
>>
>> bar()# 2
>> bar()# 2
>> bar()# 2
>
> Looks to me like you want to use the following programming pattern to
> get dynamic
Hi all,
given python description below
import random
class Node:
def __init__(self):
self.nachbarn = []
class Graph(object):
# more code here
def randomizeEdges(self, low=1, high=self.n):
pass
graph = Graph(20)
graph.randomizeEdges(2
Steve Holden schrieb:
> Maxine Weill wrote:
>> I need to install Python Imaging Library (PIL) - imaging-1.1.5.tar.gz
>> (source ) onto Suse Linux 10.1 system in order for (latest) Scribus
>> 1.3.3.2 to install and work.
>>
>> Plesae indicate how I perform PIL install (exact commands/procedures)
Hello,
consider the following code
>>> re.search("[a-z](?i)[a-z]","AA")
<_sre.SRE_Match object at 0x40177e20>
this gives a match
if we provide an extra group for the first character it still works
>>> re.search("([a-z])(?i)[a-z]","AA").group(1)
'A'
>>>
it doesn't matter where (?i) is placed
Schüle Daniel schrieb:
> [EMAIL PROTECTED] schrieb:
>> i used C too much and haven't used Python for a while...
>>
>> like in C, if we want an array of array of float, we use
>>
>> float a[200][500];
>>
>> now in Python, seems like we have to d
[EMAIL PROTECTED] schrieb:
> i used C too much and haven't used Python for a while...
>
> like in C, if we want an array of array of float, we use
>
> float a[200][500];
>
> now in Python, seems like we have to do something like
>
> a = [ [ ] ] * 200
>
> and then just use
>
> a[1].append(12.3
> True, but I don't see what it has to do with my question.
my mistake, I misunderstood your question
as Sreeram said, os.open can be used
help(os.open)
Help on built-in function open:
open(...)
open(filename, flag [, mode=0777]) -> fd
Open a file (for low level IO).
>>> import
Grant Edwards schrieb:
> When one open()s a file (that doesn't exist) for writing , how
> does one control that file's permissions (it's "mode" in Unix
> terms).
what do you mean by "contor file's mode"?
usually you try to open and if you are not allowed
you will get the exception
>>> try:
...
> A solution could be that "replace" accept a tuple/list of chars, like
> that was add into the new 2.5 for startswith.
>
> I don't know, but can be this feature included into a future python
> release?
I don't know, but I think it would be useful
as for now I use this
>>> import re
>>> cha
Juergen Huber schrieb:
> Fredrik Lundh wrote:
>> Juergen Huber wrote:
>>
>>> ok...i thought as much, that i have to copy this file!
>>>
>>> how will i do that?!
>>> how will i fix this file => delete the first line?!
>>>
>>> with which commands could i do that?!
>> start here:
>>
>> http://docs.pyt
[EMAIL PROTECTED] schrieb:
> i was wondering if anyone could point me to some good reading about the
> for and while loops
>
> i am trying to write some programs
> "Exercise 1
>
> Write a program that continually reads in numbers from the user and
> adds them together until the sum reaches 100. W
this is decorator, this is how it's may be implented
>>> def returns(t):
... def dec(f):
... def wrapped(*args, **kwargs):
... ret = f(*args, **kwargs)
... assert type(ret) is t
... return ret
... return wrapp
it's import-ed only once
# magic.py file
#!/usr/bin/python
print "here"
import magic# try to import itself
then try
# bad_magic.py
#!/usr/bin/python
print "here"
import bad_magic
reload(bad_magic)
hth, Daniel
--
http://mail.python.org/mailman/listinfo/python-list
Hello
> Here's the code I wrote:
>
> import random
>
> flip = random.randrange(2)
> heads = 0
> tails = 0
> count = 0
>
> while count < 100:
>
> if flip == 0:
flip never changes again
it's not reassigned in the while loop
> heads += 1
>
> else:
> tails += 1
>
[EMAIL PROTECTED] schrieb:
> does anyone know a module or something to convert numbers like integer
> to binary format ?
unfortunately there is no builtin function for this
>>> int("111",2)
7
>>> str(7)
'7'
>>> str(7,2)
Traceback (most recent call last):
File "", line 1, in ?
TypeError: str
Kent Johnson schrieb:
> Schüle Daniel wrote:
>> and now the obvious one (as I thought at first)
>>
>> >>> lst=[]
>> >>> for i in range(10):
>> ... lst.append(lambda:i)
>> ...
>> >>> lst[0]()
>> 9
>> &g
>> are there other solutions to this problem
>> without use of eval or exec?
>>
>
> Using a factory function & closures instead of lambda:
>>> def a(x):
... def b():
... return x
... return b
...
>>> lst=[]
>>> for i in range(10):
... lst.append(a(i))
...
>>> lst[0]()
Hello group,
>>> lst=[]
>>> for i in range(10):
... lst.append(eval("lambda:%i" % i))
...
>>> lst[0]()
0
>>> lst[1]()
1
>>> lst[9]()
9
>>>
>>> lst=[]
>>> for i in range(10):
... exec "tmp = lambda:%i" % i # assignment is not expression
... lst.append(tmp)
...
>>> lst[0](
[..]
> These are the only lines of code that reference "imageLabel":
>
> imageLabel = Label(master = frame1, image = image)
> imageLabel.pack()
>
>
> Unless the constructor of Label adds a reference of itself to frame1,
> imageLabel will also become garbage collected at the end of the
> const
Farshid Lashkari schrieb:
> Schüle Daniel wrote:
>> I don't understand what is the difference between commented lines
>> 1 and 2
>>
>> with 1 uncommented and 2 commented it works as expected
>> with 1 commented and 2 uncommented the picture doesn't appear
I don't understand what is the difference between commented lines
1 and 2
with 1 uncommented and 2 commented it works as expected
with 1 commented and 2 uncommented the picture doesn't appear
here is my code
#!/usr/bin/env python
from Tkinter import *
from Tkconstants import *
root = None
cla
Sean Givan schrieb:
> Hi. I'm new to Python
welcome
> ago. I was doing some experiments with nested functions, and ran into
> something strange.
>
> This code:
>
> def outer():
> val = 10
> def inner():
> print val
> inner()
>
> outer()
>
> ...prints out the value '10',
Sean Hammond schrieb:
>
> I've managed to create a scenario in which editing an object in a list
> of objects seems to edit every object in the list, rather than just the
> one. I'm totally stumped and wondered if anyone would be kind enough to
> read my explanation and see if they have any sug
it's easy to explain
class X:
pass
x=X()
y=X()
x and y are different instances
one can put in x
x.item = 1
y doesn't even have an attribute item for example
similar with generators
they are *different* objects of same kind generator
>>> def fib():
... a,b = 1,1
... while True:
[...]
> So finally here's my question: If you are using data.append(), doesn't
> that just put all the numbers into one long list?
no, append appends
extend does what you think
How are the tuples
> still being created in this case so that the list comprehensions still
> work? It seems like th
Hello
what I sometimes miss in Python is the possibility to
switch tha base of a number
for example this is how it's done in Ruby
irb(main):099:0* a = 10.to_s(2)
=> "1010"
irb(main):100:0> a.to_i(2)
=> 10
irb(main):101:0>
irb(main):102:0* a = 10.to_s(3)
=> "101"
irb(main):103:0> a.to_i(3)
=> 10
Russ wrote:
> I have a couple of questions for the number crunchers out there:
>
> Does "pow(x,2)" simply square x, or does it first compute logarithms
> (as would be necessary if the exponent were not an integer)?
>
> Does "x**0.5" use the same algorithm as "sqrt(x)", or does it use some
> other
Hello,
consider this code
>>> class A(object):
... def __init__(self):
... self.a = 1
... self.b = 2
...
>>> class B(A):
... __slots__ = ["x","y"]
...
>>> b=B()
>>> b.a
1
>>> b.b
2
>>> b.x = 100
>>> b.y = 100
>>> b.z = 100
no exception here
does __slots__
Steven D'Aprano wrote:
> On Fri, 10 Mar 2006 02:19:10 +0100, Schüle Daniel wrote:
>
>
>>yeah, i miss some things in complex implementation
>>for example c=complex()
>>c.abs = 2**0.5
>>c.angle = pi/2
>>
>>should result in 1+1j :)
>
>
>
Russ wrote:
> I'd like to get output formatting for my own classes that mimics the
> built-in output formatting. For example,
>
>
x = 4.54
print "%4.2f" % x
>
> 4.54
>
> In other words, if I substitute a class instance for "x" above, I'd
> like to make the format string apply to an elem
Magnus Lycka wrote:
> I want an re that matches strings like "21MAR06 31APR06 1236",
> where the last part is day numbers (1-7), i.e it can contain
> the numbers 1-7, in order, only one of each, and at least one
> digit. I want it as three groups. I was thinking of
>
> r"(\d\d[A-Z]\d\d) (\d\d[A-Z]
Anton81 wrote:
> Hi,
>
> I want to use globals that are immediately visible in all modules. My
> attempts to use "global" haven't worked. Suggestions?
>
> Anton
I think a dictionary would work here
as well as list but not strings and int's
# module1
settings = {
"release" : "1.0",
[...]
> If you think so :) Ususally people go for dictionaries in such cases.
you are right, I didn't think about dictionaries
>>> p = "complex(1-1e-%i, 1-1e-%i)"
>>> d={}
>>> [d.update({i:eval(p % (i,i))}) for i in range(20,30)]
[None, None, None, None, None, None, None, None, None, None]
s
Hello all,
>>> p = "z%i = complex(1-1e-%i, 1-1e-%i)"
>>> lst = [p % (i,i,i) for i in range(10, 30)]
>>> for item in lst:
... exec item
...
>>>
>>> p = "z%i = complex(1-1e-%i, 1-1e-%i)"
>>> lst = [p % (i,i,i) for i in range(10, 30)]
>>> [exec item for item in lst]
File "", line 1
thank you
I will have to take a closer look on __new__
Regards, Daniel
--
http://mail.python.org/mailman/listinfo/python-list
what do you think of this design?
>>> def polar(x,y=None):
... if type(x) in (list,tuple) and len(x) == 2 and y is None:
... return complex(x[0]*cos(x[1]), x[0]*sin(x[1]))
... if type(x) is complex and y is None:
... return (abs(x), atan2(x.imag,x.real))
... if
Hello
I am trying to customize the handling of complex numbers
what I am missing is a builtin possibility to create
complex numbers in polar coordinates
so first I wrote a standalone function
>>> def polar(r,arg):
... re, im = r*cos(arg), r*sin(arg)
... return re + im*1j
then I tried t
[EMAIL PROTECTED] wrote:
> First of all, please don't flame me immediately. I did browse archives
> and didn't see any solution to my problem.
>
> Assume I want to add a method to an object at runtime. Yes, to an
> object, not a class - because changing a class would have global
> effects and I wa
Hi Alex
[...]
> The trick about distinguishing a name's exact nature based on whether
> the compiler sees an assignment to that name in some part of code is
> found in both languages, albeit in different ways. In Ruby, as you've
> pointed out, it's the heuristic used to disambiguate local variabl
Gregory Petrosyan wrote:
> Hello!
> It's 1:56 o'clock in St.-Petersburg now, and I am still coding... maybe
> that's why I encountered stupid problem: I need to remove zeros from
> the begining of list, but I can't :-(. I use
>
> for i,coef in enumerate(coefs):
> if coef == 0:
in case you are trying it in the python shell
>>> def foo():return "test"
...
>>> import __main__
>>> __main__.__dict__["foo"]
>>> __main__.__dict__["foo"]()
'test'
>>>
otherwise build your own dict with string->function mapping
op = {
"plus" : lambda x,y:x+y,
"minus" : lam
> I want to write a program in python using integer arrays.
you can :)
> I wish to calculate formulas using 200 digit integers.
no problem
> I could not find any documentation in python manual about declaring arrays.
>
> I searched the internet
read here
http://diveintopython.org/native_dat
I don't want to hijack the thread I was thinking
whether something like lst.remove(item = 0, all = True)
would be worth adding to Python?
it could have this signature
def remove(item, nItems = 1, all = False)
...
return how_many_deleted
lst.remove(item = 0, nItems = 1)
lst.remove
Lonnie Princehouse wrote:
> everybody is making this way more complicated than it needs to be.
>
> storage = list[:list.index(O)]
the question is whether the old list is needed in the future or not
if not then it would be easer/mor efficient to use
del lst[lst.index(0):]
Regards, Daniel
--
ht
[...]
> I have been using something like this:
> _
>
> while list[0] != O:
> storage.append(list[0])
> list.pop(0)
> if len(list) == 0:
> break
> _
>
> But this seems ugly to me, and using "while" give me the heebies. Is
> there a bett
[...]
>
> What not
>
> for x in list:
> if x == O:
> break
> storage.append(x)
>
i think this may take too long
better aproach would be to test for zero from the end
Regards, Daniel
--
http://mail.python.org/mailman/listinfo/python-list
[...]
>> It's the same function, whether it's bound or not. Thus, it should
>> always have the same type.
>
>
> No, it's not the same function. You got the same id because you didn't
> bind B.bar and b.bar to anything so the id was reused.
thank you for the explanation
it's indeed tricky wit
Hello all,
>>> class Q:
... def bar(self):
... pass
...
>>> import types
>>> types.UnboundMethodType is types.MethodType
True
>>>
>>> type(Q.bar)
>>>
>>> q = Q()
>>> type(q.bar)
>>>
>>> type(q.bar) is types.UnboundMethodType
True
>>> q.bar
>
>>>
I think is not very c
Ernesto wrote:
> Thanks for the approach. I decided to use regular expressions. I'm
> going by the code you posted (below). I replaced the line re.findall
> line with my file handle read( ) like this:
>
> print re.findall(pattern, myFileHandle.read())
>
> This prints out only brackets []. Is
[EMAIL PROTECTED] wrote:
> Already thanks for the reply,
>
> but how to write your own copy operator? Won't you always be passing
> referrences to new_obj?
for example this would work
>>> class X(object):
... def __init__(self,lst):
... self.lst = lst
... def copy(self):
...
> I would like to have an array of "structs." Each struct has
>
> struct Person{
> string Name;
> int Age;
> int Birhtday;
> int SS;
> }
the easiest way would be
class Person:
pass
john = Person()
david = Person()
john.name = "John Brown"
john.age = 35
etc
think of
>>> lst = [1,2,3]
>>> len(lst)
3
>>> lst.__len__()
3
in genereal all objects which implements __len__
can be passed to built-in function len
>>> len
just to give one example how this can be used
>>> class X(object):
... def __len__(self):
... print "this instance has __len_
if you want the numbers you can combine it into one-liner
nums = file(r"C:\folder\myFile.txt").read().split(";")
the numbers are in string representation in the list
you can no do
nums = [float(num) for num in nums]
Regards, Daniel
--
http://mail.python.org/mailman/listinfo/python-list
Hello,
[...]
>
> I'm sure there are more, but these jump out at me as I'm going. It
> seems as if the idx=find() stuff can be done with Numeric.nonzeros(),
> but you can't index with that, like
>
> a=Numeric.arange(1,11,1)
> idx=Numeric.nonzeros(a)
import Numeric as N
N.nonzero
without s :)
thank you, I completely forgot that + is one of metacharacters
Regards, Daniel
--
http://mail.python.org/mailman/listinfo/python-list
X-Enigmail-Version: 0.76.5.0
X-Enigmail-Supports: pgp-inline, pgp-mime
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hello @all,
>>> p = re.compile(r"(\d+) = \1 + 0")
>>> p.search("123 = 123 + 0")
'search' returns None but I would expect it to
find 1
Hello NG,
recently I was using Scheme and Ruby and was really nicely surprised
to find there support for the computing with rational numbers
for example this how it works in Ruby
mond:/pool/PROG/ruby # irb
irb(main):001:0>
irb(main):002:0* require "mathn"
=> true
irb(main):003:0> r = Rational(1,
thx to all
now I understand how it works and why it should be done in this way
so it's possible to write more than only one declarator
>>> def foo(f):
... l = [1]
... def method(*a,**kw):
... f(l, *a, **kw)
... return method
...
>>> def bar(f):
... l = [2]
... de
hello NG,
consider this code
>>> def timelogger(f):
... def wrapper(*a,**kw):
... print "started at %s" % time.ctime()
... t0 = time.time()
... f(*a, **kw)
... t1 = time.time()
... print "ended at %s" % time.ctime()
...
I was not very clear about it
> or even if you "could" copy instances
>
> class X:
> def __init__(self, filename = "/path/file")
> self.file = file(filename, "w+")
> def modifyByteAt(offset):
> self.file.tell(offset)
> self.file.write("X")
>
> this is untested pse
KraftDiner wrote:
> I'm having trouble getting a copy of and object... (a deep copy)
>
> I'm writing a method that creates a mirror image of an object (on
> screen)
> In order to do this i need to get a copy of the object and then modify
> some
> of its attributes.
>
> I tried:
> objs = myListOfO
77 matches
Mail list logo